blob: 7ab54bf0cab318432f04509f45773d236b9ffafb [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]95640212014-07-26 18:14:3021#include "content/browser/accessibility/accessibility_mode_helper.h"
22#include "content/browser/accessibility/browser_accessibility_state_impl.h"
[email protected]7a846df2012-09-20 19:17:3923#include "content/browser/browser_plugin/browser_plugin_embedder.h"
24#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5925#include "content/browser/child_process_security_policy_impl.h"
dgozman24bfc912014-09-29 11:04:1826#include "content/browser/devtools/devtools_manager.h"
[email protected]5f2aa722013-08-07 16:59:4127#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0428#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4629#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1230#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1631#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1632#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4033#include "content/browser/frame_host/interstitial_page_impl.h"
34#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0135#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1836#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1637#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5738#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0539#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4440#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4041#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3042#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5243#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]29998f92014-06-15 03:12:1444#include "content/browser/media/midi_dispatcher_host.h"
[email protected]0bc7f3542013-10-21 15:05:5345#include "content/browser/message_port_message_filter.h"
46#include "content/browser/message_port_service.h"
tommyclieb25b2a2014-11-03 19:45:0947#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]d9030b82013-07-19 08:26:0648#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3049#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5050#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3251#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5052#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4853#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0954#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3355#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1156#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5857#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0358#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5659#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1460#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4261#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4462#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0263#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1764#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5165#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0266#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3667#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1168#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2869#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4470#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3671#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1772#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1473#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4674#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1575#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0076#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2777#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0078#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3779#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1480#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3081#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3282#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0983#include "content/public/browser/screen_orientation_dispatcher_host.h"
[email protected]4c3a23582012-08-18 08:54:3484#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3885#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4286#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2587#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2188#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4889#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5490#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4991#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2092#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0393#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5794#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:0595#include "content/public/common/web_preferences.h"
[email protected]a53209b2012-01-20 16:48:1696#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2997#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5398#include "net/http/http_cache.h"
99#include "net/http/http_transaction_factory.h"
100#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34101#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:56102#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01103#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41104#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52105#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31106
[email protected]583418cc2013-01-17 14:01:10107#if defined(OS_ANDROID)
108#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:45109#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18110#include "content/browser/web_contents/web_contents_android.h"
[email protected]583418cc2013-01-17 14:01:10111#endif
112
[email protected]f66df822012-05-18 16:52:17113#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50114#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57115#endif
[email protected]3e45ba92009-02-20 21:09:00116
[email protected]8ff00d72012-10-23 19:12:21117namespace content {
[email protected]420ae012009-04-24 05:16:32118namespace {
119
[email protected]960b0372014-05-19 18:01:00120const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
121
122// This matches what Blink's ProgressTracker has traditionally used for a
123// minimum progress value.
124const double kMinimumLoadingProgress = 0.1;
125
[email protected]82114f52012-03-20 22:53:41126const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05127
[email protected]155c7f22013-12-09 17:07:18128#if defined(OS_ANDROID)
129const char kWebContentsAndroidKey[] = "web_contents_android";
130#endif // OS_ANDROID
131
[email protected]e4abd3b42013-11-12 18:28:47132base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46133g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
134
thestigc4cac8f2014-09-04 21:17:50135static int StartDownload(RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39136 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29137 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30138 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02139 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58140 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02141 ++g_next_image_download_id,
142 url,
143 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30144 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02145 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39146}
147
[email protected]8bfc8272013-09-09 20:10:53148void NotifyCacheOnIO(
149 scoped_refptr<net::URLRequestContextGetter> request_context,
150 const GURL& url,
151 const std::string& http_method) {
152 request_context->GetURLRequestContext()->http_transaction_factory()->
153 GetCache()->OnExternalCacheHit(url, http_method);
154}
155
[email protected]9b159a52013-10-03 17:24:55156// Helper function for retrieving all the sites in a frame tree.
157bool CollectSites(BrowserContext* context,
158 std::set<GURL>* sites,
159 FrameTreeNode* node) {
160 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
161 return true;
162}
163
[email protected]a86c0e962013-12-17 17:10:39164bool ForEachFrameInternal(
165 const base::Callback<void(RenderFrameHost*)>& on_frame,
166 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41167 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39168 return true;
169}
170
[email protected]95640212014-07-26 18:14:30171bool ForEachPendingFrameInternal(
172 const base::Callback<void(RenderFrameHost*)>& on_frame,
173 FrameTreeNode* node) {
174 RenderFrameHost* pending_frame_host =
175 node->render_manager()->pending_frame_host();
176 if (pending_frame_host)
177 on_frame.Run(pending_frame_host);
178 return true;
179}
180
[email protected]a86c0e962013-12-17 17:10:39181void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
182 IPC::Message* message_copy = new IPC::Message(*message);
183 message_copy->set_routing_id(rfh->GetRoutingID());
184 rfh->Send(message_copy);
185}
186
[email protected]948481d2014-06-11 18:32:22187void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
188 RenderFrameHost* rfh) {
189 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
190 ->frame_tree_node()
191 ->render_manager()
192 ->GetRenderWidgetHostView();
193 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59194}
195
[email protected]95640212014-07-26 18:14:30196void SetAccessibilityModeOnFrame(AccessibilityMode mode,
197 RenderFrameHost* frame_host) {
198 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
199}
200
[email protected]420ae012009-04-24 05:16:32201} // namespace
202
[email protected]54944cde2012-12-09 09:24:59203WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15204 return WebContentsImpl::CreateWithOpener(
205 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19206}
207
208WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59209 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30210 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59211 WebContentsImpl* new_contents = new WebContentsImpl(
212 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30213
214 for (SessionStorageNamespaceMap::const_iterator it =
215 session_storage_namespace_map.begin();
216 it != session_storage_namespace_map.end();
217 ++it) {
218 new_contents->GetController()
219 .SetSessionStorageNamespace(it->first, it->second.get());
220 }
221
[email protected]54944cde2012-12-09 09:24:59222 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19223 return new_contents;
[email protected]a81343d232011-12-27 07:39:20224}
[email protected]746d3052012-05-22 15:15:47225
[email protected]e4abd3b42013-11-12 18:28:47226void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46227 g_created_callbacks.Get().push_back(callback);
228}
229
[email protected]e4abd3b42013-11-12 18:28:47230void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46231 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
232 if (g_created_callbacks.Get().at(i).Equals(callback)) {
233 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
234 return;
235 }
236 }
237}
238
[email protected]299d7f12012-05-23 05:31:15239WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47240 return rvh->GetDelegate()->GetAsWebContents();
241}
242
[email protected]a86c0e962013-12-17 17:10:39243WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
244 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
245 if (!rfh_impl)
246 return NULL;
247 return rfh_impl->delegate()->GetAsWebContents();
248}
249
[email protected]7fff43e2013-05-21 20:21:10250// WebContentsImpl::DestructionObserver ----------------------------------------
251
252class WebContentsImpl::DestructionObserver : public WebContentsObserver {
253 public:
254 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
255 : WebContentsObserver(watched_contents),
256 owner_(owner) {
257 }
258
259 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58260 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58261 owner_->OnWebContentsDestroyed(
262 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10263 }
264
265 private:
266 WebContentsImpl* owner_;
267
268 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
269};
270
[email protected]8ed16472014-04-11 19:02:48271WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
272 int render_frame_id,
273 ColorChooser* chooser,
274 int identifier)
275 : render_process_id(render_process_id),
276 render_frame_id(render_frame_id),
277 chooser(chooser),
278 identifier(identifier) {
279}
280
281WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
282}
283
[email protected]b172aee2012-04-10 17:05:26284// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32285
blundellc57b93f2014-10-29 13:19:57286WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
287 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42288 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22289 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57290 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44291 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49292 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08293#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41294 accessible_parent_(NULL),
295#endif
[email protected]6ea6bdf2013-12-06 13:35:01296 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57297 this,
298 this,
299 this,
300 this),
[email protected]d5f942ba2008-09-26 19:30:34301 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03302 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23303 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
304 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34305 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26306 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00307 loading_total_progress_(0.0),
[email protected]960b0372014-05-19 18:01:00308 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56309 upload_size_(0),
310 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47311 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10312 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55313 capturer_count_(0),
314 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57315 is_being_destroyed_(false),
316 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15317 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01318 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02319 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38320 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21321 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
322 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29323 totalPinchGestureAmount_(0),
324 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44325 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42326 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03327 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49328 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05329 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30330 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57331 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30332 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30333 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddy371ad9142014-09-17 08:01:46334 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50335 virtual_keyboard_requested_(false),
mohan.reddy371ad9142014-09-17 08:01:46336 loading_weak_factory_(this) {
[email protected]cbb1ef592013-06-05 19:49:46337 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
338 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55339 frame_tree_.SetFrameRemoveListener(
340 base::Bind(&WebContentsImpl::OnFrameRemoved,
341 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35342}
initial.commit09911bf2008-07-26 23:55:29343
[email protected]b172aee2012-04-10 17:05:26344WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32345 is_being_destroyed_ = true;
346
[email protected]21b41c7e892014-02-28 01:52:24347 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
348 // shutdown and be deleted as well.
349 frame_tree_.ForEach(
350 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
351
[email protected]d9030b82013-07-19 08:26:06352 ClearAllPowerSaveBlockers();
353
[email protected]b24b68a2012-09-24 21:57:26354 for (std::set<RenderWidgetHostImpl*>::iterator iter =
355 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
356 (*iter)->DetachDelegate();
357 }
358 created_widgets_.clear();
359
[email protected]3ab9cb82011-06-03 18:02:07360 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15361 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11362 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07363
[email protected]8ed16472014-04-11 19:02:48364 if (color_chooser_info_.get())
365 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20366
[email protected]420ae012009-04-24 05:16:32367 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32368
[email protected]ca13a442012-04-17 14:00:12369 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21370 NotificationService::current()->Notify(
371 NOTIFICATION_WEB_CONTENTS_DESTROYED,
372 Source<WebContents>(this),
373 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32374
[email protected]df0c843f2014-05-23 20:37:23375 // Destroy all frame tree nodes except for the root; this notifies observers.
376 frame_tree_.ResetForMainFrameSwap();
377 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59378
[email protected]df0c843f2014-05-23 20:37:23379 // Manually call the observer methods for the root frame tree node.
380 RenderFrameHostManager* root = GetRenderManager();
381 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27382 FOR_EACH_OBSERVER(WebContentsObserver,
383 observers_,
[email protected]df0c843f2014-05-23 20:37:23384 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27385 }
[email protected]df0c843f2014-05-23 20:37:23386 FOR_EACH_OBSERVER(WebContentsObserver,
387 observers_,
388 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27389
[email protected]df0c843f2014-05-23 20:37:23390 if (root->pending_render_view_host()) {
391 FOR_EACH_OBSERVER(WebContentsObserver,
392 observers_,
393 RenderViewDeleted(root->pending_render_view_host()));
394 }
[email protected]c06c58c2014-03-12 20:31:59395
[email protected]f273ee52013-10-18 16:05:27396 FOR_EACH_OBSERVER(WebContentsObserver,
397 observers_,
[email protected]df0c843f2014-05-23 20:37:23398 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27399
[email protected]2db9bd72012-04-13 20:20:56400 FOR_EACH_OBSERVER(WebContentsObserver,
401 observers_,
[email protected]12a46832014-05-09 13:35:58402 WebContentsDestroyed());
403
404 FOR_EACH_OBSERVER(WebContentsObserver,
405 observers_,
406 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08407
[email protected]6934a702011-12-20 00:04:51408 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10409
410 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
411 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42412}
413
[email protected]d1198fd2012-08-13 22:50:19414WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59415 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19416 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03417 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59418 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06419 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19420
[email protected]4858e432014-06-23 18:14:17421 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06422 // This makes |new_contents| act as a guest.
423 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16424 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06425 // We are instantiating a WebContents for browser plugin. Set its subframe
426 // bit to true.
427 new_contents->is_subframe_ = true;
428 }
[email protected]54944cde2012-12-09 09:24:59429 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19430 return new_contents;
431}
432
[email protected]95640212014-07-26 18:14:30433// static
434std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
435 std::vector<WebContentsImpl*> result;
436 scoped_ptr<RenderWidgetHostIterator> widgets(
437 RenderWidgetHostImpl::GetRenderWidgetHosts());
438 std::set<WebContentsImpl*> web_contents_set;
439 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
440 if (!rwh->IsRenderView())
441 continue;
442 RenderViewHost* rvh = RenderViewHost::From(rwh);
443 if (!rvh)
444 continue;
445 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
446 if (!web_contents)
447 continue;
448 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
449 if (web_contents_set.find(wci) == web_contents_set.end()) {
450 web_contents_set.insert(wci);
451 result.push_back(wci);
452 }
453 }
454 return result;
455}
456
[email protected]b0936d22013-11-28 06:47:36457RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21458 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28459}
460
[email protected]7bb761892012-07-20 09:32:47461bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
462 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44463 return OnMessageReceived(render_view_host, NULL, message);
464}
465
466bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
467 RenderFrameHost* render_frame_host,
468 const IPC::Message& message) {
469 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56470 if (GetWebUI() &&
471 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17472 return true;
[email protected]d2353452012-01-19 19:53:56473 }
[email protected]f82d57b52011-04-27 19:13:17474
[email protected]d8c660432011-12-22 20:51:25475 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
476 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33477 if (render_frame_host) {
478 while ((observer = it.GetNext()) != NULL)
479 if (observer->OnMessageReceived(message, render_frame_host))
480 return true;
481 } else {
482 while ((observer = it.GetNext()) != NULL)
483 if (observer->OnMessageReceived(message))
484 return true;
485 }
[email protected]403415a2011-01-10 18:57:53486
[email protected]1d62cf72014-02-07 21:31:57487 // Message handlers should be aware of which
488 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
489 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02490 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57491 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02492 else
[email protected]1d62cf72014-02-07 21:31:57493 render_view_message_source_ = render_view_host;
494
[email protected]724159a2010-12-30 01:11:18495 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33496 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40497 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
498 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05499 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
500 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48501 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
502 OnDocumentLoadedInFrame)
503 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00504 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
505 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
506 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
507 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48508 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
509 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
510 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
511 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19512 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
513 OnMediaPlayingNotification)
514 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
515 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11516 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
517 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18518 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
519 OnDidLoadResourceFromMemoryCache)
520 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
521 OnDidDisplayInsecureContent)
522 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
523 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25524 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26525 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21526 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20527 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
528 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20529 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
530 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16531 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10532 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50533 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50534#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:42535 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
536 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50537 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
538 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55539 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
540 OnBrowserPluginMessage(message))
thestigc4cac8f2014-09-04 21:17:50541#endif
[email protected]41225fe2013-03-29 05:32:02542 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
543 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07544 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
545 OnShowValidationMessage)
546 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
547 OnHideValidationMessage)
548 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
549 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48550#if defined(OS_ANDROID)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
552 OnFindMatchRectsReply)
553 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
554 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48555#endif
[email protected]724159a2010-12-30 01:11:18556 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33557 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44558 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57559 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18560
[email protected]724159a2010-12-30 01:11:18561 return handled;
562}
563
[email protected]b172aee2012-04-10 17:05:26564void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18565 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21566 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43567 if (delegate_)
568 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18569}
570
[email protected]d1198fd2012-08-13 22:50:19571NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56572 return controller_;
573}
574
[email protected]d1198fd2012-08-13 22:50:19575const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56576 return controller_;
577}
578
[email protected]8ff00d72012-10-23 19:12:21579BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55580 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30581}
582
[email protected]b172aee2012-04-10 17:05:26583const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24584 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32585 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51586 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31587}
588
[email protected]a093ce02013-07-22 20:53:14589const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24590 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32591 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24592 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
593}
594
595const GURL& WebContentsImpl::GetLastCommittedURL() const {
596 // We may not have a navigation entry yet.
597 NavigationEntry* entry = controller_.GetLastCommittedEntry();
598 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
599}
600
[email protected]8ff00d72012-10-23 19:12:21601WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31602 return delegate_;
603}
604
[email protected]8ff00d72012-10-23 19:12:21605void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31606 // TODO(cbentzel): remove this debugging code?
607 if (delegate == delegate_)
608 return;
609 if (delegate_)
610 delegate_->Detach(this);
611 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08612 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31613 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08614 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00615 if (view_)
[email protected]e85165c642014-06-10 14:34:31616 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08617 }
[email protected]be1f56ab2011-12-22 06:55:31618}
619
[email protected]8ff00d72012-10-23 19:12:21620RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21621 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41622 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16623}
624
[email protected]60eca4eb2013-12-06 00:02:16625RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41626 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16627}
628
[email protected]9c9343b2014-03-08 02:56:07629RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
630 if (!frame_tree_.GetFocusedFrame())
631 return NULL;
632 return frame_tree_.GetFocusedFrame()->current_frame_host();
633}
634
[email protected]a86c0e962013-12-17 17:10:39635void WebContentsImpl::ForEachFrame(
636 const base::Callback<void(RenderFrameHost*)>& on_frame) {
637 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
638}
639
640void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
641 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
642 delete message;
643}
644
[email protected]b172aee2012-04-10 17:05:26645RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21646 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31647}
648
[email protected]6b618e62012-08-16 12:59:18649int WebContentsImpl::GetRoutingID() const {
650 if (!GetRenderViewHost())
651 return MSG_ROUTING_NONE;
652
653 return GetRenderViewHost()->GetRoutingID();
654}
655
[email protected]44470a22013-01-24 01:21:54656int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
657 return fullscreen_widget_routing_id_;
658}
659
[email protected]b172aee2012-04-10 17:05:26660RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21661 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31662}
663
[email protected]4aebbca2013-09-17 22:26:49664RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
665 const {
666 RenderWidgetHost* const widget_host =
667 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
668 GetFullscreenWidgetRoutingID());
669 return widget_host ? widget_host->GetView() : NULL;
670}
671
[email protected]8ff00d72012-10-23 19:12:21672WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31673 return view_.get();
674}
675
[email protected]95640212014-07-26 18:14:30676void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
677 if (mode == accessibility_mode_)
678 return;
679
680 accessibility_mode_ = mode;
681 frame_tree_.ForEach(
682 base::Bind(&ForEachFrameInternal,
683 base::Bind(&SetAccessibilityModeOnFrame, mode)));
684 frame_tree_.ForEach(
685 base::Bind(&ForEachPendingFrameInternal,
686 base::Bind(&SetAccessibilityModeOnFrame, mode)));
687}
688
689void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50690 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30691}
692
693void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50694 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30695}
696
zhenw1f790352014-10-30 00:06:04697void WebContentsImpl::ClearNavigationTransitionData() {
698 FrameTreeNode* node = frame_tree_.root();
699 node->render_manager()->ClearNavigationTransitionData();
700}
701
[email protected]8ff00d72012-10-23 19:12:21702WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56703 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03704 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
705 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22706 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58707 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22708 web_ui->SetController(controller);
709 return web_ui;
710 }
711
712 delete web_ui;
713 return NULL;
714}
715
[email protected]8ff00d72012-10-23 19:12:21716WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21717 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
718 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31719}
720
[email protected]8ff00d72012-10-23 19:12:21721WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21722 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34723}
724
[email protected]86ef6a392012-05-11 22:03:11725void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22726 if (GetUserAgentOverride() == override)
727 return;
728
729 renderer_preferences_.user_agent_override = override;
730
731 // Send the new override string to the renderer.
732 RenderViewHost* host = GetRenderViewHost();
733 if (host)
734 host->SyncRendererPrefs();
735
736 // Reload the page if a load is currently in progress to avoid having
737 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27738 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22739 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
740 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53741
742 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
743 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11744}
745
746const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22747 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11748}
749
[email protected]95640212014-07-26 18:14:30750void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
751 AddAccessibilityMode(AccessibilityModeTreeOnly);
752}
753
754bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
755 return accessibility_mode_ == AccessibilityModeTreeOnly;
756}
757
758bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
759 return accessibility_mode_ == AccessibilityModeComplete;
760}
761
[email protected]2ceee8f2014-01-14 18:02:08762#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41763void WebContentsImpl::SetParentNativeViewAccessible(
764gfx::NativeViewAccessible accessible_parent) {
765 accessible_parent_ = accessible_parent;
[email protected]95640212014-07-26 18:14:30766 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
767 if (rfh)
768 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41769}
770#endif
771
[email protected]fcf75d42013-12-03 20:11:26772const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55773 // Transient entries take precedence. They are used for interstitial pages
774 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23775 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08776 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21777 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30778 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23779 if (entry) {
[email protected]b5cca982011-05-26 04:42:08780 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23781 }
[email protected]fa944cb82013-11-15 17:51:21782 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
783 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58784 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54785 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32786 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54787 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35788 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26789 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54790 if (!title.empty())
791 return title;
792 }
793 }
794
795 // We use the title for the last committed entry rather than a pending
796 // navigation entry. For example, when the user types in a URL, we want to
797 // keep the old page's title until the new load has committed and we get a new
798 // title.
[email protected]96d185d2009-04-24 03:28:54799 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32800
[email protected]9eeafc012013-11-25 23:49:47801 // We make an exception for initial navigations.
802 if (controller_.IsInitialNavigation()) {
803 // We only want to use the title from the visible entry in one of two cases:
804 // 1. There's already a committed entry for an initial navigation, in which
805 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
806 // 2. The pending entry has been explicitly assigned a title to display.
807 //
808 // If there's no last committed entry and no assigned title, we should fall
809 // back to |page_title_when_no_navigation_entry_| rather than showing the
810 // URL.
811 if (entry ||
812 (controller_.GetVisibleEntry() &&
813 !controller_.GetVisibleEntry()->GetTitle().empty())) {
814 entry = controller_.GetVisibleEntry();
815 }
816 }
[email protected]59167c22013-06-03 18:07:32817
[email protected]45d0ef7f2011-01-05 13:46:23818 if (entry) {
[email protected]b5cca982011-05-26 04:42:08819 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23820 }
[email protected]987fc3a2011-05-26 14:18:09821
822 // |page_title_when_no_navigation_entry_| is finally used
823 // if no title cannot be retrieved.
824 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54825}
826
[email protected]b172aee2012-04-10 17:05:26827int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46828 return GetMaxPageIDForSiteInstance(GetSiteInstance());
829}
830
[email protected]b172aee2012-04-10 17:05:26831int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
832 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33833 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
834 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46835
[email protected]b6583592012-01-25 19:52:33836 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34837}
838
[email protected]b172aee2012-04-10 17:05:26839void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46840 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
841}
842
[email protected]b172aee2012-04-10 17:05:26843void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33844 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46845 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33846 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34847}
848
[email protected]ec6c05f2013-10-23 18:41:57849void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
850 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
851 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57852}
853
creiscce56cd2014-09-29 22:45:22854SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21855 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54856}
857
creiscce56cd2014-09-29 22:45:22858SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
859 RenderViewHostImpl* dest_rvh =
860 GetRenderManager()->pending_render_view_host() ?
861 GetRenderManager()->pending_render_view_host() :
862 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58863 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38864}
865
[email protected]b172aee2012-04-10 17:05:26866bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31867 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49868}
869
[email protected]6dfed692014-05-22 04:18:03870bool WebContentsImpl::IsLoadingToDifferentDocument() const {
871 return is_loading_ && is_load_to_different_document_;
872}
873
[email protected]b172aee2012-04-10 17:05:26874bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03875 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31876}
877
[email protected]b172aee2012-04-10 17:05:26878const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31879 return load_state_;
880}
881
[email protected]fcf75d42013-12-03 20:11:26882const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31883 return load_state_host_;
884}
885
[email protected]b172aee2012-04-10 17:05:26886uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31887 return upload_size_;
888}
889
[email protected]b172aee2012-04-10 17:05:26890uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31891 return upload_position_;
892}
893
[email protected]1ae93fb2013-06-14 03:38:56894std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56895 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39896 frame_tree_.ForEach(base::Bind(&CollectSites,
897 base::Unretained(GetBrowserContext()),
898 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56899 return sites;
900}
901
[email protected]b172aee2012-04-10 17:05:26902const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54903 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31904}
905
[email protected]b172aee2012-04-10 17:05:26906bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31907 return displayed_insecure_content_;
908}
909
[email protected]222f5822014-02-05 23:40:49910void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25911 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55912 ++capturer_count_;
913 DVLOG(1) << "There are now " << capturer_count_
914 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49915
916 // Note: This provides a hint to upstream code to size the views optimally
917 // for quality (e.g., to avoid scaling).
918 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
919 preferred_size_for_capture_ = capture_size;
920 OnPreferredSizeChanged(preferred_size_);
921 }
[email protected]54597982013-02-06 01:59:55922}
923
924void WebContentsImpl::DecrementCapturerCount() {
925 --capturer_count_;
926 DVLOG(1) << "There are now " << capturer_count_
927 << " capturing(s) of WebContentsImpl@" << this;
928 DCHECK_LE(0, capturer_count_);
929
[email protected]5a652232013-02-12 06:15:25930 if (is_being_destroyed_)
931 return;
932
[email protected]222f5822014-02-05 23:40:49933 if (capturer_count_ == 0) {
934 const gfx::Size old_size = preferred_size_for_capture_;
935 preferred_size_for_capture_ = gfx::Size();
936 OnPreferredSizeChanged(old_size);
937 }
938
[email protected]1ac10dca2013-08-20 20:47:04939 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55940 DVLOG(1) << "Executing delayed WasHidden().";
941 WasHidden();
942 }
[email protected]be1f56ab2011-12-22 06:55:31943}
944
[email protected]f2bd40812013-07-20 04:30:44945int WebContentsImpl::GetCapturerCount() const {
946 return capturer_count_;
947}
948
miu50f97892014-09-22 22:49:52949bool WebContentsImpl::IsAudioMuted() const {
950 return audio_muter_.get() && audio_muter_->is_muting();
951}
952
953void WebContentsImpl::SetAudioMuted(bool mute) {
954 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
955 << " for WebContentsImpl@" << this;
956
957 if (mute == IsAudioMuted())
958 return;
959
960 if (mute) {
961 if (!audio_muter_)
962 audio_muter_.reset(new WebContentsAudioMuter(this));
963 audio_muter_->StartMuting();
964 } else {
965 DCHECK(audio_muter_);
966 audio_muter_->StopMuting();
967 }
968
969 // Notification for UI updates in response to the changed muting state.
970 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
971}
972
[email protected]b172aee2012-04-10 17:05:26973bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31974 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
975 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
976 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49977}
978
[email protected]b172aee2012-04-10 17:05:26979void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
980 int error_code) {
[email protected]443b80e2010-12-14 00:42:23981 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34982 return;
983
[email protected]443b80e2010-12-14 00:42:23984 crashed_status_ = status;
985 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21986 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34987}
988
[email protected]b172aee2012-04-10 17:05:26989base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31990 return crashed_status_;
991}
992
[email protected]b172aee2012-04-10 17:05:26993bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31994 return is_being_destroyed_;
995}
996
[email protected]7f924832014-08-09 05:57:22997void WebContentsImpl::NotifyNavigationStateChanged(
998 InvalidateTypes changed_flags) {
dalecurtisbc6572e12014-09-12 19:22:30999 // Create and release the audio power save blocker depending on whether the
1000 // tab is actively producing audio or not.
1001 if (changed_flags == INVALIDATE_TYPE_TAB &&
1002 AudioStreamMonitor::monitoring_available()) {
1003 if (WasRecentlyAudible()) {
1004 if (!audio_power_save_blocker_)
1005 CreateAudioPowerSaveBlocker();
1006 } else {
1007 audio_power_save_blocker_.reset();
1008 }
1009 }
1010
[email protected]d5f942ba2008-09-26 19:30:341011 if (delegate_)
1012 delegate_->NavigationStateChanged(this, changed_flags);
1013}
1014
[email protected]9a890452014-02-13 22:21:021015base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1016 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331017}
1018
[email protected]9e2e4632012-07-27 16:38:411019void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541020 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591021
[email protected]948481d2014-06-11 18:32:221022 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1023 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591024 iter != widgets.end();
1025 iter++) {
[email protected]948481d2014-06-11 18:32:221026 if (*iter) {
1027 (*iter)->Show();
[email protected]789e9152009-08-04 21:59:431028#if defined(OS_MACOSX)
[email protected]948481d2014-06-11 18:32:221029 (*iter)->SetActive(true);
[email protected]789e9152009-08-04 21:59:431030#endif
[email protected]de3c5d82014-05-28 22:12:591031 }
[email protected]789e9152009-08-04 21:59:431032 }
[email protected]96d185d2009-04-24 03:28:541033
[email protected]9a890452014-02-13 22:21:021034 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381035
[email protected]b9769d82012-02-10 00:23:591036 // The resize rect might have changed while this was inactive -- send the new
1037 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581038 RenderViewHostImpl* rvh =
1039 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591040 if (rvh) {
1041 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1042 }
[email protected]96d185d2009-04-24 03:28:541043
dalecurtisbc6572e12014-09-12 19:22:301044 // Restore power save blocker if there are active video players running.
1045 if (!active_video_players_.empty() && !video_power_save_blocker_)
1046 CreateVideoPowerSaveBlocker();
1047
[email protected]c0d9d5672013-10-09 07:38:031048 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1049
[email protected]54597982013-02-06 01:59:551050 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311051}
1052
[email protected]b172aee2012-04-10 17:05:261053void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551054 // If there are entities capturing screenshots or video (e.g., mirroring),
1055 // don't activate the "disable rendering" optimization.
1056 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521057 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551058 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261059 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521060 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331061 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521062 // calls us).
[email protected]948481d2014-06-11 18:32:221063 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1064 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591065 iter != widgets.end();
1066 iter++) {
[email protected]948481d2014-06-11 18:32:221067 if (*iter)
1068 (*iter)->Hide();
[email protected]de3c5d82014-05-28 22:12:591069 }
dalecurtisbc6572e12014-09-12 19:22:301070
1071 // Release any video power save blockers held as video is not visible.
1072 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541073 }
1074
[email protected]c0d9d5672013-10-09 07:38:031075 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1076
[email protected]54597982013-02-06 01:59:551077 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371078}
1079
[email protected]b172aee2012-04-10 17:05:261080bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311081 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271082 return WillNotifyDisconnection() &&
1083 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581084 !static_cast<RenderViewHostImpl*>(
1085 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311086}
1087
[email protected]1c3f80bd2014-04-08 23:02:061088void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1089 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1090 for_cross_site_transition);
1091}
1092
[email protected]b172aee2012-04-10 17:05:261093void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211094 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401095 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271096}
1097
[email protected]b172aee2012-04-10 17:05:261098WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441099 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451100 // We pass our own opener so that the cloned page can access it if it was
1101 // before.
[email protected]54944cde2012-12-09 09:24:591102 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451103 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591104 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191105 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221106 FOR_EACH_OBSERVER(WebContentsObserver,
1107 observers_,
1108 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271109 return tc;
1110}
1111
[email protected]14392a52012-05-02 20:28:441112void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211113 const NotificationSource& source,
1114 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441115 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211116 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1117 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031118 RenderWidgetHostView* view = host->GetView();
1119 if (view == GetFullscreenRenderWidgetHostView()) {
1120 // We cannot just call view_->RestoreFocus() here. On some platforms,
1121 // attempting to focus the currently-invisible WebContentsView will be
1122 // flat-out ignored. Therefore, this boolean is used to track whether
1123 // we will request focus after the fullscreen widget has been
1124 // destroyed.
1125 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1126 } else {
1127 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1128 i != pending_widget_views_.end(); ++i) {
1129 if (host->GetView() == i->second) {
1130 pending_widget_views_.erase(i);
1131 break;
1132 }
[email protected]bafe6cd2012-05-23 23:09:501133 }
1134 }
1135 break;
1136 }
[email protected]14392a52012-05-02 20:28:441137 default:
1138 NOTREACHED();
1139 }
1140}
1141
[email protected]ec6c05f2013-10-23 18:41:571142WebContents* WebContentsImpl::GetWebContents() {
1143 return this;
1144}
1145
[email protected]54944cde2012-12-09 09:24:591146void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211147 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361148 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211149 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431150 should_normally_be_visible_ = !params.initially_hidden;
1151
[email protected]fa944cb82013-11-15 17:51:211152 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041153 params.browser_context, params.site_instance, params.routing_id,
1154 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191155
[email protected]fc2b46b2014-05-03 16:33:451156 WebContentsViewDelegate* delegate =
1157 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1158
1159 if (browser_plugin_guest_) {
1160 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1161 this, delegate, &render_view_host_delegate_view_));
1162
1163 WebContentsViewGuest* rv = new WebContentsViewGuest(
1164 this, browser_plugin_guest_.get(), platform_view.Pass(),
1165 render_view_host_delegate_view_);
1166 render_view_host_delegate_view_ = rv;
1167 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191168 } else {
[email protected]fc2b46b2014-05-03 16:33:451169 // Regular WebContentsView.
1170 view_.reset(CreateWebContentsView(
1171 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191172 }
[email protected]fc2b46b2014-05-03 16:33:451173 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191174 CHECK(view_.get());
1175
[email protected]ed245db2012-12-18 08:00:451176 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591177 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191178
1179 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101180 if (opener_)
1181 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191182
tommyclieb25b2a2014-11-03 19:45:091183#if defined(ENABLE_PLUGINS)
1184 plugin_content_origin_whitelist_.reset(
1185 new PluginContentOriginWhitelist(this));
1186#endif
1187
[email protected]d1198fd2012-08-13 22:50:191188 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211189 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1190 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101191
[email protected]29998f92014-06-15 03:12:141192 midi_dispatcher_host_.reset(new MidiDispatcherHost(this));
[email protected]f28ef9a32014-05-12 16:36:101193
[email protected]01f83f92014-06-17 14:41:541194 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091195 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541196
mlamouriefdca9d2014-09-16 16:55:401197 manifest_manager_host_.reset(new ManifestManagerHost(this));
1198
[email protected]c7654a232013-06-12 21:04:441199#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101200 date_time_chooser_.reset(new DateTimeChooserAndroid());
1201#endif
[email protected]d1198fd2012-08-13 22:50:191202}
1203
[email protected]7fff43e2013-05-21 20:21:101204void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1205 RemoveDestructionObserver(web_contents);
1206
[email protected]14392a52012-05-02 20:28:441207 // Clear the opener if it has been closed.
1208 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441209 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511210 return;
[email protected]14392a52012-05-02 20:28:441211 }
[email protected]ceee8cd2013-03-08 04:59:511212 // Clear a pending contents that has been closed before being shown.
1213 for (PendingContents::iterator iter = pending_contents_.begin();
1214 iter != pending_contents_.end();
1215 ++iter) {
1216 if (iter->second != web_contents)
1217 continue;
1218 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511219 return;
1220 }
1221 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441222}
1223
[email protected]7fff43e2013-05-21 20:21:101224void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1225 if (!ContainsKey(destruction_observers_, web_contents)) {
1226 destruction_observers_[web_contents] =
1227 new DestructionObserver(this, web_contents);
1228 }
1229}
1230
1231void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1232 DestructionObservers::iterator iter =
1233 destruction_observers_.find(web_contents);
1234 if (iter != destruction_observers_.end()) {
1235 delete destruction_observers_[web_contents];
1236 destruction_observers_.erase(iter);
1237 }
1238}
1239
[email protected]b172aee2012-04-10 17:05:261240void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311241 observers_.AddObserver(observer);
1242}
1243
[email protected]b172aee2012-04-10 17:05:261244void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311245 observers_.RemoveObserver(observer);
1246}
1247
[email protected]948481d2014-06-11 18:32:221248std::set<RenderWidgetHostView*>
1249WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1250 std::set<RenderWidgetHostView*> set;
1251 if (ShowingInterstitialPage()) {
1252 set.insert(GetRenderWidgetHostView());
1253 } else {
1254 ForEachFrame(
1255 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1256 }
[email protected]de3c5d82014-05-28 22:12:591257 return set;
1258}
1259
[email protected]b172aee2012-04-10 17:05:261260void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341261 if (delegate_)
1262 delegate_->ActivateContents(this);
1263}
1264
[email protected]b172aee2012-04-10 17:05:261265void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121266 if (delegate_)
1267 delegate_->DeactivateContents(this);
1268}
1269
[email protected]b172aee2012-04-10 17:05:261270void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481271 if (delegate_)
1272 delegate_->LostCapture();
1273}
1274
[email protected]b24b68a2012-09-24 21:57:261275void WebContentsImpl::RenderWidgetDeleted(
1276 RenderWidgetHostImpl* render_widget_host) {
1277 if (is_being_destroyed_) {
1278 // |created_widgets_| might have been destroyed.
1279 return;
1280 }
1281
1282 std::set<RenderWidgetHostImpl*>::iterator iter =
1283 created_widgets_.find(render_widget_host);
1284 if (iter != created_widgets_.end())
1285 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541286
1287 if (render_widget_host &&
1288 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491289 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1290 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541291 FOR_EACH_OBSERVER(WebContentsObserver,
1292 observers_,
1293 DidDestroyFullscreenWidget(
1294 fullscreen_widget_routing_id_));
1295 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031296 if (fullscreen_widget_had_focus_at_shutdown_)
1297 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541298 }
[email protected]b24b68a2012-09-24 21:57:261299}
1300
miu9e14e492014-10-25 02:39:041301void WebContentsImpl::RenderWidgetGotFocus(
1302 RenderWidgetHostImpl* render_widget_host) {
1303 // Notify the delegate if an embedded fullscreen widget was focused.
1304 if (delegate_ && render_widget_host &&
1305 delegate_->EmbedsFullscreenWidget() &&
1306 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1307 delegate_->WebContentsFocused(this);
1308}
1309
[email protected]b172aee2012-04-10 17:05:261310bool WebContentsImpl::PreHandleKeyboardEvent(
1311 const NativeWebKeyboardEvent& event,
1312 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481313 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131314 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481315}
1316
[email protected]b172aee2012-04-10 17:05:261317void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101318 if (browser_plugin_embedder_ &&
1319 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1320 return;
1321 }
[email protected]63954792011-07-11 04:17:481322 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131323 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481324}
1325
[email protected]d92026ef2014-03-03 21:04:131326bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461327 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191328#if !defined(OS_MACOSX)
1329 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1330 // isn't done for two reasons:
1331 // -the OS already has a gesture to do this through pinch-zoom
1332 // -if a user starts an inertial scroll, let's go, and presses control
1333 // (i.e. control+tab) then the OS's buffered scroll events will come in
1334 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521335 if (delegate_ &&
1336 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551337 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1338 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1339 // gestures, which are regrettably easy to trigger accidentally.
1340 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521341 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1342 return true;
1343 }
[email protected]bccc4472013-04-18 16:37:191344#endif
[email protected]fb3f066e2013-02-12 19:12:521345 return false;
1346}
1347
[email protected]04bce562014-01-30 05:34:541348bool WebContentsImpl::PreHandleGestureEvent(
1349 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031350 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541351}
1352
[email protected]bab38af2014-03-30 17:37:291353bool WebContentsImpl::HandleGestureEvent(
1354 const blink::WebGestureEvent& event) {
1355 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1356 // Use them to implement browser zoom, as for HandleWheelEvent above.
1357 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331358 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291359 // The scale difference necessary to trigger a zoom action. Derived from
1360 // experimentation to find a value that feels reasonable.
1361 const float kZoomStepValue = 0.6f;
1362
1363 // Find the (absolute) thresholds on either side of the current zoom factor,
1364 // then convert those to actual numbers to trigger a zoom in or out.
1365 // This logic deliberately makes the range around the starting zoom value
1366 // for the gesture twice as large as the other ranges (i.e., the notches are
1367 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1368 // so that it's easier to get back to your starting point than it is to
1369 // overshoot.
1370 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1371 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1372 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1373 : -backStep;
1374 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1375 : backStep;
1376
[email protected]fb546cb2014-04-28 14:09:371377 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291378 if (totalPinchGestureAmount_ > zoomInThreshold) {
1379 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461380 if (delegate_)
1381 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291382 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1383 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461384 if (delegate_)
1385 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291386 }
1387 return true;
1388 }
1389
1390 return false;
1391}
1392
[email protected]b172aee2012-04-10 17:05:261393void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431394 if (delegate_)
1395 delegate_->HandleMouseDown();
1396}
1397
[email protected]b172aee2012-04-10 17:05:261398void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481399 if (delegate_)
1400 delegate_->HandleMouseUp();
1401}
1402
[email protected]590a634e2012-07-19 16:38:231403void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481404 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231405 delegate_->HandlePointerActivate();
1406}
1407
1408void WebContentsImpl::HandleGestureBegin() {
1409 if (delegate_)
1410 delegate_->HandleGestureBegin();
1411}
1412
1413void WebContentsImpl::HandleGestureEnd() {
1414 if (delegate_)
1415 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481416}
1417
[email protected]b172aee2012-04-10 17:05:261418void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491419 // This method is being called to enter or leave renderer-initiated fullscreen
1420 // mode. Either way, make sure any existing fullscreen widget is shut down
1421 // first.
1422 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1423 if (widget_view)
1424 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1425
[email protected]8a5e0ca2011-08-25 06:30:471426 if (delegate_)
1427 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371428
1429 FOR_EACH_OBSERVER(WebContentsObserver,
1430 observers_,
1431 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471432}
1433
[email protected]b172aee2012-04-10 17:05:261434bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381435 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121436}
1437
[email protected]a9c81f02012-06-01 00:15:441438void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1439 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371440 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441441 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371442 } else {
1443 GotResponseToLockMouseRequest(false);
1444 }
1445}
1446
[email protected]b172aee2012-04-10 17:05:261447void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371448 if (delegate_)
1449 delegate_->LostMouseLock();
1450}
1451
[email protected]bafe6cd2012-05-23 23:09:501452void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201453 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501454 int route_id,
[email protected]227692c52013-05-31 22:43:041455 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131456 const ViewHostMsg_CreateWindow_Params& params,
1457 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501458 // We usually create the new window in the same BrowsingInstance (group of
1459 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551460 // if the opener is being suppressed (in a non-guest), we create a new
1461 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251462 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551463
[email protected]04cbd3d2013-12-04 04:58:201464 // If the opener is to be suppressed, the new window can be in any process.
1465 // Since routing ids are process specific, we must not have one passed in
1466 // as argument here.
1467 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1468
[email protected]bafe6cd2012-05-23 23:09:501469 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551470 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571471 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501472 GetSiteInstance();
1473
[email protected]04cbd3d2013-12-04 04:58:201474 // A message to create a new window can only come from the active process for
1475 // this WebContentsImpl instance. If any other process sends the request,
1476 // it is invalid and the process must be terminated.
1477 if (GetRenderProcessHost()->GetID() != render_process_id) {
1478 base::ProcessHandle process_handle =
1479 RenderProcessHost::FromID(render_process_id)->GetHandle();
1480 if (process_handle != base::kNullProcessHandle) {
1481 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391482 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
thestigc4cac8f2014-09-04 21:17:501483 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201484 }
1485 return;
1486 }
1487
[email protected]d1198fd2012-08-13 22:50:191488 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341489 //
1490 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301491 const std::string& partition_id =
1492 GetContentClient()->browser()->
1493 GetStoragePartitionIdForSite(GetBrowserContext(),
1494 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461495 StoragePartition* partition = BrowserContext::GetStoragePartition(
1496 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411497 DOMStorageContextWrapper* dom_storage_context =
1498 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191499 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1500 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1501 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371502
1503 if (delegate_ &&
1504 !delegate_->ShouldCreateWebContents(this,
1505 route_id,
1506 params.window_container_type,
1507 params.frame_name,
1508 params.target_url,
1509 partition_id,
1510 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011511 if (route_id != MSG_ROUTING_NONE &&
1512 !RenderViewHost::FromID(render_process_id, route_id)) {
1513 // If the embedder didn't create a WebContents for this route, we need to
1514 // delete the RenderView that had already been created.
1515 Send(new ViewMsg_Close(route_id));
1516 }
[email protected]dd6730412013-08-14 15:03:371517 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1518 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1519 main_frame_route_id);
1520 return;
1521 }
1522
1523 // Create the new web contents. This will automatically create the new
1524 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461525 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591526 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041527 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061528 create_params.opener = this;
1529 create_params.opener_suppressed = params.opener_suppressed;
1530 if (params.disposition == NEW_BACKGROUND_TAB)
1531 create_params.initially_hidden = true;
1532
[email protected]4858e432014-06-23 18:14:171533 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551534 if (!is_guest) {
1535 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451536 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171537 new_contents = static_cast<WebContentsImpl*>(
1538 WebContents::Create(create_params));
1539 } else {
1540 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551541 }
[email protected]50d326e2014-05-20 17:59:061542 new_contents->GetController().SetSessionStorageNamespace(
1543 partition_id,
1544 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261545 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191546
[email protected]c4538072013-03-18 02:17:551547 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341548 // will be shown immediately).
1549 if (!params.opener_suppressed) {
1550 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451551 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501552
[email protected]d70bea92013-04-05 04:23:341553 // TODO(brettw): It seems bogus that we have to call this function on the
1554 // newly created object and give it one of its own member variables.
lazyboy549b3b42014-10-20 17:16:041555 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false);
[email protected]d70bea92013-04-05 04:23:341556 }
[email protected]bafe6cd2012-05-23 23:09:501557 // Save the created window associated with the route so we can show it
1558 // later.
1559 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1560 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101561 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501562 }
1563
1564 if (delegate_) {
1565 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071566 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131567 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501568 }
1569
1570 if (params.opener_suppressed) {
1571 // When the opener is suppressed, the original renderer cannot access the
1572 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001573 bool was_blocked = false;
1574 if (delegate_) {
1575 gfx::Rect initial_pos;
1576 delegate_->AddNewContents(
1577 this, new_contents, params.disposition, initial_pos,
1578 params.user_gesture, &was_blocked);
1579 }
1580 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211581 OpenURLParams open_params(params.target_url,
1582 Referrer(),
1583 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351584 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211585 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301586 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001587 new_contents->OpenURL(open_params);
1588 }
[email protected]bafe6cd2012-05-23 23:09:501589 }
1590}
1591
[email protected]a8504022013-12-04 20:23:511592void WebContentsImpl::CreateNewWidget(int render_process_id,
1593 int route_id,
[email protected]180ef242013-11-07 06:50:461594 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511595 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501596}
1597
[email protected]a8504022013-12-04 20:23:511598void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1599 int route_id) {
1600 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501601}
1602
[email protected]a8504022013-12-04 20:23:511603void WebContentsImpl::CreateNewWidget(int render_process_id,
1604 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501605 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461606 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211607 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511608 // A message to create a new widget can only come from the active process for
1609 // this WebContentsImpl instance. If any other process sends the request,
1610 // it is invalid and the process must be terminated.
1611 if (process->GetID() != render_process_id) {
1612 base::ProcessHandle process_handle =
1613 RenderProcessHost::FromID(render_process_id)->GetHandle();
1614 if (process_handle != base::kNullProcessHandle) {
1615 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391616 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
thestigc4cac8f2014-09-04 21:17:501617 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511618 }
1619 return;
1620 }
1621
[email protected]bafe6cd2012-05-23 23:09:501622 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041623 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261624 created_widgets_.insert(widget_host);
1625
[email protected]cfd80b02014-05-01 17:46:481626 RenderWidgetHostViewBase* widget_view =
1627 static_cast<RenderWidgetHostViewBase*>(
1628 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191629 if (!widget_view)
1630 return;
[email protected]bafe6cd2012-05-23 23:09:501631 if (!is_fullscreen) {
1632 // Popups should not get activated.
1633 widget_view->SetPopupType(popup_type);
1634 }
1635 // Save the created widget associated with the route so we can show it later.
1636 pending_widget_views_[route_id] = widget_view;
1637
1638#if defined(OS_MACOSX)
1639 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1640 // to allow it to survive the trip without being hosted.
1641 base::mac::NSObjectRetain(widget_view->GetNativeView());
1642#endif
1643}
1644
1645void WebContentsImpl::ShowCreatedWindow(int route_id,
1646 WindowOpenDisposition disposition,
1647 const gfx::Rect& initial_pos,
1648 bool user_gesture) {
1649 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001650 if (contents) {
1651 WebContentsDelegate* delegate = GetDelegate();
1652 if (delegate) {
1653 delegate->AddNewContents(
1654 this, contents, disposition, initial_pos, user_gesture, NULL);
1655 }
1656 }
[email protected]bafe6cd2012-05-23 23:09:501657}
1658
1659void WebContentsImpl::ShowCreatedWidget(int route_id,
1660 const gfx::Rect& initial_pos) {
1661 ShowCreatedWidget(route_id, false, initial_pos);
1662}
1663
1664void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1665 ShowCreatedWidget(route_id, true, gfx::Rect());
1666}
1667
1668void WebContentsImpl::ShowCreatedWidget(int route_id,
1669 bool is_fullscreen,
1670 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481671 RenderWidgetHostViewBase* widget_host_view =
1672 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501673 if (!widget_host_view)
1674 return;
[email protected]cfd80b02014-05-01 17:46:481675
1676 RenderWidgetHostView* view = NULL;
1677 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1678 if (guest && guest->embedder_web_contents()) {
1679 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1680 } else {
1681 view = GetRenderWidgetHostView();
1682 }
1683
[email protected]4aebbca2013-09-17 22:26:491684 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311685 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031686 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311687 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491688 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1689 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1690 delegate_->ToggleFullscreenModeForTab(this, true);
1691 } else {
[email protected]cfd80b02014-05-01 17:46:481692 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491693 }
[email protected]4aebbca2013-09-17 22:26:491694 FOR_EACH_OBSERVER(WebContentsObserver,
1695 observers_,
1696 DidShowFullscreenWidget(route_id));
1697 if (!widget_host_view->HasFocus())
1698 widget_host_view->Focus();
1699 } else {
[email protected]cfd80b02014-05-01 17:46:481700 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491701 }
[email protected]89054502012-06-03 10:29:241702
1703 RenderWidgetHostImpl* render_widget_host_impl =
1704 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1705 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311706 // Only allow privileged mouse lock for fullscreen render widget, which is
1707 // used to implement Pepper Flash fullscreen.
1708 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501709
1710#if defined(OS_MACOSX)
1711 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1712 // properly embedded (or purposefully ignored) we can release the retain we
1713 // took in CreateNewWidget().
1714 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1715#endif
1716}
1717
1718WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1719 PendingContents::iterator iter = pending_contents_.find(route_id);
1720
1721 // Certain systems can block the creation of new windows. If we didn't succeed
1722 // in creating one, just return NULL.
1723 if (iter == pending_contents_.end()) {
1724 return NULL;
1725 }
1726
1727 WebContentsImpl* new_contents = iter->second;
1728 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101729 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501730
[email protected]d70bea92013-04-05 04:23:341731 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251732 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341733 return new_contents;
1734
[email protected]bafe6cd2012-05-23 23:09:501735 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1736 !new_contents->GetRenderViewHost()->GetView())
1737 return NULL;
1738
creis82dd6af2014-09-17 16:30:451739 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501740 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1741 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
creis82dd6af2014-09-17 16:30:451742 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
1743
[email protected]bafe6cd2012-05-23 23:09:501744 return new_contents;
1745}
1746
1747RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1748 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1749 if (iter == pending_widget_views_.end()) {
1750 DCHECK(false);
1751 return NULL;
1752 }
1753
1754 RenderWidgetHostView* widget_host_view = iter->second;
1755 pending_widget_views_.erase(route_id);
1756
1757 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1758 if (!widget_host->GetProcess()->HasConnection()) {
1759 // The view has gone away or the renderer crashed. Nothing to do.
1760 return NULL;
1761 }
1762
1763 return widget_host_view;
1764}
1765
[email protected]f13b4202012-06-12 23:53:231766void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091767 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211768 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371769 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231770 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371771 } else {
1772 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041773 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371774 scoped_ptr<MediaStreamUI>());
1775 }
[email protected]f13b4202012-06-12 23:53:231776}
1777
grunell657d4d82014-09-18 00:09:431778bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1779 MediaStreamType type) {
1780 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1781 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1782 return delegate_ &&
1783 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1784}
1785
[email protected]cc9200432013-07-23 23:02:401786SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1787 SiteInstance* instance) {
1788 return controller_.GetSessionStorageNamespace(instance);
1789}
1790
[email protected]6de7fc482014-06-06 10:46:441791SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1792 return controller_.GetSessionStorageNamespaceMap();
1793}
1794
[email protected]9b159a52013-10-03 17:24:551795FrameTree* WebContentsImpl::GetFrameTree() {
1796 return &frame_tree_;
1797}
1798
lukendc35e7f2014-11-10 19:06:141799void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
1800 virtual_keyboard_requested_ = requested;
1801}
1802
1803bool WebContentsImpl::IsVirtualKeyboardRequested() {
1804 return virtual_keyboard_requested_;
1805}
1806
[email protected]95640212014-07-26 18:14:301807AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1808 return accessibility_mode_;
1809}
1810
[email protected]31a71eaf2014-03-13 01:47:361811void WebContentsImpl::AccessibilityEventReceived(
1812 const std::vector<AXEventNotificationDetails>& details) {
1813 FOR_EACH_OBSERVER(
1814 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1815}
1816
dmazzonia656928e2014-09-15 20:28:541817RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
1818 int browser_plugin_instance_id) {
1819 BrowserPluginGuestManager* guest_manager =
1820 GetBrowserContext()->GetGuestManager();
1821 WebContents* guest = guest_manager->GetGuestByInstanceID(
1822 this, browser_plugin_instance_id);
1823 if (!guest)
1824 return NULL;
1825 return guest->GetMainFrame();
1826}
1827
blundellc57b93f2014-10-29 13:19:571828GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
1829 return geolocation_service_context_.get();
1830}
1831
[email protected]edc3af82013-12-12 21:24:071832void WebContentsImpl::OnShowValidationMessage(
1833 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291834 const base::string16& main_text,
1835 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071836 if (delegate_)
1837 delegate_->ShowValidationMessage(
1838 this, anchor_in_root_view, main_text, sub_text);
1839}
1840
1841void WebContentsImpl::OnHideValidationMessage() {
1842 if (delegate_)
1843 delegate_->HideValidationMessage(this);
1844}
1845
1846void WebContentsImpl::OnMoveValidationMessage(
1847 const gfx::Rect& anchor_in_root_view) {
1848 if (delegate_)
1849 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1850}
1851
[email protected]32deec62013-05-15 23:55:041852void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1853 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441854 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041855}
1856
[email protected]95640212014-07-26 18:14:301857BrowserAccessibilityManager*
1858 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1859 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1860 return rfh ? rfh->browser_accessibility_manager() : NULL;
1861}
1862
1863BrowserAccessibilityManager*
1864 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1865 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1866 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1867}
1868
[email protected]b172aee2012-04-10 17:05:261869void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491870 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231871 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491872 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331873}
1874
[email protected]b172aee2012-04-10 17:05:261875void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341876 if (delegate_)
1877 delegate_->ResizeDueToAutoResize(this, new_size);
1878}
1879
[email protected]b172aee2012-04-10 17:05:261880WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201881 if (!delegate_)
1882 return NULL;
[email protected]00c37fc2011-08-02 00:22:501883
[email protected]e5d549d2011-12-28 01:29:201884 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201885 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341886}
1887
[email protected]6b618e62012-08-16 12:59:181888bool WebContentsImpl::Send(IPC::Message* message) {
1889 if (!GetRenderViewHost()) {
1890 delete message;
1891 return false;
1892 }
1893
1894 return GetRenderViewHost()->Send(message);
1895}
1896
[email protected]b172aee2012-04-10 17:05:261897bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501898 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261899 FrameTreeNode* node = frame_tree_.root();
1900
creise42f2a52014-09-18 18:14:571901 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
1902 // is currently only used in --site-per-process and tests.
[email protected]61ac9e242014-03-21 20:55:261903 NavigationEntryImpl* pending_entry =
1904 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
creise42f2a52014-09-18 18:14:571905 if (pending_entry->frame_tree_node_id() != -1) {
1906 FrameTreeNode* subframe =
1907 frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1908 DCHECK(subframe);
1909 if (subframe)
1910 node = subframe;
[email protected]61ac9e242014-03-21 20:55:261911 }
1912
1913 return node->navigator()->NavigateToPendingEntry(
1914 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541915}
[email protected]96d185d2009-04-24 03:28:541916
[email protected]a86c0e962013-12-17 17:10:391917void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1918 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441919 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391920 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441921}
1922
[email protected]20ca0382013-02-28 19:50:071923void WebContentsImpl::AttachInterstitialPage(
1924 InterstitialPageImpl* interstitial_page) {
1925 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211926 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291927
1928 // Cancel any visible dialogs so that they don't interfere with the
1929 // interstitial.
1930 if (dialog_manager_)
1931 dialog_manager_->CancelActiveAndPendingDialogs(this);
1932
[email protected]20ca0382013-02-28 19:50:071933 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1934 DidAttachInterstitialPage());
1935}
1936
1937void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571938 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211939 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071940 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1941 DidDetachInterstitialPage());
1942}
1943
[email protected]b172aee2012-04-10 17:05:261944void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331945 const SiteInstance* site_instance,
1946 int history_length,
1947 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411948 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1949 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211950 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191951 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141952 return;
[email protected]9e1ad4b2011-08-14 16:49:191953 }
[email protected]9f76c1e2012-03-05 15:15:581954 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191955 if (!rvh) {
1956 NOTREACHED();
1957 return;
1958 }
[email protected]9f76c1e2012-03-05 15:15:581959 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191960 NOTREACHED();
1961 return;
1962 }
[email protected]6b618e62012-08-16 12:59:181963 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1964 history_length,
1965 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141966}
1967
[email protected]4fed3702014-04-01 09:08:001968void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171969 RenderFrameHost* focused_frame = GetFocusedFrame();
1970 if (!focused_frame)
1971 return;
1972
[email protected]959be4c2014-04-08 15:01:331973 focused_frame->Send(new FrameMsg_Reload(
1974 focused_frame->GetRoutingID(), ignore_cache));
1975}
1976
1977void WebContentsImpl::Undo() {
1978 RenderFrameHost* focused_frame = GetFocusedFrame();
1979 if (!focused_frame)
1980 return;
1981
1982 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1983 RecordAction(base::UserMetricsAction("Undo"));
1984}
1985
1986void WebContentsImpl::Redo() {
1987 RenderFrameHost* focused_frame = GetFocusedFrame();
1988 if (!focused_frame)
1989 return;
1990 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1991 RecordAction(base::UserMetricsAction("Redo"));
1992}
1993
1994void WebContentsImpl::Cut() {
1995 RenderFrameHost* focused_frame = GetFocusedFrame();
1996 if (!focused_frame)
1997 return;
1998
1999 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2000 RecordAction(base::UserMetricsAction("Cut"));
2001}
2002
2003void WebContentsImpl::Copy() {
2004 RenderFrameHost* focused_frame = GetFocusedFrame();
2005 if (!focused_frame)
2006 return;
2007
2008 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2009 RecordAction(base::UserMetricsAction("Copy"));
2010}
2011
2012void WebContentsImpl::CopyToFindPboard() {
2013#if defined(OS_MACOSX)
2014 RenderFrameHost* focused_frame = GetFocusedFrame();
2015 if (!focused_frame)
2016 return;
2017
2018 // Windows/Linux don't have the concept of a find pasteboard.
2019 focused_frame->Send(
2020 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2021 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2022#endif
2023}
2024
2025void WebContentsImpl::Paste() {
2026 RenderFrameHost* focused_frame = GetFocusedFrame();
2027 if (!focused_frame)
2028 return;
2029
2030 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2031 RecordAction(base::UserMetricsAction("Paste"));
2032}
2033
2034void WebContentsImpl::PasteAndMatchStyle() {
2035 RenderFrameHost* focused_frame = GetFocusedFrame();
2036 if (!focused_frame)
2037 return;
2038
2039 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2040 focused_frame->GetRoutingID()));
2041 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2042}
2043
2044void WebContentsImpl::Delete() {
2045 RenderFrameHost* focused_frame = GetFocusedFrame();
2046 if (!focused_frame)
2047 return;
2048
2049 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2050 RecordAction(base::UserMetricsAction("DeleteSelection"));
2051}
2052
2053void WebContentsImpl::SelectAll() {
2054 RenderFrameHost* focused_frame = GetFocusedFrame();
2055 if (!focused_frame)
2056 return;
2057
2058 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2059 RecordAction(base::UserMetricsAction("SelectAll"));
2060}
2061
2062void WebContentsImpl::Unselect() {
2063 RenderFrameHost* focused_frame = GetFocusedFrame();
2064 if (!focused_frame)
2065 return;
2066
2067 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2068 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172069}
2070
2071void WebContentsImpl::Replace(const base::string16& word) {
2072 RenderFrameHost* focused_frame = GetFocusedFrame();
2073 if (!focused_frame)
2074 return;
2075
[email protected]959be4c2014-04-08 15:01:332076 focused_frame->Send(new InputMsg_Replace(
2077 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172078}
2079
2080void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2081 RenderFrameHost* focused_frame = GetFocusedFrame();
2082 if (!focused_frame)
2083 return;
2084
[email protected]959be4c2014-04-08 15:01:332085 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2086 focused_frame->GetRoutingID(), word));
2087}
2088
2089void WebContentsImpl::NotifyContextMenuClosed(
2090 const CustomContextMenuContext& context) {
2091 RenderFrameHost* focused_frame = GetFocusedFrame();
2092 if (!focused_frame)
2093 return;
2094
2095 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2096 focused_frame->GetRoutingID(), context));
2097}
2098
2099void WebContentsImpl::ExecuteCustomContextMenuCommand(
2100 int action, const CustomContextMenuContext& context) {
2101 RenderFrameHost* focused_frame = GetFocusedFrame();
2102 if (!focused_frame)
2103 return;
2104
2105 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2106 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002107}
2108
[email protected]fc2b46b2014-05-03 16:33:452109gfx::NativeView WebContentsImpl::GetNativeView() {
2110 return view_->GetNativeView();
2111}
2112
2113gfx::NativeView WebContentsImpl::GetContentNativeView() {
2114 return view_->GetContentNativeView();
2115}
2116
2117gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2118 return view_->GetTopLevelNativeWindow();
2119}
2120
2121gfx::Rect WebContentsImpl::GetViewBounds() {
2122 return view_->GetViewBounds();
2123}
2124
2125gfx::Rect WebContentsImpl::GetContainerBounds() {
2126 gfx::Rect rv;
2127 view_->GetContainerBounds(&rv);
2128 return rv;
2129}
2130
2131DropData* WebContentsImpl::GetDropData() {
2132 return view_->GetDropData();
2133}
2134
2135void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042136 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452137}
2138
2139void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042140 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452141}
2142
2143void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042144 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452145}
2146
2147void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042148 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452149}
2150
[email protected]b172aee2012-04-10 17:05:262151void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272152 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212153 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542154 return;
2155 }
[email protected]0b431992014-06-24 00:08:032156 RenderWidgetHostView* const fullscreen_view =
2157 GetFullscreenRenderWidgetHostView();
2158 if (fullscreen_view) {
2159 fullscreen_view->Focus();
2160 return;
2161 }
[email protected]9f76c1e2012-03-05 15:15:582162 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542163}
2164
[email protected]b172aee2012-04-10 17:05:262165bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212166 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542167}
2168
[email protected]b172aee2012-04-10 17:05:262169InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212170 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222171}
2172
[email protected]b172aee2012-04-10 17:05:262173bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162174 // WebKit creates Document object when MIME type is application/xhtml+xml,
2175 // so we also support this MIME type.
2176 return contents_mime_type_ == "text/html" ||
2177 contents_mime_type_ == "text/xml" ||
2178 contents_mime_type_ == "application/xhtml+xml" ||
2179 contents_mime_type_ == "text/plain" ||
2180 contents_mime_type_ == "text/css" ||
2181 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2182}
2183
[email protected]b172aee2012-04-10 17:05:262184void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592185 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162186 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552187 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012188 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142189 return;
[email protected]c7dd2f62011-07-18 15:57:592190 }
2191
2192 Stop();
2193
2194 // Create the save package and possibly prompt the user for the name to save
2195 // the page as. The user prompt is an asynchronous operation that runs on
2196 // another thread.
2197 save_package_ = new SavePackage(this);
2198 save_package_->GetSaveInfo();
2199}
2200
2201// Used in automated testing to bypass prompting the user for file names.
2202// Instead, the names and paths are hard coded rather than running them through
2203// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342204bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2205 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212206 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592207 // Stop the page from navigating.
2208 Stop();
2209
2210 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212211 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592212}
2213
[email protected]3c71576ce2013-07-23 02:00:012214void WebContentsImpl::SaveFrame(const GURL& url,
2215 const Referrer& referrer) {
2216 if (!GetURL().is_valid())
2217 return;
sammc92af61552014-11-19 23:27:402218 if (delegate_ && delegate_->SaveFrame(url, referrer))
2219 return;
2220
[email protected]3c71576ce2013-07-23 02:00:012221 bool is_main_frame = (url == GetURL());
2222
2223 DownloadManager* dlm =
2224 BrowserContext::GetDownloadManager(GetBrowserContext());
2225 if (!dlm)
2226 return;
2227 int64 post_id = -1;
2228 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272229 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012230 if (entry)
2231 post_id = entry->GetPostID();
2232 }
2233 scoped_ptr<DownloadUrlParameters> params(
2234 DownloadUrlParameters::FromWebContents(this, url));
2235 params->set_referrer(referrer);
2236 params->set_post_id(post_id);
2237 params->set_prefer_cache(true);
2238 if (post_id >= 0)
2239 params->set_method("POST");
2240 params->set_prompt(true);
2241 dlm->DownloadUrl(params.Pass());
2242}
2243
[email protected]b172aee2012-04-10 17:05:262244void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342245 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482246 const base::Callback<void(int64)>& callback) {
2247 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122248}
2249
[email protected]b172aee2012-04-10 17:05:262250const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272251 return contents_mime_type_;
2252}
2253
[email protected]b172aee2012-04-10 17:05:262254bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272255 return notify_disconnection_;
2256}
2257
[email protected]b172aee2012-04-10 17:05:262258void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312259 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182260 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162261}
2262
[email protected]b172aee2012-04-10 17:05:262263void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542264 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182265 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162266}
2267
[email protected]8ff00d72012-10-23 19:12:212268RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272269 return &renderer_preferences_;
2270}
2271
[email protected]e35ccd52012-05-23 16:22:472272void WebContentsImpl::Close() {
2273 Close(GetRenderViewHost());
2274}
2275
[email protected]cf200a562013-05-03 16:24:292276void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462277 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292278 if (browser_plugin_embedder_.get())
2279 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2280 screen_x, screen_y, operation);
2281 if (GetRenderViewHost())
2282 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2283 screen_x, screen_y, operation);
2284}
2285
[email protected]d60f3702013-12-26 16:30:242286void WebContentsImpl::DidGetResourceResponseStart(
2287 const ResourceRequestDetails& details) {
2288 controller_.ssl_manager()->DidStartResourceResponse(details);
2289
2290 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2291 DidGetResourceResponseStart(details));
2292
2293 // TODO(avi): Remove. http://crbug.com/170921
2294 NotificationService::current()->Notify(
2295 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2296 Source<WebContents>(this),
2297 Details<const ResourceRequestDetails>(&details));
2298}
2299
2300void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462301 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242302 const ResourceRedirectDetails& details) {
2303 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2304
2305 FOR_EACH_OBSERVER(
2306 WebContentsObserver,
2307 observers_,
creis114ca1b2014-11-13 23:51:462308 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242309
2310 // TODO(avi): Remove. http://crbug.com/170921
2311 NotificationService::current()->Notify(
2312 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2313 Source<WebContents>(this),
2314 Details<const ResourceRedirectDetails>(&details));
2315}
2316
[email protected]b172aee2012-04-10 17:05:262317void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522318 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582319 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512320 if (delegate_)
2321 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292322 if (browser_plugin_embedder_.get())
2323 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342324}
2325
[email protected]e35ccd52012-05-23 16:22:472326void WebContentsImpl::UserGestureDone() {
2327 OnUserGesture();
2328}
2329
[email protected]b172aee2012-04-10 17:05:262330void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272331 closed_by_user_gesture_ = value;
2332}
2333
[email protected]b172aee2012-04-10 17:05:262334bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272335 return closed_by_user_gesture_;
2336}
2337
[email protected]b172aee2012-04-10 17:05:262338void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502339 if (!delegate_)
2340 return;
2341
[email protected]6286a372013-10-09 04:03:272342 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2343 if (!entry)
[email protected]1788e772010-12-15 16:40:502344 return;
2345
[email protected]6286a372013-10-09 04:03:272346 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122347}
2348
[email protected]b172aee2012-04-10 17:05:262349void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042350 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272351 if (!delegate_)
2352 return;
2353
[email protected]691aa2f2013-05-28 22:52:042354 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272355}
2356
[email protected]b172aee2012-04-10 17:05:262357int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272358 return minimum_zoom_percent_;
2359}
2360
[email protected]b172aee2012-04-10 17:05:262361int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272362 return maximum_zoom_percent_;
2363}
2364
[email protected]b172aee2012-04-10 17:05:262365gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492366 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232367}
2368
[email protected]b172aee2012-04-10 17:05:262369bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052370 if (GetBrowserPluginGuest())
2371 return GetBrowserPluginGuest()->LockMouse(allowed);
2372
[email protected]0bfbf882011-12-22 18:19:272373 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582374 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272375}
2376
[email protected]b172aee2012-04-10 17:05:262377bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442378 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502379}
2380
[email protected]cb805452013-05-22 15:16:212381void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482382 if (!color_chooser_info_.get())
2383 return;
2384 RenderFrameHost* rfh = RenderFrameHost::FromID(
2385 color_chooser_info_->render_process_id,
2386 color_chooser_info_->render_frame_id);
2387 if (!rfh)
2388 return;
2389
2390 rfh->Send(new FrameMsg_DidChooseColorResponse(
2391 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202392}
2393
[email protected]cb805452013-05-22 15:16:212394void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482395 if (!color_chooser_info_.get())
2396 return;
2397 RenderFrameHost* rfh = RenderFrameHost::FromID(
2398 color_chooser_info_->render_process_id,
2399 color_chooser_info_->render_frame_id);
2400 if (!rfh)
2401 return;
2402
2403 rfh->Send(new FrameMsg_DidEndColorChooser(
2404 rfh->GetRoutingID(), color_chooser_info_->identifier));
2405 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202406}
2407
[email protected]41225fe2013-03-29 05:32:022408int WebContentsImpl::DownloadImage(const GURL& url,
2409 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302410 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022411 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582412 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022413 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392414 return id;
2415}
2416
[email protected]5dcaf8e2013-12-28 01:31:422417bool WebContentsImpl::IsSubframe() const {
2418 return is_subframe_;
2419}
2420
[email protected]36ec24f2014-01-09 00:32:082421void WebContentsImpl::Find(int request_id,
2422 const base::string16& search_text,
2423 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092424 // See if a top level browser plugin handles the find request first.
2425 if (browser_plugin_embedder_ &&
2426 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2427 return;
2428 }
[email protected]36ec24f2014-01-09 00:32:082429 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2430}
2431
2432void WebContentsImpl::StopFinding(StopFindAction action) {
2433 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2434}
2435
[email protected]4fe53add2014-04-08 19:53:362436void WebContentsImpl::InsertCSS(const std::string& css) {
2437 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2438 GetMainFrame()->GetRoutingID(), css));
2439}
2440
dalecurtisbc6572e12014-09-12 19:22:302441bool WebContentsImpl::WasRecentlyAudible() {
2442 return audio_stream_monitor_.WasRecentlyAudible();
2443}
2444
mlamouriefdca9d2014-09-16 16:55:402445void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2446 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2447}
2448
[email protected]b172aee2012-04-10 17:05:262449bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272450 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172451 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332452 return true;
2453 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272454}
2455
[email protected]b172aee2012-04-10 17:05:262456void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272457 if (delegate_)
2458 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212459}
2460
[email protected]52913802013-12-10 05:52:182461void WebContentsImpl::DidStartProvisionalLoad(
2462 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182463 const GURL& validated_url,
2464 bool is_error_page,
2465 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102466 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482467 FOR_EACH_OBSERVER(
2468 WebContentsObserver,
2469 observers_,
2470 DidStartProvisionalLoadForFrame(
2471 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
[email protected]400992b2012-06-14 00:03:542472}
2473
[email protected]0c3c54f2014-07-31 01:29:002474void WebContentsImpl::DidStartNavigationTransition(
morritaffb82612014-10-31 18:26:592475 RenderFrameHostImpl* render_frame_host) {
[email protected]0c3c54f2014-07-31 01:29:002476#if defined(OS_ANDROID)
2477 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562478 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
morritaffb82612014-10-31 18:26:592479 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002480#endif
2481}
2482
[email protected]3109fbb72014-01-06 23:57:152483void WebContentsImpl::DidFailProvisionalLoadWithError(
2484 RenderFrameHostImpl* render_frame_host,
2485 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2486 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312487 FOR_EACH_OBSERVER(WebContentsObserver,
2488 observers_,
2489 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312490 validated_url,
2491 params.error_code,
2492 params.error_description));
[email protected]3109fbb72014-01-06 23:57:152493}
2494
[email protected]b80624c2014-02-09 02:46:552495void WebContentsImpl::DidFailLoadWithError(
2496 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552497 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552498 int error_code,
2499 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142500 FOR_EACH_OBSERVER(
2501 WebContentsObserver,
2502 observers_,
2503 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552504}
2505
[email protected]52913802013-12-10 05:52:182506void WebContentsImpl::NotifyChangedNavigationState(
2507 InvalidateTypes changed_flags) {
2508 NotifyNavigationStateChanged(changed_flags);
2509}
2510
[email protected]3691e5cf2014-01-22 10:16:202511void WebContentsImpl::AboutToNavigateRenderFrame(
2512 RenderFrameHostImpl* render_frame_host) {
creis114ca1b2014-11-13 23:51:462513 // Notify observers that we will navigate in this RenderFrame.
[email protected]3691e5cf2014-01-22 10:16:202514 FOR_EACH_OBSERVER(
2515 WebContentsObserver,
2516 observers_,
creis114ca1b2014-11-13 23:51:462517 AboutToNavigateRenderFrame(render_frame_host));
[email protected]3691e5cf2014-01-22 10:16:202518}
2519
2520void WebContentsImpl::DidStartNavigationToPendingEntry(
2521 RenderFrameHostImpl* render_frame_host,
2522 const GURL& url,
2523 NavigationController::ReloadType reload_type) {
2524 // Notify observers about navigation.
2525 FOR_EACH_OBSERVER(
2526 WebContentsObserver,
2527 observers_,
2528 DidStartNavigationToPendingEntry(url, reload_type));
2529}
2530
[email protected]8cb834e2014-03-06 14:23:232531void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2532 const OpenURLParams& params) {
[email protected]65920f332014-03-04 21:14:182533 WebContents* new_contents = OpenURL(params);
2534
2535 if (new_contents) {
2536 // Notify observers.
2537 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2538 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:462539 render_frame_host,
[email protected]65920f332014-03-04 21:14:182540 params.url,
2541 params.referrer,
2542 params.disposition,
creis114ca1b2014-11-13 23:51:462543 params.transition));
[email protected]65920f332014-03-04 21:14:182544 }
2545}
2546
[email protected]aa62afd2014-04-22 19:22:462547bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2548 if (!delegate_)
2549 return false;
2550 return delegate_->ShouldPreserveAbortedURLs(this);
2551}
2552
[email protected]37567b432014-02-12 01:12:222553void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432554 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222555 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352556 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222557 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482558 FOR_EACH_OBSERVER(WebContentsObserver,
2559 observers_,
2560 DidCommitProvisionalLoadForFrame(
2561 render_frame_host, url, transition_type));
[email protected]37567b432014-02-12 01:12:222562}
2563
[email protected]0d0f4c492014-04-02 06:42:572564void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232565 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572566 // Ensure fullscreen mode is exited before committing the navigation to a
2567 // different page. The next page will not start out assuming it is in
2568 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232569 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192570 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572571 return;
2572 }
2573 if (IsFullscreenForCurrentTab())
2574 GetRenderViewHost()->ExitFullscreen();
2575 DCHECK(!IsFullscreenForCurrentTab());
2576}
2577
[email protected]37567b432014-02-12 01:12:222578void WebContentsImpl::DidNavigateMainFramePostCommit(
2579 const LoadCommittedDetails& details,
2580 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2581 if (details.is_navigation_to_different_page()) {
2582 // Clear the status bubble. This is a workaround for a bug where WebKit
2583 // doesn't let us know that the cursor left an element during a
2584 // transition (this is also why the mouse cursor remains as a hand after
2585 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2586 // clear the bubble when a user navigates to a named anchor in the same
2587 // page.
avi450ce00e2014-09-24 01:58:522588 UpdateTargetURL(GURL());
[email protected]37567b432014-02-12 01:12:222589 }
2590
2591 if (!details.is_in_page) {
2592 // Once the main frame is navigated, we're no longer considered to have
2593 // displayed insecure content.
2594 displayed_insecure_content_ = false;
2595 SSLManager::NotifySSLInternalStateChanged(
2596 GetController().GetBrowserContext());
2597 }
2598
2599 // Notify observers about navigation.
2600 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2601 DidNavigateMainFrame(details, params));
2602
[email protected]e85165c642014-06-10 14:34:312603 if (delegate_)
[email protected]37567b432014-02-12 01:12:222604 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312605 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222606}
2607
2608void WebContentsImpl::DidNavigateAnyFramePostCommit(
2609 RenderFrameHostImpl* render_frame_host,
2610 const LoadCommittedDetails& details,
2611 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102612 // Now that something has committed, we don't need to track whether the
2613 // initial page has been accessed.
2614 has_accessed_initial_document_ = false;
2615
[email protected]37567b432014-02-12 01:12:222616 // If we navigate off the page, close all JavaScript dialogs.
2617 if (dialog_manager_ && !details.is_in_page)
2618 dialog_manager_->CancelActiveAndPendingDialogs(this);
2619
2620 // Notify observers about navigation.
2621 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:092622 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:222623}
2624
2625void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2626 contents_mime_type_ = mime_type;
2627}
2628
[email protected]277857a2014-06-03 10:38:012629bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312630 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052631 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312632 return false;
2633
[email protected]37567b432014-02-12 01:12:222634 if (delegate_)
2635 return delegate_->CanOverscrollContent();
2636
2637 return false;
2638}
2639
[email protected]37b64c52014-07-11 21:14:052640void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252641 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052642 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252643}
2644
[email protected]b172aee2012-04-10 17:05:262645void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182646 const GURL& url,
[email protected]70435962011-08-02 20:13:282647 const std::string& security_info,
2648 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182649 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402650 ResourceType resource_type) {
[email protected]28620862011-03-22 23:07:192651 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182652 cache.Increment();
2653
2654 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082655 int cert_id = 0;
2656 net::CertStatus cert_status = 0;
2657 int security_bits = -1;
2658 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122659 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212660 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122661 &security_bits, &connection_status,
2662 &signed_certificate_timestamp_ids);
2663 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212664 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002665 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2666 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182667
[email protected]b0f724c2013-09-05 04:21:132668 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2669
2670 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2671 DidLoadResourceFromMemoryCache(details));
2672
[email protected]8bfc8272013-09-09 20:10:532673 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2674 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402675 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532676 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2677 GetRenderProcessHost()->GetID()) :
2678 GetBrowserContext()->GetRequestContextForRenderProcess(
2679 GetRenderProcessHost()->GetID()));
2680 BrowserThread::PostTask(
2681 BrowserThread::IO,
2682 FROM_HERE,
2683 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2684 }
[email protected]724159a2010-12-30 01:11:182685}
2686
[email protected]b172aee2012-04-10 17:05:262687void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392688 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182689 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192690 SSLManager::NotifySSLInternalStateChanged(
2691 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182692}
2693
[email protected]b172aee2012-04-10 17:05:262694void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022695 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582696 LOG(WARNING) << security_origin << " ran insecure content from "
2697 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392698 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412699 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392700 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182701 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412702 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192703 SSLManager::NotifySSLInternalStateChanged(
2704 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182705}
2706
[email protected]501052ff2014-02-21 22:19:072707void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572708 CHECK(render_frame_message_source_);
2709 CHECK(!render_view_message_source_);
2710 RenderFrameHostImpl* rfh =
2711 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142712 FOR_EACH_OBSERVER(
2713 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182714}
2715
[email protected]b172aee2012-04-10 17:05:262716void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262717 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372718 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122719 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2720 GetRenderProcessHost()->ReceivedBadMessage();
2721 return;
2722 }
[email protected]a1b99262013-12-27 21:56:222723
[email protected]8b3af1e2014-01-24 13:29:122724 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442725 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372726 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422727 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372728
[email protected]61ac9e242014-03-21 20:55:262729 RenderFrameHostImpl* rfh =
2730 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142731 FOR_EACH_OBSERVER(
2732 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312733}
2734
[email protected]960b0372014-05-19 18:01:002735void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2736 RenderFrameHostImpl* rfh =
2737 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2738 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2739
2740 // It is possible to get multiple calls to OnDidStartLoading that don't have
2741 // corresponding calls to OnDidStopLoading:
2742 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2743 // out for a cross-process navigation, and it turns into a placeholder for
2744 // one being rendered in a different process.
2745 // - Also, there might be more than one RenderFrameHost sharing the same
2746 // FrameTreeNode (and thus sharing its ID) each sending a start.
2747 // - But in the future, once clamy@ moves navigation network requests to the
2748 // browser process, there's a good chance that callbacks about starting and
2749 // stopping will all be handled by the browser. When that happens, there
2750 // should no longer be a start/stop call imbalance. TODO(avi): When this
2751 // future arrives, update this code to not allow this case.
2752 DCHECK_GE(loading_frames_in_progress_, 0);
2753 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2754 if (loading_frames_in_progress_ == 0)
2755 DidStartLoading(rfh, to_different_document);
2756 ++loading_frames_in_progress_;
2757 }
2758
2759 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2760 SendLoadProgressChanged();
2761}
2762
2763void WebContentsImpl::OnDidStopLoading() {
2764 RenderFrameHostImpl* rfh =
2765 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2766 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2767
2768 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2769 // Load stopped while we were still tracking load. Make sure we update
2770 // progress based on this frame's completion.
2771 loading_progresses_[render_frame_id] = 1.0;
2772 SendLoadProgressChanged();
2773 // Then we clean-up our states.
2774 if (loading_total_progress_ == 1.0)
2775 ResetLoadProgressState();
2776 }
2777
2778 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2779 // calls DidStopLoading() without a matching DidStartLoading().
2780 if (loading_frames_in_progress_ == 0)
2781 return;
2782 --loading_frames_in_progress_;
2783 if (loading_frames_in_progress_ == 0)
2784 DidStopLoading(rfh);
2785}
2786
2787void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2788 RenderFrameHostImpl* rfh =
2789 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2790 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2791
2792 loading_progresses_[render_frame_id] = load_progress;
2793
2794 // We notify progress change immediately for the first and last updates.
2795 // Also, since the message loop may be pretty busy when a page is loaded, it
2796 // might not execute a posted task in a timely manner so we make sure to
2797 // immediately send progress report if enough time has passed.
2798 base::TimeDelta min_delay =
2799 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2800 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2801 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2802 // If there is a pending task to send progress, it is now obsolete.
2803 loading_weak_factory_.InvalidateWeakPtrs();
2804 SendLoadProgressChanged();
2805 if (loading_total_progress_ == 1.0)
2806 ResetLoadProgressState();
2807 return;
2808 }
2809
2810 if (loading_weak_factory_.HasWeakPtrs())
2811 return;
2812
2813 base::MessageLoop::current()->PostDelayedTask(
2814 FROM_HERE,
2815 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2816 loading_weak_factory_.GetWeakPtr()),
2817 min_delay);
2818}
2819
[email protected]b172aee2012-04-10 17:05:262820void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222821 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2822 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262823}
2824
[email protected]b172aee2012-04-10 17:05:262825void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302826 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262827 minimum_zoom_percent_ = minimum_percent;
2828 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262829}
2830
[email protected]b172aee2012-04-10 17:05:262831void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342832 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432833 if (!delegate_)
2834 return;
2835
[email protected]b9535422012-02-09 01:47:592836 ChildProcessSecurityPolicyImpl* policy =
2837 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222838 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592839 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212840}
2841
[email protected]b172aee2012-04-10 17:05:262842void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2843 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262844 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362845 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432846 if (!delegate_)
2847 return;
2848
[email protected]b9535422012-02-09 01:47:592849 ChildProcessSecurityPolicyImpl* policy =
2850 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322851 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592852 return;
[email protected]8f810632013-06-06 22:33:322853
[email protected]c125e532014-05-10 20:39:062854 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202855}
2856
[email protected]f5273e52014-07-14 16:30:202857void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2858 const GURL& url,
2859 bool user_gesture) {
2860 if (!delegate_)
2861 return;
2862
2863 ChildProcessSecurityPolicyImpl* policy =
2864 ChildProcessSecurityPolicyImpl::GetInstance();
2865 if (policy->IsPseudoScheme(protocol))
2866 return;
2867
2868 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2869}
2870
[email protected]b172aee2012-04-10 17:05:262871void WebContentsImpl::OnFindReply(int request_id,
2872 int number_of_matches,
2873 const gfx::Rect& selection_rect,
2874 int active_match_ordinal,
2875 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432876 if (delegate_) {
2877 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2878 active_match_ordinal, final_update);
2879 }
[email protected]b888919c2011-09-02 00:32:162880}
2881
[email protected]59363fc92012-09-05 03:46:312882#if defined(OS_ANDROID)
2883void WebContentsImpl::OnFindMatchRectsReply(
2884 int version,
2885 const std::vector<gfx::RectF>& rects,
2886 const gfx::RectF& active_rect) {
2887 if (delegate_)
2888 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2889}
[email protected]583418cc2013-01-17 14:01:102890
[email protected]1ff427972013-02-07 21:14:072891void WebContentsImpl::OnOpenDateTimeDialog(
2892 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:172893 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:092894 GetRenderViewHost(),
2895 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132896 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092897 value.minimum,
2898 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172899 value.step,
2900 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102901}
[email protected]59363fc92012-09-05 03:46:312902#endif
2903
[email protected]cfa856d62014-02-22 07:58:402904void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2905 int automation_id) {
2906 DomOperationNotificationDetails details(json_string, automation_id);
2907 NotificationService::current()->Notify(
2908 NOTIFICATION_DOM_OPERATION_RESPONSE,
2909 Source<WebContents>(this),
2910 Details<DomOperationNotificationDetails>(&details));
2911}
2912
[email protected]b172aee2012-04-10 17:05:262913void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2914 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102915 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252916 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102917 AppCacheAccessed(manifest_url, blocked_by_policy));
2918}
2919
[email protected]8bc5ff02013-11-29 06:34:032920void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482921 int color_chooser_id,
2922 SkColor color,
2923 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462924 ColorChooser* new_color_chooser = delegate_ ?
2925 delegate_->OpenColorChooser(this, color, suggestions) :
2926 NULL;
[email protected]820957a2014-01-14 14:56:302927 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212928 return;
[email protected]8ed16472014-04-11 19:02:482929 if (color_chooser_info_.get())
2930 color_chooser_info_->chooser->End();
2931
2932 color_chooser_info_.reset(new ColorChooserInfo(
2933 render_frame_message_source_->GetProcess()->GetID(),
2934 render_frame_message_source_->GetRoutingID(),
2935 new_color_chooser,
2936 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202937}
2938
[email protected]b172aee2012-04-10 17:05:262939void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482940 if (color_chooser_info_ &&
2941 color_chooser_id == color_chooser_info_->identifier)
2942 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202943}
2944
[email protected]b172aee2012-04-10 17:05:262945void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322946 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482947 if (color_chooser_info_ &&
2948 color_chooser_id == color_chooser_info_->identifier)
2949 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202950}
2951
[email protected]d0759f492012-04-19 22:50:502952// This exists for render views that don't have a WebUI, but do have WebUI
2953// bindings enabled.
2954void WebContentsImpl::OnWebUISend(const GURL& source_url,
2955 const std::string& name,
2956 const base::ListValue& args) {
2957 if (delegate_)
2958 delegate_->WebUISend(this, source_url, name, args);
2959}
2960
thestigc4cac8f2014-09-04 21:17:502961#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:422962void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2963 const base::FilePath& path,
2964 bool is_hung) {
2965 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2966
2967 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2968 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2969}
2970
2971void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
2972 base::ProcessId plugin_pid) {
2973 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2974 PluginCrashed(plugin_path, plugin_pid));
2975}
2976
[email protected]d8415ad92012-08-23 14:40:502977void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442978 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502979 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342980 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162981 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442982 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162983 return;
[email protected]d8415ad92012-08-23 14:40:502984 }
2985
[email protected]8c8fc292012-11-23 18:57:162986 if (!delegate_->RequestPpapiBrokerPermission(
2987 this, url, plugin_path,
2988 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442989 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162990 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442991 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162992 }
[email protected]d8415ad92012-08-23 14:40:502993}
2994
[email protected]ea0309c2013-08-06 19:35:442995void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502996 bool result) {
[email protected]ea0309c2013-08-06 19:35:442997 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502998}
2999
[email protected]c4538072013-03-18 02:17:553000void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:373001 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:083002 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:553003 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:393004 // For more info, see comment above classes BrowserPluginEmbedder and
3005 // BrowserPluginGuest.
3006 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:143007 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:083008 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:373009}
tommyclie6633ca72014-10-31 00:40:423010#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373011
[email protected]41225fe2013-03-29 05:32:023012void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393013 int id,
[email protected]749fadd2013-05-15 08:37:483014 int http_status_code,
[email protected]795c28972012-12-06 06:13:393015 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303016 const std::vector<SkBitmap>& bitmaps,
3017 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133018 if (bitmaps.size() != original_bitmap_sizes.size())
3019 return;
3020
[email protected]41225fe2013-03-29 05:32:023021 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3022 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393023 // Currently WebContents notifies us of ANY downloads so that it is
3024 // possible to get here.
3025 return;
3026 }
3027 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303028 iter->second.Run(
3029 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393030 }
[email protected]41225fe2013-03-29 05:32:023031 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393032}
3033
3034void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393035 const std::vector<FaviconURL>& candidates) {
3036 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293037 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393038}
3039
dalecurtisbc6572e12014-09-12 19:22:303040void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3041 // ChromeOS has its own way of handling power save blocks for media.
3042#if !defined(OS_CHROMEOS)
3043 DCHECK(!audio_power_save_blocker_);
3044 audio_power_save_blocker_ = PowerSaveBlocker::Create(
3045 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing Audio");
3046#endif
3047}
3048
3049void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3050 // ChromeOS has its own way of handling power save blocks for media.
3051#if !defined(OS_CHROMEOS)
3052 DCHECK(!video_power_save_blocker_);
3053 DCHECK(!active_video_players_.empty());
3054 video_power_save_blocker_ = PowerSaveBlocker::Create(
3055 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing Video");
3056#if defined(OS_ANDROID)
3057 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3058 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3059#endif
3060#endif
3061}
3062
3063void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3064 // If there are no more audio players and we don't have audio stream
3065 // monitoring, release the audio power save blocker here instead of during
3066 // NotifyNavigationStateChanged().
3067 if (active_audio_players_.empty() &&
3068 !AudioStreamMonitor::monitoring_available()) {
3069 audio_power_save_blocker_.reset();
3070 }
3071
3072 // If there are no more video players, clear the video power save blocker.
3073 if (active_video_players_.empty())
3074 video_power_save_blocker_.reset();
3075}
3076
[email protected]1dd0bb752014-02-01 01:16:263077void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3078 bool has_video,
avayvod68017be2014-10-10 18:02:433079 bool has_audio,
3080 bool is_remote) {
3081 // Ignore the videos playing remotely and don't hold the wake lock for the
3082 // screen.
3083 if (is_remote) return;
3084
dalecurtisbc6572e12014-09-12 19:22:303085 if (has_audio) {
3086 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3087
3088 // If we don't have audio stream monitoring, allocate the audio power save
3089 // blocker here instead of during NotifyNavigationStateChanged().
3090 if (!audio_power_save_blocker_ &&
3091 !AudioStreamMonitor::monitoring_available()) {
3092 CreateAudioPowerSaveBlocker();
3093 }
[email protected]1dd0bb752014-02-01 01:16:263094 }
loislo0381a742014-09-11 10:58:113095
dalecurtisbc6572e12014-09-12 19:22:303096 if (has_video) {
3097 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3098
3099 // If we're not hidden and have just created a player, create a blocker.
3100 if (!video_power_save_blocker_ && !IsHidden())
3101 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113102 }
[email protected]1dd0bb752014-02-01 01:16:263103}
3104
3105void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303106 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3107 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3108 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063109}
3110
[email protected]50279492014-05-05 23:24:293111void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153112 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293113 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153114}
[email protected]d9030b82013-07-19 08:26:063115
[email protected]e67ebf32013-02-13 11:07:193116void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073117 if (delegate_)
3118 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193119}
3120
[email protected]17e286e2013-03-01 23:29:393121void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3122 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3123 BeforeFormRepostWarningShow());
3124}
3125
[email protected]ec6c05f2013-10-23 18:41:573126void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3127 Activate();
3128 if (delegate_)
3129 delegate_->ShowRepostFormWarningDialog(this);
3130}
3131
[email protected]b4c84012014-04-28 19:51:103132bool WebContentsImpl::HasAccessedInitialDocument() {
3133 return has_accessed_initial_document_;
3134}
3135
[email protected]96d185d2009-04-24 03:28:543136// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593137// loading, or done loading.
3138void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3139 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093140 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263141 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543142 if (is_loading == is_loading_)
3143 return;
3144
3145 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263146 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3147 base::string16());
[email protected]96d185d2009-04-24 03:28:543148 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563149 upload_size_ = 0;
3150 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543151 }
3152
[email protected]fa944cb82013-11-15 17:51:213153 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543154
3155 is_loading_ = is_loading;
3156 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033157 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543158
[email protected]6ebdc9b2010-09-27 16:55:573159 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093160 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213161 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543162
[email protected]eab61442013-11-14 18:35:483163 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593164 if (is_loading) {
naskob8744d22014-08-28 17:07:433165 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3166 this, "URL", url);
[email protected]91621872013-10-08 04:04:593167 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3168 DidStartLoading(render_view_host));
3169 } else {
naskob8744d22014-08-28 17:07:433170 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3171 this, "URL", url);
[email protected]91621872013-10-08 04:04:593172 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3173 DidStopLoading(render_view_host));
3174 }
[email protected]66798902013-10-01 18:40:163175
3176 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213177 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3178 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543179 if (details)
[email protected]8ff00d72012-10-23 19:12:213180 det = Details<LoadNotificationDetails>(details);
3181 NotificationService::current()->Notify(
3182 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543183}
3184
christiankaeed9862014-11-05 10:49:143185void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
3186 RenderFrameHost* focused_frame = GetFocusedFrame();
3187 if (!focused_frame)
3188 return;
3189
3190 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
3191 focused_frame->GetRoutingID(), extent));
3192}
3193
3194void WebContentsImpl::SelectRange(const gfx::Point& base,
3195 const gfx::Point& extent) {
[email protected]959be4c2014-04-08 15:01:333196 RenderFrameHost* focused_frame = GetFocusedFrame();
3197 if (!focused_frame)
3198 return;
3199
3200 focused_frame->Send(
christiankaeed9862014-11-05 10:49:143201 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
[email protected]959be4c2014-04-08 15:01:333202}
3203
[email protected]b172aee2012-04-10 17:05:263204void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463205 // If we are creating a RVH for a restored controller, then we need to make
3206 // sure the RenderView starts with a next_page_id_ larger than the number
3207 // of restored entries. This must be called before the RenderView starts
3208 // navigating (to avoid a race between the browser updating max_page_id and
3209 // the renderer updating next_page_id_). Because of this, we only call this
3210 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563211 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583212 if (max_restored_page_id >
3213 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3214 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3215 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323216}
3217
[email protected]b172aee2012-04-10 17:05:263218bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263219 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323220 // For file URLs without a title, use the pathname instead. In the case of a
3221 // synthesized title, we don't want the update to count toward the "one set
3222 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263223 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323224 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513225 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243226 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323227 explicit_set = false; // Don't count synthetic titles toward the set limit.
3228 } else {
[email protected]8af69c6c2014-03-03 19:05:313229 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323230 explicit_set = true;
3231 }
3232
[email protected]987fc3a2011-05-26 14:18:093233 // If a page is created via window.open and never navigated,
3234 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553235 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093236 if (entry) {
[email protected]36fc0392011-12-25 03:59:513237 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093238 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323239
[email protected]36fc0392011-12-25 03:59:513240 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093241 } else {
3242 if (page_title_when_no_navigation_entry_ == final_title)
3243 return false; // Nothing changed, don't bother.
3244
3245 page_title_when_no_navigation_entry_ = final_title;
3246 }
[email protected]420ae012009-04-24 05:16:323247
[email protected]420ae012009-04-24 05:16:323248 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233249 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323250
[email protected]66798902013-10-01 18:40:163251 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533252 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163253
3254 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213255 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463256 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213257 NotificationService::current()->Notify(
3258 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3259 Source<WebContents>(this),
3260 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043261
[email protected]420ae012009-04-24 05:16:323262 return true;
3263}
3264
[email protected]960b0372014-05-19 18:01:003265void WebContentsImpl::SendLoadProgressChanged() {
3266 loading_last_progress_update_ = base::TimeTicks::Now();
3267 double progress = 0.0;
3268 int frame_count = 0;
3269
3270 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3271 it != loading_progresses_.end();
3272 ++it) {
3273 progress += it->second;
3274 ++frame_count;
3275 }
3276 if (frame_count == 0)
3277 return;
3278 progress /= frame_count;
3279 DCHECK(progress <= 1.0);
3280
3281 if (progress <= loading_total_progress_)
3282 return;
3283 loading_total_progress_ = progress;
3284
3285 if (delegate_)
3286 delegate_->LoadProgressChanged(this, progress);
3287}
3288
3289void WebContentsImpl::ResetLoadProgressState() {
3290 loading_progresses_.clear();
3291 loading_total_progress_ = 0.0;
3292 loading_weak_factory_.InvalidateWeakPtrs();
3293 loading_last_progress_update_ = base::TimeTicks();
3294}
3295
[email protected]02d7b6e2014-06-24 21:01:503296void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3297 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323298 // After sending out a swap notification, we need to send a disconnect
3299 // notification so that clients that pick up a pointer to |this| can NULL the
3300 // pointer. See Bug 1230284.
3301 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113302 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283303 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113304
3305 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283306 std::pair<RenderViewHost*, RenderViewHost*> details =
3307 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213308 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283309 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213310 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283311 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393312
3313 // Ensure that the associated embedder gets cleared after a RenderViewHost
3314 // gets swapped, so we don't reuse the same embedder next time a
3315 // RenderViewHost is attached to this WebContents.
3316 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323317}
3318
[email protected]02d7b6e2014-06-24 21:01:503319void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3320 RenderFrameHost* new_host) {
3321 FOR_EACH_OBSERVER(WebContentsObserver,
3322 observers_,
3323 RenderFrameHostChanged(old_host, new_host));
3324}
3325
[email protected]da7a7182013-09-06 08:11:113326// TODO(avi): Remove this entire function because this notification is already
3327// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263328void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323329 if (!notify_disconnection_)
3330 return;
3331
3332 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213333 NotificationService::current()->Notify(
3334 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3335 Source<WebContents>(this),
3336 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323337}
3338
[email protected]cbb1ef592013-06-05 19:49:463339void WebContentsImpl::NotifyNavigationEntryCommitted(
3340 const LoadCommittedDetails& load_details) {
3341 FOR_EACH_OBSERVER(
3342 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3343}
3344
[email protected]f114fa42013-12-06 17:06:443345bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3346 const IPC::Message& message) {
3347 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313348}
3349
[email protected]c31a84802014-04-03 15:55:493350const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3351 return GetLastCommittedURL();
3352}
3353
[email protected]b849847b2013-12-10 21:57:583354void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3355 // Note this is only for subframes, the notification for the main frame
3356 // happens in RenderViewCreated.
3357 FOR_EACH_OBSERVER(WebContentsObserver,
3358 observers_,
3359 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303360 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583361}
3362
3363void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193364 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583365 FOR_EACH_OBSERVER(WebContentsObserver,
3366 observers_,
3367 RenderFrameDeleted(render_frame_host));
3368}
3369
[email protected]a09d53ce2014-01-31 00:46:423370void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303371 if (delegate_)
3372 delegate_->WorkerCrashed(this);
3373}
3374
[email protected]a09d53ce2014-01-31 00:46:423375void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3376 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103377 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423378 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103379 if (GetBrowserPluginGuest()) {
3380 WebContentsViewGuest* view_guest =
3381 static_cast<WebContentsViewGuest*>(GetView());
3382 context_menu_params = view_guest->ConvertContextMenuParams(params);
3383 }
3384 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423385 return;
3386
[email protected]077e704b2014-05-23 19:24:103387 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3388 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423389}
3390
[email protected]87de04b02014-04-08 22:14:493391void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013392 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493393 const base::string16& message,
3394 const base::string16& default_prompt,
3395 const GURL& frame_url,
3396 JavaScriptMessageType javascript_message_type,
3397 IPC::Message* reply_msg) {
3398 // Suppress JavaScript dialogs when requested. Also suppress messages when
3399 // showing an interstitial as it's shown over the previous page and we don't
3400 // want the hidden page's dialogs to interfere with the interstitial.
3401 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223402 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503403 ShowingInterstitialPage() || !delegate_ ||
3404 delegate_->ShouldSuppressDialogs(this) ||
3405 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493406
3407 if (!suppress_this_message) {
3408 std::string accept_lang = GetContentClient()->browser()->
3409 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503410 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493411 dialog_manager_->RunJavaScriptDialog(
3412 this,
3413 frame_url.GetOrigin(),
3414 accept_lang,
3415 javascript_message_type,
3416 message,
3417 default_prompt,
3418 base::Bind(&WebContentsImpl::OnDialogClosed,
3419 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013420 render_frame_host->GetProcess()->GetID(),
3421 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493422 reply_msg,
3423 false),
3424 &suppress_this_message);
3425 }
3426
3427 if (suppress_this_message) {
3428 // If we are suppressing messages, just reply as if the user immediately
3429 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013430 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3431 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283432 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493433 }
3434
3435 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3436 // http://crbug.com/288961 ). The only safe thing to do here is return.
3437}
3438
3439void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013440 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493441 const base::string16& message,
3442 bool is_reload,
3443 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013444 RenderFrameHostImpl* rfhi =
3445 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493446 if (delegate_)
3447 delegate_->WillRunBeforeUnloadConfirm();
3448
3449 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503450 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT || !delegate_ ||
3451 delegate_->ShouldSuppressDialogs(this) ||
3452 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493453 if (suppress_this_message) {
3454 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3455 return;
3456 }
3457
3458 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503459 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493460 dialog_manager_->RunBeforeUnloadDialog(
3461 this, message, is_reload,
3462 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013463 render_frame_host->GetProcess()->GetID(),
3464 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283465 false));
[email protected]87de04b02014-04-08 22:14:493466}
3467
[email protected]a86c0e962013-12-17 17:10:393468WebContents* WebContentsImpl::GetAsWebContents() {
3469 return this;
3470}
3471
[email protected]7912e822014-04-16 02:37:033472bool WebContentsImpl::IsNeverVisible() {
3473 if (!delegate_)
3474 return false;
3475 return delegate_->IsNeverVisible(this);
3476}
3477
[email protected]95640212014-07-26 18:14:303478#if defined(OS_WIN)
3479gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3480 return accessible_parent_;
3481}
3482#endif
3483
[email protected]5a3bdf52012-05-24 15:12:573484RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3485 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323486}
3487
[email protected]8ff00d72012-10-23 19:12:213488RendererPreferences WebContentsImpl::GetRendererPrefs(
3489 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463490 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513491}
3492
[email protected]b172aee2012-04-10 17:05:263493gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173494 if (delegate_)
3495 return delegate_->GetRootWindowResizerRect();
3496 return gfx::Rect();
3497}
3498
[email protected]7a846df2012-09-20 19:17:393499void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273500 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393501 browser_plugin_embedder_.reset();
3502}
3503
[email protected]b172aee2012-04-10 17:05:263504void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443505 // Don't send notifications if we are just creating a swapped-out RVH for
3506 // the opener chain. These won't be used for view-source or WebUI, so it's
3507 // ok to return early.
creiscce56cd2014-09-29 22:45:223508 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443509 return;
3510
[email protected]86f98a22013-03-20 14:35:003511 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313512 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083513
[email protected]8ff00d72012-10-23 19:12:213514 NotificationService::current()->Notify(
3515 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3516 Source<WebContents>(this),
3517 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323518
3519 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353520 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213521 if (GetRenderManager()->pending_web_ui())
3522 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323523
[email protected]6286a372013-10-09 04:03:273524 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333525 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323526 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183527 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583528 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323529 }
[email protected]0666aef2009-05-13 19:48:083530
[email protected]60780f412013-02-25 16:34:103531 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263532
3533 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253534 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583535
3536 // We tell the observers now instead of when the main RenderFrameHostImpl is
3537 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3538 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363539 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583540 FOR_EACH_OBSERVER(
3541 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303542 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
dgozman24bfc912014-09-29 11:04:183543
3544 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:323545}
3546
[email protected]b172aee2012-04-10 17:05:263547void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523548 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323549 // Don't notify the world, since this came from a renderer in the
3550 // background.
3551 return;
3552 }
3553
[email protected]da7a7182013-09-06 08:11:113554 notify_disconnection_ = true;
3555 // TODO(avi): Remove. http://crbug.com/170921
3556 NotificationService::current()->Notify(
3557 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3558 Source<WebContents>(this),
3559 NotificationService::NoDetails());
3560
[email protected]be1f56ab2011-12-22 06:55:313561 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233562 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303563
3564 // Restore the focus to the tab (otherwise the focus will be on the top
3565 // window).
[email protected]484ae5912010-09-29 19:16:143566 if (was_crashed && !FocusLocationBarByDefault() &&
3567 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063568 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143569 }
[email protected]32ded2212011-11-10 18:51:433570
[email protected]d8c660432011-12-22 20:51:253571 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323572}
3573
[email protected]ec6a7eb2013-04-22 17:34:223574void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3575 base::TerminationStatus status,
3576 int error_code) {
[email protected]151a63d2011-12-20 22:32:523577 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323578 // The pending page's RenderViewHost is gone.
3579 return;
3580 }
3581
[email protected]2fcdcc32014-03-05 02:14:073582 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3583 // renderer may not have made a clean exit.
3584 if (IsFullscreenForCurrentTab())
3585 ToggleFullscreenMode(false);
3586
[email protected]698191dc2014-02-25 01:06:133587 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3588 if (dialog_manager_)
3589 dialog_manager_->CancelActiveAndPendingDialogs(this);
3590
[email protected]f738bdcb2014-07-11 20:40:443591 if (delegate_)
3592 delegate_->HideValidationMessage(this);
3593
[email protected]e3b10d12014-03-28 16:06:093594 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323595 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233596 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453597
[email protected]960b0372014-05-19 18:01:003598 // Reset the loading progress. TODO(avi): What does it mean to have a
3599 // "renderer crash" when there is more than one renderer process serving a
3600 // webpage? Once this function is called at a more granular frame level, we
3601 // probably will need to more granularly reset the state here.
3602 ResetLoadProgressState();
3603 loading_frames_in_progress_ = 0;
3604
[email protected]d8c660432011-12-22 20:51:253605 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273606 observers_,
[email protected]58d5cfe2013-07-10 02:40:523607 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323608}
3609
[email protected]b172aee2012-04-10 17:05:263610void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253611 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063612}
3613
[email protected]b172aee2012-04-10 17:05:263614void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3615 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043616 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153617 // Ensure that this state update comes from either the active RVH or one of
3618 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413619 // TODO(nasko): This should go through RenderFrameHost.
3620 // TODO(creis): We can't update state for cross-process subframes until we
3621 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3622 if (rvh != GetRenderViewHost() &&
3623 !GetRenderManager()->IsRVHOnSwappedOutList(
3624 static_cast<RenderViewHostImpl*>(rvh)))
3625 return;
[email protected]420ae012009-04-24 05:16:323626
3627 // We must be prepared to handle state updates for any page, these occur
3628 // when the user is scrolling and entering form data, as well as when we're
3629 // leaving a page, in which case our state may have already been moved to
3630 // the next page. The navigation controller will look up the appropriate
3631 // NavigationEntry and update it when it is notified via the delegate.
3632
3633 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583634 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323635 if (entry_index < 0)
3636 return;
[email protected]10f417c52011-12-28 21:04:233637 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323638
[email protected]691aa2f2013-05-28 22:52:043639 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323640 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043641 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323642 controller_.NotifyEntryChanged(entry, entry_index);
3643}
3644
avi450ce00e2014-09-24 01:58:523645void WebContentsImpl::UpdateTargetURL(const GURL& url) {
[email protected]6934a702011-12-20 00:04:513646 if (delegate_)
avi450ce00e2014-09-24 01:58:523647 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323648}
3649
[email protected]b172aee2012-04-10 17:05:263650void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103651#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293652 // The UI may be in an event-tracking loop, such as between the
3653 // mouse-down and mouse-up in text selection or a button click.
3654 // Defer the close until after tracking is complete, so that we
3655 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293656 // TODO(shess): This could get more fine-grained. For instance,
3657 // closing a tab in another window while selecting text in the
3658 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103659 if (view_->IsEventTracking()) {
3660 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293661 return;
3662 }
[email protected]60780f412013-02-25 16:34:103663#endif
[email protected]07707302009-11-06 00:50:293664
[email protected]420ae012009-04-24 05:16:323665 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523666 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513667 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323668}
3669
[email protected]66bbadaf2014-03-28 16:25:543670void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573671 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3672 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573673}
3674
[email protected]6f2ac772014-07-24 22:22:083675void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253676 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173677#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563678 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173679#endif
3680}
3681
3682bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3683#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563684 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173685#else
3686 return false;
3687#endif
3688}
3689
[email protected]b172aee2012-04-10 17:05:263690void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513691 if (delegate_ && delegate_->IsPopupOrPanel(this))
3692 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323693}
3694
[email protected]e3b10d12014-03-28 16:06:093695void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3696 bool to_different_document) {
3697 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3698 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323699}
3700
[email protected]723971b2014-02-12 11:08:253701void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323702 scoped_ptr<LoadNotificationDetails> details;
3703
[email protected]9595fd82013-04-19 21:28:493704 // Use the last committed entry rather than the active one, in case a
3705 // pending entry has been created.
3706 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203707 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493708
[email protected]420ae012009-04-24 05:16:323709 // An entry may not exist for a stop when loading an initial blank page or
3710 // if an iframe injected by script into a blank page finishes loading.
3711 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203712 base::TimeDelta elapsed =
3713 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323714
3715 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513716 entry->GetVirtualURL(),
3717 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323718 elapsed,
3719 &controller_,
3720 controller_.GetCurrentEntryIndex()));
3721 }
3722
[email protected]e3b10d12014-03-28 16:06:093723 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3724 details.get());
[email protected]420ae012009-04-24 05:16:323725}
3726
[email protected]b172aee2012-04-10 17:05:263727void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163728 controller_.DiscardNonCommittedEntries();
3729
3730 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213731 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163732}
3733
[email protected]59167c22013-06-03 18:07:323734void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103735 has_accessed_initial_document_ = true;
3736
[email protected]d1371bf8e2014-04-19 03:26:243737 // We may have left a failed browser-initiated navigation in the address bar
3738 // to let the user edit it and try again. Clear it now that content might
3739 // show up underneath it.
3740 if (!IsLoading() && controller_.GetPendingEntry())
3741 controller_.DiscardPendingEntry();
3742
[email protected]59167c22013-06-03 18:07:323743 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503744 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323745}
3746
[email protected]3f19f1a2014-05-02 05:23:273747void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473748 // No action is necessary if the opener has already been cleared.
3749 if (!opener_)
3750 return;
3751
3752 // Clear our opener so that future cross-process navigations don't have an
3753 // opener assigned.
3754 RemoveDestructionObserver(opener_);
3755 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273756
3757 // Notify all swapped out RenderViewHosts for this tab. This is important
3758 // in case we go back to them, or if another window in those processes tries
3759 // to access window.opener.
creisbbbeb062014-08-25 18:20:313760 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273761}
3762
[email protected]39f2f9252014-05-03 00:54:013763void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293764 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093765 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293766 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093767
3768 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213769 NotificationService::current()->Notify(
3770 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3771 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293772 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083773}
3774
[email protected]ef3adfc2014-05-11 00:04:543775void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3776 int32 page_id,
3777 const base::string16& title,
3778 base::i18n::TextDirection title_direction) {
3779 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3780
3781 // If we have a title, that's a pretty good indication that we've started
3782 // getting useful data.
3783 SetNotWaitingForResponse();
3784
3785 // Try to find the navigation entry, which might not be the current one.
3786 // For example, it might be from a pending RVH for the pending entry.
3787 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3788 rvh->GetSiteInstance(), page_id);
3789
3790 // We can handle title updates when we don't have an entry in
3791 // UpdateTitleForEntry, but only if the update is from the current RVH.
3792 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3793 if (!entry && rvh != GetRenderViewHost())
3794 return;
3795
3796 // TODO(evan): make use of title_direction.
3797 // http://code.google.com/p/chromium/issues/detail?id=27094
3798 if (!UpdateTitleForEntry(entry, title))
3799 return;
3800
3801 // Broadcast notifications when the UI should be updated.
3802 if (entry == controller_.GetEntryAtOffset(0))
3803 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3804}
3805
3806void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3807 const std::string& encoding) {
3808 SetEncoding(encoding);
3809}
3810
[email protected]39f2f9252014-05-03 00:54:013811void WebContentsImpl::DocumentAvailableInMainFrame(
3812 RenderViewHost* render_view_host) {
3813 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3814 DocumentAvailableInMainFrame());
3815}
[email protected]e1c3a552012-05-04 20:51:323816void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3817 // Tell the active RenderViewHost to run unload handlers and close, as long
3818 // as the request came from a RenderViewHost in the same BrowsingInstance.
3819 // In most cases, we receive this from a swapped out RenderViewHost.
3820 // It is possible to receive it from one that has just been swapped in,
3821 // in which case we might as well deliver the message anyway.
3822 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3823 GetRenderViewHost()->ClosePage();
3824}
3825
[email protected]f546640b2012-05-15 00:03:493826void WebContentsImpl::RouteMessageEvent(
3827 RenderViewHost* rvh,
3828 const ViewMsg_PostMessage_Params& params) {
3829 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363830 // came from a RenderViewHost in the same BrowsingInstance or if this
3831 // WebContents is dedicated to a browser plugin guest.
3832 // Note: This check means that an embedder could theoretically receive a
3833 // postMessage from anyone (not just its own guests). However, this is
3834 // probably not a risk for apps since other pages won't have references
3835 // to App windows.
3836 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3837 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493838 return;
3839
3840 ViewMsg_PostMessage_Params new_params(params);
3841
[email protected]0bc7f3542013-10-21 15:05:533842 if (!params.message_port_ids.empty()) {
3843 MessagePortMessageFilter* message_port_message_filter =
3844 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3845 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093846 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3847 params.message_port_ids,
3848 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533849 }
3850
[email protected]f546640b2012-05-15 00:03:493851 // If there is a source_routing_id, translate it to the routing ID for
3852 // the equivalent swapped out RVH in the target process. If we need
3853 // to create a swapped out RVH for the source tab, we create its opener
3854 // chain as well, since those will also be accessible to the target page.
3855 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3856 // Try to look up the WebContents for the source page.
3857 WebContentsImpl* source_contents = NULL;
3858 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3859 rvh->GetProcess()->GetID(), params.source_routing_id);
3860 if (source_rvh) {
3861 source_contents = static_cast<WebContentsImpl*>(
3862 source_rvh->GetDelegate()->GetAsWebContents());
3863 }
3864
3865 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363866 if (GetBrowserPluginGuest()) {
3867 // We create a swapped out RenderView for the embedder in the guest's
3868 // render process but we intentionally do not expose the embedder's
3869 // opener chain to it.
3870 new_params.source_routing_id =
3871 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3872 } else {
3873 new_params.source_routing_id =
3874 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3875 }
[email protected]f546640b2012-05-15 00:03:493876 } else {
3877 // We couldn't find it, so don't pass a source frame.
3878 new_params.source_routing_id = MSG_ROUTING_NONE;
3879 }
3880 }
3881
3882 // In most cases, we receive this from a swapped out RenderViewHost.
3883 // It is possible to receive it from one that has just been swapped in,
3884 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183885 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493886}
3887
[email protected]a796f202012-05-30 14:14:253888bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263889 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253890 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263891 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253892 if (!delegate_)
3893 return false;
3894 return delegate_->AddMessageToConsole(this, level, message, line_no,
3895 source_id);
3896}
3897
[email protected]9e797d22014-08-08 21:31:303898WebPreferences WebContentsImpl::ComputeWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273899 // We want to base the page config off of the actual URL, rather than the
3900 // virtual URL.
3901 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3902 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003903 GURL url = controller_.GetActiveEntry()
3904 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153905
[email protected]9e797d22014-08-08 21:31:303906 return GetRenderManager()->current_host()->ComputeWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323907}
3908
[email protected]0eba810b2012-10-18 03:19:363909int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213910 SiteInstance* instance) {
[email protected]82307f6b2014-08-07 03:30:123911 return GetRenderManager()->CreateRenderFrame(
kenrb32d18a42014-11-17 22:16:073912 instance, MSG_ROUTING_NONE, CREATE_RF_SWAPPED_OUT |
3913 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
3914 CREATE_RF_HIDDEN);
[email protected]0eba810b2012-10-18 03:19:363915}
3916
[email protected]b172aee2012-04-10 17:05:263917void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273918 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253919 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223920
[email protected]ea114722012-03-12 01:11:253921 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173922 if (rdh) // NULL in unittests.
3923 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253924}
3925
[email protected]b172aee2012-04-10 17:05:263926void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443927 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253928 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443929}
3930
creiscce56cd2014-09-29 22:45:223931void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:153932 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:223933 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153934 return;
3935
creiscce56cd2014-09-29 22:45:223936 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
3937 RenderFrameHostImpl* rfhi =
3938 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:583939
[email protected]e5fc1632011-08-08 07:51:533940 // Ignore renderer unresponsive event if debugger is attached to the tab
3941 // since the event may be a result of the renderer sitting on a breakpoint.
3942 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363943 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533944 return;
3945
creiscce56cd2014-09-29 22:45:223946 if (rfhi->is_waiting_for_beforeunload_ack() ||
3947 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:323948 // Hang occurred while firing the beforeunload/unload handler.
3949 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583950 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323951
[email protected]fa944cb82013-11-15 17:51:213952 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323953 return;
3954
3955 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563956 // nothing we can do to recover. If the hang is in the beforeunload handler,
3957 // pretend the beforeunload listeners have all fired and allow the delegate
3958 // to continue closing; the user will not have the option of cancelling the
3959 // close. Otherwise, pretend the unload listeners have all fired and close
3960 // the tab.
3961 bool close = true;
creiscce56cd2014-09-29 22:45:223962 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563963 delegate_->BeforeUnloadFired(this, true, &close);
3964 }
3965 if (close)
creiscce56cd2014-09-29 22:45:223966 Close(rvhi);
[email protected]420ae012009-04-24 05:16:323967 return;
3968 }
3969
[email protected]9f76c1e2012-03-05 15:15:583970 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473971 return;
3972
[email protected]6934a702011-12-20 00:04:513973 if (delegate_)
3974 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323975}
3976
[email protected]b172aee2012-04-10 17:05:263977void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513978 if (delegate_)
3979 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323980}
3981
[email protected]b172aee2012-04-10 17:05:263982void WebContentsImpl::LoadStateChanged(
3983 const GURL& url,
3984 const net::LoadStateWithParam& load_state,
3985 uint64 upload_position,
3986 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323987 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563988 upload_position_ = upload_position;
3989 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503990 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213991 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303992 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213993 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323994 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463995 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:223996 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
3997 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:463998 }
[email protected]420ae012009-04-24 05:16:323999}
4000
[email protected]b172aee2012-04-10 17:05:264001void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554002 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324003 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124004 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4005 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514006 if (delegate_)
4007 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094008 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324009}
4010
[email protected]58d5cfe2013-07-10 02:40:524011void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544012 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234013 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224014 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544015}
4016
[email protected]b172aee2012-04-10 17:05:264017void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104018 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214019 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264020 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4021 // here during container initialization and normal window size will be set
4022 // later. In case of tab duplication this resizing to 0x0 prevents setting
4023 // normal size later so just ignore it.
4024 if (!size.IsEmpty())
4025 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324026}
4027
[email protected]af905902013-10-01 21:38:514028void WebContentsImpl::CancelModalDialogsForRenderManager() {
4029 // We need to cancel modal dialogs when doing a process swap, since the load
4030 // deferrer would prevent us from swapping out.
4031 if (dialog_manager_)
4032 dialog_manager_->CancelActiveAndPendingDialogs(this);
4033}
4034
[email protected]02d7b6e2014-06-24 21:01:504035void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4036 RenderFrameHost* new_host,
4037 bool is_main_frame) {
4038 if (is_main_frame) {
4039 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4040 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084041
[email protected]02d7b6e2014-06-24 21:01:504042 // Make sure the visible RVH reflects the new delegate's preferences.
4043 if (delegate_)
4044 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394045
[email protected]02d7b6e2014-06-24 21:01:504046 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4047 }
4048
4049 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544050}
4051
[email protected]14392a52012-05-02 20:28:444052int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4053 SiteInstance* instance) {
4054 if (!opener_)
4055 return MSG_ROUTING_NONE;
4056
4057 // Recursively create RenderViews for anything else in the opener chain.
4058 return opener_->CreateOpenerRenderViews(instance);
4059}
4060
4061int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4062 int opener_route_id = MSG_ROUTING_NONE;
4063
4064 // If this tab has an opener, ensure it has a RenderView in the given
4065 // SiteInstance as well.
4066 if (opener_)
4067 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4068
[email protected]45a22ad2013-02-21 03:25:004069 // If any of the renderers (current, pending, or swapped out) for this
4070 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214071 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4072 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374073
[email protected]fa944cb82013-11-15 17:51:214074 if (GetRenderManager()->pending_render_view_host() &&
4075 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4076 instance)
4077 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004078
[email protected]fa944cb82013-11-15 17:51:214079 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374080 instance);
4081 if (rvh)
4082 return rvh->GetRoutingID();
4083
[email protected]14392a52012-05-02 20:28:444084 // Create a swapped out RenderView in the given SiteInstance if none exists,
4085 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]82307f6b2014-08-07 03:30:124086 return GetRenderManager()->CreateRenderFrame(
kenrb32d18a42014-11-17 22:16:074087 instance, opener_route_id, CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4088 CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN);
[email protected]14392a52012-05-02 20:28:444089}
4090
[email protected]b172aee2012-04-10 17:05:264091NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194092 return GetController();
[email protected]3a3d47472010-07-15 21:03:544093}
4094
[email protected]b172aee2012-04-10 17:05:264095WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:564096 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:324097}
4098
[email protected]10f417c52011-12-28 21:04:234099NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264100 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324101 return controller_.GetLastCommittedEntry();
4102}
4103
[email protected]b172aee2012-04-10 17:05:264104bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164105 RenderViewHost* render_view_host,
4106 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044107 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124108 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434109 TRACE_EVENT0("browser,navigation",
4110 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444111 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484112 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164113 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4114 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4115 // case this because RWH is still a base class of RenderViewHost, and child
4116 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124117 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164118 RenderWidgetHostViewChildFrame* rwh_view_child =
4119 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164120 rwh_view = rwh_view_child;
4121 } else {
lazyboy549b3b42014-10-20 17:16:044122 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164123 }
[email protected]1a98a932009-11-17 00:12:524124
[email protected]420ae012009-04-24 05:16:324125 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444126 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214127 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324128
[email protected]74ce1ad2011-12-16 21:51:464129 // Make sure we use the correct starting page_id in the new RenderView.
4130 UpdateMaxPageIDIfNecessary(render_view_host);
4131 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584132 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464133
[email protected]9f76c1e2012-03-05 15:15:584134 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264135 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494136 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044137 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494138 max_page_id,
4139 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524140 return false;
[email protected]14392a52012-05-02 20:28:444141 }
[email protected]a4127722011-04-27 23:13:524142
[email protected]a220b5932013-09-21 03:47:444143#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504144 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4145 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444146 if (rwh_view) {
4147 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4148 render_widget_host->WasResized();
4149 }
[email protected]f8233cc2011-05-31 20:24:504150#endif
4151
[email protected]420ae012009-04-24 05:16:324152 return true;
4153}
4154
[email protected]82307f6b2014-08-07 03:30:124155bool WebContentsImpl::CreateRenderFrameForRenderManager(
4156 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494157 int parent_routing_id,
4158 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434159 TRACE_EVENT0("browser,navigation",
4160 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124161
4162 RenderFrameHostImpl* rfh =
4163 static_cast<RenderFrameHostImpl*>(render_frame_host);
japhete6adf142014-10-31 00:01:494164 if (!rfh->CreateRenderFrame(parent_routing_id, proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124165 return false;
4166
4167 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4168 // RenderFrameHost will have to be associated with the appropriate
4169 // RenderWidgetHostView or a new one should be created here.
4170
4171 return true;
4172}
4173
[email protected]7d244f12013-08-22 21:41:514174#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454175
[email protected]155c7f22013-12-09 17:07:184176base::android::ScopedJavaLocalRef<jobject>
4177WebContentsImpl::GetJavaWebContents() {
4178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564179 return GetWebContentsAndroid()->GetJavaObject();
4180}
[email protected]155c7f22013-12-09 17:07:184181
[email protected]0e813a52014-08-13 10:34:564182WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184183 WebContentsAndroid* web_contents_android =
4184 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4185 if (!web_contents_android) {
4186 web_contents_android = new WebContentsAndroid(this);
4187 SetUserData(kWebContentsAndroidKey, web_contents_android);
4188 }
[email protected]0e813a52014-08-13 10:34:564189 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184190}
4191
[email protected]7d244f12013-08-22 21:41:514192bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4193 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164194 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044195 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594196 true);
[email protected]7d244f12013-08-22 21:41:514197}
[email protected]fc2b46b2014-05-03 16:33:454198
4199#elif defined(OS_MACOSX)
4200
[email protected]75f4df72014-07-16 22:39:424201void WebContentsImpl::SetAllowOtherViews(bool allow) {
4202 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454203}
4204
[email protected]75f4df72014-07-16 22:39:424205bool WebContentsImpl::GetAllowOtherViews() {
4206 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454207}
4208
[email protected]7d244f12013-08-22 21:41:514209#endif
4210
[email protected]6fba26d2014-04-29 09:38:284211void WebContentsImpl::OnDialogClosed(int render_process_id,
4212 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264213 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494214 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264215 bool success,
[email protected]fcf75d42013-12-03 20:11:264216 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284217 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4218 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494219 last_dialog_suppressed_ = dialog_was_suppressed;
4220
[email protected]beb440c2009-11-06 04:08:544221 if (is_showing_before_unload_dialog_ && !success) {
4222 // If a beforeunload dialog is canceled, we need to stop the throbber from
4223 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284224 if (rfh)
4225 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354226 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104227
[email protected]6d65a462013-06-21 21:29:124228 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4229 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544230 }
[email protected]87de04b02014-04-08 22:14:494231
[email protected]beb440c2009-11-06 04:08:544232 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284233 if (rfh) {
4234 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4235 dialog_was_suppressed);
4236 } else {
4237 // Don't leak the sync IPC reply if the RFH or process is gone.
4238 delete reply_msg;
4239 }
[email protected]beb440c2009-11-06 04:08:544240}
4241
[email protected]b172aee2012-04-10 17:05:264242void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544243 if (encoding == last_reported_encoding_)
4244 return;
4245 last_reported_encoding_ = encoding;
4246
4247 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124248 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104249}
[email protected]f45d2a72010-03-08 23:28:354250
[email protected]1ac10dca2013-08-20 20:47:044251bool WebContentsImpl::IsHidden() {
4252 return capturer_count_ == 0 && !should_normally_be_visible_;
4253}
4254
[email protected]b0936d22013-11-28 06:47:364255RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214256 return frame_tree_.root()->render_manager();
4257}
4258
[email protected]b172aee2012-04-10 17:05:264259RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584260 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4261}
[email protected]7900bfdb2012-05-24 19:31:244262
[email protected]f8497342013-02-05 22:15:024263BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394264 return browser_plugin_guest_.get();
4265}
4266
[email protected]738f57a2013-06-29 21:06:544267void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4268 CHECK(!browser_plugin_guest_);
4269 browser_plugin_guest_.reset(guest);
4270}
4271
[email protected]f8497342013-02-05 22:15:024272BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394273 return browser_plugin_embedder_.get();
4274}
[email protected]8ff00d72012-10-23 19:12:214275
[email protected]d9030b82013-07-19 08:26:064276void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194277 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304278 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4279 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4280 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064281}
4282
4283void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304284 active_audio_players_.clear();
4285 active_video_players_.clear();
4286 audio_power_save_blocker_.reset();
4287 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064288}
4289
[email protected]fc2b46b2014-05-03 16:33:454290gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214291 gfx::Size size;
4292 if (delegate_)
4293 size = delegate_->GetSizeForNewRenderView(this);
4294 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454295 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214296 return size;
4297}
4298
[email protected]ae7eeda2014-07-04 01:53:264299void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4300 FOR_EACH_OBSERVER(
4301 WebContentsObserver, observers_, FrameDetached(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554302}
4303
[email protected]222f5822014-02-05 23:40:494304void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4305 if (!delegate_)
4306 return;
4307 const gfx::Size new_size = GetPreferredSize();
4308 if (new_size != old_size)
4309 delegate_->UpdatePreferredSize(this, new_size);
4310}
4311
dalecurtisbc6572e12014-09-12 19:22:304312void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4313 ActiveMediaPlayerMap* player_map) {
4314 const uintptr_t key =
4315 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4316 DCHECK(std::find((*player_map)[key].begin(),
4317 (*player_map)[key].end(),
4318 player_cookie) == (*player_map)[key].end());
4319 (*player_map)[key].push_back(player_cookie);
4320}
4321
4322void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4323 ActiveMediaPlayerMap* player_map) {
4324 const uintptr_t key =
4325 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4326 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4327 if (it == player_map->end())
4328 return;
4329
4330 // Remove the player.
4331 PlayerList::iterator player_it =
4332 std::find(it->second.begin(), it->second.end(), player_cookie);
4333 if (player_it != it->second.end())
4334 it->second.erase(player_it);
4335
4336 // If there are no players left, remove the map entry.
4337 if (it->second.empty())
4338 player_map->erase(it);
4339}
4340
4341void WebContentsImpl::RemoveAllMediaPlayerEntries(
4342 RenderFrameHost* render_frame_host,
4343 ActiveMediaPlayerMap* player_map) {
4344 ActiveMediaPlayerMap::iterator it =
4345 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4346 if (it == player_map->end())
4347 return;
4348 player_map->erase(it);
4349}
4350
[email protected]23f41fd2014-06-21 05:29:174351void WebContentsImpl::ResumeResponseDeferredAtStart() {
4352 FrameTreeNode* node = frame_tree_.root();
4353 node->render_manager()->ResumeResponseDeferredAtStart();
4354}
4355
[email protected]34ff1cfc2014-08-20 06:16:054356void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4357 force_disable_overscroll_content_ = force_disable;
4358 if (view_)
4359 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4360}
4361
[email protected]8ff00d72012-10-23 19:12:214362} // namespace content