blob: 4ff481b2dcc5f5b1251ecc74f8b6c665546efd28 [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"
skyostil95082a62015-06-05 19:53:0711#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2014#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2215#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0716#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5117#include "base/strings/string16.h"
18#include "base/strings/string_number_conversions.h"
19#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0020#include "base/strings/utf_string_conversions.h"
skyostil95082a62015-06-05 19:53:0721#include "base/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3722#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4223#include "base/trace_event/trace_event.h"
rsleevic327b48f82015-04-30 02:03:2524#include "components/mime_util/mime_util.h"
[email protected]95640212014-07-26 18:14:3025#include "content/browser/accessibility/accessibility_mode_helper.h"
26#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1827#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3928#include "content/browser/browser_plugin/browser_plugin_embedder.h"
29#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5930#include "content/browser/child_process_security_policy_impl.h"
[email protected]5f2aa722013-08-07 16:59:4131#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0432#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4633#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1234#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1635#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1636#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4037#include "content/browser/frame_host/interstitial_page_impl.h"
38#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0139#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1840#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1641#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5742#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0543#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4444#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4045#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3046#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5247#include "content/browser/media/capture/web_contents_audio_muter.h"
[email protected]0bc7f3542013-10-21 15:05:5348#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0949#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]d9030b82013-07-19 08:26:0650#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3051#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5052#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3253#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5054#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4855#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0956#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3357#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1158#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5859#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0360#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5661#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1462#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4263#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4464#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1765#include "content/common/input_messages.h"
avi286019ce2015-07-29 01:26:5866#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5167#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0268#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3669#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1170#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2871#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4472#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3673#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1774#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1475#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4676#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1577#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0078#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2779#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0080#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3781#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1482#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3083#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:3284#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:0985#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:1286#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:3487#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3888#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4289#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2590#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2191#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:0892#include "content/public/common/browser_plugin_guest_mode.h"
[email protected]54087fe2011-10-28 22:02:4893#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5494#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4995#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2096#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:0197#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:0398#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5799#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05100#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40101#include "mojo/common/url_type_converters.h"
102#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]d686e812009-06-03 19:10:29103#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:53104#include "net/http/http_cache.h"
105#include "net/http/http_transaction_factory.h"
106#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34107#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40108#include "skia/public/type_converters.h"
109#include "third_party/skia/include/core/SkBitmap.h"
[email protected]a08412b62012-05-29 21:28:56110#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01111#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41112#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52113#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31114
qinmin58567c82015-01-07 21:00:20115#if defined(ENABLE_BROWSER_CDMS)
116#include "content/browser/media/media_web_contents_observer.h"
117#endif
118
[email protected]583418cc2013-01-17 14:01:10119#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40120#include "content/browser/android/content_video_view.h"
[email protected]583418cc2013-01-17 14:01:10121#include "content/browser/android/date_time_chooser_android.h"
timavf6f6f692015-03-04 02:19:37122#include "content/browser/android/media_players_observer.h"
avayvod41634b12015-07-08 17:07:05123#include "content/browser/media/android/media_session.h"
[email protected]155c7f22013-12-09 17:07:18124#include "content/browser/web_contents/web_contents_android.h"
[email protected]583418cc2013-01-17 14:01:10125#endif
126
[email protected]f66df822012-05-18 16:52:17127#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50128#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57129#endif
[email protected]3e45ba92009-02-20 21:09:00130
[email protected]8ff00d72012-10-23 19:12:21131namespace content {
[email protected]420ae012009-04-24 05:16:32132namespace {
133
[email protected]960b0372014-05-19 18:01:00134const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41135const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05136
[email protected]155c7f22013-12-09 17:07:18137#if defined(OS_ANDROID)
138const char kWebContentsAndroidKey[] = "web_contents_android";
139#endif // OS_ANDROID
140
[email protected]e4abd3b42013-11-12 18:28:47141base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46142g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
143
halton.huoca2eabd2015-07-06 08:17:40144static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback,
145 int id,
146 const GURL& image_url,
147 image_downloader::DownloadResultPtr result) {
148 DCHECK(result);
149
150 const std::vector<SkBitmap> images =
151 result->images.To<std::vector<SkBitmap>>();
152 const std::vector<gfx::Size> original_image_sizes =
153 result->original_image_sizes.To<std::vector<gfx::Size>>();
154
155 callback.Run(id, result->http_status_code, image_url, images,
156 original_image_sizes);
[email protected]795c28972012-12-06 06:13:39157}
158
[email protected]8bfc8272013-09-09 20:10:53159void NotifyCacheOnIO(
160 scoped_refptr<net::URLRequestContextGetter> request_context,
161 const GURL& url,
162 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58163 net::HttpCache* cache = request_context->GetURLRequestContext()->
164 http_transaction_factory()->GetCache();
165 if (cache)
166 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53167}
168
[email protected]9b159a52013-10-03 17:24:55169// Helper function for retrieving all the sites in a frame tree.
170bool CollectSites(BrowserContext* context,
171 std::set<GURL>* sites,
172 FrameTreeNode* node) {
173 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
174 return true;
175}
176
alexmos4cf2aa32015-07-15 23:40:43177bool FindMatchingProcess(int render_process_id,
178 bool* did_match_process,
179 FrameTreeNode* node) {
180 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) {
181 *did_match_process = true;
182 return false;
183 }
184 return true;
185}
186
[email protected]a86c0e962013-12-17 17:10:39187bool ForEachFrameInternal(
188 const base::Callback<void(RenderFrameHost*)>& on_frame,
189 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41190 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39191 return true;
192}
193
[email protected]95640212014-07-26 18:14:30194bool ForEachPendingFrameInternal(
195 const base::Callback<void(RenderFrameHost*)>& on_frame,
196 FrameTreeNode* node) {
197 RenderFrameHost* pending_frame_host =
198 node->render_manager()->pending_frame_host();
199 if (pending_frame_host)
200 on_frame.Run(pending_frame_host);
201 return true;
202}
203
[email protected]a86c0e962013-12-17 17:10:39204void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
205 IPC::Message* message_copy = new IPC::Message(*message);
206 message_copy->set_routing_id(rfh->GetRoutingID());
207 rfh->Send(message_copy);
208}
209
[email protected]948481d2014-06-11 18:32:22210void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
211 RenderFrameHost* rfh) {
212 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
213 ->frame_tree_node()
214 ->render_manager()
215 ->GetRenderWidgetHostView();
216 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59217}
218
[email protected]95640212014-07-26 18:14:30219void SetAccessibilityModeOnFrame(AccessibilityMode mode,
220 RenderFrameHost* frame_host) {
221 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
222}
223
dtseng0dd3fa12015-07-22 19:00:52224void ResetAccessibility(RenderFrameHost* rfh) {
225 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
226}
227
[email protected]420ae012009-04-24 05:16:32228} // namespace
229
[email protected]54944cde2012-12-09 09:24:59230WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21231 FrameTreeNode* opener_node = nullptr;
232 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
233 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
234 params.opener_render_process_id, params.opener_render_frame_id);
235 if (opener_rfh)
236 opener_node = opener_rfh->frame_tree_node();
237 }
238 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19239}
240
241WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59242 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30243 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21244 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30245
246 for (SessionStorageNamespaceMap::const_iterator it =
247 session_storage_namespace_map.begin();
248 it != session_storage_namespace_map.end();
249 ++it) {
250 new_contents->GetController()
251 .SetSessionStorageNamespace(it->first, it->second.get());
252 }
253
[email protected]54944cde2012-12-09 09:24:59254 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19255 return new_contents;
[email protected]a81343d232011-12-27 07:39:20256}
[email protected]746d3052012-05-22 15:15:47257
nickf9acfbe2014-12-23 19:12:37258void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
259 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46260 g_created_callbacks.Get().push_back(callback);
261}
262
nickf9acfbe2014-12-23 19:12:37263void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
264 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46265 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
266 if (g_created_callbacks.Get().at(i).Equals(callback)) {
267 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
268 return;
269 }
270 }
271}
272
[email protected]299d7f12012-05-23 05:31:15273WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47274 return rvh->GetDelegate()->GetAsWebContents();
275}
276
[email protected]a86c0e962013-12-17 17:10:39277WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
278 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
279 if (!rfh_impl)
280 return NULL;
281 return rfh_impl->delegate()->GetAsWebContents();
282}
283
[email protected]7fff43e2013-05-21 20:21:10284// WebContentsImpl::DestructionObserver ----------------------------------------
285
286class WebContentsImpl::DestructionObserver : public WebContentsObserver {
287 public:
288 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
289 : WebContentsObserver(watched_contents),
290 owner_(owner) {
291 }
292
293 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58294 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58295 owner_->OnWebContentsDestroyed(
296 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10297 }
298
299 private:
300 WebContentsImpl* owner_;
301
302 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
303};
304
[email protected]8ed16472014-04-11 19:02:48305WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
306 int render_frame_id,
307 ColorChooser* chooser,
308 int identifier)
309 : render_process_id(render_process_id),
310 render_frame_id(render_frame_id),
311 chooser(chooser),
312 identifier(identifier) {
313}
314
315WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
316}
317
lazyboy6ec48b2a2015-06-29 15:18:14318// WebContentsImpl::WebContentsTreeNode ----------------------------------------
319WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
320 : outer_web_contents_(nullptr),
321 outer_contents_frame_tree_node_id_(
322 FrameTreeNode::kFrameTreeNodeInvalidID) {
323}
324
325WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
326 // Remove child pointer from our parent.
327 if (outer_web_contents_) {
328 ChildrenSet& child_ptrs_in_parent =
329 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
330 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
331 DCHECK(iter != child_ptrs_in_parent.end());
332 child_ptrs_in_parent.erase(this);
333 }
334
335 // Remove parent pointers from our children.
336 // TODO(lazyboy): We should destroy the children WebContentses too. If the
337 // children do not manage their own lifetime, then we would leak their
338 // WebContentses.
339 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
340 child->outer_web_contents_ = nullptr;
341}
342
343void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
344 WebContentsImpl* outer_web_contents,
345 RenderFrameHostImpl* outer_contents_frame) {
346 outer_web_contents_ = outer_web_contents;
347 outer_contents_frame_tree_node_id_ =
348 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
349
350 if (!outer_web_contents_->node_)
351 outer_web_contents_->node_.reset(new WebContentsTreeNode());
352
353 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
354}
355
[email protected]b172aee2012-04-10 17:05:26356// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32357
alexmose201c7cd2015-06-10 17:14:21358WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42359 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22360 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57361 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21362 created_with_opener_(false),
[email protected]2ceee8f2014-01-14 18:02:08363#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41364 accessible_parent_(NULL),
365#endif
[email protected]6ea6bdf2013-12-06 13:35:01366 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57367 this,
368 this,
369 this,
370 this),
[email protected]d5f942ba2008-09-26 19:30:34371 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03372 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23373 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
374 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34375 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26376 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56377 upload_size_(0),
378 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16379 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47380 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10381 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28382 theme_color_(SK_ColorTRANSPARENT),
383 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29384 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55385 capturer_count_(0),
386 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57387 is_being_destroyed_(false),
388 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15389 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01390 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39391 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38392 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21393 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
394 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]f114fa42013-12-06 17:06:44395 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55396 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42397 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03398 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49399 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05400 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30401 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57402 geolocation_service_context_(new GeolocationServiceContext()),
[email protected]95640212014-07-26 18:14:30403 accessibility_mode_(
dalecurtisbc6572e12014-09-12 19:22:30404 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
mohan.reddyaae039a2014-11-21 17:39:50405 virtual_keyboard_requested_(false),
mohan.reddy371ad9142014-09-17 08:01:46406 loading_weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55407 frame_tree_.SetFrameRemoveListener(
408 base::Bind(&WebContentsImpl::OnFrameRemoved,
409 base::Unretained(this)));
qinmin58567c82015-01-07 21:00:20410#if defined(ENABLE_BROWSER_CDMS)
411 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
412#endif
timavf6f6f692015-03-04 02:19:37413
414#if defined(OS_ANDROID)
415 audio_state_provider_.reset(new MediaPlayersObserver(this));
416#else
417 audio_state_provider_.reset(new AudioStreamMonitor(this));
418#endif
[email protected]332af7732009-03-11 13:21:35419}
initial.commit09911bf2008-07-26 23:55:29420
[email protected]b172aee2012-04-10 17:05:26421WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32422 is_being_destroyed_ = true;
423
[email protected]21b41c7e892014-02-28 01:52:24424 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
425 // shutdown and be deleted as well.
426 frame_tree_.ForEach(
427 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
428
[email protected]d9030b82013-07-19 08:26:06429 ClearAllPowerSaveBlockers();
430
[email protected]b24b68a2012-09-24 21:57:26431 for (std::set<RenderWidgetHostImpl*>::iterator iter =
432 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
433 (*iter)->DetachDelegate();
434 }
435 created_widgets_.clear();
436
[email protected]3ab9cb82011-06-03 18:02:07437 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15438 if (dialog_manager_)
avi2460c762015-04-17 15:21:54439 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07440
[email protected]8ed16472014-04-11 19:02:48441 if (color_chooser_info_.get())
442 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20443
[email protected]420ae012009-04-24 05:16:32444 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32445
[email protected]ca13a442012-04-17 14:00:12446 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21447 NotificationService::current()->Notify(
448 NOTIFICATION_WEB_CONTENTS_DESTROYED,
449 Source<WebContents>(this),
450 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32451
[email protected]df0c843f2014-05-23 20:37:23452 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14453 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23454 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59455
[email protected]df0c843f2014-05-23 20:37:23456 // Manually call the observer methods for the root frame tree node.
457 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56458
459 if (root->pending_frame_host())
460 root->pending_frame_host()->SetRenderFrameCreated(false);
461 root->current_frame_host()->SetRenderFrameCreated(false);
[email protected]f273ee52013-10-18 16:05:27462
naskoa83483fb2015-02-27 16:57:10463 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
464 FrameDeleted(root->current_frame_host()));
465
[email protected]df0c843f2014-05-23 20:37:23466 if (root->pending_render_view_host()) {
467 FOR_EACH_OBSERVER(WebContentsObserver,
468 observers_,
469 RenderViewDeleted(root->pending_render_view_host()));
470 }
[email protected]c06c58c2014-03-12 20:31:59471
[email protected]f273ee52013-10-18 16:05:27472 FOR_EACH_OBSERVER(WebContentsObserver,
473 observers_,
[email protected]df0c843f2014-05-23 20:37:23474 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27475
[email protected]2db9bd72012-04-13 20:20:56476 FOR_EACH_OBSERVER(WebContentsObserver,
477 observers_,
[email protected]12a46832014-05-09 13:35:58478 WebContentsDestroyed());
479
480 FOR_EACH_OBSERVER(WebContentsObserver,
481 observers_,
482 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08483
[email protected]6934a702011-12-20 00:04:51484 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10485
486 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
487 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42488}
489
[email protected]d1198fd2012-08-13 22:50:19490WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59491 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21492 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03493 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21494 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19495
alexmose201c7cd2015-06-10 17:14:21496 if (!params.opener_suppressed && opener) {
497 new_contents->GetFrameTree()->root()->SetOpener(opener);
498 new_contents->created_with_opener_ = true;
499 }
500
501 // This may be true even when opener is null, such as when opening blocked
502 // popups.
alexmos090fae8e2015-05-28 17:09:28503 if (params.created_with_opener)
504 new_contents->created_with_opener_ = true;
505
[email protected]4858e432014-06-23 18:14:17506 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06507 // This makes |new_contents| act as a guest.
508 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16509 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06510 // We are instantiating a WebContents for browser plugin. Set its subframe
511 // bit to true.
512 new_contents->is_subframe_ = true;
513 }
[email protected]54944cde2012-12-09 09:24:59514 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19515 return new_contents;
516}
517
[email protected]95640212014-07-26 18:14:30518// static
519std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
520 std::vector<WebContentsImpl*> result;
521 scoped_ptr<RenderWidgetHostIterator> widgets(
522 RenderWidgetHostImpl::GetRenderWidgetHosts());
523 std::set<WebContentsImpl*> web_contents_set;
524 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
525 if (!rwh->IsRenderView())
526 continue;
527 RenderViewHost* rvh = RenderViewHost::From(rwh);
528 if (!rvh)
529 continue;
530 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
531 if (!web_contents)
532 continue;
533 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents);
534 if (web_contents_set.find(wci) == web_contents_set.end()) {
535 web_contents_set.insert(wci);
536 result.push_back(wci);
537 }
538 }
539 return result;
540}
541
clamya16aa8172015-05-26 13:07:25542// static
543WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
544 FrameTreeNode* frame_tree_node) {
545 return static_cast<WebContentsImpl*>(
546 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
547}
548
[email protected]b0936d22013-11-28 06:47:36549RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21550 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28551}
552
[email protected]7bb761892012-07-20 09:32:47553bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
554 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44555 return OnMessageReceived(render_view_host, NULL, message);
556}
557
558bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
559 RenderFrameHost* render_frame_host,
560 const IPC::Message& message) {
561 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56562 if (GetWebUI() &&
563 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17564 return true;
[email protected]d2353452012-01-19 19:53:56565 }
[email protected]f82d57b52011-04-27 19:13:17566
brettw5a1613dc2015-06-02 05:34:43567 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25568 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33569 if (render_frame_host) {
570 while ((observer = it.GetNext()) != NULL)
571 if (observer->OnMessageReceived(message, render_frame_host))
572 return true;
573 } else {
574 while ((observer = it.GetNext()) != NULL)
575 if (observer->OnMessageReceived(message))
576 return true;
577 }
[email protected]403415a2011-01-10 18:57:53578
[email protected]1d62cf72014-02-07 21:31:57579 // Message handlers should be aware of which
580 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
581 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02582 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57583 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02584 else
[email protected]1d62cf72014-02-07 21:31:57585 render_view_message_source_ = render_view_host;
586
[email protected]724159a2010-12-30 01:11:18587 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33588 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40589 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
590 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05591 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
592 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48593 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
594 OnDocumentLoadedInFrame)
595 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
596 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
597 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
598 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
599 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19600 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
601 OnMediaPlayingNotification)
602 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
603 OnMediaPausedNotification)
[email protected]586871b2014-07-22 17:05:11604 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFirstVisuallyNonEmptyPaint,
605 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18606 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
607 OnDidLoadResourceFromMemoryCache)
608 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
609 OnDidDisplayInsecureContent)
610 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
611 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25612 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26613 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21614 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48615 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
616 OnRegisterProtocolHandler)
617 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
618 OnUnregisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16619 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10620 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50621 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50622#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00623 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
624 OnPepperInstanceCreated)
625 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
626 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42627 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
628 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50629 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
630 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55631 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40632 OnBrowserPluginMessage(render_frame_host,
633 message))
thestigc4cac8f2014-09-04 21:17:50634#endif
[email protected]41225fe2013-03-29 05:32:02635 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07636 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
637 OnShowValidationMessage)
638 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
639 OnHideValidationMessage)
640 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
641 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48642#if defined(OS_ANDROID)
643 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
644 OnFindMatchRectsReply)
645 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
646 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48647#endif
[email protected]724159a2010-12-30 01:11:18648 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33649 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44650 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57651 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18652
[email protected]724159a2010-12-30 01:11:18653 return handled;
654}
655
nasko907fcb62015-01-28 04:24:11656bool WebContentsImpl::HasValidFrameSource() {
657 if (!render_frame_message_source_) {
658 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18659 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
660 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11661 return false;
662 }
663
664 return true;
665}
666
[email protected]b172aee2012-04-10 17:05:26667void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18668 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21669 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43670 if (delegate_)
671 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18672}
673
[email protected]d1198fd2012-08-13 22:50:19674NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56675 return controller_;
676}
677
[email protected]d1198fd2012-08-13 22:50:19678const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56679 return controller_;
680}
681
[email protected]8ff00d72012-10-23 19:12:21682BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55683 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30684}
685
[email protected]b172aee2012-04-10 17:05:26686const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24687 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32688 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51689 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31690}
691
[email protected]a093ce02013-07-22 20:53:14692const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24693 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32694 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24695 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
696}
697
698const GURL& WebContentsImpl::GetLastCommittedURL() const {
699 // We may not have a navigation entry yet.
700 NavigationEntry* entry = controller_.GetLastCommittedEntry();
701 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
702}
703
[email protected]8ff00d72012-10-23 19:12:21704WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31705 return delegate_;
706}
707
[email protected]8ff00d72012-10-23 19:12:21708void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31709 // TODO(cbentzel): remove this debugging code?
710 if (delegate == delegate_)
711 return;
712 if (delegate_)
713 delegate_->Detach(this);
714 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08715 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31716 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08717 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00718 if (view_)
[email protected]e85165c642014-06-10 14:34:31719 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08720 }
[email protected]be1f56ab2011-12-22 06:55:31721}
722
[email protected]8ff00d72012-10-23 19:12:21723RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21724 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41725 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16726}
727
clamydf1975e2015-02-05 19:12:24728RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41729 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16730}
731
nick53d5cbf2015-04-23 22:50:14732RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
733 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
734 if (!focused_node)
735 return nullptr;
736 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07737}
738
[email protected]a86c0e962013-12-17 17:10:39739void WebContentsImpl::ForEachFrame(
740 const base::Callback<void(RenderFrameHost*)>& on_frame) {
741 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
742}
743
744void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
745 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
746 delete message;
747}
748
creisc014b402015-04-23 16:41:45749RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21750 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31751}
752
[email protected]6b618e62012-08-16 12:59:18753int WebContentsImpl::GetRoutingID() const {
754 if (!GetRenderViewHost())
755 return MSG_ROUTING_NONE;
756
757 return GetRenderViewHost()->GetRoutingID();
758}
759
creis89a0f782015-05-27 16:13:17760void WebContentsImpl::CancelActiveAndPendingDialogs() {
761 if (dialog_manager_)
762 dialog_manager_->CancelActiveAndPendingDialogs(this);
763 if (browser_plugin_embedder_)
764 browser_plugin_embedder_->CancelGuestDialogs();
765}
766
[email protected]44470a22013-01-24 01:21:54767int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
768 return fullscreen_widget_routing_id_;
769}
770
naskoc0fceff2015-04-30 15:53:52771void WebContentsImpl::ClosePage() {
772 GetRenderViewHost()->ClosePage();
773}
774
[email protected]b172aee2012-04-10 17:05:26775RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21776 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31777}
778
[email protected]4aebbca2013-09-17 22:26:49779RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
780 const {
781 RenderWidgetHost* const widget_host =
782 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
783 GetFullscreenWidgetRoutingID());
784 return widget_host ? widget_host->GetView() : NULL;
785}
786
[email protected]8ff00d72012-10-23 19:12:21787WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31788 return view_.get();
789}
790
yusufod41c5f92015-03-06 00:14:28791SkColor WebContentsImpl::GetThemeColor() const {
792 return theme_color_;
793}
794
[email protected]95640212014-07-26 18:14:30795void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
796 if (mode == accessibility_mode_)
797 return;
798
799 accessibility_mode_ = mode;
800 frame_tree_.ForEach(
801 base::Bind(&ForEachFrameInternal,
802 base::Bind(&SetAccessibilityModeOnFrame, mode)));
803 frame_tree_.ForEach(
804 base::Bind(&ForEachPendingFrameInternal,
805 base::Bind(&SetAccessibilityModeOnFrame, mode)));
806}
807
808void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50809 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30810}
811
812void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50813 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30814}
815
dmazzoni83ba5c82015-04-14 07:11:51816void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
817 // TODO(dmazzoni): http://crbug.com/475608 This only returns the
818 // accessibility tree from the main frame and everything in the
819 // same site instance.
820 GetMainFrame()->RequestAXTreeSnapshot(callback);
821}
822
[email protected]8ff00d72012-10-23 19:12:21823WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56824 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03825 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
826 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22827 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58828 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22829 web_ui->SetController(controller);
830 return web_ui;
831 }
832
833 delete web_ui;
834 return NULL;
835}
836
[email protected]8ff00d72012-10-23 19:12:21837WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21838 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
839 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31840}
841
[email protected]8ff00d72012-10-23 19:12:21842WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21843 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34844}
845
[email protected]86ef6a392012-05-11 22:03:11846void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22847 if (GetUserAgentOverride() == override)
848 return;
849
850 renderer_preferences_.user_agent_override = override;
851
852 // Send the new override string to the renderer.
853 RenderViewHost* host = GetRenderViewHost();
854 if (host)
855 host->SyncRendererPrefs();
856
857 // Reload the page if a load is currently in progress to avoid having
858 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27859 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22860 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
861 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53862
863 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
864 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11865}
866
867const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22868 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11869}
870
[email protected]95640212014-07-26 18:14:30871void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dtseng0dd3fa12015-07-22 19:00:52872 if (GetAccessibilityMode() == AccessibilityModeTreeOnly)
873 ForEachFrame(base::Bind(&ResetAccessibility));
874 else
875 AddAccessibilityMode(AccessibilityModeTreeOnly);
[email protected]95640212014-07-26 18:14:30876}
877
878bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
879 return accessibility_mode_ == AccessibilityModeTreeOnly;
880}
881
882bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
883 return accessibility_mode_ == AccessibilityModeComplete;
884}
885
[email protected]2ceee8f2014-01-14 18:02:08886#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41887void WebContentsImpl::SetParentNativeViewAccessible(
888gfx::NativeViewAccessible accessible_parent) {
889 accessible_parent_ = accessible_parent;
creisc014b402015-04-23 16:41:45890 RenderFrameHostImpl* rfh = GetMainFrame();
[email protected]95640212014-07-26 18:14:30891 if (rfh)
892 rfh->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41893}
894#endif
895
[email protected]fcf75d42013-12-03 20:11:26896const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55897 // Transient entries take precedence. They are used for interstitial pages
898 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23899 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08900 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21901 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30902 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23903 if (entry) {
[email protected]b5cca982011-05-26 04:42:08904 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23905 }
[email protected]fa944cb82013-11-15 17:51:21906 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
907 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58908 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54909 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32910 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54911 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35912 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26913 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54914 if (!title.empty())
915 return title;
916 }
917 }
918
919 // We use the title for the last committed entry rather than a pending
920 // navigation entry. For example, when the user types in a URL, we want to
921 // keep the old page's title until the new load has committed and we get a new
922 // title.
[email protected]96d185d2009-04-24 03:28:54923 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32924
[email protected]9eeafc012013-11-25 23:49:47925 // We make an exception for initial navigations.
926 if (controller_.IsInitialNavigation()) {
927 // We only want to use the title from the visible entry in one of two cases:
928 // 1. There's already a committed entry for an initial navigation, in which
929 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
930 // 2. The pending entry has been explicitly assigned a title to display.
931 //
932 // If there's no last committed entry and no assigned title, we should fall
933 // back to |page_title_when_no_navigation_entry_| rather than showing the
934 // URL.
935 if (entry ||
936 (controller_.GetVisibleEntry() &&
937 !controller_.GetVisibleEntry()->GetTitle().empty())) {
938 entry = controller_.GetVisibleEntry();
939 }
940 }
[email protected]59167c22013-06-03 18:07:32941
[email protected]45d0ef7f2011-01-05 13:46:23942 if (entry) {
[email protected]b5cca982011-05-26 04:42:08943 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23944 }
[email protected]987fc3a2011-05-26 14:18:09945
946 // |page_title_when_no_navigation_entry_| is finally used
947 // if no title cannot be retrieved.
948 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54949}
950
[email protected]b172aee2012-04-10 17:05:26951int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46952 return GetMaxPageIDForSiteInstance(GetSiteInstance());
953}
954
[email protected]b172aee2012-04-10 17:05:26955int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
956 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33957 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
958 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46959
[email protected]b6583592012-01-25 19:52:33960 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34961}
962
[email protected]b172aee2012-04-10 17:05:26963void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46964 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
965}
966
[email protected]b172aee2012-04-10 17:05:26967void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33968 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46969 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33970 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34971}
972
[email protected]ec6c05f2013-10-23 18:41:57973void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
974 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
975 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57976}
977
creiscce56cd2014-09-29 22:45:22978SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21979 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54980}
981
creiscce56cd2014-09-29 22:45:22982SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
983 RenderViewHostImpl* dest_rvh =
984 GetRenderManager()->pending_render_view_host() ?
985 GetRenderManager()->pending_render_view_host() :
986 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58987 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38988}
989
[email protected]b172aee2012-04-10 17:05:26990bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31991 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49992}
993
[email protected]6dfed692014-05-22 04:18:03994bool WebContentsImpl::IsLoadingToDifferentDocument() const {
995 return is_loading_ && is_load_to_different_document_;
996}
997
[email protected]b172aee2012-04-10 17:05:26998bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03999 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311000}
1001
[email protected]b172aee2012-04-10 17:05:261002const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311003 return load_state_;
1004}
1005
[email protected]fcf75d42013-12-03 20:11:261006const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311007 return load_state_host_;
1008}
1009
[email protected]b172aee2012-04-10 17:05:261010uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311011 return upload_size_;
1012}
1013
[email protected]b172aee2012-04-10 17:05:261014uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311015 return upload_position_;
1016}
1017
[email protected]1ae93fb2013-06-14 03:38:561018std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:561019 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:391020 frame_tree_.ForEach(base::Bind(&CollectSites,
1021 base::Unretained(GetBrowserContext()),
1022 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:561023 return sites;
1024}
1025
[email protected]b172aee2012-04-10 17:05:261026const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541027 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311028}
1029
[email protected]b172aee2012-04-10 17:05:261030bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311031 return displayed_insecure_content_;
1032}
1033
[email protected]222f5822014-02-05 23:40:491034void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251035 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551036 ++capturer_count_;
1037 DVLOG(1) << "There are now " << capturer_count_
1038 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491039
1040 // Note: This provides a hint to upstream code to size the views optimally
1041 // for quality (e.g., to avoid scaling).
1042 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1043 preferred_size_for_capture_ = capture_size;
1044 OnPreferredSizeChanged(preferred_size_);
1045 }
ccameron8807c38f2015-01-17 00:29:191046
1047 // Ensure that all views are un-occluded before capture begins.
1048 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551049}
1050
1051void WebContentsImpl::DecrementCapturerCount() {
1052 --capturer_count_;
1053 DVLOG(1) << "There are now " << capturer_count_
1054 << " capturing(s) of WebContentsImpl@" << this;
1055 DCHECK_LE(0, capturer_count_);
1056
[email protected]5a652232013-02-12 06:15:251057 if (is_being_destroyed_)
1058 return;
1059
[email protected]222f5822014-02-05 23:40:491060 if (capturer_count_ == 0) {
1061 const gfx::Size old_size = preferred_size_for_capture_;
1062 preferred_size_for_capture_ = gfx::Size();
1063 OnPreferredSizeChanged(old_size);
1064 }
1065
[email protected]1ac10dca2013-08-20 20:47:041066 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551067 DVLOG(1) << "Executing delayed WasHidden().";
1068 WasHidden();
1069 }
[email protected]be1f56ab2011-12-22 06:55:311070}
1071
[email protected]f2bd40812013-07-20 04:30:441072int WebContentsImpl::GetCapturerCount() const {
1073 return capturer_count_;
1074}
1075
miu50f97892014-09-22 22:49:521076bool WebContentsImpl::IsAudioMuted() const {
1077 return audio_muter_.get() && audio_muter_->is_muting();
1078}
1079
1080void WebContentsImpl::SetAudioMuted(bool mute) {
1081 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1082 << " for WebContentsImpl@" << this;
1083
1084 if (mute == IsAudioMuted())
1085 return;
1086
1087 if (mute) {
1088 if (!audio_muter_)
1089 audio_muter_.reset(new WebContentsAudioMuter(this));
1090 audio_muter_->StartMuting();
1091 } else {
1092 DCHECK(audio_muter_);
1093 audio_muter_->StopMuting();
1094 }
1095
1096 // Notification for UI updates in response to the changed muting state.
1097 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1098}
1099
[email protected]b172aee2012-04-10 17:05:261100bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311101 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1102 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
oshima620225722015-06-04 19:45:271103 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED
1104#if defined(OS_CHROMEOS)
1105 ||
1106 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM
1107#endif
1108 );
[email protected]3c9e1872010-11-18 16:17:491109}
1110
[email protected]b172aee2012-04-10 17:05:261111void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1112 int error_code) {
[email protected]443b80e2010-12-14 00:42:231113 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341114 return;
1115
[email protected]443b80e2010-12-14 00:42:231116 crashed_status_ = status;
1117 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211118 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341119}
1120
[email protected]b172aee2012-04-10 17:05:261121base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311122 return crashed_status_;
1123}
1124
[email protected]b172aee2012-04-10 17:05:261125bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311126 return is_being_destroyed_;
1127}
1128
[email protected]7f924832014-08-09 05:57:221129void WebContentsImpl::NotifyNavigationStateChanged(
1130 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541131 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1132 // is fixed.
1133 tracked_objects::ScopedTracker tracking_profile(
1134 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1135 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtisbc6572e12014-09-12 19:22:301136 // Create and release the audio power save blocker depending on whether the
1137 // tab is actively producing audio or not.
dalecurtis27011852015-01-06 19:52:341138 if ((changed_flags & INVALIDATE_TYPE_TAB) &&
timavf6f6f692015-03-04 02:19:371139 audio_state_provider_->IsAudioStateAvailable()) {
dalecurtisbc6572e12014-09-12 19:22:301140 if (WasRecentlyAudible()) {
1141 if (!audio_power_save_blocker_)
1142 CreateAudioPowerSaveBlocker();
1143 } else {
1144 audio_power_save_blocker_.reset();
1145 }
1146 }
1147
[email protected]d5f942ba2008-09-26 19:30:341148 if (delegate_)
1149 delegate_->NavigationStateChanged(this, changed_flags);
1150}
1151
gab0dccfef2015-05-20 18:43:391152base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021153 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331154}
1155
georgesak5582cbe2015-05-22 22:08:071156void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1157 last_active_time_ = last_active_time;
1158}
1159
[email protected]9e2e4632012-07-27 16:38:411160void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541161 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591162
ccameron8807c38f2015-01-17 00:29:191163 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1164 if (view) {
1165 view->Show();
[email protected]789e9152009-08-04 21:59:431166#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191167 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431168#endif
[email protected]de3c5d82014-05-28 22:12:591169 }
[email protected]789e9152009-08-04 21:59:431170 }
[email protected]96d185d2009-04-24 03:28:541171
gab0dccfef2015-05-20 18:43:391172 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381173
[email protected]b9769d82012-02-10 00:23:591174 // The resize rect might have changed while this was inactive -- send the new
1175 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451176 RenderViewHostImpl* rvh = GetRenderViewHost();
1177 if (rvh)
[email protected]b9769d82012-02-10 00:23:591178 rvh->ResizeRectChanged(GetRootWindowResizerRect());
[email protected]96d185d2009-04-24 03:28:541179
dalecurtisbc6572e12014-09-12 19:22:301180 // Restore power save blocker if there are active video players running.
1181 if (!active_video_players_.empty() && !video_power_save_blocker_)
1182 CreateVideoPowerSaveBlocker();
1183
[email protected]c0d9d5672013-10-09 07:38:031184 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1185
[email protected]54597982013-02-06 01:59:551186 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311187}
1188
[email protected]b172aee2012-04-10 17:05:261189void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551190 // If there are entities capturing screenshots or video (e.g., mirroring),
1191 // don't activate the "disable rendering" optimization.
1192 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521193 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551194 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261195 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521196 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331197 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521198 // calls us).
ccameron8807c38f2015-01-17 00:29:191199 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1200 if (view)
1201 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591202 }
dalecurtisbc6572e12014-09-12 19:22:301203
1204 // Release any video power save blockers held as video is not visible.
1205 video_power_save_blocker_.reset();
[email protected]96d185d2009-04-24 03:28:541206 }
1207
[email protected]c0d9d5672013-10-09 07:38:031208 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1209
[email protected]54597982013-02-06 01:59:551210 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371211}
1212
ccameron8807c38f2015-01-17 00:29:191213void WebContentsImpl::WasOccluded() {
1214 if (capturer_count_ > 0)
1215 return;
1216
1217 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1218 if (view)
1219 view->WasOccluded();
1220 }
1221}
1222
1223void WebContentsImpl::WasUnOccluded() {
1224 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1225 if (view)
1226 view->WasUnOccluded();
1227 }
1228}
1229
[email protected]b172aee2012-04-10 17:05:261230bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311231 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451232 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1233 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311234}
1235
[email protected]1c3f80bd2014-04-08 23:02:061236void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451237 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061238}
1239
lazyboy6ec48b2a2015-06-29 15:18:141240void WebContentsImpl::AttachToOuterWebContentsFrame(
1241 WebContents* outer_web_contents,
1242 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081243 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lazyboy6ec48b2a2015-06-29 15:18:141244 // Create a link to our outer WebContents.
1245 node_.reset(new WebContentsTreeNode());
1246 node_->ConnectToOuterWebContents(
1247 static_cast<WebContentsImpl*>(outer_web_contents),
1248 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1249
1250 DCHECK(outer_contents_frame);
1251
1252 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1253 // SiteInstance of the outer WebContents. The proxy will be used to send
1254 // postMessage to the inner WebContents.
1255 GetRenderManager()->CreateOuterDelegateProxy(
1256 outer_contents_frame->GetSiteInstance(),
1257 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1258
1259 GetRenderManager()->SetRWHViewForInnerContents(
1260 GetRenderManager()->GetRenderWidgetHostView());
1261}
1262
[email protected]b172aee2012-04-10 17:05:261263void WebContentsImpl::Stop() {
clamyf73862c42015-07-08 12:31:331264 frame_tree_.ForEach(base::Bind(&FrameTreeNode::StopLoading));
[email protected]d16609c2013-08-23 06:01:401265 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271266}
1267
[email protected]b172aee2012-04-10 17:05:261268WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441269 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211270 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451271 // before.
[email protected]54944cde2012-12-09 09:24:591272 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451273 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211274 WebContentsImpl* tc =
1275 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191276 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221277 FOR_EACH_OBSERVER(WebContentsObserver,
1278 observers_,
1279 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271280 return tc;
1281}
1282
[email protected]14392a52012-05-02 20:28:441283void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211284 const NotificationSource& source,
1285 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441286 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211287 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1288 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031289 RenderWidgetHostView* view = host->GetView();
1290 if (view == GetFullscreenRenderWidgetHostView()) {
1291 // We cannot just call view_->RestoreFocus() here. On some platforms,
1292 // attempting to focus the currently-invisible WebContentsView will be
1293 // flat-out ignored. Therefore, this boolean is used to track whether
1294 // we will request focus after the fullscreen widget has been
1295 // destroyed.
1296 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1297 } else {
1298 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1299 i != pending_widget_views_.end(); ++i) {
1300 if (host->GetView() == i->second) {
1301 pending_widget_views_.erase(i);
1302 break;
1303 }
[email protected]bafe6cd2012-05-23 23:09:501304 }
1305 }
1306 break;
1307 }
[email protected]14392a52012-05-02 20:28:441308 default:
1309 NOTREACHED();
1310 }
1311}
1312
[email protected]ec6c05f2013-10-23 18:41:571313WebContents* WebContentsImpl::GetWebContents() {
1314 return this;
1315}
1316
[email protected]54944cde2012-12-09 09:24:591317void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211318 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361319 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211320 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431321 should_normally_be_visible_ = !params.initially_hidden;
1322
avic2c29d782014-12-12 00:23:541323 // Either both routing ids can be given, or neither can be.
1324 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
1325 params.main_frame_routing_id == MSG_ROUTING_NONE) ||
1326 (params.routing_id != MSG_ROUTING_NONE &&
1327 params.main_frame_routing_id != MSG_ROUTING_NONE));
[email protected]fa944cb82013-11-15 17:51:211328 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041329 params.browser_context, params.site_instance, params.routing_id,
1330 params.main_frame_routing_id);
naskoc9f51dd2015-05-13 00:39:281331 frame_tree_.root()->SetFrameName(params.main_frame_name);
[email protected]d1198fd2012-08-13 22:50:191332
[email protected]fc2b46b2014-05-03 16:33:451333 WebContentsViewDelegate* delegate =
1334 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1335
lazyboy6ec48b2a2015-06-29 15:18:141336 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081337 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
[email protected]fc2b46b2014-05-03 16:33:451338 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1339 this, delegate, &render_view_host_delegate_view_));
1340
1341 WebContentsViewGuest* rv = new WebContentsViewGuest(
1342 this, browser_plugin_guest_.get(), platform_view.Pass(),
1343 render_view_host_delegate_view_);
1344 render_view_host_delegate_view_ = rv;
1345 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191346 } else {
[email protected]fc2b46b2014-05-03 16:33:451347 // Regular WebContentsView.
1348 view_.reset(CreateWebContentsView(
1349 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191350 }
[email protected]fc2b46b2014-05-03 16:33:451351 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191352 CHECK(view_.get());
1353
[email protected]ed245db2012-12-18 08:00:451354 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591355 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191356
tommyclieb25b2a2014-11-03 19:45:091357#if defined(ENABLE_PLUGINS)
1358 plugin_content_origin_whitelist_.reset(
1359 new PluginContentOriginWhitelist(this));
1360#endif
1361
[email protected]d1198fd2012-08-13 22:50:191362 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211363 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1364 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101365
[email protected]01f83f92014-06-17 14:41:541366 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091367 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541368
mlamouriefdca9d2014-09-16 16:55:401369 manifest_manager_host_.reset(new ManifestManagerHost(this));
1370
[email protected]c7654a232013-06-12 21:04:441371#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101372 date_time_chooser_.reset(new DateTimeChooserAndroid());
1373#endif
fsamuel7310a4262014-12-05 05:06:441374
1375 // BrowserPluginGuest::Init needs to be called after this WebContents has
1376 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1377 if (browser_plugin_guest_)
1378 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371379
1380 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1381 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561382
1383 // If the WebContents creation was renderer-initiated, it means that the
1384 // corresponding RenderView and main RenderFrame have already been created.
1385 // Ensure observers are notified about this.
1386 if (params.renderer_initiated_creation) {
lfg269b702f2015-06-08 19:28:191387 GetRenderViewHost()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561388 RenderViewCreated(GetRenderViewHost());
1389 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1390 }
naskof5940b9f2015-03-02 23:04:051391
1392 // Ensure that observers are notified of the creation of this WebContents's
1393 // main RenderFrameHost. It must be done here for main frames, since the
1394 // NotifySwappedFromRenderManager expects view_ to already be created and that
1395 // happens after RenderFrameHostManager::Init.
1396 NotifySwappedFromRenderManager(
1397 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191398}
1399
[email protected]7fff43e2013-05-21 20:21:101400void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1401 RemoveDestructionObserver(web_contents);
1402
[email protected]ceee8cd2013-03-08 04:59:511403 // Clear a pending contents that has been closed before being shown.
1404 for (PendingContents::iterator iter = pending_contents_.begin();
1405 iter != pending_contents_.end();
1406 ++iter) {
1407 if (iter->second != web_contents)
1408 continue;
1409 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511410 return;
1411 }
1412 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441413}
1414
[email protected]7fff43e2013-05-21 20:21:101415void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1416 if (!ContainsKey(destruction_observers_, web_contents)) {
1417 destruction_observers_[web_contents] =
1418 new DestructionObserver(this, web_contents);
1419 }
1420}
1421
1422void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1423 DestructionObservers::iterator iter =
1424 destruction_observers_.find(web_contents);
1425 if (iter != destruction_observers_.end()) {
1426 delete destruction_observers_[web_contents];
1427 destruction_observers_.erase(iter);
1428 }
1429}
1430
[email protected]b172aee2012-04-10 17:05:261431void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311432 observers_.AddObserver(observer);
1433}
1434
[email protected]b172aee2012-04-10 17:05:261435void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311436 observers_.RemoveObserver(observer);
1437}
1438
[email protected]948481d2014-06-11 18:32:221439std::set<RenderWidgetHostView*>
1440WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1441 std::set<RenderWidgetHostView*> set;
1442 if (ShowingInterstitialPage()) {
1443 set.insert(GetRenderWidgetHostView());
1444 } else {
1445 ForEachFrame(
1446 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1447 }
[email protected]de3c5d82014-05-28 22:12:591448 return set;
1449}
1450
[email protected]b172aee2012-04-10 17:05:261451void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341452 if (delegate_)
1453 delegate_->ActivateContents(this);
1454}
1455
[email protected]b172aee2012-04-10 17:05:261456void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121457 if (delegate_)
1458 delegate_->DeactivateContents(this);
1459}
1460
[email protected]b172aee2012-04-10 17:05:261461void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481462 if (delegate_)
1463 delegate_->LostCapture();
1464}
1465
[email protected]b24b68a2012-09-24 21:57:261466void WebContentsImpl::RenderWidgetDeleted(
1467 RenderWidgetHostImpl* render_widget_host) {
1468 if (is_being_destroyed_) {
1469 // |created_widgets_| might have been destroyed.
1470 return;
1471 }
1472
1473 std::set<RenderWidgetHostImpl*>::iterator iter =
1474 created_widgets_.find(render_widget_host);
1475 if (iter != created_widgets_.end())
1476 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541477
1478 if (render_widget_host &&
1479 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491480 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531481 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541482 FOR_EACH_OBSERVER(WebContentsObserver,
1483 observers_,
1484 DidDestroyFullscreenWidget(
1485 fullscreen_widget_routing_id_));
1486 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031487 if (fullscreen_widget_had_focus_at_shutdown_)
1488 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541489 }
[email protected]b24b68a2012-09-24 21:57:261490}
1491
miu9e14e492014-10-25 02:39:041492void WebContentsImpl::RenderWidgetGotFocus(
1493 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371494 // Notify the observers if an embedded fullscreen widget was focused.
1495 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1496 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1497 NotifyWebContentsFocused();
1498 }
miu9e14e492014-10-25 02:39:041499}
1500
estaded0a0c992015-01-21 14:12:061501void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311502 RenderWidgetHostImpl* render_widget_host,
1503 bool width_changed) {
creisc014b402015-04-23 16:41:451504 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291505 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061506 return;
estaded0a0c992015-01-21 14:12:061507
rouslan2f5993f2015-01-29 00:18:311508 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1509 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061510}
1511
paulmeyer9ef6e4462015-02-24 19:15:101512void WebContentsImpl::ScreenInfoChanged() {
1513 if (browser_plugin_embedder_)
1514 browser_plugin_embedder_->ScreenInfoChanged();
1515}
1516
[email protected]b172aee2012-04-10 17:05:261517bool WebContentsImpl::PreHandleKeyboardEvent(
1518 const NativeWebKeyboardEvent& event,
1519 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481520 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131521 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481522}
1523
[email protected]b172aee2012-04-10 17:05:261524void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101525 if (browser_plugin_embedder_ &&
1526 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1527 return;
1528 }
[email protected]63954792011-07-11 04:17:481529 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131530 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481531}
1532
[email protected]d92026ef2014-03-03 21:04:131533bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461534 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191535#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331536 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1537 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191538 // -the OS already has a gesture to do this through pinch-zoom
1539 // -if a user starts an inertial scroll, let's go, and presses control
1540 // (i.e. control+tab) then the OS's buffered scroll events will come in
1541 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331542 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551543 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331544 !event.canScroll) {
[email protected]fb3f066e2013-02-12 19:12:521545 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1546 return true;
1547 }
[email protected]bccc4472013-04-18 16:37:191548#endif
[email protected]fb3f066e2013-02-12 19:12:521549 return false;
1550}
1551
[email protected]04bce562014-01-30 05:34:541552bool WebContentsImpl::PreHandleGestureEvent(
1553 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031554 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541555}
1556
mlamouri7a78d6fd2015-01-17 13:23:531557void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1558 // This method is being called to enter renderer-initiated fullscreen mode.
1559 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491560 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1561 if (widget_view)
1562 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1563
[email protected]8a5e0ca2011-08-25 06:30:471564 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531565 delegate_->EnterFullscreenModeForTab(this, origin);
1566
1567 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1568 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
1569}
1570
1571void WebContentsImpl::ExitFullscreenMode() {
1572 // This method is being called to leave renderer-initiated fullscreen mode.
1573 // Make sure any existing fullscreen widget is shut down first.
1574 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1575 if (widget_view)
1576 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1577
hugo.holgersson61288e6c2015-01-28 17:04:401578#if defined(OS_ANDROID)
1579 ContentVideoView* video_view = ContentVideoView::GetInstance();
1580 if (video_view != NULL)
1581 video_view->OnExitFullscreen();
1582#endif
1583
mlamouri7a78d6fd2015-01-17 13:23:531584 if (delegate_)
1585 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371586
scheib3dcb6c932015-02-23 10:55:581587 // Ensure web contents exit fullscreen state by sending a resize message,
1588 // which includes the fullscreen state. This is required for the situation
1589 // of the browser moving the view into a fullscreen state "browser fullscreen"
1590 // and then the contents entering "tab fullscreen". Exiting the contents
1591 // "tab fullscreen" then won't have the side effect of the view resizing,
1592 // hence the explicit call here is required.
1593 if (RenderWidgetHostView* rwh_view = GetRenderWidgetHostView()) {
1594 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
1595 render_widget_host->WasResized();
1596 }
1597
[email protected]657c8e02014-03-19 19:18:371598 FOR_EACH_OBSERVER(WebContentsObserver,
1599 observers_,
1600 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471601}
1602
[email protected]b172aee2012-04-10 17:05:261603bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381604 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121605}
1606
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121607blink::WebDisplayMode WebContentsImpl::GetDisplayMode() const {
1608 return delegate_ ? delegate_->GetDisplayMode(this)
1609 : blink::WebDisplayModeBrowser;
1610}
1611
[email protected]a9c81f02012-06-01 00:15:441612void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1613 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371614 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441615 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371616 } else {
1617 GotResponseToLockMouseRequest(false);
1618 }
1619}
1620
[email protected]b172aee2012-04-10 17:05:261621void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371622 if (delegate_)
1623 delegate_->LostMouseLock();
1624}
1625
[email protected]bafe6cd2012-05-23 23:09:501626void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431627 SiteInstance* source_site_instance,
[email protected]bafe6cd2012-05-23 23:09:501628 int route_id,
[email protected]227692c52013-05-31 22:43:041629 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131630 const ViewHostMsg_CreateWindow_Params& params,
1631 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501632 // We usually create the new window in the same BrowsingInstance (group of
1633 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551634 // if the opener is being suppressed (in a non-guest), we create a new
1635 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251636 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551637
nickd30fd962015-07-27 21:51:081638 if (is_guest && BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:141639 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1640 // yet.
1641 NOTREACHED();
1642 }
1643
[email protected]04cbd3d2013-12-04 04:58:201644 // If the opener is to be suppressed, the new window can be in any process.
1645 // Since routing ids are process specific, we must not have one passed in
1646 // as argument here.
1647 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1648
[email protected]bafe6cd2012-05-23 23:09:501649 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431650 params.opener_suppressed && !is_guest
1651 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1652 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501653
alexmos4cf2aa32015-07-15 23:40:431654 // A message to create a new window can only come from a process for a frame
1655 // in this WebContents' FrameTree. If any other process sends the request, it
1656 // is invalid and the process must be terminated.
1657 int render_process_id = source_site_instance->GetProcess()->GetID();
1658 bool did_match_process = false;
1659 frame_tree_.ForEach(
1660 base::Bind(&FindMatchingProcess, render_process_id, &did_match_process));
1661 if (!did_match_process) {
1662 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351663 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201664 if (process_handle != base::kNullProcessHandle) {
1665 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391666 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351667 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201668 }
1669 return;
1670 }
1671
[email protected]d1198fd2012-08-13 22:50:191672 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341673 //
1674 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301675 const std::string& partition_id =
1676 GetContentClient()->browser()->
1677 GetStoragePartitionIdForSite(GetBrowserContext(),
1678 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461679 StoragePartition* partition = BrowserContext::GetStoragePartition(
1680 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411681 DOMStorageContextWrapper* dom_storage_context =
1682 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191683 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1684 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1685 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371686
1687 if (delegate_ &&
1688 !delegate_->ShouldCreateWebContents(this,
1689 route_id,
avic2c29d782014-12-12 00:23:541690 main_frame_route_id,
[email protected]dd6730412013-08-14 15:03:371691 params.window_container_type,
1692 params.frame_name,
1693 params.target_url,
1694 partition_id,
1695 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011696 if (route_id != MSG_ROUTING_NONE &&
1697 !RenderViewHost::FromID(render_process_id, route_id)) {
1698 // If the embedder didn't create a WebContents for this route, we need to
1699 // delete the RenderView that had already been created.
1700 Send(new ViewMsg_Close(route_id));
1701 }
[email protected]dd6730412013-08-14 15:03:371702 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1703 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1704 main_frame_route_id);
1705 return;
1706 }
1707
1708 // Create the new web contents. This will automatically create the new
1709 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461710 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591711 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041712 create_params.main_frame_routing_id = main_frame_route_id;
nasko48321ca32015-07-02 20:44:121713 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431714 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211715 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061716 create_params.opener_suppressed = params.opener_suppressed;
1717 if (params.disposition == NEW_BACKGROUND_TAB)
1718 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191719 create_params.renderer_initiated_creation =
1720 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061721
[email protected]4858e432014-06-23 18:14:171722 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551723 if (!is_guest) {
1724 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451725 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171726 new_contents = static_cast<WebContentsImpl*>(
1727 WebContents::Create(create_params));
1728 } else {
1729 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551730 }
[email protected]50d326e2014-05-20 17:59:061731 new_contents->GetController().SetSessionStorageNamespace(
1732 partition_id,
1733 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191734
alexmos646fec02015-07-25 00:11:491735 // If the new frame has a name, make sure any SiteInstances that can find
1736 // this named frame have proxies for it. Must be called after
1737 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1738 // GetSessionStorageNamespace.
1739 if (!params.frame_name.empty())
1740 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1741
[email protected]c4538072013-03-18 02:17:551742 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341743 // will be shown immediately).
1744 if (!params.opener_suppressed) {
1745 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451746 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501747
[email protected]d70bea92013-04-05 04:23:341748 // TODO(brettw): It seems bogus that we have to call this function on the
1749 // newly created object and give it one of its own member variables.
lazyboy549b3b42014-10-20 17:16:041750 new_view->CreateViewForWidget(new_contents->GetRenderViewHost(), false);
[email protected]d70bea92013-04-05 04:23:341751 }
[email protected]bafe6cd2012-05-23 23:09:501752 // Save the created window associated with the route so we can show it
1753 // later.
1754 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1755 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101756 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501757 }
1758
1759 if (delegate_) {
1760 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071761 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131762 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501763 }
1764
1765 if (params.opener_suppressed) {
1766 // When the opener is suppressed, the original renderer cannot access the
1767 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001768 bool was_blocked = false;
1769 if (delegate_) {
bokan107a47f2015-02-03 23:23:391770 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:001771 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:391772 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:001773 params.user_gesture, &was_blocked);
1774 }
1775 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211776 OpenURLParams open_params(params.target_url,
1777 Referrer(),
1778 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:351779 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:211780 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301781 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:371782
1783 if (delegate_ && !is_guest &&
1784 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
1785 // We are in asynchronous add new contents path, delay opening url
1786 new_contents->delayed_open_url_params_.reset(
1787 new OpenURLParams(open_params));
1788 } else {
1789 new_contents->OpenURL(open_params);
1790 }
[email protected]eda238a12012-09-07 23:44:001791 }
[email protected]bafe6cd2012-05-23 23:09:501792 }
1793}
1794
[email protected]a8504022013-12-04 20:23:511795void WebContentsImpl::CreateNewWidget(int render_process_id,
1796 int route_id,
[email protected]180ef242013-11-07 06:50:461797 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511798 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501799}
1800
[email protected]a8504022013-12-04 20:23:511801void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1802 int route_id) {
1803 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501804}
1805
[email protected]a8504022013-12-04 20:23:511806void WebContentsImpl::CreateNewWidget(int render_process_id,
1807 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501808 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461809 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211810 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511811 // A message to create a new widget can only come from the active process for
1812 // this WebContentsImpl instance. If any other process sends the request,
1813 // it is invalid and the process must be terminated.
1814 if (process->GetID() != render_process_id) {
jaekyun37e572a32014-12-04 23:33:351815 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
1816 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]a8504022013-12-04 20:23:511817 if (process_handle != base::kNullProcessHandle) {
1818 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391819 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
jaekyun37e572a32014-12-04 23:33:351820 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:511821 }
1822 return;
1823 }
1824
[email protected]bafe6cd2012-05-23 23:09:501825 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041826 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261827 created_widgets_.insert(widget_host);
1828
[email protected]cfd80b02014-05-01 17:46:481829 RenderWidgetHostViewBase* widget_view =
1830 static_cast<RenderWidgetHostViewBase*>(
1831 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191832 if (!widget_view)
1833 return;
[email protected]bafe6cd2012-05-23 23:09:501834 if (!is_fullscreen) {
1835 // Popups should not get activated.
1836 widget_view->SetPopupType(popup_type);
1837 }
1838 // Save the created widget associated with the route so we can show it later.
1839 pending_widget_views_[route_id] = widget_view;
1840
1841#if defined(OS_MACOSX)
1842 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1843 // to allow it to survive the trip without being hosted.
1844 base::mac::NSObjectRetain(widget_view->GetNativeView());
1845#endif
1846}
1847
1848void WebContentsImpl::ShowCreatedWindow(int route_id,
1849 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:391850 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:501851 bool user_gesture) {
1852 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001853 if (contents) {
1854 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:161855 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:381856 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
1857 contents->ResumeLoadingCreatedWebContents();
1858
[email protected]eda238a12012-09-07 23:44:001859 if (delegate) {
1860 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:391861 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:001862 }
1863 }
[email protected]bafe6cd2012-05-23 23:09:501864}
1865
1866void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:391867 const gfx::Rect& initial_rect) {
1868 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:501869}
1870
1871void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1872 ShowCreatedWidget(route_id, true, gfx::Rect());
1873}
1874
1875void WebContentsImpl::ShowCreatedWidget(int route_id,
1876 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:391877 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:481878 RenderWidgetHostViewBase* widget_host_view =
1879 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501880 if (!widget_host_view)
1881 return;
[email protected]cfd80b02014-05-01 17:46:481882
1883 RenderWidgetHostView* view = NULL;
1884 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1885 if (guest && guest->embedder_web_contents()) {
1886 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1887 } else {
1888 view = GetRenderWidgetHostView();
1889 }
1890
[email protected]4aebbca2013-09-17 22:26:491891 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311892 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031893 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311894 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491895 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1896 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:531897 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:491898 } else {
[email protected]cfd80b02014-05-01 17:46:481899 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491900 }
[email protected]4aebbca2013-09-17 22:26:491901 FOR_EACH_OBSERVER(WebContentsObserver,
1902 observers_,
1903 DidShowFullscreenWidget(route_id));
1904 if (!widget_host_view->HasFocus())
1905 widget_host_view->Focus();
1906 } else {
bokan107a47f2015-02-03 23:23:391907 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:491908 }
[email protected]89054502012-06-03 10:29:241909
1910 RenderWidgetHostImpl* render_widget_host_impl =
1911 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1912 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311913 // Only allow privileged mouse lock for fullscreen render widget, which is
1914 // used to implement Pepper Flash fullscreen.
1915 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501916
1917#if defined(OS_MACOSX)
1918 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1919 // properly embedded (or purposefully ignored) we can release the retain we
1920 // took in CreateNewWidget().
1921 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1922#endif
1923}
1924
1925WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1926 PendingContents::iterator iter = pending_contents_.find(route_id);
1927
1928 // Certain systems can block the creation of new windows. If we didn't succeed
1929 // in creating one, just return NULL.
1930 if (iter == pending_contents_.end()) {
1931 return NULL;
1932 }
1933
1934 WebContentsImpl* new_contents = iter->second;
1935 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101936 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501937
[email protected]d70bea92013-04-05 04:23:341938 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251939 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341940 return new_contents;
1941
[email protected]bafe6cd2012-05-23 23:09:501942 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1943 !new_contents->GetRenderViewHost()->GetView())
1944 return NULL;
1945
[email protected]bafe6cd2012-05-23 23:09:501946 return new_contents;
1947}
1948
1949RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1950 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1951 if (iter == pending_widget_views_.end()) {
1952 DCHECK(false);
1953 return NULL;
1954 }
1955
1956 RenderWidgetHostView* widget_host_view = iter->second;
1957 pending_widget_views_.erase(route_id);
1958
1959 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1960 if (!widget_host->GetProcess()->HasConnection()) {
1961 // The view has gone away or the renderer crashed. Nothing to do.
1962 return NULL;
1963 }
1964
1965 return widget_host_view;
1966}
1967
[email protected]f13b4202012-06-12 23:53:231968void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091969 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211970 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371971 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231972 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371973 } else {
1974 callback.Run(MediaStreamDevices(),
grunelle544e132014-09-25 22:30:041975 MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
[email protected]d19b84b2014-03-14 11:52:371976 scoped_ptr<MediaStreamUI>());
1977 }
[email protected]f13b4202012-06-12 23:53:231978}
1979
grunell657d4d82014-09-18 00:09:431980bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
1981 MediaStreamType type) {
1982 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
1983 type == MEDIA_DEVICE_VIDEO_CAPTURE);
1984 return delegate_ &&
1985 delegate_->CheckMediaAccessPermission(this, security_origin, type);
1986}
1987
[email protected]cc9200432013-07-23 23:02:401988SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1989 SiteInstance* instance) {
1990 return controller_.GetSessionStorageNamespace(instance);
1991}
1992
[email protected]6de7fc482014-06-06 10:46:441993SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1994 return controller_.GetSessionStorageNamespaceMap();
1995}
1996
[email protected]9b159a52013-10-03 17:24:551997FrameTree* WebContentsImpl::GetFrameTree() {
1998 return &frame_tree_;
1999}
2000
lukendc35e7f2014-11-10 19:06:142001void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2002 virtual_keyboard_requested_ = requested;
2003}
2004
2005bool WebContentsImpl::IsVirtualKeyboardRequested() {
2006 return virtual_keyboard_requested_;
2007}
2008
[email protected]95640212014-07-26 18:14:302009AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2010 return accessibility_mode_;
2011}
2012
[email protected]31a71eaf2014-03-13 01:47:362013void WebContentsImpl::AccessibilityEventReceived(
2014 const std::vector<AXEventNotificationDetails>& details) {
2015 FOR_EACH_OBSERVER(
2016 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2017}
2018
dmazzonia656928e2014-09-15 20:28:542019RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402020 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542021 int browser_plugin_instance_id) {
2022 BrowserPluginGuestManager* guest_manager =
2023 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202024 if (!guest_manager)
2025 return nullptr;
2026
dmazzonia656928e2014-09-15 20:28:542027 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442028 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542029 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202030 return nullptr;
2031
dmazzonia656928e2014-09-15 20:28:542032 return guest->GetMainFrame();
2033}
2034
blundellc57b93f2014-10-29 13:19:572035GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2036 return geolocation_service_context_.get();
2037}
2038
[email protected]edc3af82013-12-12 21:24:072039void WebContentsImpl::OnShowValidationMessage(
2040 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292041 const base::string16& main_text,
2042 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072043 if (delegate_)
2044 delegate_->ShowValidationMessage(
2045 this, anchor_in_root_view, main_text, sub_text);
2046}
2047
2048void WebContentsImpl::OnHideValidationMessage() {
2049 if (delegate_)
2050 delegate_->HideValidationMessage(this);
2051}
2052
2053void WebContentsImpl::OnMoveValidationMessage(
2054 const gfx::Rect& anchor_in_root_view) {
2055 if (delegate_)
2056 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2057}
2058
[email protected]32deec62013-05-15 23:55:042059void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
2060 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442061 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042062}
2063
[email protected]95640212014-07-26 18:14:302064BrowserAccessibilityManager*
2065 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452066 RenderFrameHostImpl* rfh = GetMainFrame();
2067 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302068}
2069
2070BrowserAccessibilityManager*
2071 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452072 RenderFrameHostImpl* rfh = GetMainFrame();
2073 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302074}
2075
mohsen7ab1ec16ec2015-07-02 18:26:232076void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2077 RenderFrameHost* focused_frame = GetFocusedFrame();
2078 if (!focused_frame)
2079 return;
2080
2081 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2082 focused_frame->GetRoutingID(), extent));
2083}
2084
2085void WebContentsImpl::SelectRange(const gfx::Point& base,
2086 const gfx::Point& extent) {
2087 RenderFrameHost* focused_frame = GetFocusedFrame();
2088 if (!focused_frame)
2089 return;
2090
2091 focused_frame->Send(
2092 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2093}
2094
aurimasab0319022015-07-10 21:57:382095void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2096 int end_adjust) {
2097 RenderFrameHost* focused_frame = GetFocusedFrame();
2098 if (!focused_frame)
2099 return;
2100
2101 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2102 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2103}
2104
[email protected]b172aee2012-04-10 17:05:262105void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492106 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232107 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492108 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332109}
2110
[email protected]b172aee2012-04-10 17:05:262111void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:342112 if (delegate_)
2113 delegate_->ResizeDueToAutoResize(this, new_size);
2114}
2115
[email protected]b172aee2012-04-10 17:05:262116WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202117 if (!delegate_)
2118 return NULL;
[email protected]00c37fc2011-08-02 00:22:502119
[email protected]e5d549d2011-12-28 01:29:202120 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202121 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342122}
2123
[email protected]6b618e62012-08-16 12:59:182124bool WebContentsImpl::Send(IPC::Message* message) {
2125 if (!GetRenderViewHost()) {
2126 delete message;
2127 return false;
2128 }
2129
2130 return GetRenderViewHost()->Send(message);
2131}
2132
[email protected]a86c0e962013-12-17 17:10:392133void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2134 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442135 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392136 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442137}
2138
[email protected]20ca0382013-02-28 19:50:072139void WebContentsImpl::AttachInterstitialPage(
2140 InterstitialPageImpl* interstitial_page) {
2141 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212142 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292143
2144 // Cancel any visible dialogs so that they don't interfere with the
2145 // interstitial.
creis89a0f782015-05-27 16:13:172146 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292147
[email protected]20ca0382013-02-28 19:50:072148 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2149 DidAttachInterstitialPage());
2150}
2151
2152void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:572153 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212154 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072155 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2156 DidDetachInterstitialPage());
2157}
2158
avi2b177592014-12-10 02:08:022159void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2160 int history_length) {
2161 SetHistoryOffsetAndLengthForView(
2162 GetRenderViewHost(), history_offset, history_length);
2163}
2164
2165void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2166 RenderViewHost* render_view_host,
2167 int history_offset,
2168 int history_length) {
2169 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2170 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142171}
2172
[email protected]4fed3702014-04-01 09:08:002173void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172174 RenderFrameHost* focused_frame = GetFocusedFrame();
2175 if (!focused_frame)
2176 return;
2177
[email protected]959be4c2014-04-08 15:01:332178 focused_frame->Send(new FrameMsg_Reload(
2179 focused_frame->GetRoutingID(), ignore_cache));
2180}
2181
2182void WebContentsImpl::Undo() {
2183 RenderFrameHost* focused_frame = GetFocusedFrame();
2184 if (!focused_frame)
2185 return;
2186
2187 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2188 RecordAction(base::UserMetricsAction("Undo"));
2189}
2190
2191void WebContentsImpl::Redo() {
2192 RenderFrameHost* focused_frame = GetFocusedFrame();
2193 if (!focused_frame)
2194 return;
2195 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2196 RecordAction(base::UserMetricsAction("Redo"));
2197}
2198
2199void WebContentsImpl::Cut() {
2200 RenderFrameHost* focused_frame = GetFocusedFrame();
2201 if (!focused_frame)
2202 return;
2203
2204 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2205 RecordAction(base::UserMetricsAction("Cut"));
2206}
2207
2208void WebContentsImpl::Copy() {
2209 RenderFrameHost* focused_frame = GetFocusedFrame();
2210 if (!focused_frame)
2211 return;
2212
2213 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2214 RecordAction(base::UserMetricsAction("Copy"));
2215}
2216
2217void WebContentsImpl::CopyToFindPboard() {
2218#if defined(OS_MACOSX)
2219 RenderFrameHost* focused_frame = GetFocusedFrame();
2220 if (!focused_frame)
2221 return;
2222
2223 // Windows/Linux don't have the concept of a find pasteboard.
2224 focused_frame->Send(
2225 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2226 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2227#endif
2228}
2229
2230void WebContentsImpl::Paste() {
2231 RenderFrameHost* focused_frame = GetFocusedFrame();
2232 if (!focused_frame)
2233 return;
2234
2235 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2236 RecordAction(base::UserMetricsAction("Paste"));
2237}
2238
2239void WebContentsImpl::PasteAndMatchStyle() {
2240 RenderFrameHost* focused_frame = GetFocusedFrame();
2241 if (!focused_frame)
2242 return;
2243
2244 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2245 focused_frame->GetRoutingID()));
2246 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2247}
2248
2249void WebContentsImpl::Delete() {
2250 RenderFrameHost* focused_frame = GetFocusedFrame();
2251 if (!focused_frame)
2252 return;
2253
2254 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2255 RecordAction(base::UserMetricsAction("DeleteSelection"));
2256}
2257
2258void WebContentsImpl::SelectAll() {
2259 RenderFrameHost* focused_frame = GetFocusedFrame();
2260 if (!focused_frame)
2261 return;
2262
2263 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2264 RecordAction(base::UserMetricsAction("SelectAll"));
2265}
2266
2267void WebContentsImpl::Unselect() {
2268 RenderFrameHost* focused_frame = GetFocusedFrame();
2269 if (!focused_frame)
2270 return;
2271
2272 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2273 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172274}
2275
2276void WebContentsImpl::Replace(const base::string16& word) {
2277 RenderFrameHost* focused_frame = GetFocusedFrame();
2278 if (!focused_frame)
2279 return;
2280
[email protected]959be4c2014-04-08 15:01:332281 focused_frame->Send(new InputMsg_Replace(
2282 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172283}
2284
2285void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2286 RenderFrameHost* focused_frame = GetFocusedFrame();
2287 if (!focused_frame)
2288 return;
2289
[email protected]959be4c2014-04-08 15:01:332290 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2291 focused_frame->GetRoutingID(), word));
2292}
2293
2294void WebContentsImpl::NotifyContextMenuClosed(
2295 const CustomContextMenuContext& context) {
2296 RenderFrameHost* focused_frame = GetFocusedFrame();
2297 if (!focused_frame)
2298 return;
2299
2300 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2301 focused_frame->GetRoutingID(), context));
2302}
2303
2304void WebContentsImpl::ExecuteCustomContextMenuCommand(
2305 int action, const CustomContextMenuContext& context) {
2306 RenderFrameHost* focused_frame = GetFocusedFrame();
2307 if (!focused_frame)
2308 return;
2309
2310 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2311 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002312}
2313
[email protected]fc2b46b2014-05-03 16:33:452314gfx::NativeView WebContentsImpl::GetNativeView() {
2315 return view_->GetNativeView();
2316}
2317
2318gfx::NativeView WebContentsImpl::GetContentNativeView() {
2319 return view_->GetContentNativeView();
2320}
2321
2322gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2323 return view_->GetTopLevelNativeWindow();
2324}
2325
2326gfx::Rect WebContentsImpl::GetViewBounds() {
2327 return view_->GetViewBounds();
2328}
2329
2330gfx::Rect WebContentsImpl::GetContainerBounds() {
2331 gfx::Rect rv;
2332 view_->GetContainerBounds(&rv);
2333 return rv;
2334}
2335
2336DropData* WebContentsImpl::GetDropData() {
2337 return view_->GetDropData();
2338}
2339
2340void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042341 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452342}
2343
2344void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042345 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452346}
2347
2348void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042349 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452350}
2351
2352void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042353 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452354}
2355
[email protected]b172aee2012-04-10 17:05:262356void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272357 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212358 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542359 return;
2360 }
[email protected]0b431992014-06-24 00:08:032361 RenderWidgetHostView* const fullscreen_view =
2362 GetFullscreenRenderWidgetHostView();
2363 if (fullscreen_view) {
2364 fullscreen_view->Focus();
2365 return;
2366 }
creisc014b402015-04-23 16:41:452367 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542368}
2369
[email protected]b172aee2012-04-10 17:05:262370bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212371 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542372}
2373
[email protected]b172aee2012-04-10 17:05:262374InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212375 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222376}
2377
[email protected]b172aee2012-04-10 17:05:262378bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162379 // WebKit creates Document object when MIME type is application/xhtml+xml,
2380 // so we also support this MIME type.
2381 return contents_mime_type_ == "text/html" ||
2382 contents_mime_type_ == "text/xml" ||
2383 contents_mime_type_ == "application/xhtml+xml" ||
2384 contents_mime_type_ == "text/plain" ||
2385 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252386 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162387}
2388
[email protected]b172aee2012-04-10 17:05:262389void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592390 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162391 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552392 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192393 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142394 return;
[email protected]c7dd2f62011-07-18 15:57:592395 }
2396
2397 Stop();
2398
2399 // Create the save package and possibly prompt the user for the name to save
2400 // the page as. The user prompt is an asynchronous operation that runs on
2401 // another thread.
2402 save_package_ = new SavePackage(this);
2403 save_package_->GetSaveInfo();
2404}
2405
2406// Used in automated testing to bypass prompting the user for file names.
2407// Instead, the names and paths are hard coded rather than running them through
2408// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342409bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2410 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212411 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592412 // Stop the page from navigating.
2413 Stop();
2414
2415 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212416 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592417}
2418
[email protected]3c71576ce2013-07-23 02:00:012419void WebContentsImpl::SaveFrame(const GURL& url,
2420 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372421 SaveFrameWithHeaders(url, referrer, std::string());
2422}
2423
2424void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2425 const Referrer& referrer,
2426 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192427 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012428 return;
sammc92af61552014-11-19 23:27:402429 if (delegate_ && delegate_->SaveFrame(url, referrer))
2430 return;
2431
nasko89ad7742015-03-05 22:14:192432 // TODO(nasko): This check for main frame is incorrect and should be fixed
2433 // by explicitly passing in which frame this method should target.
2434 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012435
2436 DownloadManager* dlm =
2437 BrowserContext::GetDownloadManager(GetBrowserContext());
2438 if (!dlm)
2439 return;
2440 int64 post_id = -1;
2441 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272442 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012443 if (entry)
2444 post_id = entry->GetPostID();
2445 }
2446 scoped_ptr<DownloadUrlParameters> params(
2447 DownloadUrlParameters::FromWebContents(this, url));
2448 params->set_referrer(referrer);
2449 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012450 if (post_id >= 0)
2451 params->set_method("POST");
2452 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372453
2454 if (headers.empty()) {
2455 params->set_prefer_cache(true);
2456 } else {
2457 std::vector<std::string> key_value_list;
2458 base::SplitString(headers, '\n', &key_value_list);
2459 for (const auto& key_value : key_value_list) {
2460 std::vector<std::string> pair;
2461 base::SplitString(key_value, ':', &pair);
2462 DCHECK_EQ(2ul, pair.size());
2463 params->add_request_header(pair[0], pair[1]);
2464 }
2465 }
[email protected]3c71576ce2013-07-23 02:00:012466 dlm->DownloadUrl(params.Pass());
2467}
2468
[email protected]b172aee2012-04-10 17:05:262469void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342470 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482471 const base::Callback<void(int64)>& callback) {
2472 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122473}
2474
[email protected]b172aee2012-04-10 17:05:262475const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272476 return contents_mime_type_;
2477}
2478
[email protected]b172aee2012-04-10 17:05:262479bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272480 return notify_disconnection_;
2481}
2482
[email protected]b172aee2012-04-10 17:05:262483void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312484 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182485 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162486}
2487
[email protected]b172aee2012-04-10 17:05:262488void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542489 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182490 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162491}
2492
[email protected]8ff00d72012-10-23 19:12:212493RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272494 return &renderer_preferences_;
2495}
2496
[email protected]e35ccd52012-05-23 16:22:472497void WebContentsImpl::Close() {
2498 Close(GetRenderViewHost());
2499}
2500
[email protected]cf200a562013-05-03 16:24:292501void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462502 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292503 if (browser_plugin_embedder_.get())
2504 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2505 screen_x, screen_y, operation);
2506 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452507 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2508 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292509}
2510
[email protected]d60f3702013-12-26 16:30:242511void WebContentsImpl::DidGetResourceResponseStart(
2512 const ResourceRequestDetails& details) {
2513 controller_.ssl_manager()->DidStartResourceResponse(details);
2514
2515 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2516 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242517}
2518
2519void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462520 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242521 const ResourceRedirectDetails& details) {
2522 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2523
2524 FOR_EACH_OBSERVER(
2525 WebContentsObserver,
2526 observers_,
creis114ca1b2014-11-13 23:51:462527 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242528
2529 // TODO(avi): Remove. http://crbug.com/170921
2530 NotificationService::current()->Notify(
2531 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2532 Source<WebContents>(this),
2533 Details<const ResourceRedirectDetails>(&details));
2534}
2535
calamity7fe55ce2015-04-10 03:59:372536void WebContentsImpl::NotifyWebContentsFocused() {
2537 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2538}
2539
[email protected]b172aee2012-04-10 17:05:262540void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522541 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452542 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292543 if (browser_plugin_embedder_.get())
2544 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342545}
2546
[email protected]e35ccd52012-05-23 16:22:472547void WebContentsImpl::UserGestureDone() {
2548 OnUserGesture();
2549}
2550
[email protected]b172aee2012-04-10 17:05:262551void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272552 closed_by_user_gesture_ = value;
2553}
2554
[email protected]b172aee2012-04-10 17:05:262555bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272556 return closed_by_user_gesture_;
2557}
2558
[email protected]b172aee2012-04-10 17:05:262559void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502560 if (!delegate_)
2561 return;
2562
[email protected]6286a372013-10-09 04:03:272563 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2564 if (!entry)
[email protected]1788e772010-12-15 16:40:502565 return;
2566
[email protected]6286a372013-10-09 04:03:272567 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122568}
2569
[email protected]b172aee2012-04-10 17:05:262570void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042571 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272572 if (!delegate_)
2573 return;
2574
[email protected]691aa2f2013-05-28 22:52:042575 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272576}
2577
[email protected]b172aee2012-04-10 17:05:262578int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272579 return minimum_zoom_percent_;
2580}
2581
[email protected]b172aee2012-04-10 17:05:262582int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272583 return maximum_zoom_percent_;
2584}
2585
ccameronb7c1d6c2015-03-09 17:08:242586void WebContentsImpl::ResetPageScale() {
2587 Send(new ViewMsg_ResetPageScale(GetRoutingID()));
2588}
2589
[email protected]b172aee2012-04-10 17:05:262590gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492591 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232592}
2593
[email protected]b172aee2012-04-10 17:05:262594bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052595 if (GetBrowserPluginGuest())
2596 return GetBrowserPluginGuest()->LockMouse(allowed);
2597
creisc014b402015-04-23 16:41:452598 return GetRenderViewHost()
2599 ? GetRenderViewHost()->GotResponseToLockMouseRequest(allowed)
2600 : false;
[email protected]0bfbf882011-12-22 18:19:272601}
2602
[email protected]b172aee2012-04-10 17:05:262603bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212604 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502605}
2606
alexmose201c7cd2015-06-10 17:14:212607WebContentsImpl* WebContentsImpl::GetOpener() const {
2608 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2609 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572610}
2611
[email protected]cb805452013-05-22 15:16:212612void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482613 if (!color_chooser_info_.get())
2614 return;
2615 RenderFrameHost* rfh = RenderFrameHost::FromID(
2616 color_chooser_info_->render_process_id,
2617 color_chooser_info_->render_frame_id);
2618 if (!rfh)
2619 return;
2620
2621 rfh->Send(new FrameMsg_DidChooseColorResponse(
2622 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202623}
2624
[email protected]cb805452013-05-22 15:16:212625void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482626 if (!color_chooser_info_.get())
2627 return;
2628 RenderFrameHost* rfh = RenderFrameHost::FromID(
2629 color_chooser_info_->render_process_id,
2630 color_chooser_info_->render_frame_id);
2631 if (!rfh)
2632 return;
2633
2634 rfh->Send(new FrameMsg_DidEndColorChooser(
2635 rfh->GetRoutingID(), color_chooser_info_->identifier));
2636 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202637}
2638
halton.huoca2eabd2015-07-06 08:17:402639int WebContentsImpl::DownloadImage(
2640 const GURL& url,
2641 bool is_favicon,
2642 uint32_t max_bitmap_size,
2643 bool bypass_cache,
2644 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552645 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402646 static int next_image_download_id = 0;
2647 const image_downloader::ImageDownloaderPtr& mojo_image_downloader =
2648 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552649 const int download_id = ++next_image_download_id;
2650 if (!mojo_image_downloader) {
2651 // If the renderer process is dead (i.e. crash, or memory pressure on
2652 // Android), the downloader service will be invalid. Pre-Mojo, this would
2653 // hang the callback indefinetly since the IPC would be dropped. Now,
2654 // respond with a 400 HTTP error code to indicate that something went wrong.
2655 BrowserThread::PostTask(
2656 BrowserThread::UI, FROM_HERE,
2657 base::Bind(&WebContents::ImageDownloadCallback::Run,
2658 base::Owned(new ImageDownloadCallback(callback)),
2659 download_id, 400, url, std::vector<SkBitmap>(),
2660 std::vector<gfx::Size>()));
2661 return download_id;
2662 }
2663
halton.huoca2eabd2015-07-06 08:17:402664 image_downloader::DownloadRequestPtr req =
2665 image_downloader::DownloadRequest::New();
2666
2667 req->url = mojo::String::From(url);
2668 req->is_favicon = is_favicon;
2669 req->max_bitmap_size = max_bitmap_size;
2670 req->bypass_cache = bypass_cache;
2671
2672 mojo_image_downloader->DownloadImage(
2673 req.Pass(),
amistry9f01b772015-07-29 01:54:552674 base::Bind(&DidDownloadImage, callback, download_id, url));
2675 return download_id;
[email protected]795c28972012-12-06 06:13:392676}
2677
[email protected]5dcaf8e2013-12-28 01:31:422678bool WebContentsImpl::IsSubframe() const {
2679 return is_subframe_;
2680}
2681
[email protected]36ec24f2014-01-09 00:32:082682void WebContentsImpl::Find(int request_id,
2683 const base::string16& search_text,
2684 const blink::WebFindOptions& options) {
raymes0fa0be52014-10-13 20:38:092685 // See if a top level browser plugin handles the find request first.
raymes5491de12015-04-17 02:01:302686 if (browser_plugin_embedder_) {
2687 BrowserPluginGuest* guest = browser_plugin_embedder_->GetFullPageGuest();
2688 if (guest && guest->Find(request_id, search_text, options))
2689 return;
raymes0fa0be52014-10-13 20:38:092690 }
[email protected]36ec24f2014-01-09 00:32:082691 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2692}
2693
2694void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:012695 // See if a top level browser plugin handles the stop finding request first.
raymes5491de12015-04-17 02:01:302696 if (browser_plugin_embedder_) {
2697 BrowserPluginGuest* guest = browser_plugin_embedder_->GetFullPageGuest();
2698 if (guest && guest->StopFinding(action))
2699 return;
raymes2bc64182015-02-06 01:23:012700 }
[email protected]36ec24f2014-01-09 00:32:082701 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2702}
2703
[email protected]4fe53add2014-04-08 19:53:362704void WebContentsImpl::InsertCSS(const std::string& css) {
2705 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2706 GetMainFrame()->GetRoutingID(), css));
2707}
2708
dalecurtisbc6572e12014-09-12 19:22:302709bool WebContentsImpl::WasRecentlyAudible() {
timavf6f6f692015-03-04 02:19:372710 return audio_state_provider_->WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:302711}
2712
mlamouriefdca9d2014-09-16 16:55:402713void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
2714 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
2715}
2716
mlamouri7a78d6fd2015-01-17 13:23:532717void WebContentsImpl::ExitFullscreen() {
2718 // Clean up related state and initiate the fullscreen exit.
creisc014b402015-04-23 16:41:452719 GetRenderViewHost()->RejectMouseLockOrUnlockIfNecessary();
mlamouri7a78d6fd2015-01-17 13:23:532720 ExitFullscreenMode();
2721}
2722
mariakhomenko44bdc4732015-04-29 01:55:382723void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:372724 if (delayed_open_url_params_.get()) {
2725 OpenURL(*delayed_open_url_params_.get());
2726 delayed_open_url_params_.reset(nullptr);
2727 return;
2728 }
2729
mariakhomenko44bdc4732015-04-29 01:55:382730 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
2731 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:162732 if (is_resume_pending_) {
2733 is_resume_pending_ = false;
2734 GetRenderViewHost()->Init();
2735 GetMainFrame()->Init();
2736 }
mariakhomenko44bdc4732015-04-29 01:55:382737}
2738
[email protected]b172aee2012-04-10 17:05:262739bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272740 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172741 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332742 return true;
2743 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272744}
2745
[email protected]b172aee2012-04-10 17:05:262746void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272747 if (delegate_)
2748 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212749}
2750
[email protected]52913802013-12-10 05:52:182751void WebContentsImpl::DidStartProvisionalLoad(
2752 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:182753 const GURL& validated_url,
2754 bool is_error_page,
2755 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:102756 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482757 FOR_EACH_OBSERVER(
2758 WebContentsObserver,
2759 observers_,
2760 DidStartProvisionalLoadForFrame(
2761 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:082762
2763 // Notify accessibility if this is a reload.
2764 NavigationEntry* entry = controller_.GetVisibleEntry();
2765 if (entry && ui::PageTransitionCoreTypeIs(
2766 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
2767 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2768 BrowserAccessibilityManager* manager =
2769 ftn->current_frame_host()->browser_accessibility_manager();
2770 if (manager)
2771 manager->UserIsReloading();
2772 }
[email protected]400992b2012-06-14 00:03:542773}
2774
[email protected]3109fbb72014-01-06 23:57:152775void WebContentsImpl::DidFailProvisionalLoadWithError(
2776 RenderFrameHostImpl* render_frame_host,
2777 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2778 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:312779 FOR_EACH_OBSERVER(WebContentsObserver,
2780 observers_,
2781 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:312782 validated_url,
2783 params.error_code,
gsennton6fbb38692015-06-24 19:23:552784 params.error_description,
2785 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:082786
2787 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
2788 BrowserAccessibilityManager* manager =
2789 ftn->current_frame_host()->browser_accessibility_manager();
2790 if (manager)
2791 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:152792}
2793
[email protected]b80624c2014-02-09 02:46:552794void WebContentsImpl::DidFailLoadWithError(
2795 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552796 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552797 int error_code,
gsennton6fbb38692015-06-24 19:23:552798 const base::string16& error_description,
2799 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:142800 FOR_EACH_OBSERVER(
2801 WebContentsObserver,
2802 observers_,
gsennton6fbb38692015-06-24 19:23:552803 DidFailLoad(render_frame_host, url, error_code, error_description,
2804 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:552805}
2806
[email protected]52913802013-12-10 05:52:182807void WebContentsImpl::NotifyChangedNavigationState(
2808 InvalidateTypes changed_flags) {
2809 NotifyNavigationStateChanged(changed_flags);
2810}
2811
[email protected]3691e5cf2014-01-22 10:16:202812void WebContentsImpl::AboutToNavigateRenderFrame(
pfeldmanf87691a2015-01-23 16:58:172813 RenderFrameHostImpl* old_host,
2814 RenderFrameHostImpl* new_host) {
creis114ca1b2014-11-13 23:51:462815 // Notify observers that we will navigate in this RenderFrame.
[email protected]3691e5cf2014-01-22 10:16:202816 FOR_EACH_OBSERVER(
2817 WebContentsObserver,
2818 observers_,
pfeldmanf87691a2015-01-23 16:58:172819 AboutToNavigateRenderFrame(old_host, new_host));
[email protected]3691e5cf2014-01-22 10:16:202820}
2821
2822void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:202823 const GURL& url,
2824 NavigationController::ReloadType reload_type) {
2825 // Notify observers about navigation.
2826 FOR_EACH_OBSERVER(
2827 WebContentsObserver,
2828 observers_,
2829 DidStartNavigationToPendingEntry(url, reload_type));
2830}
2831
[email protected]8cb834e2014-03-06 14:23:232832void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2833 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:502834 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
2835 // weak pointer of sorts.
2836 const int32_t process_id = render_frame_host->GetProcess()->GetID();
2837 const int32_t frame_id = render_frame_host->GetRoutingID();
2838
[email protected]65920f332014-03-04 21:14:182839 WebContents* new_contents = OpenURL(params);
2840
dchengb907f7332015-01-07 20:35:502841 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:182842 // Notify observers.
2843 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2844 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:462845 render_frame_host,
[email protected]65920f332014-03-04 21:14:182846 params.url,
2847 params.referrer,
2848 params.disposition,
creis114ca1b2014-11-13 23:51:462849 params.transition));
[email protected]65920f332014-03-04 21:14:182850 }
2851}
2852
[email protected]aa62afd2014-04-22 19:22:462853bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2854 if (!delegate_)
2855 return false;
2856 return delegate_->ShouldPreserveAbortedURLs(this);
2857}
2858
[email protected]37567b432014-02-12 01:12:222859void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432860 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222861 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352862 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222863 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:482864 FOR_EACH_OBSERVER(WebContentsObserver,
2865 observers_,
2866 DidCommitProvisionalLoadForFrame(
2867 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:082868
2869 BrowserAccessibilityManager* manager =
2870 render_frame_host->browser_accessibility_manager();
2871 if (manager)
2872 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:222873}
2874
[email protected]0d0f4c492014-04-02 06:42:572875void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232876 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572877 // Ensure fullscreen mode is exited before committing the navigation to a
2878 // different page. The next page will not start out assuming it is in
2879 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232880 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192881 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572882 return;
2883 }
2884 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:532885 ExitFullscreen();
[email protected]0d0f4c492014-04-02 06:42:572886 DCHECK(!IsFullscreenForCurrentTab());
2887}
2888
[email protected]37567b432014-02-12 01:12:222889void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:282890 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222891 const LoadCommittedDetails& details,
2892 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2893 if (details.is_navigation_to_different_page()) {
2894 // Clear the status bubble. This is a workaround for a bug where WebKit
2895 // doesn't let us know that the cursor left an element during a
2896 // transition (this is also why the mouse cursor remains as a hand after
2897 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2898 // clear the bubble when a user navigates to a named anchor in the same
2899 // page.
sky8b00392d2015-01-10 00:30:282900 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:002901
2902 RenderWidgetHostViewBase* rwhvb =
2903 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2904 if (rwhvb)
2905 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:282906
peter90afaba2015-06-01 12:05:292907 did_first_visually_non_empty_paint_ = false;
2908
yusufod41c5f92015-03-06 00:14:282909 // Reset theme color on navigation to new page.
2910 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:222911 }
2912
2913 if (!details.is_in_page) {
2914 // Once the main frame is navigated, we're no longer considered to have
2915 // displayed insecure content.
2916 displayed_insecure_content_ = false;
2917 SSLManager::NotifySSLInternalStateChanged(
2918 GetController().GetBrowserContext());
2919 }
2920
2921 // Notify observers about navigation.
2922 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2923 DidNavigateMainFrame(details, params));
2924
[email protected]e85165c642014-06-10 14:34:312925 if (delegate_)
[email protected]37567b432014-02-12 01:12:222926 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312927 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222928}
2929
2930void WebContentsImpl::DidNavigateAnyFramePostCommit(
2931 RenderFrameHostImpl* render_frame_host,
2932 const LoadCommittedDetails& details,
2933 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102934 // Now that something has committed, we don't need to track whether the
2935 // initial page has been accessed.
2936 has_accessed_initial_document_ = false;
2937
[email protected]37567b432014-02-12 01:12:222938 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:172939 if (!details.is_in_page)
2940 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:222941
2942 // Notify observers about navigation.
2943 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:092944 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:222945}
2946
2947void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2948 contents_mime_type_ = mime_type;
2949}
2950
[email protected]277857a2014-06-03 10:38:012951bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312952 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:052953 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:312954 return false;
2955
[email protected]37567b432014-02-12 01:12:222956 if (delegate_)
2957 return delegate_->CanOverscrollContent();
2958
2959 return false;
2960}
2961
[email protected]37b64c52014-07-11 21:14:052962void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:292963 // Update the theme color. This is to be published to observers after the
2964 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:282965 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:292966
2967 if (did_first_visually_non_empty_paint_ &&
2968 last_sent_theme_color_ != theme_color_) {
2969 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2970 DidChangeThemeColor(theme_color_));
2971 last_sent_theme_color_ = theme_color_;
2972 }
[email protected]e7104762014-06-20 19:17:252973}
2974
[email protected]b172aee2012-04-10 17:05:262975void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182976 const GURL& url,
[email protected]70435962011-08-02 20:13:282977 const std::string& security_info,
2978 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182979 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:402980 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:532981 SSLStatus status;
2982 if (!DeserializeSecurityInfo(security_info, &status)) {
2983 bad_message::ReceivedBadMessage(
2984 GetRenderProcessHost(),
2985 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
2986 return;
2987 }
[email protected]724159a2010-12-30 01:11:182988
2989 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:592990 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:212991 LoadFromMemoryCacheDetails details(
avie0d90182015-07-08 19:33:592992 url, GetRenderProcessHost()->GetID(), status.cert_id, status.cert_status,
2993 http_method, mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182994
[email protected]b0f724c2013-09-05 04:21:132995 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2996
2997 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2998 DidLoadResourceFromMemoryCache(details));
2999
[email protected]8bfc8272013-09-09 20:10:533000 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3001 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403002 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533003 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3004 GetRenderProcessHost()->GetID()) :
3005 GetBrowserContext()->GetRequestContextForRenderProcess(
3006 GetRenderProcessHost()->GetID()));
3007 BrowserThread::PostTask(
3008 BrowserThread::IO,
3009 FROM_HERE,
3010 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3011 }
[email protected]724159a2010-12-30 01:11:183012}
3013
[email protected]b172aee2012-04-10 17:05:263014void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393015 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183016 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193017 SSLManager::NotifySSLInternalStateChanged(
3018 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183019}
3020
[email protected]b172aee2012-04-10 17:05:263021void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:023022 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583023 LOG(WARNING) << security_origin << " ran insecure content from "
3024 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393025 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
brettwa7ff1b292015-07-16 17:49:293026 if (base::EndsWith(security_origin, kDotGoogleDotCom,
3027 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393028 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183029 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:413030 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193031 SSLManager::NotifySSLInternalStateChanged(
3032 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183033}
3034
[email protected]501052ff2014-02-21 22:19:073035void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113036 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473037 return;
naskofbd033392015-01-27 02:34:473038
[email protected]1d62cf72014-02-07 21:31:573039 RenderFrameHostImpl* rfh =
3040 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143041 FOR_EACH_OBSERVER(
3042 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183043}
3044
naskofbd033392015-01-27 02:34:473045void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113046 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123047 return;
[email protected]a1b99262013-12-27 21:56:223048
[email protected]8b3af1e2014-01-24 13:29:123049 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443050 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373051 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423052 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373053
[email protected]61ac9e242014-03-21 20:55:263054 RenderFrameHostImpl* rfh =
3055 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143056 FOR_EACH_OBSERVER(
3057 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313058}
3059
[email protected]b172aee2012-04-10 17:05:263060void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573061 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3062 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263063}
3064
[email protected]b172aee2012-04-10 17:05:263065void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303066 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263067 minimum_zoom_percent_ = minimum_percent;
3068 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263069}
3070
[email protected]b172aee2012-04-10 17:05:263071void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343072 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433073 if (!delegate_)
3074 return;
3075
[email protected]b9535422012-02-09 01:47:593076 ChildProcessSecurityPolicyImpl* policy =
3077 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223078 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593079 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213080}
3081
[email protected]b172aee2012-04-10 17:05:263082void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3083 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263084 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363085 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433086 if (!delegate_)
3087 return;
3088
[email protected]b9535422012-02-09 01:47:593089 ChildProcessSecurityPolicyImpl* policy =
3090 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323091 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593092 return;
[email protected]8f810632013-06-06 22:33:323093
[email protected]c125e532014-05-10 20:39:063094 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203095}
3096
[email protected]f5273e52014-07-14 16:30:203097void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3098 const GURL& url,
3099 bool user_gesture) {
3100 if (!delegate_)
3101 return;
3102
3103 ChildProcessSecurityPolicyImpl* policy =
3104 ChildProcessSecurityPolicyImpl::GetInstance();
3105 if (policy->IsPseudoScheme(protocol))
3106 return;
3107
3108 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3109}
3110
[email protected]b172aee2012-04-10 17:05:263111void WebContentsImpl::OnFindReply(int request_id,
3112 int number_of_matches,
3113 const gfx::Rect& selection_rect,
3114 int active_match_ordinal,
3115 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:433116 if (delegate_) {
3117 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
3118 active_match_ordinal, final_update);
3119 }
[email protected]b888919c2011-09-02 00:32:163120}
3121
[email protected]59363fc92012-09-05 03:46:313122#if defined(OS_ANDROID)
3123void WebContentsImpl::OnFindMatchRectsReply(
3124 int version,
3125 const std::vector<gfx::RectF>& rects,
3126 const gfx::RectF& active_rect) {
3127 if (delegate_)
3128 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
3129}
[email protected]583418cc2013-01-17 14:01:103130
[email protected]1ff427972013-02-07 21:14:073131void WebContentsImpl::OnOpenDateTimeDialog(
3132 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173133 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093134 GetRenderViewHost(),
3135 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133136 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093137 value.minimum,
3138 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173139 value.step,
3140 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103141}
[email protected]59363fc92012-09-05 03:46:313142#endif
3143
[email protected]cfa856d62014-02-22 07:58:403144void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
3145 int automation_id) {
3146 DomOperationNotificationDetails details(json_string, automation_id);
3147 NotificationService::current()->Notify(
3148 NOTIFICATION_DOM_OPERATION_RESPONSE,
3149 Source<WebContents>(this),
3150 Details<DomOperationNotificationDetails>(&details));
3151}
3152
[email protected]b172aee2012-04-10 17:05:263153void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3154 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103155 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253156 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103157 AppCacheAccessed(manifest_url, blocked_by_policy));
3158}
3159
[email protected]8bc5ff02013-11-29 06:34:033160void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483161 int color_chooser_id,
3162 SkColor color,
3163 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113164 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003165 return;
nasko907fcb62015-01-28 04:24:113166
[email protected]aa62afd2014-04-22 19:22:463167 ColorChooser* new_color_chooser = delegate_ ?
3168 delegate_->OpenColorChooser(this, color, suggestions) :
3169 NULL;
[email protected]820957a2014-01-14 14:56:303170 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213171 return;
[email protected]8ed16472014-04-11 19:02:483172 if (color_chooser_info_.get())
3173 color_chooser_info_->chooser->End();
3174
3175 color_chooser_info_.reset(new ColorChooserInfo(
3176 render_frame_message_source_->GetProcess()->GetID(),
3177 render_frame_message_source_->GetRoutingID(),
3178 new_color_chooser,
3179 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203180}
3181
[email protected]b172aee2012-04-10 17:05:263182void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483183 if (color_chooser_info_ &&
3184 color_chooser_id == color_chooser_info_->identifier)
3185 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203186}
3187
[email protected]b172aee2012-04-10 17:05:263188void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323189 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483190 if (color_chooser_info_ &&
3191 color_chooser_id == color_chooser_info_->identifier)
3192 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203193}
3194
[email protected]d0759f492012-04-19 22:50:503195// This exists for render views that don't have a WebUI, but do have WebUI
3196// bindings enabled.
3197void WebContentsImpl::OnWebUISend(const GURL& source_url,
3198 const std::string& name,
3199 const base::ListValue& args) {
3200 if (delegate_)
3201 delegate_->WebUISend(this, source_url, name, args);
3202}
3203
thestigc4cac8f2014-09-04 21:17:503204#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003205void WebContentsImpl::OnPepperInstanceCreated() {
3206 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3207}
3208
3209void WebContentsImpl::OnPepperInstanceDeleted() {
3210 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3211}
3212
tommyclie6633ca72014-10-31 00:40:423213void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3214 const base::FilePath& path,
3215 bool is_hung) {
3216 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3217
3218 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3219 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3220}
3221
3222void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3223 base::ProcessId plugin_pid) {
3224 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3225 PluginCrashed(plugin_path, plugin_pid));
3226}
3227
[email protected]d8415ad92012-08-23 14:40:503228void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443229 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503230 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343231 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163232 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443233 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163234 return;
[email protected]d8415ad92012-08-23 14:40:503235 }
3236
[email protected]8c8fc292012-11-23 18:57:163237 if (!delegate_->RequestPpapiBrokerPermission(
3238 this, url, plugin_path,
3239 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443240 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163241 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443242 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163243 }
[email protected]d8415ad92012-08-23 14:40:503244}
3245
[email protected]ea0309c2013-08-06 19:35:443246void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503247 bool result) {
[email protected]ea0309c2013-08-06 19:35:443248 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503249}
3250
fsamuel833ee7c2015-02-13 23:40:403251void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3252 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393253 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143254 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403255 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373256}
tommyclie6633ca72014-10-31 00:40:423257#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373258
[email protected]795c28972012-12-06 06:13:393259void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393260 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063261 // We get updated favicon URLs after the page stops loading. If a cross-site
3262 // navigation occurs while a page is still loading, the initial page
3263 // may stop loading and send us updated favicon URLs after the navigation
3264 // for the new page has committed.
3265 RenderViewHostImpl* rvhi =
3266 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3267 if (!rvhi->is_active())
3268 return;
3269
[email protected]795c28972012-12-06 06:13:393270 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293271 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393272}
3273
dalecurtisbc6572e12014-09-12 19:22:303274void WebContentsImpl::CreateAudioPowerSaveBlocker() {
dalecurtisbc6572e12014-09-12 19:22:303275 DCHECK(!audio_power_save_blocker_);
3276 audio_power_save_blocker_ = PowerSaveBlocker::Create(
deratf3c302a2015-02-23 18:33:033277 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
3278 PowerSaveBlocker::kReasonAudioPlayback, "Playing audio");
dalecurtisbc6572e12014-09-12 19:22:303279}
3280
3281void WebContentsImpl::CreateVideoPowerSaveBlocker() {
dalecurtisbc6572e12014-09-12 19:22:303282 DCHECK(!video_power_save_blocker_);
3283 DCHECK(!active_video_players_.empty());
3284 video_power_save_blocker_ = PowerSaveBlocker::Create(
deratf3c302a2015-02-23 18:33:033285 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
3286 PowerSaveBlocker::kReasonVideoPlayback, "Playing video");
dalecurtisbc6572e12014-09-12 19:22:303287#if defined(OS_ANDROID)
3288 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get())
boliu65a9d1d2015-04-09 03:58:523289 ->InitDisplaySleepBlocker(this);
dalecurtisbc6572e12014-09-12 19:22:303290#endif
dalecurtisbc6572e12014-09-12 19:22:303291}
3292
3293void WebContentsImpl::MaybeReleasePowerSaveBlockers() {
3294 // If there are no more audio players and we don't have audio stream
3295 // monitoring, release the audio power save blocker here instead of during
3296 // NotifyNavigationStateChanged().
3297 if (active_audio_players_.empty() &&
timavf6f6f692015-03-04 02:19:373298 !audio_state_provider_->IsAudioStateAvailable()) {
dalecurtisbc6572e12014-09-12 19:22:303299 audio_power_save_blocker_.reset();
3300 }
3301
3302 // If there are no more video players, clear the video power save blocker.
3303 if (active_video_players_.empty())
3304 video_power_save_blocker_.reset();
3305}
3306
[email protected]1dd0bb752014-02-01 01:16:263307void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
3308 bool has_video,
avayvod68017be2014-10-10 18:02:433309 bool has_audio,
3310 bool is_remote) {
3311 // Ignore the videos playing remotely and don't hold the wake lock for the
3312 // screen.
3313 if (is_remote) return;
3314
dalecurtisbc6572e12014-09-12 19:22:303315 if (has_audio) {
3316 AddMediaPlayerEntry(player_cookie, &active_audio_players_);
3317
3318 // If we don't have audio stream monitoring, allocate the audio power save
3319 // blocker here instead of during NotifyNavigationStateChanged().
3320 if (!audio_power_save_blocker_ &&
timavf6f6f692015-03-04 02:19:373321 !audio_state_provider_->IsAudioStateAvailable()) {
dalecurtisbc6572e12014-09-12 19:22:303322 CreateAudioPowerSaveBlocker();
3323 }
[email protected]1dd0bb752014-02-01 01:16:263324 }
loislo0381a742014-09-11 10:58:113325
dalecurtisbc6572e12014-09-12 19:22:303326 if (has_video) {
3327 AddMediaPlayerEntry(player_cookie, &active_video_players_);
3328
3329 // If we're not hidden and have just created a player, create a blocker.
3330 if (!video_power_save_blocker_ && !IsHidden())
3331 CreateVideoPowerSaveBlocker();
loislo0381a742014-09-11 10:58:113332 }
prashantv0c9b968d22015-03-26 00:58:543333
3334 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying());
[email protected]1dd0bb752014-02-01 01:16:263335}
3336
3337void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
dalecurtisbc6572e12014-09-12 19:22:303338 RemoveMediaPlayerEntry(player_cookie, &active_audio_players_);
3339 RemoveMediaPlayerEntry(player_cookie, &active_video_players_);
3340 MaybeReleasePowerSaveBlockers();
prashantv0c9b968d22015-03-26 00:58:543341
3342 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaPaused());
[email protected]d9030b82013-07-19 08:26:063343}
3344
avayvod41634b12015-07-08 17:07:053345#if defined(OS_ANDROID)
3346
3347void WebContentsImpl::OnMediaSessionStateChanged() {
3348 MediaSession* session = MediaSession::Get(this);
3349 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3350 MediaSessionStateChanged(session->IsControllable(),
3351 session->IsSuspended()));
3352}
3353
3354void WebContentsImpl::ResumeMediaSession() {
3355 MediaSession::Get(this)->Resume();
3356}
3357
3358void WebContentsImpl::SuspendMediaSession() {
3359 MediaSession::Get(this)->Suspend();
3360}
3361
3362#endif // defined(OS_ANDROID)
3363
[email protected]50279492014-05-05 23:24:293364void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153365 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293366 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283367
peter90afaba2015-06-01 12:05:293368 did_first_visually_non_empty_paint_ = true;
3369
yusufod41c5f92015-03-06 00:14:283370 if (theme_color_ != last_sent_theme_color_) {
3371 // Theme color should have updated by now if there was one.
3372 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3373 DidChangeThemeColor(theme_color_));
3374 last_sent_theme_color_ = theme_color_;
3375 }
[email protected]9f268072013-11-07 00:02:153376}
[email protected]d9030b82013-07-19 08:26:063377
[email protected]e67ebf32013-02-13 11:07:193378void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013379 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073380 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013381
estark5ea80e52015-06-19 18:43:123382 SecurityStyleExplanations security_style_explanations;
3383 SecurityStyle security_style =
3384 delegate_->GetSecurityStyle(this, &security_style_explanations);
3385 FOR_EACH_OBSERVER(
3386 WebContentsObserver, observers_,
3387 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013388 }
[email protected]e67ebf32013-02-13 11:07:193389}
3390
[email protected]17e286e2013-03-01 23:29:393391void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3392 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3393 BeforeFormRepostWarningShow());
3394}
3395
[email protected]ec6c05f2013-10-23 18:41:573396void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3397 Activate();
3398 if (delegate_)
3399 delegate_->ShowRepostFormWarningDialog(this);
3400}
3401
[email protected]b4c84012014-04-28 19:51:103402bool WebContentsImpl::HasAccessedInitialDocument() {
3403 return has_accessed_initial_document_;
3404}
3405
[email protected]96d185d2009-04-24 03:28:543406// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:593407// loading, or done loading.
fdegans6ce28f52015-03-19 12:52:223408void WebContentsImpl::SetIsLoading(bool is_loading,
[email protected]e3b10d12014-03-28 16:06:093409 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:263410 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:543411 if (is_loading == is_loading_)
3412 return;
3413
3414 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:263415 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3416 base::string16());
[email protected]96d185d2009-04-24 03:28:543417 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563418 upload_size_ = 0;
3419 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543420 }
3421
[email protected]fa944cb82013-11-15 17:51:213422 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543423
3424 is_loading_ = is_loading;
3425 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033426 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543427
[email protected]6ebdc9b2010-09-27 16:55:573428 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093429 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213430 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543431
[email protected]eab61442013-11-14 18:35:483432 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593433 if (is_loading) {
naskob8744d22014-08-28 17:07:433434 TRACE_EVENT_ASYNC_BEGIN1("browser,navigation", "WebContentsImpl Loading",
3435 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223436 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]91621872013-10-08 04:04:593437 } else {
naskob8744d22014-08-28 17:07:433438 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3439 this, "URL", url);
fdegans6ce28f52015-03-19 12:52:223440 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]91621872013-10-08 04:04:593441 }
[email protected]66798902013-10-01 18:40:163442
3443 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213444 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3445 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543446 if (details)
[email protected]8ff00d72012-10-23 19:12:213447 det = Details<LoadNotificationDetails>(details);
3448 NotificationService::current()->Notify(
3449 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543450}
3451
[email protected]b172aee2012-04-10 17:05:263452void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463453 // If we are creating a RVH for a restored controller, then we need to make
3454 // sure the RenderView starts with a next_page_id_ larger than the number
3455 // of restored entries. This must be called before the RenderView starts
3456 // navigating (to avoid a race between the browser updating max_page_id and
3457 // the renderer updating next_page_id_). Because of this, we only call this
3458 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563459 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583460 if (max_restored_page_id >
3461 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3462 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3463 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323464}
3465
[email protected]b172aee2012-04-10 17:05:263466bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263467 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323468 // For file URLs without a title, use the pathname instead. In the case of a
3469 // synthesized title, we don't want the update to count toward the "one set
3470 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263471 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323472 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513473 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243474 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323475 explicit_set = false; // Don't count synthetic titles toward the set limit.
3476 } else {
[email protected]8af69c6c2014-03-03 19:05:313477 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323478 explicit_set = true;
3479 }
3480
[email protected]987fc3a2011-05-26 14:18:093481 // If a page is created via window.open and never navigated,
3482 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553483 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093484 if (entry) {
[email protected]36fc0392011-12-25 03:59:513485 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093486 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323487
[email protected]36fc0392011-12-25 03:59:513488 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093489 } else {
3490 if (page_title_when_no_navigation_entry_ == final_title)
3491 return false; // Nothing changed, don't bother.
3492
3493 page_title_when_no_navigation_entry_ = final_title;
3494 }
[email protected]420ae012009-04-24 05:16:323495
[email protected]420ae012009-04-24 05:16:323496 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233497 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323498
[email protected]66798902013-10-01 18:40:163499 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533500 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163501
[email protected]420ae012009-04-24 05:16:323502 return true;
3503}
3504
fdegansa696e5112015-04-17 01:57:593505void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003506 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003507 if (delegate_)
fdegansa696e5112015-04-17 01:57:593508 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003509}
3510
3511void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343512 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003513 loading_weak_factory_.InvalidateWeakPtrs();
3514 loading_last_progress_update_ = base::TimeTicks();
3515}
3516
[email protected]02d7b6e2014-06-24 21:01:503517void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3518 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323519 // After sending out a swap notification, we need to send a disconnect
3520 // notification so that clients that pick up a pointer to |this| can NULL the
3521 // pointer. See Bug 1230284.
3522 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113523 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283524 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113525
[email protected]7a846df2012-09-20 19:17:393526 // Ensure that the associated embedder gets cleared after a RenderViewHost
3527 // gets swapped, so we don't reuse the same embedder next time a
3528 // RenderViewHost is attached to this WebContents.
3529 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323530}
3531
[email protected]02d7b6e2014-06-24 21:01:503532void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3533 RenderFrameHost* new_host) {
3534 FOR_EACH_OBSERVER(WebContentsObserver,
3535 observers_,
3536 RenderFrameHostChanged(old_host, new_host));
3537}
3538
[email protected]da7a7182013-09-06 08:11:113539// TODO(avi): Remove this entire function because this notification is already
3540// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263541void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323542 if (!notify_disconnection_)
3543 return;
3544
3545 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213546 NotificationService::current()->Notify(
3547 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3548 Source<WebContents>(this),
3549 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323550}
3551
[email protected]cbb1ef592013-06-05 19:49:463552void WebContentsImpl::NotifyNavigationEntryCommitted(
3553 const LoadCommittedDetails& load_details) {
3554 FOR_EACH_OBSERVER(
3555 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3556}
3557
[email protected]f114fa42013-12-06 17:06:443558bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3559 const IPC::Message& message) {
3560 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313561}
3562
[email protected]c31a84802014-04-03 15:55:493563const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3564 return GetLastCommittedURL();
3565}
3566
[email protected]b849847b2013-12-10 21:57:583567void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3568 // Note this is only for subframes, the notification for the main frame
3569 // happens in RenderViewCreated.
3570 FOR_EACH_OBSERVER(WebContentsObserver,
3571 observers_,
3572 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303573 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
[email protected]b849847b2013-12-10 21:57:583574}
3575
3576void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193577 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583578 FOR_EACH_OBSERVER(WebContentsObserver,
3579 observers_,
3580 RenderFrameDeleted(render_frame_host));
3581}
3582
[email protected]a09d53ce2014-01-31 00:46:423583void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3584 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103585 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423586 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103587 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423588 return;
3589
[email protected]077e704b2014-05-23 19:24:103590 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3591 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423592}
3593
[email protected]87de04b02014-04-08 22:14:493594void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013595 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493596 const base::string16& message,
3597 const base::string16& default_prompt,
3598 const GURL& frame_url,
3599 JavaScriptMessageType javascript_message_type,
3600 IPC::Message* reply_msg) {
3601 // Suppress JavaScript dialogs when requested. Also suppress messages when
3602 // showing an interstitial as it's shown over the previous page and we don't
3603 // want the hidden page's dialogs to interfere with the interstitial.
3604 bool suppress_this_message =
creiscce56cd2014-09-29 22:45:223605 static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() ||
mathiash72a5e462014-11-19 08:18:503606 ShowingInterstitialPage() || !delegate_ ||
3607 delegate_->ShouldSuppressDialogs(this) ||
3608 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493609
3610 if (!suppress_this_message) {
3611 std::string accept_lang = GetContentClient()->browser()->
3612 GetAcceptLangs(GetBrowserContext());
mathiash72a5e462014-11-19 08:18:503613 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493614 dialog_manager_->RunJavaScriptDialog(
3615 this,
3616 frame_url.GetOrigin(),
3617 accept_lang,
3618 javascript_message_type,
3619 message,
3620 default_prompt,
3621 base::Bind(&WebContentsImpl::OnDialogClosed,
3622 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013623 render_frame_host->GetProcess()->GetID(),
3624 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493625 reply_msg,
3626 false),
3627 &suppress_this_message);
3628 }
3629
3630 if (suppress_this_message) {
3631 // If we are suppressing messages, just reply as if the user immediately
3632 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013633 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3634 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283635 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493636 }
3637
3638 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3639 // http://crbug.com/288961 ). The only safe thing to do here is return.
3640}
3641
3642void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013643 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493644 const base::string16& message,
3645 bool is_reload,
3646 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013647 RenderFrameHostImpl* rfhi =
3648 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493649 if (delegate_)
3650 delegate_->WillRunBeforeUnloadConfirm();
3651
3652 bool suppress_this_message =
creis36e228b2015-06-08 18:48:023653 rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT ||
3654 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:503655 delegate_->ShouldSuppressDialogs(this) ||
3656 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493657 if (suppress_this_message) {
3658 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3659 return;
3660 }
3661
3662 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:503663 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493664 dialog_manager_->RunBeforeUnloadDialog(
3665 this, message, is_reload,
3666 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013667 render_frame_host->GetProcess()->GetID(),
3668 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283669 false));
[email protected]87de04b02014-04-08 22:14:493670}
3671
[email protected]a86c0e962013-12-17 17:10:393672WebContents* WebContentsImpl::GetAsWebContents() {
3673 return this;
3674}
3675
[email protected]7912e822014-04-16 02:37:033676bool WebContentsImpl::IsNeverVisible() {
3677 if (!delegate_)
3678 return false;
3679 return delegate_->IsNeverVisible(this);
3680}
3681
[email protected]95640212014-07-26 18:14:303682#if defined(OS_WIN)
3683gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
3684 return accessible_parent_;
3685}
3686#endif
3687
[email protected]5a3bdf52012-05-24 15:12:573688RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3689 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323690}
3691
[email protected]8ff00d72012-10-23 19:12:213692RendererPreferences WebContentsImpl::GetRendererPrefs(
3693 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463694 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513695}
3696
[email protected]b172aee2012-04-10 17:05:263697gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173698 if (delegate_)
3699 return delegate_->GetRootWindowResizerRect();
3700 return gfx::Rect();
3701}
3702
[email protected]7a846df2012-09-20 19:17:393703void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273704 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393705 browser_plugin_embedder_.reset();
3706}
3707
[email protected]b172aee2012-04-10 17:05:263708void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443709 // Don't send notifications if we are just creating a swapped-out RVH for
3710 // the opener chain. These won't be used for view-source or WebUI, so it's
3711 // ok to return early.
creiscce56cd2014-09-29 22:45:223712 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:443713 return;
3714
[email protected]86f98a22013-03-20 14:35:003715 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313716 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083717
[email protected]8ff00d72012-10-23 19:12:213718 NotificationService::current()->Notify(
3719 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3720 Source<WebContents>(this),
3721 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323722
3723 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353724 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213725 if (GetRenderManager()->pending_web_ui())
3726 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323727
clamy3e849a0e2015-06-11 10:58:033728 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3729 switches::kEnableBrowserSideNavigation) &&
3730 GetRenderManager()->speculative_web_ui()) {
3731 GetRenderManager()->speculative_web_ui()->RenderViewCreated(
3732 render_view_host);
3733 }
3734
[email protected]6286a372013-10-09 04:03:273735 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333736 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323737 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183738 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583739 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323740 }
[email protected]0666aef2009-05-13 19:48:083741
[email protected]60780f412013-02-25 16:34:103742 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263743
3744 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253745 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:323746}
3747
[email protected]b172aee2012-04-10 17:05:263748void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523749 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323750 // Don't notify the world, since this came from a renderer in the
3751 // background.
3752 return;
3753 }
3754
[email protected]da7a7182013-09-06 08:11:113755 notify_disconnection_ = true;
3756 // TODO(avi): Remove. http://crbug.com/170921
3757 NotificationService::current()->Notify(
3758 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3759 Source<WebContents>(this),
3760 NotificationService::NoDetails());
3761
[email protected]be1f56ab2011-12-22 06:55:313762 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233763 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303764
3765 // Restore the focus to the tab (otherwise the focus will be on the top
3766 // window).
[email protected]484ae5912010-09-29 19:16:143767 if (was_crashed && !FocusLocationBarByDefault() &&
3768 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063769 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143770 }
[email protected]32ded2212011-11-10 18:51:433771
[email protected]d8c660432011-12-22 20:51:253772 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323773}
3774
[email protected]ec6a7eb2013-04-22 17:34:223775void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3776 base::TerminationStatus status,
3777 int error_code) {
[email protected]151a63d2011-12-20 22:32:523778 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323779 // The pending page's RenderViewHost is gone.
3780 return;
3781 }
3782
[email protected]2fcdcc32014-03-05 02:14:073783 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3784 // renderer may not have made a clean exit.
3785 if (IsFullscreenForCurrentTab())
mlamouri7a78d6fd2015-01-17 13:23:533786 ExitFullscreenMode();
[email protected]2fcdcc32014-03-05 02:14:073787
[email protected]698191dc2014-02-25 01:06:133788 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:173789 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:133790
[email protected]f738bdcb2014-07-11 20:40:443791 if (delegate_)
3792 delegate_->HideValidationMessage(this);
3793
fdegans6ce28f52015-03-19 12:52:223794 SetIsLoading(false, true, nullptr);
[email protected]420ae012009-04-24 05:16:323795 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233796 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453797
[email protected]960b0372014-05-19 18:01:003798 // Reset the loading progress. TODO(avi): What does it mean to have a
3799 // "renderer crash" when there is more than one renderer process serving a
3800 // webpage? Once this function is called at a more granular frame level, we
3801 // probably will need to more granularly reset the state here.
3802 ResetLoadProgressState();
[email protected]960b0372014-05-19 18:01:003803
[email protected]d8c660432011-12-22 20:51:253804 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273805 observers_,
[email protected]58d5cfe2013-07-10 02:40:523806 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323807}
3808
[email protected]b172aee2012-04-10 17:05:263809void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253810 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063811}
3812
[email protected]b172aee2012-04-10 17:05:263813void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3814 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043815 const PageState& page_state) {
creise1d3e5b2014-12-01 18:21:573816 // Ensure that this state update comes from a RenderViewHost that belongs to
3817 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:413818 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:573819 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:413820 return;
[email protected]420ae012009-04-24 05:16:323821
avi286019ce2015-07-29 01:26:583822 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:323823 // when the user is scrolling and entering form data, as well as when we're
3824 // leaving a page, in which case our state may have already been moved to
3825 // the next page. The navigation controller will look up the appropriate
3826 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:583827 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:113828 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:583829 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:113830 if (!entry)
[email protected]420ae012009-04-24 05:16:323831 return;
[email protected]420ae012009-04-24 05:16:323832
avi286019ce2015-07-29 01:26:583833 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
3834 rvhi->nav_entry_id());
3835
3836 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
3837 // TODO(creis): We can't properly update state for cross-process subframes
3838 // until PageState is decomposed into FrameStates. Until then, use the new
3839 // method.
3840 entry = new_entry;
3841 } else {
3842 DCHECK_EQ(entry, new_entry);
3843 }
3844
[email protected]691aa2f2013-05-28 22:52:043845 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323846 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043847 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:113848 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:323849}
3850
sky8b00392d2015-01-10 00:30:283851void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
3852 const GURL& url) {
3853 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
3854 // If we're fullscreen only update the url if it's from the fullscreen
3855 // renderer.
3856 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
3857 if (fs && fs->GetRenderWidgetHost() != render_view_host)
3858 return;
3859 }
[email protected]6934a702011-12-20 00:04:513860 if (delegate_)
avi450ce00e2014-09-24 01:58:523861 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:323862}
3863
[email protected]b172aee2012-04-10 17:05:263864void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103865#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293866 // The UI may be in an event-tracking loop, such as between the
3867 // mouse-down and mouse-up in text selection or a button click.
3868 // Defer the close until after tracking is complete, so that we
3869 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293870 // TODO(shess): This could get more fine-grained. For instance,
3871 // closing a tab in another window while selecting text in the
3872 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103873 if (view_->IsEventTracking()) {
3874 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293875 return;
3876 }
[email protected]60780f412013-02-25 16:34:103877#endif
[email protected]07707302009-11-06 00:50:293878
[email protected]420ae012009-04-24 05:16:323879 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523880 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513881 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323882}
3883
[email protected]66bbadaf2014-03-28 16:25:543884void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573885 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3886 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573887}
3888
[email protected]b172aee2012-04-10 17:05:263889void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513890 if (delegate_ && delegate_->IsPopupOrPanel(this))
3891 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323892}
3893
fdegansa696e5112015-04-17 01:57:593894void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:093895 bool to_different_document) {
fdegans6ce28f52015-03-19 12:52:223896 SetIsLoading(true, to_different_document, nullptr);
dmazzonibf8cec42015-02-08 08:28:083897
3898 // Notify accessibility that the user is navigating away from the
3899 // current document.
3900 //
3901 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:083902 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:593903 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:083904 if (manager)
3905 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:323906}
3907
fdegansc73eec22015-03-19 14:47:543908void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:323909 scoped_ptr<LoadNotificationDetails> details;
3910
[email protected]9595fd82013-04-19 21:28:493911 // Use the last committed entry rather than the active one, in case a
3912 // pending entry has been created.
3913 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203914 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493915
[email protected]420ae012009-04-24 05:16:323916 // An entry may not exist for a stop when loading an initial blank page or
3917 // if an iframe injected by script into a blank page finishes loading.
3918 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203919 base::TimeDelta elapsed =
3920 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323921
3922 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513923 entry->GetVirtualURL(),
3924 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323925 elapsed,
3926 &controller_,
3927 controller_.GetCurrentEntryIndex()));
3928 }
3929
fdegans6ce28f52015-03-19 12:52:223930 SetIsLoading(false, true, details.get());
[email protected]420ae012009-04-24 05:16:323931}
3932
fdegansa696e5112015-04-17 01:57:593933void WebContentsImpl::DidChangeLoadProgress() {
3934 double load_progress = frame_tree_.load_progress();
3935
3936 // The delegate is notified immediately for the first and last updates. Also,
3937 // since the message loop may be pretty busy when a page is loaded, it might
3938 // not execute a posted task in a timely manner so the progress report is sent
3939 // immediately if enough time has passed.
3940 base::TimeDelta min_delay =
3941 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
3942 bool delay_elapsed = loading_last_progress_update_.is_null() ||
3943 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
3944
3945 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
3946 // If there is a pending task to send progress, it is now obsolete.
3947 loading_weak_factory_.InvalidateWeakPtrs();
3948
3949 // Notify the load progress change.
3950 SendChangeLoadProgress();
3951
3952 // Clean-up the states if needed.
3953 if (load_progress == 1.0)
3954 ResetLoadProgressState();
3955 return;
3956 }
3957
3958 if (loading_weak_factory_.HasWeakPtrs())
3959 return;
3960
skyostil95082a62015-06-05 19:53:073961 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
3962 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
3963 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:593964 min_delay);
3965}
3966
[email protected]b172aee2012-04-10 17:05:263967void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163968 controller_.DiscardNonCommittedEntries();
3969
3970 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213971 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163972}
3973
[email protected]59167c22013-06-03 18:07:323974void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103975 has_accessed_initial_document_ = true;
3976
[email protected]d1371bf8e2014-04-19 03:26:243977 // We may have left a failed browser-initiated navigation in the address bar
3978 // to let the user edit it and try again. Clear it now that content might
3979 // show up underneath it.
3980 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:453981 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:243982
[email protected]59167c22013-06-03 18:07:323983 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:503984 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:323985}
3986
alexmosbe2f4c32015-03-10 02:30:233987void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
3988 const std::string& name) {
3989 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3990 FrameNameChanged(render_frame_host, name));
3991}
3992
[email protected]39f2f9252014-05-03 00:54:013993void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293994 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093995 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293996 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093997
3998 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213999 NotificationService::current()->Notify(
4000 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4001 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294002 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084003}
4004
[email protected]ef3adfc2014-05-11 00:04:544005void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
4006 int32 page_id,
4007 const base::string16& title,
4008 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544009 // If we have a title, that's a pretty good indication that we've started
4010 // getting useful data.
4011 SetNotWaitingForResponse();
4012
4013 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584014 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544015 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584016 render_frame_host->GetSiteInstance(), page_id);
4017
4018 RenderViewHostImpl* rvhi =
4019 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
4020 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4021 rvhi->nav_entry_id());
4022 DCHECK_EQ(entry, new_entry);
[email protected]ef3adfc2014-05-11 00:04:544023
4024 // We can handle title updates when we don't have an entry in
4025 // UpdateTitleForEntry, but only if the update is from the current RVH.
4026 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584027 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544028 return;
4029
4030 // TODO(evan): make use of title_direction.
4031 // http://code.google.com/p/chromium/issues/detail?id=27094
4032 if (!UpdateTitleForEntry(entry, title))
4033 return;
4034
4035 // Broadcast notifications when the UI should be updated.
4036 if (entry == controller_.GetEntryAtOffset(0))
4037 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4038}
4039
4040void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4041 const std::string& encoding) {
4042 SetEncoding(encoding);
4043}
4044
[email protected]39f2f9252014-05-03 00:54:014045void WebContentsImpl::DocumentAvailableInMainFrame(
4046 RenderViewHost* render_view_host) {
4047 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4048 DocumentAvailableInMainFrame());
4049}
naskoc0fceff2015-04-30 15:53:524050
[email protected]e1c3a552012-05-04 20:51:324051void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4052 // Tell the active RenderViewHost to run unload handlers and close, as long
4053 // as the request came from a RenderViewHost in the same BrowsingInstance.
4054 // In most cases, we receive this from a swapped out RenderViewHost.
4055 // It is possible to receive it from one that has just been swapped in,
4056 // in which case we might as well deliver the message anyway.
4057 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524058 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324059}
4060
alexmose7da5a12015-04-09 02:22:164061bool WebContentsImpl::ShouldRouteMessageEvent(
4062 RenderFrameHost* target_rfh,
4063 SiteInstance* source_site_instance) const {
4064 // Allow the message if this WebContents is dedicated to a browser plugin
4065 // guest.
[email protected]0eba810b2012-10-18 03:19:364066 // Note: This check means that an embedder could theoretically receive a
4067 // postMessage from anyone (not just its own guests). However, this is
4068 // probably not a risk for apps since other pages won't have references
4069 // to App windows.
alexmose7da5a12015-04-09 02:22:164070 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4071}
[email protected]f546640b2012-05-15 00:03:494072
alexmos58729042015-06-18 23:20:004073void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164074 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4075 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494076
alexmose7da5a12015-04-09 02:22:164077 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144078 // If this message is going to outer WebContents from inner WebContents,
4079 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4080 // already created a RenderFrameProxyHost for that purpose.
4081 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084082 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144083 return;
4084 }
4085
alexmose7da5a12015-04-09 02:22:164086 if (GetBrowserPluginGuest()) {
4087 // We create a swapped out RenderView for the embedder in the guest's
4088 // render process but we intentionally do not expose the embedder's
4089 // opener chain to it.
alexmos58729042015-06-18 23:20:004090 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494091 } else {
alexmos58729042015-06-18 23:20:004092 RenderFrameHostImpl* source_rfhi =
4093 static_cast<RenderFrameHostImpl*>(source_rfh);
4094 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
4095 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494096 }
4097 }
[email protected]f546640b2012-05-15 00:03:494098}
4099
[email protected]a796f202012-05-30 14:14:254100bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:264101 const base::string16& message,
[email protected]a796f202012-05-30 14:14:254102 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:264103 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254104 if (!delegate_)
4105 return false;
4106 return delegate_->AddMessageToConsole(this, level, message, line_no,
4107 source_id);
4108}
4109
[email protected]0eba810b2012-10-18 03:19:364110int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:214111 SiteInstance* instance) {
carlosk37f793792014-11-27 15:08:294112 int render_view_routing_id = MSG_ROUTING_NONE;
nick5bf51632015-06-23 22:45:404113 if (RenderFrameHostManager::IsSwappedOutStateForbidden()) {
nasko4c0feb62015-06-05 18:37:064114 GetRenderManager()->CreateRenderFrameProxy(instance);
4115 } else {
4116 GetRenderManager()->CreateRenderFrame(
alexmos5ac402d2015-07-09 07:51:104117 instance, nullptr,
nasko4c0feb62015-06-05 18:37:064118 CREATE_RF_SWAPPED_OUT | CREATE_RF_FOR_MAIN_FRAME_NAVIGATION |
4119 CREATE_RF_HIDDEN,
4120 &render_view_routing_id);
4121 }
carlosk37f793792014-11-27 15:08:294122 return render_view_routing_id;
[email protected]0eba810b2012-10-18 03:19:364123}
4124
[email protected]b172aee2012-04-10 17:05:264125void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:274126 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254127 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:224128
[email protected]ea114722012-03-12 01:11:254129 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:174130 if (rdh) // NULL in unittests.
4131 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:254132}
4133
[email protected]b172aee2012-04-10 17:05:264134void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444135 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254136 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444137}
4138
creiscce56cd2014-09-29 22:45:224139void WebContentsImpl::RendererUnresponsive(RenderViewHost* render_view_host) {
[email protected]992db4c2011-05-12 15:37:154140 // Don't show hung renderer dialog for a swapped out RVH.
creiscce56cd2014-09-29 22:45:224141 if (render_view_host != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:154142 return;
4143
creiscce56cd2014-09-29 22:45:224144 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(render_view_host);
4145 RenderFrameHostImpl* rfhi =
4146 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584147
[email protected]e5fc1632011-08-08 07:51:534148 // Ignore renderer unresponsive event if debugger is attached to the tab
4149 // since the event may be a result of the renderer sitting on a breakpoint.
4150 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364151 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534152 return;
4153
clamy226727e2015-06-29 10:28:474154 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224155 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324156 // Hang occurred while firing the beforeunload/unload handler.
4157 // Pretend the handler fired so tab closing continues as if it had.
clamyc0a278672015-03-24 17:08:554158 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324159
[email protected]fa944cb82013-11-15 17:51:214160 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324161 return;
4162
4163 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564164 // nothing we can do to recover. If the hang is in the beforeunload handler,
4165 // pretend the beforeunload listeners have all fired and allow the delegate
4166 // to continue closing; the user will not have the option of cancelling the
4167 // close. Otherwise, pretend the unload listeners have all fired and close
4168 // the tab.
4169 bool close = true;
clamy226727e2015-06-29 10:28:474170 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564171 delegate_->BeforeUnloadFired(this, true, &close);
4172 }
4173 if (close)
creiscce56cd2014-09-29 22:45:224174 Close(rvhi);
[email protected]420ae012009-04-24 05:16:324175 return;
4176 }
4177
creisc014b402015-04-23 16:41:454178 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474179 return;
4180
[email protected]6934a702011-12-20 00:04:514181 if (delegate_)
4182 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324183}
4184
[email protected]b172aee2012-04-10 17:05:264185void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:514186 if (delegate_)
4187 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324188}
4189
[email protected]b172aee2012-04-10 17:05:264190void WebContentsImpl::LoadStateChanged(
4191 const GURL& url,
4192 const net::LoadStateWithParam& load_state,
4193 uint64 upload_position,
4194 uint64 upload_size) {
erikchen174b78c62015-03-11 22:02:544195 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4196 // is fixed.
4197 tracked_objects::ScopedTracker tracking_profile1(
4198 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4199 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324200 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564201 upload_position_ = upload_position;
4202 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:504203 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:214204 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:304205 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:214206 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324207 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464208 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224209 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4210 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464211 }
[email protected]420ae012009-04-24 05:16:324212}
4213
[email protected]b172aee2012-04-10 17:05:264214void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554215 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324216 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124217 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4218 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514219 if (delegate_)
4220 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094221 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324222}
4223
[email protected]58d5cfe2013-07-10 02:40:524224void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544225 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234226 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224227 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544228}
4229
[email protected]b172aee2012-04-10 17:05:264230void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104231 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214232 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264233 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4234 // here during container initialization and normal window size will be set
4235 // later. In case of tab duplication this resizing to 0x0 prevents setting
4236 // normal size later so just ignore it.
4237 if (!size.IsEmpty())
4238 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324239}
4240
[email protected]af905902013-10-01 21:38:514241void WebContentsImpl::CancelModalDialogsForRenderManager() {
4242 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544243 // deferrer would prevent us from swapping out. We also clear the state
4244 // because this is a cross-process navigation, which means that it's a new
4245 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174246 //
4247 // Note that we don't bother telling browser_plugin_embedder_ because the
4248 // cross-process navigation will either destroy the browser plugins or not
4249 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514250 if (dialog_manager_)
avi2460c762015-04-17 15:21:544251 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514252}
4253
[email protected]02d7b6e2014-06-24 21:01:504254void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4255 RenderFrameHost* new_host,
4256 bool is_main_frame) {
4257 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054258 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504259 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084260
[email protected]02d7b6e2014-06-24 21:01:504261 // Make sure the visible RVH reflects the new delegate's preferences.
4262 if (delegate_)
4263 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394264
[email protected]02d7b6e2014-06-24 21:01:504265 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4266 }
4267
4268 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544269}
4270
naskof5940b9f2015-03-02 23:04:054271void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4272 RenderViewHost* old_host,
4273 RenderViewHost* new_host) {
4274 NotifyViewSwapped(old_host, new_host);
4275}
4276
[email protected]b172aee2012-04-10 17:05:264277NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194278 return GetController();
[email protected]3a3d47472010-07-15 21:03:544279}
4280
carlosk37f793792014-11-27 15:08:294281scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderManager(
4282 const GURL& url) {
4283 return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI(url)));
[email protected]420ae012009-04-24 05:16:324284}
4285
[email protected]10f417c52011-12-28 21:04:234286NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264287 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324288 return controller_.GetLastCommittedEntry();
4289}
4290
[email protected]b172aee2012-04-10 17:05:264291bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:164292 RenderViewHost* render_view_host,
alexmos5ac402d2015-07-09 07:51:104293 int opener_frame_routing_id,
[email protected]5a7100d2014-05-19 01:29:044294 int proxy_routing_id,
nasko4c0feb62015-06-05 18:37:064295 const FrameReplicationState& replicated_frame_state,
[email protected]82307f6b2014-08-07 03:30:124296 bool for_main_frame_navigation) {
naskob8744d22014-08-28 17:07:434297 TRACE_EVENT0("browser,navigation",
4298 "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:444299 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:484300 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:164301 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4302 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4303 // case this because RWH is still a base class of RenderViewHost, and child
4304 // frame RWHVs are unique in that they do not have their own WebContents.
lazyboy6ec48b2a2015-06-29 15:18:144305 bool is_guest_in_site_per_process =
4306 !!browser_plugin_guest_.get() &&
nickd30fd962015-07-27 21:51:084307 BrowserPluginGuestMode::UseCrossProcessFramesForGuests();
lazyboy6ec48b2a2015-06-29 15:18:144308 if (!for_main_frame_navigation || is_guest_in_site_per_process) {
[email protected]bffc8302014-01-23 20:52:164309 RenderWidgetHostViewChildFrame* rwh_view_child =
4310 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:164311 rwh_view = rwh_view_child;
4312 } else {
lazyboy549b3b42014-10-20 17:16:044313 rwh_view = view_->CreateViewForWidget(render_view_host, false);
[email protected]bffc8302014-01-23 20:52:164314 }
[email protected]1a98a932009-11-17 00:12:524315
[email protected]420ae012009-04-24 05:16:324316 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444317 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214318 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:324319
[email protected]74ce1ad2011-12-16 21:51:464320 // Make sure we use the correct starting page_id in the new RenderView.
4321 UpdateMaxPageIDIfNecessary(render_view_host);
4322 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584323 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464324
alexmos5ac402d2015-07-09 07:51:104325 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4326 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4327 max_page_id, replicated_frame_state,
4328 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524329 return false;
[email protected]14392a52012-05-02 20:28:444330 }
[email protected]a4127722011-04-27 23:13:524331
avi2b177592014-12-10 02:08:024332 SetHistoryOffsetAndLengthForView(render_view_host,
4333 controller_.GetLastCommittedEntryIndex(),
4334 controller_.GetEntryCount());
4335
[email protected]a220b5932013-09-21 03:47:444336#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504337 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4338 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:444339 if (rwh_view) {
4340 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4341 render_widget_host->WasResized();
4342 }
[email protected]f8233cc2011-05-31 20:24:504343#endif
4344
[email protected]420ae012009-04-24 05:16:324345 return true;
4346}
4347
[email protected]82307f6b2014-08-07 03:30:124348bool WebContentsImpl::CreateRenderFrameForRenderManager(
4349 RenderFrameHost* render_frame_host,
japhete6adf142014-10-31 00:01:494350 int parent_routing_id,
alexmos9f8705a2015-05-06 19:58:594351 int previous_sibling_routing_id,
japhete6adf142014-10-31 00:01:494352 int proxy_routing_id) {
naskob8744d22014-08-28 17:07:434353 TRACE_EVENT0("browser,navigation",
4354 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124355
4356 RenderFrameHostImpl* rfh =
4357 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmos9f8705a2015-05-06 19:58:594358 if (!rfh->CreateRenderFrame(parent_routing_id, previous_sibling_routing_id,
4359 proxy_routing_id))
[email protected]82307f6b2014-08-07 03:30:124360 return false;
4361
4362 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4363 // RenderFrameHost will have to be associated with the appropriate
4364 // RenderWidgetHostView or a new one should be created here.
4365
4366 return true;
4367}
4368
[email protected]7d244f12013-08-22 21:41:514369#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454370
[email protected]155c7f22013-12-09 17:07:184371base::android::ScopedJavaLocalRef<jobject>
4372WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404373 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564374 return GetWebContentsAndroid()->GetJavaObject();
4375}
[email protected]155c7f22013-12-09 17:07:184376
[email protected]0e813a52014-08-13 10:34:564377WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184378 WebContentsAndroid* web_contents_android =
4379 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4380 if (!web_contents_android) {
4381 web_contents_android = new WebContentsAndroid(this);
4382 SetUserData(kWebContentsAndroidKey, web_contents_android);
4383 }
[email protected]0e813a52014-08-13 10:34:564384 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184385}
4386
[email protected]7d244f12013-08-22 21:41:514387bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064388 return CreateRenderViewForRenderManager(
4389 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
4390 frame_tree_.root()->current_replication_state(), true);
[email protected]7d244f12013-08-22 21:41:514391}
[email protected]fc2b46b2014-05-03 16:33:454392
4393#elif defined(OS_MACOSX)
4394
[email protected]75f4df72014-07-16 22:39:424395void WebContentsImpl::SetAllowOtherViews(bool allow) {
4396 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454397}
4398
[email protected]75f4df72014-07-16 22:39:424399bool WebContentsImpl::GetAllowOtherViews() {
4400 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454401}
4402
[email protected]7d244f12013-08-22 21:41:514403#endif
4404
[email protected]6fba26d2014-04-29 09:38:284405void WebContentsImpl::OnDialogClosed(int render_process_id,
4406 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264407 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494408 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264409 bool success,
[email protected]fcf75d42013-12-03 20:11:264410 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284411 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4412 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494413 last_dialog_suppressed_ = dialog_was_suppressed;
4414
[email protected]beb440c2009-11-06 04:08:544415 if (is_showing_before_unload_dialog_ && !success) {
4416 // If a beforeunload dialog is canceled, we need to stop the throbber from
4417 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284418 if (rfh)
fdegansc73eec22015-03-19 14:47:544419 DidStopLoading();
[email protected]15d160c02012-07-04 10:52:354420 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104421
[email protected]6d65a462013-06-21 21:29:124422 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4423 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544424 }
[email protected]87de04b02014-04-08 22:14:494425
[email protected]beb440c2009-11-06 04:08:544426 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284427 if (rfh) {
4428 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4429 dialog_was_suppressed);
4430 } else {
4431 // Don't leak the sync IPC reply if the RFH or process is gone.
4432 delete reply_msg;
4433 }
[email protected]beb440c2009-11-06 04:08:544434}
4435
[email protected]b172aee2012-04-10 17:05:264436void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544437 if (encoding == last_reported_encoding_)
4438 return;
4439 last_reported_encoding_ = encoding;
4440
4441 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124442 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104443}
[email protected]f45d2a72010-03-08 23:28:354444
[email protected]1ac10dca2013-08-20 20:47:044445bool WebContentsImpl::IsHidden() {
4446 return capturer_count_ == 0 && !should_normally_be_visible_;
4447}
4448
lazyboy6ec48b2a2015-06-29 15:18:144449int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() {
4450 if (node_ && node_->outer_web_contents())
4451 return node_->outer_contents_frame_tree_node_id();
4452
4453 return FrameTreeNode::kFrameTreeNodeInvalidID;
4454}
4455
[email protected]b0936d22013-11-28 06:47:364456RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214457 return frame_tree_.root()->render_manager();
4458}
4459
[email protected]f8497342013-02-05 22:15:024460BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394461 return browser_plugin_guest_.get();
4462}
4463
[email protected]738f57a2013-06-29 21:06:544464void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4465 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144466 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544467 browser_plugin_guest_.reset(guest);
4468}
4469
[email protected]f8497342013-02-05 22:15:024470BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394471 return browser_plugin_embedder_.get();
4472}
[email protected]8ff00d72012-10-23 19:12:214473
fsamuel60b42282015-03-10 03:29:144474void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4475 if (browser_plugin_embedder_)
4476 return;
4477 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4478}
4479
[email protected]d9030b82013-07-19 08:26:064480void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194481 RenderFrameHost* render_frame_host) {
dalecurtisbc6572e12014-09-12 19:22:304482 RemoveAllMediaPlayerEntries(render_frame_host, &active_audio_players_);
4483 RemoveAllMediaPlayerEntries(render_frame_host, &active_video_players_);
4484 MaybeReleasePowerSaveBlockers();
[email protected]d9030b82013-07-19 08:26:064485}
4486
4487void WebContentsImpl::ClearAllPowerSaveBlockers() {
dalecurtisbc6572e12014-09-12 19:22:304488 active_audio_players_.clear();
4489 active_video_players_.clear();
4490 audio_power_save_blocker_.reset();
4491 video_power_save_blocker_.reset();
[email protected]d9030b82013-07-19 08:26:064492}
4493
[email protected]fc2b46b2014-05-03 16:33:454494gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214495 gfx::Size size;
4496 if (delegate_)
4497 size = delegate_->GetSizeForNewRenderView(this);
4498 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454499 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214500 return size;
4501}
4502
[email protected]ae7eeda2014-07-04 01:53:264503void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4504 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024505 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554506}
4507
[email protected]222f5822014-02-05 23:40:494508void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4509 if (!delegate_)
4510 return;
4511 const gfx::Size new_size = GetPreferredSize();
4512 if (new_size != old_size)
4513 delegate_->UpdatePreferredSize(this, new_size);
4514}
4515
dalecurtisbc6572e12014-09-12 19:22:304516void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie,
4517 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114518 if (!HasValidFrameSource())
4519 return;
4520
dalecurtisbc6572e12014-09-12 19:22:304521 const uintptr_t key =
4522 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4523 DCHECK(std::find((*player_map)[key].begin(),
4524 (*player_map)[key].end(),
4525 player_cookie) == (*player_map)[key].end());
4526 (*player_map)[key].push_back(player_cookie);
4527}
4528
4529void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie,
4530 ActiveMediaPlayerMap* player_map) {
nasko907fcb62015-01-28 04:24:114531 if (!HasValidFrameSource())
4532 return;
4533
dalecurtisbc6572e12014-09-12 19:22:304534 const uintptr_t key =
4535 reinterpret_cast<uintptr_t>(render_frame_message_source_);
4536 ActiveMediaPlayerMap::iterator it = player_map->find(key);
4537 if (it == player_map->end())
4538 return;
4539
4540 // Remove the player.
4541 PlayerList::iterator player_it =
4542 std::find(it->second.begin(), it->second.end(), player_cookie);
4543 if (player_it != it->second.end())
4544 it->second.erase(player_it);
4545
4546 // If there are no players left, remove the map entry.
4547 if (it->second.empty())
4548 player_map->erase(it);
4549}
4550
4551void WebContentsImpl::RemoveAllMediaPlayerEntries(
4552 RenderFrameHost* render_frame_host,
4553 ActiveMediaPlayerMap* player_map) {
4554 ActiveMediaPlayerMap::iterator it =
4555 player_map->find(reinterpret_cast<uintptr_t>(render_frame_host));
4556 if (it == player_map->end())
4557 return;
4558 player_map->erase(it);
4559}
4560
[email protected]34ff1cfc2014-08-20 06:16:054561void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4562 force_disable_overscroll_content_ = force_disable;
4563 if (view_)
4564 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4565}
4566
[email protected]8ff00d72012-10-23 19:12:214567} // namespace content