blob: b12ae2164ac6d296468350bbb90c41f8c88722d2 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]cbb1ef592013-06-05 19:49:4610#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5611#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2013#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5114#include "base/strings/string16.h"
15#include "base/strings/string_number_conversions.h"
16#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0017#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3718#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4219#include "base/trace_event/trace_event.h"
[email protected]95640212014-07-26 18:14:3020#include "content/browser/accessibility/accessibility_mode_helper.h"
21#include "content/browser/accessibility/browser_accessibility_state_impl.h"
[email protected]7a846df2012-09-20 19:17:3922#include "content/browser/browser_plugin/browser_plugin_embedder.h"
23#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5924#include "content/browser/child_process_security_policy_impl.h"
dgozman24bfc912014-09-29 11:04:1825#include "content/browser/devtools/devtools_manager.h"
[email protected]5f2aa722013-08-07 16:59:4126#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0427#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4628#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1229#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1630#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1631#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4032#include "content/browser/frame_host/interstitial_page_impl.h"
33#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0134#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1835#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1636#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5737#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0538#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4439#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4040#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3041#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5242#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]0bc7f3542013-10-21 15:05:5343#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0944#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]d9030b82013-07-19 08:26:0645#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3046#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5047#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3248#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5049#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4850#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0951#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3352#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1153#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5854#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0355#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5656#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1457#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4258#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4459#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0260#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1761#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5162#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0263#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3664#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1165#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2866#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4467#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3668#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1769#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1470#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4671#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1572#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0073#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2774#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0075#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3776#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1477#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3078#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3279#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0980#include "content/public/browser/screen_orientation_dispatcher_host.h"
[email protected]4c3a23582012-08-18 08:54:3481#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3882#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4283#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2584#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2185#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4886#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5487#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4988#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2089#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0390#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5791#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:0592#include "content/public/common/web_preferences.h"
[email protected]a53209b2012-01-20 16:48:1693#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2994#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5395#include "net/http/http_cache.h"
96#include "net/http/http_transaction_factory.h"
97#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3498#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5699#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01100#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41101#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52102#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31103
qinmin58567c82015-01-07 21:00:20104#if defined(ENABLE_BROWSER_CDMS)
105#include "content/browser/media/media_web_contents_observer.h"
106#endif
107
[email protected]583418cc2013-01-17 14:01:10108#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40109#include "content/browser/android/content_video_view.h"
[email protected]583418cc2013-01-17 14:01:10110#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:45111#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18112#include "content/browser/web_contents/web_contents_android.h"
[email protected]583418cc2013-01-17 14:01:10113#endif
114
[email protected]f66df822012-05-18 16:52:17115#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50116#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57117#endif
[email protected]3e45ba92009-02-20 21:09:00118
[email protected]8ff00d72012-10-23 19:12:21119namespace content {
[email protected]420ae012009-04-24 05:16:32120namespace {
121
[email protected]960b0372014-05-19 18:01:00122const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
123
124// This matches what Blink's ProgressTracker has traditionally used for a
125// minimum progress value.
126const double kMinimumLoadingProgress = 0.1;
127
[email protected]82114f52012-03-20 22:53:41128const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05129
[email protected]155c7f22013-12-09 17:07:18130#if defined(OS_ANDROID)
131const char kWebContentsAndroidKey[] = "web_contents_android";
132#endif // OS_ANDROID
133
[email protected]e4abd3b42013-11-12 18:28:47134base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46135g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
136
thestigc4cac8f2014-09-04 21:17:50137static int StartDownload(RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39138 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29139 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30140 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02141 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58142 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02143 ++g_next_image_download_id,
144 url,
145 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30146 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02147 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39148}
149
[email protected]8bfc8272013-09-09 20:10:53150void NotifyCacheOnIO(
151 scoped_refptr<net::URLRequestContextGetter> request_context,
152 const GURL& url,
153 const std::string& http_method) {
154 request_context->GetURLRequestContext()->http_transaction_factory()->
155 GetCache()->OnExternalCacheHit(url, http_method);
156}
157
[email protected]9b159a52013-10-03 17:24:55158// Helper function for retrieving all the sites in a frame tree.
159bool CollectSites(BrowserContext* context,
160 std::set<GURL>* sites,
161 FrameTreeNode* node) {
162 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
163 return true;
164}
165
[email protected]a86c0e962013-12-17 17:10:39166bool ForEachFrameInternal(
167 const base::Callback<void(RenderFrameHost*)>& on_frame,
168 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41169 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39170 return true;
171}
172
[email protected]95640212014-07-26 18:14:30173bool ForEachPendingFrameInternal(
174 const base::Callback<void(RenderFrameHost*)>& on_frame,
175 FrameTreeNode* node) {
176 RenderFrameHost* pending_frame_host =
177 node->render_manager()->pending_frame_host();
178 if (pending_frame_host)
179 on_frame.Run(pending_frame_host);
180 return true;
181}
182
[email protected]a86c0e962013-12-17 17:10:39183void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
184 IPC::Message* message_copy = new IPC::Message(*message);
185 message_copy->set_routing_id(rfh->GetRoutingID());
186 rfh->Send(message_copy);
187}
188
[email protected]948481d2014-06-11 18:32:22189void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
190 RenderFrameHost* rfh) {
191 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
192 ->frame_tree_node()
193 ->render_manager()
194 ->GetRenderWidgetHostView();
195 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59196}
197
[email protected]95640212014-07-26 18:14:30198void SetAccessibilityModeOnFrame(AccessibilityMode mode,
199 RenderFrameHost* frame_host) {
200 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
201}
202
clamydf1975e2015-02-05 19:12:24203// Enable sudden termination for the current RenderFrameHost of
204// |frame_tree_node| if the ID of its SiteInstance is |site_instance_id|. Used
205// with FrameTree::ForEach.
206bool EnableSuddenTermination(int32 site_instance_id,
207 FrameTreeNode* frame_tree_node) {
208 if (frame_tree_node->current_frame_host()->GetSiteInstance()->GetId()
209 == site_instance_id) {
210 frame_tree_node->current_frame_host()
211 ->set_override_sudden_termination_status(true);
212 }
213 return true;
214}
215
216// Returns false and sets |sudden_termination_allowed| to false if sudden
217// termination is not allowed for the current RenderFrameHost of
218// |frame_tree_node|. Used with FrameTree::ForEach.
219bool SuddenTerminationAllowed(bool* sudden_termination_allowed,
220 FrameTreeNode* frame_tree_node) {
221 if (frame_tree_node->current_frame_host()->SuddenTerminationAllowed())
222 return true;
223 *sudden_termination_allowed = false;
224 return false;
225}
226
[email protected]420ae012009-04-24 05:16:32227} // namespace
228
[email protected]54944cde2012-12-09 09:24:59229WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15230 return WebContentsImpl::CreateWithOpener(
231 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19232}
233
234WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59235 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30236 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59237 WebContentsImpl* new_contents = new WebContentsImpl(
238 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30239
240 for (SessionStorageNamespaceMap::const_iterator it =
241 session_storage_namespace_map.begin();
242 it != session_storage_namespace_map.end();
243 ++it) {
244 new_contents->GetController()
245 .SetSessionStorageNamespace(it->first, it->second.get());
246 }
247
[email protected]54944cde2012-12-09 09:24:59248 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19249 return new_contents;
[email protected]a81343d232011-12-27 07:39:20250}
[email protected]746d3052012-05-22 15:15:47251
nickf9acfbe2014-12-23 19:12:37252void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
253 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46254 g_created_callbacks.Get().push_back(callback);
255}
256
nickf9acfbe2014-12-23 19:12:37257void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
258 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46259 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
260 if (g_created_callbacks.Get().at(i).Equals(callback)) {
261 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
262 return;
263 }
264 }
265}
266
[email protected]299d7f12012-05-23 05:31:15267WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47268 return rvh->GetDelegate()->GetAsWebContents();
269}
270
[email protected]a86c0e962013-12-17 17:10:39271WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
272 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
273 if (!rfh_impl)
274 return NULL;
275 return rfh_impl->delegate()->GetAsWebContents();
276}
277
[email protected]7fff43e2013-05-21 20:21:10278// WebContentsImpl::DestructionObserver ----------------------------------------
279
280class WebContentsImpl::DestructionObserver : public WebContentsObserver {
281 public:
282 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
283 : WebContentsObserver(watched_contents),
284 owner_(owner) {
285 }
286
287 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58288 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58289 owner_->OnWebContentsDestroyed(
290 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10291 }
292
293 private:
294 WebContentsImpl* owner_;
295
296 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
297};
298
[email protected]8ed16472014-04-11 19:02:48299WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
300 int render_frame_id,
301 ColorChooser* chooser,
302 int identifier)
303 : render_process_id(render_process_id),
304 render_frame_id(render_frame_id),
305 chooser(chooser),
306 identifier(identifier) {
307}
308
309WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
310}
311
[email protected]b172aee2012-04-10 17:05:26312// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32313
blundellc57b93f2014-10-29 13:19:57314WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
315 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42316 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22317 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57318 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44319 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49320 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08321#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41322 accessible_parent_(NULL),
323#endif
[email protected]6ea6bdf2013-12-06 13:35:01324 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57325 this,
326 this,
327 this,
328 this),
[email protected]d5f942ba2008-09-26 19:30:34329 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03330 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23331 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
332 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34333 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26334 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00335 loading_total_progress_(0.0),
[email protected]960b0372014-05-19 18:01:00336 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56337 upload_size_(0),
338 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47339 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10340 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55341 capturer_count_(0),
342 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57343 is_being_destroyed_(false),
344 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15345 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01346 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02347 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38348 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21349 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
350 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]f114fa42013-12-06 17:06:44351 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55352 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42353 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03354 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49355 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05356 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30357 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57358 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30359 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30360 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddy371ad9142014-09-17 08:01:46361 audio_stream_monitor_(this),
mohan.reddyaae039a2014-11-21 17:39:50362 virtual_keyboard_requested_(false),
mohan.reddy371ad9142014-09-17 08:01:46363 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55364 frame_tree_.SetFrameRemoveListener(
365 base::Bind(&WebContentsImpl::OnFrameRemoved,
366 base::Unretained(this)));
qinmin58567c82015-01-07 21:00:20367#if defined(ENABLE_BROWSER_CDMS)
368 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
369#endif
[email protected]332af7732009-03-11 13:21:35370}
initial.commit09911bf2008-07-26 23:55:29371
[email protected]b172aee2012-04-10 17:05:26372WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32373 is_being_destroyed_ = true;
374
[email protected]21b41c7e892014-02-28 01:52:24375 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
376 // shutdown and be deleted as well.
377 frame_tree_.ForEach(
378 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
379
[email protected]d9030b82013-07-19 08:26:06380 ClearAllPowerSaveBlockers();
381
[email protected]b24b68a2012-09-24 21:57:26382 for (std::set<RenderWidgetHostImpl*>::iterator iter =
383 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
384 (*iter)->DetachDelegate();
385 }
386 created_widgets_.clear();
387
[email protected]3ab9cb82011-06-03 18:02:07388 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15389 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11390 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07391
[email protected]8ed16472014-04-11 19:02:48392 if (color_chooser_info_.get())
393 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20394
[email protected]420ae012009-04-24 05:16:32395 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32396
[email protected]ca13a442012-04-17 14:00:12397 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21398 NotificationService::current()->Notify(
399 NOTIFICATION_WEB_CONTENTS_DESTROYED,
400 Source<WebContents>(this),
401 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32402
[email protected]df0c843f2014-05-23 20:37:23403 // Destroy all frame tree nodes except for the root; this notifies observers.
404 frame_tree_.ResetForMainFrameSwap();
405 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59406
[email protected]df0c843f2014-05-23 20:37:23407 // Manually call the observer methods for the root frame tree node.
408 RenderFrameHostManager* root = GetRenderManager();
409 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27410 FOR_EACH_OBSERVER(WebContentsObserver,
411 observers_,
[email protected]df0c843f2014-05-23 20:37:23412 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27413 }
[email protected]df0c843f2014-05-23 20:37:23414 FOR_EACH_OBSERVER(WebContentsObserver,
415 observers_,
416 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27417
[email protected]df0c843f2014-05-23 20:37:23418 if (root->pending_render_view_host()) {
419 FOR_EACH_OBSERVER(WebContentsObserver,
420 observers_,
421 RenderViewDeleted(root->pending_render_view_host()));
422 }
[email protected]c06c58c2014-03-12 20:31:59423
[email protected]f273ee52013-10-18 16:05:27424 FOR_EACH_OBSERVER(WebContentsObserver,
425 observers_,
[email protected]df0c843f2014-05-23 20:37:23426 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27427
[email protected]2db9bd72012-04-13 20:20:56428 FOR_EACH_OBSERVER(WebContentsObserver,
429 observers_,
[email protected]12a46832014-05-09 13:35:58430 WebContentsDestroyed());
431
432 FOR_EACH_OBSERVER(WebContentsObserver,
433 observers_,
434 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08435
[email protected]6934a702011-12-20 00:04:51436 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10437
438 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
439 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42440}
441
[email protected]d1198fd2012-08-13 22:50:19442WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59443 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19444 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03445 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59446 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06447 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19448
[email protected]4858e432014-06-23 18:14:17449 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06450 // This makes |new_contents| act as a guest.
451 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16452 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06453 // We are instantiating a WebContents for browser plugin. Set its subframe
454 // bit to true.
455 new_contents->is_subframe_ = true;
456 }
[email protected]54944cde2012-12-09 09:24:59457 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19458 return new_contents;
459}
460
[email protected]95640212014-07-26 18:14:30461// static
462std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
463 std::vector<WebContentsImpl*> result;
464 scoped_ptr<RenderWidgetHostIterator> widgets(
465 RenderWidgetHostImpl::GetRenderWidgetHosts());
466 std::set<WebContentsImpl*> web_contents_set;
467 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
468 if (!rwh->IsRenderView())
469 continue;
470 RenderViewHost* rvh = RenderViewHost::From(rwh);
471 if (!rvh)
472 continue;
473 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
474 if (!web_contents)
475 continue;
476 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
477 if (web_contents_set.find(wci) == web_contents_set.end()) {
478 web_contents_set.insert(wci);
479 result.push_back(wci);
480 }
481 }
482 return result;
483}
484
[email protected]b0936d22013-11-28 06:47:36485RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21486 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28487}
488
[email protected]7bb761892012-07-20 09:32:47489bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
490 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44491 return OnMessageReceived(render_view_host, NULL, message);
492}
493
494bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
495 RenderFrameHost* render_frame_host,
496 const IPC::Message& message) {
497 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56498 if (GetWebUI() &&
499 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17500 return true;
[email protected]d2353452012-01-19 19:53:56501 }
[email protected]f82d57b52011-04-27 19:13:17502
[email protected]d8c660432011-12-22 20:51:25503 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
504 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33505 if (render_frame_host) {
506 while ((observer = it.GetNext()) != NULL)
507 if (observer->OnMessageReceived(message, render_frame_host))
508 return true;
509 } else {
510 while ((observer = it.GetNext()) != NULL)
511 if (observer->OnMessageReceived(message))
512 return true;
513 }
[email protected]403415a2011-01-10 18:57:53514
[email protected]1d62cf72014-02-07 21:31:57515 // Message handlers should be aware of which
516 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
517 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02518 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57519 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02520 else
[email protected]1d62cf72014-02-07 21:31:57521 render_view_message_source_ = render_view_host;
522
[email protected]724159a2010-12-30 01:11:18523 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33524 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40525 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
526 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05527 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
528 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48529 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
530 OnDocumentLoadedInFrame)
531 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00532 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
533 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
534 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
535 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48536 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
537 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
538 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
539 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19540 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
541 OnMediaPlayingNotification)
542 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
543 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11544 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
545 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18546 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
547 OnDidLoadResourceFromMemoryCache)
548 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
549 OnDidDisplayInsecureContent)
550 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
551 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25552 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26553 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21554 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20555 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
556 OnRegisterProtocolHandler)
[email protected]f5273e52014-07-14 16:30:20557 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler,
558 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16559 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10560 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50561 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50562#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:42563 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
564 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50565 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
566 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55567 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40568 OnBrowserPluginMessage(render_frame_host,
569 message))
thestigc4cac8f2014-09-04 21:17:50570#endif
[email protected]41225fe2013-03-29 05:32:02571 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
572 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07573 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
574 OnShowValidationMessage)
575 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
576 OnHideValidationMessage)
577 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
578 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48579#if defined(OS_ANDROID)
580 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
581 OnFindMatchRectsReply)
582 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
583 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48584#endif
[email protected]724159a2010-12-30 01:11:18585 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33586 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44587 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57588 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18589
[email protected]724159a2010-12-30 01:11:18590 return handled;
591}
592
nasko907fcb62015-01-28 04:24:11593bool WebContentsImpl::HasValidFrameSource() {
594 if (!render_frame_message_source_) {
595 DCHECK(render_view_message_source_);
596 RecordAction(base::UserMetricsAction("BadMessageTerminate_WC"));
597 GetRenderProcessHost()->ReceivedBadMessage();
598 return false;
599 }
600
601 return true;
602}
603
[email protected]b172aee2012-04-10 17:05:26604void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18605 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21606 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43607 if (delegate_)
608 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18609}
610
[email protected]d1198fd2012-08-13 22:50:19611NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56612 return controller_;
613}
614
[email protected]d1198fd2012-08-13 22:50:19615const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56616 return controller_;
617}
618
[email protected]8ff00d72012-10-23 19:12:21619BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55620 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30621}
622
[email protected]b172aee2012-04-10 17:05:26623const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24624 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32625 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51626 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31627}
628
[email protected]a093ce02013-07-22 20:53:14629const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24630 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32631 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24632 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
633}
634
635const GURL& WebContentsImpl::GetLastCommittedURL() const {
636 // We may not have a navigation entry yet.
637 NavigationEntry* entry = controller_.GetLastCommittedEntry();
638 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
639}
640
[email protected]8ff00d72012-10-23 19:12:21641WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31642 return delegate_;
643}
644
[email protected]8ff00d72012-10-23 19:12:21645void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31646 // TODO(cbentzel): remove this debugging code?
647 if (delegate == delegate_)
648 return;
649 if (delegate_)
650 delegate_->Detach(this);
651 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08652 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31653 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08654 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00655 if (view_)
[email protected]e85165c642014-06-10 14:34:31656 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08657 }
[email protected]be1f56ab2011-12-22 06:55:31658}
659
[email protected]8ff00d72012-10-23 19:12:21660RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21661 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41662 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16663}
664
clamydf1975e2015-02-05 19:12:24665RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41666 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16667}
668
[email protected]9c9343b2014-03-08 02:56:07669RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
670 if (!frame_tree_.GetFocusedFrame())
671 return NULL;
672 return frame_tree_.GetFocusedFrame()->current_frame_host();
673}
674
[email protected]a86c0e962013-12-17 17:10:39675void WebContentsImpl::ForEachFrame(
676 const base::Callback<void(RenderFrameHost*)>& on_frame) {
677 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
678}
679
680void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
681 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
682 delete message;
683}
684
[email protected]b172aee2012-04-10 17:05:26685RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21686 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31687}
688
[email protected]6b618e62012-08-16 12:59:18689int WebContentsImpl::GetRoutingID() const {
690 if (!GetRenderViewHost())
691 return MSG_ROUTING_NONE;
692
693 return GetRenderViewHost()->GetRoutingID();
694}
695
[email protected]44470a22013-01-24 01:21:54696int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
697 return fullscreen_widget_routing_id_;
698}
699
[email protected]b172aee2012-04-10 17:05:26700RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21701 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31702}
703
[email protected]4aebbca2013-09-17 22:26:49704RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
705 const {
706 RenderWidgetHost* const widget_host =
707 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
708 GetFullscreenWidgetRoutingID());
709 return widget_host ? widget_host->GetView() : NULL;
710}
711
[email protected]8ff00d72012-10-23 19:12:21712WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31713 return view_.get();
714}
715
[email protected]95640212014-07-26 18:14:30716void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
717 if (mode == accessibility_mode_)
718 return;
719
720 accessibility_mode_ = mode;
721 frame_tree_.ForEach(
722 base::Bind(&ForEachFrameInternal,
723 base::Bind(&SetAccessibilityModeOnFrame, mode)));
724 frame_tree_.ForEach(
725 base::Bind(&ForEachPendingFrameInternal,
726 base::Bind(&SetAccessibilityModeOnFrame, mode)));
727}
728
729void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50730 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30731}
732
733void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50734 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30735}
736
zhenw1f790352014-10-30 00:06:04737void WebContentsImpl::ClearNavigationTransitionData() {
738 FrameTreeNode* node = frame_tree_.root();
739 node->render_manager()->ClearNavigationTransitionData();
740}
741
[email protected]8ff00d72012-10-23 19:12:21742WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56743 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03744 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
745 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22746 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58747 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22748 web_ui->SetController(controller);
749 return web_ui;
750 }
751
752 delete web_ui;
753 return NULL;
754}
755
[email protected]8ff00d72012-10-23 19:12:21756WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21757 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
758 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31759}
760
[email protected]8ff00d72012-10-23 19:12:21761WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21762 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34763}
764
[email protected]86ef6a392012-05-11 22:03:11765void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22766 if (GetUserAgentOverride() == override)
767 return;
768
769 renderer_preferences_.user_agent_override = override;
770
771 // Send the new override string to the renderer.
772 RenderViewHost* host = GetRenderViewHost();
773 if (host)
774 host->SyncRendererPrefs();
775
776 // Reload the page if a load is currently in progress to avoid having
777 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27778 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22779 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
780 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53781
782 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
783 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11784}
785
786const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22787 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11788}
789
[email protected]95640212014-07-26 18:14:30790void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
791 AddAccessibilityMode(AccessibilityModeTreeOnly);
792}
793
794bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
795 return accessibility_mode_ == AccessibilityModeTreeOnly;
796}
797
798bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
799 return accessibility_mode_ == AccessibilityModeComplete;
800}
801
[email protected]2ceee8f2014-01-14 18:02:08802#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41803void WebContentsImpl::SetParentNativeViewAccessible(
804gfx::NativeViewAccessible accessible_parent) {
805 accessible_parent_ = accessible_parent;
clamydf1975e2015-02-05 19:12:24806 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:30807 if (rfh)
808 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41809}
810#endif
811
[email protected]fcf75d42013-12-03 20:11:26812const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55813 // Transient entries take precedence. They are used for interstitial pages
814 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23815 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08816 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21817 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30818 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23819 if (entry) {
[email protected]b5cca982011-05-26 04:42:08820 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23821 }
[email protected]fa944cb82013-11-15 17:51:21822 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
823 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58824 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54825 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32826 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54827 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35828 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26829 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54830 if (!title.empty())
831 return title;
832 }
833 }
834
835 // We use the title for the last committed entry rather than a pending
836 // navigation entry. For example, when the user types in a URL, we want to
837 // keep the old page's title until the new load has committed and we get a new
838 // title.
[email protected]96d185d2009-04-24 03:28:54839 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32840
[email protected]9eeafc012013-11-25 23:49:47841 // We make an exception for initial navigations.
842 if (controller_.IsInitialNavigation()) {
843 // We only want to use the title from the visible entry in one of two cases:
844 // 1. There's already a committed entry for an initial navigation, in which
845 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
846 // 2. The pending entry has been explicitly assigned a title to display.
847 //
848 // If there's no last committed entry and no assigned title, we should fall
849 // back to |page_title_when_no_navigation_entry_| rather than showing the
850 // URL.
851 if (entry ||
852 (controller_.GetVisibleEntry() &&
853 !controller_.GetVisibleEntry()->GetTitle().empty())) {
854 entry = controller_.GetVisibleEntry();
855 }
856 }
[email protected]59167c22013-06-03 18:07:32857
[email protected]45d0ef7f2011-01-05 13:46:23858 if (entry) {
[email protected]b5cca982011-05-26 04:42:08859 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23860 }
[email protected]987fc3a2011-05-26 14:18:09861
862 // |page_title_when_no_navigation_entry_| is finally used
863 // if no title cannot be retrieved.
864 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54865}
866
[email protected]b172aee2012-04-10 17:05:26867int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46868 return GetMaxPageIDForSiteInstance(GetSiteInstance());
869}
870
[email protected]b172aee2012-04-10 17:05:26871int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
872 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33873 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
874 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46875
[email protected]b6583592012-01-25 19:52:33876 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34877}
878
[email protected]b172aee2012-04-10 17:05:26879void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46880 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
881}
882
[email protected]b172aee2012-04-10 17:05:26883void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33884 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46885 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33886 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34887}
888
[email protected]ec6c05f2013-10-23 18:41:57889void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
890 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
891 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57892}
893
creiscce56cd2014-09-29 22:45:22894SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21895 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54896}
897
creiscce56cd2014-09-29 22:45:22898SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
899 RenderViewHostImpl* dest_rvh =
900 GetRenderManager()->pending_render_view_host() ?
901 GetRenderManager()->pending_render_view_host() :
902 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58903 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38904}
905
[email protected]b172aee2012-04-10 17:05:26906bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31907 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49908}
909
[email protected]6dfed692014-05-22 04:18:03910bool WebContentsImpl::IsLoadingToDifferentDocument() const {
911 return is_loading_ && is_load_to_different_document_;
912}
913
[email protected]b172aee2012-04-10 17:05:26914bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03915 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31916}
917
[email protected]b172aee2012-04-10 17:05:26918const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31919 return load_state_;
920}
921
[email protected]fcf75d42013-12-03 20:11:26922const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31923 return load_state_host_;
924}
925
[email protected]b172aee2012-04-10 17:05:26926uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31927 return upload_size_;
928}
929
[email protected]b172aee2012-04-10 17:05:26930uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31931 return upload_position_;
932}
933
[email protected]1ae93fb2013-06-14 03:38:56934std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56935 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39936 frame_tree_.ForEach(base::Bind(&CollectSites,
937 base::Unretained(GetBrowserContext()),
938 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56939 return sites;
940}
941
[email protected]b172aee2012-04-10 17:05:26942const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54943 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31944}
945
[email protected]b172aee2012-04-10 17:05:26946bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31947 return displayed_insecure_content_;
948}
949
[email protected]222f5822014-02-05 23:40:49950void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25951 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55952 ++capturer_count_;
953 DVLOG(1) << "There are now " << capturer_count_
954 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49955
956 // Note: This provides a hint to upstream code to size the views optimally
957 // for quality (e.g., to avoid scaling).
958 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
959 preferred_size_for_capture_ = capture_size;
960 OnPreferredSizeChanged(preferred_size_);
961 }
ccameron8807c38f2015-01-17 00:29:19962
963 // Ensure that all views are un-occluded before capture begins.
964 WasUnOccluded();
[email protected]54597982013-02-06 01:59:55965}
966
967void WebContentsImpl::DecrementCapturerCount() {
968 --capturer_count_;
969 DVLOG(1) << "There are now " << capturer_count_
970 << " capturing(s) of WebContentsImpl@" << this;
971 DCHECK_LE(0, capturer_count_);
972
[email protected]5a652232013-02-12 06:15:25973 if (is_being_destroyed_)
974 return;
975
[email protected]222f5822014-02-05 23:40:49976 if (capturer_count_ == 0) {
977 const gfx::Size old_size = preferred_size_for_capture_;
978 preferred_size_for_capture_ = gfx::Size();
979 OnPreferredSizeChanged(old_size);
980 }
981
[email protected]1ac10dca2013-08-20 20:47:04982 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55983 DVLOG(1) << "Executing delayed WasHidden().";
984 WasHidden();
985 }
[email protected]be1f56ab2011-12-22 06:55:31986}
987
[email protected]f2bd40812013-07-20 04:30:44988int WebContentsImpl::GetCapturerCount() const {
989 return capturer_count_;
990}
991
miu50f97892014-09-22 22:49:52992bool WebContentsImpl::IsAudioMuted() const {
993 return audio_muter_.get() && audio_muter_->is_muting();
994}
995
996void WebContentsImpl::SetAudioMuted(bool mute) {
997 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
998 << " for WebContentsImpl@" << this;
999
1000 if (mute == IsAudioMuted())
1001 return;
1002
1003 if (mute) {
1004 if (!audio_muter_)
1005 audio_muter_.reset(new WebContentsAudioMuter(this));
1006 audio_muter_->StartMuting();
1007 } else {
1008 DCHECK(audio_muter_);
1009 audio_muter_->StopMuting();
1010 }
1011
1012 // Notification for UI updates in response to the changed muting state.
1013 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1014}
1015
[email protected]b172aee2012-04-10 17:05:261016bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311017 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1018 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
1019 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:491020}
1021
[email protected]b172aee2012-04-10 17:05:261022void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1023 int error_code) {
[email protected]443b80e2010-12-14 00:42:231024 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341025 return;
1026
[email protected]443b80e2010-12-14 00:42:231027 crashed_status_ = status;
1028 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211029 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341030}
1031
[email protected]b172aee2012-04-10 17:05:261032base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311033 return crashed_status_;
1034}
1035
[email protected]b172aee2012-04-10 17:05:261036bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311037 return is_being_destroyed_;
1038}
1039
[email protected]7f924832014-08-09 05:57:221040void WebContentsImpl::NotifyNavigationStateChanged(
1041 InvalidateTypes changed_flags) {
dalecurtisbc6572e12014-09-12 19:22:301042 // Create and release the audio power save blocker depending on whether the
1043 // tab is actively producing audio or not.
dalecurtis27011852015-01-06 19:52:341044 if ((changed_flags & INVALIDATE_TYPE_TAB) &&
dalecurtisbc6572e12014-09-12 19:22:301045 AudioStreamMonitor::monitoring_available()) {
1046 if (WasRecentlyAudible()) {
1047 if (!audio_power_save_blocker_)
1048 CreateAudioPowerSaveBlocker();
1049 } else {
1050 audio_power_save_blocker_.reset();
1051 }
1052 }
1053
[email protected]d5f942ba2008-09-26 19:30:341054 if (delegate_)
1055 delegate_->NavigationStateChanged(this, changed_flags);
1056}
1057
[email protected]9a890452014-02-13 22:21:021058base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
1059 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331060}
1061
[email protected]9e2e4632012-07-27 16:38:411062void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541063 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591064
ccameron8807c38f2015-01-17 00:29:191065 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1066 if (view) {
1067 view->Show();
[email protected]789e9152009-08-04 21:59:431068#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191069 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431070#endif
[email protected]de3c5d82014-05-28 22:12:591071 }
[email protected]789e9152009-08-04 21:59:431072 }
[email protected]96d185d2009-04-24 03:28:541073
[email protected]9a890452014-02-13 22:21:021074 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381075
[email protected]b9769d82012-02-10 00:23:591076 // The resize rect might have changed while this was inactive -- send the new
1077 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:581078 RenderViewHostImpl* rvh =
1079 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:591080 if (rvh) {
1081 rvh->ResizeRectChanged(GetRootWindowResizerRect());
1082 }
[email protected]96d185d2009-04-24 03:28:541083
dalecurtisbc6572e12014-09-12 19:22:301084 // Restore power save blocker if there are active video players running.
1085 if (!active_video_players_.empty() && !video_power_save_blocker_)
1086 CreateVideoPowerSaveBlocker();
1087
[email protected]c0d9d5672013-10-09 07:38:031088 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1089
[email protected]54597982013-02-06 01:59:551090 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311091}
1092
[email protected]b172aee2012-04-10 17:05:261093void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551094 // If there are entities capturing screenshots or video (e.g., mirroring),
1095 // don't activate the "disable rendering" optimization.
1096 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521097 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551098 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261099 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521100 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331101 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521102 // calls us).
ccameron8807c38f2015-01-17 00:29:191103 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1104 if (view)
1105 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591106 }
dalecurtisbc6572e12014-09-12 19:22:301107
1108 // Release any video power save blockers held as video is not visible.
1109 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541110 }
1111
[email protected]c0d9d5672013-10-09 07:38:031112 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1113
[email protected]54597982013-02-06 01:59:551114 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371115}
1116
ccameron8807c38f2015-01-17 00:29:191117void WebContentsImpl::WasOccluded() {
1118 if (capturer_count_ > 0)
1119 return;
1120
1121 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1122 if (view)
1123 view->WasOccluded();
1124 }
1125}
1126
1127void WebContentsImpl::WasUnOccluded() {
1128 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1129 if (view)
1130 view->WasUnOccluded();
1131 }
1132}
1133
[email protected]b172aee2012-04-10 17:05:261134bool WebContentsImpl::NeedToFireBeforeUnload() {
clamydf1975e2015-02-05 19:12:241135 bool sudden_termination_allowed = true;
1136 frame_tree_.ForEach(base::Bind(
1137 &SuddenTerminationAllowed, &sudden_termination_allowed));
[email protected]be1f56ab2011-12-22 06:55:311138 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271139 return WillNotifyDisconnection() &&
1140 !ShowingInterstitialPage() &&
clamydf1975e2015-02-05 19:12:241141 !sudden_termination_allowed;
[email protected]be1f56ab2011-12-22 06:55:311142}
1143
[email protected]1c3f80bd2014-04-08 23:02:061144void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
clamydf1975e2015-02-05 19:12:241145 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061146}
1147
[email protected]b172aee2012-04-10 17:05:261148void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211149 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401150 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271151}
1152
[email protected]b172aee2012-04-10 17:05:261153WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441154 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451155 // We pass our own opener so that the cloned page can access it if it was
1156 // before.
[email protected]54944cde2012-12-09 09:24:591157 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451158 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591159 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191160 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221161 FOR_EACH_OBSERVER(WebContentsObserver,
1162 observers_,
1163 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271164 return tc;
1165}
1166
[email protected]14392a52012-05-02 20:28:441167void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211168 const NotificationSource& source,
1169 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441170 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211171 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1172 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031173 RenderWidgetHostView* view = host->GetView();
1174 if (view == GetFullscreenRenderWidgetHostView()) {
1175 // We cannot just call view_->RestoreFocus() here. On some platforms,
1176 // attempting to focus the currently-invisible WebContentsView will be
1177 // flat-out ignored. Therefore, this boolean is used to track whether
1178 // we will request focus after the fullscreen widget has been
1179 // destroyed.
1180 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1181 } else {
1182 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1183 i != pending_widget_views_.end(); ++i) {
1184 if (host->GetView() == i->second) {
1185 pending_widget_views_.erase(i);
1186 break;
1187 }
[email protected]bafe6cd2012-05-23 23:09:501188 }
1189 }
1190 break;
1191 }
[email protected]14392a52012-05-02 20:28:441192 default:
1193 NOTREACHED();
1194 }
1195}
1196
[email protected]ec6c05f2013-10-23 18:41:571197WebContents* WebContentsImpl::GetWebContents() {
1198 return this;
1199}
1200
[email protected]54944cde2012-12-09 09:24:591201void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211202 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361203 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211204 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431205 should_normally_be_visible_ = !params.initially_hidden;
1206
avic2c29d782014-12-12 00:23:541207 // Either both routing ids can be given, or neither can be.
1208 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
1209 params.main_frame_routing_id == MSG_ROUTING_NONE) ||
1210 (params.routing_id != MSG_ROUTING_NONE &&
1211 params.main_frame_routing_id != MSG_ROUTING_NONE));
[email protected]fa944cb82013-11-15 17:51:211212 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041213 params.browser_context, params.site_instance, params.routing_id,
1214 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191215
[email protected]fc2b46b2014-05-03 16:33:451216 WebContentsViewDelegate* delegate =
1217 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1218
1219 if (browser_plugin_guest_) {
1220 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1221 this, delegate, &render_view_host_delegate_view_));
1222
1223 WebContentsViewGuest* rv = new WebContentsViewGuest(
1224 this, browser_plugin_guest_.get(), platform_view.Pass(),
1225 render_view_host_delegate_view_);
1226 render_view_host_delegate_view_ = rv;
1227 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191228 } else {
[email protected]fc2b46b2014-05-03 16:33:451229 // Regular WebContentsView.
1230 view_.reset(CreateWebContentsView(
1231 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191232 }
[email protected]fc2b46b2014-05-03 16:33:451233 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191234 CHECK(view_.get());
1235
[email protected]ed245db2012-12-18 08:00:451236 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591237 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191238
1239 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101240 if (opener_)
1241 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191242
tommyclieb25b2a2014-11-03 19:45:091243#if defined(ENABLE_PLUGINS)
1244 plugin_content_origin_whitelist_.reset(
1245 new PluginContentOriginWhitelist(this));
1246#endif
1247
[email protected]d1198fd2012-08-13 22:50:191248 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211249 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1250 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101251
[email protected]01f83f92014-06-17 14:41:541252 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091253 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541254
mlamouriefdca9d2014-09-16 16:55:401255 manifest_manager_host_.reset(new ManifestManagerHost(this));
1256
[email protected]c7654a232013-06-12 21:04:441257#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101258 date_time_chooser_.reset(new DateTimeChooserAndroid());
1259#endif
fsamuel7310a4262014-12-05 05:06:441260
1261 // BrowserPluginGuest::Init needs to be called after this WebContents has
1262 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1263 if (browser_plugin_guest_)
1264 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371265
1266 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1267 g_created_callbacks.Get().at(i).Run(this);
[email protected]d1198fd2012-08-13 22:50:191268}
1269
[email protected]7fff43e2013-05-21 20:21:101270void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1271 RemoveDestructionObserver(web_contents);
1272
[email protected]14392a52012-05-02 20:28:441273 // Clear the opener if it has been closed.
1274 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441275 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511276 return;
[email protected]14392a52012-05-02 20:28:441277 }
[email protected]ceee8cd2013-03-08 04:59:511278 // Clear a pending contents that has been closed before being shown.
1279 for (PendingContents::iterator iter = pending_contents_.begin();
1280 iter != pending_contents_.end();
1281 ++iter) {
1282 if (iter->second != web_contents)
1283 continue;
1284 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511285 return;
1286 }
1287 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441288}
1289
[email protected]7fff43e2013-05-21 20:21:101290void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1291 if (!ContainsKey(destruction_observers_, web_contents)) {
1292 destruction_observers_[web_contents] =
1293 new DestructionObserver(this, web_contents);
1294 }
1295}
1296
1297void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1298 DestructionObservers::iterator iter =
1299 destruction_observers_.find(web_contents);
1300 if (iter != destruction_observers_.end()) {
1301 delete destruction_observers_[web_contents];
1302 destruction_observers_.erase(iter);
1303 }
1304}
1305
[email protected]b172aee2012-04-10 17:05:261306void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311307 observers_.AddObserver(observer);
1308}
1309
[email protected]b172aee2012-04-10 17:05:261310void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311311 observers_.RemoveObserver(observer);
1312}
1313
[email protected]948481d2014-06-11 18:32:221314std::set<RenderWidgetHostView*>
1315WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1316 std::set<RenderWidgetHostView*> set;
1317 if (ShowingInterstitialPage()) {
1318 set.insert(GetRenderWidgetHostView());
1319 } else {
1320 ForEachFrame(
1321 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1322 }
[email protected]de3c5d82014-05-28 22:12:591323 return set;
1324}
1325
[email protected]b172aee2012-04-10 17:05:261326void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341327 if (delegate_)
1328 delegate_->ActivateContents(this);
1329}
1330
[email protected]b172aee2012-04-10 17:05:261331void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121332 if (delegate_)
1333 delegate_->DeactivateContents(this);
1334}
1335
[email protected]b172aee2012-04-10 17:05:261336void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481337 if (delegate_)
1338 delegate_->LostCapture();
1339}
1340
[email protected]b24b68a2012-09-24 21:57:261341void WebContentsImpl::RenderWidgetDeleted(
1342 RenderWidgetHostImpl* render_widget_host) {
1343 if (is_being_destroyed_) {
1344 // |created_widgets_| might have been destroyed.
1345 return;
1346 }
1347
1348 std::set<RenderWidgetHostImpl*>::iterator iter =
1349 created_widgets_.find(render_widget_host);
1350 if (iter != created_widgets_.end())
1351 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541352
1353 if (render_widget_host &&
1354 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491355 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531356 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541357 FOR_EACH_OBSERVER(WebContentsObserver,
1358 observers_,
1359 DidDestroyFullscreenWidget(
1360 fullscreen_widget_routing_id_));
1361 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031362 if (fullscreen_widget_had_focus_at_shutdown_)
1363 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541364 }
[email protected]b24b68a2012-09-24 21:57:261365}
1366
miu9e14e492014-10-25 02:39:041367void WebContentsImpl::RenderWidgetGotFocus(
1368 RenderWidgetHostImpl* render_widget_host) {
1369 // Notify the delegate if an embedded fullscreen widget was focused.
1370 if (delegate_ && render_widget_host &&
1371 delegate_->EmbedsFullscreenWidget() &&
1372 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1373 delegate_->WebContentsFocused(this);
1374}
1375
estaded0a0c992015-01-21 14:12:061376void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311377 RenderWidgetHostImpl* render_widget_host,
1378 bool width_changed) {
clamydf1975e2015-02-05 19:12:241379 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291380 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061381 return;
estaded0a0c992015-01-21 14:12:061382
rouslan2f5993f2015-01-29 00:18:311383 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1384 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061385}
1386
[email protected]b172aee2012-04-10 17:05:261387bool WebContentsImpl::PreHandleKeyboardEvent(
1388 const NativeWebKeyboardEvent& event,
1389 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481390 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131391 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481392}
1393
[email protected]b172aee2012-04-10 17:05:261394void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101395 if (browser_plugin_embedder_ &&
1396 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1397 return;
1398 }
[email protected]63954792011-07-11 04:17:481399 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131400 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481401}
1402
[email protected]d92026ef2014-03-03 21:04:131403bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461404 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191405#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331406 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1407 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191408 // -the OS already has a gesture to do this through pinch-zoom
1409 // -if a user starts an inertial scroll, let's go, and presses control
1410 // (i.e. control+tab) then the OS's buffered scroll events will come in
1411 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331412 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551413 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331414 !event.canScroll) {
[email protected]fb3f066e2013-02-12 19:12:521415 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1416 return true;
1417 }
[email protected]bccc4472013-04-18 16:37:191418#endif
[email protected]fb3f066e2013-02-12 19:12:521419 return false;
1420}
1421
[email protected]04bce562014-01-30 05:34:541422bool WebContentsImpl::PreHandleGestureEvent(
1423 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031424 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541425}
1426
[email protected]b172aee2012-04-10 17:05:261427void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431428 if (delegate_)
1429 delegate_->HandleMouseDown();
1430}
1431
[email protected]b172aee2012-04-10 17:05:261432void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481433 if (delegate_)
1434 delegate_->HandleMouseUp();
1435}
1436
[email protected]590a634e2012-07-19 16:38:231437void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481438 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231439 delegate_->HandlePointerActivate();
1440}
1441
1442void WebContentsImpl::HandleGestureBegin() {
1443 if (delegate_)
1444 delegate_->HandleGestureBegin();
1445}
1446
1447void WebContentsImpl::HandleGestureEnd() {
1448 if (delegate_)
1449 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481450}
1451
mlamouri7a78d6fd2015-01-17 13:23:531452void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1453 // This method is being called to enter renderer-initiated fullscreen mode.
1454 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491455 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1456 if (widget_view)
1457 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1458
[email protected]8a5e0ca2011-08-25 06:30:471459 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531460 delegate_->EnterFullscreenModeForTab(this, origin);
1461
1462 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1463 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
1464}
1465
1466void WebContentsImpl::ExitFullscreenMode() {
1467 // This method is being called to leave renderer-initiated fullscreen mode.
1468 // Make sure any existing fullscreen widget is shut down first.
1469 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1470 if (widget_view)
1471 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1472
hugo.holgersson61288e6c2015-01-28 17:04:401473#if defined(OS_ANDROID)
1474 ContentVideoView* video_view = ContentVideoView::GetInstance();
1475 if (video_view != NULL)
1476 video_view->OnExitFullscreen();
1477#endif
1478
mlamouri7a78d6fd2015-01-17 13:23:531479 if (delegate_)
1480 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371481
scheib3dcb6c932015-02-23 10:55:581482 // Ensure web contents exit fullscreen state by sending a resize message,
1483 // which includes the fullscreen state. This is required for the situation
1484 // of the browser moving the view into a fullscreen state "browser fullscreen"
1485 // and then the contents entering "tab fullscreen". Exiting the contents
1486 // "tab fullscreen" then won't have the side effect of the view resizing,
1487 // hence the explicit call here is required.
1488 if (RenderWidgetHostView* rwh_view = GetRenderWidgetHostView()) {
1489 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1490 render_widget_host->WasResized();
1491 }
1492
[email protected]657c8e02014-03-19 19:18:371493 FOR_EACH_OBSERVER(WebContentsObserver,
1494 observers_,
1495 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471496}
1497
[email protected]b172aee2012-04-10 17:05:261498bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381499 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121500}
1501
[email protected]a9c81f02012-06-01 00:15:441502void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1503 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371504 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441505 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371506 } else {
1507 GotResponseToLockMouseRequest(false);
1508 }
1509}
1510
[email protected]b172aee2012-04-10 17:05:261511void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371512 if (delegate_)
1513 delegate_->LostMouseLock();
1514}
1515
[email protected]bafe6cd2012-05-23 23:09:501516void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201517 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501518 int route_id,
[email protected]227692c52013-05-31 22:43:041519 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131520 const ViewHostMsg_CreateWindow_Params& params,
1521 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501522 // We usually create the new window in the same BrowsingInstance (group of
1523 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551524 // if the opener is being suppressed (in a non-guest), we create a new
1525 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251526 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551527
[email protected]04cbd3d2013-12-04 04:58:201528 // If the opener is to be suppressed, the new window can be in any process.
1529 // Since routing ids are process specific, we must not have one passed in
1530 // as argument here.
1531 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1532
[email protected]bafe6cd2012-05-23 23:09:501533 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551534 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571535 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501536 GetSiteInstance();
1537
[email protected]04cbd3d2013-12-04 04:58:201538 // A message to create a new window can only come from the active process for
1539 // this WebContentsImpl instance. If any other process sends the request,
1540 // it is invalid and the process must be terminated.
1541 if (GetRenderProcessHost()->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351542 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1543 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201544 if (process_handle != base::kNullProcessHandle) {
1545 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391546 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351547 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201548 }
1549 return;
1550 }
1551
[email protected]d1198fd2012-08-13 22:50:191552 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341553 //
1554 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301555 const std::string& partition_id =
1556 GetContentClient()->browser()->
1557 GetStoragePartitionIdForSite(GetBrowserContext(),
1558 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461559 StoragePartition* partition = BrowserContext::GetStoragePartition(
1560 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411561 DOMStorageContextWrapper* dom_storage_context =
1562 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191563 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1564 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1565 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371566
1567 if (delegate_ &&
1568 !delegate_->ShouldCreateWebContents(this,
1569 route_id,
avic2c29d782014-12-12 00:23:541570 main_frame_route_id,
[email protected]dd6730412013-08-14 15:03:371571 params.window_container_type,
1572 params.frame_name,
1573 params.target_url,
1574 partition_id,
1575 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011576 if (route_id != MSG_ROUTING_NONE &&
1577 !RenderViewHost::FromID(render_process_id, route_id)) {
1578 // If the embedder didn't create a WebContents for this route, we need to
1579 // delete the RenderView that had already been created.
1580 Send(new ViewMsg_Close(route_id));
1581 }
[email protected]dd6730412013-08-14 15:03:371582 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1583 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1584 main_frame_route_id);
1585 return;
1586 }
1587
1588 // Create the new web contents. This will automatically create the new
1589 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461590 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591591 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041592 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061593 create_params.opener = this;
1594 create_params.opener_suppressed = params.opener_suppressed;
1595 if (params.disposition == NEW_BACKGROUND_TAB)
1596 create_params.initially_hidden = true;
1597
[email protected]4858e432014-06-23 18:14:171598 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551599 if (!is_guest) {
1600 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451601 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171602 new_contents = static_cast<WebContentsImpl*>(
1603 WebContents::Create(create_params));
1604 } else {
1605 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551606 }
[email protected]50d326e2014-05-20 17:59:061607 new_contents->GetController().SetSessionStorageNamespace(
1608 partition_id,
1609 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261610 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191611
[email protected]c4538072013-03-18 02:17:551612 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341613 // will be shown immediately).
1614 if (!params.opener_suppressed) {
1615 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451616 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501617
[email protected]d70bea92013-04-05 04:23:341618 // TODO(brettw): It seems bogus that we have to call this function on the
1619 // newly created object and give it one of its own member variables.
lazyboy549b3b42014-10-20 17:16:041620 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false);
[email protected]d70bea92013-04-05 04:23:341621 }
[email protected]bafe6cd2012-05-23 23:09:501622 // Save the created window associated with the route so we can show it
1623 // later.
1624 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1625 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101626 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501627 }
1628
1629 if (delegate_) {
1630 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071631 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131632 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501633 }
1634
1635 if (params.opener_suppressed) {
1636 // When the opener is suppressed, the original renderer cannot access the
1637 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001638 bool was_blocked = false;
1639 if (delegate_) {
bokan107a47f2015-02-03 23:23:391640 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001641 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391642 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001643 params.user_gesture, &was_blocked);
1644 }
1645 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211646 OpenURLParams open_params(params.target_url,
1647 Referrer(),
1648 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351649 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211650 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301651 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001652 new_contents->OpenURL(open_params);
1653 }
[email protected]bafe6cd2012-05-23 23:09:501654 }
1655}
1656
[email protected]a8504022013-12-04 20:23:511657void WebContentsImpl::CreateNewWidget(int render_process_id,
1658 int route_id,
[email protected]180ef242013-11-07 06:50:461659 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511660 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501661}
1662
[email protected]a8504022013-12-04 20:23:511663void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1664 int route_id) {
1665 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501666}
1667
[email protected]a8504022013-12-04 20:23:511668void WebContentsImpl::CreateNewWidget(int render_process_id,
1669 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501670 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461671 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211672 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511673 // A message to create a new widget can only come from the active process for
1674 // this WebContentsImpl instance. If any other process sends the request,
1675 // it is invalid and the process must be terminated.
1676 if (process->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351677 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1678 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511679 if (process_handle != base::kNullProcessHandle) {
1680 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391681 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351682 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511683 }
1684 return;
1685 }
1686
[email protected]bafe6cd2012-05-23 23:09:501687 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041688 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261689 created_widgets_.insert(widget_host);
1690
[email protected]cfd80b02014-05-01 17:46:481691 RenderWidgetHostViewBase* widget_view =
1692 static_cast<RenderWidgetHostViewBase*>(
1693 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191694 if (!widget_view)
1695 return;
[email protected]bafe6cd2012-05-23 23:09:501696 if (!is_fullscreen) {
1697 // Popups should not get activated.
1698 widget_view->SetPopupType(popup_type);
1699 }
1700 // Save the created widget associated with the route so we can show it later.
1701 pending_widget_views_[route_id] = widget_view;
1702
1703#if defined(OS_MACOSX)
1704 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1705 // to allow it to survive the trip without being hosted.
1706 base::mac::NSObjectRetain(widget_view->GetNativeView());
1707#endif
1708}
1709
1710void WebContentsImpl::ShowCreatedWindow(int route_id,
1711 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:391712 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:501713 bool user_gesture) {
1714 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001715 if (contents) {
1716 WebContentsDelegate* delegate = GetDelegate();
1717 if (delegate) {
1718 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:391719 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:001720 }
1721 }
[email protected]bafe6cd2012-05-23 23:09:501722}
1723
1724void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:391725 const gfx::Rect& initial_rect) {
1726 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:501727}
1728
1729void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1730 ShowCreatedWidget(route_id, true, gfx::Rect());
1731}
1732
1733void WebContentsImpl::ShowCreatedWidget(int route_id,
1734 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:391735 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:481736 RenderWidgetHostViewBase* widget_host_view =
1737 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501738 if (!widget_host_view)
1739 return;
[email protected]cfd80b02014-05-01 17:46:481740
1741 RenderWidgetHostView* view = NULL;
1742 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1743 if (guest && guest->embedder_web_contents()) {
1744 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1745 } else {
1746 view = GetRenderWidgetHostView();
1747 }
1748
[email protected]4aebbca2013-09-17 22:26:491749 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311750 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031751 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311752 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491753 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1754 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:531755 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:491756 } else {
[email protected]cfd80b02014-05-01 17:46:481757 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491758 }
[email protected]4aebbca2013-09-17 22:26:491759 FOR_EACH_OBSERVER(WebContentsObserver,
1760 observers_,
1761 DidShowFullscreenWidget(route_id));
1762 if (!widget_host_view->HasFocus())
1763 widget_host_view->Focus();
1764 } else {
bokan107a47f2015-02-03 23:23:391765 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:491766 }
[email protected]89054502012-06-03 10:29:241767
1768 RenderWidgetHostImpl* render_widget_host_impl =
1769 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1770 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311771 // Only allow privileged mouse lock for fullscreen render widget, which is
1772 // used to implement Pepper Flash fullscreen.
1773 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501774
1775#if defined(OS_MACOSX)
1776 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1777 // properly embedded (or purposefully ignored) we can release the retain we
1778 // took in CreateNewWidget().
1779 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1780#endif
1781}
1782
1783WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1784 PendingContents::iterator iter = pending_contents_.find(route_id);
1785
1786 // Certain systems can block the creation of new windows. If we didn't succeed
1787 // in creating one, just return NULL.
1788 if (iter == pending_contents_.end()) {
1789 return NULL;
1790 }
1791
1792 WebContentsImpl* new_contents = iter->second;
1793 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101794 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501795
[email protected]d70bea92013-04-05 04:23:341796 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251797 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341798 return new_contents;
1799
[email protected]bafe6cd2012-05-23 23:09:501800 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1801 !new_contents->GetRenderViewHost()->GetView())
1802 return NULL;
1803
creis82dd6af2014-09-17 16:30:451804 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
[email protected]bafe6cd2012-05-23 23:09:501805 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1806 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
clamydf1975e2015-02-05 19:12:241807 new_contents->GetMainFrame()->Init();
creis82dd6af2014-09-17 16:30:451808
[email protected]bafe6cd2012-05-23 23:09:501809 return new_contents;
1810}
1811
1812RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1813 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1814 if (iter == pending_widget_views_.end()) {
1815 DCHECK(false);
1816 return NULL;
1817 }
1818
1819 RenderWidgetHostView* widget_host_view = iter->second;
1820 pending_widget_views_.erase(route_id);
1821
1822 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1823 if (!widget_host->GetProcess()->HasConnection()) {
1824 // The view has gone away or the renderer crashed. Nothing to do.
1825 return NULL;
1826 }
1827
1828 return widget_host_view;
1829}
1830
[email protected]f13b4202012-06-12 23:53:231831void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091832 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211833 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371834 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231835 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371836 } else {
1837 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041838 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371839 scoped_ptr<MediaStreamUI>());
1840 }
[email protected]f13b4202012-06-12 23:53:231841}
1842
grunell657d4d82014-09-18 00:09:431843bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1844 MediaStreamType type) {
1845 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1846 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1847 return delegate_ &&
1848 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1849}
1850
[email protected]cc9200432013-07-23 23:02:401851SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1852 SiteInstance* instance) {
1853 return controller_.GetSessionStorageNamespace(instance);
1854}
1855
[email protected]6de7fc482014-06-06 10:46:441856SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1857 return controller_.GetSessionStorageNamespaceMap();
1858}
1859
[email protected]9b159a52013-10-03 17:24:551860FrameTree* WebContentsImpl::GetFrameTree() {
1861 return &frame_tree_;
1862}
1863
lukendc35e7f2014-11-10 19:06:141864void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
1865 virtual_keyboard_requested_ = requested;
1866}
1867
1868bool WebContentsImpl::IsVirtualKeyboardRequested() {
1869 return virtual_keyboard_requested_;
1870}
1871
[email protected]95640212014-07-26 18:14:301872AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
1873 return accessibility_mode_;
1874}
1875
[email protected]31a71eaf2014-03-13 01:47:361876void WebContentsImpl::AccessibilityEventReceived(
1877 const std::vector<AXEventNotificationDetails>& details) {
1878 FOR_EACH_OBSERVER(
1879 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1880}
1881
dmazzonia656928e2014-09-15 20:28:541882RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:401883 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:541884 int browser_plugin_instance_id) {
1885 BrowserPluginGuestManager* guest_manager =
1886 GetBrowserContext()->GetGuestManager();
fsamuel833ee7c2015-02-13 23:40:401887 // TODO(fsamuel): Change message routing to use the process ID of the
1888 // |render_frame_host| once BrowserPlugin IPCs get routed using the RFH
1889 // routing ID. See http://crbug.com/436339.
dmazzonia656928e2014-09-15 20:28:541890 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:401891 GetRenderProcessHost()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:541892 if (!guest)
1893 return NULL;
1894 return guest->GetMainFrame();
1895}
1896
blundellc57b93f2014-10-29 13:19:571897GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
1898 return geolocation_service_context_.get();
1899}
1900
[email protected]edc3af82013-12-12 21:24:071901void WebContentsImpl::OnShowValidationMessage(
1902 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291903 const base::string16& main_text,
1904 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071905 if (delegate_)
1906 delegate_->ShowValidationMessage(
1907 this, anchor_in_root_view, main_text, sub_text);
1908}
1909
1910void WebContentsImpl::OnHideValidationMessage() {
1911 if (delegate_)
1912 delegate_->HideValidationMessage(this);
1913}
1914
1915void WebContentsImpl::OnMoveValidationMessage(
1916 const gfx::Rect& anchor_in_root_view) {
1917 if (delegate_)
1918 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1919}
1920
[email protected]32deec62013-05-15 23:55:041921void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1922 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441923 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041924}
1925
[email protected]95640212014-07-26 18:14:301926BrowserAccessibilityManager*
1927 WebContentsImpl::GetRootBrowserAccessibilityManager() {
clamydf1975e2015-02-05 19:12:241928 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:301929 return rfh ? rfh->browser_accessibility_manager() : NULL;
1930}
1931
1932BrowserAccessibilityManager*
1933 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
clamydf1975e2015-02-05 19:12:241934 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:301935 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1936}
1937
[email protected]b172aee2012-04-10 17:05:261938void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491939 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231940 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491941 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331942}
1943
[email protected]b172aee2012-04-10 17:05:261944void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341945 if (delegate_)
1946 delegate_->ResizeDueToAutoResize(this, new_size);
1947}
1948
[email protected]b172aee2012-04-10 17:05:261949WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201950 if (!delegate_)
1951 return NULL;
[email protected]00c37fc2011-08-02 00:22:501952
[email protected]e5d549d2011-12-28 01:29:201953 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201954 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341955}
1956
[email protected]6b618e62012-08-16 12:59:181957bool WebContentsImpl::Send(IPC::Message* message) {
1958 if (!GetRenderViewHost()) {
1959 delete message;
1960 return false;
1961 }
1962
1963 return GetRenderViewHost()->Send(message);
1964}
1965
[email protected]b172aee2012-04-10 17:05:261966bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501967 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261968 FrameTreeNode* node = frame_tree_.root();
1969
creise42f2a52014-09-18 18:14:571970 // Navigate in the FrameTreeNode specified in the pending entry, if any. This
1971 // is currently only used in --site-per-process and tests.
creis2b4cc93952015-02-20 02:04:051972 // TODO(creis): Remove this method and NavigationEntryImpl::frame_tree_node_id
1973 // by using FrameNavigationEntries instead. See https://crbug.com/236848.
creis3da03872015-02-20 21:12:321974 NavigationEntryImpl* pending_entry = controller_.GetPendingEntry();
creise42f2a52014-09-18 18:14:571975 if (pending_entry->frame_tree_node_id() != -1) {
1976 FrameTreeNode* subframe =
1977 frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1978 DCHECK(subframe);
1979 if (subframe)
1980 node = subframe;
[email protected]61ac9e242014-03-21 20:55:261981 }
1982
creis2b4cc93952015-02-20 02:04:051983 return node->navigator()->NavigateToPendingEntry(node, reload_type);
[email protected]876bc832010-09-07 16:29:541984}
[email protected]96d185d2009-04-24 03:28:541985
[email protected]a86c0e962013-12-17 17:10:391986void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1987 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441988 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391989 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441990}
1991
[email protected]20ca0382013-02-28 19:50:071992void WebContentsImpl::AttachInterstitialPage(
1993 InterstitialPageImpl* interstitial_page) {
1994 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211995 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291996
1997 // Cancel any visible dialogs so that they don't interfere with the
1998 // interstitial.
1999 if (dialog_manager_)
2000 dialog_manager_->CancelActiveAndPendingDialogs(this);
2001
[email protected]20ca0382013-02-28 19:50:072002 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2003 DidAttachInterstitialPage());
2004}
2005
2006void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:572007 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212008 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072009 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2010 DidDetachInterstitialPage());
2011}
2012
avi2b177592014-12-10 02:08:022013void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2014 int history_length) {
2015 SetHistoryOffsetAndLengthForView(
2016 GetRenderViewHost(), history_offset, history_length);
2017}
2018
2019void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2020 RenderViewHost* render_view_host,
2021 int history_offset,
2022 int history_length) {
2023 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2024 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142025}
2026
[email protected]4fed3702014-04-01 09:08:002027void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172028 RenderFrameHost* focused_frame = GetFocusedFrame();
2029 if (!focused_frame)
2030 return;
2031
[email protected]959be4c2014-04-08 15:01:332032 focused_frame->Send(new FrameMsg_Reload(
2033 focused_frame->GetRoutingID(), ignore_cache));
2034}
2035
2036void WebContentsImpl::Undo() {
2037 RenderFrameHost* focused_frame = GetFocusedFrame();
2038 if (!focused_frame)
2039 return;
2040
2041 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2042 RecordAction(base::UserMetricsAction("Undo"));
2043}
2044
2045void WebContentsImpl::Redo() {
2046 RenderFrameHost* focused_frame = GetFocusedFrame();
2047 if (!focused_frame)
2048 return;
2049 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2050 RecordAction(base::UserMetricsAction("Redo"));
2051}
2052
2053void WebContentsImpl::Cut() {
2054 RenderFrameHost* focused_frame = GetFocusedFrame();
2055 if (!focused_frame)
2056 return;
2057
2058 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2059 RecordAction(base::UserMetricsAction("Cut"));
2060}
2061
2062void WebContentsImpl::Copy() {
2063 RenderFrameHost* focused_frame = GetFocusedFrame();
2064 if (!focused_frame)
2065 return;
2066
2067 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2068 RecordAction(base::UserMetricsAction("Copy"));
2069}
2070
2071void WebContentsImpl::CopyToFindPboard() {
2072#if defined(OS_MACOSX)
2073 RenderFrameHost* focused_frame = GetFocusedFrame();
2074 if (!focused_frame)
2075 return;
2076
2077 // Windows/Linux don't have the concept of a find pasteboard.
2078 focused_frame->Send(
2079 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2080 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2081#endif
2082}
2083
2084void WebContentsImpl::Paste() {
2085 RenderFrameHost* focused_frame = GetFocusedFrame();
2086 if (!focused_frame)
2087 return;
2088
2089 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2090 RecordAction(base::UserMetricsAction("Paste"));
2091}
2092
2093void WebContentsImpl::PasteAndMatchStyle() {
2094 RenderFrameHost* focused_frame = GetFocusedFrame();
2095 if (!focused_frame)
2096 return;
2097
2098 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2099 focused_frame->GetRoutingID()));
2100 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2101}
2102
2103void WebContentsImpl::Delete() {
2104 RenderFrameHost* focused_frame = GetFocusedFrame();
2105 if (!focused_frame)
2106 return;
2107
2108 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2109 RecordAction(base::UserMetricsAction("DeleteSelection"));
2110}
2111
2112void WebContentsImpl::SelectAll() {
2113 RenderFrameHost* focused_frame = GetFocusedFrame();
2114 if (!focused_frame)
2115 return;
2116
2117 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2118 RecordAction(base::UserMetricsAction("SelectAll"));
2119}
2120
2121void WebContentsImpl::Unselect() {
2122 RenderFrameHost* focused_frame = GetFocusedFrame();
2123 if (!focused_frame)
2124 return;
2125
2126 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2127 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172128}
2129
2130void WebContentsImpl::Replace(const base::string16& word) {
2131 RenderFrameHost* focused_frame = GetFocusedFrame();
2132 if (!focused_frame)
2133 return;
2134
[email protected]959be4c2014-04-08 15:01:332135 focused_frame->Send(new InputMsg_Replace(
2136 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172137}
2138
2139void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2140 RenderFrameHost* focused_frame = GetFocusedFrame();
2141 if (!focused_frame)
2142 return;
2143
[email protected]959be4c2014-04-08 15:01:332144 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2145 focused_frame->GetRoutingID(), word));
2146}
2147
2148void WebContentsImpl::NotifyContextMenuClosed(
2149 const CustomContextMenuContext& context) {
2150 RenderFrameHost* focused_frame = GetFocusedFrame();
2151 if (!focused_frame)
2152 return;
2153
2154 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2155 focused_frame->GetRoutingID(), context));
2156}
2157
2158void WebContentsImpl::ExecuteCustomContextMenuCommand(
2159 int action, const CustomContextMenuContext& context) {
2160 RenderFrameHost* focused_frame = GetFocusedFrame();
2161 if (!focused_frame)
2162 return;
2163
2164 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2165 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002166}
2167
[email protected]fc2b46b2014-05-03 16:33:452168gfx::NativeView WebContentsImpl::GetNativeView() {
2169 return view_->GetNativeView();
2170}
2171
2172gfx::NativeView WebContentsImpl::GetContentNativeView() {
2173 return view_->GetContentNativeView();
2174}
2175
2176gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2177 return view_->GetTopLevelNativeWindow();
2178}
2179
2180gfx::Rect WebContentsImpl::GetViewBounds() {
2181 return view_->GetViewBounds();
2182}
2183
2184gfx::Rect WebContentsImpl::GetContainerBounds() {
2185 gfx::Rect rv;
2186 view_->GetContainerBounds(&rv);
2187 return rv;
2188}
2189
2190DropData* WebContentsImpl::GetDropData() {
2191 return view_->GetDropData();
2192}
2193
2194void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042195 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452196}
2197
2198void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042199 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452200}
2201
2202void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042203 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452204}
2205
2206void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042207 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452208}
2209
[email protected]b172aee2012-04-10 17:05:262210void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272211 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212212 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542213 return;
2214 }
[email protected]0b431992014-06-24 00:08:032215 RenderWidgetHostView* const fullscreen_view =
2216 GetFullscreenRenderWidgetHostView();
2217 if (fullscreen_view) {
2218 fullscreen_view->Focus();
2219 return;
2220 }
[email protected]9f76c1e2012-03-05 15:15:582221 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542222}
2223
[email protected]b172aee2012-04-10 17:05:262224bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212225 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542226}
2227
[email protected]b172aee2012-04-10 17:05:262228InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212229 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222230}
2231
[email protected]b172aee2012-04-10 17:05:262232bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162233 // WebKit creates Document object when MIME type is application/xhtml+xml,
2234 // so we also support this MIME type.
2235 return contents_mime_type_ == "text/html" ||
2236 contents_mime_type_ == "text/xml" ||
2237 contents_mime_type_ == "application/xhtml+xml" ||
2238 contents_mime_type_ == "text/plain" ||
2239 contents_mime_type_ == "text/css" ||
2240 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2241}
2242
[email protected]b172aee2012-04-10 17:05:262243void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592244 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162245 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552246 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012247 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142248 return;
[email protected]c7dd2f62011-07-18 15:57:592249 }
2250
2251 Stop();
2252
2253 // Create the save package and possibly prompt the user for the name to save
2254 // the page as. The user prompt is an asynchronous operation that runs on
2255 // another thread.
2256 save_package_ = new SavePackage(this);
2257 save_package_->GetSaveInfo();
2258}
2259
2260// Used in automated testing to bypass prompting the user for file names.
2261// Instead, the names and paths are hard coded rather than running them through
2262// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342263bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2264 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212265 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592266 // Stop the page from navigating.
2267 Stop();
2268
2269 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212270 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592271}
2272
[email protected]3c71576ce2013-07-23 02:00:012273void WebContentsImpl::SaveFrame(const GURL& url,
2274 const Referrer& referrer) {
2275 if (!GetURL().is_valid())
2276 return;
sammc92af61552014-11-19 23:27:402277 if (delegate_ && delegate_->SaveFrame(url, referrer))
2278 return;
2279
[email protected]3c71576ce2013-07-23 02:00:012280 bool is_main_frame = (url == GetURL());
2281
2282 DownloadManager* dlm =
2283 BrowserContext::GetDownloadManager(GetBrowserContext());
2284 if (!dlm)
2285 return;
2286 int64 post_id = -1;
2287 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272288 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012289 if (entry)
2290 post_id = entry->GetPostID();
2291 }
2292 scoped_ptr<DownloadUrlParameters> params(
2293 DownloadUrlParameters::FromWebContents(this, url));
2294 params->set_referrer(referrer);
2295 params->set_post_id(post_id);
2296 params->set_prefer_cache(true);
2297 if (post_id >= 0)
2298 params->set_method("POST");
2299 params->set_prompt(true);
2300 dlm->DownloadUrl(params.Pass());
2301}
2302
[email protected]b172aee2012-04-10 17:05:262303void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342304 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482305 const base::Callback<void(int64)>& callback) {
2306 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122307}
2308
[email protected]b172aee2012-04-10 17:05:262309const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272310 return contents_mime_type_;
2311}
2312
[email protected]b172aee2012-04-10 17:05:262313bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272314 return notify_disconnection_;
2315}
2316
[email protected]b172aee2012-04-10 17:05:262317void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312318 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182319 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162320}
2321
[email protected]b172aee2012-04-10 17:05:262322void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542323 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182324 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162325}
2326
[email protected]8ff00d72012-10-23 19:12:212327RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272328 return &renderer_preferences_;
2329}
2330
[email protected]e35ccd52012-05-23 16:22:472331void WebContentsImpl::Close() {
2332 Close(GetRenderViewHost());
2333}
2334
[email protected]cf200a562013-05-03 16:24:292335void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462336 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292337 if (browser_plugin_embedder_.get())
2338 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2339 screen_x, screen_y, operation);
2340 if (GetRenderViewHost())
2341 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2342 screen_x, screen_y, operation);
2343}
2344
[email protected]d60f3702013-12-26 16:30:242345void WebContentsImpl::DidGetResourceResponseStart(
2346 const ResourceRequestDetails& details) {
2347 controller_.ssl_manager()->DidStartResourceResponse(details);
2348
2349 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2350 DidGetResourceResponseStart(details));
2351
2352 // TODO(avi): Remove. http://crbug.com/170921
2353 NotificationService::current()->Notify(
2354 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2355 Source<WebContents>(this),
2356 Details<const ResourceRequestDetails>(&details));
2357}
2358
2359void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462360 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242361 const ResourceRedirectDetails& details) {
2362 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2363
2364 FOR_EACH_OBSERVER(
2365 WebContentsObserver,
2366 observers_,
creis114ca1b2014-11-13 23:51:462367 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242368
2369 // TODO(avi): Remove. http://crbug.com/170921
2370 NotificationService::current()->Notify(
2371 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2372 Source<WebContents>(this),
2373 Details<const ResourceRedirectDetails>(&details));
2374}
2375
[email protected]b172aee2012-04-10 17:05:262376void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522377 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582378 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512379 if (delegate_)
2380 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292381 if (browser_plugin_embedder_.get())
2382 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342383}
2384
[email protected]e35ccd52012-05-23 16:22:472385void WebContentsImpl::UserGestureDone() {
2386 OnUserGesture();
2387}
2388
[email protected]b172aee2012-04-10 17:05:262389void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272390 closed_by_user_gesture_ = value;
2391}
2392
[email protected]b172aee2012-04-10 17:05:262393bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272394 return closed_by_user_gesture_;
2395}
2396
[email protected]b172aee2012-04-10 17:05:262397void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502398 if (!delegate_)
2399 return;
2400
[email protected]6286a372013-10-09 04:03:272401 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2402 if (!entry)
[email protected]1788e772010-12-15 16:40:502403 return;
2404
[email protected]6286a372013-10-09 04:03:272405 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122406}
2407
[email protected]b172aee2012-04-10 17:05:262408void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042409 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272410 if (!delegate_)
2411 return;
2412
[email protected]691aa2f2013-05-28 22:52:042413 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272414}
2415
[email protected]b172aee2012-04-10 17:05:262416int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272417 return minimum_zoom_percent_;
2418}
2419
[email protected]b172aee2012-04-10 17:05:262420int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272421 return maximum_zoom_percent_;
2422}
2423
[email protected]b172aee2012-04-10 17:05:262424gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492425 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232426}
2427
[email protected]b172aee2012-04-10 17:05:262428bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052429 if (GetBrowserPluginGuest())
2430 return GetBrowserPluginGuest()->LockMouse(allowed);
2431
[email protected]0bfbf882011-12-22 18:19:272432 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582433 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272434}
2435
[email protected]b172aee2012-04-10 17:05:262436bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442437 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502438}
2439
jochen55ff3502014-12-18 20:52:572440WebContents* WebContentsImpl::GetOpener() const {
2441 return static_cast<WebContents*>(opener_);
2442}
2443
[email protected]cb805452013-05-22 15:16:212444void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482445 if (!color_chooser_info_.get())
2446 return;
2447 RenderFrameHost* rfh = RenderFrameHost::FromID(
2448 color_chooser_info_->render_process_id,
2449 color_chooser_info_->render_frame_id);
2450 if (!rfh)
2451 return;
2452
2453 rfh->Send(new FrameMsg_DidChooseColorResponse(
2454 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202455}
2456
[email protected]cb805452013-05-22 15:16:212457void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482458 if (!color_chooser_info_.get())
2459 return;
2460 RenderFrameHost* rfh = RenderFrameHost::FromID(
2461 color_chooser_info_->render_process_id,
2462 color_chooser_info_->render_frame_id);
2463 if (!rfh)
2464 return;
2465
2466 rfh->Send(new FrameMsg_DidEndColorChooser(
2467 rfh->GetRoutingID(), color_chooser_info_->identifier));
2468 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202469}
2470
[email protected]41225fe2013-03-29 05:32:022471int WebContentsImpl::DownloadImage(const GURL& url,
2472 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302473 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022474 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582475 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022476 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392477 return id;
2478}
2479
[email protected]5dcaf8e2013-12-28 01:31:422480bool WebContentsImpl::IsSubframe() const {
2481 return is_subframe_;
2482}
2483
[email protected]36ec24f2014-01-09 00:32:082484void WebContentsImpl::Find(int request_id,
2485 const base::string16& search_text,
2486 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092487 // See if a top level browser plugin handles the find request first.
2488 if (browser_plugin_embedder_ &&
2489 browser_plugin_embedder_->Find(request_id, search_text, options)) {
2490 return;
2491 }
[email protected]36ec24f2014-01-09 00:32:082492 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2493}
2494
2495void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012496 // See if a top level browser plugin handles the stop finding request first.
2497 if (browser_plugin_embedder_ &&
2498 browser_plugin_embedder_->StopFinding(action)) {
2499 return;
2500 }
[email protected]36ec24f2014-01-09 00:32:082501 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2502}
2503
[email protected]4fe53add2014-04-08 19:53:362504void WebContentsImpl::InsertCSS(const std::string& css) {
2505 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2506 GetMainFrame()->GetRoutingID(), css));
2507}
2508
dalecurtisbc6572e12014-09-12 19:22:302509bool WebContentsImpl::WasRecentlyAudible() {
2510 return audio_stream_monitor_.WasRecentlyAudible();
2511}
2512
mlamouriefdca9d2014-09-16 16:55:402513void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2514 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2515}
2516
mlamouri7a78d6fd2015-01-17 13:23:532517void WebContentsImpl::ExitFullscreen() {
2518 // Clean up related state and initiate the fullscreen exit.
2519 GetRenderViewHostImpl()->RejectMouseLockOrUnlockIfNecessary();
2520 ExitFullscreenMode();
2521}
2522
[email protected]b172aee2012-04-10 17:05:262523bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272524 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172525 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332526 return true;
2527 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272528}
2529
[email protected]b172aee2012-04-10 17:05:262530void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272531 if (delegate_)
2532 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212533}
2534
[email protected]52913802013-12-10 05:52:182535void WebContentsImpl::DidStartProvisionalLoad(
2536 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182537 const GURL& validated_url,
2538 bool is_error_page,
2539 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102540 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482541 FOR_EACH_OBSERVER(
2542 WebContentsObserver,
2543 observers_,
2544 DidStartProvisionalLoadForFrame(
2545 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:082546
2547 // Notify accessibility if this is a reload.
2548 NavigationEntry* entry = controller_.GetVisibleEntry();
2549 if (entry && ui::PageTransitionCoreTypeIs(
2550 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
2551 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2552 BrowserAccessibilityManager* manager =
2553 ftn->current_frame_host()->browser_accessibility_manager();
2554 if (manager)
2555 manager->UserIsReloading();
2556 }
[email protected]400992b2012-06-14 00:03:542557}
2558
[email protected]0c3c54f2014-07-31 01:29:002559void WebContentsImpl::DidStartNavigationTransition(
morritaffb82612014-10-31 18:26:592560 RenderFrameHostImpl* render_frame_host) {
[email protected]0c3c54f2014-07-31 01:29:002561#if defined(OS_ANDROID)
2562 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]0e813a52014-08-13 10:34:562563 GetWebContentsAndroid()->DidStartNavigationTransitionForFrame(
morritaffb82612014-10-31 18:26:592564 render_frame_id);
[email protected]0c3c54f2014-07-31 01:29:002565#endif
2566}
2567
[email protected]3109fbb72014-01-06 23:57:152568void WebContentsImpl::DidFailProvisionalLoadWithError(
2569 RenderFrameHostImpl* render_frame_host,
2570 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2571 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312572 FOR_EACH_OBSERVER(WebContentsObserver,
2573 observers_,
2574 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312575 validated_url,
2576 params.error_code,
2577 params.error_description));
dmazzonibf8cec42015-02-08 08:28:082578
2579 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2580 BrowserAccessibilityManager* manager =
2581 ftn->current_frame_host()->browser_accessibility_manager();
2582 if (manager)
2583 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:152584}
2585
[email protected]b80624c2014-02-09 02:46:552586void WebContentsImpl::DidFailLoadWithError(
2587 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552588 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552589 int error_code,
2590 const base::string16& error_description) {
[email protected]3619ca82014-07-09 15:45:142591 FOR_EACH_OBSERVER(
2592 WebContentsObserver,
2593 observers_,
2594 DidFailLoad(render_frame_host, url, error_code, error_description));
[email protected]b80624c2014-02-09 02:46:552595}
2596
[email protected]52913802013-12-10 05:52:182597void WebContentsImpl::NotifyChangedNavigationState(
2598 InvalidateTypes changed_flags) {
2599 NotifyNavigationStateChanged(changed_flags);
2600}
2601
[email protected]3691e5cf2014-01-22 10:16:202602void WebContentsImpl::AboutToNavigateRenderFrame(
pfeldmanf87691a2015-01-23 16:58:172603 RenderFrameHostImpl* old_host,
2604 RenderFrameHostImpl* new_host) {
creis114ca1b2014-11-13 23:51:462605 // Notify observers that we will navigate in this RenderFrame.
[email protected]3691e5cf2014-01-22 10:16:202606 FOR_EACH_OBSERVER(
2607 WebContentsObserver,
2608 observers_,
pfeldmanf87691a2015-01-23 16:58:172609 AboutToNavigateRenderFrame(old_host, new_host));
[email protected]3691e5cf2014-01-22 10:16:202610}
2611
2612void WebContentsImpl::DidStartNavigationToPendingEntry(
2613 RenderFrameHostImpl* render_frame_host,
2614 const GURL& url,
2615 NavigationController::ReloadType reload_type) {
2616 // Notify observers about navigation.
2617 FOR_EACH_OBSERVER(
2618 WebContentsObserver,
2619 observers_,
2620 DidStartNavigationToPendingEntry(url, reload_type));
2621}
2622
[email protected]8cb834e2014-03-06 14:23:232623void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2624 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:502625 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
2626 // weak pointer of sorts.
2627 const int32_t process_id = render_frame_host->GetProcess()->GetID();
2628 const int32_t frame_id = render_frame_host->GetRoutingID();
2629
[email protected]65920f332014-03-04 21:14:182630 WebContents* new_contents = OpenURL(params);
2631
dchengb907f7332015-01-07 20:35:502632 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:182633 // Notify observers.
2634 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2635 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:462636 render_frame_host,
[email protected]65920f332014-03-04 21:14:182637 params.url,
2638 params.referrer,
2639 params.disposition,
creis114ca1b2014-11-13 23:51:462640 params.transition));
[email protected]65920f332014-03-04 21:14:182641 }
2642}
2643
[email protected]aa62afd2014-04-22 19:22:462644bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2645 if (!delegate_)
2646 return false;
2647 return delegate_->ShouldPreserveAbortedURLs(this);
2648}
2649
[email protected]37567b432014-02-12 01:12:222650void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432651 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222652 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352653 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222654 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482655 FOR_EACH_OBSERVER(WebContentsObserver,
2656 observers_,
2657 DidCommitProvisionalLoadForFrame(
2658 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:082659
2660 BrowserAccessibilityManager* manager =
2661 render_frame_host->browser_accessibility_manager();
2662 if (manager)
2663 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:222664}
2665
[email protected]0d0f4c492014-04-02 06:42:572666void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232667 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572668 // Ensure fullscreen mode is exited before committing the navigation to a
2669 // different page. The next page will not start out assuming it is in
2670 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232671 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192672 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572673 return;
2674 }
2675 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:532676 ExitFullscreen();
[email protected]0d0f4c492014-04-02 06:42:572677 DCHECK(!IsFullscreenForCurrentTab());
2678}
2679
[email protected]37567b432014-02-12 01:12:222680void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:282681 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222682 const LoadCommittedDetails& details,
2683 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2684 if (details.is_navigation_to_different_page()) {
2685 // Clear the status bubble. This is a workaround for a bug where WebKit
2686 // doesn't let us know that the cursor left an element during a
2687 // transition (this is also why the mouse cursor remains as a hand after
2688 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2689 // clear the bubble when a user navigates to a named anchor in the same
2690 // page.
sky8b00392d2015-01-10 00:30:282691 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:002692
2693 RenderWidgetHostViewBase* rwhvb =
2694 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2695 if (rwhvb)
2696 rwhvb->OnDidNavigateMainFrameToNewPage();
[email protected]37567b432014-02-12 01:12:222697 }
2698
2699 if (!details.is_in_page) {
2700 // Once the main frame is navigated, we're no longer considered to have
2701 // displayed insecure content.
2702 displayed_insecure_content_ = false;
2703 SSLManager::NotifySSLInternalStateChanged(
2704 GetController().GetBrowserContext());
2705 }
2706
2707 // Notify observers about navigation.
2708 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2709 DidNavigateMainFrame(details, params));
2710
[email protected]e85165c642014-06-10 14:34:312711 if (delegate_)
[email protected]37567b432014-02-12 01:12:222712 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312713 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222714}
2715
2716void WebContentsImpl::DidNavigateAnyFramePostCommit(
2717 RenderFrameHostImpl* render_frame_host,
2718 const LoadCommittedDetails& details,
2719 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102720 // Now that something has committed, we don't need to track whether the
2721 // initial page has been accessed.
2722 has_accessed_initial_document_ = false;
2723
[email protected]37567b432014-02-12 01:12:222724 // If we navigate off the page, close all JavaScript dialogs.
2725 if (dialog_manager_ && !details.is_in_page)
2726 dialog_manager_->CancelActiveAndPendingDialogs(this);
2727
2728 // Notify observers about navigation.
2729 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:092730 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:222731}
2732
2733void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2734 contents_mime_type_ = mime_type;
2735}
2736
[email protected]277857a2014-06-03 10:38:012737bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312738 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052739 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312740 return false;
2741
[email protected]37567b432014-02-12 01:12:222742 if (delegate_)
2743 return delegate_->CanOverscrollContent();
2744
2745 return false;
2746}
2747
[email protected]37b64c52014-07-11 21:14:052748void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
[email protected]e7104762014-06-20 19:17:252749 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]37b64c52014-07-11 21:14:052750 DidChangeThemeColor(theme_color));
[email protected]e7104762014-06-20 19:17:252751}
2752
[email protected]b172aee2012-04-10 17:05:262753void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182754 const GURL& url,
[email protected]70435962011-08-02 20:13:282755 const std::string& security_info,
2756 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182757 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402758 ResourceType resource_type) {
[email protected]724159a2010-12-30 01:11:182759
2760 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082761 int cert_id = 0;
2762 net::CertStatus cert_status = 0;
2763 int security_bits = -1;
2764 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122765 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212766 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122767 &security_bits, &connection_status,
2768 &signed_certificate_timestamp_ids);
2769 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212770 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002771 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2772 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182773
[email protected]b0f724c2013-09-05 04:21:132774 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2775
2776 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2777 DidLoadResourceFromMemoryCache(details));
2778
[email protected]8bfc8272013-09-09 20:10:532779 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2780 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:402781 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:532782 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2783 GetRenderProcessHost()->GetID()) :
2784 GetBrowserContext()->GetRequestContextForRenderProcess(
2785 GetRenderProcessHost()->GetID()));
2786 BrowserThread::PostTask(
2787 BrowserThread::IO,
2788 FROM_HERE,
2789 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2790 }
[email protected]724159a2010-12-30 01:11:182791}
2792
[email protected]b172aee2012-04-10 17:05:262793void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392794 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182795 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192796 SSLManager::NotifySSLInternalStateChanged(
2797 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182798}
2799
[email protected]b172aee2012-04-10 17:05:262800void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022801 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582802 LOG(WARNING) << security_origin << " ran insecure content from "
2803 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392804 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412805 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392806 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182807 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412808 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192809 SSLManager::NotifySSLInternalStateChanged(
2810 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182811}
2812
[email protected]501052ff2014-02-21 22:19:072813void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:112814 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:472815 return;
naskofbd033392015-01-27 02:34:472816
[email protected]1d62cf72014-02-07 21:31:572817 RenderFrameHostImpl* rfh =
2818 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142819 FOR_EACH_OBSERVER(
2820 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:182821}
2822
naskofbd033392015-01-27 02:34:472823void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:112824 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:122825 return;
[email protected]a1b99262013-12-27 21:56:222826
[email protected]8b3af1e2014-01-24 13:29:122827 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442828 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372829 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422830 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372831
[email protected]61ac9e242014-03-21 20:55:262832 RenderFrameHostImpl* rfh =
2833 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:142834 FOR_EACH_OBSERVER(
2835 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:312836}
2837
[email protected]960b0372014-05-19 18:01:002838void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
nasko907fcb62015-01-28 04:24:112839 if (!HasValidFrameSource())
2840 return;
2841
[email protected]960b0372014-05-19 18:01:002842 RenderFrameHostImpl* rfh =
2843 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2844 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2845
creis1163acf2014-12-19 21:18:472846 // Any main frame load to a new document should reset the load progress, since
2847 // it will replace the current page and any frames.
2848 if (to_different_document && !rfh->GetParent()) {
2849 ResetLoadProgressState();
2850 loading_frames_in_progress_ = 0;
naskoa7064ad6e2015-01-15 18:44:562851 rfh->frame_tree_node()->set_is_loading(false);
creis1163acf2014-12-19 21:18:472852 }
2853
[email protected]960b0372014-05-19 18:01:002854 // It is possible to get multiple calls to OnDidStartLoading that don't have
2855 // corresponding calls to OnDidStopLoading:
2856 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2857 // out for a cross-process navigation, and it turns into a placeholder for
2858 // one being rendered in a different process.
2859 // - Also, there might be more than one RenderFrameHost sharing the same
2860 // FrameTreeNode (and thus sharing its ID) each sending a start.
2861 // - But in the future, once clamy@ moves navigation network requests to the
2862 // browser process, there's a good chance that callbacks about starting and
2863 // stopping will all be handled by the browser. When that happens, there
2864 // should no longer be a start/stop call imbalance. TODO(avi): When this
2865 // future arrives, update this code to not allow this case.
naskoa7064ad6e2015-01-15 18:44:562866 if (rfh->frame_tree_node()->is_loading())
2867 return;
2868
[email protected]960b0372014-05-19 18:01:002869 DCHECK_GE(loading_frames_in_progress_, 0);
naskoa7064ad6e2015-01-15 18:44:562870 if (loading_frames_in_progress_ == 0)
2871 DidStartLoading(rfh, to_different_document);
2872
2873 ++loading_frames_in_progress_;
2874 rfh->frame_tree_node()->set_is_loading(true);
[email protected]960b0372014-05-19 18:01:002875
nasko3e8c20e2014-12-18 06:54:562876 // Notify the RenderFrameHostManager of the event.
2877 rfh->frame_tree_node()->render_manager()->OnDidStartLoading();
2878
[email protected]960b0372014-05-19 18:01:002879 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2880 SendLoadProgressChanged();
2881}
2882
2883void WebContentsImpl::OnDidStopLoading() {
nasko907fcb62015-01-28 04:24:112884 if (!HasValidFrameSource())
2885 return;
2886
[email protected]960b0372014-05-19 18:01:002887 RenderFrameHostImpl* rfh =
2888 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2889 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
naskoa7064ad6e2015-01-15 18:44:562890 rfh->frame_tree_node()->set_is_loading(false);
[email protected]960b0372014-05-19 18:01:002891
2892 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2893 // Load stopped while we were still tracking load. Make sure we update
2894 // progress based on this frame's completion.
2895 loading_progresses_[render_frame_id] = 1.0;
2896 SendLoadProgressChanged();
2897 // Then we clean-up our states.
2898 if (loading_total_progress_ == 1.0)
2899 ResetLoadProgressState();
2900 }
2901
nasko3e8c20e2014-12-18 06:54:562902 // Notify the RenderFrameHostManager of the event.
2903 rfh->frame_tree_node()->render_manager()->OnDidStopLoading();
2904
[email protected]960b0372014-05-19 18:01:002905 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2906 // calls DidStopLoading() without a matching DidStartLoading().
2907 if (loading_frames_in_progress_ == 0)
2908 return;
2909 --loading_frames_in_progress_;
2910 if (loading_frames_in_progress_ == 0)
2911 DidStopLoading(rfh);
2912}
2913
2914void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
nasko907fcb62015-01-28 04:24:112915 if (!HasValidFrameSource())
2916 return;
2917
[email protected]960b0372014-05-19 18:01:002918 RenderFrameHostImpl* rfh =
2919 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2920 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2921
2922 loading_progresses_[render_frame_id] = load_progress;
2923
2924 // We notify progress change immediately for the first and last updates.
2925 // Also, since the message loop may be pretty busy when a page is loaded, it
2926 // might not execute a posted task in a timely manner so we make sure to
2927 // immediately send progress report if enough time has passed.
2928 base::TimeDelta min_delay =
2929 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2930 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2931 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2932 // If there is a pending task to send progress, it is now obsolete.
2933 loading_weak_factory_.InvalidateWeakPtrs();
2934 SendLoadProgressChanged();
2935 if (loading_total_progress_ == 1.0)
2936 ResetLoadProgressState();
2937 return;
2938 }
2939
2940 if (loading_weak_factory_.HasWeakPtrs())
2941 return;
2942
2943 base::MessageLoop::current()->PostDelayedTask(
2944 FROM_HERE,
2945 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2946 loading_weak_factory_.GetWeakPtr()),
2947 min_delay);
2948}
2949
[email protected]b172aee2012-04-10 17:05:262950void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222951 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2952 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262953}
2954
[email protected]b172aee2012-04-10 17:05:262955void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302956 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262957 minimum_zoom_percent_ = minimum_percent;
2958 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262959}
2960
[email protected]b172aee2012-04-10 17:05:262961void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342962 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432963 if (!delegate_)
2964 return;
2965
[email protected]b9535422012-02-09 01:47:592966 ChildProcessSecurityPolicyImpl* policy =
2967 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222968 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592969 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212970}
2971
[email protected]b172aee2012-04-10 17:05:262972void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2973 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262974 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362975 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432976 if (!delegate_)
2977 return;
2978
[email protected]b9535422012-02-09 01:47:592979 ChildProcessSecurityPolicyImpl* policy =
2980 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322981 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592982 return;
[email protected]8f810632013-06-06 22:33:322983
[email protected]c125e532014-05-10 20:39:062984 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202985}
2986
[email protected]f5273e52014-07-14 16:30:202987void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
2988 const GURL& url,
2989 bool user_gesture) {
2990 if (!delegate_)
2991 return;
2992
2993 ChildProcessSecurityPolicyImpl* policy =
2994 ChildProcessSecurityPolicyImpl::GetInstance();
2995 if (policy->IsPseudoScheme(protocol))
2996 return;
2997
2998 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
2999}
3000
[email protected]b172aee2012-04-10 17:05:263001void WebContentsImpl::OnFindReply(int request_id,
3002 int number_of_matches,
3003 const gfx::Rect& selection_rect,
3004 int active_match_ordinal,
3005 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433006 if (delegate_) {
3007 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3008 active_match_ordinal, final_update);
3009 }
[email protected]b888919c2011-09-02 00:32:163010}
3011
[email protected]59363fc92012-09-05 03:46:313012#if defined(OS_ANDROID)
3013void WebContentsImpl::OnFindMatchRectsReply(
3014 int version,
3015 const std::vector<gfx::RectF>& rects,
3016 const gfx::RectF& active_rect) {
3017 if (delegate_)
3018 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3019}
[email protected]583418cc2013-01-17 14:01:103020
[email protected]1ff427972013-02-07 21:14:073021void WebContentsImpl::OnOpenDateTimeDialog(
3022 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173023 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093024 GetRenderViewHost(),
3025 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133026 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093027 value.minimum,
3028 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173029 value.step,
3030 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103031}
[email protected]59363fc92012-09-05 03:46:313032#endif
3033
[email protected]cfa856d62014-02-22 07:58:403034void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
3035 int automation_id) {
3036 DomOperationNotificationDetails details(json_string, automation_id);
3037 NotificationService::current()->Notify(
3038 NOTIFICATION_DOM_OPERATION_RESPONSE,
3039 Source<WebContents>(this),
3040 Details<DomOperationNotificationDetails>(&details));
3041}
3042
[email protected]b172aee2012-04-10 17:05:263043void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3044 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103045 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253046 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103047 AppCacheAccessed(manifest_url, blocked_by_policy));
3048}
3049
[email protected]8bc5ff02013-11-29 06:34:033050void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483051 int color_chooser_id,
3052 SkColor color,
3053 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113054 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003055 return;
nasko907fcb62015-01-28 04:24:113056
[email protected]aa62afd2014-04-22 19:22:463057 ColorChooser* new_color_chooser = delegate_ ?
3058 delegate_->OpenColorChooser(this, color, suggestions) :
3059 NULL;
[email protected]820957a2014-01-14 14:56:303060 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213061 return;
[email protected]8ed16472014-04-11 19:02:483062 if (color_chooser_info_.get())
3063 color_chooser_info_->chooser->End();
3064
3065 color_chooser_info_.reset(new ColorChooserInfo(
3066 render_frame_message_source_->GetProcess()->GetID(),
3067 render_frame_message_source_->GetRoutingID(),
3068 new_color_chooser,
3069 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203070}
3071
[email protected]b172aee2012-04-10 17:05:263072void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483073 if (color_chooser_info_ &&
3074 color_chooser_id == color_chooser_info_->identifier)
3075 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203076}
3077
[email protected]b172aee2012-04-10 17:05:263078void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323079 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483080 if (color_chooser_info_ &&
3081 color_chooser_id == color_chooser_info_->identifier)
3082 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203083}
3084
[email protected]d0759f492012-04-19 22:50:503085// This exists for render views that don't have a WebUI, but do have WebUI
3086// bindings enabled.
3087void WebContentsImpl::OnWebUISend(const GURL& source_url,
3088 const std::string& name,
3089 const base::ListValue& args) {
3090 if (delegate_)
3091 delegate_->WebUISend(this, source_url, name, args);
3092}
3093
thestigc4cac8f2014-09-04 21:17:503094#if defined(ENABLE_PLUGINS)
tommyclie6633ca72014-10-31 00:40:423095void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3096 const base::FilePath& path,
3097 bool is_hung) {
3098 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3099
3100 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3101 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3102}
3103
3104void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3105 base::ProcessId plugin_pid) {
3106 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3107 PluginCrashed(plugin_path, plugin_pid));
3108}
3109
[email protected]d8415ad92012-08-23 14:40:503110void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443111 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503112 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343113 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163114 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443115 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163116 return;
[email protected]d8415ad92012-08-23 14:40:503117 }
3118
[email protected]8c8fc292012-11-23 18:57:163119 if (!delegate_->RequestPpapiBrokerPermission(
3120 this, url, plugin_path,
3121 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443122 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163123 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443124 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163125 }
[email protected]d8415ad92012-08-23 14:40:503126}
3127
[email protected]ea0309c2013-08-06 19:35:443128void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503129 bool result) {
[email protected]ea0309c2013-08-06 19:35:443130 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503131}
3132
fsamuel833ee7c2015-02-13 23:40:403133void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3134 const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:373135 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:083136 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:553137 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:393138 // For more info, see comment above classes BrowserPluginEmbedder and
3139 // BrowserPluginGuest.
3140 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:143141 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
fsamuel833ee7c2015-02-13 23:40:403142 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373143}
tommyclie6633ca72014-10-31 00:40:423144#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373145
[email protected]41225fe2013-03-29 05:32:023146void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:393147 int id,
[email protected]749fadd2013-05-15 08:37:483148 int http_status_code,
[email protected]795c28972012-12-06 06:13:393149 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:303150 const std::vector<SkBitmap>& bitmaps,
3151 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:133152 if (bitmaps.size() != original_bitmap_sizes.size())
3153 return;
3154
[email protected]41225fe2013-03-29 05:32:023155 ImageDownloadMap::iterator iter = image_download_map_.find(id);
3156 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:393157 // Currently WebContents notifies us of ANY downloads so that it is
3158 // possible to get here.
3159 return;
3160 }
3161 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:303162 iter->second.Run(
3163 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:393164 }
[email protected]41225fe2013-03-29 05:32:023165 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:393166}
3167
3168void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393169 const std::vector<FaviconURL>& candidates) {
3170 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293171 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393172}
3173
dalecurtisbc6572e12014-09-12 19:22:303174void WebContentsImpl::CreateAudioPowerSaveBlocker() {
dalecurtisbc6572e12014-09-12 19:22:303175 DCHECK(!audio_power_save_blocker_);
3176 audio_power_save_blocker_ = PowerSaveBlocker::Create(
deratf3c302a2015-02-23 18:33:033177 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
3178 PowerSaveBlocker::kReasonAudioPlayback, "Playing audio");
dalecurtisbc6572e12014-09-12 19:22:303179}
3180
3181void WebContentsImpl::CreateVideoPowerSaveBlocker() {
dalecurtisbc6572e12014-09-12 19:22:303182 DCHECK(!video_power_save_blocker_);
3183 DCHECK(!active_video_players_.empty());
3184 video_power_save_blocker_ = PowerSaveBlocker::Create(
deratf3c302a2015-02-23 18:33:033185 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
3186 PowerSaveBlocker::kReasonVideoPlayback, "Playing video");
dalecurtisbc6572e12014-09-12 19:22:303187#if defined(OS_ANDROID)
3188 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
3189 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
3190#endif
dalecurtisbc6572e12014-09-12 19:22:303191}
3192
3193void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3194 // If there are no more audio players and we don't have audio stream
3195 // monitoring, release the audio power save blocker here instead of during
3196 // NotifyNavigationStateChanged().
3197 if (active_audio_players_.empty() &&
3198 !AudioStreamMonitor::monitoring_available()) {
3199 audio_power_save_blocker_.reset();
3200 }
3201
3202 // If there are no more video players, clear the video power save blocker.
3203 if (active_video_players_.empty())
3204 video_power_save_blocker_.reset();
3205}
3206
[email protected]1dd0bb752014-02-01 01:16:263207void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3208 bool has_video,
avayvod68017be2014-10-10 18:02:433209 bool has_audio,
3210 bool is_remote) {
3211 // Ignore the videos playing remotely and don't hold the wake lock for the
3212 // screen.
3213 if (is_remote) return;
3214
dalecurtisbc6572e12014-09-12 19:22:303215 if (has_audio) {
3216 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3217
3218 // If we don't have audio stream monitoring, allocate the audio power save
3219 // blocker here instead of during NotifyNavigationStateChanged().
3220 if (!audio_power_save_blocker_ &&
3221 !AudioStreamMonitor::monitoring_available()) {
3222 CreateAudioPowerSaveBlocker();
3223 }
[email protected]1dd0bb752014-02-01 01:16:263224 }
loislo0381a742014-09-11 10:58:113225
dalecurtisbc6572e12014-09-12 19:22:303226 if (has_video) {
3227 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3228
3229 // If we're not hidden and have just created a player, create a blocker.
3230 if (!video_power_save_blocker_ && !IsHidden())
3231 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113232 }
[email protected]1dd0bb752014-02-01 01:16:263233}
3234
3235void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303236 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3237 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3238 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:063239}
3240
[email protected]50279492014-05-05 23:24:293241void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153242 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293243 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:153244}
[email protected]d9030b82013-07-19 08:26:063245
[email protected]e67ebf32013-02-13 11:07:193246void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:073247 if (delegate_)
3248 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:193249}
3250
[email protected]17e286e2013-03-01 23:29:393251void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3252 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3253 BeforeFormRepostWarningShow());
3254}
3255
[email protected]ec6c05f2013-10-23 18:41:573256void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3257 Activate();
3258 if (delegate_)
3259 delegate_->ShowRepostFormWarningDialog(this);
3260}
3261
[email protected]b4c84012014-04-28 19:51:103262bool WebContentsImpl::HasAccessedInitialDocument() {
3263 return has_accessed_initial_document_;
3264}
3265
[email protected]96d185d2009-04-24 03:28:543266// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593267// loading, or done loading.
3268void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
3269 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093270 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263271 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543272 if (is_loading == is_loading_)
3273 return;
3274
3275 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263276 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3277 base::string16());
[email protected]96d185d2009-04-24 03:28:543278 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563279 upload_size_ = 0;
3280 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543281 }
3282
[email protected]fa944cb82013-11-15 17:51:213283 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543284
3285 is_loading_ = is_loading;
3286 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033287 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543288
[email protected]6ebdc9b2010-09-27 16:55:573289 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093290 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213291 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543292
[email protected]eab61442013-11-14 18:35:483293 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593294 if (is_loading) {
naskob8744d22014-08-28 17:07:433295 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3296 this, "URL", url);
[email protected]91621872013-10-08 04:04:593297 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3298 DidStartLoading(render_view_host));
3299 } else {
naskob8744d22014-08-28 17:07:433300 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3301 this, "URL", url);
[email protected]91621872013-10-08 04:04:593302 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3303 DidStopLoading(render_view_host));
3304 }
[email protected]66798902013-10-01 18:40:163305
3306 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213307 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3308 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543309 if (details)
[email protected]8ff00d72012-10-23 19:12:213310 det = Details<LoadNotificationDetails>(details);
3311 NotificationService::current()->Notify(
3312 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543313}
3314
christiankaeed9862014-11-05 10:49:143315void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
3316 RenderFrameHost* focused_frame = GetFocusedFrame();
3317 if (!focused_frame)
3318 return;
3319
3320 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
3321 focused_frame->GetRoutingID(), extent));
3322}
3323
3324void WebContentsImpl::SelectRange(const gfx::Point& base,
3325 const gfx::Point& extent) {
[email protected]959be4c2014-04-08 15:01:333326 RenderFrameHost* focused_frame = GetFocusedFrame();
3327 if (!focused_frame)
3328 return;
3329
3330 focused_frame->Send(
christiankaeed9862014-11-05 10:49:143331 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
[email protected]959be4c2014-04-08 15:01:333332}
3333
[email protected]b172aee2012-04-10 17:05:263334void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463335 // If we are creating a RVH for a restored controller, then we need to make
3336 // sure the RenderView starts with a next_page_id_ larger than the number
3337 // of restored entries. This must be called before the RenderView starts
3338 // navigating (to avoid a race between the browser updating max_page_id and
3339 // the renderer updating next_page_id_). Because of this, we only call this
3340 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563341 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583342 if (max_restored_page_id >
3343 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3344 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3345 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323346}
3347
[email protected]b172aee2012-04-10 17:05:263348bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263349 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323350 // For file URLs without a title, use the pathname instead. In the case of a
3351 // synthesized title, we don't want the update to count toward the "one set
3352 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263353 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323354 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513355 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243356 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323357 explicit_set = false; // Don't count synthetic titles toward the set limit.
3358 } else {
[email protected]8af69c6c2014-03-03 19:05:313359 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323360 explicit_set = true;
3361 }
3362
[email protected]987fc3a2011-05-26 14:18:093363 // If a page is created via window.open and never navigated,
3364 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553365 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093366 if (entry) {
[email protected]36fc0392011-12-25 03:59:513367 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093368 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323369
[email protected]36fc0392011-12-25 03:59:513370 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093371 } else {
3372 if (page_title_when_no_navigation_entry_ == final_title)
3373 return false; // Nothing changed, don't bother.
3374
3375 page_title_when_no_navigation_entry_ = final_title;
3376 }
[email protected]420ae012009-04-24 05:16:323377
[email protected]420ae012009-04-24 05:16:323378 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233379 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323380
[email protected]66798902013-10-01 18:40:163381 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533382 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163383
3384 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213385 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463386 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213387 NotificationService::current()->Notify(
3388 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3389 Source<WebContents>(this),
3390 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043391
[email protected]420ae012009-04-24 05:16:323392 return true;
3393}
3394
[email protected]960b0372014-05-19 18:01:003395void WebContentsImpl::SendLoadProgressChanged() {
3396 loading_last_progress_update_ = base::TimeTicks::Now();
3397 double progress = 0.0;
3398 int frame_count = 0;
3399
3400 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3401 it != loading_progresses_.end();
3402 ++it) {
3403 progress += it->second;
3404 ++frame_count;
3405 }
3406 if (frame_count == 0)
3407 return;
3408 progress /= frame_count;
3409 DCHECK(progress <= 1.0);
3410
3411 if (progress <= loading_total_progress_)
3412 return;
3413 loading_total_progress_ = progress;
3414
3415 if (delegate_)
3416 delegate_->LoadProgressChanged(this, progress);
3417}
3418
3419void WebContentsImpl::ResetLoadProgressState() {
3420 loading_progresses_.clear();
3421 loading_total_progress_ = 0.0;
3422 loading_weak_factory_.InvalidateWeakPtrs();
3423 loading_last_progress_update_ = base::TimeTicks();
3424}
3425
[email protected]02d7b6e2014-06-24 21:01:503426void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3427 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323428 // After sending out a swap notification, we need to send a disconnect
3429 // notification so that clients that pick up a pointer to |this| can NULL the
3430 // pointer. See Bug 1230284.
3431 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113432 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283433 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113434
3435 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283436 std::pair<RenderViewHost*, RenderViewHost*> details =
3437 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213438 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283439 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213440 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283441 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393442
3443 // Ensure that the associated embedder gets cleared after a RenderViewHost
3444 // gets swapped, so we don't reuse the same embedder next time a
3445 // RenderViewHost is attached to this WebContents.
3446 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323447}
3448
[email protected]02d7b6e2014-06-24 21:01:503449void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3450 RenderFrameHost* new_host) {
3451 FOR_EACH_OBSERVER(WebContentsObserver,
3452 observers_,
3453 RenderFrameHostChanged(old_host, new_host));
3454}
3455
[email protected]da7a7182013-09-06 08:11:113456// TODO(avi): Remove this entire function because this notification is already
3457// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263458void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323459 if (!notify_disconnection_)
3460 return;
3461
3462 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213463 NotificationService::current()->Notify(
3464 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3465 Source<WebContents>(this),
3466 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323467}
3468
[email protected]cbb1ef592013-06-05 19:49:463469void WebContentsImpl::NotifyNavigationEntryCommitted(
3470 const LoadCommittedDetails& load_details) {
3471 FOR_EACH_OBSERVER(
3472 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3473}
3474
[email protected]f114fa42013-12-06 17:06:443475bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3476 const IPC::Message& message) {
3477 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313478}
3479
[email protected]c31a84802014-04-03 15:55:493480const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3481 return GetLastCommittedURL();
3482}
3483
[email protected]b849847b2013-12-10 21:57:583484void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3485 // Note this is only for subframes, the notification for the main frame
3486 // happens in RenderViewCreated.
3487 FOR_EACH_OBSERVER(WebContentsObserver,
3488 observers_,
3489 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303490 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583491}
3492
3493void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193494 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583495 FOR_EACH_OBSERVER(WebContentsObserver,
3496 observers_,
3497 RenderFrameDeleted(render_frame_host));
3498}
3499
[email protected]a09d53ce2014-01-31 00:46:423500void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303501 if (delegate_)
3502 delegate_->WorkerCrashed(this);
3503}
3504
[email protected]a09d53ce2014-01-31 00:46:423505void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3506 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103507 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423508 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103509 if (GetBrowserPluginGuest()) {
3510 WebContentsViewGuest* view_guest =
3511 static_cast<WebContentsViewGuest*>(GetView());
3512 context_menu_params = view_guest->ConvertContextMenuParams(params);
3513 }
3514 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423515 return;
3516
[email protected]077e704b2014-05-23 19:24:103517 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3518 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423519}
3520
[email protected]87de04b02014-04-08 22:14:493521void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013522 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493523 const base::string16& message,
3524 const base::string16& default_prompt,
3525 const GURL& frame_url,
3526 JavaScriptMessageType javascript_message_type,
3527 IPC::Message* reply_msg) {
3528 // Suppress JavaScript dialogs when requested. Also suppress messages when
3529 // showing an interstitial as it's shown over the previous page and we don't
3530 // want the hidden page's dialogs to interfere with the interstitial.
3531 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223532 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503533 ShowingInterstitialPage() || !delegate_ ||
3534 delegate_->ShouldSuppressDialogs(this) ||
3535 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493536
3537 if (!suppress_this_message) {
3538 std::string accept_lang = GetContentClient()->browser()->
3539 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503540 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493541 dialog_manager_->RunJavaScriptDialog(
3542 this,
3543 frame_url.GetOrigin(),
3544 accept_lang,
3545 javascript_message_type,
3546 message,
3547 default_prompt,
3548 base::Bind(&WebContentsImpl::OnDialogClosed,
3549 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013550 render_frame_host->GetProcess()->GetID(),
3551 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493552 reply_msg,
3553 false),
3554 &suppress_this_message);
3555 }
3556
3557 if (suppress_this_message) {
3558 // If we are suppressing messages, just reply as if the user immediately
3559 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013560 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3561 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283562 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493563 }
3564
3565 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3566 // http://crbug.com/288961 ). The only safe thing to do here is return.
3567}
3568
3569void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013570 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493571 const base::string16& message,
3572 bool is_reload,
3573 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013574 RenderFrameHostImpl* rfhi =
3575 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493576 if (delegate_)
3577 delegate_->WillRunBeforeUnloadConfirm();
3578
3579 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503580 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT || !delegate_ ||
3581 delegate_->ShouldSuppressDialogs(this) ||
3582 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493583 if (suppress_this_message) {
3584 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3585 return;
3586 }
3587
3588 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503589 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493590 dialog_manager_->RunBeforeUnloadDialog(
3591 this, message, is_reload,
3592 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013593 render_frame_host->GetProcess()->GetID(),
3594 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283595 false));
[email protected]87de04b02014-04-08 22:14:493596}
3597
[email protected]a86c0e962013-12-17 17:10:393598WebContents* WebContentsImpl::GetAsWebContents() {
3599 return this;
3600}
3601
[email protected]7912e822014-04-16 02:37:033602bool WebContentsImpl::IsNeverVisible() {
3603 if (!delegate_)
3604 return false;
3605 return delegate_->IsNeverVisible(this);
3606}
3607
[email protected]95640212014-07-26 18:14:303608#if defined(OS_WIN)
3609gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3610 return accessible_parent_;
3611}
3612#endif
3613
[email protected]5a3bdf52012-05-24 15:12:573614RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3615 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323616}
3617
[email protected]8ff00d72012-10-23 19:12:213618RendererPreferences WebContentsImpl::GetRendererPrefs(
3619 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463620 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513621}
3622
[email protected]b172aee2012-04-10 17:05:263623gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173624 if (delegate_)
3625 return delegate_->GetRootWindowResizerRect();
3626 return gfx::Rect();
3627}
3628
[email protected]7a846df2012-09-20 19:17:393629void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273630 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393631 browser_plugin_embedder_.reset();
3632}
3633
[email protected]b172aee2012-04-10 17:05:263634void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443635 // Don't send notifications if we are just creating a swapped-out RVH for
3636 // the opener chain. These won't be used for view-source or WebUI, so it's
3637 // ok to return early.
creiscce56cd2014-09-29 22:45:223638 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443639 return;
3640
[email protected]86f98a22013-03-20 14:35:003641 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313642 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083643
[email protected]8ff00d72012-10-23 19:12:213644 NotificationService::current()->Notify(
3645 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3646 Source<WebContents>(this),
3647 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323648
3649 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353650 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213651 if (GetRenderManager()->pending_web_ui())
3652 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323653
[email protected]6286a372013-10-09 04:03:273654 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333655 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323656 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183657 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583658 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323659 }
[email protected]0666aef2009-05-13 19:48:083660
[email protected]60780f412013-02-25 16:34:103661 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263662
3663 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253664 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583665
3666 // We tell the observers now instead of when the main RenderFrameHostImpl is
3667 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3668 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363669 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583670 FOR_EACH_OBSERVER(
3671 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]95640212014-07-26 18:14:303672 SetAccessibilityModeOnFrame(accessibility_mode_, main_frame);
dgozman24bfc912014-09-29 11:04:183673
3674 DevToolsManager::GetInstance()->RenderViewCreated(this, render_view_host);
[email protected]420ae012009-04-24 05:16:323675}
3676
[email protected]b172aee2012-04-10 17:05:263677void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523678 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323679 // Don't notify the world, since this came from a renderer in the
3680 // background.
3681 return;
3682 }
3683
[email protected]da7a7182013-09-06 08:11:113684 notify_disconnection_ = true;
3685 // TODO(avi): Remove. http://crbug.com/170921
3686 NotificationService::current()->Notify(
3687 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3688 Source<WebContents>(this),
3689 NotificationService::NoDetails());
3690
[email protected]be1f56ab2011-12-22 06:55:313691 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233692 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303693
3694 // Restore the focus to the tab (otherwise the focus will be on the top
3695 // window).
[email protected]484ae5912010-09-29 19:16:143696 if (was_crashed && !FocusLocationBarByDefault() &&
3697 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063698 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143699 }
[email protected]32ded2212011-11-10 18:51:433700
[email protected]d8c660432011-12-22 20:51:253701 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323702}
3703
[email protected]ec6a7eb2013-04-22 17:34:223704void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3705 base::TerminationStatus status,
3706 int error_code) {
dalecurtis8fc7b4dd2015-02-06 01:05:333707 // TODO(nasko): This isn't ideal; the termination process should be handled by
3708 // RenderFrameDeleted(). See http://crbug.com/455943.
3709 ClearPowerSaveBlockers(rvh->GetMainFrame());
3710
[email protected]151a63d2011-12-20 22:32:523711 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323712 // The pending page's RenderViewHost is gone.
3713 return;
3714 }
3715
[email protected]2fcdcc32014-03-05 02:14:073716 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3717 // renderer may not have made a clean exit.
3718 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:533719 ExitFullscreenMode();
[email protected]2fcdcc32014-03-05 02:14:073720
[email protected]698191dc2014-02-25 01:06:133721 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3722 if (dialog_manager_)
3723 dialog_manager_->CancelActiveAndPendingDialogs(this);
3724
[email protected]f738bdcb2014-07-11 20:40:443725 if (delegate_)
3726 delegate_->HideValidationMessage(this);
3727
[email protected]e3b10d12014-03-28 16:06:093728 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323729 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233730 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453731
[email protected]960b0372014-05-19 18:01:003732 // Reset the loading progress. TODO(avi): What does it mean to have a
3733 // "renderer crash" when there is more than one renderer process serving a
3734 // webpage? Once this function is called at a more granular frame level, we
3735 // probably will need to more granularly reset the state here.
3736 ResetLoadProgressState();
3737 loading_frames_in_progress_ = 0;
3738
[email protected]d8c660432011-12-22 20:51:253739 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273740 observers_,
[email protected]58d5cfe2013-07-10 02:40:523741 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323742}
3743
[email protected]b172aee2012-04-10 17:05:263744void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253745 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063746}
3747
[email protected]b172aee2012-04-10 17:05:263748void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3749 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043750 const PageState& page_state) {
creise1d3e5b2014-12-01 18:21:573751 // Ensure that this state update comes from a RenderViewHost that belongs to
3752 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413753 // TODO(nasko): This should go through RenderFrameHost.
3754 // TODO(creis): We can't update state for cross-process subframes until we
3755 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
creise1d3e5b2014-12-01 18:21:573756 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413757 return;
[email protected]420ae012009-04-24 05:16:323758
3759 // We must be prepared to handle state updates for any page, these occur
3760 // when the user is scrolling and entering form data, as well as when we're
3761 // leaving a page, in which case our state may have already been moved to
3762 // the next page. The navigation controller will look up the appropriate
3763 // NavigationEntry and update it when it is notified via the delegate.
3764
3765 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583766 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323767 if (entry_index < 0)
3768 return;
[email protected]10f417c52011-12-28 21:04:233769 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323770
[email protected]691aa2f2013-05-28 22:52:043771 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323772 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043773 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323774 controller_.NotifyEntryChanged(entry, entry_index);
3775}
3776
sky8b00392d2015-01-10 00:30:283777void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
3778 const GURL& url) {
3779 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
3780 // If we're fullscreen only update the url if it's from the fullscreen
3781 // renderer.
3782 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
3783 if (fs && fs->GetRenderWidgetHost() != render_view_host)
3784 return;
3785 }
[email protected]6934a702011-12-20 00:04:513786 if (delegate_)
avi450ce00e2014-09-24 01:58:523787 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323788}
3789
[email protected]b172aee2012-04-10 17:05:263790void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103791#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293792 // The UI may be in an event-tracking loop, such as between the
3793 // mouse-down and mouse-up in text selection or a button click.
3794 // Defer the close until after tracking is complete, so that we
3795 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293796 // TODO(shess): This could get more fine-grained. For instance,
3797 // closing a tab in another window while selecting text in the
3798 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103799 if (view_->IsEventTracking()) {
3800 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293801 return;
3802 }
[email protected]60780f412013-02-25 16:34:103803#endif
[email protected]07707302009-11-06 00:50:293804
[email protected]420ae012009-04-24 05:16:323805 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523806 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513807 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323808}
3809
[email protected]66bbadaf2014-03-28 16:25:543810void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573811 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3812 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573813}
3814
[email protected]6f2ac772014-07-24 22:22:083815void WebContentsImpl::DidDeferAfterResponseStarted(
[email protected]9e6bea412014-08-08 06:35:253816 const TransitionLayerData& transition_data) {
[email protected]23f41fd2014-06-21 05:29:173817#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563818 GetWebContentsAndroid()->DidDeferAfterResponseStarted(transition_data);
[email protected]23f41fd2014-06-21 05:29:173819#endif
3820}
3821
3822bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3823#if defined(OS_ANDROID)
[email protected]0e813a52014-08-13 10:34:563824 return GetWebContentsAndroid()->WillHandleDeferAfterResponseStarted();
[email protected]23f41fd2014-06-21 05:29:173825#else
3826 return false;
3827#endif
3828}
3829
[email protected]b172aee2012-04-10 17:05:263830void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513831 if (delegate_ && delegate_->IsPopupOrPanel(this))
3832 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323833}
3834
[email protected]e3b10d12014-03-28 16:06:093835void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3836 bool to_different_document) {
3837 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3838 to_different_document, NULL);
dmazzonibf8cec42015-02-08 08:28:083839
3840 // Notify accessibility that the user is navigating away from the
3841 // current document.
3842 //
3843 // TODO(dmazzoni): do this using a WebContentsObserver.
3844 FrameTreeNode* ftn = static_cast<RenderFrameHostImpl*>(render_frame_host)->
3845 frame_tree_node();
3846 BrowserAccessibilityManager* manager =
3847 ftn->current_frame_host()->browser_accessibility_manager();
3848 if (manager)
3849 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:323850}
3851
[email protected]723971b2014-02-12 11:08:253852void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323853 scoped_ptr<LoadNotificationDetails> details;
3854
[email protected]9595fd82013-04-19 21:28:493855 // Use the last committed entry rather than the active one, in case a
3856 // pending entry has been created.
3857 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203858 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493859
[email protected]420ae012009-04-24 05:16:323860 // An entry may not exist for a stop when loading an initial blank page or
3861 // if an iframe injected by script into a blank page finishes loading.
3862 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203863 base::TimeDelta elapsed =
3864 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323865
3866 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513867 entry->GetVirtualURL(),
3868 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323869 elapsed,
3870 &controller_,
3871 controller_.GetCurrentEntryIndex()));
3872 }
3873
[email protected]e3b10d12014-03-28 16:06:093874 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3875 details.get());
[email protected]420ae012009-04-24 05:16:323876}
3877
[email protected]b172aee2012-04-10 17:05:263878void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163879 controller_.DiscardNonCommittedEntries();
3880
3881 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213882 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163883}
3884
[email protected]59167c22013-06-03 18:07:323885void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103886 has_accessed_initial_document_ = true;
3887
[email protected]d1371bf8e2014-04-19 03:26:243888 // We may have left a failed browser-initiated navigation in the address bar
3889 // to let the user edit it and try again. Clear it now that content might
3890 // show up underneath it.
3891 if (!IsLoading() && controller_.GetPendingEntry())
3892 controller_.DiscardPendingEntry();
3893
[email protected]59167c22013-06-03 18:07:323894 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503895 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323896}
3897
[email protected]3f19f1a2014-05-02 05:23:273898void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
[email protected]eaece5472014-08-22 23:36:473899 // No action is necessary if the opener has already been cleared.
3900 if (!opener_)
3901 return;
3902
3903 // Clear our opener so that future cross-process navigations don't have an
3904 // opener assigned.
3905 RemoveDestructionObserver(opener_);
3906 opener_ = NULL;
[email protected]3f19f1a2014-05-02 05:23:273907
3908 // Notify all swapped out RenderViewHosts for this tab. This is important
3909 // in case we go back to them, or if another window in those processes tries
3910 // to access window.opener.
creisbbbeb062014-08-25 18:20:313911 GetRenderManager()->DidDisownOpener(render_frame_host);
[email protected]3f19f1a2014-05-02 05:23:273912}
3913
[email protected]39f2f9252014-05-03 00:54:013914void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293915 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093916 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293917 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093918
3919 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213920 NotificationService::current()->Notify(
3921 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3922 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293923 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083924}
3925
[email protected]ef3adfc2014-05-11 00:04:543926void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3927 int32 page_id,
3928 const base::string16& title,
3929 base::i18n::TextDirection title_direction) {
3930 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3931
3932 // If we have a title, that's a pretty good indication that we've started
3933 // getting useful data.
3934 SetNotWaitingForResponse();
3935
3936 // Try to find the navigation entry, which might not be the current one.
3937 // For example, it might be from a pending RVH for the pending entry.
3938 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3939 rvh->GetSiteInstance(), page_id);
3940
3941 // We can handle title updates when we don't have an entry in
3942 // UpdateTitleForEntry, but only if the update is from the current RVH.
3943 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3944 if (!entry && rvh != GetRenderViewHost())
3945 return;
3946
3947 // TODO(evan): make use of title_direction.
3948 // http://code.google.com/p/chromium/issues/detail?id=27094
3949 if (!UpdateTitleForEntry(entry, title))
3950 return;
3951
3952 // Broadcast notifications when the UI should be updated.
3953 if (entry == controller_.GetEntryAtOffset(0))
3954 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3955}
3956
3957void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3958 const std::string& encoding) {
3959 SetEncoding(encoding);
3960}
3961
[email protected]39f2f9252014-05-03 00:54:013962void WebContentsImpl::DocumentAvailableInMainFrame(
3963 RenderViewHost* render_view_host) {
3964 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3965 DocumentAvailableInMainFrame());
3966}
[email protected]e1c3a552012-05-04 20:51:323967void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3968 // Tell the active RenderViewHost to run unload handlers and close, as long
3969 // as the request came from a RenderViewHost in the same BrowsingInstance.
3970 // In most cases, we receive this from a swapped out RenderViewHost.
3971 // It is possible to receive it from one that has just been swapped in,
3972 // in which case we might as well deliver the message anyway.
3973 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3974 GetRenderViewHost()->ClosePage();
3975}
3976
[email protected]f546640b2012-05-15 00:03:493977void WebContentsImpl::RouteMessageEvent(
3978 RenderViewHost* rvh,
3979 const ViewMsg_PostMessage_Params& params) {
3980 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363981 // came from a RenderViewHost in the same BrowsingInstance or if this
3982 // WebContents is dedicated to a browser plugin guest.
3983 // Note: This check means that an embedder could theoretically receive a
3984 // postMessage from anyone (not just its own guests). However, this is
3985 // probably not a risk for apps since other pages won't have references
3986 // to App windows.
3987 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3988 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493989 return;
3990
3991 ViewMsg_PostMessage_Params new_params(params);
3992
3993 // If there is a source_routing_id, translate it to the routing ID for
3994 // the equivalent swapped out RVH in the target process. If we need
3995 // to create a swapped out RVH for the source tab, we create its opener
3996 // chain as well, since those will also be accessible to the target page.
3997 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3998 // Try to look up the WebContents for the source page.
3999 WebContentsImpl* source_contents = NULL;
4000 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
4001 rvh->GetProcess()->GetID(), params.source_routing_id);
4002 if (source_rvh) {
4003 source_contents = static_cast<WebContentsImpl*>(
4004 source_rvh->GetDelegate()->GetAsWebContents());
4005 }
4006
4007 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:364008 if (GetBrowserPluginGuest()) {
4009 // We create a swapped out RenderView for the embedder in the guest's
4010 // render process but we intentionally do not expose the embedder's
4011 // opener chain to it.
4012 new_params.source_routing_id =
4013 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
4014 } else {
4015 new_params.source_routing_id =
4016 source_contents->CreateOpenerRenderViews(GetSiteInstance());
4017 }
[email protected]f546640b2012-05-15 00:03:494018 } else {
4019 // We couldn't find it, so don't pass a source frame.
4020 new_params.source_routing_id = MSG_ROUTING_NONE;
4021 }
4022 }
4023
4024 // In most cases, we receive this from a swapped out RenderViewHost.
4025 // It is possible to receive it from one that has just been swapped in,
4026 // in which case we might as well deliver the message anyway.
marjab5fe7ad32015-02-18 23:08:464027 if (!params.message_port_ids.empty()) {
4028 // Updating the message port information has to be done in the IO thread;
4029 // MessagePortMessageFilter::RouteMessageEventWithMessagePorts will send
4030 // ViewMsg_PostMessageEvent after it's done. Note that a trivial solution
4031 // would've been to post a task on the IO thread to do the IO-thread-bound
4032 // work, and make that post a task back to WebContentsImpl in the UI
4033 // thread. But we cannot do that, since there's nothing to guarantee that
4034 // WebContentsImpl stays alive during the round trip.
4035 scoped_refptr<MessagePortMessageFilter> message_port_message_filter(
4036 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
4037 ->message_port_message_filter());
4038 BrowserThread::PostTask(
4039 BrowserThread::IO, FROM_HERE,
4040 base::Bind(&MessagePortMessageFilter::RouteMessageEventWithMessagePorts,
4041 message_port_message_filter, GetRoutingID(), new_params));
4042 } else {
4043 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
4044 }
[email protected]f546640b2012-05-15 00:03:494045}
4046
[email protected]a796f202012-05-30 14:14:254047bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:264048 const base::string16& message,
[email protected]a796f202012-05-30 14:14:254049 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:264050 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254051 if (!delegate_)
4052 return false;
4053 return delegate_->AddMessageToConsole(this, level, message, line_no,
4054 source_id);
4055}
4056
[email protected]0eba810b2012-10-18 03:19:364057int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214058 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294059 int render_view_routing_id = MSG_ROUTING_NONE;
4060 GetRenderManager()->CreateRenderFrame(
4061 instance, nullptr, MSG_ROUTING_NONE,
4062 CREATE_RF_SWAPPED_OUT | CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4063 CREATE_RF_HIDDEN,
4064 &render_view_routing_id);
4065 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364066}
4067
[email protected]b172aee2012-04-10 17:05:264068void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:274069 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254070 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224071
[email protected]ea114722012-03-12 01:11:254072 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174073 if (rdh) // NULL in unittests.
4074 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254075}
4076
[email protected]b172aee2012-04-10 17:05:264077void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444078 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254079 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444080}
4081
creiscce56cd2014-09-29 22:45:224082void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:154083 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:224084 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:154085 return;
4086
creiscce56cd2014-09-29 22:45:224087 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
4088 RenderFrameHostImpl* rfhi =
4089 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584090
[email protected]e5fc1632011-08-08 07:51:534091 // Ignore renderer unresponsive event if debugger is attached to the tab
4092 // since the event may be a result of the renderer sitting on a breakpoint.
4093 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364094 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534095 return;
4096
clamyafbf7f02015-01-21 20:38:114097 if (rfhi->IsWaitingForBeforeUnloadACK() ||
creiscce56cd2014-09-29 22:45:224098 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324099 // Hang occurred while firing the beforeunload/unload handler.
4100 // Pretend the handler fired so tab closing continues as if it had.
clamydf1975e2015-02-05 19:12:244101 frame_tree_.ForEach(base::Bind(
4102 &EnableSuddenTermination, rvhi->GetSiteInstance()->GetId()));
[email protected]420ae012009-04-24 05:16:324103
[email protected]fa944cb82013-11-15 17:51:214104 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324105 return;
4106
4107 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564108 // nothing we can do to recover. If the hang is in the beforeunload handler,
4109 // pretend the beforeunload listeners have all fired and allow the delegate
4110 // to continue closing; the user will not have the option of cancelling the
4111 // close. Otherwise, pretend the unload listeners have all fired and close
4112 // the tab.
4113 bool close = true;
clamyafbf7f02015-01-21 20:38:114114 if (rfhi->IsWaitingForBeforeUnloadACK() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564115 delegate_->BeforeUnloadFired(this, true, &close);
4116 }
4117 if (close)
creiscce56cd2014-09-29 22:45:224118 Close(rvhi);
[email protected]420ae012009-04-24 05:16:324119 return;
4120 }
4121
[email protected]9f76c1e2012-03-05 15:15:584122 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474123 return;
4124
[email protected]6934a702011-12-20 00:04:514125 if (delegate_)
4126 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324127}
4128
[email protected]b172aee2012-04-10 17:05:264129void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:514130 if (delegate_)
4131 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324132}
4133
[email protected]b172aee2012-04-10 17:05:264134void WebContentsImpl::LoadStateChanged(
4135 const GURL& url,
4136 const net::LoadStateWithParam& load_state,
4137 uint64 upload_position,
4138 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:324139 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564140 upload_position_ = upload_position;
4141 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:504142 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:214143 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:304144 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214145 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324146 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464147 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224148 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4149 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464150 }
[email protected]420ae012009-04-24 05:16:324151}
4152
[email protected]b172aee2012-04-10 17:05:264153void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554154 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324155 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124156 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4157 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514158 if (delegate_)
4159 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094160 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324161}
4162
[email protected]58d5cfe2013-07-10 02:40:524163void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544164 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234165 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224166 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544167}
4168
[email protected]b172aee2012-04-10 17:05:264169void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104170 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214171 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264172 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4173 // here during container initialization and normal window size will be set
4174 // later. In case of tab duplication this resizing to 0x0 prevents setting
4175 // normal size later so just ignore it.
4176 if (!size.IsEmpty())
4177 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324178}
4179
[email protected]af905902013-10-01 21:38:514180void WebContentsImpl::CancelModalDialogsForRenderManager() {
4181 // We need to cancel modal dialogs when doing a process swap, since the load
4182 // deferrer would prevent us from swapping out.
4183 if (dialog_manager_)
4184 dialog_manager_->CancelActiveAndPendingDialogs(this);
4185}
4186
[email protected]02d7b6e2014-06-24 21:01:504187void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4188 RenderFrameHost* new_host,
4189 bool is_main_frame) {
4190 if (is_main_frame) {
4191 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
4192 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084193
[email protected]02d7b6e2014-06-24 21:01:504194 // Make sure the visible RVH reflects the new delegate's preferences.
4195 if (delegate_)
4196 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394197
[email protected]02d7b6e2014-06-24 21:01:504198 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4199 }
4200
4201 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544202}
4203
[email protected]14392a52012-05-02 20:28:444204int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
4205 SiteInstance* instance) {
4206 if (!opener_)
4207 return MSG_ROUTING_NONE;
4208
4209 // Recursively create RenderViews for anything else in the opener chain.
4210 return opener_->CreateOpenerRenderViews(instance);
4211}
4212
4213int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
4214 int opener_route_id = MSG_ROUTING_NONE;
4215
4216 // If this tab has an opener, ensure it has a RenderView in the given
4217 // SiteInstance as well.
4218 if (opener_)
4219 opener_route_id = opener_->CreateOpenerRenderViews(instance);
4220
[email protected]45a22ad2013-02-21 03:25:004221 // If any of the renderers (current, pending, or swapped out) for this
4222 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:214223 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
4224 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:374225
[email protected]fa944cb82013-11-15 17:51:214226 if (GetRenderManager()->pending_render_view_host() &&
4227 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
4228 instance)
4229 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:004230
[email protected]fa944cb82013-11-15 17:51:214231 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:374232 instance);
4233 if (rvh)
4234 return rvh->GetRoutingID();
4235
[email protected]14392a52012-05-02 20:28:444236 // Create a swapped out RenderView in the given SiteInstance if none exists,
4237 // setting its opener to the given route_id. Return the new view's route_id.
carlosk37f793792014-11-27 15:08:294238 int render_view_routing_id = MSG_ROUTING_NONE;
4239 GetRenderManager()->CreateRenderFrame(instance, nullptr, opener_route_id,
4240 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4241 CREATE_RF_SWAPPED_OUT |
4242 CREATE_RF_HIDDEN,
4243 &render_view_routing_id);
4244 return render_view_routing_id;
[email protected]14392a52012-05-02 20:28:444245}
4246
[email protected]b172aee2012-04-10 17:05:264247NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194248 return GetController();
[email protected]3a3d47472010-07-15 21:03:544249}
4250
carlosk37f793792014-11-27 15:08:294251scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderManager(
4252 const GURL& url) {
4253 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(url)));
[email protected]420ae012009-04-24 05:16:324254}
4255
[email protected]10f417c52011-12-28 21:04:234256NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264257 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324258 return controller_.GetLastCommittedEntry();
4259}
4260
[email protected]b172aee2012-04-10 17:05:264261bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164262 RenderViewHost* render_view_host,
4263 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044264 int proxy_routing_id,
[email protected]82307f6b2014-08-07 03:30:124265 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434266 TRACE_EVENT0("browser,navigation",
4267 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444268 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484269 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164270 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4271 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4272 // case this because RWH is still a base class of RenderViewHost, and child
4273 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]82307f6b2014-08-07 03:30:124274 if (!for_main_frame_navigation) {
[email protected]bffc8302014-01-23 20:52:164275 RenderWidgetHostViewChildFrame* rwh_view_child =
4276 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164277 rwh_view = rwh_view_child;
4278 } else {
lazyboy549b3b42014-10-20 17:16:044279 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164280 }
[email protected]1a98a932009-11-17 00:12:524281
[email protected]420ae012009-04-24 05:16:324282 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444283 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214284 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324285
[email protected]74ce1ad2011-12-16 21:51:464286 // Make sure we use the correct starting page_id in the new RenderView.
4287 UpdateMaxPageIDIfNecessary(render_view_host);
4288 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584289 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464290
[email protected]9f76c1e2012-03-05 15:15:584291 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:264292 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:494293 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:044294 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:494295 max_page_id,
4296 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524297 return false;
[email protected]14392a52012-05-02 20:28:444298 }
[email protected]a4127722011-04-27 23:13:524299
avi2b177592014-12-10 02:08:024300 SetHistoryOffsetAndLengthForView(render_view_host,
4301 controller_.GetLastCommittedEntryIndex(),
4302 controller_.GetEntryCount());
4303
[email protected]a220b5932013-09-21 03:47:444304#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504305 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4306 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444307 if (rwh_view) {
4308 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4309 render_widget_host->WasResized();
4310 }
[email protected]f8233cc2011-05-31 20:24:504311#endif
4312
[email protected]420ae012009-04-24 05:16:324313 return true;
4314}
4315
[email protected]82307f6b2014-08-07 03:30:124316bool WebContentsImpl::CreateRenderFrameForRenderManager(
4317 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494318 int parent_routing_id,
4319 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434320 TRACE_EVENT0("browser,navigation",
4321 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124322
4323 RenderFrameHostImpl* rfh =
4324 static_cast<RenderFrameHostImpl*>(render_frame_host);
japhete6adf142014-10-31 00:01:494325 if (!rfh->CreateRenderFrame(parent_routing_id, proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124326 return false;
4327
4328 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4329 // RenderFrameHost will have to be associated with the appropriate
4330 // RenderWidgetHostView or a new one should be created here.
4331
4332 return true;
4333}
4334
[email protected]7d244f12013-08-22 21:41:514335#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454336
[email protected]155c7f22013-12-09 17:07:184337base::android::ScopedJavaLocalRef<jobject>
4338WebContentsImpl::GetJavaWebContents() {
4339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]0e813a52014-08-13 10:34:564340 return GetWebContentsAndroid()->GetJavaObject();
4341}
[email protected]155c7f22013-12-09 17:07:184342
[email protected]0e813a52014-08-13 10:34:564343WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184344 WebContentsAndroid* web_contents_android =
4345 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4346 if (!web_contents_android) {
4347 web_contents_android = new WebContentsAndroid(this);
4348 SetUserData(kWebContentsAndroidKey, web_contents_android);
4349 }
[email protected]0e813a52014-08-13 10:34:564350 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184351}
4352
[email protected]7d244f12013-08-22 21:41:514353bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
4354 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:164355 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:044356 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594357 true);
[email protected]7d244f12013-08-22 21:41:514358}
[email protected]fc2b46b2014-05-03 16:33:454359
4360#elif defined(OS_MACOSX)
4361
[email protected]75f4df72014-07-16 22:39:424362void WebContentsImpl::SetAllowOtherViews(bool allow) {
4363 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454364}
4365
[email protected]75f4df72014-07-16 22:39:424366bool WebContentsImpl::GetAllowOtherViews() {
4367 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454368}
4369
[email protected]7d244f12013-08-22 21:41:514370#endif
4371
[email protected]6fba26d2014-04-29 09:38:284372void WebContentsImpl::OnDialogClosed(int render_process_id,
4373 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264374 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494375 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264376 bool success,
[email protected]fcf75d42013-12-03 20:11:264377 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284378 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4379 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494380 last_dialog_suppressed_ = dialog_was_suppressed;
4381
[email protected]beb440c2009-11-06 04:08:544382 if (is_showing_before_unload_dialog_ && !success) {
4383 // If a beforeunload dialog is canceled, we need to stop the throbber from
4384 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284385 if (rfh)
4386 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354387 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104388
[email protected]6d65a462013-06-21 21:29:124389 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4390 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544391 }
[email protected]87de04b02014-04-08 22:14:494392
[email protected]beb440c2009-11-06 04:08:544393 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284394 if (rfh) {
4395 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4396 dialog_was_suppressed);
4397 } else {
4398 // Don't leak the sync IPC reply if the RFH or process is gone.
4399 delete reply_msg;
4400 }
[email protected]beb440c2009-11-06 04:08:544401}
4402
[email protected]b172aee2012-04-10 17:05:264403void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544404 if (encoding == last_reported_encoding_)
4405 return;
4406 last_reported_encoding_ = encoding;
4407
4408 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124409 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104410}
[email protected]f45d2a72010-03-08 23:28:354411
[email protected]1ac10dca2013-08-20 20:47:044412bool WebContentsImpl::IsHidden() {
4413 return capturer_count_ == 0 && !should_normally_be_visible_;
4414}
4415
[email protected]b0936d22013-11-28 06:47:364416RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214417 return frame_tree_.root()->render_manager();
4418}
4419
[email protected]b172aee2012-04-10 17:05:264420RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584421 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4422}
[email protected]7900bfdb2012-05-24 19:31:244423
[email protected]f8497342013-02-05 22:15:024424BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394425 return browser_plugin_guest_.get();
4426}
4427
[email protected]738f57a2013-06-29 21:06:544428void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4429 CHECK(!browser_plugin_guest_);
4430 browser_plugin_guest_.reset(guest);
4431}
4432
[email protected]f8497342013-02-05 22:15:024433BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394434 return browser_plugin_embedder_.get();
4435}
[email protected]8ff00d72012-10-23 19:12:214436
[email protected]d9030b82013-07-19 08:26:064437void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194438 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304439 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4440 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4441 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064442}
4443
4444void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304445 active_audio_players_.clear();
4446 active_video_players_.clear();
4447 audio_power_save_blocker_.reset();
4448 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064449}
4450
[email protected]fc2b46b2014-05-03 16:33:454451gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214452 gfx::Size size;
4453 if (delegate_)
4454 size = delegate_->GetSizeForNewRenderView(this);
4455 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454456 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214457 return size;
4458}
4459
[email protected]ae7eeda2014-07-04 01:53:264460void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4461 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024462 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554463}
4464
[email protected]222f5822014-02-05 23:40:494465void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4466 if (!delegate_)
4467 return;
4468 const gfx::Size new_size = GetPreferredSize();
4469 if (new_size != old_size)
4470 delegate_->UpdatePreferredSize(this, new_size);
4471}
4472
dalecurtisbc6572e12014-09-12 19:22:304473void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4474 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114475 if (!HasValidFrameSource())
4476 return;
4477
dalecurtisbc6572e12014-09-12 19:22:304478 const uintptr_t key =
4479 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4480 DCHECK(std::find((*player_map)[key].begin(),
4481 (*player_map)[key].end(),
4482 player_cookie) == (*player_map)[key].end());
4483 (*player_map)[key].push_back(player_cookie);
4484}
4485
4486void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4487 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114488 if (!HasValidFrameSource())
4489 return;
4490
dalecurtisbc6572e12014-09-12 19:22:304491 const uintptr_t key =
4492 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4493 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4494 if (it == player_map->end())
4495 return;
4496
4497 // Remove the player.
4498 PlayerList::iterator player_it =
4499 std::find(it->second.begin(), it->second.end(), player_cookie);
4500 if (player_it != it->second.end())
4501 it->second.erase(player_it);
4502
4503 // If there are no players left, remove the map entry.
4504 if (it->second.empty())
4505 player_map->erase(it);
4506}
4507
4508void WebContentsImpl::RemoveAllMediaPlayerEntries(
4509 RenderFrameHost* render_frame_host,
4510 ActiveMediaPlayerMap* player_map) {
4511 ActiveMediaPlayerMap::iterator it =
4512 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4513 if (it == player_map->end())
4514 return;
4515 player_map->erase(it);
4516}
4517
[email protected]23f41fd2014-06-21 05:29:174518void WebContentsImpl::ResumeResponseDeferredAtStart() {
4519 FrameTreeNode* node = frame_tree_.root();
4520 node->render_manager()->ResumeResponseDeferredAtStart();
4521}
4522
[email protected]34ff1cfc2014-08-20 06:16:054523void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4524 force_disable_overscroll_content_ = force_disable;
4525 if (view_)
4526 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4527}
4528
[email protected]8ff00d72012-10-23 19:12:214529} // namespace content