blob: f0812d69ebbf0b953f34938287401e55c2a10d8a [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/browser_plugin/browser_plugin_embedder.h"
22#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5923#include "content/browser/child_process_security_policy_impl.h"
[email protected]49413ca52014-03-05 14:13:4324#include "content/browser/devtools/render_view_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4125#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0426#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4627#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1228#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1629#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1630#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4031#include "content/browser/frame_host/interstitial_page_impl.h"
32#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0133#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1834#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1635#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]f28ef9a32014-05-12 16:36:1036#include "content/browser/geolocation/geolocation_dispatcher_host.h"
[email protected]5c9250872012-01-30 17:24:0537#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4438#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5339#include "content/browser/message_port_message_filter.h"
40#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0641#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3042#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5043#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3244#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5045#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4846#include "content/browser/renderer_host/render_widget_host_view_base.h"
[email protected]b6583592012-01-25 19:52:3347#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1148#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5849#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0350#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5651#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1452#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4253#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4454#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0255#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1756#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5157#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0258#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3659#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1160#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2861#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4462#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3663#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1764#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1465#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4666#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1567#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0068#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2769#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0070#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3771#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1472#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3273#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3474#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3875#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4276#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2577#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2178#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4879#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5480#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4981#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2082#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0383#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5784#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1685#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2986#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5387#include "net/http/http_cache.h"
88#include "net/http/http_transaction_factory.h"
89#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3490#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5691#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0192#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4193#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5294#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1895#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3196
[email protected]583418cc2013-01-17 14:01:1097#if defined(OS_ANDROID)
98#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:4599#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18100#include "content/browser/web_contents/web_contents_android.h"
[email protected]74ebfb12013-06-07 20:48:00101#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10102#endif
103
[email protected]f66df822012-05-18 16:52:17104#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50105#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27106#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57107#endif
[email protected]3e45ba92009-02-20 21:09:00108
[email protected]420ae012009-04-24 05:16:32109// Cross-Site Navigations
110//
[email protected]b172aee2012-04-10 17:05:26111// If a WebContentsImpl is told to navigate to a different web site (as
112// determined by SiteInstance), it will replace its current RenderViewHost with
113// a new RenderViewHost dedicated to the new SiteInstance. This works as
114// follows:
[email protected]420ae012009-04-24 05:16:32115//
[email protected]fc6c1872013-10-03 01:22:35116// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46117// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32118// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35119// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32120// run in the current RVH.
121// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35122// that it has a pending cross-site request. We will check this on the IO
123// thread when deciding how to handle the response.
124// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46125// cancel all the pending logic. Otherwise we allow the pending RVH to send
126// the navigation request to its renderer.
127// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35128// main resource load on the pending RVH. It creates a
129// CrossSiteResourceHandler to check whether a process swap is needed when
130// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46131// - When RDH receives a response, the BufferedResourceHandler determines
132// whether it is a download. If so, it sends a message to the new renderer
133// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26134// pending RVH remains until the next DidNavigate event for this
135// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32136// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35137// download, the CrossSiteResourceHandler checks whether a process swap is
138// needed (either because CrossSiteRequestManager has state for it or because
139// a transfer was needed for a redirect).
140// - If so, CrossSiteResourceHandler pauses the response to first run the old
141// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36142// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
143// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35144// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
145// to a new process is needed, based on the stored pending_nav_params_. (This
146// is independent of whether we started out with a cross-process navigation.)
147// - If not, it just tells the ResourceDispatcherHost to resume the response
148// to its current RenderViewHost.
149// - If so, it cancels the current pending RenderViewHost and sets up a new
150// navigation using RequestTransferURL. When the transferred request
151// arrives in the ResourceDispatcherHost, we transfer the response and
152// resume it.
[email protected]420ae012009-04-24 05:16:32153// - The pending renderer sends a FrameNavigate message that invokes the
154// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46155// pending RVH.
[email protected]b0936d22013-11-28 06:47:36156// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15157// the user goes back. The process only stays live if another tab is using
158// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32159
[email protected]8ff00d72012-10-23 19:12:21160namespace content {
[email protected]420ae012009-04-24 05:16:32161namespace {
162
[email protected]82114f52012-03-20 22:53:41163const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05164
[email protected]155c7f22013-12-09 17:07:18165#if defined(OS_ANDROID)
166const char kWebContentsAndroidKey[] = "web_contents_android";
167#endif // OS_ANDROID
168
[email protected]e4abd3b42013-11-12 18:28:47169base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46170g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
171
[email protected]988ed7132014-03-31 16:25:58172static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39173 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29174 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30175 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02176 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58177 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02178 ++g_next_image_download_id,
179 url,
180 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30181 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02182 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39183}
184
[email protected]8bfc8272013-09-09 20:10:53185void NotifyCacheOnIO(
186 scoped_refptr<net::URLRequestContextGetter> request_context,
187 const GURL& url,
188 const std::string& http_method) {
189 request_context->GetURLRequestContext()->http_transaction_factory()->
190 GetCache()->OnExternalCacheHit(url, http_method);
191}
192
[email protected]9b159a52013-10-03 17:24:55193// Helper function for retrieving all the sites in a frame tree.
194bool CollectSites(BrowserContext* context,
195 std::set<GURL>* sites,
196 FrameTreeNode* node) {
197 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
198 return true;
199}
200
[email protected]a86c0e962013-12-17 17:10:39201bool ForEachFrameInternal(
202 const base::Callback<void(RenderFrameHost*)>& on_frame,
203 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41204 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39205 return true;
206}
207
[email protected]c06c58c2014-03-12 20:31:59208bool ForEachPendingFrameInternal(
209 const base::Callback<void(RenderFrameHost*)>& on_frame,
210 FrameTreeNode* node) {
211 RenderFrameHost* pending_frame_host =
212 node->render_manager()->pending_frame_host();
213 if (pending_frame_host)
214 on_frame.Run(pending_frame_host);
215 return true;
216}
217
[email protected]a86c0e962013-12-17 17:10:39218void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
219 IPC::Message* message_copy = new IPC::Message(*message);
220 message_copy->set_routing_id(rfh->GetRoutingID());
221 rfh->Send(message_copy);
222}
223
[email protected]c06c58c2014-03-12 20:31:59224void RunRenderFrameDeleted(
225 ObserverList<WebContentsObserver>* observer_list,
226 RenderFrameHost* render_frame_host) {
227 FOR_EACH_OBSERVER(WebContentsObserver,
228 *observer_list,
229 RenderFrameDeleted(render_frame_host));
230}
231
[email protected]420ae012009-04-24 05:16:32232} // namespace
233
[email protected]54944cde2012-12-09 09:24:59234WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15235 return WebContentsImpl::CreateWithOpener(
236 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19237}
238
239WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59240 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30241 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59242 WebContentsImpl* new_contents = new WebContentsImpl(
243 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30244
245 for (SessionStorageNamespaceMap::const_iterator it =
246 session_storage_namespace_map.begin();
247 it != session_storage_namespace_map.end();
248 ++it) {
249 new_contents->GetController()
250 .SetSessionStorageNamespace(it->first, it->second.get());
251 }
252
[email protected]54944cde2012-12-09 09:24:59253 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19254 return new_contents;
[email protected]a81343d232011-12-27 07:39:20255}
[email protected]746d3052012-05-22 15:15:47256
[email protected]e4abd3b42013-11-12 18:28:47257void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46258 g_created_callbacks.Get().push_back(callback);
259}
260
[email protected]e4abd3b42013-11-12 18:28:47261void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46262 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
263 if (g_created_callbacks.Get().at(i).Equals(callback)) {
264 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
265 return;
266 }
267 }
268}
269
[email protected]299d7f12012-05-23 05:31:15270WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47271 return rvh->GetDelegate()->GetAsWebContents();
272}
273
[email protected]a86c0e962013-12-17 17:10:39274WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
275 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
276 if (!rfh_impl)
277 return NULL;
278 return rfh_impl->delegate()->GetAsWebContents();
279}
280
[email protected]7fff43e2013-05-21 20:21:10281// WebContentsImpl::DestructionObserver ----------------------------------------
282
283class WebContentsImpl::DestructionObserver : public WebContentsObserver {
284 public:
285 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
286 : WebContentsObserver(watched_contents),
287 owner_(owner) {
288 }
289
290 // WebContentsObserver:
[email protected]12a46832014-05-09 13:35:58291 virtual void WebContentsDestroyed() OVERRIDE {
292 owner_->OnWebContentsDestroyed(
293 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10294 }
295
296 private:
297 WebContentsImpl* owner_;
298
299 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
300};
301
[email protected]8ed16472014-04-11 19:02:48302WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
303 int render_frame_id,
304 ColorChooser* chooser,
305 int identifier)
306 : render_process_id(render_process_id),
307 render_frame_id(render_frame_id),
308 chooser(chooser),
309 identifier(identifier) {
310}
311
312WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
313}
314
[email protected]b172aee2012-04-10 17:05:26315// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32316
[email protected]b172aee2012-04-10 17:05:26317WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21318 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19319 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42320 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22321 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57322 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44323 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49324 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08325#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41326 accessible_parent_(NULL),
327#endif
[email protected]6ea6bdf2013-12-06 13:35:01328 frame_tree_(new NavigatorImpl(&controller_, this),
329 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34330 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23331 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
332 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34333 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26334 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56335 upload_size_(0),
336 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47337 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10338 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55339 capturer_count_(0),
340 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57341 is_being_destroyed_(false),
342 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15343 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01344 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02345 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38346 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21347 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
348 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00349 temporary_zoom_settings_(false),
[email protected]bab38af2014-03-30 17:37:29350 totalPinchGestureAmount_(0),
351 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44352 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42353 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]87de04b02014-04-08 22:14:49354 is_subframe_(false),
355 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46356 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
357 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55358 frame_tree_.SetFrameRemoveListener(
359 base::Bind(&WebContentsImpl::OnFrameRemoved,
360 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35361}
initial.commit09911bf2008-07-26 23:55:29362
[email protected]b172aee2012-04-10 17:05:26363WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32364 is_being_destroyed_ = true;
365
[email protected]21b41c7e892014-02-28 01:52:24366 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
367 // shutdown and be deleted as well.
368 frame_tree_.ForEach(
369 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
370
[email protected]d9030b82013-07-19 08:26:06371 ClearAllPowerSaveBlockers();
372
[email protected]b24b68a2012-09-24 21:57:26373 for (std::set<RenderWidgetHostImpl*>::iterator iter =
374 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
375 (*iter)->DetachDelegate();
376 }
377 created_widgets_.clear();
378
[email protected]3ab9cb82011-06-03 18:02:07379 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15380 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11381 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07382
[email protected]8ed16472014-04-11 19:02:48383 if (color_chooser_info_.get())
384 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20385
[email protected]420ae012009-04-24 05:16:32386 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32387
[email protected]ca13a442012-04-17 14:00:12388 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21389 NotificationService::current()->Notify(
390 NOTIFICATION_WEB_CONTENTS_DESTROYED,
391 Source<WebContents>(this),
392 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32393
[email protected]c06c58c2014-03-12 20:31:59394 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
395 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
396 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
397 run_render_frame_deleted_callback));
398
[email protected]fa944cb82013-11-15 17:51:21399 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27400 if (pending_rvh) {
401 FOR_EACH_OBSERVER(WebContentsObserver,
402 observers_,
403 RenderViewDeleted(pending_rvh));
404 }
405
[email protected]c06c58c2014-03-12 20:31:59406 ForEachFrame(run_render_frame_deleted_callback);
407
[email protected]f273ee52013-10-18 16:05:27408 FOR_EACH_OBSERVER(WebContentsObserver,
409 observers_,
[email protected]fa944cb82013-11-15 17:51:21410 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27411
[email protected]2db9bd72012-04-13 20:20:56412 FOR_EACH_OBSERVER(WebContentsObserver,
413 observers_,
[email protected]12a46832014-05-09 13:35:58414 WebContentsDestroyed());
415
416 FOR_EACH_OBSERVER(WebContentsObserver,
417 observers_,
418 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08419
[email protected]6934a702011-12-20 00:04:51420 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10421
422 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
423 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42424}
425
[email protected]d1198fd2012-08-13 22:50:19426WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59427 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19428 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03429 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59430 WebContentsImpl* new_contents = new WebContentsImpl(
431 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19432
[email protected]83100cd2014-05-10 11:50:06433 if (params.guest_instance_id) {
434 scoped_ptr<base::DictionaryValue> extra_params(
435 params.guest_extra_params->DeepCopy());
436 // This makes |new_contents| act as a guest.
437 // For more info, see comment above class BrowserPluginGuest.
438 BrowserPluginGuest::Create(params.guest_instance_id,
439 params.site_instance,
440 new_contents,
441 extra_params.Pass());
442 // We are instantiating a WebContents for browser plugin. Set its subframe
443 // bit to true.
444 new_contents->is_subframe_ = true;
445 }
[email protected]54944cde2012-12-09 09:24:59446 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19447 return new_contents;
448}
449
[email protected]b0936d22013-11-28 06:47:36450RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21451 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28452}
453
[email protected]7bb761892012-07-20 09:32:47454bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
455 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44456 return OnMessageReceived(render_view_host, NULL, message);
457}
458
459bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
460 RenderFrameHost* render_frame_host,
461 const IPC::Message& message) {
462 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56463 if (GetWebUI() &&
464 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17465 return true;
[email protected]d2353452012-01-19 19:53:56466 }
[email protected]f82d57b52011-04-27 19:13:17467
[email protected]d8c660432011-12-22 20:51:25468 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
469 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33470 if (render_frame_host) {
471 while ((observer = it.GetNext()) != NULL)
472 if (observer->OnMessageReceived(message, render_frame_host))
473 return true;
474 } else {
475 while ((observer = it.GetNext()) != NULL)
476 if (observer->OnMessageReceived(message))
477 return true;
478 }
[email protected]403415a2011-01-10 18:57:53479
[email protected]1d62cf72014-02-07 21:31:57480 // Message handlers should be aware of which
481 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
482 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43483 if (render_frame_host) {
484 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
485 render_frame_host->GetRenderViewHost(), message))
486 return true;
[email protected]1d62cf72014-02-07 21:31:57487 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43488 } else {
489 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
490 render_view_host, message))
491 return true;
[email protected]1d62cf72014-02-07 21:31:57492 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43493 }
[email protected]1d62cf72014-02-07 21:31:57494
[email protected]724159a2010-12-30 01:11:18495 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33496 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]f114fa42013-12-06 17:06:44497 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
498 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40499 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
500 OnDomOperationResponse)
[email protected]8ed16472014-04-11 19:02:48501 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
502 OnDocumentLoadedInFrame)
503 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
504 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
505 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
506 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
507 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19508 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
509 OnMediaPlayingNotification)
510 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
511 OnMediaPausedNotification)
[email protected]724159a2010-12-30 01:11:18512 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
513 OnDidLoadResourceFromMemoryCache)
514 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
515 OnDidDisplayInsecureContent)
516 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
517 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25518 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26519 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21520 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20521 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
522 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16523 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10524 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50525 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50526 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
527 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55528 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
529 OnBrowserPluginMessage(message))
530 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
531 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02532 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
533 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]9f268072013-11-07 00:02:15534 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
535 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07536 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
537 OnShowValidationMessage)
538 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
539 OnHideValidationMessage)
540 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
541 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48542#if defined(OS_ANDROID)
543 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
544 OnFindMatchRectsReply)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
546 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48547#endif
[email protected]724159a2010-12-30 01:11:18548 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33549 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44550 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57551 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18552
[email protected]724159a2010-12-30 01:11:18553 return handled;
554}
555
[email protected]b172aee2012-04-10 17:05:26556void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18557 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21558 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43559 if (delegate_)
560 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18561}
562
[email protected]d1198fd2012-08-13 22:50:19563NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56564 return controller_;
565}
566
[email protected]d1198fd2012-08-13 22:50:19567const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56568 return controller_;
569}
570
[email protected]8ff00d72012-10-23 19:12:21571BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55572 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30573}
574
[email protected]b172aee2012-04-10 17:05:26575const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24576 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32577 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51578 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31579}
580
[email protected]a093ce02013-07-22 20:53:14581const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24582 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32583 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24584 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
585}
586
587const GURL& WebContentsImpl::GetLastCommittedURL() const {
588 // We may not have a navigation entry yet.
589 NavigationEntry* entry = controller_.GetLastCommittedEntry();
590 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
591}
592
[email protected]8ff00d72012-10-23 19:12:21593WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31594 return delegate_;
595}
596
[email protected]8ff00d72012-10-23 19:12:21597void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31598 // TODO(cbentzel): remove this debugging code?
599 if (delegate == delegate_)
600 return;
601 if (delegate_)
602 delegate_->Detach(this);
603 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08604 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31605 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08606 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00607 if (view_)
608 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08609 }
[email protected]be1f56ab2011-12-22 06:55:31610}
611
[email protected]8ff00d72012-10-23 19:12:21612RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21613 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41614 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16615}
616
[email protected]60eca4eb2013-12-06 00:02:16617RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41618 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16619}
620
[email protected]9c9343b2014-03-08 02:56:07621RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
622 if (!frame_tree_.GetFocusedFrame())
623 return NULL;
624 return frame_tree_.GetFocusedFrame()->current_frame_host();
625}
626
[email protected]a86c0e962013-12-17 17:10:39627void WebContentsImpl::ForEachFrame(
628 const base::Callback<void(RenderFrameHost*)>& on_frame) {
629 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
630}
631
632void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
633 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
634 delete message;
635}
636
[email protected]b172aee2012-04-10 17:05:26637RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21638 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31639}
640
[email protected]bfcfa692013-02-07 06:17:02641WebContents* WebContentsImpl::GetEmbedderWebContents() const {
642 BrowserPluginGuest* guest = GetBrowserPluginGuest();
643 if (guest)
644 return guest->embedder_web_contents();
645 return NULL;
646}
647
648int WebContentsImpl::GetEmbeddedInstanceID() const {
649 BrowserPluginGuest* guest = GetBrowserPluginGuest();
650 if (guest)
651 return guest->instance_id();
652 return 0;
653}
654
[email protected]6b618e62012-08-16 12:59:18655int WebContentsImpl::GetRoutingID() const {
656 if (!GetRenderViewHost())
657 return MSG_ROUTING_NONE;
658
659 return GetRenderViewHost()->GetRoutingID();
660}
661
[email protected]44470a22013-01-24 01:21:54662int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
663 return fullscreen_widget_routing_id_;
664}
665
[email protected]b172aee2012-04-10 17:05:26666RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21667 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31668}
669
[email protected]4aebbca2013-09-17 22:26:49670RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
671 const {
672 RenderWidgetHost* const widget_host =
673 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
674 GetFullscreenWidgetRoutingID());
675 return widget_host ? widget_host->GetView() : NULL;
676}
677
[email protected]8ff00d72012-10-23 19:12:21678WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31679 return view_.get();
680}
681
[email protected]8ff00d72012-10-23 19:12:21682WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56683 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03684 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
685 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22686 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58687 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22688 web_ui->SetController(controller);
689 return web_ui;
690 }
691
692 delete web_ui;
693 return NULL;
694}
695
[email protected]8ff00d72012-10-23 19:12:21696WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21697 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
698 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31699}
700
[email protected]8ff00d72012-10-23 19:12:21701WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21702 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34703}
704
[email protected]86ef6a392012-05-11 22:03:11705void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22706 if (GetUserAgentOverride() == override)
707 return;
708
709 renderer_preferences_.user_agent_override = override;
710
711 // Send the new override string to the renderer.
712 RenderViewHost* host = GetRenderViewHost();
713 if (host)
714 host->SyncRendererPrefs();
715
716 // Reload the page if a load is currently in progress to avoid having
717 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27718 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22719 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
720 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53721
722 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
723 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11724}
725
726const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22727 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11728}
729
[email protected]2ceee8f2014-01-14 18:02:08730#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41731void WebContentsImpl::SetParentNativeViewAccessible(
732gfx::NativeViewAccessible accessible_parent) {
733 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45734 if (GetRenderViewHost())
735 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41736}
737#endif
738
[email protected]fcf75d42013-12-03 20:11:26739const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55740 // Transient entries take precedence. They are used for interstitial pages
741 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23742 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08743 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21744 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30745 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23746 if (entry) {
[email protected]b5cca982011-05-26 04:42:08747 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23748 }
[email protected]fa944cb82013-11-15 17:51:21749 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
750 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58751 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54752 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32753 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54754 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35755 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26756 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54757 if (!title.empty())
758 return title;
759 }
760 }
761
762 // We use the title for the last committed entry rather than a pending
763 // navigation entry. For example, when the user types in a URL, we want to
764 // keep the old page's title until the new load has committed and we get a new
765 // title.
[email protected]96d185d2009-04-24 03:28:54766 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32767
[email protected]9eeafc012013-11-25 23:49:47768 // We make an exception for initial navigations.
769 if (controller_.IsInitialNavigation()) {
770 // We only want to use the title from the visible entry in one of two cases:
771 // 1. There's already a committed entry for an initial navigation, in which
772 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
773 // 2. The pending entry has been explicitly assigned a title to display.
774 //
775 // If there's no last committed entry and no assigned title, we should fall
776 // back to |page_title_when_no_navigation_entry_| rather than showing the
777 // URL.
778 if (entry ||
779 (controller_.GetVisibleEntry() &&
780 !controller_.GetVisibleEntry()->GetTitle().empty())) {
781 entry = controller_.GetVisibleEntry();
782 }
783 }
[email protected]59167c22013-06-03 18:07:32784
[email protected]45d0ef7f2011-01-05 13:46:23785 if (entry) {
[email protected]b5cca982011-05-26 04:42:08786 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23787 }
[email protected]987fc3a2011-05-26 14:18:09788
789 // |page_title_when_no_navigation_entry_| is finally used
790 // if no title cannot be retrieved.
791 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54792}
793
[email protected]b172aee2012-04-10 17:05:26794int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46795 return GetMaxPageIDForSiteInstance(GetSiteInstance());
796}
797
[email protected]b172aee2012-04-10 17:05:26798int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
799 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33800 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
801 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46802
[email protected]b6583592012-01-25 19:52:33803 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34804}
805
[email protected]b172aee2012-04-10 17:05:26806void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46807 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
808}
809
[email protected]b172aee2012-04-10 17:05:26810void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33811 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46812 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33813 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34814}
815
[email protected]ec6c05f2013-10-23 18:41:57816void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
817 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
818 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57819}
820
[email protected]b172aee2012-04-10 17:05:26821SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21822 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54823}
824
[email protected]b172aee2012-04-10 17:05:26825SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21826 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
827 GetRenderManager()->pending_render_view_host() :
828 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58829 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38830}
831
[email protected]b172aee2012-04-10 17:05:26832bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31833 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49834}
835
[email protected]b172aee2012-04-10 17:05:26836bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31837 return waiting_for_response_;
838}
839
[email protected]b172aee2012-04-10 17:05:26840const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31841 return load_state_;
842}
843
[email protected]fcf75d42013-12-03 20:11:26844const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31845 return load_state_host_;
846}
847
[email protected]b172aee2012-04-10 17:05:26848uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31849 return upload_size_;
850}
851
[email protected]b172aee2012-04-10 17:05:26852uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31853 return upload_position_;
854}
855
[email protected]1ae93fb2013-06-14 03:38:56856std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56857 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39858 frame_tree_.ForEach(base::Bind(&CollectSites,
859 base::Unretained(GetBrowserContext()),
860 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56861 return sites;
862}
863
[email protected]b172aee2012-04-10 17:05:26864const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54865 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31866}
867
[email protected]b172aee2012-04-10 17:05:26868bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31869 return displayed_insecure_content_;
870}
871
[email protected]222f5822014-02-05 23:40:49872void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25873 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55874 ++capturer_count_;
875 DVLOG(1) << "There are now " << capturer_count_
876 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49877
878 // Note: This provides a hint to upstream code to size the views optimally
879 // for quality (e.g., to avoid scaling).
880 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
881 preferred_size_for_capture_ = capture_size;
882 OnPreferredSizeChanged(preferred_size_);
883 }
[email protected]54597982013-02-06 01:59:55884}
885
886void WebContentsImpl::DecrementCapturerCount() {
887 --capturer_count_;
888 DVLOG(1) << "There are now " << capturer_count_
889 << " capturing(s) of WebContentsImpl@" << this;
890 DCHECK_LE(0, capturer_count_);
891
[email protected]5a652232013-02-12 06:15:25892 if (is_being_destroyed_)
893 return;
894
[email protected]222f5822014-02-05 23:40:49895 if (capturer_count_ == 0) {
896 const gfx::Size old_size = preferred_size_for_capture_;
897 preferred_size_for_capture_ = gfx::Size();
898 OnPreferredSizeChanged(old_size);
899 }
900
[email protected]1ac10dca2013-08-20 20:47:04901 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55902 DVLOG(1) << "Executing delayed WasHidden().";
903 WasHidden();
904 }
[email protected]be1f56ab2011-12-22 06:55:31905}
906
[email protected]f2bd40812013-07-20 04:30:44907int WebContentsImpl::GetCapturerCount() const {
908 return capturer_count_;
909}
910
[email protected]b172aee2012-04-10 17:05:26911bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31912 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
913 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
914 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49915}
916
[email protected]b172aee2012-04-10 17:05:26917void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
918 int error_code) {
[email protected]443b80e2010-12-14 00:42:23919 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34920 return;
921
[email protected]443b80e2010-12-14 00:42:23922 crashed_status_ = status;
923 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21924 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34925}
926
[email protected]b172aee2012-04-10 17:05:26927base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31928 return crashed_status_;
929}
930
[email protected]b172aee2012-04-10 17:05:26931bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31932 return is_being_destroyed_;
933}
934
[email protected]b172aee2012-04-10 17:05:26935void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34936 if (delegate_)
937 delegate_->NavigationStateChanged(this, changed_flags);
938}
939
[email protected]9a890452014-02-13 22:21:02940base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
941 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33942}
943
[email protected]9e2e4632012-07-27 16:38:41944void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54945 controller_.SetActive(true);
[email protected]cfd80b02014-05-01 17:46:48946 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]8cb5d5b2010-02-09 11:36:16947 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29948 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43949#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16950 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43951#endif
952 }
[email protected]96d185d2009-04-24 03:28:54953
[email protected]9a890452014-02-13 22:21:02954 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38955
[email protected]b9769d82012-02-10 00:23:59956 // The resize rect might have changed while this was inactive -- send the new
957 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58958 RenderViewHostImpl* rvh =
959 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59960 if (rvh) {
961 rvh->ResizeRectChanged(GetRootWindowResizerRect());
962 }
[email protected]96d185d2009-04-24 03:28:54963
[email protected]c0d9d5672013-10-09 07:38:03964 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
965
[email protected]54597982013-02-06 01:59:55966 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31967}
968
[email protected]b172aee2012-04-10 17:05:26969void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55970 // If there are entities capturing screenshots or video (e.g., mirroring),
971 // don't activate the "disable rendering" optimization.
972 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52973 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55974 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26975 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52976 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33977 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52978 // calls us).
[email protected]cfd80b02014-05-01 17:46:48979 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]8cb5d5b2010-02-09 11:36:16980 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29981 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54982 }
983
[email protected]c0d9d5672013-10-09 07:38:03984 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
985
[email protected]54597982013-02-06 01:59:55986 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37987}
988
[email protected]b172aee2012-04-10 17:05:26989bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31990 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27991 return WillNotifyDisconnection() &&
992 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58993 !static_cast<RenderViewHostImpl*>(
994 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31995}
996
[email protected]1c3f80bd2014-04-08 23:02:06997void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
998 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
999 for_cross_site_transition);
1000}
1001
[email protected]b172aee2012-04-10 17:05:261002void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211003 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401004 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271005}
1006
[email protected]b172aee2012-04-10 17:05:261007WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441008 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451009 // We pass our own opener so that the cloned page can access it if it was
1010 // before.
[email protected]54944cde2012-12-09 09:24:591011 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451012 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591013 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191014 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221015 FOR_EACH_OBSERVER(WebContentsObserver,
1016 observers_,
1017 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271018 return tc;
1019}
1020
[email protected]14392a52012-05-02 20:28:441021void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211022 const NotificationSource& source,
1023 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441024 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211025 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1026 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501027 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1028 i != pending_widget_views_.end(); ++i) {
1029 if (host->GetView() == i->second) {
1030 pending_widget_views_.erase(i);
1031 break;
1032 }
1033 }
1034 break;
1035 }
[email protected]14392a52012-05-02 20:28:441036 default:
1037 NOTREACHED();
1038 }
1039}
1040
[email protected]ec6c05f2013-10-23 18:41:571041WebContents* WebContentsImpl::GetWebContents() {
1042 return this;
1043}
1044
[email protected]54944cde2012-12-09 09:24:591045void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211046 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361047 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211048 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431049 should_normally_be_visible_ = !params.initially_hidden;
1050
[email protected]fa944cb82013-11-15 17:51:211051 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041052 params.browser_context, params.site_instance, params.routing_id,
1053 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191054
[email protected]fc2b46b2014-05-03 16:33:451055 WebContentsViewDelegate* delegate =
1056 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1057
1058 if (browser_plugin_guest_) {
1059 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1060 this, delegate, &render_view_host_delegate_view_));
1061
1062 WebContentsViewGuest* rv = new WebContentsViewGuest(
1063 this, browser_plugin_guest_.get(), platform_view.Pass(),
1064 render_view_host_delegate_view_);
1065 render_view_host_delegate_view_ = rv;
1066 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191067 } else {
[email protected]fc2b46b2014-05-03 16:33:451068 // Regular WebContentsView.
1069 view_.reset(CreateWebContentsView(
1070 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191071 }
[email protected]fc2b46b2014-05-03 16:33:451072 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191073 CHECK(view_.get());
1074
[email protected]ed245db2012-12-18 08:00:451075 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591076 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191077
1078 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101079 if (opener_)
1080 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191081
1082 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211083 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1084 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101085
1086 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
1087
[email protected]c7654a232013-06-12 21:04:441088#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101089 date_time_chooser_.reset(new DateTimeChooserAndroid());
1090#endif
[email protected]d1198fd2012-08-13 22:50:191091}
1092
[email protected]7fff43e2013-05-21 20:21:101093void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1094 RemoveDestructionObserver(web_contents);
1095
[email protected]14392a52012-05-02 20:28:441096 // Clear the opener if it has been closed.
1097 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441098 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511099 return;
[email protected]14392a52012-05-02 20:28:441100 }
[email protected]ceee8cd2013-03-08 04:59:511101 // Clear a pending contents that has been closed before being shown.
1102 for (PendingContents::iterator iter = pending_contents_.begin();
1103 iter != pending_contents_.end();
1104 ++iter) {
1105 if (iter->second != web_contents)
1106 continue;
1107 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511108 return;
1109 }
1110 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441111}
1112
[email protected]7fff43e2013-05-21 20:21:101113void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1114 if (!ContainsKey(destruction_observers_, web_contents)) {
1115 destruction_observers_[web_contents] =
1116 new DestructionObserver(this, web_contents);
1117 }
1118}
1119
1120void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1121 DestructionObservers::iterator iter =
1122 destruction_observers_.find(web_contents);
1123 if (iter != destruction_observers_.end()) {
1124 delete destruction_observers_[web_contents];
1125 destruction_observers_.erase(iter);
1126 }
1127}
1128
[email protected]b172aee2012-04-10 17:05:261129void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311130 observers_.AddObserver(observer);
1131}
1132
[email protected]b172aee2012-04-10 17:05:261133void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311134 observers_.RemoveObserver(observer);
1135}
1136
[email protected]b172aee2012-04-10 17:05:261137void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341138 if (delegate_)
1139 delegate_->ActivateContents(this);
1140}
1141
[email protected]b172aee2012-04-10 17:05:261142void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121143 if (delegate_)
1144 delegate_->DeactivateContents(this);
1145}
1146
[email protected]b172aee2012-04-10 17:05:261147void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481148 if (delegate_)
1149 delegate_->LostCapture();
1150}
1151
[email protected]b24b68a2012-09-24 21:57:261152void WebContentsImpl::RenderWidgetDeleted(
1153 RenderWidgetHostImpl* render_widget_host) {
1154 if (is_being_destroyed_) {
1155 // |created_widgets_| might have been destroyed.
1156 return;
1157 }
1158
1159 std::set<RenderWidgetHostImpl*>::iterator iter =
1160 created_widgets_.find(render_widget_host);
1161 if (iter != created_widgets_.end())
1162 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541163
1164 if (render_widget_host &&
1165 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491166 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1167 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541168 FOR_EACH_OBSERVER(WebContentsObserver,
1169 observers_,
1170 DidDestroyFullscreenWidget(
1171 fullscreen_widget_routing_id_));
1172 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1173 }
[email protected]b24b68a2012-09-24 21:57:261174}
1175
[email protected]b172aee2012-04-10 17:05:261176bool WebContentsImpl::PreHandleKeyboardEvent(
1177 const NativeWebKeyboardEvent& event,
1178 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481179 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131180 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481181}
1182
[email protected]b172aee2012-04-10 17:05:261183void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481184 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131185 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481186}
1187
[email protected]d92026ef2014-03-03 21:04:131188bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461189 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191190#if !defined(OS_MACOSX)
1191 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1192 // isn't done for two reasons:
1193 // -the OS already has a gesture to do this through pinch-zoom
1194 // -if a user starts an inertial scroll, let's go, and presses control
1195 // (i.e. control+tab) then the OS's buffered scroll events will come in
1196 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521197 if (delegate_ &&
1198 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551199 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1200 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1201 // gestures, which are regrettably easy to trigger accidentally.
1202 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521203 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1204 return true;
1205 }
[email protected]bccc4472013-04-18 16:37:191206#endif
[email protected]fb3f066e2013-02-12 19:12:521207 return false;
1208}
1209
[email protected]04bce562014-01-30 05:34:541210bool WebContentsImpl::PreHandleGestureEvent(
1211 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031212 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541213}
1214
[email protected]bab38af2014-03-30 17:37:291215bool WebContentsImpl::HandleGestureEvent(
1216 const blink::WebGestureEvent& event) {
1217 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1218 // Use them to implement browser zoom, as for HandleWheelEvent above.
1219 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1220 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1221 // The scale difference necessary to trigger a zoom action. Derived from
1222 // experimentation to find a value that feels reasonable.
1223 const float kZoomStepValue = 0.6f;
1224
1225 // Find the (absolute) thresholds on either side of the current zoom factor,
1226 // then convert those to actual numbers to trigger a zoom in or out.
1227 // This logic deliberately makes the range around the starting zoom value
1228 // for the gesture twice as large as the other ranges (i.e., the notches are
1229 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1230 // so that it's easier to get back to your starting point than it is to
1231 // overshoot.
1232 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1233 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1234 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1235 : -backStep;
1236 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1237 : backStep;
1238
[email protected]fb546cb2014-04-28 14:09:371239 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291240 if (totalPinchGestureAmount_ > zoomInThreshold) {
1241 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461242 if (delegate_)
1243 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291244 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1245 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461246 if (delegate_)
1247 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291248 }
1249 return true;
1250 }
1251
1252 return false;
1253}
1254
[email protected]2ceee8f2014-01-14 18:02:081255#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411256gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1257 return accessible_parent_;
1258}
1259#endif
1260
[email protected]b172aee2012-04-10 17:05:261261void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431262 if (delegate_)
1263 delegate_->HandleMouseDown();
1264}
1265
[email protected]b172aee2012-04-10 17:05:261266void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481267 if (delegate_)
1268 delegate_->HandleMouseUp();
1269}
1270
[email protected]590a634e2012-07-19 16:38:231271void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481272 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231273 delegate_->HandlePointerActivate();
1274}
1275
1276void WebContentsImpl::HandleGestureBegin() {
1277 if (delegate_)
1278 delegate_->HandleGestureBegin();
1279}
1280
1281void WebContentsImpl::HandleGestureEnd() {
1282 if (delegate_)
1283 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481284}
1285
[email protected]b172aee2012-04-10 17:05:261286void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491287 // This method is being called to enter or leave renderer-initiated fullscreen
1288 // mode. Either way, make sure any existing fullscreen widget is shut down
1289 // first.
1290 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1291 if (widget_view)
1292 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1293
[email protected]8a5e0ca2011-08-25 06:30:471294 if (delegate_)
1295 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371296
1297 FOR_EACH_OBSERVER(WebContentsObserver,
1298 observers_,
1299 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471300}
1301
[email protected]b172aee2012-04-10 17:05:261302bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381303 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121304}
1305
[email protected]a9c81f02012-06-01 00:15:441306void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1307 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371308 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441309 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371310 } else {
1311 GotResponseToLockMouseRequest(false);
1312 }
1313}
1314
[email protected]b172aee2012-04-10 17:05:261315void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371316 if (delegate_)
1317 delegate_->LostMouseLock();
1318}
1319
[email protected]bafe6cd2012-05-23 23:09:501320void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201321 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501322 int route_id,
[email protected]227692c52013-05-31 22:43:041323 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131324 const ViewHostMsg_CreateWindow_Params& params,
1325 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501326 // We usually create the new window in the same BrowsingInstance (group of
1327 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551328 // if the opener is being suppressed (in a non-guest), we create a new
1329 // SiteInstance in its own BrowsingInstance.
1330 bool is_guest = GetRenderProcessHost()->IsGuest();
1331
[email protected]04cbd3d2013-12-04 04:58:201332 // If the opener is to be suppressed, the new window can be in any process.
1333 // Since routing ids are process specific, we must not have one passed in
1334 // as argument here.
1335 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1336
[email protected]bafe6cd2012-05-23 23:09:501337 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551338 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571339 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501340 GetSiteInstance();
1341
[email protected]04cbd3d2013-12-04 04:58:201342 // A message to create a new window can only come from the active process for
1343 // this WebContentsImpl instance. If any other process sends the request,
1344 // it is invalid and the process must be terminated.
1345 if (GetRenderProcessHost()->GetID() != render_process_id) {
1346 base::ProcessHandle process_handle =
1347 RenderProcessHost::FromID(render_process_id)->GetHandle();
1348 if (process_handle != base::kNullProcessHandle) {
1349 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391350 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201351 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1352 }
1353 return;
1354 }
1355
[email protected]d1198fd2012-08-13 22:50:191356 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341357 //
1358 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301359 const std::string& partition_id =
1360 GetContentClient()->browser()->
1361 GetStoragePartitionIdForSite(GetBrowserContext(),
1362 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461363 StoragePartition* partition = BrowserContext::GetStoragePartition(
1364 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411365 DOMStorageContextWrapper* dom_storage_context =
1366 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191367 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1368 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1369 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371370
1371 if (delegate_ &&
1372 !delegate_->ShouldCreateWebContents(this,
1373 route_id,
1374 params.window_container_type,
1375 params.frame_name,
1376 params.target_url,
1377 partition_id,
1378 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011379 if (route_id != MSG_ROUTING_NONE &&
1380 !RenderViewHost::FromID(render_process_id, route_id)) {
1381 // If the embedder didn't create a WebContents for this route, we need to
1382 // delete the RenderView that had already been created.
1383 Send(new ViewMsg_Close(route_id));
1384 }
[email protected]dd6730412013-08-14 15:03:371385 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1386 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1387 main_frame_route_id);
1388 return;
1389 }
1390
1391 // Create the new web contents. This will automatically create the new
1392 // WebContentsView. In the future, we may want to create the view separately.
1393 WebContentsImpl* new_contents =
1394 new WebContentsImpl(GetBrowserContext(),
1395 params.opener_suppressed ? NULL : this);
1396
[email protected]d1198fd2012-08-13 22:50:191397 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301398 partition_id,
[email protected]d1198fd2012-08-13 22:50:191399 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461400 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591401 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041402 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551403 if (!is_guest) {
1404 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451405 create_params.initial_size = GetContainerBounds().size();
[email protected]c4538072013-03-18 02:17:551406 } else {
1407 // This makes |new_contents| act as a guest.
1408 // For more info, see comment above class BrowserPluginGuest.
[email protected]24569262014-05-06 03:31:301409 int instance_id =
[email protected]139355f2014-05-11 14:21:281410 GetBrowserContext()->GetGuestManager()->GetNextInstanceID();
[email protected]c4538072013-03-18 02:17:551411 WebContentsImpl* new_contents_impl =
1412 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461413 BrowserPluginGuest::CreateWithOpener(instance_id,
1414 new_contents_impl->opener() != NULL,
1415 new_contents_impl,
1416 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551417 }
[email protected]1ac10dca2013-08-20 20:47:041418 if (params.disposition == NEW_BACKGROUND_TAB)
1419 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591420 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191421
[email protected]c4538072013-03-18 02:17:551422 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341423 // will be shown immediately).
1424 if (!params.opener_suppressed) {
1425 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451426 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501427
[email protected]d70bea92013-04-05 04:23:341428 // TODO(brettw): It seems bogus that we have to call this function on the
1429 // newly created object and give it one of its own member variables.
1430 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1431 }
[email protected]bafe6cd2012-05-23 23:09:501432 // Save the created window associated with the route so we can show it
1433 // later.
1434 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1435 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101436 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501437 }
1438
1439 if (delegate_) {
1440 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071441 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131442 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501443 }
1444
1445 if (params.opener_suppressed) {
1446 // When the opener is suppressed, the original renderer cannot access the
1447 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001448 bool was_blocked = false;
1449 if (delegate_) {
1450 gfx::Rect initial_pos;
1451 delegate_->AddNewContents(
1452 this, new_contents, params.disposition, initial_pos,
1453 params.user_gesture, &was_blocked);
1454 }
1455 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211456 OpenURLParams open_params(params.target_url,
1457 Referrer(),
1458 CURRENT_TAB,
1459 PAGE_TRANSITION_LINK,
1460 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301461 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001462 new_contents->OpenURL(open_params);
1463 }
[email protected]bafe6cd2012-05-23 23:09:501464 }
1465}
1466
[email protected]a8504022013-12-04 20:23:511467void WebContentsImpl::CreateNewWidget(int render_process_id,
1468 int route_id,
[email protected]180ef242013-11-07 06:50:461469 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511470 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501471}
1472
[email protected]a8504022013-12-04 20:23:511473void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1474 int route_id) {
1475 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501476}
1477
[email protected]a8504022013-12-04 20:23:511478void WebContentsImpl::CreateNewWidget(int render_process_id,
1479 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501480 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461481 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211482 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511483 // A message to create a new widget can only come from the active process for
1484 // this WebContentsImpl instance. If any other process sends the request,
1485 // it is invalid and the process must be terminated.
1486 if (process->GetID() != render_process_id) {
1487 base::ProcessHandle process_handle =
1488 RenderProcessHost::FromID(render_process_id)->GetHandle();
1489 if (process_handle != base::kNullProcessHandle) {
1490 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391491 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511492 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1493 }
1494 return;
1495 }
1496
[email protected]bafe6cd2012-05-23 23:09:501497 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041498 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261499 created_widgets_.insert(widget_host);
1500
[email protected]cfd80b02014-05-01 17:46:481501 RenderWidgetHostViewBase* widget_view =
1502 static_cast<RenderWidgetHostViewBase*>(
1503 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191504 if (!widget_view)
1505 return;
[email protected]bafe6cd2012-05-23 23:09:501506 if (!is_fullscreen) {
1507 // Popups should not get activated.
1508 widget_view->SetPopupType(popup_type);
1509 }
1510 // Save the created widget associated with the route so we can show it later.
1511 pending_widget_views_[route_id] = widget_view;
1512
1513#if defined(OS_MACOSX)
1514 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1515 // to allow it to survive the trip without being hosted.
1516 base::mac::NSObjectRetain(widget_view->GetNativeView());
1517#endif
1518}
1519
1520void WebContentsImpl::ShowCreatedWindow(int route_id,
1521 WindowOpenDisposition disposition,
1522 const gfx::Rect& initial_pos,
1523 bool user_gesture) {
1524 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001525 if (contents) {
1526 WebContentsDelegate* delegate = GetDelegate();
1527 if (delegate) {
1528 delegate->AddNewContents(
1529 this, contents, disposition, initial_pos, user_gesture, NULL);
1530 }
1531 }
[email protected]bafe6cd2012-05-23 23:09:501532}
1533
1534void WebContentsImpl::ShowCreatedWidget(int route_id,
1535 const gfx::Rect& initial_pos) {
1536 ShowCreatedWidget(route_id, false, initial_pos);
1537}
1538
1539void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1540 ShowCreatedWidget(route_id, true, gfx::Rect());
1541}
1542
1543void WebContentsImpl::ShowCreatedWidget(int route_id,
1544 bool is_fullscreen,
1545 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481546 RenderWidgetHostViewBase* widget_host_view =
1547 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501548 if (!widget_host_view)
1549 return;
[email protected]cfd80b02014-05-01 17:46:481550
1551 RenderWidgetHostView* view = NULL;
1552 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1553 if (guest && guest->embedder_web_contents()) {
1554 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1555 } else {
1556 view = GetRenderWidgetHostView();
1557 }
1558
[email protected]4aebbca2013-09-17 22:26:491559 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311560 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1561 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491562 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1563 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1564 delegate_->ToggleFullscreenModeForTab(this, true);
1565 } else {
[email protected]cfd80b02014-05-01 17:46:481566 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491567 }
[email protected]4aebbca2013-09-17 22:26:491568 FOR_EACH_OBSERVER(WebContentsObserver,
1569 observers_,
1570 DidShowFullscreenWidget(route_id));
1571 if (!widget_host_view->HasFocus())
1572 widget_host_view->Focus();
1573 } else {
[email protected]cfd80b02014-05-01 17:46:481574 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491575 }
[email protected]89054502012-06-03 10:29:241576
1577 RenderWidgetHostImpl* render_widget_host_impl =
1578 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1579 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311580 // Only allow privileged mouse lock for fullscreen render widget, which is
1581 // used to implement Pepper Flash fullscreen.
1582 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501583
1584#if defined(OS_MACOSX)
1585 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1586 // properly embedded (or purposefully ignored) we can release the retain we
1587 // took in CreateNewWidget().
1588 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1589#endif
1590}
1591
1592WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1593 PendingContents::iterator iter = pending_contents_.find(route_id);
1594
1595 // Certain systems can block the creation of new windows. If we didn't succeed
1596 // in creating one, just return NULL.
1597 if (iter == pending_contents_.end()) {
1598 return NULL;
1599 }
1600
1601 WebContentsImpl* new_contents = iter->second;
1602 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101603 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501604
[email protected]d70bea92013-04-05 04:23:341605 // Don't initialize the guest WebContents immediately.
1606 if (new_contents->GetRenderProcessHost()->IsGuest())
1607 return new_contents;
1608
[email protected]bafe6cd2012-05-23 23:09:501609 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1610 !new_contents->GetRenderViewHost()->GetView())
1611 return NULL;
1612
1613 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1614 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1615 return new_contents;
1616}
1617
1618RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1619 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1620 if (iter == pending_widget_views_.end()) {
1621 DCHECK(false);
1622 return NULL;
1623 }
1624
1625 RenderWidgetHostView* widget_host_view = iter->second;
1626 pending_widget_views_.erase(route_id);
1627
1628 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1629 if (!widget_host->GetProcess()->HasConnection()) {
1630 // The view has gone away or the renderer crashed. Nothing to do.
1631 return NULL;
1632 }
1633
1634 return widget_host_view;
1635}
1636
[email protected]f13b4202012-06-12 23:53:231637void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091638 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211639 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371640 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231641 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371642 } else {
1643 callback.Run(MediaStreamDevices(),
1644 MEDIA_DEVICE_INVALID_STATE,
1645 scoped_ptr<MediaStreamUI>());
1646 }
[email protected]f13b4202012-06-12 23:53:231647}
1648
[email protected]cc9200432013-07-23 23:02:401649SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1650 SiteInstance* instance) {
1651 return controller_.GetSessionStorageNamespace(instance);
1652}
1653
[email protected]9b159a52013-10-03 17:24:551654FrameTree* WebContentsImpl::GetFrameTree() {
1655 return &frame_tree_;
1656}
1657
[email protected]31a71eaf2014-03-13 01:47:361658void WebContentsImpl::AccessibilityEventReceived(
1659 const std::vector<AXEventNotificationDetails>& details) {
1660 FOR_EACH_OBSERVER(
1661 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1662}
1663
[email protected]edc3af82013-12-12 21:24:071664void WebContentsImpl::OnShowValidationMessage(
1665 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291666 const base::string16& main_text,
1667 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071668 if (delegate_)
1669 delegate_->ShowValidationMessage(
1670 this, anchor_in_root_view, main_text, sub_text);
1671}
1672
1673void WebContentsImpl::OnHideValidationMessage() {
1674 if (delegate_)
1675 delegate_->HideValidationMessage(this);
1676}
1677
1678void WebContentsImpl::OnMoveValidationMessage(
1679 const gfx::Rect& anchor_in_root_view) {
1680 if (delegate_)
1681 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1682}
1683
[email protected]32deec62013-05-15 23:55:041684void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1685 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441686 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491690 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231691 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491692 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331693}
1694
[email protected]b172aee2012-04-10 17:05:261695void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341696 if (delegate_)
1697 delegate_->ResizeDueToAutoResize(this, new_size);
1698}
1699
[email protected]b172aee2012-04-10 17:05:261700WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201701 if (!delegate_)
1702 return NULL;
[email protected]00c37fc2011-08-02 00:22:501703
[email protected]e5d549d2011-12-28 01:29:201704 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201705 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341706}
1707
[email protected]6b618e62012-08-16 12:59:181708bool WebContentsImpl::Send(IPC::Message* message) {
1709 if (!GetRenderViewHost()) {
1710 delete message;
1711 return false;
1712 }
1713
1714 return GetRenderViewHost()->Send(message);
1715}
1716
[email protected]b172aee2012-04-10 17:05:261717bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501718 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261719 FrameTreeNode* node = frame_tree_.root();
1720
1721 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1722 // specified in the pending entry.
1723 NavigationEntryImpl* pending_entry =
1724 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1725 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1726 pending_entry->frame_tree_node_id() != -1) {
1727 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1728 }
1729
1730 return node->navigator()->NavigateToPendingEntry(
1731 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541732}
[email protected]96d185d2009-04-24 03:28:541733
[email protected]a86c0e962013-12-17 17:10:391734void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1735 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441736 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391737 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441738}
1739
[email protected]20ca0382013-02-28 19:50:071740void WebContentsImpl::AttachInterstitialPage(
1741 InterstitialPageImpl* interstitial_page) {
1742 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211743 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291744
1745 // Cancel any visible dialogs so that they don't interfere with the
1746 // interstitial.
1747 if (dialog_manager_)
1748 dialog_manager_->CancelActiveAndPendingDialogs(this);
1749
[email protected]20ca0382013-02-28 19:50:071750 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1751 DidAttachInterstitialPage());
1752}
1753
1754void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571755 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211756 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071757 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1758 DidDetachInterstitialPage());
1759}
1760
[email protected]b172aee2012-04-10 17:05:261761void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331762 const SiteInstance* site_instance,
1763 int history_length,
1764 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411765 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1766 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211767 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191768 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141769 return;
[email protected]9e1ad4b2011-08-14 16:49:191770 }
[email protected]9f76c1e2012-03-05 15:15:581771 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191772 if (!rvh) {
1773 NOTREACHED();
1774 return;
1775 }
[email protected]9f76c1e2012-03-05 15:15:581776 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191777 NOTREACHED();
1778 return;
1779 }
[email protected]6b618e62012-08-16 12:59:181780 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1781 history_length,
1782 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141783}
1784
[email protected]4fed3702014-04-01 09:08:001785void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171786 RenderFrameHost* focused_frame = GetFocusedFrame();
1787 if (!focused_frame)
1788 return;
1789
[email protected]959be4c2014-04-08 15:01:331790 focused_frame->Send(new FrameMsg_Reload(
1791 focused_frame->GetRoutingID(), ignore_cache));
1792}
1793
1794void WebContentsImpl::Undo() {
1795 RenderFrameHost* focused_frame = GetFocusedFrame();
1796 if (!focused_frame)
1797 return;
1798
1799 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1800 RecordAction(base::UserMetricsAction("Undo"));
1801}
1802
1803void WebContentsImpl::Redo() {
1804 RenderFrameHost* focused_frame = GetFocusedFrame();
1805 if (!focused_frame)
1806 return;
1807 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1808 RecordAction(base::UserMetricsAction("Redo"));
1809}
1810
1811void WebContentsImpl::Cut() {
1812 RenderFrameHost* focused_frame = GetFocusedFrame();
1813 if (!focused_frame)
1814 return;
1815
1816 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1817 RecordAction(base::UserMetricsAction("Cut"));
1818}
1819
1820void WebContentsImpl::Copy() {
1821 RenderFrameHost* focused_frame = GetFocusedFrame();
1822 if (!focused_frame)
1823 return;
1824
1825 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1826 RecordAction(base::UserMetricsAction("Copy"));
1827}
1828
1829void WebContentsImpl::CopyToFindPboard() {
1830#if defined(OS_MACOSX)
1831 RenderFrameHost* focused_frame = GetFocusedFrame();
1832 if (!focused_frame)
1833 return;
1834
1835 // Windows/Linux don't have the concept of a find pasteboard.
1836 focused_frame->Send(
1837 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1838 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1839#endif
1840}
1841
1842void WebContentsImpl::Paste() {
1843 RenderFrameHost* focused_frame = GetFocusedFrame();
1844 if (!focused_frame)
1845 return;
1846
1847 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1848 RecordAction(base::UserMetricsAction("Paste"));
1849}
1850
1851void WebContentsImpl::PasteAndMatchStyle() {
1852 RenderFrameHost* focused_frame = GetFocusedFrame();
1853 if (!focused_frame)
1854 return;
1855
1856 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1857 focused_frame->GetRoutingID()));
1858 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1859}
1860
1861void WebContentsImpl::Delete() {
1862 RenderFrameHost* focused_frame = GetFocusedFrame();
1863 if (!focused_frame)
1864 return;
1865
1866 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1867 RecordAction(base::UserMetricsAction("DeleteSelection"));
1868}
1869
1870void WebContentsImpl::SelectAll() {
1871 RenderFrameHost* focused_frame = GetFocusedFrame();
1872 if (!focused_frame)
1873 return;
1874
1875 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1876 RecordAction(base::UserMetricsAction("SelectAll"));
1877}
1878
1879void WebContentsImpl::Unselect() {
1880 RenderFrameHost* focused_frame = GetFocusedFrame();
1881 if (!focused_frame)
1882 return;
1883
1884 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1885 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171886}
1887
1888void WebContentsImpl::Replace(const base::string16& word) {
1889 RenderFrameHost* focused_frame = GetFocusedFrame();
1890 if (!focused_frame)
1891 return;
1892
[email protected]959be4c2014-04-08 15:01:331893 focused_frame->Send(new InputMsg_Replace(
1894 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171895}
1896
1897void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1898 RenderFrameHost* focused_frame = GetFocusedFrame();
1899 if (!focused_frame)
1900 return;
1901
[email protected]959be4c2014-04-08 15:01:331902 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1903 focused_frame->GetRoutingID(), word));
1904}
1905
1906void WebContentsImpl::NotifyContextMenuClosed(
1907 const CustomContextMenuContext& context) {
1908 RenderFrameHost* focused_frame = GetFocusedFrame();
1909 if (!focused_frame)
1910 return;
1911
1912 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1913 focused_frame->GetRoutingID(), context));
1914}
1915
1916void WebContentsImpl::ExecuteCustomContextMenuCommand(
1917 int action, const CustomContextMenuContext& context) {
1918 RenderFrameHost* focused_frame = GetFocusedFrame();
1919 if (!focused_frame)
1920 return;
1921
1922 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1923 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001924}
1925
[email protected]fc2b46b2014-05-03 16:33:451926gfx::NativeView WebContentsImpl::GetNativeView() {
1927 return view_->GetNativeView();
1928}
1929
1930gfx::NativeView WebContentsImpl::GetContentNativeView() {
1931 return view_->GetContentNativeView();
1932}
1933
1934gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1935 return view_->GetTopLevelNativeWindow();
1936}
1937
1938gfx::Rect WebContentsImpl::GetViewBounds() {
1939 return view_->GetViewBounds();
1940}
1941
1942gfx::Rect WebContentsImpl::GetContainerBounds() {
1943 gfx::Rect rv;
1944 view_->GetContainerBounds(&rv);
1945 return rv;
1946}
1947
1948DropData* WebContentsImpl::GetDropData() {
1949 return view_->GetDropData();
1950}
1951
1952void WebContentsImpl::Focus() {
1953 view_->Focus();
1954}
1955
1956void WebContentsImpl::SetInitialFocus() {
1957 view_->SetInitialFocus();
1958}
1959
1960void WebContentsImpl::StoreFocus() {
1961 view_->StoreFocus();
1962}
1963
1964void WebContentsImpl::RestoreFocus() {
1965 view_->RestoreFocus();
1966}
1967
[email protected]b172aee2012-04-10 17:05:261968void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271969 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211970 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541971 return;
1972 }
[email protected]9f76c1e2012-03-05 15:15:581973 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541974}
1975
[email protected]b172aee2012-04-10 17:05:261976bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211977 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541978}
1979
[email protected]b172aee2012-04-10 17:05:261980InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211981 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221982}
1983
[email protected]b172aee2012-04-10 17:05:261984bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161985 // WebKit creates Document object when MIME type is application/xhtml+xml,
1986 // so we also support this MIME type.
1987 return contents_mime_type_ == "text/html" ||
1988 contents_mime_type_ == "text/xml" ||
1989 contents_mime_type_ == "application/xhtml+xml" ||
1990 contents_mime_type_ == "text/plain" ||
1991 contents_mime_type_ == "text/css" ||
1992 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1993}
1994
[email protected]b172aee2012-04-10 17:05:261995void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591996 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161997 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551998 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011999 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142000 return;
[email protected]c7dd2f62011-07-18 15:57:592001 }
2002
2003 Stop();
2004
2005 // Create the save package and possibly prompt the user for the name to save
2006 // the page as. The user prompt is an asynchronous operation that runs on
2007 // another thread.
2008 save_package_ = new SavePackage(this);
2009 save_package_->GetSaveInfo();
2010}
2011
2012// Used in automated testing to bypass prompting the user for file names.
2013// Instead, the names and paths are hard coded rather than running them through
2014// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342015bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2016 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212017 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592018 // Stop the page from navigating.
2019 Stop();
2020
2021 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212022 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592023}
2024
[email protected]3c71576ce2013-07-23 02:00:012025void WebContentsImpl::SaveFrame(const GURL& url,
2026 const Referrer& referrer) {
2027 if (!GetURL().is_valid())
2028 return;
2029 bool is_main_frame = (url == GetURL());
2030
2031 DownloadManager* dlm =
2032 BrowserContext::GetDownloadManager(GetBrowserContext());
2033 if (!dlm)
2034 return;
2035 int64 post_id = -1;
2036 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272037 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012038 if (entry)
2039 post_id = entry->GetPostID();
2040 }
2041 scoped_ptr<DownloadUrlParameters> params(
2042 DownloadUrlParameters::FromWebContents(this, url));
2043 params->set_referrer(referrer);
2044 params->set_post_id(post_id);
2045 params->set_prefer_cache(true);
2046 if (post_id >= 0)
2047 params->set_method("POST");
2048 params->set_prompt(true);
2049 dlm->DownloadUrl(params.Pass());
2050}
2051
[email protected]b172aee2012-04-10 17:05:262052void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342053 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482054 const base::Callback<void(int64)>& callback) {
2055 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122056}
2057
[email protected]6286a372013-10-09 04:03:272058// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262059bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272060 NavigationEntryImpl* visible_entry =
2061 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2062 return (visible_entry != NULL &&
2063 visible_entry->site_instance() == GetSiteInstance() &&
2064 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322065}
2066
[email protected]b172aee2012-04-10 17:05:262067const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272068 return contents_mime_type_;
2069}
2070
[email protected]b172aee2012-04-10 17:05:262071bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272072 return notify_disconnection_;
2073}
2074
[email protected]b172aee2012-04-10 17:05:262075void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312076 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182077 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162078}
2079
[email protected]b172aee2012-04-10 17:05:262080void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542081 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182082 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162083}
2084
[email protected]8ff00d72012-10-23 19:12:212085RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272086 return &renderer_preferences_;
2087}
2088
[email protected]e35ccd52012-05-23 16:22:472089void WebContentsImpl::Close() {
2090 Close(GetRenderViewHost());
2091}
2092
[email protected]cf200a562013-05-03 16:24:292093void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462094 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292095 if (browser_plugin_embedder_.get())
2096 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2097 screen_x, screen_y, operation);
2098 if (GetRenderViewHost())
2099 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2100 screen_x, screen_y, operation);
2101}
2102
[email protected]d60f3702013-12-26 16:30:242103void WebContentsImpl::DidGetResourceResponseStart(
2104 const ResourceRequestDetails& details) {
2105 controller_.ssl_manager()->DidStartResourceResponse(details);
2106
2107 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2108 DidGetResourceResponseStart(details));
2109
2110 // TODO(avi): Remove. http://crbug.com/170921
2111 NotificationService::current()->Notify(
2112 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2113 Source<WebContents>(this),
2114 Details<const ResourceRequestDetails>(&details));
2115}
2116
2117void WebContentsImpl::DidGetRedirectForResourceRequest(
2118 RenderViewHost* render_view_host,
2119 const ResourceRedirectDetails& details) {
2120 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2121
2122 FOR_EACH_OBSERVER(
2123 WebContentsObserver,
2124 observers_,
2125 DidGetRedirectForResourceRequest(render_view_host, details));
2126
2127 // TODO(avi): Remove. http://crbug.com/170921
2128 NotificationService::current()->Notify(
2129 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2130 Source<WebContents>(this),
2131 Details<const ResourceRedirectDetails>(&details));
2132}
2133
[email protected]b172aee2012-04-10 17:05:262134void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522135 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582136 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512137 if (delegate_)
2138 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292139 if (browser_plugin_embedder_.get())
2140 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342141}
2142
[email protected]e35ccd52012-05-23 16:22:472143void WebContentsImpl::UserGestureDone() {
2144 OnUserGesture();
2145}
2146
[email protected]b172aee2012-04-10 17:05:262147void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272148 closed_by_user_gesture_ = value;
2149}
2150
[email protected]b172aee2012-04-10 17:05:262151bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272152 return closed_by_user_gesture_;
2153}
2154
[email protected]b172aee2012-04-10 17:05:262155double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052156 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562157 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252158 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172159 return 0;
[email protected]b75b8292010-10-01 07:28:252160
2161 double zoom_level;
2162 if (temporary_zoom_settings_) {
2163 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582164 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252165 } else {
[email protected]2ae88d12011-10-14 09:11:192166 GURL url;
[email protected]6286a372013-10-09 04:03:272167 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192168 // Since zoom map is updated using rewritten URL, use rewritten URL
2169 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272170 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022171 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2172 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252173 }
[email protected]d0b8d092010-10-25 04:05:172174 return zoom_level;
2175}
[email protected]b75b8292010-10-01 07:28:252176
[email protected]b172aee2012-04-10 17:05:262177int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592178 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172179 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012180 // Calculate the zoom percent from the factor. Round up to the nearest whole
2181 // number.
[email protected]b75b8292010-10-01 07:28:252182 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492183 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252184 *enable_decrement = percent > minimum_zoom_percent_;
2185 *enable_increment = percent < maximum_zoom_percent_;
2186 return percent;
2187}
2188
[email protected]b172aee2012-04-10 17:05:262189void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502190 if (!delegate_)
2191 return;
2192
[email protected]6286a372013-10-09 04:03:272193 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2194 if (!entry)
[email protected]1788e772010-12-15 16:40:502195 return;
2196
[email protected]6286a372013-10-09 04:03:272197 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122198}
2199
[email protected]b172aee2012-04-10 17:05:262200void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042201 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272202 if (!delegate_)
2203 return;
2204
[email protected]691aa2f2013-05-28 22:52:042205 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272206}
2207
[email protected]b172aee2012-04-10 17:05:262208int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272209 return minimum_zoom_percent_;
2210}
2211
[email protected]b172aee2012-04-10 17:05:262212int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272213 return maximum_zoom_percent_;
2214}
2215
[email protected]b172aee2012-04-10 17:05:262216gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492217 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232218}
2219
[email protected]b172aee2012-04-10 17:05:262220bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052221 if (GetBrowserPluginGuest())
2222 return GetBrowserPluginGuest()->LockMouse(allowed);
2223
[email protected]0bfbf882011-12-22 18:19:272224 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582225 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272226}
2227
[email protected]b172aee2012-04-10 17:05:262228bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442229 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502230}
2231
[email protected]cb805452013-05-22 15:16:212232void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482233 if (!color_chooser_info_.get())
2234 return;
2235 RenderFrameHost* rfh = RenderFrameHost::FromID(
2236 color_chooser_info_->render_process_id,
2237 color_chooser_info_->render_frame_id);
2238 if (!rfh)
2239 return;
2240
2241 rfh->Send(new FrameMsg_DidChooseColorResponse(
2242 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202243}
2244
[email protected]cb805452013-05-22 15:16:212245void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482246 if (!color_chooser_info_.get())
2247 return;
2248 RenderFrameHost* rfh = RenderFrameHost::FromID(
2249 color_chooser_info_->render_process_id,
2250 color_chooser_info_->render_frame_id);
2251 if (!rfh)
2252 return;
2253
2254 rfh->Send(new FrameMsg_DidEndColorChooser(
2255 rfh->GetRoutingID(), color_chooser_info_->identifier));
2256 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202257}
2258
[email protected]41225fe2013-03-29 05:32:022259int WebContentsImpl::DownloadImage(const GURL& url,
2260 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302261 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022262 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582263 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022264 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392265 return id;
2266}
2267
[email protected]5dcaf8e2013-12-28 01:31:422268bool WebContentsImpl::IsSubframe() const {
2269 return is_subframe_;
2270}
2271
[email protected]9649d492014-01-10 07:15:522272void WebContentsImpl::SetZoomLevel(double level) {
2273 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2274 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2275 if (embedder)
2276 embedder->SetZoomLevel(level);
2277}
2278
[email protected]36ec24f2014-01-09 00:32:082279void WebContentsImpl::Find(int request_id,
2280 const base::string16& search_text,
2281 const blink::WebFindOptions& options) {
2282 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2283}
2284
2285void WebContentsImpl::StopFinding(StopFindAction action) {
2286 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2287}
2288
[email protected]4fe53add2014-04-08 19:53:362289void WebContentsImpl::InsertCSS(const std::string& css) {
2290 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2291 GetMainFrame()->GetRoutingID(), css));
2292}
2293
[email protected]b172aee2012-04-10 17:05:262294bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272295 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202296 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332297 return true;
2298 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272299}
2300
[email protected]b172aee2012-04-10 17:05:262301void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272302 if (delegate_)
2303 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212304}
2305
[email protected]52913802013-12-10 05:52:182306void WebContentsImpl::DidStartProvisionalLoad(
2307 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072308 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182309 const GURL& validated_url,
2310 bool is_error_page,
2311 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262312 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182313 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572314 DidChangeLoadProgress(0);
2315
[email protected]0d60f0192011-04-14 12:40:102316 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272317 int render_frame_id = render_frame_host->GetRoutingID();
2318 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252319 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072320 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272321 render_frame_id, parent_routing_id, is_main_frame,
2322 validated_url, is_error_page, is_iframe_srcdoc,
2323 render_view_host));
[email protected]400992b2012-06-14 00:03:542324
2325 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182326 FOR_EACH_OBSERVER(
2327 WebContentsObserver,
2328 observers_,
2329 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582330 render_frame_host));
[email protected]400992b2012-06-14 00:03:542331 }
2332}
2333
[email protected]3109fbb72014-01-06 23:57:152334void WebContentsImpl::DidFailProvisionalLoadWithError(
2335 RenderFrameHostImpl* render_frame_host,
2336 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2337 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272338 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262339 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272340 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152341 FOR_EACH_OBSERVER(
2342 WebContentsObserver,
2343 observers_,
[email protected]161eabd2014-03-19 19:47:272344 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152345 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262346 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152347 validated_url,
2348 params.error_code,
2349 params.error_description,
[email protected]161eabd2014-03-19 19:47:272350 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152351}
2352
[email protected]b80624c2014-02-09 02:46:552353void WebContentsImpl::DidFailLoadWithError(
2354 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552355 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552356 int error_code,
2357 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272358 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262359 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272360 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552361 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272362 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262363 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552364}
2365
[email protected]52913802013-12-10 05:52:182366void WebContentsImpl::NotifyChangedNavigationState(
2367 InvalidateTypes changed_flags) {
2368 NotifyNavigationStateChanged(changed_flags);
2369}
2370
[email protected]3691e5cf2014-01-22 10:16:202371void WebContentsImpl::AboutToNavigateRenderFrame(
2372 RenderFrameHostImpl* render_frame_host) {
2373 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272374 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202375 FOR_EACH_OBSERVER(
2376 WebContentsObserver,
2377 observers_,
[email protected]161eabd2014-03-19 19:47:272378 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202379}
2380
2381void WebContentsImpl::DidStartNavigationToPendingEntry(
2382 RenderFrameHostImpl* render_frame_host,
2383 const GURL& url,
2384 NavigationController::ReloadType reload_type) {
2385 // Notify observers about navigation.
2386 FOR_EACH_OBSERVER(
2387 WebContentsObserver,
2388 observers_,
2389 DidStartNavigationToPendingEntry(url, reload_type));
2390}
2391
[email protected]8cb834e2014-03-06 14:23:232392void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2393 const OpenURLParams& params) {
2394 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182395 WebContents* new_contents = OpenURL(params);
2396
2397 if (new_contents) {
2398 // Notify observers.
2399 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2400 DidOpenRequestedURL(new_contents,
2401 params.url,
2402 params.referrer,
2403 params.disposition,
2404 params.transition,
[email protected]8cb834e2014-03-06 14:23:232405 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182406 }
2407}
2408
[email protected]aa62afd2014-04-22 19:22:462409bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2410 if (!delegate_)
2411 return false;
2412 return delegate_->ShouldPreserveAbortedURLs(this);
2413}
2414
[email protected]400992b2012-06-14 00:03:542415void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582416 RenderFrameHostImpl* render_frame_host,
2417 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542418 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582419 FOR_EACH_OBSERVER(
2420 WebContentsObserver,
2421 observers_,
2422 ProvisionalChangeToMainFrameUrl(validated_target_url,
2423 render_frame_host));
[email protected]724159a2010-12-30 01:11:182424}
2425
[email protected]37567b432014-02-12 01:12:222426void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432427 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222428 const base::string16& frame_unique_name,
2429 bool is_main_frame,
2430 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432431 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432432 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272433 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222434 // Notify observers about the commit of the provisional load.
2435 FOR_EACH_OBSERVER(
2436 WebContentsObserver,
2437 observers_,
[email protected]27dd82fd2014-03-03 22:11:432438 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222439 frame_unique_name,
2440 is_main_frame,
2441 url,
2442 transition_type,
2443 render_view_host));
2444}
2445
[email protected]0d0f4c492014-04-02 06:42:572446void WebContentsImpl::DidNavigateMainFramePreCommit(
2447 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2448 // Ensure fullscreen mode is exited before committing the navigation to a
2449 // different page. The next page will not start out assuming it is in
2450 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192451 if (controller_.IsURLInPageNavigation(params.url,
2452 params.was_within_same_page,
2453 NAVIGATION_TYPE_UNKNOWN)) {
2454 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572455 return;
2456 }
2457 if (IsFullscreenForCurrentTab())
2458 GetRenderViewHost()->ExitFullscreen();
2459 DCHECK(!IsFullscreenForCurrentTab());
2460}
2461
[email protected]37567b432014-02-12 01:12:222462void WebContentsImpl::DidNavigateMainFramePostCommit(
2463 const LoadCommittedDetails& details,
2464 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2465 if (details.is_navigation_to_different_page()) {
2466 // Clear the status bubble. This is a workaround for a bug where WebKit
2467 // doesn't let us know that the cursor left an element during a
2468 // transition (this is also why the mouse cursor remains as a hand after
2469 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2470 // clear the bubble when a user navigates to a named anchor in the same
2471 // page.
2472 UpdateTargetURL(details.entry->GetPageID(), GURL());
2473 }
2474
2475 if (!details.is_in_page) {
2476 // Once the main frame is navigated, we're no longer considered to have
2477 // displayed insecure content.
2478 displayed_insecure_content_ = false;
2479 SSLManager::NotifySSLInternalStateChanged(
2480 GetController().GetBrowserContext());
2481 }
2482
2483 // Notify observers about navigation.
2484 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2485 DidNavigateMainFrame(details, params));
2486
2487 if (delegate_) {
2488 delegate_->DidNavigateMainFramePostCommit(this);
2489 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2490 }
2491}
2492
2493void WebContentsImpl::DidNavigateAnyFramePostCommit(
2494 RenderFrameHostImpl* render_frame_host,
2495 const LoadCommittedDetails& details,
2496 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102497 // Now that something has committed, we don't need to track whether the
2498 // initial page has been accessed.
2499 has_accessed_initial_document_ = false;
2500
[email protected]37567b432014-02-12 01:12:222501 // If we navigate off the page, close all JavaScript dialogs.
2502 if (dialog_manager_ && !details.is_in_page)
2503 dialog_manager_->CancelActiveAndPendingDialogs(this);
2504
2505 // Notify observers about navigation.
2506 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2507 DidNavigateAnyFrame(details, params));
2508}
2509
2510void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2511 contents_mime_type_ = mime_type;
2512}
2513
2514bool WebContentsImpl::CanOverscrollContent() {
2515 if (delegate_)
2516 return delegate_->CanOverscrollContent();
2517
2518 return false;
2519}
2520
[email protected]b172aee2012-04-10 17:05:262521void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182522 const GURL& url,
[email protected]70435962011-08-02 20:13:282523 const std::string& security_info,
2524 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182525 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282526 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192527 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182528 cache.Increment();
2529
2530 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082531 int cert_id = 0;
2532 net::CertStatus cert_status = 0;
2533 int security_bits = -1;
2534 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122535 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212536 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122537 &security_bits, &connection_status,
2538 &signed_certificate_timestamp_ids);
2539 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212540 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002541 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2542 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182543
[email protected]b0f724c2013-09-05 04:21:132544 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2545
2546 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2547 DidLoadResourceFromMemoryCache(details));
2548
[email protected]8bfc8272013-09-09 20:10:532549 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2550 scoped_refptr<net::URLRequestContextGetter> request_context(
2551 resource_type == ResourceType::MEDIA ?
2552 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2553 GetRenderProcessHost()->GetID()) :
2554 GetBrowserContext()->GetRequestContextForRenderProcess(
2555 GetRenderProcessHost()->GetID()));
2556 BrowserThread::PostTask(
2557 BrowserThread::IO,
2558 FROM_HERE,
2559 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2560 }
[email protected]724159a2010-12-30 01:11:182561}
2562
[email protected]b172aee2012-04-10 17:05:262563void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392564 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182565 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192566 SSLManager::NotifySSLInternalStateChanged(
2567 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182568}
2569
[email protected]b172aee2012-04-10 17:05:262570void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022571 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582572 LOG(WARNING) << security_origin << " ran insecure content from "
2573 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392574 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412575 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392576 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182577 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412578 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192579 SSLManager::NotifySSLInternalStateChanged(
2580 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182581}
2582
[email protected]501052ff2014-02-21 22:19:072583void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572584 CHECK(render_frame_message_source_);
2585 CHECK(!render_view_message_source_);
2586 RenderFrameHostImpl* rfh =
2587 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2588
[email protected]161eabd2014-03-19 19:47:272589 int render_frame_id = rfh->GetRoutingID();
2590 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572591 FOR_EACH_OBSERVER(WebContentsObserver,
2592 observers_,
[email protected]161eabd2014-03-19 19:47:272593 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182594}
2595
[email protected]b172aee2012-04-10 17:05:262596void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262597 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372598 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122599 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2600 GetRenderProcessHost()->ReceivedBadMessage();
2601 return;
2602 }
[email protected]a1b99262013-12-27 21:56:222603
[email protected]8b3af1e2014-01-24 13:29:122604 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442605 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372606 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422607 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372608
[email protected]61ac9e242014-03-21 20:55:262609 RenderFrameHostImpl* rfh =
2610 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272611 int render_frame_id = rfh->GetRoutingID();
2612 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262613 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252614 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272615 DidFinishLoad(render_frame_id, validated_url,
2616 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312617}
2618
[email protected]b172aee2012-04-10 17:05:262619void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222620 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2621 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262622}
2623
[email protected]b172aee2012-04-10 17:05:262624void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2625 int maximum_percent,
2626 bool remember) {
[email protected]216813952011-05-19 22:21:262627 minimum_zoom_percent_ = minimum_percent;
2628 maximum_zoom_percent_ = maximum_percent;
2629 temporary_zoom_settings_ = !remember;
2630}
2631
[email protected]b172aee2012-04-10 17:05:262632void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342633 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432634 if (!delegate_)
2635 return;
2636
[email protected]b9535422012-02-09 01:47:592637 ChildProcessSecurityPolicyImpl* policy =
2638 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222639 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592640 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212641}
2642
[email protected]b172aee2012-04-10 17:05:262643void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2644 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262645 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362646 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432647 if (!delegate_)
2648 return;
2649
[email protected]b9535422012-02-09 01:47:592650 ChildProcessSecurityPolicyImpl* policy =
2651 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322652 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592653 return;
[email protected]8f810632013-06-06 22:33:322654
[email protected]c125e532014-05-10 20:39:062655 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202656}
2657
[email protected]b172aee2012-04-10 17:05:262658void WebContentsImpl::OnFindReply(int request_id,
2659 int number_of_matches,
2660 const gfx::Rect& selection_rect,
2661 int active_match_ordinal,
2662 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432663 if (delegate_) {
2664 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2665 active_match_ordinal, final_update);
2666 }
[email protected]b888919c2011-09-02 00:32:162667}
2668
[email protected]59363fc92012-09-05 03:46:312669#if defined(OS_ANDROID)
2670void WebContentsImpl::OnFindMatchRectsReply(
2671 int version,
2672 const std::vector<gfx::RectF>& rects,
2673 const gfx::RectF& active_rect) {
2674 if (delegate_)
2675 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2676}
[email protected]583418cc2013-01-17 14:01:102677
[email protected]1ff427972013-02-07 21:14:072678void WebContentsImpl::OnOpenDateTimeDialog(
2679 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092680 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2681 GetRenderViewHost(),
2682 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132683 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092684 value.minimum,
2685 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172686 value.step,
2687 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102688}
2689
[email protected]59363fc92012-09-05 03:46:312690#endif
2691
[email protected]f114fa42013-12-06 17:06:442692void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2693 const base::FilePath& path,
2694 bool is_hung) {
2695 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2696
2697 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2698 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2699}
2700
2701void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422702 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442703 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422704 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452705}
2706
[email protected]cfa856d62014-02-22 07:58:402707void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2708 int automation_id) {
2709 DomOperationNotificationDetails details(json_string, automation_id);
2710 NotificationService::current()->Notify(
2711 NOTIFICATION_DOM_OPERATION_RESPONSE,
2712 Source<WebContents>(this),
2713 Details<DomOperationNotificationDetails>(&details));
2714}
2715
[email protected]b172aee2012-04-10 17:05:262716void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2717 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102718 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252719 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102720 AppCacheAccessed(manifest_url, blocked_by_policy));
2721}
2722
[email protected]8bc5ff02013-11-29 06:34:032723void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482724 int color_chooser_id,
2725 SkColor color,
2726 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462727 ColorChooser* new_color_chooser = delegate_ ?
2728 delegate_->OpenColorChooser(this, color, suggestions) :
2729 NULL;
[email protected]820957a2014-01-14 14:56:302730 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212731 return;
[email protected]8ed16472014-04-11 19:02:482732 if (color_chooser_info_.get())
2733 color_chooser_info_->chooser->End();
2734
2735 color_chooser_info_.reset(new ColorChooserInfo(
2736 render_frame_message_source_->GetProcess()->GetID(),
2737 render_frame_message_source_->GetRoutingID(),
2738 new_color_chooser,
2739 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202740}
2741
[email protected]b172aee2012-04-10 17:05:262742void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482743 if (color_chooser_info_ &&
2744 color_chooser_id == color_chooser_info_->identifier)
2745 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202746}
2747
[email protected]b172aee2012-04-10 17:05:262748void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322749 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482750 if (color_chooser_info_ &&
2751 color_chooser_id == color_chooser_info_->identifier)
2752 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202753}
2754
[email protected]d0759f492012-04-19 22:50:502755// This exists for render views that don't have a WebUI, but do have WebUI
2756// bindings enabled.
2757void WebContentsImpl::OnWebUISend(const GURL& source_url,
2758 const std::string& name,
2759 const base::ListValue& args) {
2760 if (delegate_)
2761 delegate_->WebUISend(this, source_url, name, args);
2762}
2763
[email protected]d8415ad92012-08-23 14:40:502764void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442765 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502766 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342767 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162768 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442769 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162770 return;
[email protected]d8415ad92012-08-23 14:40:502771 }
2772
[email protected]8c8fc292012-11-23 18:57:162773 if (!delegate_->RequestPpapiBrokerPermission(
2774 this, url, plugin_path,
2775 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442776 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162777 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442778 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162779 }
[email protected]d8415ad92012-08-23 14:40:502780}
2781
[email protected]ea0309c2013-08-06 19:35:442782void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502783 bool result) {
[email protected]ea0309c2013-08-06 19:35:442784 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502785}
2786
[email protected]c4538072013-03-18 02:17:552787void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372788 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082789 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552790 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392791 // For more info, see comment above classes BrowserPluginEmbedder and
2792 // BrowserPluginGuest.
2793 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142794 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082795 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372796}
2797
[email protected]41225fe2013-03-29 05:32:022798void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392799 int id,
[email protected]749fadd2013-05-15 08:37:482800 int http_status_code,
[email protected]795c28972012-12-06 06:13:392801 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302802 const std::vector<SkBitmap>& bitmaps,
2803 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132804 if (bitmaps.size() != original_bitmap_sizes.size())
2805 return;
2806
[email protected]41225fe2013-03-29 05:32:022807 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2808 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392809 // Currently WebContents notifies us of ANY downloads so that it is
2810 // possible to get here.
2811 return;
2812 }
2813 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302814 iter->second.Run(
2815 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392816 }
[email protected]41225fe2013-03-29 05:32:022817 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392818}
2819
2820void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392821 const std::vector<FaviconURL>& candidates) {
2822 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292823 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392824}
2825
[email protected]1dd0bb752014-02-01 01:16:262826void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2827 bool has_video,
2828 bool has_audio) {
2829// Chrome OS does its own detection of audio and video.
2830#if !defined(OS_CHROMEOS)
2831 scoped_ptr<PowerSaveBlocker> blocker;
2832 if (has_video) {
2833 blocker = PowerSaveBlocker::Create(
2834 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2835#if defined(OS_ANDROID)
2836 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2837 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2838#endif
2839 } else if (has_audio) {
2840 blocker = PowerSaveBlocker::Create(
2841 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2842 }
2843
2844 if (blocker) {
[email protected]96307312014-05-04 01:00:192845 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262846 blocker.release();
2847 }
2848#endif // !defined(OS_CHROMEOS)
2849}
2850
2851void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062852 // Chrome OS does its own detection of audio and video.
2853#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192854 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2855 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062856#endif // !defined(OS_CHROMEOS)
2857}
2858
[email protected]50279492014-05-05 23:24:292859void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152860 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292861 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152862}
[email protected]d9030b82013-07-19 08:26:062863
[email protected]e67ebf32013-02-13 11:07:192864void WebContentsImpl::DidChangeVisibleSSLState() {
2865 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2866 DidChangeVisibleSSLState());
2867}
2868
[email protected]17e286e2013-03-01 23:29:392869void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2870 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2871 BeforeFormRepostWarningShow());
2872}
2873
[email protected]ec6c05f2013-10-23 18:41:572874
2875void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2876 Activate();
2877 if (delegate_)
2878 delegate_->ShowRepostFormWarningDialog(this);
2879}
2880
[email protected]b4c84012014-04-28 19:51:102881bool WebContentsImpl::HasAccessedInitialDocument() {
2882 return has_accessed_initial_document_;
2883}
2884
[email protected]96d185d2009-04-24 03:28:542885// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592886// loading, or done loading.
2887void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2888 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092889 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262890 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542891 if (is_loading == is_loading_)
2892 return;
2893
2894 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262895 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2896 base::string16());
[email protected]96d185d2009-04-24 03:28:542897 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562898 upload_size_ = 0;
2899 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542900 }
2901
[email protected]fa944cb82013-11-15 17:51:212902 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542903
2904 is_loading_ = is_loading;
2905 waiting_for_response_ = is_loading;
2906
[email protected]6ebdc9b2010-09-27 16:55:572907 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092908 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212909 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542910
[email protected]eab61442013-11-14 18:35:482911 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592912 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482913 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2914 "URL", url);
[email protected]91621872013-10-08 04:04:592915 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2916 DidStartLoading(render_view_host));
2917 } else {
[email protected]eab61442013-11-14 18:35:482918 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2919 "URL", url);
[email protected]91621872013-10-08 04:04:592920 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2921 DidStopLoading(render_view_host));
2922 }
[email protected]66798902013-10-01 18:40:162923
2924 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212925 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2926 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542927 if (details)
[email protected]8ff00d72012-10-23 19:12:212928 det = Details<LoadNotificationDetails>(details);
2929 NotificationService::current()->Notify(
2930 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542931}
2932
[email protected]959be4c2014-04-08 15:01:332933void WebContentsImpl::SelectRange(const gfx::Point& start,
2934 const gfx::Point& end) {
2935 RenderFrameHost* focused_frame = GetFocusedFrame();
2936 if (!focused_frame)
2937 return;
2938
2939 focused_frame->Send(
2940 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
2941}
2942
[email protected]b172aee2012-04-10 17:05:262943void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462944 // If we are creating a RVH for a restored controller, then we need to make
2945 // sure the RenderView starts with a next_page_id_ larger than the number
2946 // of restored entries. This must be called before the RenderView starts
2947 // navigating (to avoid a race between the browser updating max_page_id and
2948 // the renderer updating next_page_id_). Because of this, we only call this
2949 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562950 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582951 if (max_restored_page_id >
2952 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2953 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2954 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322955}
2956
[email protected]b172aee2012-04-10 17:05:262957bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262958 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322959 // For file URLs without a title, use the pathname instead. In the case of a
2960 // synthesized title, we don't want the update to count toward the "one set
2961 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262962 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322963 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512964 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242965 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322966 explicit_set = false; // Don't count synthetic titles toward the set limit.
2967 } else {
[email protected]8af69c6c2014-03-03 19:05:312968 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322969 explicit_set = true;
2970 }
2971
[email protected]987fc3a2011-05-26 14:18:092972 // If a page is created via window.open and never navigated,
2973 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552974 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092975 if (entry) {
[email protected]36fc0392011-12-25 03:59:512976 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092977 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322978
[email protected]36fc0392011-12-25 03:59:512979 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092980 } else {
2981 if (page_title_when_no_navigation_entry_ == final_title)
2982 return false; // Nothing changed, don't bother.
2983
2984 page_title_when_no_navigation_entry_ = final_title;
2985 }
[email protected]420ae012009-04-24 05:16:322986
[email protected]420ae012009-04-24 05:16:322987 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232988 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322989
[email protected]66798902013-10-01 18:40:162990 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532991 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162992
2993 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212994 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462995 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212996 NotificationService::current()->Notify(
2997 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2998 Source<WebContents>(this),
2999 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043000
[email protected]420ae012009-04-24 05:16:323001 return true;
3002}
3003
[email protected]7b712ee22013-10-03 00:57:283004void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
3005 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323006 // After sending out a swap notification, we need to send a disconnect
3007 // notification so that clients that pick up a pointer to |this| can NULL the
3008 // pointer. See Bug 1230284.
3009 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113010 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283011 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113012
3013 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283014 std::pair<RenderViewHost*, RenderViewHost*> details =
3015 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213016 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283017 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213018 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283019 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393020
3021 // Ensure that the associated embedder gets cleared after a RenderViewHost
3022 // gets swapped, so we don't reuse the same embedder next time a
3023 // RenderViewHost is attached to this WebContents.
3024 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323025}
3026
[email protected]da7a7182013-09-06 08:11:113027// TODO(avi): Remove this entire function because this notification is already
3028// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263029void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323030 if (!notify_disconnection_)
3031 return;
3032
3033 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213034 NotificationService::current()->Notify(
3035 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3036 Source<WebContents>(this),
3037 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323038}
3039
[email protected]cbb1ef592013-06-05 19:49:463040void WebContentsImpl::NotifyNavigationEntryCommitted(
3041 const LoadCommittedDetails& load_details) {
3042 FOR_EACH_OBSERVER(
3043 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3044}
3045
[email protected]f114fa42013-12-06 17:06:443046bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3047 const IPC::Message& message) {
3048 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313049}
3050
[email protected]c31a84802014-04-03 15:55:493051const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3052 return GetLastCommittedURL();
3053}
3054
[email protected]b849847b2013-12-10 21:57:583055void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3056 // Note this is only for subframes, the notification for the main frame
3057 // happens in RenderViewCreated.
3058 FOR_EACH_OBSERVER(WebContentsObserver,
3059 observers_,
3060 RenderFrameCreated(render_frame_host));
3061}
3062
3063void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193064 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583065 FOR_EACH_OBSERVER(WebContentsObserver,
3066 observers_,
3067 RenderFrameDeleted(render_frame_host));
3068}
3069
[email protected]a09d53ce2014-01-31 00:46:423070void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303071 if (delegate_)
3072 delegate_->WorkerCrashed(this);
3073}
3074
[email protected]a09d53ce2014-01-31 00:46:423075void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3076 const ContextMenuParams& params) {
3077 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:403078 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:423079 return;
3080
3081 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
3082}
3083
[email protected]87de04b02014-04-08 22:14:493084void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013085 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493086 const base::string16& message,
3087 const base::string16& default_prompt,
3088 const GURL& frame_url,
3089 JavaScriptMessageType javascript_message_type,
3090 IPC::Message* reply_msg) {
3091 // Suppress JavaScript dialogs when requested. Also suppress messages when
3092 // showing an interstitial as it's shown over the previous page and we don't
3093 // want the hidden page's dialogs to interfere with the interstitial.
3094 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013095 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493096 IsSwappedOut() ||
3097 ShowingInterstitialPage() ||
3098 !delegate_ ||
3099 delegate_->ShouldSuppressDialogs() ||
3100 !delegate_->GetJavaScriptDialogManager();
3101
3102 if (!suppress_this_message) {
3103 std::string accept_lang = GetContentClient()->browser()->
3104 GetAcceptLangs(GetBrowserContext());
3105 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3106 dialog_manager_->RunJavaScriptDialog(
3107 this,
3108 frame_url.GetOrigin(),
3109 accept_lang,
3110 javascript_message_type,
3111 message,
3112 default_prompt,
3113 base::Bind(&WebContentsImpl::OnDialogClosed,
3114 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013115 render_frame_host->GetProcess()->GetID(),
3116 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493117 reply_msg,
3118 false),
3119 &suppress_this_message);
3120 }
3121
3122 if (suppress_this_message) {
3123 // If we are suppressing messages, just reply as if the user immediately
3124 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013125 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3126 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283127 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493128 }
3129
3130 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3131 // http://crbug.com/288961 ). The only safe thing to do here is return.
3132}
3133
3134void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013135 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493136 const base::string16& message,
3137 bool is_reload,
3138 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013139 RenderFrameHostImpl* rfhi =
3140 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493141 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013142 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493143 if (delegate_)
3144 delegate_->WillRunBeforeUnloadConfirm();
3145
3146 bool suppress_this_message =
3147 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3148 !delegate_ ||
3149 delegate_->ShouldSuppressDialogs() ||
3150 !delegate_->GetJavaScriptDialogManager();
3151 if (suppress_this_message) {
3152 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3153 return;
3154 }
3155
3156 is_showing_before_unload_dialog_ = true;
3157 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3158 dialog_manager_->RunBeforeUnloadDialog(
3159 this, message, is_reload,
3160 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013161 render_frame_host->GetProcess()->GetID(),
3162 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283163 false));
[email protected]87de04b02014-04-08 22:14:493164}
3165
[email protected]a86c0e962013-12-17 17:10:393166WebContents* WebContentsImpl::GetAsWebContents() {
3167 return this;
3168}
3169
[email protected]7912e822014-04-16 02:37:033170bool WebContentsImpl::IsNeverVisible() {
3171 if (!delegate_)
3172 return false;
3173 return delegate_->IsNeverVisible(this);
3174}
3175
[email protected]5a3bdf52012-05-24 15:12:573176RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3177 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323178}
3179
[email protected]8ff00d72012-10-23 19:12:213180RendererPreferences WebContentsImpl::GetRendererPrefs(
3181 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463182 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513183}
3184
[email protected]b172aee2012-04-10 17:05:263185gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173186 if (delegate_)
3187 return delegate_->GetRootWindowResizerRect();
3188 return gfx::Rect();
3189}
3190
[email protected]7a846df2012-09-20 19:17:393191void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273192 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393193 browser_plugin_embedder_.reset();
3194}
3195
[email protected]b172aee2012-04-10 17:05:263196void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443197 // Don't send notifications if we are just creating a swapped-out RVH for
3198 // the opener chain. These won't be used for view-source or WebUI, so it's
3199 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243200 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443201 return;
3202
[email protected]86f98a22013-03-20 14:35:003203 if (delegate_)
3204 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083205
[email protected]8ff00d72012-10-23 19:12:213206 NotificationService::current()->Notify(
3207 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3208 Source<WebContents>(this),
3209 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323210
3211 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353212 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213213 if (GetRenderManager()->pending_web_ui())
3214 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323215
[email protected]6286a372013-10-09 04:03:273216 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333217 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323218 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183219 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583220 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323221 }
[email protected]0666aef2009-05-13 19:48:083222
[email protected]60780f412013-02-25 16:34:103223 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263224
3225 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253226 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583227
3228 // We tell the observers now instead of when the main RenderFrameHostImpl is
3229 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3230 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363231 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583232 FOR_EACH_OBSERVER(
3233 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323234}
3235
[email protected]b172aee2012-04-10 17:05:263236void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523237 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323238 // Don't notify the world, since this came from a renderer in the
3239 // background.
3240 return;
3241 }
3242
[email protected]da7a7182013-09-06 08:11:113243 notify_disconnection_ = true;
3244 // TODO(avi): Remove. http://crbug.com/170921
3245 NotificationService::current()->Notify(
3246 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3247 Source<WebContents>(this),
3248 NotificationService::NoDetails());
3249
[email protected]be1f56ab2011-12-22 06:55:313250 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233251 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303252
3253 // Restore the focus to the tab (otherwise the focus will be on the top
3254 // window).
[email protected]484ae5912010-09-29 19:16:143255 if (was_crashed && !FocusLocationBarByDefault() &&
3256 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063257 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143258 }
[email protected]32ded2212011-11-10 18:51:433259
[email protected]d8c660432011-12-22 20:51:253260 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323261}
3262
[email protected]ec6a7eb2013-04-22 17:34:223263void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3264 base::TerminationStatus status,
3265 int error_code) {
[email protected]151a63d2011-12-20 22:32:523266 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323267 // The pending page's RenderViewHost is gone.
3268 return;
3269 }
3270
[email protected]2fcdcc32014-03-05 02:14:073271 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3272 // renderer may not have made a clean exit.
3273 if (IsFullscreenForCurrentTab())
3274 ToggleFullscreenMode(false);
3275
[email protected]698191dc2014-02-25 01:06:133276 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3277 if (dialog_manager_)
3278 dialog_manager_->CancelActiveAndPendingDialogs(this);
3279
[email protected]e3b10d12014-03-28 16:06:093280 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323281 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233282 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453283
3284#if defined(OS_ANDROID)
3285 if (GetRenderViewHostImpl()->media_player_manager())
3286 GetRenderViewHostImpl()->media_player_manager()->DestroyAllMediaPlayers();
3287#endif
[email protected]420ae012009-04-24 05:16:323288
[email protected]d8c660432011-12-22 20:51:253289 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273290 observers_,
[email protected]58d5cfe2013-07-10 02:40:523291 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323292}
3293
[email protected]b172aee2012-04-10 17:05:263294void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253295 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063296}
3297
[email protected]b172aee2012-04-10 17:05:263298void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3299 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043300 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153301 // Ensure that this state update comes from either the active RVH or one of
3302 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413303 // TODO(nasko): This should go through RenderFrameHost.
3304 // TODO(creis): We can't update state for cross-process subframes until we
3305 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3306 if (rvh != GetRenderViewHost() &&
3307 !GetRenderManager()->IsRVHOnSwappedOutList(
3308 static_cast<RenderViewHostImpl*>(rvh)))
3309 return;
[email protected]420ae012009-04-24 05:16:323310
3311 // We must be prepared to handle state updates for any page, these occur
3312 // when the user is scrolling and entering form data, as well as when we're
3313 // leaving a page, in which case our state may have already been moved to
3314 // the next page. The navigation controller will look up the appropriate
3315 // NavigationEntry and update it when it is notified via the delegate.
3316
3317 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583318 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323319 if (entry_index < 0)
3320 return;
[email protected]10f417c52011-12-28 21:04:233321 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323322
[email protected]691aa2f2013-05-28 22:52:043323 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323324 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043325 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323326 controller_.NotifyEntryChanged(entry, entry_index);
3327}
3328
[email protected]b172aee2012-04-10 17:05:263329void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513330 if (delegate_)
3331 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323332}
3333
[email protected]b172aee2012-04-10 17:05:263334void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103335#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293336 // The UI may be in an event-tracking loop, such as between the
3337 // mouse-down and mouse-up in text selection or a button click.
3338 // Defer the close until after tracking is complete, so that we
3339 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293340 // TODO(shess): This could get more fine-grained. For instance,
3341 // closing a tab in another window while selecting text in the
3342 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103343 if (view_->IsEventTracking()) {
3344 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293345 return;
3346 }
[email protected]60780f412013-02-25 16:34:103347#endif
[email protected]07707302009-11-06 00:50:293348
[email protected]420ae012009-04-24 05:16:323349 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523350 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513351 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323352}
3353
[email protected]66bbadaf2014-03-28 16:25:543354void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573355 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3356 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573357}
3358
[email protected]b172aee2012-04-10 17:05:263359void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513360 if (delegate_ && delegate_->IsPopupOrPanel(this))
3361 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323362}
3363
[email protected]e3b10d12014-03-28 16:06:093364void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3365 bool to_different_document) {
3366 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3367 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323368}
3369
[email protected]723971b2014-02-12 11:08:253370void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323371 scoped_ptr<LoadNotificationDetails> details;
3372
[email protected]9595fd82013-04-19 21:28:493373 // Use the last committed entry rather than the active one, in case a
3374 // pending entry has been created.
3375 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203376 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493377
[email protected]420ae012009-04-24 05:16:323378 // An entry may not exist for a stop when loading an initial blank page or
3379 // if an iframe injected by script into a blank page finishes loading.
3380 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203381 base::TimeDelta elapsed =
3382 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323383
3384 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513385 entry->GetVirtualURL(),
3386 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323387 elapsed,
3388 &controller_,
3389 controller_.GetCurrentEntryIndex()));
3390 }
3391
[email protected]e3b10d12014-03-28 16:06:093392 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3393 details.get());
[email protected]420ae012009-04-24 05:16:323394}
3395
[email protected]b172aee2012-04-10 17:05:263396void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163397 controller_.DiscardNonCommittedEntries();
3398
3399 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213400 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163401}
3402
[email protected]b172aee2012-04-10 17:05:263403void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513404 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133405 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403406}
3407
[email protected]59167c22013-06-03 18:07:323408void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103409 has_accessed_initial_document_ = true;
3410
[email protected]d1371bf8e2014-04-19 03:26:243411 // We may have left a failed browser-initiated navigation in the address bar
3412 // to let the user edit it and try again. Clear it now that content might
3413 // show up underneath it.
3414 if (!IsLoading() && controller_.GetPendingEntry())
3415 controller_.DiscardPendingEntry();
3416
[email protected]59167c22013-06-03 18:07:323417 // Update the URL display.
3418 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3419}
3420
[email protected]3f19f1a2014-05-02 05:23:273421void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3422 if (opener_) {
3423 // Clear our opener so that future cross-process navigations don't have an
3424 // opener assigned.
3425 RemoveDestructionObserver(opener_);
3426 opener_ = NULL;
3427 }
3428
3429 // Notify all swapped out RenderViewHosts for this tab. This is important
3430 // in case we go back to them, or if another window in those processes tries
3431 // to access window.opener.
3432 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3433}
3434
[email protected]39f2f9252014-05-03 00:54:013435void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293436 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093437 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293438 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093439
3440 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213441 NotificationService::current()->Notify(
3442 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3443 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293444 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083445}
3446
[email protected]ef3adfc2014-05-11 00:04:543447void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3448 int32 page_id,
3449 const base::string16& title,
3450 base::i18n::TextDirection title_direction) {
3451 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3452
3453 // If we have a title, that's a pretty good indication that we've started
3454 // getting useful data.
3455 SetNotWaitingForResponse();
3456
3457 // Try to find the navigation entry, which might not be the current one.
3458 // For example, it might be from a pending RVH for the pending entry.
3459 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3460 rvh->GetSiteInstance(), page_id);
3461
3462 // We can handle title updates when we don't have an entry in
3463 // UpdateTitleForEntry, but only if the update is from the current RVH.
3464 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3465 if (!entry && rvh != GetRenderViewHost())
3466 return;
3467
3468 // TODO(evan): make use of title_direction.
3469 // http://code.google.com/p/chromium/issues/detail?id=27094
3470 if (!UpdateTitleForEntry(entry, title))
3471 return;
3472
3473 // Broadcast notifications when the UI should be updated.
3474 if (entry == controller_.GetEntryAtOffset(0))
3475 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3476}
3477
3478void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3479 const std::string& encoding) {
3480 SetEncoding(encoding);
3481}
3482
[email protected]39f2f9252014-05-03 00:54:013483void WebContentsImpl::DocumentAvailableInMainFrame(
3484 RenderViewHost* render_view_host) {
3485 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3486 DocumentAvailableInMainFrame());
3487}
[email protected]e1c3a552012-05-04 20:51:323488void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3489 // Tell the active RenderViewHost to run unload handlers and close, as long
3490 // as the request came from a RenderViewHost in the same BrowsingInstance.
3491 // In most cases, we receive this from a swapped out RenderViewHost.
3492 // It is possible to receive it from one that has just been swapped in,
3493 // in which case we might as well deliver the message anyway.
3494 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3495 GetRenderViewHost()->ClosePage();
3496}
3497
[email protected]f546640b2012-05-15 00:03:493498void WebContentsImpl::RouteMessageEvent(
3499 RenderViewHost* rvh,
3500 const ViewMsg_PostMessage_Params& params) {
3501 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363502 // came from a RenderViewHost in the same BrowsingInstance or if this
3503 // WebContents is dedicated to a browser plugin guest.
3504 // Note: This check means that an embedder could theoretically receive a
3505 // postMessage from anyone (not just its own guests). However, this is
3506 // probably not a risk for apps since other pages won't have references
3507 // to App windows.
3508 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3509 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493510 return;
3511
3512 ViewMsg_PostMessage_Params new_params(params);
3513
[email protected]0bc7f3542013-10-21 15:05:533514 if (!params.message_port_ids.empty()) {
3515 MessagePortMessageFilter* message_port_message_filter =
3516 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3517 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093518 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3519 params.message_port_ids,
3520 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533521 }
3522
[email protected]f546640b2012-05-15 00:03:493523 // If there is a source_routing_id, translate it to the routing ID for
3524 // the equivalent swapped out RVH in the target process. If we need
3525 // to create a swapped out RVH for the source tab, we create its opener
3526 // chain as well, since those will also be accessible to the target page.
3527 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3528 // Try to look up the WebContents for the source page.
3529 WebContentsImpl* source_contents = NULL;
3530 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3531 rvh->GetProcess()->GetID(), params.source_routing_id);
3532 if (source_rvh) {
3533 source_contents = static_cast<WebContentsImpl*>(
3534 source_rvh->GetDelegate()->GetAsWebContents());
3535 }
3536
3537 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363538 if (GetBrowserPluginGuest()) {
3539 // We create a swapped out RenderView for the embedder in the guest's
3540 // render process but we intentionally do not expose the embedder's
3541 // opener chain to it.
3542 new_params.source_routing_id =
3543 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3544 } else {
3545 new_params.source_routing_id =
3546 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3547 }
[email protected]f546640b2012-05-15 00:03:493548 } else {
3549 // We couldn't find it, so don't pass a source frame.
3550 new_params.source_routing_id = MSG_ROUTING_NONE;
3551 }
3552 }
3553
3554 // In most cases, we receive this from a swapped out RenderViewHost.
3555 // It is possible to receive it from one that has just been swapped in,
3556 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183557 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493558}
3559
[email protected]a796f202012-05-30 14:14:253560bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263561 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253562 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263563 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253564 if (!delegate_)
3565 return false;
3566 return delegate_->AddMessageToConsole(this, level, message, line_no,
3567 source_id);
3568}
3569
[email protected]b172aee2012-04-10 17:05:263570WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273571 // We want to base the page config off of the actual URL, rather than the
3572 // virtual URL.
3573 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3574 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003575 GURL url = controller_.GetActiveEntry()
3576 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153577
[email protected]fa944cb82013-11-15 17:51:213578 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323579}
3580
[email protected]0eba810b2012-10-18 03:19:363581int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213582 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413583 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3584 true, true);
[email protected]0eba810b2012-10-18 03:19:363585}
3586
[email protected]b172aee2012-04-10 17:05:263587void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273588 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253589 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223590
[email protected]ea114722012-03-12 01:11:253591 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173592 if (rdh) // NULL in unittests.
3593 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253594}
3595
[email protected]b172aee2012-04-10 17:05:263596void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443597 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253598 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443599}
3600
[email protected]b172aee2012-04-10 17:05:263601void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563602 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263603 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153604 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523605 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153606 return;
3607
[email protected]9f76c1e2012-03-05 15:15:583608 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3609
[email protected]e5fc1632011-08-08 07:51:533610 // Ignore renderer unresponsive event if debugger is attached to the tab
3611 // since the event may be a result of the renderer sitting on a breakpoint.
3612 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363613 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533614 return;
3615
[email protected]2e9d79f2013-08-16 05:45:563616 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323617 // Hang occurred while firing the beforeunload/unload handler.
3618 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583619 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323620
[email protected]fa944cb82013-11-15 17:51:213621 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323622 return;
3623
3624 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563625 // nothing we can do to recover. If the hang is in the beforeunload handler,
3626 // pretend the beforeunload listeners have all fired and allow the delegate
3627 // to continue closing; the user will not have the option of cancelling the
3628 // close. Otherwise, pretend the unload listeners have all fired and close
3629 // the tab.
3630 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463631 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563632 delegate_->BeforeUnloadFired(this, true, &close);
3633 }
3634 if (close)
3635 Close(rvh);
[email protected]420ae012009-04-24 05:16:323636 return;
3637 }
3638
[email protected]9f76c1e2012-03-05 15:15:583639 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473640 return;
3641
[email protected]6934a702011-12-20 00:04:513642 if (delegate_)
3643 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323644}
3645
[email protected]b172aee2012-04-10 17:05:263646void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513647 if (delegate_)
3648 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323649}
3650
[email protected]b172aee2012-04-10 17:05:263651void WebContentsImpl::LoadStateChanged(
3652 const GURL& url,
3653 const net::LoadStateWithParam& load_state,
3654 uint64 upload_position,
3655 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323656 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563657 upload_position_ = upload_position;
3658 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503659 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213660 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303661 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213662 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323663 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463664 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213665 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463666 }
[email protected]420ae012009-04-24 05:16:323667}
3668
[email protected]b172aee2012-04-10 17:05:263669void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553670 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323671 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123672 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3673 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513674 if (delegate_)
3675 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093676 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323677}
3678
[email protected]58d5cfe2013-07-10 02:40:523679void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543680 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233681 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223682 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543683}
3684
[email protected]b172aee2012-04-10 17:05:263685void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103686 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213687 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263688 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3689 // here during container initialization and normal window size will be set
3690 // later. In case of tab duplication this resizing to 0x0 prevents setting
3691 // normal size later so just ignore it.
3692 if (!size.IsEmpty())
3693 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323694}
3695
[email protected]af905902013-10-01 21:38:513696void WebContentsImpl::CancelModalDialogsForRenderManager() {
3697 // We need to cancel modal dialogs when doing a process swap, since the load
3698 // deferrer would prevent us from swapping out.
3699 if (dialog_manager_)
3700 dialog_manager_->CancelActiveAndPendingDialogs(this);
3701}
3702
[email protected]7b712ee22013-10-03 00:57:283703void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3704 RenderViewHost* new_host) {
3705 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083706
3707 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003708 if (delegate_)
3709 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393710
[email protected]7b712ee22013-10-03 00:57:283711 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543712}
3713
[email protected]14392a52012-05-02 20:28:443714int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3715 SiteInstance* instance) {
3716 if (!opener_)
3717 return MSG_ROUTING_NONE;
3718
3719 // Recursively create RenderViews for anything else in the opener chain.
3720 return opener_->CreateOpenerRenderViews(instance);
3721}
3722
3723int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3724 int opener_route_id = MSG_ROUTING_NONE;
3725
3726 // If this tab has an opener, ensure it has a RenderView in the given
3727 // SiteInstance as well.
3728 if (opener_)
3729 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3730
[email protected]45a22ad2013-02-21 03:25:003731 // If any of the renderers (current, pending, or swapped out) for this
3732 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213733 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3734 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373735
[email protected]fa944cb82013-11-15 17:51:213736 if (GetRenderManager()->pending_render_view_host() &&
3737 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3738 instance)
3739 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003740
[email protected]fa944cb82013-11-15 17:51:213741 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373742 instance);
3743 if (rvh)
3744 return rvh->GetRoutingID();
3745
[email protected]14392a52012-05-02 20:28:443746 // Create a swapped out RenderView in the given SiteInstance if none exists,
3747 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413748 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3749 true, true);
[email protected]14392a52012-05-02 20:28:443750}
3751
[email protected]b172aee2012-04-10 17:05:263752NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193753 return GetController();
[email protected]3a3d47472010-07-15 21:03:543754}
3755
[email protected]b172aee2012-04-10 17:05:263756WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563757 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323758}
3759
[email protected]10f417c52011-12-28 21:04:233760NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263761 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323762 return controller_.GetLastCommittedEntry();
3763}
3764
[email protected]b172aee2012-04-10 17:05:263765bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163766 RenderViewHost* render_view_host,
3767 int opener_route_id,
3768 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033769 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443770 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483771 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163772 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3773 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3774 // case this because RWH is still a base class of RenderViewHost, and child
3775 // frame RWHVs are unique in that they do not have their own WebContents.
3776 if (frame_connector) {
3777 RenderWidgetHostViewChildFrame* rwh_view_child =
3778 new RenderWidgetHostViewChildFrame(render_view_host);
3779 frame_connector->set_view(rwh_view_child);
3780 rwh_view = rwh_view_child;
3781 } else {
3782 rwh_view = view_->CreateViewForWidget(render_view_host);
3783 }
[email protected]1a98a932009-11-17 00:12:523784
[email protected]420ae012009-04-24 05:16:323785 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443786 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213787 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323788
[email protected]74ce1ad2011-12-16 21:51:463789 // Make sure we use the correct starting page_id in the new RenderView.
3790 UpdateMaxPageIDIfNecessary(render_view_host);
3791 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583792 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463793
[email protected]9f76c1e2012-03-05 15:15:583794 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263795 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493796 opener_route_id,
[email protected]c7c0d822014-04-16 20:19:493797 max_page_id,
3798 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523799 return false;
[email protected]14392a52012-05-02 20:28:443800 }
[email protected]a4127722011-04-27 23:13:523801
[email protected]a220b5932013-09-21 03:47:443802#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503803 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3804 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443805 if (rwh_view) {
3806 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3807 render_widget_host->WasResized();
3808 }
[email protected]f8233cc2011-05-31 20:24:503809#endif
3810
[email protected]420ae012009-04-24 05:16:323811 return true;
3812}
3813
[email protected]7d244f12013-08-22 21:41:513814#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453815
[email protected]155c7f22013-12-09 17:07:183816base::android::ScopedJavaLocalRef<jobject>
3817WebContentsImpl::GetJavaWebContents() {
3818 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3819
3820 WebContentsAndroid* web_contents_android =
3821 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3822 if (!web_contents_android) {
3823 web_contents_android = new WebContentsAndroid(this);
3824 SetUserData(kWebContentsAndroidKey, web_contents_android);
3825 }
3826 return web_contents_android->GetJavaObject();
3827}
3828
[email protected]7d244f12013-08-22 21:41:513829bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3830 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163831 MSG_ROUTING_NONE,
3832 NULL);
[email protected]7d244f12013-08-22 21:41:513833}
[email protected]fc2b46b2014-05-03 16:33:453834
3835#elif defined(OS_MACOSX)
3836
3837void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
3838 view_->SetAllowOverlappingViews(overlapping);
3839}
3840
3841bool WebContentsImpl::GetAllowOverlappingViews() {
3842 return view_->GetAllowOverlappingViews();
3843}
3844
3845void WebContentsImpl::SetOverlayView(WebContents* overlay,
3846 const gfx::Point& offset) {
3847 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
3848 offset);
3849}
3850
3851void WebContentsImpl::RemoveOverlayView() {
3852 view_->RemoveOverlayView();
3853}
3854
[email protected]7d244f12013-08-22 21:41:513855#endif
3856
[email protected]6fba26d2014-04-29 09:38:283857void WebContentsImpl::OnDialogClosed(int render_process_id,
3858 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:263859 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493860 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263861 bool success,
[email protected]fcf75d42013-12-03 20:11:263862 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:283863 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3864 render_frame_id);
[email protected]87de04b02014-04-08 22:14:493865 last_dialog_suppressed_ = dialog_was_suppressed;
3866
[email protected]beb440c2009-11-06 04:08:543867 if (is_showing_before_unload_dialog_ && !success) {
3868 // If a beforeunload dialog is canceled, we need to stop the throbber from
3869 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:283870 if (rfh)
3871 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353872 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103873
[email protected]6d65a462013-06-21 21:29:123874 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3875 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543876 }
[email protected]87de04b02014-04-08 22:14:493877
[email protected]beb440c2009-11-06 04:08:543878 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:283879 if (rfh) {
3880 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3881 dialog_was_suppressed);
3882 } else {
3883 // Don't leak the sync IPC reply if the RFH or process is gone.
3884 delete reply_msg;
3885 }
[email protected]beb440c2009-11-06 04:08:543886}
3887
[email protected]b172aee2012-04-10 17:05:263888void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:543889 if (encoding == last_reported_encoding_)
3890 return;
3891 last_reported_encoding_ = encoding;
3892
3893 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123894 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103895}
[email protected]f45d2a72010-03-08 23:28:353896
[email protected]b172aee2012-04-10 17:05:263897void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:483898 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443899 // Can be NULL during tests.
3900 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:453901 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:363902}
[email protected]9f76c1e2012-03-05 15:15:583903
[email protected]1ac10dca2013-08-20 20:47:043904bool WebContentsImpl::IsHidden() {
3905 return capturer_count_ == 0 && !should_normally_be_visible_;
3906}
3907
[email protected]b0936d22013-11-28 06:47:363908RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213909 return frame_tree_.root()->render_manager();
3910}
3911
[email protected]b172aee2012-04-10 17:05:263912RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583913 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3914}
[email protected]7900bfdb2012-05-24 19:31:243915
[email protected]f8497342013-02-05 22:15:023916BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393917 return browser_plugin_guest_.get();
3918}
3919
[email protected]738f57a2013-06-29 21:06:543920void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3921 CHECK(!browser_plugin_guest_);
3922 browser_plugin_guest_.reset(guest);
3923}
3924
[email protected]f8497342013-02-05 22:15:023925BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393926 return browser_plugin_embedder_.get();
3927}
[email protected]8ff00d72012-10-23 19:12:213928
[email protected]d9030b82013-07-19 08:26:063929void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:193930 RenderFrameHost* render_frame_host) {
3931 STLDeleteValues(&power_save_blockers_[render_frame_host]);
3932 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:063933}
3934
3935void WebContentsImpl::ClearAllPowerSaveBlockers() {
3936 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3937 i != power_save_blockers_.end(); ++i)
3938 STLDeleteValues(&power_save_blockers_[i->first]);
3939 power_save_blockers_.clear();
3940}
3941
[email protected]fc2b46b2014-05-03 16:33:453942gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:213943 gfx::Size size;
3944 if (delegate_)
3945 size = delegate_->GetSizeForNewRenderView(this);
3946 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:453947 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:213948 return size;
3949}
3950
[email protected]9b159a52013-10-03 17:24:553951void WebContentsImpl::OnFrameRemoved(
3952 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583953 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553954 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583955 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553956}
3957
[email protected]222f5822014-02-05 23:40:493958void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3959 if (!delegate_)
3960 return;
3961 const gfx::Size new_size = GetPreferredSize();
3962 if (new_size != old_size)
3963 delegate_->UpdatePreferredSize(this, new_size);
3964}
3965
[email protected]8ff00d72012-10-23 19:12:213966} // namespace content