blob: c6baca64d653243aae5e383c6cb91e3af71246c2 [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"
[email protected]f28ef9a32014-05-12 16:36:1038#include "content/browser/geolocation/geolocation_dispatcher_host.h"
blundellc57b93f2014-10-29 13:19:5739#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0540#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4441#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4042#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3043#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5244#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]29998f92014-06-15 03:12:1445#include "content/browser/media/midi_dispatcher_host.h"
[email protected]0bc7f3542013-10-21 15:05:5346#include "content/browser/message_port_message_filter.h"
47#include "content/browser/message_port_service.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),
335 loading_weak_factory_(this) {
[email protected]cbb1ef592013-06-05 19:49:46336 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
337 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55338 frame_tree_.SetFrameRemoveListener(
339 base::Bind(&WebContentsImpl::OnFrameRemoved,
340 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35341}
initial.commit09911bf2008-07-26 23:55:29342
[email protected]b172aee2012-04-10 17:05:26343WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32344 is_being_destroyed_ = true;
345
[email protected]21b41c7e892014-02-28 01:52:24346 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
347 // shutdown and be deleted as well.
348 frame_tree_.ForEach(
349 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
350
[email protected]d9030b82013-07-19 08:26:06351 ClearAllPowerSaveBlockers();
352
[email protected]b24b68a2012-09-24 21:57:26353 for (std::set<RenderWidgetHostImpl*>::iterator iter =
354 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
355 (*iter)->DetachDelegate();
356 }
357 created_widgets_.clear();
358
[email protected]3ab9cb82011-06-03 18:02:07359 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15360 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11361 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07362
[email protected]8ed16472014-04-11 19:02:48363 if (color_chooser_info_.get())
364 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20365
[email protected]420ae012009-04-24 05:16:32366 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32367
[email protected]ca13a442012-04-17 14:00:12368 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21369 NotificationService::current()->Notify(
370 NOTIFICATION_WEB_CONTENTS_DESTROYED,
371 Source<WebContents>(this),
372 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32373
[email protected]df0c843f2014-05-23 20:37:23374 // Destroy all frame tree nodes except for the root; this notifies observers.
375 frame_tree_.ResetForMainFrameSwap();
376 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59377
[email protected]df0c843f2014-05-23 20:37:23378 // Manually call the observer methods for the root frame tree node.
379 RenderFrameHostManager* root = GetRenderManager();
380 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27381 FOR_EACH_OBSERVER(WebContentsObserver,
382 observers_,
[email protected]df0c843f2014-05-23 20:37:23383 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27384 }
[email protected]df0c843f2014-05-23 20:37:23385 FOR_EACH_OBSERVER(WebContentsObserver,
386 observers_,
387 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27388
[email protected]df0c843f2014-05-23 20:37:23389 if (root->pending_render_view_host()) {
390 FOR_EACH_OBSERVER(WebContentsObserver,
391 observers_,
392 RenderViewDeleted(root->pending_render_view_host()));
393 }
[email protected]c06c58c2014-03-12 20:31:59394
[email protected]f273ee52013-10-18 16:05:27395 FOR_EACH_OBSERVER(WebContentsObserver,
396 observers_,
[email protected]df0c843f2014-05-23 20:37:23397 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27398
[email protected]2db9bd72012-04-13 20:20:56399 FOR_EACH_OBSERVER(WebContentsObserver,
400 observers_,
[email protected]12a46832014-05-09 13:35:58401 WebContentsDestroyed());
402
403 FOR_EACH_OBSERVER(WebContentsObserver,
404 observers_,
405 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08406
[email protected]6934a702011-12-20 00:04:51407 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10408
409 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
410 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42411}
412
[email protected]d1198fd2012-08-13 22:50:19413WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59414 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19415 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03416 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59417 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06418 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19419
[email protected]4858e432014-06-23 18:14:17420 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06421 // This makes |new_contents| act as a guest.
422 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16423 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06424 // We are instantiating a WebContents for browser plugin. Set its subframe
425 // bit to true.
426 new_contents->is_subframe_ = true;
427 }
[email protected]54944cde2012-12-09 09:24:59428 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19429 return new_contents;
430}
431
[email protected]95640212014-07-26 18:14:30432// static
433std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
434 std::vector<WebContentsImpl*> result;
435 scoped_ptr<RenderWidgetHostIterator> widgets(
436 RenderWidgetHostImpl::GetRenderWidgetHosts());
437 std::set<WebContentsImpl*> web_contents_set;
438 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
439 if (!rwh->IsRenderView())
440 continue;
441 RenderViewHost* rvh = RenderViewHost::From(rwh);
442 if (!rvh)
443 continue;
444 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
445 if (!web_contents)
446 continue;
447 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
448 if (web_contents_set.find(wci) == web_contents_set.end()) {
449 web_contents_set.insert(wci);
450 result.push_back(wci);
451 }
452 }
453 return result;
454}
455
[email protected]b0936d22013-11-28 06:47:36456RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21457 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28458}
459
[email protected]7bb761892012-07-20 09:32:47460bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
461 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44462 return OnMessageReceived(render_view_host, NULL, message);
463}
464
465bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
466 RenderFrameHost* render_frame_host,
467 const IPC::Message& message) {
468 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56469 if (GetWebUI() &&
470 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17471 return true;
[email protected]d2353452012-01-19 19:53:56472 }
[email protected]f82d57b52011-04-27 19:13:17473
[email protected]d8c660432011-12-22 20:51:25474 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
475 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33476 if (render_frame_host) {
477 while ((observer = it.GetNext()) != NULL)
478 if (observer->OnMessageReceived(message, render_frame_host))
479 return true;
480 } else {
481 while ((observer = it.GetNext()) != NULL)
482 if (observer->OnMessageReceived(message))
483 return true;
484 }
[email protected]403415a2011-01-10 18:57:53485
[email protected]1d62cf72014-02-07 21:31:57486 // Message handlers should be aware of which
487 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
488 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02489 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57490 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02491 else
[email protected]1d62cf72014-02-07 21:31:57492 render_view_message_source_ = render_view_host;
493
[email protected]724159a2010-12-30 01:11:18494 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33495 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40496 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
497 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05498 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
499 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48500 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
501 OnDocumentLoadedInFrame)
502 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00503 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
504 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
505 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
506 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48507 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
508 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
509 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
510 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19511 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
512 OnMediaPlayingNotification)
513 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
514 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11515 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
516 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18517 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
518 OnDidLoadResourceFromMemoryCache)
519 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
520 OnDidDisplayInsecureContent)
521 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
522 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25523 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26524 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21525 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20526 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
527 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20528 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
529 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16530 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10531 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50532 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50533#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:42534 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
535 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50536 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
537 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55538 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
539 OnBrowserPluginMessage(message))
thestigc4cac8f2014-09-04 21:17:50540#endif
[email protected]41225fe2013-03-29 05:32:02541 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
542 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07543 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
544 OnShowValidationMessage)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
546 OnHideValidationMessage)
547 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
548 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48549#if defined(OS_ANDROID)
550 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
551 OnFindMatchRectsReply)
552 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
553 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48554#endif
[email protected]724159a2010-12-30 01:11:18555 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33556 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44557 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57558 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18559
[email protected]724159a2010-12-30 01:11:18560 return handled;
561}
562
[email protected]b172aee2012-04-10 17:05:26563void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18564 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21565 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43566 if (delegate_)
567 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18568}
569
[email protected]d1198fd2012-08-13 22:50:19570NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56571 return controller_;
572}
573
[email protected]d1198fd2012-08-13 22:50:19574const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56575 return controller_;
576}
577
[email protected]8ff00d72012-10-23 19:12:21578BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55579 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30580}
581
[email protected]b172aee2012-04-10 17:05:26582const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24583 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32584 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51585 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31586}
587
[email protected]a093ce02013-07-22 20:53:14588const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24589 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32590 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24591 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
592}
593
594const GURL& WebContentsImpl::GetLastCommittedURL() const {
595 // We may not have a navigation entry yet.
596 NavigationEntry* entry = controller_.GetLastCommittedEntry();
597 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
598}
599
[email protected]8ff00d72012-10-23 19:12:21600WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31601 return delegate_;
602}
603
[email protected]8ff00d72012-10-23 19:12:21604void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31605 // TODO(cbentzel): remove this debugging code?
606 if (delegate == delegate_)
607 return;
608 if (delegate_)
609 delegate_->Detach(this);
610 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08611 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31612 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08613 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00614 if (view_)
[email protected]e85165c642014-06-10 14:34:31615 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08616 }
[email protected]be1f56ab2011-12-22 06:55:31617}
618
[email protected]8ff00d72012-10-23 19:12:21619RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21620 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41621 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16622}
623
[email protected]60eca4eb2013-12-06 00:02:16624RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41625 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16626}
627
[email protected]9c9343b2014-03-08 02:56:07628RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
629 if (!frame_tree_.GetFocusedFrame())
630 return NULL;
631 return frame_tree_.GetFocusedFrame()->current_frame_host();
632}
633
[email protected]a86c0e962013-12-17 17:10:39634void WebContentsImpl::ForEachFrame(
635 const base::Callback<void(RenderFrameHost*)>& on_frame) {
636 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
637}
638
639void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
640 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
641 delete message;
642}
643
[email protected]b172aee2012-04-10 17:05:26644RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21645 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31646}
647
[email protected]6b618e62012-08-16 12:59:18648int WebContentsImpl::GetRoutingID() const {
649 if (!GetRenderViewHost())
650 return MSG_ROUTING_NONE;
651
652 return GetRenderViewHost()->GetRoutingID();
653}
654
[email protected]44470a22013-01-24 01:21:54655int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
656 return fullscreen_widget_routing_id_;
657}
658
[email protected]b172aee2012-04-10 17:05:26659RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21660 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31661}
662
[email protected]4aebbca2013-09-17 22:26:49663RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
664 const {
665 RenderWidgetHost* const widget_host =
666 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
667 GetFullscreenWidgetRoutingID());
668 return widget_host ? widget_host->GetView() : NULL;
669}
670
[email protected]8ff00d72012-10-23 19:12:21671WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31672 return view_.get();
673}
674
[email protected]95640212014-07-26 18:14:30675void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
676 if (mode == accessibility_mode_)
677 return;
678
679 accessibility_mode_ = mode;
680 frame_tree_.ForEach(
681 base::Bind(&ForEachFrameInternal,
682 base::Bind(&SetAccessibilityModeOnFrame, mode)));
683 frame_tree_.ForEach(
684 base::Bind(&ForEachPendingFrameInternal,
685 base::Bind(&SetAccessibilityModeOnFrame, mode)));
686}
687
688void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50689 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30690}
691
692void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50693 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30694}
695
zhenw1f790352014-10-30 00:06:04696void WebContentsImpl::ClearNavigationTransitionData() {
697 FrameTreeNode* node = frame_tree_.root();
698 node->render_manager()->ClearNavigationTransitionData();
699}
700
[email protected]8ff00d72012-10-23 19:12:21701WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56702 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03703 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
704 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22705 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58706 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22707 web_ui->SetController(controller);
708 return web_ui;
709 }
710
711 delete web_ui;
712 return NULL;
713}
714
[email protected]8ff00d72012-10-23 19:12:21715WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21716 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
717 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31718}
719
[email protected]8ff00d72012-10-23 19:12:21720WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21721 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34722}
723
[email protected]86ef6a392012-05-11 22:03:11724void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22725 if (GetUserAgentOverride() == override)
726 return;
727
728 renderer_preferences_.user_agent_override = override;
729
730 // Send the new override string to the renderer.
731 RenderViewHost* host = GetRenderViewHost();
732 if (host)
733 host->SyncRendererPrefs();
734
735 // Reload the page if a load is currently in progress to avoid having
736 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27737 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22738 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
739 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53740
741 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
742 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11743}
744
745const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22746 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11747}
748
[email protected]95640212014-07-26 18:14:30749void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
750 AddAccessibilityMode(AccessibilityModeTreeOnly);
751}
752
753bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
754 return accessibility_mode_ == AccessibilityModeTreeOnly;
755}
756
757bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
758 return accessibility_mode_ == AccessibilityModeComplete;
759}
760
[email protected]2ceee8f2014-01-14 18:02:08761#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41762void WebContentsImpl::SetParentNativeViewAccessible(
763gfx::NativeViewAccessible accessible_parent) {
764 accessible_parent_ = accessible_parent;
[email protected]95640212014-07-26 18:14:30765 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
766 if (rfh)
767 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41768}
769#endif
770
[email protected]fcf75d42013-12-03 20:11:26771const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55772 // Transient entries take precedence. They are used for interstitial pages
773 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23774 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08775 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21776 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30777 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23778 if (entry) {
[email protected]b5cca982011-05-26 04:42:08779 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23780 }
[email protected]fa944cb82013-11-15 17:51:21781 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
782 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58783 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54784 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32785 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54786 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35787 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26788 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54789 if (!title.empty())
790 return title;
791 }
792 }
793
794 // We use the title for the last committed entry rather than a pending
795 // navigation entry. For example, when the user types in a URL, we want to
796 // keep the old page's title until the new load has committed and we get a new
797 // title.
[email protected]96d185d2009-04-24 03:28:54798 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32799
[email protected]9eeafc012013-11-25 23:49:47800 // We make an exception for initial navigations.
801 if (controller_.IsInitialNavigation()) {
802 // We only want to use the title from the visible entry in one of two cases:
803 // 1. There's already a committed entry for an initial navigation, in which
804 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
805 // 2. The pending entry has been explicitly assigned a title to display.
806 //
807 // If there's no last committed entry and no assigned title, we should fall
808 // back to |page_title_when_no_navigation_entry_| rather than showing the
809 // URL.
810 if (entry ||
811 (controller_.GetVisibleEntry() &&
812 !controller_.GetVisibleEntry()->GetTitle().empty())) {
813 entry = controller_.GetVisibleEntry();
814 }
815 }
[email protected]59167c22013-06-03 18:07:32816
[email protected]45d0ef7f2011-01-05 13:46:23817 if (entry) {
[email protected]b5cca982011-05-26 04:42:08818 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23819 }
[email protected]987fc3a2011-05-26 14:18:09820
821 // |page_title_when_no_navigation_entry_| is finally used
822 // if no title cannot be retrieved.
823 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54824}
825
[email protected]b172aee2012-04-10 17:05:26826int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46827 return GetMaxPageIDForSiteInstance(GetSiteInstance());
828}
829
[email protected]b172aee2012-04-10 17:05:26830int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
831 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33832 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
833 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46834
[email protected]b6583592012-01-25 19:52:33835 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34836}
837
[email protected]b172aee2012-04-10 17:05:26838void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46839 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
840}
841
[email protected]b172aee2012-04-10 17:05:26842void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33843 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46844 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33845 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34846}
847
[email protected]ec6c05f2013-10-23 18:41:57848void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
849 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
850 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57851}
852
creiscce56cd2014-09-29 22:45:22853SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21854 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54855}
856
creiscce56cd2014-09-29 22:45:22857SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
858 RenderViewHostImpl* dest_rvh =
859 GetRenderManager()->pending_render_view_host() ?
860 GetRenderManager()->pending_render_view_host() :
861 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58862 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38863}
864
[email protected]b172aee2012-04-10 17:05:26865bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31866 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49867}
868
[email protected]6dfed692014-05-22 04:18:03869bool WebContentsImpl::IsLoadingToDifferentDocument() const {
870 return is_loading_ && is_load_to_different_document_;
871}
872
[email protected]b172aee2012-04-10 17:05:26873bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03874 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31875}
876
[email protected]b172aee2012-04-10 17:05:26877const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31878 return load_state_;
879}
880
[email protected]fcf75d42013-12-03 20:11:26881const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31882 return load_state_host_;
883}
884
[email protected]b172aee2012-04-10 17:05:26885uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31886 return upload_size_;
887}
888
[email protected]b172aee2012-04-10 17:05:26889uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31890 return upload_position_;
891}
892
[email protected]1ae93fb2013-06-14 03:38:56893std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56894 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39895 frame_tree_.ForEach(base::Bind(&CollectSites,
896 base::Unretained(GetBrowserContext()),
897 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56898 return sites;
899}
900
[email protected]b172aee2012-04-10 17:05:26901const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54902 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31903}
904
[email protected]b172aee2012-04-10 17:05:26905bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31906 return displayed_insecure_content_;
907}
908
[email protected]222f5822014-02-05 23:40:49909void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25910 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55911 ++capturer_count_;
912 DVLOG(1) << "There are now " << capturer_count_
913 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49914
915 // Note: This provides a hint to upstream code to size the views optimally
916 // for quality (e.g., to avoid scaling).
917 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
918 preferred_size_for_capture_ = capture_size;
919 OnPreferredSizeChanged(preferred_size_);
920 }
[email protected]54597982013-02-06 01:59:55921}
922
923void WebContentsImpl::DecrementCapturerCount() {
924 --capturer_count_;
925 DVLOG(1) << "There are now " << capturer_count_
926 << " capturing(s) of WebContentsImpl@" << this;
927 DCHECK_LE(0, capturer_count_);
928
[email protected]5a652232013-02-12 06:15:25929 if (is_being_destroyed_)
930 return;
931
[email protected]222f5822014-02-05 23:40:49932 if (capturer_count_ == 0) {
933 const gfx::Size old_size = preferred_size_for_capture_;
934 preferred_size_for_capture_ = gfx::Size();
935 OnPreferredSizeChanged(old_size);
936 }
937
[email protected]1ac10dca2013-08-20 20:47:04938 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55939 DVLOG(1) << "Executing delayed WasHidden().";
940 WasHidden();
941 }
[email protected]be1f56ab2011-12-22 06:55:31942}
943
[email protected]f2bd40812013-07-20 04:30:44944int WebContentsImpl::GetCapturerCount() const {
945 return capturer_count_;
946}
947
miu50f97892014-09-22 22:49:52948bool WebContentsImpl::IsAudioMuted() const {
949 return audio_muter_.get() && audio_muter_->is_muting();
950}
951
952void WebContentsImpl::SetAudioMuted(bool mute) {
953 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
954 << " for WebContentsImpl@" << this;
955
956 if (mute == IsAudioMuted())
957 return;
958
959 if (mute) {
960 if (!audio_muter_)
961 audio_muter_.reset(new WebContentsAudioMuter(this));
962 audio_muter_->StartMuting();
963 } else {
964 DCHECK(audio_muter_);
965 audio_muter_->StopMuting();
966 }
967
968 // Notification for UI updates in response to the changed muting state.
969 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
970}
971
[email protected]b172aee2012-04-10 17:05:26972bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31973 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
974 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
975 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49976}
977
[email protected]b172aee2012-04-10 17:05:26978void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
979 int error_code) {
[email protected]443b80e2010-12-14 00:42:23980 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34981 return;
982
[email protected]443b80e2010-12-14 00:42:23983 crashed_status_ = status;
984 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21985 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34986}
987
[email protected]b172aee2012-04-10 17:05:26988base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31989 return crashed_status_;
990}
991
[email protected]b172aee2012-04-10 17:05:26992bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31993 return is_being_destroyed_;
994}
995
[email protected]7f924832014-08-09 05:57:22996void WebContentsImpl::NotifyNavigationStateChanged(
997 InvalidateTypes changed_flags) {
dalecurtisbc6572e12014-09-12 19:22:30998 // Create and release the audio power save blocker depending on whether the
999 // tab is actively producing audio or not.
1000 if (changed_flags == INVALIDATE_TYPE_TAB &&
1001 AudioStreamMonitor::monitoring_available()) {
1002 if (WasRecentlyAudible()) {
1003 if (!audio_power_save_blocker_)
1004 CreateAudioPowerSaveBlocker();
1005 } else {
1006 audio_power_save_blocker_.reset();
1007 }
1008 }
1009
[email protected]d5f942ba2008-09-26 19:30:341010 if (delegate_)
1011 delegate_->NavigationStateChanged(this, changed_flags);
1012}
1013
[email protected]9a890452014-02-13 22:21:021014base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1015 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331016}
1017
[email protected]9e2e4632012-07-27 16:38:411018void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541019 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591020
[email protected]948481d2014-06-11 18:32:221021 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1022 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591023 iter != widgets.end();
1024 iter++) {
[email protected]948481d2014-06-11 18:32:221025 if (*iter) {
1026 (*iter)->Show();
[email protected]789e9152009-08-04 21:59:431027#if defined(OS_MACOSX)
[email protected]948481d2014-06-11 18:32:221028 (*iter)->SetActive(true);
[email protected]789e9152009-08-04 21:59:431029#endif
[email protected]de3c5d82014-05-28 22:12:591030 }
[email protected]789e9152009-08-04 21:59:431031 }
[email protected]96d185d2009-04-24 03:28:541032
[email protected]9a890452014-02-13 22:21:021033 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381034
[email protected]b9769d82012-02-10 00:23:591035 // The resize rect might have changed while this was inactive -- send the new
1036 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581037 RenderViewHostImpl* rvh =
1038 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591039 if (rvh) {
1040 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1041 }
[email protected]96d185d2009-04-24 03:28:541042
dalecurtisbc6572e12014-09-12 19:22:301043 // Restore power save blocker if there are active video players running.
1044 if (!active_video_players_.empty() && !video_power_save_blocker_)
1045 CreateVideoPowerSaveBlocker();
1046
[email protected]c0d9d5672013-10-09 07:38:031047 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1048
[email protected]54597982013-02-06 01:59:551049 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311050}
1051
[email protected]b172aee2012-04-10 17:05:261052void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551053 // If there are entities capturing screenshots or video (e.g., mirroring),
1054 // don't activate the "disable rendering" optimization.
1055 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521056 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551057 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261058 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521059 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331060 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521061 // calls us).
[email protected]948481d2014-06-11 18:32:221062 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
1063 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:591064 iter != widgets.end();
1065 iter++) {
[email protected]948481d2014-06-11 18:32:221066 if (*iter)
1067 (*iter)->Hide();
[email protected]de3c5d82014-05-28 22:12:591068 }
dalecurtisbc6572e12014-09-12 19:22:301069
1070 // Release any video power save blockers held as video is not visible.
1071 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541072 }
1073
[email protected]c0d9d5672013-10-09 07:38:031074 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1075
[email protected]54597982013-02-06 01:59:551076 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371077}
1078
[email protected]b172aee2012-04-10 17:05:261079bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311080 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271081 return WillNotifyDisconnection() &&
1082 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581083 !static_cast<RenderViewHostImpl*>(
1084 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311085}
1086
[email protected]1c3f80bd2014-04-08 23:02:061087void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1088 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1089 for_cross_site_transition);
1090}
1091
[email protected]b172aee2012-04-10 17:05:261092void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211093 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401094 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271095}
1096
[email protected]b172aee2012-04-10 17:05:261097WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441098 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451099 // We pass our own opener so that the cloned page can access it if it was
1100 // before.
[email protected]54944cde2012-12-09 09:24:591101 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451102 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591103 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191104 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221105 FOR_EACH_OBSERVER(WebContentsObserver,
1106 observers_,
1107 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271108 return tc;
1109}
1110
[email protected]14392a52012-05-02 20:28:441111void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211112 const NotificationSource& source,
1113 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441114 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211115 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1116 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031117 RenderWidgetHostView* view = host->GetView();
1118 if (view == GetFullscreenRenderWidgetHostView()) {
1119 // We cannot just call view_->RestoreFocus() here. On some platforms,
1120 // attempting to focus the currently-invisible WebContentsView will be
1121 // flat-out ignored. Therefore, this boolean is used to track whether
1122 // we will request focus after the fullscreen widget has been
1123 // destroyed.
1124 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1125 } else {
1126 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1127 i != pending_widget_views_.end(); ++i) {
1128 if (host->GetView() == i->second) {
1129 pending_widget_views_.erase(i);
1130 break;
1131 }
[email protected]bafe6cd2012-05-23 23:09:501132 }
1133 }
1134 break;
1135 }
[email protected]14392a52012-05-02 20:28:441136 default:
1137 NOTREACHED();
1138 }
1139}
1140
[email protected]ec6c05f2013-10-23 18:41:571141WebContents* WebContentsImpl::GetWebContents() {
1142 return this;
1143}
1144
[email protected]54944cde2012-12-09 09:24:591145void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211146 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361147 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211148 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431149 should_normally_be_visible_ = !params.initially_hidden;
1150
[email protected]fa944cb82013-11-15 17:51:211151 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041152 params.browser_context, params.site_instance, params.routing_id,
1153 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191154
[email protected]fc2b46b2014-05-03 16:33:451155 WebContentsViewDelegate* delegate =
1156 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1157
1158 if (browser_plugin_guest_) {
1159 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1160 this, delegate, &render_view_host_delegate_view_));
1161
1162 WebContentsViewGuest* rv = new WebContentsViewGuest(
1163 this, browser_plugin_guest_.get(), platform_view.Pass(),
1164 render_view_host_delegate_view_);
1165 render_view_host_delegate_view_ = rv;
1166 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191167 } else {
[email protected]fc2b46b2014-05-03 16:33:451168 // Regular WebContentsView.
1169 view_.reset(CreateWebContentsView(
1170 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191171 }
[email protected]fc2b46b2014-05-03 16:33:451172 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191173 CHECK(view_.get());
1174
[email protected]ed245db2012-12-18 08:00:451175 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591176 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191177
1178 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101179 if (opener_)
1180 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191181
1182 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211183 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1184 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101185
1186 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
[email protected]29998f92014-06-15 03:12:141187 midi_dispatcher_host_.reset(new MidiDispatcherHost(this));
[email protected]f28ef9a32014-05-12 16:36:101188
[email protected]01f83f92014-06-17 14:41:541189 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091190 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541191
mlamouriefdca9d2014-09-16 16:55:401192 manifest_manager_host_.reset(new ManifestManagerHost(this));
1193
[email protected]c7654a232013-06-12 21:04:441194#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101195 date_time_chooser_.reset(new DateTimeChooserAndroid());
1196#endif
[email protected]d1198fd2012-08-13 22:50:191197}
1198
[email protected]7fff43e2013-05-21 20:21:101199void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1200 RemoveDestructionObserver(web_contents);
1201
[email protected]14392a52012-05-02 20:28:441202 // Clear the opener if it has been closed.
1203 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441204 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511205 return;
[email protected]14392a52012-05-02 20:28:441206 }
[email protected]ceee8cd2013-03-08 04:59:511207 // Clear a pending contents that has been closed before being shown.
1208 for (PendingContents::iterator iter = pending_contents_.begin();
1209 iter != pending_contents_.end();
1210 ++iter) {
1211 if (iter->second != web_contents)
1212 continue;
1213 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511214 return;
1215 }
1216 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441217}
1218
[email protected]7fff43e2013-05-21 20:21:101219void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1220 if (!ContainsKey(destruction_observers_, web_contents)) {
1221 destruction_observers_[web_contents] =
1222 new DestructionObserver(this, web_contents);
1223 }
1224}
1225
1226void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1227 DestructionObservers::iterator iter =
1228 destruction_observers_.find(web_contents);
1229 if (iter != destruction_observers_.end()) {
1230 delete destruction_observers_[web_contents];
1231 destruction_observers_.erase(iter);
1232 }
1233}
1234
[email protected]b172aee2012-04-10 17:05:261235void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311236 observers_.AddObserver(observer);
1237}
1238
[email protected]b172aee2012-04-10 17:05:261239void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311240 observers_.RemoveObserver(observer);
1241}
1242
[email protected]948481d2014-06-11 18:32:221243std::set<RenderWidgetHostView*>
1244WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1245 std::set<RenderWidgetHostView*> set;
1246 if (ShowingInterstitialPage()) {
1247 set.insert(GetRenderWidgetHostView());
1248 } else {
1249 ForEachFrame(
1250 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1251 }
[email protected]de3c5d82014-05-28 22:12:591252 return set;
1253}
1254
[email protected]b172aee2012-04-10 17:05:261255void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341256 if (delegate_)
1257 delegate_->ActivateContents(this);
1258}
1259
[email protected]b172aee2012-04-10 17:05:261260void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121261 if (delegate_)
1262 delegate_->DeactivateContents(this);
1263}
1264
[email protected]b172aee2012-04-10 17:05:261265void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481266 if (delegate_)
1267 delegate_->LostCapture();
1268}
1269
[email protected]b24b68a2012-09-24 21:57:261270void WebContentsImpl::RenderWidgetDeleted(
1271 RenderWidgetHostImpl* render_widget_host) {
1272 if (is_being_destroyed_) {
1273 // |created_widgets_| might have been destroyed.
1274 return;
1275 }
1276
1277 std::set<RenderWidgetHostImpl*>::iterator iter =
1278 created_widgets_.find(render_widget_host);
1279 if (iter != created_widgets_.end())
1280 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541281
1282 if (render_widget_host &&
1283 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491284 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1285 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541286 FOR_EACH_OBSERVER(WebContentsObserver,
1287 observers_,
1288 DidDestroyFullscreenWidget(
1289 fullscreen_widget_routing_id_));
1290 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031291 if (fullscreen_widget_had_focus_at_shutdown_)
1292 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541293 }
[email protected]b24b68a2012-09-24 21:57:261294}
1295
miu9e14e492014-10-25 02:39:041296void WebContentsImpl::RenderWidgetGotFocus(
1297 RenderWidgetHostImpl* render_widget_host) {
1298 // Notify the delegate if an embedded fullscreen widget was focused.
1299 if (delegate_ && render_widget_host &&
1300 delegate_->EmbedsFullscreenWidget() &&
1301 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1302 delegate_->WebContentsFocused(this);
1303}
1304
[email protected]b172aee2012-04-10 17:05:261305bool WebContentsImpl::PreHandleKeyboardEvent(
1306 const NativeWebKeyboardEvent& event,
1307 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481308 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131309 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481310}
1311
[email protected]b172aee2012-04-10 17:05:261312void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101313 if (browser_plugin_embedder_ &&
1314 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1315 return;
1316 }
[email protected]63954792011-07-11 04:17:481317 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131318 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481319}
1320
[email protected]d92026ef2014-03-03 21:04:131321bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461322 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191323#if !defined(OS_MACOSX)
1324 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1325 // isn't done for two reasons:
1326 // -the OS already has a gesture to do this through pinch-zoom
1327 // -if a user starts an inertial scroll, let's go, and presses control
1328 // (i.e. control+tab) then the OS's buffered scroll events will come in
1329 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521330 if (delegate_ &&
1331 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551332 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1333 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1334 // gestures, which are regrettably easy to trigger accidentally.
1335 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521336 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1337 return true;
1338 }
[email protected]bccc4472013-04-18 16:37:191339#endif
[email protected]fb3f066e2013-02-12 19:12:521340 return false;
1341}
1342
[email protected]04bce562014-01-30 05:34:541343bool WebContentsImpl::PreHandleGestureEvent(
1344 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031345 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541346}
1347
[email protected]bab38af2014-03-30 17:37:291348bool WebContentsImpl::HandleGestureEvent(
1349 const blink::WebGestureEvent& event) {
1350 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1351 // Use them to implement browser zoom, as for HandleWheelEvent above.
1352 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331353 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291354 // The scale difference necessary to trigger a zoom action. Derived from
1355 // experimentation to find a value that feels reasonable.
1356 const float kZoomStepValue = 0.6f;
1357
1358 // Find the (absolute) thresholds on either side of the current zoom factor,
1359 // then convert those to actual numbers to trigger a zoom in or out.
1360 // This logic deliberately makes the range around the starting zoom value
1361 // for the gesture twice as large as the other ranges (i.e., the notches are
1362 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1363 // so that it's easier to get back to your starting point than it is to
1364 // overshoot.
1365 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1366 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1367 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1368 : -backStep;
1369 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1370 : backStep;
1371
[email protected]fb546cb2014-04-28 14:09:371372 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291373 if (totalPinchGestureAmount_ > zoomInThreshold) {
1374 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461375 if (delegate_)
1376 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291377 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1378 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461379 if (delegate_)
1380 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291381 }
1382 return true;
1383 }
1384
1385 return false;
1386}
1387
[email protected]b172aee2012-04-10 17:05:261388void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431389 if (delegate_)
1390 delegate_->HandleMouseDown();
1391}
1392
[email protected]b172aee2012-04-10 17:05:261393void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481394 if (delegate_)
1395 delegate_->HandleMouseUp();
1396}
1397
[email protected]590a634e2012-07-19 16:38:231398void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481399 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231400 delegate_->HandlePointerActivate();
1401}
1402
1403void WebContentsImpl::HandleGestureBegin() {
1404 if (delegate_)
1405 delegate_->HandleGestureBegin();
1406}
1407
1408void WebContentsImpl::HandleGestureEnd() {
1409 if (delegate_)
1410 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481411}
1412
[email protected]b172aee2012-04-10 17:05:261413void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491414 // This method is being called to enter or leave renderer-initiated fullscreen
1415 // mode. Either way, make sure any existing fullscreen widget is shut down
1416 // first.
1417 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1418 if (widget_view)
1419 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1420
[email protected]8a5e0ca2011-08-25 06:30:471421 if (delegate_)
1422 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371423
1424 FOR_EACH_OBSERVER(WebContentsObserver,
1425 observers_,
1426 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471427}
1428
[email protected]b172aee2012-04-10 17:05:261429bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381430 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121431}
1432
[email protected]a9c81f02012-06-01 00:15:441433void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1434 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371435 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441436 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371437 } else {
1438 GotResponseToLockMouseRequest(false);
1439 }
1440}
1441
[email protected]b172aee2012-04-10 17:05:261442void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371443 if (delegate_)
1444 delegate_->LostMouseLock();
1445}
1446
[email protected]bafe6cd2012-05-23 23:09:501447void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201448 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501449 int route_id,
[email protected]227692c52013-05-31 22:43:041450 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131451 const ViewHostMsg_CreateWindow_Params& params,
1452 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501453 // We usually create the new window in the same BrowsingInstance (group of
1454 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551455 // if the opener is being suppressed (in a non-guest), we create a new
1456 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251457 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551458
[email protected]04cbd3d2013-12-04 04:58:201459 // If the opener is to be suppressed, the new window can be in any process.
1460 // Since routing ids are process specific, we must not have one passed in
1461 // as argument here.
1462 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1463
[email protected]bafe6cd2012-05-23 23:09:501464 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551465 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571466 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501467 GetSiteInstance();
1468
[email protected]04cbd3d2013-12-04 04:58:201469 // A message to create a new window can only come from the active process for
1470 // this WebContentsImpl instance. If any other process sends the request,
1471 // it is invalid and the process must be terminated.
1472 if (GetRenderProcessHost()->GetID() != render_process_id) {
1473 base::ProcessHandle process_handle =
1474 RenderProcessHost::FromID(render_process_id)->GetHandle();
1475 if (process_handle != base::kNullProcessHandle) {
1476 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391477 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
thestigc4cac8f2014-09-04 21:17:501478 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201479 }
1480 return;
1481 }
1482
[email protected]d1198fd2012-08-13 22:50:191483 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341484 //
1485 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301486 const std::string& partition_id =
1487 GetContentClient()->browser()->
1488 GetStoragePartitionIdForSite(GetBrowserContext(),
1489 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461490 StoragePartition* partition = BrowserContext::GetStoragePartition(
1491 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411492 DOMStorageContextWrapper* dom_storage_context =
1493 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191494 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1495 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1496 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371497
1498 if (delegate_ &&
1499 !delegate_->ShouldCreateWebContents(this,
1500 route_id,
1501 params.window_container_type,
1502 params.frame_name,
1503 params.target_url,
1504 partition_id,
1505 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011506 if (route_id != MSG_ROUTING_NONE &&
1507 !RenderViewHost::FromID(render_process_id, route_id)) {
1508 // If the embedder didn't create a WebContents for this route, we need to
1509 // delete the RenderView that had already been created.
1510 Send(new ViewMsg_Close(route_id));
1511 }
[email protected]dd6730412013-08-14 15:03:371512 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1513 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1514 main_frame_route_id);
1515 return;
1516 }
1517
1518 // Create the new web contents. This will automatically create the new
1519 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461520 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591521 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041522 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061523 create_params.opener = this;
1524 create_params.opener_suppressed = params.opener_suppressed;
1525 if (params.disposition == NEW_BACKGROUND_TAB)
1526 create_params.initially_hidden = true;
1527
[email protected]4858e432014-06-23 18:14:171528 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551529 if (!is_guest) {
1530 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451531 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171532 new_contents = static_cast<WebContentsImpl*>(
1533 WebContents::Create(create_params));
1534 } else {
1535 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551536 }
[email protected]50d326e2014-05-20 17:59:061537 new_contents->GetController().SetSessionStorageNamespace(
1538 partition_id,
1539 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261540 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191541
[email protected]c4538072013-03-18 02:17:551542 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341543 // will be shown immediately).
1544 if (!params.opener_suppressed) {
1545 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451546 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501547
[email protected]d70bea92013-04-05 04:23:341548 // TODO(brettw): It seems bogus that we have to call this function on the
1549 // newly created object and give it one of its own member variables.
lazyboy549b3b42014-10-20 17:16:041550 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false);
[email protected]d70bea92013-04-05 04:23:341551 }
[email protected]bafe6cd2012-05-23 23:09:501552 // Save the created window associated with the route so we can show it
1553 // later.
1554 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1555 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101556 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501557 }
1558
1559 if (delegate_) {
1560 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071561 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131562 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501563 }
1564
1565 if (params.opener_suppressed) {
1566 // When the opener is suppressed, the original renderer cannot access the
1567 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001568 bool was_blocked = false;
1569 if (delegate_) {
1570 gfx::Rect initial_pos;
1571 delegate_->AddNewContents(
1572 this, new_contents, params.disposition, initial_pos,
1573 params.user_gesture, &was_blocked);
1574 }
1575 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211576 OpenURLParams open_params(params.target_url,
1577 Referrer(),
1578 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351579 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211580 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301581 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001582 new_contents->OpenURL(open_params);
1583 }
[email protected]bafe6cd2012-05-23 23:09:501584 }
1585}
1586
[email protected]a8504022013-12-04 20:23:511587void WebContentsImpl::CreateNewWidget(int render_process_id,
1588 int route_id,
[email protected]180ef242013-11-07 06:50:461589 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511590 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501591}
1592
[email protected]a8504022013-12-04 20:23:511593void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1594 int route_id) {
1595 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501596}
1597
[email protected]a8504022013-12-04 20:23:511598void WebContentsImpl::CreateNewWidget(int render_process_id,
1599 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501600 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461601 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211602 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511603 // A message to create a new widget can only come from the active process for
1604 // this WebContentsImpl instance. If any other process sends the request,
1605 // it is invalid and the process must be terminated.
1606 if (process->GetID() != render_process_id) {
1607 base::ProcessHandle process_handle =
1608 RenderProcessHost::FromID(render_process_id)->GetHandle();
1609 if (process_handle != base::kNullProcessHandle) {
1610 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391611 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
thestigc4cac8f2014-09-04 21:17:501612 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511613 }
1614 return;
1615 }
1616
[email protected]bafe6cd2012-05-23 23:09:501617 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041618 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261619 created_widgets_.insert(widget_host);
1620
[email protected]cfd80b02014-05-01 17:46:481621 RenderWidgetHostViewBase* widget_view =
1622 static_cast<RenderWidgetHostViewBase*>(
1623 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191624 if (!widget_view)
1625 return;
[email protected]bafe6cd2012-05-23 23:09:501626 if (!is_fullscreen) {
1627 // Popups should not get activated.
1628 widget_view->SetPopupType(popup_type);
1629 }
1630 // Save the created widget associated with the route so we can show it later.
1631 pending_widget_views_[route_id] = widget_view;
1632
1633#if defined(OS_MACOSX)
1634 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1635 // to allow it to survive the trip without being hosted.
1636 base::mac::NSObjectRetain(widget_view->GetNativeView());
1637#endif
1638}
1639
1640void WebContentsImpl::ShowCreatedWindow(int route_id,
1641 WindowOpenDisposition disposition,
1642 const gfx::Rect& initial_pos,
1643 bool user_gesture) {
1644 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001645 if (contents) {
1646 WebContentsDelegate* delegate = GetDelegate();
1647 if (delegate) {
1648 delegate->AddNewContents(
1649 this, contents, disposition, initial_pos, user_gesture, NULL);
1650 }
1651 }
[email protected]bafe6cd2012-05-23 23:09:501652}
1653
1654void WebContentsImpl::ShowCreatedWidget(int route_id,
1655 const gfx::Rect& initial_pos) {
1656 ShowCreatedWidget(route_id, false, initial_pos);
1657}
1658
1659void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1660 ShowCreatedWidget(route_id, true, gfx::Rect());
1661}
1662
1663void WebContentsImpl::ShowCreatedWidget(int route_id,
1664 bool is_fullscreen,
1665 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481666 RenderWidgetHostViewBase* widget_host_view =
1667 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501668 if (!widget_host_view)
1669 return;
[email protected]cfd80b02014-05-01 17:46:481670
1671 RenderWidgetHostView* view = NULL;
1672 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1673 if (guest && guest->embedder_web_contents()) {
1674 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1675 } else {
1676 view = GetRenderWidgetHostView();
1677 }
1678
[email protected]4aebbca2013-09-17 22:26:491679 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311680 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031681 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311682 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491683 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1684 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1685 delegate_->ToggleFullscreenModeForTab(this, true);
1686 } else {
[email protected]cfd80b02014-05-01 17:46:481687 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491688 }
[email protected]4aebbca2013-09-17 22:26:491689 FOR_EACH_OBSERVER(WebContentsObserver,
1690 observers_,
1691 DidShowFullscreenWidget(route_id));
1692 if (!widget_host_view->HasFocus())
1693 widget_host_view->Focus();
1694 } else {
[email protected]cfd80b02014-05-01 17:46:481695 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491696 }
[email protected]89054502012-06-03 10:29:241697
1698 RenderWidgetHostImpl* render_widget_host_impl =
1699 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1700 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311701 // Only allow privileged mouse lock for fullscreen render widget, which is
1702 // used to implement Pepper Flash fullscreen.
1703 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501704
1705#if defined(OS_MACOSX)
1706 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1707 // properly embedded (or purposefully ignored) we can release the retain we
1708 // took in CreateNewWidget().
1709 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1710#endif
1711}
1712
1713WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1714 PendingContents::iterator iter = pending_contents_.find(route_id);
1715
1716 // Certain systems can block the creation of new windows. If we didn't succeed
1717 // in creating one, just return NULL.
1718 if (iter == pending_contents_.end()) {
1719 return NULL;
1720 }
1721
1722 WebContentsImpl* new_contents = iter->second;
1723 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101724 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501725
[email protected]d70bea92013-04-05 04:23:341726 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251727 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341728 return new_contents;
1729
[email protected]bafe6cd2012-05-23 23:09:501730 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1731 !new_contents->GetRenderViewHost()->GetView())
1732 return NULL;
1733
creis82dd6af2014-09-17 16:30:451734 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501735 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1736 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
creis82dd6af2014-09-17 16:30:451737 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
1738
[email protected]bafe6cd2012-05-23 23:09:501739 return new_contents;
1740}
1741
1742RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1743 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1744 if (iter == pending_widget_views_.end()) {
1745 DCHECK(false);
1746 return NULL;
1747 }
1748
1749 RenderWidgetHostView* widget_host_view = iter->second;
1750 pending_widget_views_.erase(route_id);
1751
1752 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1753 if (!widget_host->GetProcess()->HasConnection()) {
1754 // The view has gone away or the renderer crashed. Nothing to do.
1755 return NULL;
1756 }
1757
1758 return widget_host_view;
1759}
1760
[email protected]f13b4202012-06-12 23:53:231761void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091762 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211763 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371764 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231765 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371766 } else {
1767 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041768 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371769 scoped_ptr<MediaStreamUI>());
1770 }
[email protected]f13b4202012-06-12 23:53:231771}
1772
grunell657d4d82014-09-18 00:09:431773bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1774 MediaStreamType type) {
1775 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1776 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1777 return delegate_ &&
1778 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1779}
1780
[email protected]cc9200432013-07-23 23:02:401781SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1782 SiteInstance* instance) {
1783 return controller_.GetSessionStorageNamespace(instance);
1784}
1785
[email protected]6de7fc482014-06-06 10:46:441786SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1787 return controller_.GetSessionStorageNamespaceMap();
1788}
1789
[email protected]9b159a52013-10-03 17:24:551790FrameTree* WebContentsImpl::GetFrameTree() {
1791 return &frame_tree_;
1792}
1793
[email protected]95640212014-07-26 18:14:301794AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1795 return accessibility_mode_;
1796}
1797
[email protected]31a71eaf2014-03-13 01:47:361798void WebContentsImpl::AccessibilityEventReceived(
1799 const std::vector<AXEventNotificationDetails>& details) {
1800 FOR_EACH_OBSERVER(
1801 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1802}
1803
dmazzonia656928e2014-09-15 20:28:541804RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
1805 int browser_plugin_instance_id) {
1806 BrowserPluginGuestManager* guest_manager =
1807 GetBrowserContext()->GetGuestManager();
1808 WebContents* guest = guest_manager->GetGuestByInstanceID(
1809 this, browser_plugin_instance_id);
1810 if (!guest)
1811 return NULL;
1812 return guest->GetMainFrame();
1813}
1814
blundellc57b93f2014-10-29 13:19:571815GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
1816 return geolocation_service_context_.get();
1817}
1818
[email protected]edc3af82013-12-12 21:24:071819void WebContentsImpl::OnShowValidationMessage(
1820 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291821 const base::string16& main_text,
1822 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071823 if (delegate_)
1824 delegate_->ShowValidationMessage(
1825 this, anchor_in_root_view, main_text, sub_text);
1826}
1827
1828void WebContentsImpl::OnHideValidationMessage() {
1829 if (delegate_)
1830 delegate_->HideValidationMessage(this);
1831}
1832
1833void WebContentsImpl::OnMoveValidationMessage(
1834 const gfx::Rect& anchor_in_root_view) {
1835 if (delegate_)
1836 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1837}
1838
[email protected]32deec62013-05-15 23:55:041839void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1840 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441841 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041842}
1843
[email protected]95640212014-07-26 18:14:301844BrowserAccessibilityManager*
1845 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1846 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1847 return rfh ? rfh->browser_accessibility_manager() : NULL;
1848}
1849
1850BrowserAccessibilityManager*
1851 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1852 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1853 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1854}
1855
[email protected]b172aee2012-04-10 17:05:261856void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491857 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231858 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491859 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331860}
1861
[email protected]b172aee2012-04-10 17:05:261862void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341863 if (delegate_)
1864 delegate_->ResizeDueToAutoResize(this, new_size);
1865}
1866
[email protected]b172aee2012-04-10 17:05:261867WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201868 if (!delegate_)
1869 return NULL;
[email protected]00c37fc2011-08-02 00:22:501870
[email protected]e5d549d2011-12-28 01:29:201871 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201872 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341873}
1874
[email protected]6b618e62012-08-16 12:59:181875bool WebContentsImpl::Send(IPC::Message* message) {
1876 if (!GetRenderViewHost()) {
1877 delete message;
1878 return false;
1879 }
1880
1881 return GetRenderViewHost()->Send(message);
1882}
1883
[email protected]b172aee2012-04-10 17:05:261884bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501885 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261886 FrameTreeNode* node = frame_tree_.root();
1887
creise42f2a52014-09-18 18:14:571888 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
1889 // is currently only used in --site-per-process and tests.
[email protected]61ac9e242014-03-21 20:55:261890 NavigationEntryImpl* pending_entry =
1891 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
creise42f2a52014-09-18 18:14:571892 if (pending_entry->frame_tree_node_id() != -1) {
1893 FrameTreeNode* subframe =
1894 frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1895 DCHECK(subframe);
1896 if (subframe)
1897 node = subframe;
[email protected]61ac9e242014-03-21 20:55:261898 }
1899
1900 return node->navigator()->NavigateToPendingEntry(
1901 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541902}
[email protected]96d185d2009-04-24 03:28:541903
[email protected]a86c0e962013-12-17 17:10:391904void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1905 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441906 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391907 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441908}
1909
[email protected]20ca0382013-02-28 19:50:071910void WebContentsImpl::AttachInterstitialPage(
1911 InterstitialPageImpl* interstitial_page) {
1912 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211913 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291914
1915 // Cancel any visible dialogs so that they don't interfere with the
1916 // interstitial.
1917 if (dialog_manager_)
1918 dialog_manager_->CancelActiveAndPendingDialogs(this);
1919
[email protected]20ca0382013-02-28 19:50:071920 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1921 DidAttachInterstitialPage());
1922}
1923
1924void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571925 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211926 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071927 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1928 DidDetachInterstitialPage());
1929}
1930
[email protected]b172aee2012-04-10 17:05:261931void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331932 const SiteInstance* site_instance,
1933 int history_length,
1934 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411935 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1936 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211937 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191938 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141939 return;
[email protected]9e1ad4b2011-08-14 16:49:191940 }
[email protected]9f76c1e2012-03-05 15:15:581941 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191942 if (!rvh) {
1943 NOTREACHED();
1944 return;
1945 }
[email protected]9f76c1e2012-03-05 15:15:581946 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191947 NOTREACHED();
1948 return;
1949 }
[email protected]6b618e62012-08-16 12:59:181950 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1951 history_length,
1952 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141953}
1954
[email protected]4fed3702014-04-01 09:08:001955void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171956 RenderFrameHost* focused_frame = GetFocusedFrame();
1957 if (!focused_frame)
1958 return;
1959
[email protected]959be4c2014-04-08 15:01:331960 focused_frame->Send(new FrameMsg_Reload(
1961 focused_frame->GetRoutingID(), ignore_cache));
1962}
1963
1964void WebContentsImpl::Undo() {
1965 RenderFrameHost* focused_frame = GetFocusedFrame();
1966 if (!focused_frame)
1967 return;
1968
1969 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1970 RecordAction(base::UserMetricsAction("Undo"));
1971}
1972
1973void WebContentsImpl::Redo() {
1974 RenderFrameHost* focused_frame = GetFocusedFrame();
1975 if (!focused_frame)
1976 return;
1977 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1978 RecordAction(base::UserMetricsAction("Redo"));
1979}
1980
1981void WebContentsImpl::Cut() {
1982 RenderFrameHost* focused_frame = GetFocusedFrame();
1983 if (!focused_frame)
1984 return;
1985
1986 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1987 RecordAction(base::UserMetricsAction("Cut"));
1988}
1989
1990void WebContentsImpl::Copy() {
1991 RenderFrameHost* focused_frame = GetFocusedFrame();
1992 if (!focused_frame)
1993 return;
1994
1995 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1996 RecordAction(base::UserMetricsAction("Copy"));
1997}
1998
1999void WebContentsImpl::CopyToFindPboard() {
2000#if defined(OS_MACOSX)
2001 RenderFrameHost* focused_frame = GetFocusedFrame();
2002 if (!focused_frame)
2003 return;
2004
2005 // Windows/Linux don't have the concept of a find pasteboard.
2006 focused_frame->Send(
2007 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2008 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2009#endif
2010}
2011
2012void WebContentsImpl::Paste() {
2013 RenderFrameHost* focused_frame = GetFocusedFrame();
2014 if (!focused_frame)
2015 return;
2016
2017 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2018 RecordAction(base::UserMetricsAction("Paste"));
2019}
2020
2021void WebContentsImpl::PasteAndMatchStyle() {
2022 RenderFrameHost* focused_frame = GetFocusedFrame();
2023 if (!focused_frame)
2024 return;
2025
2026 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2027 focused_frame->GetRoutingID()));
2028 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2029}
2030
2031void WebContentsImpl::Delete() {
2032 RenderFrameHost* focused_frame = GetFocusedFrame();
2033 if (!focused_frame)
2034 return;
2035
2036 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2037 RecordAction(base::UserMetricsAction("DeleteSelection"));
2038}
2039
2040void WebContentsImpl::SelectAll() {
2041 RenderFrameHost* focused_frame = GetFocusedFrame();
2042 if (!focused_frame)
2043 return;
2044
2045 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2046 RecordAction(base::UserMetricsAction("SelectAll"));
2047}
2048
2049void WebContentsImpl::Unselect() {
2050 RenderFrameHost* focused_frame = GetFocusedFrame();
2051 if (!focused_frame)
2052 return;
2053
2054 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2055 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172056}
2057
2058void WebContentsImpl::Replace(const base::string16& word) {
2059 RenderFrameHost* focused_frame = GetFocusedFrame();
2060 if (!focused_frame)
2061 return;
2062
[email protected]959be4c2014-04-08 15:01:332063 focused_frame->Send(new InputMsg_Replace(
2064 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172065}
2066
2067void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2068 RenderFrameHost* focused_frame = GetFocusedFrame();
2069 if (!focused_frame)
2070 return;
2071
[email protected]959be4c2014-04-08 15:01:332072 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2073 focused_frame->GetRoutingID(), word));
2074}
2075
2076void WebContentsImpl::NotifyContextMenuClosed(
2077 const CustomContextMenuContext& context) {
2078 RenderFrameHost* focused_frame = GetFocusedFrame();
2079 if (!focused_frame)
2080 return;
2081
2082 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2083 focused_frame->GetRoutingID(), context));
2084}
2085
2086void WebContentsImpl::ExecuteCustomContextMenuCommand(
2087 int action, const CustomContextMenuContext& context) {
2088 RenderFrameHost* focused_frame = GetFocusedFrame();
2089 if (!focused_frame)
2090 return;
2091
2092 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2093 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002094}
2095
[email protected]fc2b46b2014-05-03 16:33:452096gfx::NativeView WebContentsImpl::GetNativeView() {
2097 return view_->GetNativeView();
2098}
2099
2100gfx::NativeView WebContentsImpl::GetContentNativeView() {
2101 return view_->GetContentNativeView();
2102}
2103
2104gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2105 return view_->GetTopLevelNativeWindow();
2106}
2107
2108gfx::Rect WebContentsImpl::GetViewBounds() {
2109 return view_->GetViewBounds();
2110}
2111
2112gfx::Rect WebContentsImpl::GetContainerBounds() {
2113 gfx::Rect rv;
2114 view_->GetContainerBounds(&rv);
2115 return rv;
2116}
2117
2118DropData* WebContentsImpl::GetDropData() {
2119 return view_->GetDropData();
2120}
2121
2122void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042123 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452124}
2125
2126void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042127 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452128}
2129
2130void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042131 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452132}
2133
2134void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042135 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452136}
2137
[email protected]b172aee2012-04-10 17:05:262138void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272139 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212140 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542141 return;
2142 }
[email protected]0b431992014-06-24 00:08:032143 RenderWidgetHostView* const fullscreen_view =
2144 GetFullscreenRenderWidgetHostView();
2145 if (fullscreen_view) {
2146 fullscreen_view->Focus();
2147 return;
2148 }
[email protected]9f76c1e2012-03-05 15:15:582149 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542150}
2151
[email protected]b172aee2012-04-10 17:05:262152bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212153 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542154}
2155
[email protected]b172aee2012-04-10 17:05:262156InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212157 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222158}
2159
[email protected]b172aee2012-04-10 17:05:262160bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162161 // WebKit creates Document object when MIME type is application/xhtml+xml,
2162 // so we also support this MIME type.
2163 return contents_mime_type_ == "text/html" ||
2164 contents_mime_type_ == "text/xml" ||
2165 contents_mime_type_ == "application/xhtml+xml" ||
2166 contents_mime_type_ == "text/plain" ||
2167 contents_mime_type_ == "text/css" ||
2168 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2169}
2170
[email protected]b172aee2012-04-10 17:05:262171void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592172 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162173 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552174 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012175 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142176 return;
[email protected]c7dd2f62011-07-18 15:57:592177 }
2178
2179 Stop();
2180
2181 // Create the save package and possibly prompt the user for the name to save
2182 // the page as. The user prompt is an asynchronous operation that runs on
2183 // another thread.
2184 save_package_ = new SavePackage(this);
2185 save_package_->GetSaveInfo();
2186}
2187
2188// Used in automated testing to bypass prompting the user for file names.
2189// Instead, the names and paths are hard coded rather than running them through
2190// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342191bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2192 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212193 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592194 // Stop the page from navigating.
2195 Stop();
2196
2197 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212198 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592199}
2200
[email protected]3c71576ce2013-07-23 02:00:012201void WebContentsImpl::SaveFrame(const GURL& url,
2202 const Referrer& referrer) {
2203 if (!GetURL().is_valid())
2204 return;
2205 bool is_main_frame = (url == GetURL());
2206
2207 DownloadManager* dlm =
2208 BrowserContext::GetDownloadManager(GetBrowserContext());
2209 if (!dlm)
2210 return;
2211 int64 post_id = -1;
2212 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272213 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012214 if (entry)
2215 post_id = entry->GetPostID();
2216 }
2217 scoped_ptr<DownloadUrlParameters> params(
2218 DownloadUrlParameters::FromWebContents(this, url));
2219 params->set_referrer(referrer);
2220 params->set_post_id(post_id);
2221 params->set_prefer_cache(true);
2222 if (post_id >= 0)
2223 params->set_method("POST");
2224 params->set_prompt(true);
2225 dlm->DownloadUrl(params.Pass());
2226}
2227
[email protected]b172aee2012-04-10 17:05:262228void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342229 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482230 const base::Callback<void(int64)>& callback) {
2231 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122232}
2233
[email protected]b172aee2012-04-10 17:05:262234const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272235 return contents_mime_type_;
2236}
2237
[email protected]b172aee2012-04-10 17:05:262238bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272239 return notify_disconnection_;
2240}
2241
[email protected]b172aee2012-04-10 17:05:262242void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312243 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182244 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162245}
2246
[email protected]b172aee2012-04-10 17:05:262247void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542248 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182249 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162250}
2251
[email protected]8ff00d72012-10-23 19:12:212252RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272253 return &renderer_preferences_;
2254}
2255
[email protected]e35ccd52012-05-23 16:22:472256void WebContentsImpl::Close() {
2257 Close(GetRenderViewHost());
2258}
2259
[email protected]cf200a562013-05-03 16:24:292260void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462261 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292262 if (browser_plugin_embedder_.get())
2263 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2264 screen_x, screen_y, operation);
2265 if (GetRenderViewHost())
2266 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2267 screen_x, screen_y, operation);
2268}
2269
[email protected]d60f3702013-12-26 16:30:242270void WebContentsImpl::DidGetResourceResponseStart(
2271 const ResourceRequestDetails& details) {
2272 controller_.ssl_manager()->DidStartResourceResponse(details);
2273
2274 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2275 DidGetResourceResponseStart(details));
2276
2277 // TODO(avi): Remove. http://crbug.com/170921
2278 NotificationService::current()->Notify(
2279 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2280 Source<WebContents>(this),
2281 Details<const ResourceRequestDetails>(&details));
2282}
2283
2284void WebContentsImpl::DidGetRedirectForResourceRequest(
2285 RenderViewHost* render_view_host,
2286 const ResourceRedirectDetails& details) {
2287 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2288
2289 FOR_EACH_OBSERVER(
2290 WebContentsObserver,
2291 observers_,
2292 DidGetRedirectForResourceRequest(render_view_host, details));
2293
2294 // TODO(avi): Remove. http://crbug.com/170921
2295 NotificationService::current()->Notify(
2296 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2297 Source<WebContents>(this),
2298 Details<const ResourceRedirectDetails>(&details));
2299}
2300
[email protected]b172aee2012-04-10 17:05:262301void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522302 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582303 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512304 if (delegate_)
2305 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292306 if (browser_plugin_embedder_.get())
2307 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342308}
2309
[email protected]e35ccd52012-05-23 16:22:472310void WebContentsImpl::UserGestureDone() {
2311 OnUserGesture();
2312}
2313
[email protected]b172aee2012-04-10 17:05:262314void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272315 closed_by_user_gesture_ = value;
2316}
2317
[email protected]b172aee2012-04-10 17:05:262318bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272319 return closed_by_user_gesture_;
2320}
2321
[email protected]b172aee2012-04-10 17:05:262322void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502323 if (!delegate_)
2324 return;
2325
[email protected]6286a372013-10-09 04:03:272326 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2327 if (!entry)
[email protected]1788e772010-12-15 16:40:502328 return;
2329
[email protected]6286a372013-10-09 04:03:272330 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122331}
2332
[email protected]b172aee2012-04-10 17:05:262333void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042334 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272335 if (!delegate_)
2336 return;
2337
[email protected]691aa2f2013-05-28 22:52:042338 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272339}
2340
[email protected]b172aee2012-04-10 17:05:262341int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272342 return minimum_zoom_percent_;
2343}
2344
[email protected]b172aee2012-04-10 17:05:262345int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272346 return maximum_zoom_percent_;
2347}
2348
[email protected]b172aee2012-04-10 17:05:262349gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492350 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232351}
2352
[email protected]b172aee2012-04-10 17:05:262353bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052354 if (GetBrowserPluginGuest())
2355 return GetBrowserPluginGuest()->LockMouse(allowed);
2356
[email protected]0bfbf882011-12-22 18:19:272357 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582358 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272359}
2360
[email protected]b172aee2012-04-10 17:05:262361bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442362 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502363}
2364
[email protected]cb805452013-05-22 15:16:212365void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482366 if (!color_chooser_info_.get())
2367 return;
2368 RenderFrameHost* rfh = RenderFrameHost::FromID(
2369 color_chooser_info_->render_process_id,
2370 color_chooser_info_->render_frame_id);
2371 if (!rfh)
2372 return;
2373
2374 rfh->Send(new FrameMsg_DidChooseColorResponse(
2375 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202376}
2377
[email protected]cb805452013-05-22 15:16:212378void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482379 if (!color_chooser_info_.get())
2380 return;
2381 RenderFrameHost* rfh = RenderFrameHost::FromID(
2382 color_chooser_info_->render_process_id,
2383 color_chooser_info_->render_frame_id);
2384 if (!rfh)
2385 return;
2386
2387 rfh->Send(new FrameMsg_DidEndColorChooser(
2388 rfh->GetRoutingID(), color_chooser_info_->identifier));
2389 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202390}
2391
[email protected]41225fe2013-03-29 05:32:022392int WebContentsImpl::DownloadImage(const GURL& url,
2393 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302394 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022395 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582396 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022397 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392398 return id;
2399}
2400
[email protected]5dcaf8e2013-12-28 01:31:422401bool WebContentsImpl::IsSubframe() const {
2402 return is_subframe_;
2403}
2404
[email protected]36ec24f2014-01-09 00:32:082405void WebContentsImpl::Find(int request_id,
2406 const base::string16& search_text,
2407 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092408 // See if a top level browser plugin handles the find request first.
2409 if (browser_plugin_embedder_ &&
2410 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2411 return;
2412 }
[email protected]36ec24f2014-01-09 00:32:082413 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2414}
2415
2416void WebContentsImpl::StopFinding(StopFindAction action) {
2417 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2418}
2419
[email protected]4fe53add2014-04-08 19:53:362420void WebContentsImpl::InsertCSS(const std::string& css) {
2421 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2422 GetMainFrame()->GetRoutingID(), css));
2423}
2424
dalecurtisbc6572e12014-09-12 19:22:302425bool WebContentsImpl::WasRecentlyAudible() {
2426 return audio_stream_monitor_.WasRecentlyAudible();
2427}
2428
mlamouriefdca9d2014-09-16 16:55:402429void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2430 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2431}
2432
[email protected]b172aee2012-04-10 17:05:262433bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272434 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172435 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332436 return true;
2437 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272438}
2439
[email protected]b172aee2012-04-10 17:05:262440void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272441 if (delegate_)
2442 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212443}
2444
[email protected]52913802013-12-10 05:52:182445void WebContentsImpl::DidStartProvisionalLoad(
2446 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182447 const GURL& validated_url,
2448 bool is_error_page,
2449 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102450 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482451 FOR_EACH_OBSERVER(
2452 WebContentsObserver,
2453 observers_,
2454 DidStartProvisionalLoadForFrame(
2455 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
[email protected]400992b2012-06-14 00:03:542456}
2457
[email protected]0c3c54f2014-07-31 01:29:002458void WebContentsImpl::DidStartNavigationTransition(
morritaffb82612014-10-31 18:26:592459 RenderFrameHostImpl* render_frame_host) {
[email protected]0c3c54f2014-07-31 01:29:002460#if defined(OS_ANDROID)
2461 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562462 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
morritaffb82612014-10-31 18:26:592463 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002464#endif
2465}
2466
[email protected]3109fbb72014-01-06 23:57:152467void WebContentsImpl::DidFailProvisionalLoadWithError(
2468 RenderFrameHostImpl* render_frame_host,
2469 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2470 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312471 FOR_EACH_OBSERVER(WebContentsObserver,
2472 observers_,
2473 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312474 validated_url,
2475 params.error_code,
2476 params.error_description));
[email protected]3109fbb72014-01-06 23:57:152477}
2478
[email protected]b80624c2014-02-09 02:46:552479void WebContentsImpl::DidFailLoadWithError(
2480 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552481 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552482 int error_code,
2483 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142484 FOR_EACH_OBSERVER(
2485 WebContentsObserver,
2486 observers_,
2487 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552488}
2489
[email protected]52913802013-12-10 05:52:182490void WebContentsImpl::NotifyChangedNavigationState(
2491 InvalidateTypes changed_flags) {
2492 NotifyNavigationStateChanged(changed_flags);
2493}
2494
[email protected]3691e5cf2014-01-22 10:16:202495void WebContentsImpl::AboutToNavigateRenderFrame(
2496 RenderFrameHostImpl* render_frame_host) {
2497 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272498 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202499 FOR_EACH_OBSERVER(
2500 WebContentsObserver,
2501 observers_,
[email protected]161eabd2014-03-19 19:47:272502 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202503}
2504
2505void WebContentsImpl::DidStartNavigationToPendingEntry(
2506 RenderFrameHostImpl* render_frame_host,
2507 const GURL& url,
2508 NavigationController::ReloadType reload_type) {
2509 // Notify observers about navigation.
2510 FOR_EACH_OBSERVER(
2511 WebContentsObserver,
2512 observers_,
2513 DidStartNavigationToPendingEntry(url, reload_type));
2514}
2515
[email protected]8cb834e2014-03-06 14:23:232516void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2517 const OpenURLParams& params) {
2518 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182519 WebContents* new_contents = OpenURL(params);
2520
2521 if (new_contents) {
2522 // Notify observers.
2523 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2524 DidOpenRequestedURL(new_contents,
2525 params.url,
2526 params.referrer,
2527 params.disposition,
2528 params.transition,
[email protected]8cb834e2014-03-06 14:23:232529 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182530 }
2531}
2532
[email protected]aa62afd2014-04-22 19:22:462533bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2534 if (!delegate_)
2535 return false;
2536 return delegate_->ShouldPreserveAbortedURLs(this);
2537}
2538
[email protected]37567b432014-02-12 01:12:222539void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432540 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222541 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352542 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222543 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482544 FOR_EACH_OBSERVER(WebContentsObserver,
2545 observers_,
2546 DidCommitProvisionalLoadForFrame(
2547 render_frame_host, url, transition_type));
[email protected]37567b432014-02-12 01:12:222548}
2549
[email protected]0d0f4c492014-04-02 06:42:572550void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232551 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572552 // Ensure fullscreen mode is exited before committing the navigation to a
2553 // different page. The next page will not start out assuming it is in
2554 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232555 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192556 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572557 return;
2558 }
2559 if (IsFullscreenForCurrentTab())
2560 GetRenderViewHost()->ExitFullscreen();
2561 DCHECK(!IsFullscreenForCurrentTab());
2562}
2563
[email protected]37567b432014-02-12 01:12:222564void WebContentsImpl::DidNavigateMainFramePostCommit(
2565 const LoadCommittedDetails& details,
2566 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2567 if (details.is_navigation_to_different_page()) {
2568 // Clear the status bubble. This is a workaround for a bug where WebKit
2569 // doesn't let us know that the cursor left an element during a
2570 // transition (this is also why the mouse cursor remains as a hand after
2571 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2572 // clear the bubble when a user navigates to a named anchor in the same
2573 // page.
avi450ce00e2014-09-24 01:58:522574 UpdateTargetURL(GURL());
[email protected]37567b432014-02-12 01:12:222575 }
2576
2577 if (!details.is_in_page) {
2578 // Once the main frame is navigated, we're no longer considered to have
2579 // displayed insecure content.
2580 displayed_insecure_content_ = false;
2581 SSLManager::NotifySSLInternalStateChanged(
2582 GetController().GetBrowserContext());
2583 }
2584
2585 // Notify observers about navigation.
2586 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2587 DidNavigateMainFrame(details, params));
2588
[email protected]e85165c642014-06-10 14:34:312589 if (delegate_)
[email protected]37567b432014-02-12 01:12:222590 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312591 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222592}
2593
2594void WebContentsImpl::DidNavigateAnyFramePostCommit(
2595 RenderFrameHostImpl* render_frame_host,
2596 const LoadCommittedDetails& details,
2597 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102598 // Now that something has committed, we don't need to track whether the
2599 // initial page has been accessed.
2600 has_accessed_initial_document_ = false;
2601
[email protected]37567b432014-02-12 01:12:222602 // If we navigate off the page, close all JavaScript dialogs.
2603 if (dialog_manager_ && !details.is_in_page)
2604 dialog_manager_->CancelActiveAndPendingDialogs(this);
2605
2606 // Notify observers about navigation.
2607 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:092608 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:222609}
2610
2611void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2612 contents_mime_type_ = mime_type;
2613}
2614
[email protected]277857a2014-06-03 10:38:012615bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312616 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052617 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312618 return false;
2619
[email protected]37567b432014-02-12 01:12:222620 if (delegate_)
2621 return delegate_->CanOverscrollContent();
2622
2623 return false;
2624}
2625
[email protected]37b64c52014-07-11 21:14:052626void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252627 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052628 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252629}
2630
[email protected]b172aee2012-04-10 17:05:262631void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182632 const GURL& url,
[email protected]70435962011-08-02 20:13:282633 const std::string& security_info,
2634 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182635 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402636 ResourceType resource_type) {
[email protected]28620862011-03-22 23:07:192637 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182638 cache.Increment();
2639
2640 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082641 int cert_id = 0;
2642 net::CertStatus cert_status = 0;
2643 int security_bits = -1;
2644 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122645 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212646 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122647 &security_bits, &connection_status,
2648 &signed_certificate_timestamp_ids);
2649 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212650 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002651 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2652 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182653
[email protected]b0f724c2013-09-05 04:21:132654 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2655
2656 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2657 DidLoadResourceFromMemoryCache(details));
2658
[email protected]8bfc8272013-09-09 20:10:532659 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2660 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402661 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532662 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2663 GetRenderProcessHost()->GetID()) :
2664 GetBrowserContext()->GetRequestContextForRenderProcess(
2665 GetRenderProcessHost()->GetID()));
2666 BrowserThread::PostTask(
2667 BrowserThread::IO,
2668 FROM_HERE,
2669 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2670 }
[email protected]724159a2010-12-30 01:11:182671}
2672
[email protected]b172aee2012-04-10 17:05:262673void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392674 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182675 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192676 SSLManager::NotifySSLInternalStateChanged(
2677 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182678}
2679
[email protected]b172aee2012-04-10 17:05:262680void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022681 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582682 LOG(WARNING) << security_origin << " ran insecure content from "
2683 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392684 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412685 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392686 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182687 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412688 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192689 SSLManager::NotifySSLInternalStateChanged(
2690 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182691}
2692
[email protected]501052ff2014-02-21 22:19:072693void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572694 CHECK(render_frame_message_source_);
2695 CHECK(!render_view_message_source_);
2696 RenderFrameHostImpl* rfh =
2697 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142698 FOR_EACH_OBSERVER(
2699 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182700}
2701
[email protected]b172aee2012-04-10 17:05:262702void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262703 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372704 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122705 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2706 GetRenderProcessHost()->ReceivedBadMessage();
2707 return;
2708 }
[email protected]a1b99262013-12-27 21:56:222709
[email protected]8b3af1e2014-01-24 13:29:122710 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442711 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372712 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422713 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372714
[email protected]61ac9e242014-03-21 20:55:262715 RenderFrameHostImpl* rfh =
2716 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142717 FOR_EACH_OBSERVER(
2718 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312719}
2720
[email protected]960b0372014-05-19 18:01:002721void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2722 RenderFrameHostImpl* rfh =
2723 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2724 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2725
2726 // It is possible to get multiple calls to OnDidStartLoading that don't have
2727 // corresponding calls to OnDidStopLoading:
2728 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2729 // out for a cross-process navigation, and it turns into a placeholder for
2730 // one being rendered in a different process.
2731 // - Also, there might be more than one RenderFrameHost sharing the same
2732 // FrameTreeNode (and thus sharing its ID) each sending a start.
2733 // - But in the future, once clamy@ moves navigation network requests to the
2734 // browser process, there's a good chance that callbacks about starting and
2735 // stopping will all be handled by the browser. When that happens, there
2736 // should no longer be a start/stop call imbalance. TODO(avi): When this
2737 // future arrives, update this code to not allow this case.
2738 DCHECK_GE(loading_frames_in_progress_, 0);
2739 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2740 if (loading_frames_in_progress_ == 0)
2741 DidStartLoading(rfh, to_different_document);
2742 ++loading_frames_in_progress_;
2743 }
2744
2745 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2746 SendLoadProgressChanged();
2747}
2748
2749void WebContentsImpl::OnDidStopLoading() {
2750 RenderFrameHostImpl* rfh =
2751 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2752 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2753
2754 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2755 // Load stopped while we were still tracking load. Make sure we update
2756 // progress based on this frame's completion.
2757 loading_progresses_[render_frame_id] = 1.0;
2758 SendLoadProgressChanged();
2759 // Then we clean-up our states.
2760 if (loading_total_progress_ == 1.0)
2761 ResetLoadProgressState();
2762 }
2763
2764 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2765 // calls DidStopLoading() without a matching DidStartLoading().
2766 if (loading_frames_in_progress_ == 0)
2767 return;
2768 --loading_frames_in_progress_;
2769 if (loading_frames_in_progress_ == 0)
2770 DidStopLoading(rfh);
2771}
2772
2773void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2774 RenderFrameHostImpl* rfh =
2775 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2776 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2777
2778 loading_progresses_[render_frame_id] = load_progress;
2779
2780 // We notify progress change immediately for the first and last updates.
2781 // Also, since the message loop may be pretty busy when a page is loaded, it
2782 // might not execute a posted task in a timely manner so we make sure to
2783 // immediately send progress report if enough time has passed.
2784 base::TimeDelta min_delay =
2785 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2786 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2787 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2788 // If there is a pending task to send progress, it is now obsolete.
2789 loading_weak_factory_.InvalidateWeakPtrs();
2790 SendLoadProgressChanged();
2791 if (loading_total_progress_ == 1.0)
2792 ResetLoadProgressState();
2793 return;
2794 }
2795
2796 if (loading_weak_factory_.HasWeakPtrs())
2797 return;
2798
2799 base::MessageLoop::current()->PostDelayedTask(
2800 FROM_HERE,
2801 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2802 loading_weak_factory_.GetWeakPtr()),
2803 min_delay);
2804}
2805
[email protected]b172aee2012-04-10 17:05:262806void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222807 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2808 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262809}
2810
[email protected]b172aee2012-04-10 17:05:262811void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302812 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262813 minimum_zoom_percent_ = minimum_percent;
2814 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262815}
2816
[email protected]b172aee2012-04-10 17:05:262817void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342818 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432819 if (!delegate_)
2820 return;
2821
[email protected]b9535422012-02-09 01:47:592822 ChildProcessSecurityPolicyImpl* policy =
2823 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222824 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592825 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212826}
2827
[email protected]b172aee2012-04-10 17:05:262828void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2829 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262830 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362831 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432832 if (!delegate_)
2833 return;
2834
[email protected]b9535422012-02-09 01:47:592835 ChildProcessSecurityPolicyImpl* policy =
2836 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322837 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592838 return;
[email protected]8f810632013-06-06 22:33:322839
[email protected]c125e532014-05-10 20:39:062840 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202841}
2842
[email protected]f5273e52014-07-14 16:30:202843void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2844 const GURL& url,
2845 bool user_gesture) {
2846 if (!delegate_)
2847 return;
2848
2849 ChildProcessSecurityPolicyImpl* policy =
2850 ChildProcessSecurityPolicyImpl::GetInstance();
2851 if (policy->IsPseudoScheme(protocol))
2852 return;
2853
2854 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2855}
2856
[email protected]b172aee2012-04-10 17:05:262857void WebContentsImpl::OnFindReply(int request_id,
2858 int number_of_matches,
2859 const gfx::Rect& selection_rect,
2860 int active_match_ordinal,
2861 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432862 if (delegate_) {
2863 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2864 active_match_ordinal, final_update);
2865 }
[email protected]b888919c2011-09-02 00:32:162866}
2867
[email protected]59363fc92012-09-05 03:46:312868#if defined(OS_ANDROID)
2869void WebContentsImpl::OnFindMatchRectsReply(
2870 int version,
2871 const std::vector<gfx::RectF>& rects,
2872 const gfx::RectF& active_rect) {
2873 if (delegate_)
2874 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2875}
[email protected]583418cc2013-01-17 14:01:102876
[email protected]1ff427972013-02-07 21:14:072877void WebContentsImpl::OnOpenDateTimeDialog(
2878 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:172879 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:092880 GetRenderViewHost(),
2881 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132882 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092883 value.minimum,
2884 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172885 value.step,
2886 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102887}
[email protected]59363fc92012-09-05 03:46:312888#endif
2889
[email protected]cfa856d62014-02-22 07:58:402890void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2891 int automation_id) {
2892 DomOperationNotificationDetails details(json_string, automation_id);
2893 NotificationService::current()->Notify(
2894 NOTIFICATION_DOM_OPERATION_RESPONSE,
2895 Source<WebContents>(this),
2896 Details<DomOperationNotificationDetails>(&details));
2897}
2898
[email protected]b172aee2012-04-10 17:05:262899void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2900 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102901 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252902 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102903 AppCacheAccessed(manifest_url, blocked_by_policy));
2904}
2905
[email protected]8bc5ff02013-11-29 06:34:032906void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482907 int color_chooser_id,
2908 SkColor color,
2909 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462910 ColorChooser* new_color_chooser = delegate_ ?
2911 delegate_->OpenColorChooser(this, color, suggestions) :
2912 NULL;
[email protected]820957a2014-01-14 14:56:302913 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212914 return;
[email protected]8ed16472014-04-11 19:02:482915 if (color_chooser_info_.get())
2916 color_chooser_info_->chooser->End();
2917
2918 color_chooser_info_.reset(new ColorChooserInfo(
2919 render_frame_message_source_->GetProcess()->GetID(),
2920 render_frame_message_source_->GetRoutingID(),
2921 new_color_chooser,
2922 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202923}
2924
[email protected]b172aee2012-04-10 17:05:262925void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482926 if (color_chooser_info_ &&
2927 color_chooser_id == color_chooser_info_->identifier)
2928 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202929}
2930
[email protected]b172aee2012-04-10 17:05:262931void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322932 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482933 if (color_chooser_info_ &&
2934 color_chooser_id == color_chooser_info_->identifier)
2935 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202936}
2937
[email protected]d0759f492012-04-19 22:50:502938// This exists for render views that don't have a WebUI, but do have WebUI
2939// bindings enabled.
2940void WebContentsImpl::OnWebUISend(const GURL& source_url,
2941 const std::string& name,
2942 const base::ListValue& args) {
2943 if (delegate_)
2944 delegate_->WebUISend(this, source_url, name, args);
2945}
2946
thestigc4cac8f2014-09-04 21:17:502947#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:422948void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2949 const base::FilePath& path,
2950 bool is_hung) {
2951 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2952
2953 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2954 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2955}
2956
2957void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
2958 base::ProcessId plugin_pid) {
2959 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2960 PluginCrashed(plugin_path, plugin_pid));
2961}
2962
[email protected]d8415ad92012-08-23 14:40:502963void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442964 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502965 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342966 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162967 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442968 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162969 return;
[email protected]d8415ad92012-08-23 14:40:502970 }
2971
[email protected]8c8fc292012-11-23 18:57:162972 if (!delegate_->RequestPpapiBrokerPermission(
2973 this, url, plugin_path,
2974 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442975 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162976 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442977 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162978 }
[email protected]d8415ad92012-08-23 14:40:502979}
2980
[email protected]ea0309c2013-08-06 19:35:442981void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502982 bool result) {
[email protected]ea0309c2013-08-06 19:35:442983 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502984}
2985
[email protected]c4538072013-03-18 02:17:552986void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372987 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082988 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552989 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392990 // For more info, see comment above classes BrowserPluginEmbedder and
2991 // BrowserPluginGuest.
2992 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142993 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082994 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372995}
tommyclie6633ca72014-10-31 00:40:422996#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:372997
[email protected]41225fe2013-03-29 05:32:022998void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392999 int id,
[email protected]749fadd2013-05-15 08:37:483000 int http_status_code,
[email protected]795c28972012-12-06 06:13:393001 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303002 const std::vector<SkBitmap>& bitmaps,
3003 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133004 if (bitmaps.size() != original_bitmap_sizes.size())
3005 return;
3006
[email protected]41225fe2013-03-29 05:32:023007 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3008 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393009 // Currently WebContents notifies us of ANY downloads so that it is
3010 // possible to get here.
3011 return;
3012 }
3013 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303014 iter->second.Run(
3015 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393016 }
[email protected]41225fe2013-03-29 05:32:023017 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393018}
3019
3020void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393021 const std::vector<FaviconURL>& candidates) {
3022 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293023 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393024}
3025
dalecurtisbc6572e12014-09-12 19:22:303026void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3027 // ChromeOS has its own way of handling power save blocks for media.
3028#if !defined(OS_CHROMEOS)
3029 DCHECK(!audio_power_save_blocker_);
3030 audio_power_save_blocker_ = PowerSaveBlocker::Create(
3031 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing Audio");
3032#endif
3033}
3034
3035void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3036 // ChromeOS has its own way of handling power save blocks for media.
3037#if !defined(OS_CHROMEOS)
3038 DCHECK(!video_power_save_blocker_);
3039 DCHECK(!active_video_players_.empty());
3040 video_power_save_blocker_ = PowerSaveBlocker::Create(
3041 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing Video");
3042#if defined(OS_ANDROID)
3043 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3044 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3045#endif
3046#endif
3047}
3048
3049void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3050 // If there are no more audio players and we don't have audio stream
3051 // monitoring, release the audio power save blocker here instead of during
3052 // NotifyNavigationStateChanged().
3053 if (active_audio_players_.empty() &&
3054 !AudioStreamMonitor::monitoring_available()) {
3055 audio_power_save_blocker_.reset();
3056 }
3057
3058 // If there are no more video players, clear the video power save blocker.
3059 if (active_video_players_.empty())
3060 video_power_save_blocker_.reset();
3061}
3062
[email protected]1dd0bb752014-02-01 01:16:263063void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3064 bool has_video,
avayvod68017be2014-10-10 18:02:433065 bool has_audio,
3066 bool is_remote) {
3067 // Ignore the videos playing remotely and don't hold the wake lock for the
3068 // screen.
3069 if (is_remote) return;
3070
dalecurtisbc6572e12014-09-12 19:22:303071 if (has_audio) {
3072 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3073
3074 // If we don't have audio stream monitoring, allocate the audio power save
3075 // blocker here instead of during NotifyNavigationStateChanged().
3076 if (!audio_power_save_blocker_ &&
3077 !AudioStreamMonitor::monitoring_available()) {
3078 CreateAudioPowerSaveBlocker();
3079 }
[email protected]1dd0bb752014-02-01 01:16:263080 }
loislo0381a742014-09-11 10:58:113081
dalecurtisbc6572e12014-09-12 19:22:303082 if (has_video) {
3083 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3084
3085 // If we're not hidden and have just created a player, create a blocker.
3086 if (!video_power_save_blocker_ && !IsHidden())
3087 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113088 }
[email protected]1dd0bb752014-02-01 01:16:263089}
3090
3091void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303092 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3093 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3094 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063095}
3096
[email protected]50279492014-05-05 23:24:293097void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153098 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293099 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153100}
[email protected]d9030b82013-07-19 08:26:063101
[email protected]e67ebf32013-02-13 11:07:193102void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073103 if (delegate_)
3104 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193105}
3106
[email protected]17e286e2013-03-01 23:29:393107void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3108 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3109 BeforeFormRepostWarningShow());
3110}
3111
[email protected]ec6c05f2013-10-23 18:41:573112void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3113 Activate();
3114 if (delegate_)
3115 delegate_->ShowRepostFormWarningDialog(this);
3116}
3117
[email protected]b4c84012014-04-28 19:51:103118bool WebContentsImpl::HasAccessedInitialDocument() {
3119 return has_accessed_initial_document_;
3120}
3121
[email protected]96d185d2009-04-24 03:28:543122// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593123// loading, or done loading.
3124void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3125 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093126 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263127 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543128 if (is_loading == is_loading_)
3129 return;
3130
3131 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263132 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3133 base::string16());
[email protected]96d185d2009-04-24 03:28:543134 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563135 upload_size_ = 0;
3136 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543137 }
3138
[email protected]fa944cb82013-11-15 17:51:213139 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543140
3141 is_loading_ = is_loading;
3142 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033143 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543144
[email protected]6ebdc9b2010-09-27 16:55:573145 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093146 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213147 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543148
[email protected]eab61442013-11-14 18:35:483149 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593150 if (is_loading) {
naskob8744d22014-08-28 17:07:433151 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3152 this, "URL", url);
[email protected]91621872013-10-08 04:04:593153 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3154 DidStartLoading(render_view_host));
3155 } else {
naskob8744d22014-08-28 17:07:433156 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3157 this, "URL", url);
[email protected]91621872013-10-08 04:04:593158 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3159 DidStopLoading(render_view_host));
3160 }
[email protected]66798902013-10-01 18:40:163161
3162 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213163 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3164 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543165 if (details)
[email protected]8ff00d72012-10-23 19:12:213166 det = Details<LoadNotificationDetails>(details);
3167 NotificationService::current()->Notify(
3168 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543169}
3170
[email protected]959be4c2014-04-08 15:01:333171void WebContentsImpl::SelectRange(const gfx::Point& start,
3172 const gfx::Point& end) {
3173 RenderFrameHost* focused_frame = GetFocusedFrame();
3174 if (!focused_frame)
3175 return;
3176
3177 focused_frame->Send(
3178 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
3179}
3180
[email protected]b172aee2012-04-10 17:05:263181void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463182 // If we are creating a RVH for a restored controller, then we need to make
3183 // sure the RenderView starts with a next_page_id_ larger than the number
3184 // of restored entries. This must be called before the RenderView starts
3185 // navigating (to avoid a race between the browser updating max_page_id and
3186 // the renderer updating next_page_id_). Because of this, we only call this
3187 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563188 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583189 if (max_restored_page_id >
3190 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3191 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3192 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323193}
3194
[email protected]b172aee2012-04-10 17:05:263195bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263196 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323197 // For file URLs without a title, use the pathname instead. In the case of a
3198 // synthesized title, we don't want the update to count toward the "one set
3199 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263200 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323201 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513202 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243203 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323204 explicit_set = false; // Don't count synthetic titles toward the set limit.
3205 } else {
[email protected]8af69c6c2014-03-03 19:05:313206 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323207 explicit_set = true;
3208 }
3209
[email protected]987fc3a2011-05-26 14:18:093210 // If a page is created via window.open and never navigated,
3211 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553212 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093213 if (entry) {
[email protected]36fc0392011-12-25 03:59:513214 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093215 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323216
[email protected]36fc0392011-12-25 03:59:513217 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093218 } else {
3219 if (page_title_when_no_navigation_entry_ == final_title)
3220 return false; // Nothing changed, don't bother.
3221
3222 page_title_when_no_navigation_entry_ = final_title;
3223 }
[email protected]420ae012009-04-24 05:16:323224
[email protected]420ae012009-04-24 05:16:323225 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233226 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323227
[email protected]66798902013-10-01 18:40:163228 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533229 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163230
3231 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213232 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463233 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213234 NotificationService::current()->Notify(
3235 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3236 Source<WebContents>(this),
3237 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043238
[email protected]420ae012009-04-24 05:16:323239 return true;
3240}
3241
[email protected]960b0372014-05-19 18:01:003242void WebContentsImpl::SendLoadProgressChanged() {
3243 loading_last_progress_update_ = base::TimeTicks::Now();
3244 double progress = 0.0;
3245 int frame_count = 0;
3246
3247 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3248 it != loading_progresses_.end();
3249 ++it) {
3250 progress += it->second;
3251 ++frame_count;
3252 }
3253 if (frame_count == 0)
3254 return;
3255 progress /= frame_count;
3256 DCHECK(progress <= 1.0);
3257
3258 if (progress <= loading_total_progress_)
3259 return;
3260 loading_total_progress_ = progress;
3261
3262 if (delegate_)
3263 delegate_->LoadProgressChanged(this, progress);
3264}
3265
3266void WebContentsImpl::ResetLoadProgressState() {
3267 loading_progresses_.clear();
3268 loading_total_progress_ = 0.0;
3269 loading_weak_factory_.InvalidateWeakPtrs();
3270 loading_last_progress_update_ = base::TimeTicks();
3271}
3272
[email protected]02d7b6e2014-06-24 21:01:503273void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3274 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323275 // After sending out a swap notification, we need to send a disconnect
3276 // notification so that clients that pick up a pointer to |this| can NULL the
3277 // pointer. See Bug 1230284.
3278 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113279 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283280 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113281
3282 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283283 std::pair<RenderViewHost*, RenderViewHost*> details =
3284 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213285 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283286 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213287 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283288 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393289
3290 // Ensure that the associated embedder gets cleared after a RenderViewHost
3291 // gets swapped, so we don't reuse the same embedder next time a
3292 // RenderViewHost is attached to this WebContents.
3293 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323294}
3295
[email protected]02d7b6e2014-06-24 21:01:503296void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3297 RenderFrameHost* new_host) {
3298 FOR_EACH_OBSERVER(WebContentsObserver,
3299 observers_,
3300 RenderFrameHostChanged(old_host, new_host));
3301}
3302
[email protected]da7a7182013-09-06 08:11:113303// TODO(avi): Remove this entire function because this notification is already
3304// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263305void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323306 if (!notify_disconnection_)
3307 return;
3308
3309 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213310 NotificationService::current()->Notify(
3311 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3312 Source<WebContents>(this),
3313 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323314}
3315
[email protected]cbb1ef592013-06-05 19:49:463316void WebContentsImpl::NotifyNavigationEntryCommitted(
3317 const LoadCommittedDetails& load_details) {
3318 FOR_EACH_OBSERVER(
3319 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3320}
3321
[email protected]f114fa42013-12-06 17:06:443322bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3323 const IPC::Message& message) {
3324 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313325}
3326
[email protected]c31a84802014-04-03 15:55:493327const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3328 return GetLastCommittedURL();
3329}
3330
[email protected]b849847b2013-12-10 21:57:583331void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3332 // Note this is only for subframes, the notification for the main frame
3333 // happens in RenderViewCreated.
3334 FOR_EACH_OBSERVER(WebContentsObserver,
3335 observers_,
3336 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303337 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583338}
3339
3340void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193341 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583342 FOR_EACH_OBSERVER(WebContentsObserver,
3343 observers_,
3344 RenderFrameDeleted(render_frame_host));
3345}
3346
[email protected]a09d53ce2014-01-31 00:46:423347void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303348 if (delegate_)
3349 delegate_->WorkerCrashed(this);
3350}
3351
[email protected]a09d53ce2014-01-31 00:46:423352void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3353 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103354 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423355 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103356 if (GetBrowserPluginGuest()) {
3357 WebContentsViewGuest* view_guest =
3358 static_cast<WebContentsViewGuest*>(GetView());
3359 context_menu_params = view_guest->ConvertContextMenuParams(params);
3360 }
3361 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423362 return;
3363
[email protected]077e704b2014-05-23 19:24:103364 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3365 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423366}
3367
[email protected]87de04b02014-04-08 22:14:493368void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013369 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493370 const base::string16& message,
3371 const base::string16& default_prompt,
3372 const GURL& frame_url,
3373 JavaScriptMessageType javascript_message_type,
3374 IPC::Message* reply_msg) {
3375 // Suppress JavaScript dialogs when requested. Also suppress messages when
3376 // showing an interstitial as it's shown over the previous page and we don't
3377 // want the hidden page's dialogs to interfere with the interstitial.
3378 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223379 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
[email protected]87de04b02014-04-08 22:14:493380 ShowingInterstitialPage() ||
3381 !delegate_ ||
3382 delegate_->ShouldSuppressDialogs() ||
3383 !delegate_->GetJavaScriptDialogManager();
3384
3385 if (!suppress_this_message) {
3386 std::string accept_lang = GetContentClient()->browser()->
3387 GetAcceptLangs(GetBrowserContext());
3388 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3389 dialog_manager_->RunJavaScriptDialog(
3390 this,
3391 frame_url.GetOrigin(),
3392 accept_lang,
3393 javascript_message_type,
3394 message,
3395 default_prompt,
3396 base::Bind(&WebContentsImpl::OnDialogClosed,
3397 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013398 render_frame_host->GetProcess()->GetID(),
3399 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493400 reply_msg,
3401 false),
3402 &suppress_this_message);
3403 }
3404
3405 if (suppress_this_message) {
3406 // If we are suppressing messages, just reply as if the user immediately
3407 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013408 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3409 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283410 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493411 }
3412
3413 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3414 // http://crbug.com/288961 ). The only safe thing to do here is return.
3415}
3416
3417void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013418 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493419 const base::string16& message,
3420 bool is_reload,
3421 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013422 RenderFrameHostImpl* rfhi =
3423 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493424 if (delegate_)
3425 delegate_->WillRunBeforeUnloadConfirm();
3426
3427 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223428 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT ||
[email protected]87de04b02014-04-08 22:14:493429 !delegate_ ||
3430 delegate_->ShouldSuppressDialogs() ||
3431 !delegate_->GetJavaScriptDialogManager();
3432 if (suppress_this_message) {
3433 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3434 return;
3435 }
3436
3437 is_showing_before_unload_dialog_ = true;
3438 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3439 dialog_manager_->RunBeforeUnloadDialog(
3440 this, message, is_reload,
3441 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013442 render_frame_host->GetProcess()->GetID(),
3443 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283444 false));
[email protected]87de04b02014-04-08 22:14:493445}
3446
[email protected]a86c0e962013-12-17 17:10:393447WebContents* WebContentsImpl::GetAsWebContents() {
3448 return this;
3449}
3450
[email protected]7912e822014-04-16 02:37:033451bool WebContentsImpl::IsNeverVisible() {
3452 if (!delegate_)
3453 return false;
3454 return delegate_->IsNeverVisible(this);
3455}
3456
[email protected]95640212014-07-26 18:14:303457#if defined(OS_WIN)
3458gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3459 return accessible_parent_;
3460}
3461#endif
3462
[email protected]5a3bdf52012-05-24 15:12:573463RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3464 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323465}
3466
[email protected]8ff00d72012-10-23 19:12:213467RendererPreferences WebContentsImpl::GetRendererPrefs(
3468 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463469 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513470}
3471
[email protected]b172aee2012-04-10 17:05:263472gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173473 if (delegate_)
3474 return delegate_->GetRootWindowResizerRect();
3475 return gfx::Rect();
3476}
3477
[email protected]7a846df2012-09-20 19:17:393478void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273479 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393480 browser_plugin_embedder_.reset();
3481}
3482
[email protected]b172aee2012-04-10 17:05:263483void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443484 // Don't send notifications if we are just creating a swapped-out RVH for
3485 // the opener chain. These won't be used for view-source or WebUI, so it's
3486 // ok to return early.
creiscce56cd2014-09-29 22:45:223487 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443488 return;
3489
[email protected]86f98a22013-03-20 14:35:003490 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313491 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083492
[email protected]8ff00d72012-10-23 19:12:213493 NotificationService::current()->Notify(
3494 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3495 Source<WebContents>(this),
3496 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323497
3498 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353499 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213500 if (GetRenderManager()->pending_web_ui())
3501 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323502
[email protected]6286a372013-10-09 04:03:273503 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333504 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323505 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183506 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583507 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323508 }
[email protected]0666aef2009-05-13 19:48:083509
[email protected]60780f412013-02-25 16:34:103510 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263511
3512 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253513 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583514
3515 // We tell the observers now instead of when the main RenderFrameHostImpl is
3516 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3517 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363518 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583519 FOR_EACH_OBSERVER(
3520 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303521 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
dgozman24bfc912014-09-29 11:04:183522
3523 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:323524}
3525
[email protected]b172aee2012-04-10 17:05:263526void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523527 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323528 // Don't notify the world, since this came from a renderer in the
3529 // background.
3530 return;
3531 }
3532
[email protected]da7a7182013-09-06 08:11:113533 notify_disconnection_ = true;
3534 // TODO(avi): Remove. http://crbug.com/170921
3535 NotificationService::current()->Notify(
3536 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3537 Source<WebContents>(this),
3538 NotificationService::NoDetails());
3539
[email protected]be1f56ab2011-12-22 06:55:313540 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233541 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303542
3543 // Restore the focus to the tab (otherwise the focus will be on the top
3544 // window).
[email protected]484ae5912010-09-29 19:16:143545 if (was_crashed && !FocusLocationBarByDefault() &&
3546 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063547 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143548 }
[email protected]32ded2212011-11-10 18:51:433549
[email protected]d8c660432011-12-22 20:51:253550 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323551}
3552
[email protected]ec6a7eb2013-04-22 17:34:223553void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3554 base::TerminationStatus status,
3555 int error_code) {
[email protected]151a63d2011-12-20 22:32:523556 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323557 // The pending page's RenderViewHost is gone.
3558 return;
3559 }
3560
[email protected]2fcdcc32014-03-05 02:14:073561 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3562 // renderer may not have made a clean exit.
3563 if (IsFullscreenForCurrentTab())
3564 ToggleFullscreenMode(false);
3565
[email protected]698191dc2014-02-25 01:06:133566 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3567 if (dialog_manager_)
3568 dialog_manager_->CancelActiveAndPendingDialogs(this);
3569
[email protected]f738bdcb2014-07-11 20:40:443570 if (delegate_)
3571 delegate_->HideValidationMessage(this);
3572
[email protected]e3b10d12014-03-28 16:06:093573 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323574 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233575 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453576
[email protected]960b0372014-05-19 18:01:003577 // Reset the loading progress. TODO(avi): What does it mean to have a
3578 // "renderer crash" when there is more than one renderer process serving a
3579 // webpage? Once this function is called at a more granular frame level, we
3580 // probably will need to more granularly reset the state here.
3581 ResetLoadProgressState();
3582 loading_frames_in_progress_ = 0;
3583
[email protected]d8c660432011-12-22 20:51:253584 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273585 observers_,
[email protected]58d5cfe2013-07-10 02:40:523586 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323587}
3588
[email protected]b172aee2012-04-10 17:05:263589void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253590 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063591}
3592
[email protected]b172aee2012-04-10 17:05:263593void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3594 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043595 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153596 // Ensure that this state update comes from either the active RVH or one of
3597 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413598 // TODO(nasko): This should go through RenderFrameHost.
3599 // TODO(creis): We can't update state for cross-process subframes until we
3600 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3601 if (rvh != GetRenderViewHost() &&
3602 !GetRenderManager()->IsRVHOnSwappedOutList(
3603 static_cast<RenderViewHostImpl*>(rvh)))
3604 return;
[email protected]420ae012009-04-24 05:16:323605
3606 // We must be prepared to handle state updates for any page, these occur
3607 // when the user is scrolling and entering form data, as well as when we're
3608 // leaving a page, in which case our state may have already been moved to
3609 // the next page. The navigation controller will look up the appropriate
3610 // NavigationEntry and update it when it is notified via the delegate.
3611
3612 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583613 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323614 if (entry_index < 0)
3615 return;
[email protected]10f417c52011-12-28 21:04:233616 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323617
[email protected]691aa2f2013-05-28 22:52:043618 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323619 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043620 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323621 controller_.NotifyEntryChanged(entry, entry_index);
3622}
3623
avi450ce00e2014-09-24 01:58:523624void WebContentsImpl::UpdateTargetURL(const GURL& url) {
[email protected]6934a702011-12-20 00:04:513625 if (delegate_)
avi450ce00e2014-09-24 01:58:523626 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323627}
3628
[email protected]b172aee2012-04-10 17:05:263629void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103630#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293631 // The UI may be in an event-tracking loop, such as between the
3632 // mouse-down and mouse-up in text selection or a button click.
3633 // Defer the close until after tracking is complete, so that we
3634 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293635 // TODO(shess): This could get more fine-grained. For instance,
3636 // closing a tab in another window while selecting text in the
3637 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103638 if (view_->IsEventTracking()) {
3639 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293640 return;
3641 }
[email protected]60780f412013-02-25 16:34:103642#endif
[email protected]07707302009-11-06 00:50:293643
[email protected]420ae012009-04-24 05:16:323644 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523645 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513646 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323647}
3648
[email protected]66bbadaf2014-03-28 16:25:543649void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573650 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3651 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573652}
3653
[email protected]6f2ac772014-07-24 22:22:083654void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253655 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173656#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563657 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173658#endif
3659}
3660
3661bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3662#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563663 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173664#else
3665 return false;
3666#endif
3667}
3668
[email protected]b172aee2012-04-10 17:05:263669void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513670 if (delegate_ && delegate_->IsPopupOrPanel(this))
3671 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323672}
3673
[email protected]e3b10d12014-03-28 16:06:093674void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3675 bool to_different_document) {
3676 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3677 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323678}
3679
[email protected]723971b2014-02-12 11:08:253680void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323681 scoped_ptr<LoadNotificationDetails> details;
3682
[email protected]9595fd82013-04-19 21:28:493683 // Use the last committed entry rather than the active one, in case a
3684 // pending entry has been created.
3685 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203686 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493687
[email protected]420ae012009-04-24 05:16:323688 // An entry may not exist for a stop when loading an initial blank page or
3689 // if an iframe injected by script into a blank page finishes loading.
3690 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203691 base::TimeDelta elapsed =
3692 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323693
3694 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513695 entry->GetVirtualURL(),
3696 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323697 elapsed,
3698 &controller_,
3699 controller_.GetCurrentEntryIndex()));
3700 }
3701
[email protected]e3b10d12014-03-28 16:06:093702 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3703 details.get());
[email protected]420ae012009-04-24 05:16:323704}
3705
[email protected]b172aee2012-04-10 17:05:263706void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163707 controller_.DiscardNonCommittedEntries();
3708
3709 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213710 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163711}
3712
[email protected]59167c22013-06-03 18:07:323713void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103714 has_accessed_initial_document_ = true;
3715
[email protected]d1371bf8e2014-04-19 03:26:243716 // We may have left a failed browser-initiated navigation in the address bar
3717 // to let the user edit it and try again. Clear it now that content might
3718 // show up underneath it.
3719 if (!IsLoading() && controller_.GetPendingEntry())
3720 controller_.DiscardPendingEntry();
3721
[email protected]59167c22013-06-03 18:07:323722 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503723 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323724}
3725
[email protected]3f19f1a2014-05-02 05:23:273726void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473727 // No action is necessary if the opener has already been cleared.
3728 if (!opener_)
3729 return;
3730
3731 // Clear our opener so that future cross-process navigations don't have an
3732 // opener assigned.
3733 RemoveDestructionObserver(opener_);
3734 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273735
3736 // Notify all swapped out RenderViewHosts for this tab. This is important
3737 // in case we go back to them, or if another window in those processes tries
3738 // to access window.opener.
creisbbbeb062014-08-25 18:20:313739 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273740}
3741
[email protected]39f2f9252014-05-03 00:54:013742void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293743 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093744 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293745 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093746
3747 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213748 NotificationService::current()->Notify(
3749 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3750 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293751 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083752}
3753
[email protected]ef3adfc2014-05-11 00:04:543754void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3755 int32 page_id,
3756 const base::string16& title,
3757 base::i18n::TextDirection title_direction) {
3758 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3759
3760 // If we have a title, that's a pretty good indication that we've started
3761 // getting useful data.
3762 SetNotWaitingForResponse();
3763
3764 // Try to find the navigation entry, which might not be the current one.
3765 // For example, it might be from a pending RVH for the pending entry.
3766 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3767 rvh->GetSiteInstance(), page_id);
3768
3769 // We can handle title updates when we don't have an entry in
3770 // UpdateTitleForEntry, but only if the update is from the current RVH.
3771 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3772 if (!entry && rvh != GetRenderViewHost())
3773 return;
3774
3775 // TODO(evan): make use of title_direction.
3776 // http://code.google.com/p/chromium/issues/detail?id=27094
3777 if (!UpdateTitleForEntry(entry, title))
3778 return;
3779
3780 // Broadcast notifications when the UI should be updated.
3781 if (entry == controller_.GetEntryAtOffset(0))
3782 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3783}
3784
3785void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3786 const std::string& encoding) {
3787 SetEncoding(encoding);
3788}
3789
[email protected]39f2f9252014-05-03 00:54:013790void WebContentsImpl::DocumentAvailableInMainFrame(
3791 RenderViewHost* render_view_host) {
3792 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3793 DocumentAvailableInMainFrame());
3794}
[email protected]e1c3a552012-05-04 20:51:323795void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3796 // Tell the active RenderViewHost to run unload handlers and close, as long
3797 // as the request came from a RenderViewHost in the same BrowsingInstance.
3798 // In most cases, we receive this from a swapped out RenderViewHost.
3799 // It is possible to receive it from one that has just been swapped in,
3800 // in which case we might as well deliver the message anyway.
3801 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3802 GetRenderViewHost()->ClosePage();
3803}
3804
[email protected]f546640b2012-05-15 00:03:493805void WebContentsImpl::RouteMessageEvent(
3806 RenderViewHost* rvh,
3807 const ViewMsg_PostMessage_Params& params) {
3808 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363809 // came from a RenderViewHost in the same BrowsingInstance or if this
3810 // WebContents is dedicated to a browser plugin guest.
3811 // Note: This check means that an embedder could theoretically receive a
3812 // postMessage from anyone (not just its own guests). However, this is
3813 // probably not a risk for apps since other pages won't have references
3814 // to App windows.
3815 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3816 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493817 return;
3818
3819 ViewMsg_PostMessage_Params new_params(params);
3820
[email protected]0bc7f3542013-10-21 15:05:533821 if (!params.message_port_ids.empty()) {
3822 MessagePortMessageFilter* message_port_message_filter =
3823 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3824 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093825 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3826 params.message_port_ids,
3827 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533828 }
3829
[email protected]f546640b2012-05-15 00:03:493830 // If there is a source_routing_id, translate it to the routing ID for
3831 // the equivalent swapped out RVH in the target process. If we need
3832 // to create a swapped out RVH for the source tab, we create its opener
3833 // chain as well, since those will also be accessible to the target page.
3834 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3835 // Try to look up the WebContents for the source page.
3836 WebContentsImpl* source_contents = NULL;
3837 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3838 rvh->GetProcess()->GetID(), params.source_routing_id);
3839 if (source_rvh) {
3840 source_contents = static_cast<WebContentsImpl*>(
3841 source_rvh->GetDelegate()->GetAsWebContents());
3842 }
3843
3844 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363845 if (GetBrowserPluginGuest()) {
3846 // We create a swapped out RenderView for the embedder in the guest's
3847 // render process but we intentionally do not expose the embedder's
3848 // opener chain to it.
3849 new_params.source_routing_id =
3850 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3851 } else {
3852 new_params.source_routing_id =
3853 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3854 }
[email protected]f546640b2012-05-15 00:03:493855 } else {
3856 // We couldn't find it, so don't pass a source frame.
3857 new_params.source_routing_id = MSG_ROUTING_NONE;
3858 }
3859 }
3860
3861 // In most cases, we receive this from a swapped out RenderViewHost.
3862 // It is possible to receive it from one that has just been swapped in,
3863 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183864 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493865}
3866
[email protected]a796f202012-05-30 14:14:253867bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263868 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253869 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263870 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253871 if (!delegate_)
3872 return false;
3873 return delegate_->AddMessageToConsole(this, level, message, line_no,
3874 source_id);
3875}
3876
[email protected]9e797d22014-08-08 21:31:303877WebPreferences WebContentsImpl::ComputeWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273878 // We want to base the page config off of the actual URL, rather than the
3879 // virtual URL.
3880 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3881 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003882 GURL url = controller_.GetActiveEntry()
3883 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153884
[email protected]9e797d22014-08-08 21:31:303885 return GetRenderManager()->current_host()->ComputeWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323886}
3887
[email protected]0eba810b2012-10-18 03:19:363888int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213889 SiteInstance* instance) {
[email protected]82307f6b2014-08-07 03:30:123890 return GetRenderManager()->CreateRenderFrame(
3891 instance, MSG_ROUTING_NONE, true, true, true);
[email protected]0eba810b2012-10-18 03:19:363892}
3893
[email protected]b172aee2012-04-10 17:05:263894void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273895 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253896 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223897
[email protected]ea114722012-03-12 01:11:253898 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173899 if (rdh) // NULL in unittests.
3900 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253901}
3902
[email protected]b172aee2012-04-10 17:05:263903void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443904 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253905 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443906}
3907
creiscce56cd2014-09-29 22:45:223908void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:153909 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:223910 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153911 return;
3912
creiscce56cd2014-09-29 22:45:223913 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
3914 RenderFrameHostImpl* rfhi =
3915 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:583916
[email protected]e5fc1632011-08-08 07:51:533917 // Ignore renderer unresponsive event if debugger is attached to the tab
3918 // since the event may be a result of the renderer sitting on a breakpoint.
3919 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363920 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533921 return;
3922
creiscce56cd2014-09-29 22:45:223923 if (rfhi->is_waiting_for_beforeunload_ack() ||
3924 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:323925 // Hang occurred while firing the beforeunload/unload handler.
3926 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583927 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323928
[email protected]fa944cb82013-11-15 17:51:213929 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323930 return;
3931
3932 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563933 // nothing we can do to recover. If the hang is in the beforeunload handler,
3934 // pretend the beforeunload listeners have all fired and allow the delegate
3935 // to continue closing; the user will not have the option of cancelling the
3936 // close. Otherwise, pretend the unload listeners have all fired and close
3937 // the tab.
3938 bool close = true;
creiscce56cd2014-09-29 22:45:223939 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563940 delegate_->BeforeUnloadFired(this, true, &close);
3941 }
3942 if (close)
creiscce56cd2014-09-29 22:45:223943 Close(rvhi);
[email protected]420ae012009-04-24 05:16:323944 return;
3945 }
3946
[email protected]9f76c1e2012-03-05 15:15:583947 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473948 return;
3949
[email protected]6934a702011-12-20 00:04:513950 if (delegate_)
3951 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323952}
3953
[email protected]b172aee2012-04-10 17:05:263954void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513955 if (delegate_)
3956 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323957}
3958
[email protected]b172aee2012-04-10 17:05:263959void WebContentsImpl::LoadStateChanged(
3960 const GURL& url,
3961 const net::LoadStateWithParam& load_state,
3962 uint64 upload_position,
3963 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323964 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563965 upload_position_ = upload_position;
3966 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503967 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213968 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303969 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213970 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323971 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463972 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:223973 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
3974 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:463975 }
[email protected]420ae012009-04-24 05:16:323976}
3977
[email protected]b172aee2012-04-10 17:05:263978void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553979 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323980 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123981 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3982 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513983 if (delegate_)
3984 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093985 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323986}
3987
[email protected]58d5cfe2013-07-10 02:40:523988void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543989 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233990 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223991 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543992}
3993
[email protected]b172aee2012-04-10 17:05:263994void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103995 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213996 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263997 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3998 // here during container initialization and normal window size will be set
3999 // later. In case of tab duplication this resizing to 0x0 prevents setting
4000 // normal size later so just ignore it.
4001 if (!size.IsEmpty())
4002 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324003}
4004
[email protected]af905902013-10-01 21:38:514005void WebContentsImpl::CancelModalDialogsForRenderManager() {
4006 // We need to cancel modal dialogs when doing a process swap, since the load
4007 // deferrer would prevent us from swapping out.
4008 if (dialog_manager_)
4009 dialog_manager_->CancelActiveAndPendingDialogs(this);
4010}
4011
[email protected]02d7b6e2014-06-24 21:01:504012void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4013 RenderFrameHost* new_host,
4014 bool is_main_frame) {
4015 if (is_main_frame) {
4016 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4017 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084018
[email protected]02d7b6e2014-06-24 21:01:504019 // Make sure the visible RVH reflects the new delegate's preferences.
4020 if (delegate_)
4021 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394022
[email protected]02d7b6e2014-06-24 21:01:504023 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4024 }
4025
4026 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544027}
4028
[email protected]14392a52012-05-02 20:28:444029int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4030 SiteInstance* instance) {
4031 if (!opener_)
4032 return MSG_ROUTING_NONE;
4033
4034 // Recursively create RenderViews for anything else in the opener chain.
4035 return opener_->CreateOpenerRenderViews(instance);
4036}
4037
4038int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4039 int opener_route_id = MSG_ROUTING_NONE;
4040
4041 // If this tab has an opener, ensure it has a RenderView in the given
4042 // SiteInstance as well.
4043 if (opener_)
4044 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4045
[email protected]45a22ad2013-02-21 03:25:004046 // If any of the renderers (current, pending, or swapped out) for this
4047 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214048 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4049 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374050
[email protected]fa944cb82013-11-15 17:51:214051 if (GetRenderManager()->pending_render_view_host() &&
4052 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4053 instance)
4054 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004055
[email protected]fa944cb82013-11-15 17:51:214056 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374057 instance);
4058 if (rvh)
4059 return rvh->GetRoutingID();
4060
[email protected]14392a52012-05-02 20:28:444061 // Create a swapped out RenderView in the given SiteInstance if none exists,
4062 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]82307f6b2014-08-07 03:30:124063 return GetRenderManager()->CreateRenderFrame(
4064 instance, opener_route_id, true, true, true);
[email protected]14392a52012-05-02 20:28:444065}
4066
[email protected]b172aee2012-04-10 17:05:264067NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194068 return GetController();
[email protected]3a3d47472010-07-15 21:03:544069}
4070
[email protected]b172aee2012-04-10 17:05:264071WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:564072 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:324073}
4074
[email protected]10f417c52011-12-28 21:04:234075NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264076 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324077 return controller_.GetLastCommittedEntry();
4078}
4079
[email protected]b172aee2012-04-10 17:05:264080bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164081 RenderViewHost* render_view_host,
4082 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044083 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124084 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434085 TRACE_EVENT0("browser,navigation",
4086 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444087 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484088 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164089 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4090 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4091 // case this because RWH is still a base class of RenderViewHost, and child
4092 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124093 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164094 RenderWidgetHostViewChildFrame* rwh_view_child =
4095 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164096 rwh_view = rwh_view_child;
4097 } else {
lazyboy549b3b42014-10-20 17:16:044098 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164099 }
[email protected]1a98a932009-11-17 00:12:524100
[email protected]420ae012009-04-24 05:16:324101 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444102 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214103 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324104
[email protected]74ce1ad2011-12-16 21:51:464105 // Make sure we use the correct starting page_id in the new RenderView.
4106 UpdateMaxPageIDIfNecessary(render_view_host);
4107 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584108 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464109
[email protected]9f76c1e2012-03-05 15:15:584110 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264111 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494112 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044113 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494114 max_page_id,
4115 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524116 return false;
[email protected]14392a52012-05-02 20:28:444117 }
[email protected]a4127722011-04-27 23:13:524118
[email protected]a220b5932013-09-21 03:47:444119#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504120 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4121 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444122 if (rwh_view) {
4123 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4124 render_widget_host->WasResized();
4125 }
[email protected]f8233cc2011-05-31 20:24:504126#endif
4127
[email protected]420ae012009-04-24 05:16:324128 return true;
4129}
4130
[email protected]82307f6b2014-08-07 03:30:124131bool WebContentsImpl::CreateRenderFrameForRenderManager(
4132 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494133 int parent_routing_id,
4134 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434135 TRACE_EVENT0("browser,navigation",
4136 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124137
4138 RenderFrameHostImpl* rfh =
4139 static_cast<RenderFrameHostImpl*>(render_frame_host);
japhete6adf142014-10-31 00:01:494140 if (!rfh->CreateRenderFrame(parent_routing_id, proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124141 return false;
4142
4143 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4144 // RenderFrameHost will have to be associated with the appropriate
4145 // RenderWidgetHostView or a new one should be created here.
4146
4147 return true;
4148}
4149
[email protected]7d244f12013-08-22 21:41:514150#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454151
[email protected]155c7f22013-12-09 17:07:184152base::android::ScopedJavaLocalRef<jobject>
4153WebContentsImpl::GetJavaWebContents() {
4154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564155 return GetWebContentsAndroid()->GetJavaObject();
4156}
[email protected]155c7f22013-12-09 17:07:184157
[email protected]0e813a52014-08-13 10:34:564158WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184159 WebContentsAndroid* web_contents_android =
4160 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4161 if (!web_contents_android) {
4162 web_contents_android = new WebContentsAndroid(this);
4163 SetUserData(kWebContentsAndroidKey, web_contents_android);
4164 }
[email protected]0e813a52014-08-13 10:34:564165 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184166}
4167
[email protected]7d244f12013-08-22 21:41:514168bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4169 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164170 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044171 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594172 true);
[email protected]7d244f12013-08-22 21:41:514173}
[email protected]fc2b46b2014-05-03 16:33:454174
4175#elif defined(OS_MACOSX)
4176
[email protected]75f4df72014-07-16 22:39:424177void WebContentsImpl::SetAllowOtherViews(bool allow) {
4178 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454179}
4180
[email protected]75f4df72014-07-16 22:39:424181bool WebContentsImpl::GetAllowOtherViews() {
4182 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454183}
4184
[email protected]7d244f12013-08-22 21:41:514185#endif
4186
[email protected]6fba26d2014-04-29 09:38:284187void WebContentsImpl::OnDialogClosed(int render_process_id,
4188 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264189 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494190 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264191 bool success,
[email protected]fcf75d42013-12-03 20:11:264192 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284193 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4194 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494195 last_dialog_suppressed_ = dialog_was_suppressed;
4196
[email protected]beb440c2009-11-06 04:08:544197 if (is_showing_before_unload_dialog_ && !success) {
4198 // If a beforeunload dialog is canceled, we need to stop the throbber from
4199 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284200 if (rfh)
4201 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354202 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104203
[email protected]6d65a462013-06-21 21:29:124204 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4205 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544206 }
[email protected]87de04b02014-04-08 22:14:494207
[email protected]beb440c2009-11-06 04:08:544208 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284209 if (rfh) {
4210 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4211 dialog_was_suppressed);
4212 } else {
4213 // Don't leak the sync IPC reply if the RFH or process is gone.
4214 delete reply_msg;
4215 }
[email protected]beb440c2009-11-06 04:08:544216}
4217
[email protected]b172aee2012-04-10 17:05:264218void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544219 if (encoding == last_reported_encoding_)
4220 return;
4221 last_reported_encoding_ = encoding;
4222
4223 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124224 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104225}
[email protected]f45d2a72010-03-08 23:28:354226
[email protected]1ac10dca2013-08-20 20:47:044227bool WebContentsImpl::IsHidden() {
4228 return capturer_count_ == 0 && !should_normally_be_visible_;
4229}
4230
[email protected]b0936d22013-11-28 06:47:364231RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214232 return frame_tree_.root()->render_manager();
4233}
4234
[email protected]b172aee2012-04-10 17:05:264235RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584236 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4237}
[email protected]7900bfdb2012-05-24 19:31:244238
[email protected]f8497342013-02-05 22:15:024239BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394240 return browser_plugin_guest_.get();
4241}
4242
[email protected]738f57a2013-06-29 21:06:544243void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4244 CHECK(!browser_plugin_guest_);
4245 browser_plugin_guest_.reset(guest);
4246}
4247
[email protected]f8497342013-02-05 22:15:024248BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394249 return browser_plugin_embedder_.get();
4250}
[email protected]8ff00d72012-10-23 19:12:214251
[email protected]d9030b82013-07-19 08:26:064252void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194253 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304254 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4255 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4256 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064257}
4258
4259void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304260 active_audio_players_.clear();
4261 active_video_players_.clear();
4262 audio_power_save_blocker_.reset();
4263 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064264}
4265
[email protected]fc2b46b2014-05-03 16:33:454266gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214267 gfx::Size size;
4268 if (delegate_)
4269 size = delegate_->GetSizeForNewRenderView(this);
4270 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454271 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214272 return size;
4273}
4274
[email protected]ae7eeda2014-07-04 01:53:264275void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4276 FOR_EACH_OBSERVER(
4277 WebContentsObserver, observers_, FrameDetached(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554278}
4279
[email protected]222f5822014-02-05 23:40:494280void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4281 if (!delegate_)
4282 return;
4283 const gfx::Size new_size = GetPreferredSize();
4284 if (new_size != old_size)
4285 delegate_->UpdatePreferredSize(this, new_size);
4286}
4287
dalecurtisbc6572e12014-09-12 19:22:304288void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4289 ActiveMediaPlayerMap* player_map) {
4290 const uintptr_t key =
4291 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4292 DCHECK(std::find((*player_map)[key].begin(),
4293 (*player_map)[key].end(),
4294 player_cookie) == (*player_map)[key].end());
4295 (*player_map)[key].push_back(player_cookie);
4296}
4297
4298void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4299 ActiveMediaPlayerMap* player_map) {
4300 const uintptr_t key =
4301 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4302 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4303 if (it == player_map->end())
4304 return;
4305
4306 // Remove the player.
4307 PlayerList::iterator player_it =
4308 std::find(it->second.begin(), it->second.end(), player_cookie);
4309 if (player_it != it->second.end())
4310 it->second.erase(player_it);
4311
4312 // If there are no players left, remove the map entry.
4313 if (it->second.empty())
4314 player_map->erase(it);
4315}
4316
4317void WebContentsImpl::RemoveAllMediaPlayerEntries(
4318 RenderFrameHost* render_frame_host,
4319 ActiveMediaPlayerMap* player_map) {
4320 ActiveMediaPlayerMap::iterator it =
4321 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4322 if (it == player_map->end())
4323 return;
4324 player_map->erase(it);
4325}
4326
[email protected]23f41fd2014-06-21 05:29:174327void WebContentsImpl::ResumeResponseDeferredAtStart() {
4328 FrameTreeNode* node = frame_tree_.root();
4329 node->render_manager()->ResumeResponseDeferredAtStart();
4330}
4331
[email protected]34ff1cfc2014-08-20 06:16:054332void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4333 force_disable_overscroll_content_ = force_disable;
4334 if (view_)
4335 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4336}
4337
[email protected]8ff00d72012-10-23 19:12:214338} // namespace content