blob: 84db9fef2b06226244fafcc612f93f1efb06de57 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]95640212014-07-26 18:14:3021#include "content/browser/accessibility/accessibility_mode_helper.h"
22#include "content/browser/accessibility/browser_accessibility_state_impl.h"
[email protected]7a846df2012-09-20 19:17:3923#include "content/browser/browser_plugin/browser_plugin_embedder.h"
24#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5925#include "content/browser/child_process_security_policy_impl.h"
dgozman24bfc912014-09-29 11:04:1826#include "content/browser/devtools/devtools_manager.h"
[email protected]5f2aa722013-08-07 16:59:4127#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0428#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4629#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1230#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1631#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1632#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4033#include "content/browser/frame_host/interstitial_page_impl.h"
34#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0135#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1836#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1637#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5738#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0539#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4440#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4041#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3042#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5243#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]0bc7f3542013-10-21 15:05:5344#include "content/browser/message_port_message_filter.h"
45#include "content/browser/message_port_service.h"
tommyclieb25b2a2014-11-03 19:45:0946#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]d9030b82013-07-19 08:26:0647#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3048#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5049#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3250#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5051#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4852#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0953#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3354#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1155#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5856#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0357#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5658#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1459#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4260#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4461#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0262#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1763#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5164#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0265#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3666#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1167#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2868#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4469#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3670#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1771#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1472#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4673#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1574#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0075#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2776#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0077#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3778#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1479#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3080#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3281#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0982#include "content/public/browser/screen_orientation_dispatcher_host.h"
[email protected]4c3a23582012-08-18 08:54:3483#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3884#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4285#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2586#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2187#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4888#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5489#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4990#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2091#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0392#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5793#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:0594#include "content/public/common/web_preferences.h"
[email protected]a53209b2012-01-20 16:48:1695#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2996#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5397#include "net/http/http_cache.h"
98#include "net/http/http_transaction_factory.h"
99#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34100#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:56101#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01102#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41103#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52104#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31105
[email protected]583418cc2013-01-17 14:01:10106#if defined(OS_ANDROID)
107#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:45108#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18109#include "content/browser/web_contents/web_contents_android.h"
[email protected]583418cc2013-01-17 14:01:10110#endif
111
[email protected]f66df822012-05-18 16:52:17112#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50113#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57114#endif
[email protected]3e45ba92009-02-20 21:09:00115
[email protected]8ff00d72012-10-23 19:12:21116namespace content {
[email protected]420ae012009-04-24 05:16:32117namespace {
118
[email protected]960b0372014-05-19 18:01:00119const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
120
121// This matches what Blink's ProgressTracker has traditionally used for a
122// minimum progress value.
123const double kMinimumLoadingProgress = 0.1;
124
[email protected]82114f52012-03-20 22:53:41125const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05126
[email protected]155c7f22013-12-09 17:07:18127#if defined(OS_ANDROID)
128const char kWebContentsAndroidKey[] = "web_contents_android";
129#endif // OS_ANDROID
130
[email protected]e4abd3b42013-11-12 18:28:47131base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46132g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
133
thestigc4cac8f2014-09-04 21:17:50134static int StartDownload(RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39135 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29136 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30137 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02138 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58139 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02140 ++g_next_image_download_id,
141 url,
142 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30143 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02144 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39145}
146
[email protected]8bfc8272013-09-09 20:10:53147void NotifyCacheOnIO(
148 scoped_refptr<net::URLRequestContextGetter> request_context,
149 const GURL& url,
150 const std::string& http_method) {
151 request_context->GetURLRequestContext()->http_transaction_factory()->
152 GetCache()->OnExternalCacheHit(url, http_method);
153}
154
[email protected]9b159a52013-10-03 17:24:55155// Helper function for retrieving all the sites in a frame tree.
156bool CollectSites(BrowserContext* context,
157 std::set<GURL>* sites,
158 FrameTreeNode* node) {
159 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
160 return true;
161}
162
[email protected]a86c0e962013-12-17 17:10:39163bool ForEachFrameInternal(
164 const base::Callback<void(RenderFrameHost*)>& on_frame,
165 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41166 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39167 return true;
168}
169
[email protected]95640212014-07-26 18:14:30170bool ForEachPendingFrameInternal(
171 const base::Callback<void(RenderFrameHost*)>& on_frame,
172 FrameTreeNode* node) {
173 RenderFrameHost* pending_frame_host =
174 node->render_manager()->pending_frame_host();
175 if (pending_frame_host)
176 on_frame.Run(pending_frame_host);
177 return true;
178}
179
[email protected]a86c0e962013-12-17 17:10:39180void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
181 IPC::Message* message_copy = new IPC::Message(*message);
182 message_copy->set_routing_id(rfh->GetRoutingID());
183 rfh->Send(message_copy);
184}
185
[email protected]948481d2014-06-11 18:32:22186void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
187 RenderFrameHost* rfh) {
188 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
189 ->frame_tree_node()
190 ->render_manager()
191 ->GetRenderWidgetHostView();
192 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59193}
194
[email protected]95640212014-07-26 18:14:30195void SetAccessibilityModeOnFrame(AccessibilityMode mode,
196 RenderFrameHost* frame_host) {
197 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
198}
199
[email protected]420ae012009-04-24 05:16:32200} // namespace
201
[email protected]54944cde2012-12-09 09:24:59202WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15203 return WebContentsImpl::CreateWithOpener(
204 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19205}
206
207WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59208 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30209 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59210 WebContentsImpl* new_contents = new WebContentsImpl(
211 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30212
213 for (SessionStorageNamespaceMap::const_iterator it =
214 session_storage_namespace_map.begin();
215 it != session_storage_namespace_map.end();
216 ++it) {
217 new_contents->GetController()
218 .SetSessionStorageNamespace(it->first, it->second.get());
219 }
220
[email protected]54944cde2012-12-09 09:24:59221 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19222 return new_contents;
[email protected]a81343d232011-12-27 07:39:20223}
[email protected]746d3052012-05-22 15:15:47224
[email protected]e4abd3b42013-11-12 18:28:47225void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46226 g_created_callbacks.Get().push_back(callback);
227}
228
[email protected]e4abd3b42013-11-12 18:28:47229void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46230 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
231 if (g_created_callbacks.Get().at(i).Equals(callback)) {
232 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
233 return;
234 }
235 }
236}
237
[email protected]299d7f12012-05-23 05:31:15238WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47239 return rvh->GetDelegate()->GetAsWebContents();
240}
241
[email protected]a86c0e962013-12-17 17:10:39242WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
243 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
244 if (!rfh_impl)
245 return NULL;
246 return rfh_impl->delegate()->GetAsWebContents();
247}
248
[email protected]7fff43e2013-05-21 20:21:10249// WebContentsImpl::DestructionObserver ----------------------------------------
250
251class WebContentsImpl::DestructionObserver : public WebContentsObserver {
252 public:
253 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
254 : WebContentsObserver(watched_contents),
255 owner_(owner) {
256 }
257
258 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58259 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58260 owner_->OnWebContentsDestroyed(
261 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10262 }
263
264 private:
265 WebContentsImpl* owner_;
266
267 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
268};
269
[email protected]8ed16472014-04-11 19:02:48270WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
271 int render_frame_id,
272 ColorChooser* chooser,
273 int identifier)
274 : render_process_id(render_process_id),
275 render_frame_id(render_frame_id),
276 chooser(chooser),
277 identifier(identifier) {
278}
279
280WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
281}
282
[email protected]b172aee2012-04-10 17:05:26283// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32284
blundellc57b93f2014-10-29 13:19:57285WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
286 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42287 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22288 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57289 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44290 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49291 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08292#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41293 accessible_parent_(NULL),
294#endif
[email protected]6ea6bdf2013-12-06 13:35:01295 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57296 this,
297 this,
298 this,
299 this),
[email protected]d5f942ba2008-09-26 19:30:34300 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03301 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23302 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
303 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34304 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26305 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00306 loading_total_progress_(0.0),
[email protected]960b0372014-05-19 18:01:00307 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56308 upload_size_(0),
309 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47310 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10311 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55312 capturer_count_(0),
313 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57314 is_being_destroyed_(false),
315 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15316 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01317 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02318 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38319 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21320 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
321 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29322 totalPinchGestureAmount_(0),
323 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44324 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42325 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03326 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49327 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05328 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30329 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57330 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30331 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30332 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddy371ad9142014-09-17 08:01:46333 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50334 virtual_keyboard_requested_(false),
mohan.reddy371ad9142014-09-17 08:01:46335 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
tommyclieb25b2a2014-11-03 19:45:091182#if defined(ENABLE_PLUGINS)
1183 plugin_content_origin_whitelist_.reset(
1184 new PluginContentOriginWhitelist(this));
1185#endif
1186
[email protected]d1198fd2012-08-13 22:50:191187 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211188 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1189 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101190
[email protected]01f83f92014-06-17 14:41:541191 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091192 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541193
mlamouriefdca9d2014-09-16 16:55:401194 manifest_manager_host_.reset(new ManifestManagerHost(this));
1195
[email protected]c7654a232013-06-12 21:04:441196#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101197 date_time_chooser_.reset(new DateTimeChooserAndroid());
1198#endif
[email protected]d1198fd2012-08-13 22:50:191199}
1200
[email protected]7fff43e2013-05-21 20:21:101201void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1202 RemoveDestructionObserver(web_contents);
1203
[email protected]14392a52012-05-02 20:28:441204 // Clear the opener if it has been closed.
1205 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441206 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511207 return;
[email protected]14392a52012-05-02 20:28:441208 }
[email protected]ceee8cd2013-03-08 04:59:511209 // Clear a pending contents that has been closed before being shown.
1210 for (PendingContents::iterator iter = pending_contents_.begin();
1211 iter != pending_contents_.end();
1212 ++iter) {
1213 if (iter->second != web_contents)
1214 continue;
1215 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511216 return;
1217 }
1218 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441219}
1220
[email protected]7fff43e2013-05-21 20:21:101221void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1222 if (!ContainsKey(destruction_observers_, web_contents)) {
1223 destruction_observers_[web_contents] =
1224 new DestructionObserver(this, web_contents);
1225 }
1226}
1227
1228void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1229 DestructionObservers::iterator iter =
1230 destruction_observers_.find(web_contents);
1231 if (iter != destruction_observers_.end()) {
1232 delete destruction_observers_[web_contents];
1233 destruction_observers_.erase(iter);
1234 }
1235}
1236
[email protected]b172aee2012-04-10 17:05:261237void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311238 observers_.AddObserver(observer);
1239}
1240
[email protected]b172aee2012-04-10 17:05:261241void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311242 observers_.RemoveObserver(observer);
1243}
1244
[email protected]948481d2014-06-11 18:32:221245std::set<RenderWidgetHostView*>
1246WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1247 std::set<RenderWidgetHostView*> set;
1248 if (ShowingInterstitialPage()) {
1249 set.insert(GetRenderWidgetHostView());
1250 } else {
1251 ForEachFrame(
1252 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1253 }
[email protected]de3c5d82014-05-28 22:12:591254 return set;
1255}
1256
[email protected]b172aee2012-04-10 17:05:261257void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341258 if (delegate_)
1259 delegate_->ActivateContents(this);
1260}
1261
[email protected]b172aee2012-04-10 17:05:261262void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121263 if (delegate_)
1264 delegate_->DeactivateContents(this);
1265}
1266
[email protected]b172aee2012-04-10 17:05:261267void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481268 if (delegate_)
1269 delegate_->LostCapture();
1270}
1271
[email protected]b24b68a2012-09-24 21:57:261272void WebContentsImpl::RenderWidgetDeleted(
1273 RenderWidgetHostImpl* render_widget_host) {
1274 if (is_being_destroyed_) {
1275 // |created_widgets_| might have been destroyed.
1276 return;
1277 }
1278
1279 std::set<RenderWidgetHostImpl*>::iterator iter =
1280 created_widgets_.find(render_widget_host);
1281 if (iter != created_widgets_.end())
1282 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541283
1284 if (render_widget_host &&
1285 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491286 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1287 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541288 FOR_EACH_OBSERVER(WebContentsObserver,
1289 observers_,
1290 DidDestroyFullscreenWidget(
1291 fullscreen_widget_routing_id_));
1292 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031293 if (fullscreen_widget_had_focus_at_shutdown_)
1294 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541295 }
[email protected]b24b68a2012-09-24 21:57:261296}
1297
miu9e14e492014-10-25 02:39:041298void WebContentsImpl::RenderWidgetGotFocus(
1299 RenderWidgetHostImpl* render_widget_host) {
1300 // Notify the delegate if an embedded fullscreen widget was focused.
1301 if (delegate_ && render_widget_host &&
1302 delegate_->EmbedsFullscreenWidget() &&
1303 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1304 delegate_->WebContentsFocused(this);
1305}
1306
[email protected]b172aee2012-04-10 17:05:261307bool WebContentsImpl::PreHandleKeyboardEvent(
1308 const NativeWebKeyboardEvent& event,
1309 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481310 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131311 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481312}
1313
[email protected]b172aee2012-04-10 17:05:261314void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101315 if (browser_plugin_embedder_ &&
1316 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1317 return;
1318 }
[email protected]63954792011-07-11 04:17:481319 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131320 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481321}
1322
[email protected]d92026ef2014-03-03 21:04:131323bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461324 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191325#if !defined(OS_MACOSX)
1326 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1327 // isn't done for two reasons:
1328 // -the OS already has a gesture to do this through pinch-zoom
1329 // -if a user starts an inertial scroll, let's go, and presses control
1330 // (i.e. control+tab) then the OS's buffered scroll events will come in
1331 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521332 if (delegate_ &&
1333 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551334 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1335 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1336 // gestures, which are regrettably easy to trigger accidentally.
1337 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521338 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1339 return true;
1340 }
[email protected]bccc4472013-04-18 16:37:191341#endif
[email protected]fb3f066e2013-02-12 19:12:521342 return false;
1343}
1344
[email protected]04bce562014-01-30 05:34:541345bool WebContentsImpl::PreHandleGestureEvent(
1346 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031347 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541348}
1349
[email protected]bab38af2014-03-30 17:37:291350bool WebContentsImpl::HandleGestureEvent(
1351 const blink::WebGestureEvent& event) {
1352 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1353 // Use them to implement browser zoom, as for HandleWheelEvent above.
1354 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331355 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291356 // The scale difference necessary to trigger a zoom action. Derived from
1357 // experimentation to find a value that feels reasonable.
1358 const float kZoomStepValue = 0.6f;
1359
1360 // Find the (absolute) thresholds on either side of the current zoom factor,
1361 // then convert those to actual numbers to trigger a zoom in or out.
1362 // This logic deliberately makes the range around the starting zoom value
1363 // for the gesture twice as large as the other ranges (i.e., the notches are
1364 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1365 // so that it's easier to get back to your starting point than it is to
1366 // overshoot.
1367 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1368 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1369 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1370 : -backStep;
1371 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1372 : backStep;
1373
[email protected]fb546cb2014-04-28 14:09:371374 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291375 if (totalPinchGestureAmount_ > zoomInThreshold) {
1376 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461377 if (delegate_)
1378 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291379 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1380 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461381 if (delegate_)
1382 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291383 }
1384 return true;
1385 }
1386
1387 return false;
1388}
1389
[email protected]b172aee2012-04-10 17:05:261390void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431391 if (delegate_)
1392 delegate_->HandleMouseDown();
1393}
1394
[email protected]b172aee2012-04-10 17:05:261395void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481396 if (delegate_)
1397 delegate_->HandleMouseUp();
1398}
1399
[email protected]590a634e2012-07-19 16:38:231400void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481401 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231402 delegate_->HandlePointerActivate();
1403}
1404
1405void WebContentsImpl::HandleGestureBegin() {
1406 if (delegate_)
1407 delegate_->HandleGestureBegin();
1408}
1409
1410void WebContentsImpl::HandleGestureEnd() {
1411 if (delegate_)
1412 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481413}
1414
[email protected]b172aee2012-04-10 17:05:261415void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491416 // This method is being called to enter or leave renderer-initiated fullscreen
1417 // mode. Either way, make sure any existing fullscreen widget is shut down
1418 // first.
1419 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1420 if (widget_view)
1421 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1422
[email protected]8a5e0ca2011-08-25 06:30:471423 if (delegate_)
1424 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371425
1426 FOR_EACH_OBSERVER(WebContentsObserver,
1427 observers_,
1428 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471429}
1430
[email protected]b172aee2012-04-10 17:05:261431bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381432 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121433}
1434
[email protected]a9c81f02012-06-01 00:15:441435void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1436 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371437 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441438 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371439 } else {
1440 GotResponseToLockMouseRequest(false);
1441 }
1442}
1443
[email protected]b172aee2012-04-10 17:05:261444void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371445 if (delegate_)
1446 delegate_->LostMouseLock();
1447}
1448
[email protected]bafe6cd2012-05-23 23:09:501449void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201450 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501451 int route_id,
[email protected]227692c52013-05-31 22:43:041452 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131453 const ViewHostMsg_CreateWindow_Params& params,
1454 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501455 // We usually create the new window in the same BrowsingInstance (group of
1456 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551457 // if the opener is being suppressed (in a non-guest), we create a new
1458 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251459 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551460
[email protected]04cbd3d2013-12-04 04:58:201461 // If the opener is to be suppressed, the new window can be in any process.
1462 // Since routing ids are process specific, we must not have one passed in
1463 // as argument here.
1464 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1465
[email protected]bafe6cd2012-05-23 23:09:501466 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551467 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571468 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501469 GetSiteInstance();
1470
[email protected]04cbd3d2013-12-04 04:58:201471 // A message to create a new window can only come from the active process for
1472 // this WebContentsImpl instance. If any other process sends the request,
1473 // it is invalid and the process must be terminated.
1474 if (GetRenderProcessHost()->GetID() != render_process_id) {
1475 base::ProcessHandle process_handle =
1476 RenderProcessHost::FromID(render_process_id)->GetHandle();
1477 if (process_handle != base::kNullProcessHandle) {
1478 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391479 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
thestigc4cac8f2014-09-04 21:17:501480 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201481 }
1482 return;
1483 }
1484
[email protected]d1198fd2012-08-13 22:50:191485 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341486 //
1487 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301488 const std::string& partition_id =
1489 GetContentClient()->browser()->
1490 GetStoragePartitionIdForSite(GetBrowserContext(),
1491 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461492 StoragePartition* partition = BrowserContext::GetStoragePartition(
1493 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411494 DOMStorageContextWrapper* dom_storage_context =
1495 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191496 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1497 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1498 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371499
1500 if (delegate_ &&
1501 !delegate_->ShouldCreateWebContents(this,
1502 route_id,
1503 params.window_container_type,
1504 params.frame_name,
1505 params.target_url,
1506 partition_id,
1507 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011508 if (route_id != MSG_ROUTING_NONE &&
1509 !RenderViewHost::FromID(render_process_id, route_id)) {
1510 // If the embedder didn't create a WebContents for this route, we need to
1511 // delete the RenderView that had already been created.
1512 Send(new ViewMsg_Close(route_id));
1513 }
[email protected]dd6730412013-08-14 15:03:371514 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1515 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1516 main_frame_route_id);
1517 return;
1518 }
1519
1520 // Create the new web contents. This will automatically create the new
1521 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461522 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591523 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041524 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061525 create_params.opener = this;
1526 create_params.opener_suppressed = params.opener_suppressed;
1527 if (params.disposition == NEW_BACKGROUND_TAB)
1528 create_params.initially_hidden = true;
1529
[email protected]4858e432014-06-23 18:14:171530 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551531 if (!is_guest) {
1532 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451533 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171534 new_contents = static_cast<WebContentsImpl*>(
1535 WebContents::Create(create_params));
1536 } else {
1537 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551538 }
[email protected]50d326e2014-05-20 17:59:061539 new_contents->GetController().SetSessionStorageNamespace(
1540 partition_id,
1541 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261542 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191543
[email protected]c4538072013-03-18 02:17:551544 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341545 // will be shown immediately).
1546 if (!params.opener_suppressed) {
1547 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451548 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501549
[email protected]d70bea92013-04-05 04:23:341550 // TODO(brettw): It seems bogus that we have to call this function on the
1551 // newly created object and give it one of its own member variables.
lazyboy549b3b42014-10-20 17:16:041552 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false);
[email protected]d70bea92013-04-05 04:23:341553 }
[email protected]bafe6cd2012-05-23 23:09:501554 // Save the created window associated with the route so we can show it
1555 // later.
1556 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1557 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101558 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501559 }
1560
1561 if (delegate_) {
1562 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071563 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131564 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501565 }
1566
1567 if (params.opener_suppressed) {
1568 // When the opener is suppressed, the original renderer cannot access the
1569 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001570 bool was_blocked = false;
1571 if (delegate_) {
1572 gfx::Rect initial_pos;
1573 delegate_->AddNewContents(
1574 this, new_contents, params.disposition, initial_pos,
1575 params.user_gesture, &was_blocked);
1576 }
1577 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211578 OpenURLParams open_params(params.target_url,
1579 Referrer(),
1580 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351581 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211582 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301583 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001584 new_contents->OpenURL(open_params);
1585 }
[email protected]bafe6cd2012-05-23 23:09:501586 }
1587}
1588
[email protected]a8504022013-12-04 20:23:511589void WebContentsImpl::CreateNewWidget(int render_process_id,
1590 int route_id,
[email protected]180ef242013-11-07 06:50:461591 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511592 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501593}
1594
[email protected]a8504022013-12-04 20:23:511595void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1596 int route_id) {
1597 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501598}
1599
[email protected]a8504022013-12-04 20:23:511600void WebContentsImpl::CreateNewWidget(int render_process_id,
1601 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501602 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461603 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211604 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511605 // A message to create a new widget can only come from the active process for
1606 // this WebContentsImpl instance. If any other process sends the request,
1607 // it is invalid and the process must be terminated.
1608 if (process->GetID() != render_process_id) {
1609 base::ProcessHandle process_handle =
1610 RenderProcessHost::FromID(render_process_id)->GetHandle();
1611 if (process_handle != base::kNullProcessHandle) {
1612 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391613 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
thestigc4cac8f2014-09-04 21:17:501614 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511615 }
1616 return;
1617 }
1618
[email protected]bafe6cd2012-05-23 23:09:501619 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041620 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261621 created_widgets_.insert(widget_host);
1622
[email protected]cfd80b02014-05-01 17:46:481623 RenderWidgetHostViewBase* widget_view =
1624 static_cast<RenderWidgetHostViewBase*>(
1625 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191626 if (!widget_view)
1627 return;
[email protected]bafe6cd2012-05-23 23:09:501628 if (!is_fullscreen) {
1629 // Popups should not get activated.
1630 widget_view->SetPopupType(popup_type);
1631 }
1632 // Save the created widget associated with the route so we can show it later.
1633 pending_widget_views_[route_id] = widget_view;
1634
1635#if defined(OS_MACOSX)
1636 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1637 // to allow it to survive the trip without being hosted.
1638 base::mac::NSObjectRetain(widget_view->GetNativeView());
1639#endif
1640}
1641
1642void WebContentsImpl::ShowCreatedWindow(int route_id,
1643 WindowOpenDisposition disposition,
1644 const gfx::Rect& initial_pos,
1645 bool user_gesture) {
1646 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001647 if (contents) {
1648 WebContentsDelegate* delegate = GetDelegate();
1649 if (delegate) {
1650 delegate->AddNewContents(
1651 this, contents, disposition, initial_pos, user_gesture, NULL);
1652 }
1653 }
[email protected]bafe6cd2012-05-23 23:09:501654}
1655
1656void WebContentsImpl::ShowCreatedWidget(int route_id,
1657 const gfx::Rect& initial_pos) {
1658 ShowCreatedWidget(route_id, false, initial_pos);
1659}
1660
1661void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1662 ShowCreatedWidget(route_id, true, gfx::Rect());
1663}
1664
1665void WebContentsImpl::ShowCreatedWidget(int route_id,
1666 bool is_fullscreen,
1667 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481668 RenderWidgetHostViewBase* widget_host_view =
1669 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501670 if (!widget_host_view)
1671 return;
[email protected]cfd80b02014-05-01 17:46:481672
1673 RenderWidgetHostView* view = NULL;
1674 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1675 if (guest && guest->embedder_web_contents()) {
1676 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1677 } else {
1678 view = GetRenderWidgetHostView();
1679 }
1680
[email protected]4aebbca2013-09-17 22:26:491681 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311682 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031683 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311684 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491685 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1686 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1687 delegate_->ToggleFullscreenModeForTab(this, true);
1688 } else {
[email protected]cfd80b02014-05-01 17:46:481689 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491690 }
[email protected]4aebbca2013-09-17 22:26:491691 FOR_EACH_OBSERVER(WebContentsObserver,
1692 observers_,
1693 DidShowFullscreenWidget(route_id));
1694 if (!widget_host_view->HasFocus())
1695 widget_host_view->Focus();
1696 } else {
[email protected]cfd80b02014-05-01 17:46:481697 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491698 }
[email protected]89054502012-06-03 10:29:241699
1700 RenderWidgetHostImpl* render_widget_host_impl =
1701 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1702 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311703 // Only allow privileged mouse lock for fullscreen render widget, which is
1704 // used to implement Pepper Flash fullscreen.
1705 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501706
1707#if defined(OS_MACOSX)
1708 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1709 // properly embedded (or purposefully ignored) we can release the retain we
1710 // took in CreateNewWidget().
1711 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1712#endif
1713}
1714
1715WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1716 PendingContents::iterator iter = pending_contents_.find(route_id);
1717
1718 // Certain systems can block the creation of new windows. If we didn't succeed
1719 // in creating one, just return NULL.
1720 if (iter == pending_contents_.end()) {
1721 return NULL;
1722 }
1723
1724 WebContentsImpl* new_contents = iter->second;
1725 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101726 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501727
[email protected]d70bea92013-04-05 04:23:341728 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251729 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341730 return new_contents;
1731
[email protected]bafe6cd2012-05-23 23:09:501732 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1733 !new_contents->GetRenderViewHost()->GetView())
1734 return NULL;
1735
creis82dd6af2014-09-17 16:30:451736 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501737 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1738 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
creis82dd6af2014-09-17 16:30:451739 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init();
1740
[email protected]bafe6cd2012-05-23 23:09:501741 return new_contents;
1742}
1743
1744RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1745 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1746 if (iter == pending_widget_views_.end()) {
1747 DCHECK(false);
1748 return NULL;
1749 }
1750
1751 RenderWidgetHostView* widget_host_view = iter->second;
1752 pending_widget_views_.erase(route_id);
1753
1754 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1755 if (!widget_host->GetProcess()->HasConnection()) {
1756 // The view has gone away or the renderer crashed. Nothing to do.
1757 return NULL;
1758 }
1759
1760 return widget_host_view;
1761}
1762
[email protected]f13b4202012-06-12 23:53:231763void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091764 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211765 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371766 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231767 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371768 } else {
1769 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041770 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371771 scoped_ptr<MediaStreamUI>());
1772 }
[email protected]f13b4202012-06-12 23:53:231773}
1774
grunell657d4d82014-09-18 00:09:431775bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1776 MediaStreamType type) {
1777 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1778 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1779 return delegate_ &&
1780 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1781}
1782
[email protected]cc9200432013-07-23 23:02:401783SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1784 SiteInstance* instance) {
1785 return controller_.GetSessionStorageNamespace(instance);
1786}
1787
[email protected]6de7fc482014-06-06 10:46:441788SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1789 return controller_.GetSessionStorageNamespaceMap();
1790}
1791
[email protected]9b159a52013-10-03 17:24:551792FrameTree* WebContentsImpl::GetFrameTree() {
1793 return &frame_tree_;
1794}
1795
lukendc35e7f2014-11-10 19:06:141796void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
1797 virtual_keyboard_requested_ = requested;
1798}
1799
1800bool WebContentsImpl::IsVirtualKeyboardRequested() {
1801 return virtual_keyboard_requested_;
1802}
1803
[email protected]95640212014-07-26 18:14:301804AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1805 return accessibility_mode_;
1806}
1807
[email protected]31a71eaf2014-03-13 01:47:361808void WebContentsImpl::AccessibilityEventReceived(
1809 const std::vector<AXEventNotificationDetails>& details) {
1810 FOR_EACH_OBSERVER(
1811 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1812}
1813
dmazzonia656928e2014-09-15 20:28:541814RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
1815 int browser_plugin_instance_id) {
1816 BrowserPluginGuestManager* guest_manager =
1817 GetBrowserContext()->GetGuestManager();
1818 WebContents* guest = guest_manager->GetGuestByInstanceID(
1819 this, browser_plugin_instance_id);
1820 if (!guest)
1821 return NULL;
1822 return guest->GetMainFrame();
1823}
1824
blundellc57b93f2014-10-29 13:19:571825GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
1826 return geolocation_service_context_.get();
1827}
1828
[email protected]edc3af82013-12-12 21:24:071829void WebContentsImpl::OnShowValidationMessage(
1830 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291831 const base::string16& main_text,
1832 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071833 if (delegate_)
1834 delegate_->ShowValidationMessage(
1835 this, anchor_in_root_view, main_text, sub_text);
1836}
1837
1838void WebContentsImpl::OnHideValidationMessage() {
1839 if (delegate_)
1840 delegate_->HideValidationMessage(this);
1841}
1842
1843void WebContentsImpl::OnMoveValidationMessage(
1844 const gfx::Rect& anchor_in_root_view) {
1845 if (delegate_)
1846 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1847}
1848
[email protected]32deec62013-05-15 23:55:041849void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1850 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441851 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041852}
1853
[email protected]95640212014-07-26 18:14:301854BrowserAccessibilityManager*
1855 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1856 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1857 return rfh ? rfh->browser_accessibility_manager() : NULL;
1858}
1859
1860BrowserAccessibilityManager*
1861 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1862 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame());
1863 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1864}
1865
[email protected]b172aee2012-04-10 17:05:261866void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491867 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231868 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491869 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331870}
1871
[email protected]b172aee2012-04-10 17:05:261872void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341873 if (delegate_)
1874 delegate_->ResizeDueToAutoResize(this, new_size);
1875}
1876
[email protected]b172aee2012-04-10 17:05:261877WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201878 if (!delegate_)
1879 return NULL;
[email protected]00c37fc2011-08-02 00:22:501880
[email protected]e5d549d2011-12-28 01:29:201881 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201882 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341883}
1884
[email protected]6b618e62012-08-16 12:59:181885bool WebContentsImpl::Send(IPC::Message* message) {
1886 if (!GetRenderViewHost()) {
1887 delete message;
1888 return false;
1889 }
1890
1891 return GetRenderViewHost()->Send(message);
1892}
1893
[email protected]b172aee2012-04-10 17:05:261894bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501895 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261896 FrameTreeNode* node = frame_tree_.root();
1897
creise42f2a52014-09-18 18:14:571898 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
1899 // is currently only used in --site-per-process and tests.
[email protected]61ac9e242014-03-21 20:55:261900 NavigationEntryImpl* pending_entry =
1901 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
creise42f2a52014-09-18 18:14:571902 if (pending_entry->frame_tree_node_id() != -1) {
1903 FrameTreeNode* subframe =
1904 frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1905 DCHECK(subframe);
1906 if (subframe)
1907 node = subframe;
[email protected]61ac9e242014-03-21 20:55:261908 }
1909
1910 return node->navigator()->NavigateToPendingEntry(
1911 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541912}
[email protected]96d185d2009-04-24 03:28:541913
[email protected]a86c0e962013-12-17 17:10:391914void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1915 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441916 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391917 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441918}
1919
[email protected]20ca0382013-02-28 19:50:071920void WebContentsImpl::AttachInterstitialPage(
1921 InterstitialPageImpl* interstitial_page) {
1922 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211923 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291924
1925 // Cancel any visible dialogs so that they don't interfere with the
1926 // interstitial.
1927 if (dialog_manager_)
1928 dialog_manager_->CancelActiveAndPendingDialogs(this);
1929
[email protected]20ca0382013-02-28 19:50:071930 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1931 DidAttachInterstitialPage());
1932}
1933
1934void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571935 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211936 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071937 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1938 DidDetachInterstitialPage());
1939}
1940
[email protected]b172aee2012-04-10 17:05:261941void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331942 const SiteInstance* site_instance,
1943 int history_length,
1944 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411945 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1946 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211947 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191948 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141949 return;
[email protected]9e1ad4b2011-08-14 16:49:191950 }
[email protected]9f76c1e2012-03-05 15:15:581951 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191952 if (!rvh) {
1953 NOTREACHED();
1954 return;
1955 }
[email protected]9f76c1e2012-03-05 15:15:581956 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191957 NOTREACHED();
1958 return;
1959 }
[email protected]6b618e62012-08-16 12:59:181960 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1961 history_length,
1962 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141963}
1964
[email protected]4fed3702014-04-01 09:08:001965void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171966 RenderFrameHost* focused_frame = GetFocusedFrame();
1967 if (!focused_frame)
1968 return;
1969
[email protected]959be4c2014-04-08 15:01:331970 focused_frame->Send(new FrameMsg_Reload(
1971 focused_frame->GetRoutingID(), ignore_cache));
1972}
1973
1974void WebContentsImpl::Undo() {
1975 RenderFrameHost* focused_frame = GetFocusedFrame();
1976 if (!focused_frame)
1977 return;
1978
1979 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1980 RecordAction(base::UserMetricsAction("Undo"));
1981}
1982
1983void WebContentsImpl::Redo() {
1984 RenderFrameHost* focused_frame = GetFocusedFrame();
1985 if (!focused_frame)
1986 return;
1987 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1988 RecordAction(base::UserMetricsAction("Redo"));
1989}
1990
1991void WebContentsImpl::Cut() {
1992 RenderFrameHost* focused_frame = GetFocusedFrame();
1993 if (!focused_frame)
1994 return;
1995
1996 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1997 RecordAction(base::UserMetricsAction("Cut"));
1998}
1999
2000void WebContentsImpl::Copy() {
2001 RenderFrameHost* focused_frame = GetFocusedFrame();
2002 if (!focused_frame)
2003 return;
2004
2005 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2006 RecordAction(base::UserMetricsAction("Copy"));
2007}
2008
2009void WebContentsImpl::CopyToFindPboard() {
2010#if defined(OS_MACOSX)
2011 RenderFrameHost* focused_frame = GetFocusedFrame();
2012 if (!focused_frame)
2013 return;
2014
2015 // Windows/Linux don't have the concept of a find pasteboard.
2016 focused_frame->Send(
2017 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2018 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2019#endif
2020}
2021
2022void WebContentsImpl::Paste() {
2023 RenderFrameHost* focused_frame = GetFocusedFrame();
2024 if (!focused_frame)
2025 return;
2026
2027 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2028 RecordAction(base::UserMetricsAction("Paste"));
2029}
2030
2031void WebContentsImpl::PasteAndMatchStyle() {
2032 RenderFrameHost* focused_frame = GetFocusedFrame();
2033 if (!focused_frame)
2034 return;
2035
2036 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2037 focused_frame->GetRoutingID()));
2038 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2039}
2040
2041void WebContentsImpl::Delete() {
2042 RenderFrameHost* focused_frame = GetFocusedFrame();
2043 if (!focused_frame)
2044 return;
2045
2046 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2047 RecordAction(base::UserMetricsAction("DeleteSelection"));
2048}
2049
2050void WebContentsImpl::SelectAll() {
2051 RenderFrameHost* focused_frame = GetFocusedFrame();
2052 if (!focused_frame)
2053 return;
2054
2055 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2056 RecordAction(base::UserMetricsAction("SelectAll"));
2057}
2058
2059void WebContentsImpl::Unselect() {
2060 RenderFrameHost* focused_frame = GetFocusedFrame();
2061 if (!focused_frame)
2062 return;
2063
2064 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2065 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172066}
2067
2068void WebContentsImpl::Replace(const base::string16& word) {
2069 RenderFrameHost* focused_frame = GetFocusedFrame();
2070 if (!focused_frame)
2071 return;
2072
[email protected]959be4c2014-04-08 15:01:332073 focused_frame->Send(new InputMsg_Replace(
2074 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172075}
2076
2077void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2078 RenderFrameHost* focused_frame = GetFocusedFrame();
2079 if (!focused_frame)
2080 return;
2081
[email protected]959be4c2014-04-08 15:01:332082 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2083 focused_frame->GetRoutingID(), word));
2084}
2085
2086void WebContentsImpl::NotifyContextMenuClosed(
2087 const CustomContextMenuContext& context) {
2088 RenderFrameHost* focused_frame = GetFocusedFrame();
2089 if (!focused_frame)
2090 return;
2091
2092 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2093 focused_frame->GetRoutingID(), context));
2094}
2095
2096void WebContentsImpl::ExecuteCustomContextMenuCommand(
2097 int action, const CustomContextMenuContext& context) {
2098 RenderFrameHost* focused_frame = GetFocusedFrame();
2099 if (!focused_frame)
2100 return;
2101
2102 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2103 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002104}
2105
[email protected]fc2b46b2014-05-03 16:33:452106gfx::NativeView WebContentsImpl::GetNativeView() {
2107 return view_->GetNativeView();
2108}
2109
2110gfx::NativeView WebContentsImpl::GetContentNativeView() {
2111 return view_->GetContentNativeView();
2112}
2113
2114gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2115 return view_->GetTopLevelNativeWindow();
2116}
2117
2118gfx::Rect WebContentsImpl::GetViewBounds() {
2119 return view_->GetViewBounds();
2120}
2121
2122gfx::Rect WebContentsImpl::GetContainerBounds() {
2123 gfx::Rect rv;
2124 view_->GetContainerBounds(&rv);
2125 return rv;
2126}
2127
2128DropData* WebContentsImpl::GetDropData() {
2129 return view_->GetDropData();
2130}
2131
2132void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042133 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452134}
2135
2136void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042137 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452138}
2139
2140void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042141 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452142}
2143
2144void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042145 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452146}
2147
[email protected]b172aee2012-04-10 17:05:262148void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272149 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212150 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542151 return;
2152 }
[email protected]0b431992014-06-24 00:08:032153 RenderWidgetHostView* const fullscreen_view =
2154 GetFullscreenRenderWidgetHostView();
2155 if (fullscreen_view) {
2156 fullscreen_view->Focus();
2157 return;
2158 }
[email protected]9f76c1e2012-03-05 15:15:582159 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542160}
2161
[email protected]b172aee2012-04-10 17:05:262162bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212163 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542164}
2165
[email protected]b172aee2012-04-10 17:05:262166InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212167 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222168}
2169
[email protected]b172aee2012-04-10 17:05:262170bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162171 // WebKit creates Document object when MIME type is application/xhtml+xml,
2172 // so we also support this MIME type.
2173 return contents_mime_type_ == "text/html" ||
2174 contents_mime_type_ == "text/xml" ||
2175 contents_mime_type_ == "application/xhtml+xml" ||
2176 contents_mime_type_ == "text/plain" ||
2177 contents_mime_type_ == "text/css" ||
2178 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2179}
2180
[email protected]b172aee2012-04-10 17:05:262181void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592182 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162183 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552184 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012185 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142186 return;
[email protected]c7dd2f62011-07-18 15:57:592187 }
2188
2189 Stop();
2190
2191 // Create the save package and possibly prompt the user for the name to save
2192 // the page as. The user prompt is an asynchronous operation that runs on
2193 // another thread.
2194 save_package_ = new SavePackage(this);
2195 save_package_->GetSaveInfo();
2196}
2197
2198// Used in automated testing to bypass prompting the user for file names.
2199// Instead, the names and paths are hard coded rather than running them through
2200// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342201bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2202 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212203 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592204 // Stop the page from navigating.
2205 Stop();
2206
2207 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212208 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592209}
2210
[email protected]3c71576ce2013-07-23 02:00:012211void WebContentsImpl::SaveFrame(const GURL& url,
2212 const Referrer& referrer) {
2213 if (!GetURL().is_valid())
2214 return;
sammc92af61552014-11-19 23:27:402215 if (delegate_ && delegate_->SaveFrame(url, referrer))
2216 return;
2217
[email protected]3c71576ce2013-07-23 02:00:012218 bool is_main_frame = (url == GetURL());
2219
2220 DownloadManager* dlm =
2221 BrowserContext::GetDownloadManager(GetBrowserContext());
2222 if (!dlm)
2223 return;
2224 int64 post_id = -1;
2225 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272226 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012227 if (entry)
2228 post_id = entry->GetPostID();
2229 }
2230 scoped_ptr<DownloadUrlParameters> params(
2231 DownloadUrlParameters::FromWebContents(this, url));
2232 params->set_referrer(referrer);
2233 params->set_post_id(post_id);
2234 params->set_prefer_cache(true);
2235 if (post_id >= 0)
2236 params->set_method("POST");
2237 params->set_prompt(true);
2238 dlm->DownloadUrl(params.Pass());
2239}
2240
[email protected]b172aee2012-04-10 17:05:262241void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342242 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482243 const base::Callback<void(int64)>& callback) {
2244 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122245}
2246
[email protected]b172aee2012-04-10 17:05:262247const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272248 return contents_mime_type_;
2249}
2250
[email protected]b172aee2012-04-10 17:05:262251bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272252 return notify_disconnection_;
2253}
2254
[email protected]b172aee2012-04-10 17:05:262255void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312256 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182257 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162258}
2259
[email protected]b172aee2012-04-10 17:05:262260void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542261 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182262 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162263}
2264
[email protected]8ff00d72012-10-23 19:12:212265RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272266 return &renderer_preferences_;
2267}
2268
[email protected]e35ccd52012-05-23 16:22:472269void WebContentsImpl::Close() {
2270 Close(GetRenderViewHost());
2271}
2272
[email protected]cf200a562013-05-03 16:24:292273void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462274 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292275 if (browser_plugin_embedder_.get())
2276 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2277 screen_x, screen_y, operation);
2278 if (GetRenderViewHost())
2279 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2280 screen_x, screen_y, operation);
2281}
2282
[email protected]d60f3702013-12-26 16:30:242283void WebContentsImpl::DidGetResourceResponseStart(
2284 const ResourceRequestDetails& details) {
2285 controller_.ssl_manager()->DidStartResourceResponse(details);
2286
2287 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2288 DidGetResourceResponseStart(details));
2289
2290 // TODO(avi): Remove. http://crbug.com/170921
2291 NotificationService::current()->Notify(
2292 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2293 Source<WebContents>(this),
2294 Details<const ResourceRequestDetails>(&details));
2295}
2296
2297void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462298 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242299 const ResourceRedirectDetails& details) {
2300 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2301
2302 FOR_EACH_OBSERVER(
2303 WebContentsObserver,
2304 observers_,
creis114ca1b2014-11-13 23:51:462305 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242306
2307 // TODO(avi): Remove. http://crbug.com/170921
2308 NotificationService::current()->Notify(
2309 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2310 Source<WebContents>(this),
2311 Details<const ResourceRedirectDetails>(&details));
2312}
2313
[email protected]b172aee2012-04-10 17:05:262314void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522315 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582316 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512317 if (delegate_)
2318 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292319 if (browser_plugin_embedder_.get())
2320 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342321}
2322
[email protected]e35ccd52012-05-23 16:22:472323void WebContentsImpl::UserGestureDone() {
2324 OnUserGesture();
2325}
2326
[email protected]b172aee2012-04-10 17:05:262327void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272328 closed_by_user_gesture_ = value;
2329}
2330
[email protected]b172aee2012-04-10 17:05:262331bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272332 return closed_by_user_gesture_;
2333}
2334
[email protected]b172aee2012-04-10 17:05:262335void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502336 if (!delegate_)
2337 return;
2338
[email protected]6286a372013-10-09 04:03:272339 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2340 if (!entry)
[email protected]1788e772010-12-15 16:40:502341 return;
2342
[email protected]6286a372013-10-09 04:03:272343 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122344}
2345
[email protected]b172aee2012-04-10 17:05:262346void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042347 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272348 if (!delegate_)
2349 return;
2350
[email protected]691aa2f2013-05-28 22:52:042351 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272352}
2353
[email protected]b172aee2012-04-10 17:05:262354int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272355 return minimum_zoom_percent_;
2356}
2357
[email protected]b172aee2012-04-10 17:05:262358int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272359 return maximum_zoom_percent_;
2360}
2361
[email protected]b172aee2012-04-10 17:05:262362gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492363 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232364}
2365
[email protected]b172aee2012-04-10 17:05:262366bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052367 if (GetBrowserPluginGuest())
2368 return GetBrowserPluginGuest()->LockMouse(allowed);
2369
[email protected]0bfbf882011-12-22 18:19:272370 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582371 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272372}
2373
[email protected]b172aee2012-04-10 17:05:262374bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442375 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502376}
2377
[email protected]cb805452013-05-22 15:16:212378void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[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_DidChooseColorResponse(
2388 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202389}
2390
[email protected]cb805452013-05-22 15:16:212391void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482392 if (!color_chooser_info_.get())
2393 return;
2394 RenderFrameHost* rfh = RenderFrameHost::FromID(
2395 color_chooser_info_->render_process_id,
2396 color_chooser_info_->render_frame_id);
2397 if (!rfh)
2398 return;
2399
2400 rfh->Send(new FrameMsg_DidEndColorChooser(
2401 rfh->GetRoutingID(), color_chooser_info_->identifier));
2402 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202403}
2404
[email protected]41225fe2013-03-29 05:32:022405int WebContentsImpl::DownloadImage(const GURL& url,
2406 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302407 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022408 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582409 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022410 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392411 return id;
2412}
2413
[email protected]5dcaf8e2013-12-28 01:31:422414bool WebContentsImpl::IsSubframe() const {
2415 return is_subframe_;
2416}
2417
[email protected]36ec24f2014-01-09 00:32:082418void WebContentsImpl::Find(int request_id,
2419 const base::string16& search_text,
2420 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092421 // See if a top level browser plugin handles the find request first.
2422 if (browser_plugin_embedder_ &&
2423 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2424 return;
2425 }
[email protected]36ec24f2014-01-09 00:32:082426 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2427}
2428
2429void WebContentsImpl::StopFinding(StopFindAction action) {
2430 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2431}
2432
[email protected]4fe53add2014-04-08 19:53:362433void WebContentsImpl::InsertCSS(const std::string& css) {
2434 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2435 GetMainFrame()->GetRoutingID(), css));
2436}
2437
dalecurtisbc6572e12014-09-12 19:22:302438bool WebContentsImpl::WasRecentlyAudible() {
2439 return audio_stream_monitor_.WasRecentlyAudible();
2440}
2441
mlamouriefdca9d2014-09-16 16:55:402442void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2443 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2444}
2445
[email protected]b172aee2012-04-10 17:05:262446bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272447 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172448 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332449 return true;
2450 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272451}
2452
[email protected]b172aee2012-04-10 17:05:262453void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272454 if (delegate_)
2455 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212456}
2457
[email protected]52913802013-12-10 05:52:182458void WebContentsImpl::DidStartProvisionalLoad(
2459 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182460 const GURL& validated_url,
2461 bool is_error_page,
2462 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102463 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482464 FOR_EACH_OBSERVER(
2465 WebContentsObserver,
2466 observers_,
2467 DidStartProvisionalLoadForFrame(
2468 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
[email protected]400992b2012-06-14 00:03:542469}
2470
[email protected]0c3c54f2014-07-31 01:29:002471void WebContentsImpl::DidStartNavigationTransition(
morritaffb82612014-10-31 18:26:592472 RenderFrameHostImpl* render_frame_host) {
[email protected]0c3c54f2014-07-31 01:29:002473#if defined(OS_ANDROID)
2474 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562475 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
morritaffb82612014-10-31 18:26:592476 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002477#endif
2478}
2479
[email protected]3109fbb72014-01-06 23:57:152480void WebContentsImpl::DidFailProvisionalLoadWithError(
2481 RenderFrameHostImpl* render_frame_host,
2482 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2483 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312484 FOR_EACH_OBSERVER(WebContentsObserver,
2485 observers_,
2486 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312487 validated_url,
2488 params.error_code,
2489 params.error_description));
[email protected]3109fbb72014-01-06 23:57:152490}
2491
[email protected]b80624c2014-02-09 02:46:552492void WebContentsImpl::DidFailLoadWithError(
2493 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552494 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552495 int error_code,
2496 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142497 FOR_EACH_OBSERVER(
2498 WebContentsObserver,
2499 observers_,
2500 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552501}
2502
[email protected]52913802013-12-10 05:52:182503void WebContentsImpl::NotifyChangedNavigationState(
2504 InvalidateTypes changed_flags) {
2505 NotifyNavigationStateChanged(changed_flags);
2506}
2507
[email protected]3691e5cf2014-01-22 10:16:202508void WebContentsImpl::AboutToNavigateRenderFrame(
2509 RenderFrameHostImpl* render_frame_host) {
creis114ca1b2014-11-13 23:51:462510 // Notify observers that we will navigate in this RenderFrame.
[email protected]3691e5cf2014-01-22 10:16:202511 FOR_EACH_OBSERVER(
2512 WebContentsObserver,
2513 observers_,
creis114ca1b2014-11-13 23:51:462514 AboutToNavigateRenderFrame(render_frame_host));
[email protected]3691e5cf2014-01-22 10:16:202515}
2516
2517void WebContentsImpl::DidStartNavigationToPendingEntry(
2518 RenderFrameHostImpl* render_frame_host,
2519 const GURL& url,
2520 NavigationController::ReloadType reload_type) {
2521 // Notify observers about navigation.
2522 FOR_EACH_OBSERVER(
2523 WebContentsObserver,
2524 observers_,
2525 DidStartNavigationToPendingEntry(url, reload_type));
2526}
2527
[email protected]8cb834e2014-03-06 14:23:232528void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2529 const OpenURLParams& params) {
[email protected]65920f332014-03-04 21:14:182530 WebContents* new_contents = OpenURL(params);
2531
2532 if (new_contents) {
2533 // Notify observers.
2534 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2535 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:462536 render_frame_host,
[email protected]65920f332014-03-04 21:14:182537 params.url,
2538 params.referrer,
2539 params.disposition,
creis114ca1b2014-11-13 23:51:462540 params.transition));
[email protected]65920f332014-03-04 21:14:182541 }
2542}
2543
[email protected]aa62afd2014-04-22 19:22:462544bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2545 if (!delegate_)
2546 return false;
2547 return delegate_->ShouldPreserveAbortedURLs(this);
2548}
2549
[email protected]37567b432014-02-12 01:12:222550void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432551 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222552 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352553 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222554 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482555 FOR_EACH_OBSERVER(WebContentsObserver,
2556 observers_,
2557 DidCommitProvisionalLoadForFrame(
2558 render_frame_host, url, transition_type));
[email protected]37567b432014-02-12 01:12:222559}
2560
[email protected]0d0f4c492014-04-02 06:42:572561void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232562 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572563 // Ensure fullscreen mode is exited before committing the navigation to a
2564 // different page. The next page will not start out assuming it is in
2565 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232566 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192567 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572568 return;
2569 }
2570 if (IsFullscreenForCurrentTab())
2571 GetRenderViewHost()->ExitFullscreen();
2572 DCHECK(!IsFullscreenForCurrentTab());
2573}
2574
[email protected]37567b432014-02-12 01:12:222575void WebContentsImpl::DidNavigateMainFramePostCommit(
2576 const LoadCommittedDetails& details,
2577 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2578 if (details.is_navigation_to_different_page()) {
2579 // Clear the status bubble. This is a workaround for a bug where WebKit
2580 // doesn't let us know that the cursor left an element during a
2581 // transition (this is also why the mouse cursor remains as a hand after
2582 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2583 // clear the bubble when a user navigates to a named anchor in the same
2584 // page.
avi450ce00e2014-09-24 01:58:522585 UpdateTargetURL(GURL());
[email protected]37567b432014-02-12 01:12:222586 }
2587
2588 if (!details.is_in_page) {
2589 // Once the main frame is navigated, we're no longer considered to have
2590 // displayed insecure content.
2591 displayed_insecure_content_ = false;
2592 SSLManager::NotifySSLInternalStateChanged(
2593 GetController().GetBrowserContext());
2594 }
2595
2596 // Notify observers about navigation.
2597 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2598 DidNavigateMainFrame(details, params));
2599
[email protected]e85165c642014-06-10 14:34:312600 if (delegate_)
[email protected]37567b432014-02-12 01:12:222601 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312602 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222603}
2604
2605void WebContentsImpl::DidNavigateAnyFramePostCommit(
2606 RenderFrameHostImpl* render_frame_host,
2607 const LoadCommittedDetails& details,
2608 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102609 // Now that something has committed, we don't need to track whether the
2610 // initial page has been accessed.
2611 has_accessed_initial_document_ = false;
2612
[email protected]37567b432014-02-12 01:12:222613 // If we navigate off the page, close all JavaScript dialogs.
2614 if (dialog_manager_ && !details.is_in_page)
2615 dialog_manager_->CancelActiveAndPendingDialogs(this);
2616
2617 // Notify observers about navigation.
2618 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:092619 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:222620}
2621
2622void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2623 contents_mime_type_ = mime_type;
2624}
2625
[email protected]277857a2014-06-03 10:38:012626bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312627 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052628 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312629 return false;
2630
[email protected]37567b432014-02-12 01:12:222631 if (delegate_)
2632 return delegate_->CanOverscrollContent();
2633
2634 return false;
2635}
2636
[email protected]37b64c52014-07-11 21:14:052637void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252638 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052639 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252640}
2641
[email protected]b172aee2012-04-10 17:05:262642void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182643 const GURL& url,
[email protected]70435962011-08-02 20:13:282644 const std::string& security_info,
2645 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182646 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402647 ResourceType resource_type) {
[email protected]28620862011-03-22 23:07:192648 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182649 cache.Increment();
2650
2651 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082652 int cert_id = 0;
2653 net::CertStatus cert_status = 0;
2654 int security_bits = -1;
2655 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122656 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212657 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122658 &security_bits, &connection_status,
2659 &signed_certificate_timestamp_ids);
2660 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212661 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002662 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2663 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182664
[email protected]b0f724c2013-09-05 04:21:132665 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2666
2667 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2668 DidLoadResourceFromMemoryCache(details));
2669
[email protected]8bfc8272013-09-09 20:10:532670 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2671 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402672 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532673 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2674 GetRenderProcessHost()->GetID()) :
2675 GetBrowserContext()->GetRequestContextForRenderProcess(
2676 GetRenderProcessHost()->GetID()));
2677 BrowserThread::PostTask(
2678 BrowserThread::IO,
2679 FROM_HERE,
2680 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2681 }
[email protected]724159a2010-12-30 01:11:182682}
2683
[email protected]b172aee2012-04-10 17:05:262684void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392685 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182686 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192687 SSLManager::NotifySSLInternalStateChanged(
2688 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182689}
2690
[email protected]b172aee2012-04-10 17:05:262691void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022692 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582693 LOG(WARNING) << security_origin << " ran insecure content from "
2694 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392695 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412696 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392697 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182698 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412699 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192700 SSLManager::NotifySSLInternalStateChanged(
2701 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182702}
2703
[email protected]501052ff2014-02-21 22:19:072704void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572705 CHECK(render_frame_message_source_);
2706 CHECK(!render_view_message_source_);
2707 RenderFrameHostImpl* rfh =
2708 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142709 FOR_EACH_OBSERVER(
2710 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182711}
2712
[email protected]b172aee2012-04-10 17:05:262713void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262714 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372715 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122716 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2717 GetRenderProcessHost()->ReceivedBadMessage();
2718 return;
2719 }
[email protected]a1b99262013-12-27 21:56:222720
[email protected]8b3af1e2014-01-24 13:29:122721 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442722 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372723 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422724 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372725
[email protected]61ac9e242014-03-21 20:55:262726 RenderFrameHostImpl* rfh =
2727 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142728 FOR_EACH_OBSERVER(
2729 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312730}
2731
[email protected]960b0372014-05-19 18:01:002732void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2733 RenderFrameHostImpl* rfh =
2734 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2735 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2736
2737 // It is possible to get multiple calls to OnDidStartLoading that don't have
2738 // corresponding calls to OnDidStopLoading:
2739 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2740 // out for a cross-process navigation, and it turns into a placeholder for
2741 // one being rendered in a different process.
2742 // - Also, there might be more than one RenderFrameHost sharing the same
2743 // FrameTreeNode (and thus sharing its ID) each sending a start.
2744 // - But in the future, once clamy@ moves navigation network requests to the
2745 // browser process, there's a good chance that callbacks about starting and
2746 // stopping will all be handled by the browser. When that happens, there
2747 // should no longer be a start/stop call imbalance. TODO(avi): When this
2748 // future arrives, update this code to not allow this case.
2749 DCHECK_GE(loading_frames_in_progress_, 0);
2750 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2751 if (loading_frames_in_progress_ == 0)
2752 DidStartLoading(rfh, to_different_document);
2753 ++loading_frames_in_progress_;
2754 }
2755
2756 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2757 SendLoadProgressChanged();
2758}
2759
2760void WebContentsImpl::OnDidStopLoading() {
2761 RenderFrameHostImpl* rfh =
2762 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2763 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2764
2765 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2766 // Load stopped while we were still tracking load. Make sure we update
2767 // progress based on this frame's completion.
2768 loading_progresses_[render_frame_id] = 1.0;
2769 SendLoadProgressChanged();
2770 // Then we clean-up our states.
2771 if (loading_total_progress_ == 1.0)
2772 ResetLoadProgressState();
2773 }
2774
2775 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2776 // calls DidStopLoading() without a matching DidStartLoading().
2777 if (loading_frames_in_progress_ == 0)
2778 return;
2779 --loading_frames_in_progress_;
2780 if (loading_frames_in_progress_ == 0)
2781 DidStopLoading(rfh);
2782}
2783
2784void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2785 RenderFrameHostImpl* rfh =
2786 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2787 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2788
2789 loading_progresses_[render_frame_id] = load_progress;
2790
2791 // We notify progress change immediately for the first and last updates.
2792 // Also, since the message loop may be pretty busy when a page is loaded, it
2793 // might not execute a posted task in a timely manner so we make sure to
2794 // immediately send progress report if enough time has passed.
2795 base::TimeDelta min_delay =
2796 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2797 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2798 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2799 // If there is a pending task to send progress, it is now obsolete.
2800 loading_weak_factory_.InvalidateWeakPtrs();
2801 SendLoadProgressChanged();
2802 if (loading_total_progress_ == 1.0)
2803 ResetLoadProgressState();
2804 return;
2805 }
2806
2807 if (loading_weak_factory_.HasWeakPtrs())
2808 return;
2809
2810 base::MessageLoop::current()->PostDelayedTask(
2811 FROM_HERE,
2812 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2813 loading_weak_factory_.GetWeakPtr()),
2814 min_delay);
2815}
2816
[email protected]b172aee2012-04-10 17:05:262817void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222818 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2819 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262820}
2821
[email protected]b172aee2012-04-10 17:05:262822void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302823 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262824 minimum_zoom_percent_ = minimum_percent;
2825 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262826}
2827
[email protected]b172aee2012-04-10 17:05:262828void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342829 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432830 if (!delegate_)
2831 return;
2832
[email protected]b9535422012-02-09 01:47:592833 ChildProcessSecurityPolicyImpl* policy =
2834 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222835 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592836 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212837}
2838
[email protected]b172aee2012-04-10 17:05:262839void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2840 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262841 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362842 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432843 if (!delegate_)
2844 return;
2845
[email protected]b9535422012-02-09 01:47:592846 ChildProcessSecurityPolicyImpl* policy =
2847 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322848 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592849 return;
[email protected]8f810632013-06-06 22:33:322850
[email protected]c125e532014-05-10 20:39:062851 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202852}
2853
[email protected]f5273e52014-07-14 16:30:202854void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2855 const GURL& url,
2856 bool user_gesture) {
2857 if (!delegate_)
2858 return;
2859
2860 ChildProcessSecurityPolicyImpl* policy =
2861 ChildProcessSecurityPolicyImpl::GetInstance();
2862 if (policy->IsPseudoScheme(protocol))
2863 return;
2864
2865 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2866}
2867
[email protected]b172aee2012-04-10 17:05:262868void WebContentsImpl::OnFindReply(int request_id,
2869 int number_of_matches,
2870 const gfx::Rect& selection_rect,
2871 int active_match_ordinal,
2872 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432873 if (delegate_) {
2874 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2875 active_match_ordinal, final_update);
2876 }
[email protected]b888919c2011-09-02 00:32:162877}
2878
[email protected]59363fc92012-09-05 03:46:312879#if defined(OS_ANDROID)
2880void WebContentsImpl::OnFindMatchRectsReply(
2881 int version,
2882 const std::vector<gfx::RectF>& rects,
2883 const gfx::RectF& active_rect) {
2884 if (delegate_)
2885 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2886}
[email protected]583418cc2013-01-17 14:01:102887
[email protected]1ff427972013-02-07 21:14:072888void WebContentsImpl::OnOpenDateTimeDialog(
2889 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:172890 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:092891 GetRenderViewHost(),
2892 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132893 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092894 value.minimum,
2895 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172896 value.step,
2897 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102898}
[email protected]59363fc92012-09-05 03:46:312899#endif
2900
[email protected]cfa856d62014-02-22 07:58:402901void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2902 int automation_id) {
2903 DomOperationNotificationDetails details(json_string, automation_id);
2904 NotificationService::current()->Notify(
2905 NOTIFICATION_DOM_OPERATION_RESPONSE,
2906 Source<WebContents>(this),
2907 Details<DomOperationNotificationDetails>(&details));
2908}
2909
[email protected]b172aee2012-04-10 17:05:262910void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2911 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102912 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252913 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102914 AppCacheAccessed(manifest_url, blocked_by_policy));
2915}
2916
[email protected]8bc5ff02013-11-29 06:34:032917void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482918 int color_chooser_id,
2919 SkColor color,
2920 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462921 ColorChooser* new_color_chooser = delegate_ ?
2922 delegate_->OpenColorChooser(this, color, suggestions) :
2923 NULL;
[email protected]820957a2014-01-14 14:56:302924 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212925 return;
[email protected]8ed16472014-04-11 19:02:482926 if (color_chooser_info_.get())
2927 color_chooser_info_->chooser->End();
2928
2929 color_chooser_info_.reset(new ColorChooserInfo(
2930 render_frame_message_source_->GetProcess()->GetID(),
2931 render_frame_message_source_->GetRoutingID(),
2932 new_color_chooser,
2933 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202934}
2935
[email protected]b172aee2012-04-10 17:05:262936void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482937 if (color_chooser_info_ &&
2938 color_chooser_id == color_chooser_info_->identifier)
2939 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202940}
2941
[email protected]b172aee2012-04-10 17:05:262942void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322943 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482944 if (color_chooser_info_ &&
2945 color_chooser_id == color_chooser_info_->identifier)
2946 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202947}
2948
[email protected]d0759f492012-04-19 22:50:502949// This exists for render views that don't have a WebUI, but do have WebUI
2950// bindings enabled.
2951void WebContentsImpl::OnWebUISend(const GURL& source_url,
2952 const std::string& name,
2953 const base::ListValue& args) {
2954 if (delegate_)
2955 delegate_->WebUISend(this, source_url, name, args);
2956}
2957
thestigc4cac8f2014-09-04 21:17:502958#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:422959void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2960 const base::FilePath& path,
2961 bool is_hung) {
2962 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2963
2964 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2965 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2966}
2967
2968void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
2969 base::ProcessId plugin_pid) {
2970 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2971 PluginCrashed(plugin_path, plugin_pid));
2972}
2973
[email protected]d8415ad92012-08-23 14:40:502974void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442975 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502976 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342977 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162978 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442979 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162980 return;
[email protected]d8415ad92012-08-23 14:40:502981 }
2982
[email protected]8c8fc292012-11-23 18:57:162983 if (!delegate_->RequestPpapiBrokerPermission(
2984 this, url, plugin_path,
2985 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442986 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162987 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442988 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162989 }
[email protected]d8415ad92012-08-23 14:40:502990}
2991
[email protected]ea0309c2013-08-06 19:35:442992void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502993 bool result) {
[email protected]ea0309c2013-08-06 19:35:442994 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502995}
2996
[email protected]c4538072013-03-18 02:17:552997void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372998 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082999 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:553000 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:393001 // For more info, see comment above classes BrowserPluginEmbedder and
3002 // BrowserPluginGuest.
3003 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:143004 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:083005 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:373006}
tommyclie6633ca72014-10-31 00:40:423007#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373008
[email protected]41225fe2013-03-29 05:32:023009void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393010 int id,
[email protected]749fadd2013-05-15 08:37:483011 int http_status_code,
[email protected]795c28972012-12-06 06:13:393012 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303013 const std::vector<SkBitmap>& bitmaps,
3014 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133015 if (bitmaps.size() != original_bitmap_sizes.size())
3016 return;
3017
[email protected]41225fe2013-03-29 05:32:023018 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3019 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393020 // Currently WebContents notifies us of ANY downloads so that it is
3021 // possible to get here.
3022 return;
3023 }
3024 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303025 iter->second.Run(
3026 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393027 }
[email protected]41225fe2013-03-29 05:32:023028 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393029}
3030
3031void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393032 const std::vector<FaviconURL>& candidates) {
3033 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293034 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393035}
3036
dalecurtisbc6572e12014-09-12 19:22:303037void WebContentsImpl::CreateAudioPowerSaveBlocker() {
3038 // ChromeOS has its own way of handling power save blocks for media.
3039#if !defined(OS_CHROMEOS)
3040 DCHECK(!audio_power_save_blocker_);
3041 audio_power_save_blocker_ = PowerSaveBlocker::Create(
3042 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing Audio");
3043#endif
3044}
3045
3046void WebContentsImpl::CreateVideoPowerSaveBlocker() {
3047 // ChromeOS has its own way of handling power save blocks for media.
3048#if !defined(OS_CHROMEOS)
3049 DCHECK(!video_power_save_blocker_);
3050 DCHECK(!active_video_players_.empty());
3051 video_power_save_blocker_ = PowerSaveBlocker::Create(
3052 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing Video");
3053#if defined(OS_ANDROID)
3054 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3055 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3056#endif
3057#endif
3058}
3059
3060void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3061 // If there are no more audio players and we don't have audio stream
3062 // monitoring, release the audio power save blocker here instead of during
3063 // NotifyNavigationStateChanged().
3064 if (active_audio_players_.empty() &&
3065 !AudioStreamMonitor::monitoring_available()) {
3066 audio_power_save_blocker_.reset();
3067 }
3068
3069 // If there are no more video players, clear the video power save blocker.
3070 if (active_video_players_.empty())
3071 video_power_save_blocker_.reset();
3072}
3073
[email protected]1dd0bb752014-02-01 01:16:263074void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3075 bool has_video,
avayvod68017be2014-10-10 18:02:433076 bool has_audio,
3077 bool is_remote) {
3078 // Ignore the videos playing remotely and don't hold the wake lock for the
3079 // screen.
3080 if (is_remote) return;
3081
dalecurtisbc6572e12014-09-12 19:22:303082 if (has_audio) {
3083 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3084
3085 // If we don't have audio stream monitoring, allocate the audio power save
3086 // blocker here instead of during NotifyNavigationStateChanged().
3087 if (!audio_power_save_blocker_ &&
3088 !AudioStreamMonitor::monitoring_available()) {
3089 CreateAudioPowerSaveBlocker();
3090 }
[email protected]1dd0bb752014-02-01 01:16:263091 }
loislo0381a742014-09-11 10:58:113092
dalecurtisbc6572e12014-09-12 19:22:303093 if (has_video) {
3094 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3095
3096 // If we're not hidden and have just created a player, create a blocker.
3097 if (!video_power_save_blocker_ && !IsHidden())
3098 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113099 }
[email protected]1dd0bb752014-02-01 01:16:263100}
3101
3102void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303103 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3104 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3105 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063106}
3107
[email protected]50279492014-05-05 23:24:293108void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153109 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293110 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153111}
[email protected]d9030b82013-07-19 08:26:063112
[email protected]e67ebf32013-02-13 11:07:193113void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073114 if (delegate_)
3115 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193116}
3117
[email protected]17e286e2013-03-01 23:29:393118void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3119 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3120 BeforeFormRepostWarningShow());
3121}
3122
[email protected]ec6c05f2013-10-23 18:41:573123void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3124 Activate();
3125 if (delegate_)
3126 delegate_->ShowRepostFormWarningDialog(this);
3127}
3128
[email protected]b4c84012014-04-28 19:51:103129bool WebContentsImpl::HasAccessedInitialDocument() {
3130 return has_accessed_initial_document_;
3131}
3132
[email protected]96d185d2009-04-24 03:28:543133// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593134// loading, or done loading.
3135void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3136 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093137 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263138 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543139 if (is_loading == is_loading_)
3140 return;
3141
3142 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263143 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3144 base::string16());
[email protected]96d185d2009-04-24 03:28:543145 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563146 upload_size_ = 0;
3147 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543148 }
3149
[email protected]fa944cb82013-11-15 17:51:213150 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543151
3152 is_loading_ = is_loading;
3153 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033154 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543155
[email protected]6ebdc9b2010-09-27 16:55:573156 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093157 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213158 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543159
[email protected]eab61442013-11-14 18:35:483160 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593161 if (is_loading) {
naskob8744d22014-08-28 17:07:433162 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3163 this, "URL", url);
[email protected]91621872013-10-08 04:04:593164 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3165 DidStartLoading(render_view_host));
3166 } else {
naskob8744d22014-08-28 17:07:433167 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3168 this, "URL", url);
[email protected]91621872013-10-08 04:04:593169 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3170 DidStopLoading(render_view_host));
3171 }
[email protected]66798902013-10-01 18:40:163172
3173 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213174 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3175 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543176 if (details)
[email protected]8ff00d72012-10-23 19:12:213177 det = Details<LoadNotificationDetails>(details);
3178 NotificationService::current()->Notify(
3179 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543180}
3181
christiankaeed9862014-11-05 10:49:143182void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
3183 RenderFrameHost* focused_frame = GetFocusedFrame();
3184 if (!focused_frame)
3185 return;
3186
3187 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
3188 focused_frame->GetRoutingID(), extent));
3189}
3190
3191void WebContentsImpl::SelectRange(const gfx::Point& base,
3192 const gfx::Point& extent) {
[email protected]959be4c2014-04-08 15:01:333193 RenderFrameHost* focused_frame = GetFocusedFrame();
3194 if (!focused_frame)
3195 return;
3196
3197 focused_frame->Send(
christiankaeed9862014-11-05 10:49:143198 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
[email protected]959be4c2014-04-08 15:01:333199}
3200
[email protected]b172aee2012-04-10 17:05:263201void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463202 // If we are creating a RVH for a restored controller, then we need to make
3203 // sure the RenderView starts with a next_page_id_ larger than the number
3204 // of restored entries. This must be called before the RenderView starts
3205 // navigating (to avoid a race between the browser updating max_page_id and
3206 // the renderer updating next_page_id_). Because of this, we only call this
3207 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563208 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583209 if (max_restored_page_id >
3210 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3211 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3212 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323213}
3214
[email protected]b172aee2012-04-10 17:05:263215bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263216 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323217 // For file URLs without a title, use the pathname instead. In the case of a
3218 // synthesized title, we don't want the update to count toward the "one set
3219 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263220 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323221 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513222 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243223 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323224 explicit_set = false; // Don't count synthetic titles toward the set limit.
3225 } else {
[email protected]8af69c6c2014-03-03 19:05:313226 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323227 explicit_set = true;
3228 }
3229
[email protected]987fc3a2011-05-26 14:18:093230 // If a page is created via window.open and never navigated,
3231 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553232 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093233 if (entry) {
[email protected]36fc0392011-12-25 03:59:513234 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093235 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323236
[email protected]36fc0392011-12-25 03:59:513237 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093238 } else {
3239 if (page_title_when_no_navigation_entry_ == final_title)
3240 return false; // Nothing changed, don't bother.
3241
3242 page_title_when_no_navigation_entry_ = final_title;
3243 }
[email protected]420ae012009-04-24 05:16:323244
[email protected]420ae012009-04-24 05:16:323245 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233246 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323247
[email protected]66798902013-10-01 18:40:163248 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533249 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163250
3251 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213252 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463253 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213254 NotificationService::current()->Notify(
3255 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3256 Source<WebContents>(this),
3257 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043258
[email protected]420ae012009-04-24 05:16:323259 return true;
3260}
3261
[email protected]960b0372014-05-19 18:01:003262void WebContentsImpl::SendLoadProgressChanged() {
3263 loading_last_progress_update_ = base::TimeTicks::Now();
3264 double progress = 0.0;
3265 int frame_count = 0;
3266
3267 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3268 it != loading_progresses_.end();
3269 ++it) {
3270 progress += it->second;
3271 ++frame_count;
3272 }
3273 if (frame_count == 0)
3274 return;
3275 progress /= frame_count;
3276 DCHECK(progress <= 1.0);
3277
3278 if (progress <= loading_total_progress_)
3279 return;
3280 loading_total_progress_ = progress;
3281
3282 if (delegate_)
3283 delegate_->LoadProgressChanged(this, progress);
3284}
3285
3286void WebContentsImpl::ResetLoadProgressState() {
3287 loading_progresses_.clear();
3288 loading_total_progress_ = 0.0;
3289 loading_weak_factory_.InvalidateWeakPtrs();
3290 loading_last_progress_update_ = base::TimeTicks();
3291}
3292
[email protected]02d7b6e2014-06-24 21:01:503293void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3294 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323295 // After sending out a swap notification, we need to send a disconnect
3296 // notification so that clients that pick up a pointer to |this| can NULL the
3297 // pointer. See Bug 1230284.
3298 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113299 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283300 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113301
3302 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283303 std::pair<RenderViewHost*, RenderViewHost*> details =
3304 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213305 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283306 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213307 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283308 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393309
3310 // Ensure that the associated embedder gets cleared after a RenderViewHost
3311 // gets swapped, so we don't reuse the same embedder next time a
3312 // RenderViewHost is attached to this WebContents.
3313 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323314}
3315
[email protected]02d7b6e2014-06-24 21:01:503316void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3317 RenderFrameHost* new_host) {
3318 FOR_EACH_OBSERVER(WebContentsObserver,
3319 observers_,
3320 RenderFrameHostChanged(old_host, new_host));
3321}
3322
[email protected]da7a7182013-09-06 08:11:113323// TODO(avi): Remove this entire function because this notification is already
3324// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263325void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323326 if (!notify_disconnection_)
3327 return;
3328
3329 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213330 NotificationService::current()->Notify(
3331 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3332 Source<WebContents>(this),
3333 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323334}
3335
[email protected]cbb1ef592013-06-05 19:49:463336void WebContentsImpl::NotifyNavigationEntryCommitted(
3337 const LoadCommittedDetails& load_details) {
3338 FOR_EACH_OBSERVER(
3339 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3340}
3341
[email protected]f114fa42013-12-06 17:06:443342bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3343 const IPC::Message& message) {
3344 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313345}
3346
[email protected]c31a84802014-04-03 15:55:493347const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3348 return GetLastCommittedURL();
3349}
3350
[email protected]b849847b2013-12-10 21:57:583351void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3352 // Note this is only for subframes, the notification for the main frame
3353 // happens in RenderViewCreated.
3354 FOR_EACH_OBSERVER(WebContentsObserver,
3355 observers_,
3356 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303357 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583358}
3359
3360void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193361 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583362 FOR_EACH_OBSERVER(WebContentsObserver,
3363 observers_,
3364 RenderFrameDeleted(render_frame_host));
3365}
3366
[email protected]a09d53ce2014-01-31 00:46:423367void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303368 if (delegate_)
3369 delegate_->WorkerCrashed(this);
3370}
3371
[email protected]a09d53ce2014-01-31 00:46:423372void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3373 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103374 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423375 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103376 if (GetBrowserPluginGuest()) {
3377 WebContentsViewGuest* view_guest =
3378 static_cast<WebContentsViewGuest*>(GetView());
3379 context_menu_params = view_guest->ConvertContextMenuParams(params);
3380 }
3381 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423382 return;
3383
[email protected]077e704b2014-05-23 19:24:103384 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3385 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423386}
3387
[email protected]87de04b02014-04-08 22:14:493388void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013389 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493390 const base::string16& message,
3391 const base::string16& default_prompt,
3392 const GURL& frame_url,
3393 JavaScriptMessageType javascript_message_type,
3394 IPC::Message* reply_msg) {
3395 // Suppress JavaScript dialogs when requested. Also suppress messages when
3396 // showing an interstitial as it's shown over the previous page and we don't
3397 // want the hidden page's dialogs to interfere with the interstitial.
3398 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223399 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503400 ShowingInterstitialPage() || !delegate_ ||
3401 delegate_->ShouldSuppressDialogs(this) ||
3402 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493403
3404 if (!suppress_this_message) {
3405 std::string accept_lang = GetContentClient()->browser()->
3406 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503407 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493408 dialog_manager_->RunJavaScriptDialog(
3409 this,
3410 frame_url.GetOrigin(),
3411 accept_lang,
3412 javascript_message_type,
3413 message,
3414 default_prompt,
3415 base::Bind(&WebContentsImpl::OnDialogClosed,
3416 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013417 render_frame_host->GetProcess()->GetID(),
3418 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493419 reply_msg,
3420 false),
3421 &suppress_this_message);
3422 }
3423
3424 if (suppress_this_message) {
3425 // If we are suppressing messages, just reply as if the user immediately
3426 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013427 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3428 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283429 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493430 }
3431
3432 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3433 // http://crbug.com/288961 ). The only safe thing to do here is return.
3434}
3435
3436void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013437 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493438 const base::string16& message,
3439 bool is_reload,
3440 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013441 RenderFrameHostImpl* rfhi =
3442 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493443 if (delegate_)
3444 delegate_->WillRunBeforeUnloadConfirm();
3445
3446 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503447 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT || !delegate_ ||
3448 delegate_->ShouldSuppressDialogs(this) ||
3449 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493450 if (suppress_this_message) {
3451 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3452 return;
3453 }
3454
3455 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503456 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493457 dialog_manager_->RunBeforeUnloadDialog(
3458 this, message, is_reload,
3459 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013460 render_frame_host->GetProcess()->GetID(),
3461 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283462 false));
[email protected]87de04b02014-04-08 22:14:493463}
3464
[email protected]a86c0e962013-12-17 17:10:393465WebContents* WebContentsImpl::GetAsWebContents() {
3466 return this;
3467}
3468
[email protected]7912e822014-04-16 02:37:033469bool WebContentsImpl::IsNeverVisible() {
3470 if (!delegate_)
3471 return false;
3472 return delegate_->IsNeverVisible(this);
3473}
3474
[email protected]95640212014-07-26 18:14:303475#if defined(OS_WIN)
3476gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3477 return accessible_parent_;
3478}
3479#endif
3480
[email protected]5a3bdf52012-05-24 15:12:573481RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3482 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323483}
3484
[email protected]8ff00d72012-10-23 19:12:213485RendererPreferences WebContentsImpl::GetRendererPrefs(
3486 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463487 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513488}
3489
[email protected]b172aee2012-04-10 17:05:263490gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173491 if (delegate_)
3492 return delegate_->GetRootWindowResizerRect();
3493 return gfx::Rect();
3494}
3495
[email protected]7a846df2012-09-20 19:17:393496void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273497 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393498 browser_plugin_embedder_.reset();
3499}
3500
[email protected]b172aee2012-04-10 17:05:263501void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443502 // Don't send notifications if we are just creating a swapped-out RVH for
3503 // the opener chain. These won't be used for view-source or WebUI, so it's
3504 // ok to return early.
creiscce56cd2014-09-29 22:45:223505 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443506 return;
3507
[email protected]86f98a22013-03-20 14:35:003508 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313509 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083510
[email protected]8ff00d72012-10-23 19:12:213511 NotificationService::current()->Notify(
3512 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3513 Source<WebContents>(this),
3514 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323515
3516 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353517 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213518 if (GetRenderManager()->pending_web_ui())
3519 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323520
[email protected]6286a372013-10-09 04:03:273521 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333522 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323523 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183524 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583525 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323526 }
[email protected]0666aef2009-05-13 19:48:083527
[email protected]60780f412013-02-25 16:34:103528 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263529
3530 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253531 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583532
3533 // We tell the observers now instead of when the main RenderFrameHostImpl is
3534 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3535 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363536 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583537 FOR_EACH_OBSERVER(
3538 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303539 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
dgozman24bfc912014-09-29 11:04:183540
3541 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:323542}
3543
[email protected]b172aee2012-04-10 17:05:263544void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523545 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323546 // Don't notify the world, since this came from a renderer in the
3547 // background.
3548 return;
3549 }
3550
[email protected]da7a7182013-09-06 08:11:113551 notify_disconnection_ = true;
3552 // TODO(avi): Remove. http://crbug.com/170921
3553 NotificationService::current()->Notify(
3554 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3555 Source<WebContents>(this),
3556 NotificationService::NoDetails());
3557
[email protected]be1f56ab2011-12-22 06:55:313558 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233559 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303560
3561 // Restore the focus to the tab (otherwise the focus will be on the top
3562 // window).
[email protected]484ae5912010-09-29 19:16:143563 if (was_crashed && !FocusLocationBarByDefault() &&
3564 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063565 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143566 }
[email protected]32ded2212011-11-10 18:51:433567
[email protected]d8c660432011-12-22 20:51:253568 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323569}
3570
[email protected]ec6a7eb2013-04-22 17:34:223571void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3572 base::TerminationStatus status,
3573 int error_code) {
[email protected]151a63d2011-12-20 22:32:523574 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323575 // The pending page's RenderViewHost is gone.
3576 return;
3577 }
3578
[email protected]2fcdcc32014-03-05 02:14:073579 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3580 // renderer may not have made a clean exit.
3581 if (IsFullscreenForCurrentTab())
3582 ToggleFullscreenMode(false);
3583
[email protected]698191dc2014-02-25 01:06:133584 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3585 if (dialog_manager_)
3586 dialog_manager_->CancelActiveAndPendingDialogs(this);
3587
[email protected]f738bdcb2014-07-11 20:40:443588 if (delegate_)
3589 delegate_->HideValidationMessage(this);
3590
[email protected]e3b10d12014-03-28 16:06:093591 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323592 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233593 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453594
[email protected]960b0372014-05-19 18:01:003595 // Reset the loading progress. TODO(avi): What does it mean to have a
3596 // "renderer crash" when there is more than one renderer process serving a
3597 // webpage? Once this function is called at a more granular frame level, we
3598 // probably will need to more granularly reset the state here.
3599 ResetLoadProgressState();
3600 loading_frames_in_progress_ = 0;
3601
[email protected]d8c660432011-12-22 20:51:253602 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273603 observers_,
[email protected]58d5cfe2013-07-10 02:40:523604 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323605}
3606
[email protected]b172aee2012-04-10 17:05:263607void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253608 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063609}
3610
[email protected]b172aee2012-04-10 17:05:263611void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3612 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043613 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153614 // Ensure that this state update comes from either the active RVH or one of
3615 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413616 // TODO(nasko): This should go through RenderFrameHost.
3617 // TODO(creis): We can't update state for cross-process subframes until we
3618 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3619 if (rvh != GetRenderViewHost() &&
3620 !GetRenderManager()->IsRVHOnSwappedOutList(
3621 static_cast<RenderViewHostImpl*>(rvh)))
3622 return;
[email protected]420ae012009-04-24 05:16:323623
3624 // We must be prepared to handle state updates for any page, these occur
3625 // when the user is scrolling and entering form data, as well as when we're
3626 // leaving a page, in which case our state may have already been moved to
3627 // the next page. The navigation controller will look up the appropriate
3628 // NavigationEntry and update it when it is notified via the delegate.
3629
3630 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583631 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323632 if (entry_index < 0)
3633 return;
[email protected]10f417c52011-12-28 21:04:233634 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323635
[email protected]691aa2f2013-05-28 22:52:043636 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323637 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043638 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323639 controller_.NotifyEntryChanged(entry, entry_index);
3640}
3641
avi450ce00e2014-09-24 01:58:523642void WebContentsImpl::UpdateTargetURL(const GURL& url) {
[email protected]6934a702011-12-20 00:04:513643 if (delegate_)
avi450ce00e2014-09-24 01:58:523644 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323645}
3646
[email protected]b172aee2012-04-10 17:05:263647void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103648#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293649 // The UI may be in an event-tracking loop, such as between the
3650 // mouse-down and mouse-up in text selection or a button click.
3651 // Defer the close until after tracking is complete, so that we
3652 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293653 // TODO(shess): This could get more fine-grained. For instance,
3654 // closing a tab in another window while selecting text in the
3655 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103656 if (view_->IsEventTracking()) {
3657 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293658 return;
3659 }
[email protected]60780f412013-02-25 16:34:103660#endif
[email protected]07707302009-11-06 00:50:293661
[email protected]420ae012009-04-24 05:16:323662 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523663 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513664 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323665}
3666
[email protected]66bbadaf2014-03-28 16:25:543667void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573668 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3669 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573670}
3671
[email protected]6f2ac772014-07-24 22:22:083672void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253673 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173674#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563675 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173676#endif
3677}
3678
3679bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3680#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563681 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173682#else
3683 return false;
3684#endif
3685}
3686
[email protected]b172aee2012-04-10 17:05:263687void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513688 if (delegate_ && delegate_->IsPopupOrPanel(this))
3689 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323690}
3691
[email protected]e3b10d12014-03-28 16:06:093692void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3693 bool to_different_document) {
3694 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3695 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323696}
3697
[email protected]723971b2014-02-12 11:08:253698void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323699 scoped_ptr<LoadNotificationDetails> details;
3700
[email protected]9595fd82013-04-19 21:28:493701 // Use the last committed entry rather than the active one, in case a
3702 // pending entry has been created.
3703 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203704 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493705
[email protected]420ae012009-04-24 05:16:323706 // An entry may not exist for a stop when loading an initial blank page or
3707 // if an iframe injected by script into a blank page finishes loading.
3708 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203709 base::TimeDelta elapsed =
3710 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323711
3712 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513713 entry->GetVirtualURL(),
3714 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323715 elapsed,
3716 &controller_,
3717 controller_.GetCurrentEntryIndex()));
3718 }
3719
[email protected]e3b10d12014-03-28 16:06:093720 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3721 details.get());
[email protected]420ae012009-04-24 05:16:323722}
3723
[email protected]b172aee2012-04-10 17:05:263724void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163725 controller_.DiscardNonCommittedEntries();
3726
3727 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213728 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163729}
3730
[email protected]59167c22013-06-03 18:07:323731void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103732 has_accessed_initial_document_ = true;
3733
[email protected]d1371bf8e2014-04-19 03:26:243734 // We may have left a failed browser-initiated navigation in the address bar
3735 // to let the user edit it and try again. Clear it now that content might
3736 // show up underneath it.
3737 if (!IsLoading() && controller_.GetPendingEntry())
3738 controller_.DiscardPendingEntry();
3739
[email protected]59167c22013-06-03 18:07:323740 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503741 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323742}
3743
[email protected]3f19f1a2014-05-02 05:23:273744void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473745 // No action is necessary if the opener has already been cleared.
3746 if (!opener_)
3747 return;
3748
3749 // Clear our opener so that future cross-process navigations don't have an
3750 // opener assigned.
3751 RemoveDestructionObserver(opener_);
3752 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273753
3754 // Notify all swapped out RenderViewHosts for this tab. This is important
3755 // in case we go back to them, or if another window in those processes tries
3756 // to access window.opener.
creisbbbeb062014-08-25 18:20:313757 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273758}
3759
[email protected]39f2f9252014-05-03 00:54:013760void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293761 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093762 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293763 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093764
3765 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213766 NotificationService::current()->Notify(
3767 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3768 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293769 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083770}
3771
[email protected]ef3adfc2014-05-11 00:04:543772void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3773 int32 page_id,
3774 const base::string16& title,
3775 base::i18n::TextDirection title_direction) {
3776 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3777
3778 // If we have a title, that's a pretty good indication that we've started
3779 // getting useful data.
3780 SetNotWaitingForResponse();
3781
3782 // Try to find the navigation entry, which might not be the current one.
3783 // For example, it might be from a pending RVH for the pending entry.
3784 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3785 rvh->GetSiteInstance(), page_id);
3786
3787 // We can handle title updates when we don't have an entry in
3788 // UpdateTitleForEntry, but only if the update is from the current RVH.
3789 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3790 if (!entry && rvh != GetRenderViewHost())
3791 return;
3792
3793 // TODO(evan): make use of title_direction.
3794 // http://code.google.com/p/chromium/issues/detail?id=27094
3795 if (!UpdateTitleForEntry(entry, title))
3796 return;
3797
3798 // Broadcast notifications when the UI should be updated.
3799 if (entry == controller_.GetEntryAtOffset(0))
3800 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3801}
3802
3803void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3804 const std::string& encoding) {
3805 SetEncoding(encoding);
3806}
3807
[email protected]39f2f9252014-05-03 00:54:013808void WebContentsImpl::DocumentAvailableInMainFrame(
3809 RenderViewHost* render_view_host) {
3810 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3811 DocumentAvailableInMainFrame());
3812}
[email protected]e1c3a552012-05-04 20:51:323813void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3814 // Tell the active RenderViewHost to run unload handlers and close, as long
3815 // as the request came from a RenderViewHost in the same BrowsingInstance.
3816 // In most cases, we receive this from a swapped out RenderViewHost.
3817 // It is possible to receive it from one that has just been swapped in,
3818 // in which case we might as well deliver the message anyway.
3819 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3820 GetRenderViewHost()->ClosePage();
3821}
3822
[email protected]f546640b2012-05-15 00:03:493823void WebContentsImpl::RouteMessageEvent(
3824 RenderViewHost* rvh,
3825 const ViewMsg_PostMessage_Params& params) {
3826 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363827 // came from a RenderViewHost in the same BrowsingInstance or if this
3828 // WebContents is dedicated to a browser plugin guest.
3829 // Note: This check means that an embedder could theoretically receive a
3830 // postMessage from anyone (not just its own guests). However, this is
3831 // probably not a risk for apps since other pages won't have references
3832 // to App windows.
3833 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3834 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493835 return;
3836
3837 ViewMsg_PostMessage_Params new_params(params);
3838
[email protected]0bc7f3542013-10-21 15:05:533839 if (!params.message_port_ids.empty()) {
3840 MessagePortMessageFilter* message_port_message_filter =
3841 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3842 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093843 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3844 params.message_port_ids,
3845 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533846 }
3847
[email protected]f546640b2012-05-15 00:03:493848 // If there is a source_routing_id, translate it to the routing ID for
3849 // the equivalent swapped out RVH in the target process. If we need
3850 // to create a swapped out RVH for the source tab, we create its opener
3851 // chain as well, since those will also be accessible to the target page.
3852 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3853 // Try to look up the WebContents for the source page.
3854 WebContentsImpl* source_contents = NULL;
3855 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3856 rvh->GetProcess()->GetID(), params.source_routing_id);
3857 if (source_rvh) {
3858 source_contents = static_cast<WebContentsImpl*>(
3859 source_rvh->GetDelegate()->GetAsWebContents());
3860 }
3861
3862 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363863 if (GetBrowserPluginGuest()) {
3864 // We create a swapped out RenderView for the embedder in the guest's
3865 // render process but we intentionally do not expose the embedder's
3866 // opener chain to it.
3867 new_params.source_routing_id =
3868 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3869 } else {
3870 new_params.source_routing_id =
3871 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3872 }
[email protected]f546640b2012-05-15 00:03:493873 } else {
3874 // We couldn't find it, so don't pass a source frame.
3875 new_params.source_routing_id = MSG_ROUTING_NONE;
3876 }
3877 }
3878
3879 // In most cases, we receive this from a swapped out RenderViewHost.
3880 // It is possible to receive it from one that has just been swapped in,
3881 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183882 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493883}
3884
[email protected]a796f202012-05-30 14:14:253885bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263886 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253887 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263888 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253889 if (!delegate_)
3890 return false;
3891 return delegate_->AddMessageToConsole(this, level, message, line_no,
3892 source_id);
3893}
3894
[email protected]9e797d22014-08-08 21:31:303895WebPreferences WebContentsImpl::ComputeWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273896 // We want to base the page config off of the actual URL, rather than the
3897 // virtual URL.
3898 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3899 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003900 GURL url = controller_.GetActiveEntry()
3901 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153902
[email protected]9e797d22014-08-08 21:31:303903 return GetRenderManager()->current_host()->ComputeWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323904}
3905
[email protected]0eba810b2012-10-18 03:19:363906int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213907 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:293908 int render_view_routing_id = MSG_ROUTING_NONE;
3909 GetRenderManager()->CreateRenderFrame(
3910 instance, nullptr, MSG_ROUTING_NONE,
3911 CREATE_RF_SWAPPED_OUT | CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
3912 CREATE_RF_HIDDEN,
3913 &render_view_routing_id);
3914 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:363915}
3916
[email protected]b172aee2012-04-10 17:05:263917void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273918 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253919 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223920
[email protected]ea114722012-03-12 01:11:253921 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173922 if (rdh) // NULL in unittests.
3923 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253924}
3925
[email protected]b172aee2012-04-10 17:05:263926void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443927 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253928 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443929}
3930
creiscce56cd2014-09-29 22:45:223931void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:153932 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:223933 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153934 return;
3935
creiscce56cd2014-09-29 22:45:223936 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
3937 RenderFrameHostImpl* rfhi =
3938 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:583939
[email protected]e5fc1632011-08-08 07:51:533940 // Ignore renderer unresponsive event if debugger is attached to the tab
3941 // since the event may be a result of the renderer sitting on a breakpoint.
3942 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363943 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533944 return;
3945
creiscce56cd2014-09-29 22:45:223946 if (rfhi->is_waiting_for_beforeunload_ack() ||
3947 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:323948 // Hang occurred while firing the beforeunload/unload handler.
3949 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583950 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323951
[email protected]fa944cb82013-11-15 17:51:213952 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323953 return;
3954
3955 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563956 // nothing we can do to recover. If the hang is in the beforeunload handler,
3957 // pretend the beforeunload listeners have all fired and allow the delegate
3958 // to continue closing; the user will not have the option of cancelling the
3959 // close. Otherwise, pretend the unload listeners have all fired and close
3960 // the tab.
3961 bool close = true;
creiscce56cd2014-09-29 22:45:223962 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563963 delegate_->BeforeUnloadFired(this, true, &close);
3964 }
3965 if (close)
creiscce56cd2014-09-29 22:45:223966 Close(rvhi);
[email protected]420ae012009-04-24 05:16:323967 return;
3968 }
3969
[email protected]9f76c1e2012-03-05 15:15:583970 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473971 return;
3972
[email protected]6934a702011-12-20 00:04:513973 if (delegate_)
3974 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323975}
3976
[email protected]b172aee2012-04-10 17:05:263977void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513978 if (delegate_)
3979 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323980}
3981
[email protected]b172aee2012-04-10 17:05:263982void WebContentsImpl::LoadStateChanged(
3983 const GURL& url,
3984 const net::LoadStateWithParam& load_state,
3985 uint64 upload_position,
3986 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323987 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563988 upload_position_ = upload_position;
3989 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503990 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213991 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303992 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213993 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323994 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463995 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:223996 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
3997 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:463998 }
[email protected]420ae012009-04-24 05:16:323999}
4000
[email protected]b172aee2012-04-10 17:05:264001void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554002 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324003 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124004 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4005 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514006 if (delegate_)
4007 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094008 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324009}
4010
[email protected]58d5cfe2013-07-10 02:40:524011void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544012 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234013 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224014 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544015}
4016
[email protected]b172aee2012-04-10 17:05:264017void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104018 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214019 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264020 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4021 // here during container initialization and normal window size will be set
4022 // later. In case of tab duplication this resizing to 0x0 prevents setting
4023 // normal size later so just ignore it.
4024 if (!size.IsEmpty())
4025 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324026}
4027
[email protected]af905902013-10-01 21:38:514028void WebContentsImpl::CancelModalDialogsForRenderManager() {
4029 // We need to cancel modal dialogs when doing a process swap, since the load
4030 // deferrer would prevent us from swapping out.
4031 if (dialog_manager_)
4032 dialog_manager_->CancelActiveAndPendingDialogs(this);
4033}
4034
[email protected]02d7b6e2014-06-24 21:01:504035void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4036 RenderFrameHost* new_host,
4037 bool is_main_frame) {
4038 if (is_main_frame) {
4039 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4040 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084041
[email protected]02d7b6e2014-06-24 21:01:504042 // Make sure the visible RVH reflects the new delegate's preferences.
4043 if (delegate_)
4044 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394045
[email protected]02d7b6e2014-06-24 21:01:504046 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4047 }
4048
4049 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544050}
4051
[email protected]14392a52012-05-02 20:28:444052int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4053 SiteInstance* instance) {
4054 if (!opener_)
4055 return MSG_ROUTING_NONE;
4056
4057 // Recursively create RenderViews for anything else in the opener chain.
4058 return opener_->CreateOpenerRenderViews(instance);
4059}
4060
4061int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4062 int opener_route_id = MSG_ROUTING_NONE;
4063
4064 // If this tab has an opener, ensure it has a RenderView in the given
4065 // SiteInstance as well.
4066 if (opener_)
4067 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4068
[email protected]45a22ad2013-02-21 03:25:004069 // If any of the renderers (current, pending, or swapped out) for this
4070 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214071 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4072 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374073
[email protected]fa944cb82013-11-15 17:51:214074 if (GetRenderManager()->pending_render_view_host() &&
4075 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4076 instance)
4077 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004078
[email protected]fa944cb82013-11-15 17:51:214079 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374080 instance);
4081 if (rvh)
4082 return rvh->GetRoutingID();
4083
[email protected]14392a52012-05-02 20:28:444084 // Create a swapped out RenderView in the given SiteInstance if none exists,
4085 // setting its opener to the given route_id. Return the new view's route_id.
carlosk37f793792014-11-27 15:08:294086 int render_view_routing_id = MSG_ROUTING_NONE;
4087 GetRenderManager()->CreateRenderFrame(instance, nullptr, opener_route_id,
4088 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4089 CREATE_RF_SWAPPED_OUT |
4090 CREATE_RF_HIDDEN,
4091 &render_view_routing_id);
4092 return render_view_routing_id;
[email protected]14392a52012-05-02 20:28:444093}
4094
[email protected]b172aee2012-04-10 17:05:264095NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194096 return GetController();
[email protected]3a3d47472010-07-15 21:03:544097}
4098
carlosk37f793792014-11-27 15:08:294099scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderManager(
4100 const GURL& url) {
4101 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(url)));
[email protected]420ae012009-04-24 05:16:324102}
4103
[email protected]10f417c52011-12-28 21:04:234104NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264105 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324106 return controller_.GetLastCommittedEntry();
4107}
4108
[email protected]b172aee2012-04-10 17:05:264109bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164110 RenderViewHost* render_view_host,
4111 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044112 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124113 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434114 TRACE_EVENT0("browser,navigation",
4115 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444116 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484117 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164118 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4119 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4120 // case this because RWH is still a base class of RenderViewHost, and child
4121 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124122 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164123 RenderWidgetHostViewChildFrame* rwh_view_child =
4124 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164125 rwh_view = rwh_view_child;
4126 } else {
lazyboy549b3b42014-10-20 17:16:044127 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164128 }
[email protected]1a98a932009-11-17 00:12:524129
[email protected]420ae012009-04-24 05:16:324130 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444131 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214132 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324133
[email protected]74ce1ad2011-12-16 21:51:464134 // Make sure we use the correct starting page_id in the new RenderView.
4135 UpdateMaxPageIDIfNecessary(render_view_host);
4136 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584137 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464138
[email protected]9f76c1e2012-03-05 15:15:584139 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264140 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494141 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044142 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494143 max_page_id,
4144 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524145 return false;
[email protected]14392a52012-05-02 20:28:444146 }
[email protected]a4127722011-04-27 23:13:524147
[email protected]a220b5932013-09-21 03:47:444148#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504149 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4150 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444151 if (rwh_view) {
4152 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4153 render_widget_host->WasResized();
4154 }
[email protected]f8233cc2011-05-31 20:24:504155#endif
4156
[email protected]420ae012009-04-24 05:16:324157 return true;
4158}
4159
[email protected]82307f6b2014-08-07 03:30:124160bool WebContentsImpl::CreateRenderFrameForRenderManager(
4161 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494162 int parent_routing_id,
4163 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434164 TRACE_EVENT0("browser,navigation",
4165 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124166
4167 RenderFrameHostImpl* rfh =
4168 static_cast<RenderFrameHostImpl*>(render_frame_host);
japhete6adf142014-10-31 00:01:494169 if (!rfh->CreateRenderFrame(parent_routing_id, proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124170 return false;
4171
4172 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4173 // RenderFrameHost will have to be associated with the appropriate
4174 // RenderWidgetHostView or a new one should be created here.
4175
4176 return true;
4177}
4178
[email protected]7d244f12013-08-22 21:41:514179#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454180
[email protected]155c7f22013-12-09 17:07:184181base::android::ScopedJavaLocalRef<jobject>
4182WebContentsImpl::GetJavaWebContents() {
4183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564184 return GetWebContentsAndroid()->GetJavaObject();
4185}
[email protected]155c7f22013-12-09 17:07:184186
[email protected]0e813a52014-08-13 10:34:564187WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184188 WebContentsAndroid* web_contents_android =
4189 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4190 if (!web_contents_android) {
4191 web_contents_android = new WebContentsAndroid(this);
4192 SetUserData(kWebContentsAndroidKey, web_contents_android);
4193 }
[email protected]0e813a52014-08-13 10:34:564194 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184195}
4196
[email protected]7d244f12013-08-22 21:41:514197bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4198 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164199 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044200 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594201 true);
[email protected]7d244f12013-08-22 21:41:514202}
[email protected]fc2b46b2014-05-03 16:33:454203
4204#elif defined(OS_MACOSX)
4205
[email protected]75f4df72014-07-16 22:39:424206void WebContentsImpl::SetAllowOtherViews(bool allow) {
4207 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454208}
4209
[email protected]75f4df72014-07-16 22:39:424210bool WebContentsImpl::GetAllowOtherViews() {
4211 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454212}
4213
[email protected]7d244f12013-08-22 21:41:514214#endif
4215
[email protected]6fba26d2014-04-29 09:38:284216void WebContentsImpl::OnDialogClosed(int render_process_id,
4217 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264218 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494219 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264220 bool success,
[email protected]fcf75d42013-12-03 20:11:264221 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284222 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4223 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494224 last_dialog_suppressed_ = dialog_was_suppressed;
4225
[email protected]beb440c2009-11-06 04:08:544226 if (is_showing_before_unload_dialog_ && !success) {
4227 // If a beforeunload dialog is canceled, we need to stop the throbber from
4228 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284229 if (rfh)
4230 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354231 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104232
[email protected]6d65a462013-06-21 21:29:124233 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4234 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544235 }
[email protected]87de04b02014-04-08 22:14:494236
[email protected]beb440c2009-11-06 04:08:544237 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284238 if (rfh) {
4239 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4240 dialog_was_suppressed);
4241 } else {
4242 // Don't leak the sync IPC reply if the RFH or process is gone.
4243 delete reply_msg;
4244 }
[email protected]beb440c2009-11-06 04:08:544245}
4246
[email protected]b172aee2012-04-10 17:05:264247void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544248 if (encoding == last_reported_encoding_)
4249 return;
4250 last_reported_encoding_ = encoding;
4251
4252 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124253 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104254}
[email protected]f45d2a72010-03-08 23:28:354255
[email protected]1ac10dca2013-08-20 20:47:044256bool WebContentsImpl::IsHidden() {
4257 return capturer_count_ == 0 && !should_normally_be_visible_;
4258}
4259
[email protected]b0936d22013-11-28 06:47:364260RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214261 return frame_tree_.root()->render_manager();
4262}
4263
[email protected]b172aee2012-04-10 17:05:264264RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584265 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4266}
[email protected]7900bfdb2012-05-24 19:31:244267
[email protected]f8497342013-02-05 22:15:024268BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394269 return browser_plugin_guest_.get();
4270}
4271
[email protected]738f57a2013-06-29 21:06:544272void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4273 CHECK(!browser_plugin_guest_);
4274 browser_plugin_guest_.reset(guest);
4275}
4276
[email protected]f8497342013-02-05 22:15:024277BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394278 return browser_plugin_embedder_.get();
4279}
[email protected]8ff00d72012-10-23 19:12:214280
[email protected]d9030b82013-07-19 08:26:064281void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194282 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304283 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4284 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4285 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064286}
4287
4288void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304289 active_audio_players_.clear();
4290 active_video_players_.clear();
4291 audio_power_save_blocker_.reset();
4292 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064293}
4294
[email protected]fc2b46b2014-05-03 16:33:454295gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214296 gfx::Size size;
4297 if (delegate_)
4298 size = delegate_->GetSizeForNewRenderView(this);
4299 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454300 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214301 return size;
4302}
4303
[email protected]ae7eeda2014-07-04 01:53:264304void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4305 FOR_EACH_OBSERVER(
4306 WebContentsObserver, observers_, FrameDetached(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554307}
4308
[email protected]222f5822014-02-05 23:40:494309void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4310 if (!delegate_)
4311 return;
4312 const gfx::Size new_size = GetPreferredSize();
4313 if (new_size != old_size)
4314 delegate_->UpdatePreferredSize(this, new_size);
4315}
4316
dalecurtisbc6572e12014-09-12 19:22:304317void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4318 ActiveMediaPlayerMap* player_map) {
4319 const uintptr_t key =
4320 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4321 DCHECK(std::find((*player_map)[key].begin(),
4322 (*player_map)[key].end(),
4323 player_cookie) == (*player_map)[key].end());
4324 (*player_map)[key].push_back(player_cookie);
4325}
4326
4327void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4328 ActiveMediaPlayerMap* player_map) {
4329 const uintptr_t key =
4330 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4331 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4332 if (it == player_map->end())
4333 return;
4334
4335 // Remove the player.
4336 PlayerList::iterator player_it =
4337 std::find(it->second.begin(), it->second.end(), player_cookie);
4338 if (player_it != it->second.end())
4339 it->second.erase(player_it);
4340
4341 // If there are no players left, remove the map entry.
4342 if (it->second.empty())
4343 player_map->erase(it);
4344}
4345
4346void WebContentsImpl::RemoveAllMediaPlayerEntries(
4347 RenderFrameHost* render_frame_host,
4348 ActiveMediaPlayerMap* player_map) {
4349 ActiveMediaPlayerMap::iterator it =
4350 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4351 if (it == player_map->end())
4352 return;
4353 player_map->erase(it);
4354}
4355
[email protected]23f41fd2014-06-21 05:29:174356void WebContentsImpl::ResumeResponseDeferredAtStart() {
4357 FrameTreeNode* node = frame_tree_.root();
4358 node->render_manager()->ResumeResponseDeferredAtStart();
4359}
4360
[email protected]34ff1cfc2014-08-20 06:16:054361void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4362 force_disable_overscroll_content_ = force_disable;
4363 if (view_)
4364 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4365}
4366
[email protected]8ff00d72012-10-23 19:12:214367} // namespace content