blob: 40fdc909f0284db7b6dd1af60f096229ce100985 [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]3d1dc3a2014-05-17 17:17:261421 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191422
[email protected]c4538072013-03-18 02:17:551423 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341424 // will be shown immediately).
1425 if (!params.opener_suppressed) {
1426 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451427 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501428
[email protected]d70bea92013-04-05 04:23:341429 // TODO(brettw): It seems bogus that we have to call this function on the
1430 // newly created object and give it one of its own member variables.
1431 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1432 }
[email protected]bafe6cd2012-05-23 23:09:501433 // Save the created window associated with the route so we can show it
1434 // later.
1435 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1436 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101437 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501438 }
1439
1440 if (delegate_) {
1441 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071442 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131443 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501444 }
1445
1446 if (params.opener_suppressed) {
1447 // When the opener is suppressed, the original renderer cannot access the
1448 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001449 bool was_blocked = false;
1450 if (delegate_) {
1451 gfx::Rect initial_pos;
1452 delegate_->AddNewContents(
1453 this, new_contents, params.disposition, initial_pos,
1454 params.user_gesture, &was_blocked);
1455 }
1456 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211457 OpenURLParams open_params(params.target_url,
1458 Referrer(),
1459 CURRENT_TAB,
1460 PAGE_TRANSITION_LINK,
1461 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301462 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001463 new_contents->OpenURL(open_params);
1464 }
[email protected]bafe6cd2012-05-23 23:09:501465 }
1466}
1467
[email protected]a8504022013-12-04 20:23:511468void WebContentsImpl::CreateNewWidget(int render_process_id,
1469 int route_id,
[email protected]180ef242013-11-07 06:50:461470 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511471 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501472}
1473
[email protected]a8504022013-12-04 20:23:511474void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1475 int route_id) {
1476 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501477}
1478
[email protected]a8504022013-12-04 20:23:511479void WebContentsImpl::CreateNewWidget(int render_process_id,
1480 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501481 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461482 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211483 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511484 // A message to create a new widget can only come from the active process for
1485 // this WebContentsImpl instance. If any other process sends the request,
1486 // it is invalid and the process must be terminated.
1487 if (process->GetID() != render_process_id) {
1488 base::ProcessHandle process_handle =
1489 RenderProcessHost::FromID(render_process_id)->GetHandle();
1490 if (process_handle != base::kNullProcessHandle) {
1491 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391492 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511493 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1494 }
1495 return;
1496 }
1497
[email protected]bafe6cd2012-05-23 23:09:501498 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041499 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261500 created_widgets_.insert(widget_host);
1501
[email protected]cfd80b02014-05-01 17:46:481502 RenderWidgetHostViewBase* widget_view =
1503 static_cast<RenderWidgetHostViewBase*>(
1504 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191505 if (!widget_view)
1506 return;
[email protected]bafe6cd2012-05-23 23:09:501507 if (!is_fullscreen) {
1508 // Popups should not get activated.
1509 widget_view->SetPopupType(popup_type);
1510 }
1511 // Save the created widget associated with the route so we can show it later.
1512 pending_widget_views_[route_id] = widget_view;
1513
1514#if defined(OS_MACOSX)
1515 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1516 // to allow it to survive the trip without being hosted.
1517 base::mac::NSObjectRetain(widget_view->GetNativeView());
1518#endif
1519}
1520
1521void WebContentsImpl::ShowCreatedWindow(int route_id,
1522 WindowOpenDisposition disposition,
1523 const gfx::Rect& initial_pos,
1524 bool user_gesture) {
1525 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001526 if (contents) {
1527 WebContentsDelegate* delegate = GetDelegate();
1528 if (delegate) {
1529 delegate->AddNewContents(
1530 this, contents, disposition, initial_pos, user_gesture, NULL);
1531 }
1532 }
[email protected]bafe6cd2012-05-23 23:09:501533}
1534
1535void WebContentsImpl::ShowCreatedWidget(int route_id,
1536 const gfx::Rect& initial_pos) {
1537 ShowCreatedWidget(route_id, false, initial_pos);
1538}
1539
1540void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1541 ShowCreatedWidget(route_id, true, gfx::Rect());
1542}
1543
1544void WebContentsImpl::ShowCreatedWidget(int route_id,
1545 bool is_fullscreen,
1546 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481547 RenderWidgetHostViewBase* widget_host_view =
1548 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501549 if (!widget_host_view)
1550 return;
[email protected]cfd80b02014-05-01 17:46:481551
1552 RenderWidgetHostView* view = NULL;
1553 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1554 if (guest && guest->embedder_web_contents()) {
1555 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1556 } else {
1557 view = GetRenderWidgetHostView();
1558 }
1559
[email protected]4aebbca2013-09-17 22:26:491560 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311561 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1562 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491563 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1564 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1565 delegate_->ToggleFullscreenModeForTab(this, true);
1566 } else {
[email protected]cfd80b02014-05-01 17:46:481567 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491568 }
[email protected]4aebbca2013-09-17 22:26:491569 FOR_EACH_OBSERVER(WebContentsObserver,
1570 observers_,
1571 DidShowFullscreenWidget(route_id));
1572 if (!widget_host_view->HasFocus())
1573 widget_host_view->Focus();
1574 } else {
[email protected]cfd80b02014-05-01 17:46:481575 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491576 }
[email protected]89054502012-06-03 10:29:241577
1578 RenderWidgetHostImpl* render_widget_host_impl =
1579 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1580 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311581 // Only allow privileged mouse lock for fullscreen render widget, which is
1582 // used to implement Pepper Flash fullscreen.
1583 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501584
1585#if defined(OS_MACOSX)
1586 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1587 // properly embedded (or purposefully ignored) we can release the retain we
1588 // took in CreateNewWidget().
1589 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1590#endif
1591}
1592
1593WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1594 PendingContents::iterator iter = pending_contents_.find(route_id);
1595
1596 // Certain systems can block the creation of new windows. If we didn't succeed
1597 // in creating one, just return NULL.
1598 if (iter == pending_contents_.end()) {
1599 return NULL;
1600 }
1601
1602 WebContentsImpl* new_contents = iter->second;
1603 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101604 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501605
[email protected]d70bea92013-04-05 04:23:341606 // Don't initialize the guest WebContents immediately.
1607 if (new_contents->GetRenderProcessHost()->IsGuest())
1608 return new_contents;
1609
[email protected]bafe6cd2012-05-23 23:09:501610 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1611 !new_contents->GetRenderViewHost()->GetView())
1612 return NULL;
1613
1614 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1615 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1616 return new_contents;
1617}
1618
1619RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1620 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1621 if (iter == pending_widget_views_.end()) {
1622 DCHECK(false);
1623 return NULL;
1624 }
1625
1626 RenderWidgetHostView* widget_host_view = iter->second;
1627 pending_widget_views_.erase(route_id);
1628
1629 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1630 if (!widget_host->GetProcess()->HasConnection()) {
1631 // The view has gone away or the renderer crashed. Nothing to do.
1632 return NULL;
1633 }
1634
1635 return widget_host_view;
1636}
1637
[email protected]f13b4202012-06-12 23:53:231638void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091639 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211640 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371641 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231642 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371643 } else {
1644 callback.Run(MediaStreamDevices(),
1645 MEDIA_DEVICE_INVALID_STATE,
1646 scoped_ptr<MediaStreamUI>());
1647 }
[email protected]f13b4202012-06-12 23:53:231648}
1649
[email protected]cc9200432013-07-23 23:02:401650SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1651 SiteInstance* instance) {
1652 return controller_.GetSessionStorageNamespace(instance);
1653}
1654
[email protected]9b159a52013-10-03 17:24:551655FrameTree* WebContentsImpl::GetFrameTree() {
1656 return &frame_tree_;
1657}
1658
[email protected]31a71eaf2014-03-13 01:47:361659void WebContentsImpl::AccessibilityEventReceived(
1660 const std::vector<AXEventNotificationDetails>& details) {
1661 FOR_EACH_OBSERVER(
1662 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1663}
1664
[email protected]edc3af82013-12-12 21:24:071665void WebContentsImpl::OnShowValidationMessage(
1666 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291667 const base::string16& main_text,
1668 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071669 if (delegate_)
1670 delegate_->ShowValidationMessage(
1671 this, anchor_in_root_view, main_text, sub_text);
1672}
1673
1674void WebContentsImpl::OnHideValidationMessage() {
1675 if (delegate_)
1676 delegate_->HideValidationMessage(this);
1677}
1678
1679void WebContentsImpl::OnMoveValidationMessage(
1680 const gfx::Rect& anchor_in_root_view) {
1681 if (delegate_)
1682 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1683}
1684
[email protected]32deec62013-05-15 23:55:041685void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1686 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441687 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041688}
1689
[email protected]b172aee2012-04-10 17:05:261690void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491691 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231692 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491693 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331694}
1695
[email protected]b172aee2012-04-10 17:05:261696void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341697 if (delegate_)
1698 delegate_->ResizeDueToAutoResize(this, new_size);
1699}
1700
[email protected]b172aee2012-04-10 17:05:261701WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201702 if (!delegate_)
1703 return NULL;
[email protected]00c37fc2011-08-02 00:22:501704
[email protected]e5d549d2011-12-28 01:29:201705 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201706 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341707}
1708
[email protected]6b618e62012-08-16 12:59:181709bool WebContentsImpl::Send(IPC::Message* message) {
1710 if (!GetRenderViewHost()) {
1711 delete message;
1712 return false;
1713 }
1714
1715 return GetRenderViewHost()->Send(message);
1716}
1717
[email protected]b172aee2012-04-10 17:05:261718bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501719 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261720 FrameTreeNode* node = frame_tree_.root();
1721
1722 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1723 // specified in the pending entry.
1724 NavigationEntryImpl* pending_entry =
1725 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1726 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1727 pending_entry->frame_tree_node_id() != -1) {
1728 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1729 }
1730
1731 return node->navigator()->NavigateToPendingEntry(
1732 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541733}
[email protected]96d185d2009-04-24 03:28:541734
[email protected]a86c0e962013-12-17 17:10:391735void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1736 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441737 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391738 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441739}
1740
[email protected]20ca0382013-02-28 19:50:071741void WebContentsImpl::AttachInterstitialPage(
1742 InterstitialPageImpl* interstitial_page) {
1743 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211744 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291745
1746 // Cancel any visible dialogs so that they don't interfere with the
1747 // interstitial.
1748 if (dialog_manager_)
1749 dialog_manager_->CancelActiveAndPendingDialogs(this);
1750
[email protected]20ca0382013-02-28 19:50:071751 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1752 DidAttachInterstitialPage());
1753}
1754
1755void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571756 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211757 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071758 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1759 DidDetachInterstitialPage());
1760}
1761
[email protected]b172aee2012-04-10 17:05:261762void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331763 const SiteInstance* site_instance,
1764 int history_length,
1765 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411766 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1767 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211768 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191769 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141770 return;
[email protected]9e1ad4b2011-08-14 16:49:191771 }
[email protected]9f76c1e2012-03-05 15:15:581772 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191773 if (!rvh) {
1774 NOTREACHED();
1775 return;
1776 }
[email protected]9f76c1e2012-03-05 15:15:581777 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191778 NOTREACHED();
1779 return;
1780 }
[email protected]6b618e62012-08-16 12:59:181781 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1782 history_length,
1783 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141784}
1785
[email protected]4fed3702014-04-01 09:08:001786void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171787 RenderFrameHost* focused_frame = GetFocusedFrame();
1788 if (!focused_frame)
1789 return;
1790
[email protected]959be4c2014-04-08 15:01:331791 focused_frame->Send(new FrameMsg_Reload(
1792 focused_frame->GetRoutingID(), ignore_cache));
1793}
1794
1795void WebContentsImpl::Undo() {
1796 RenderFrameHost* focused_frame = GetFocusedFrame();
1797 if (!focused_frame)
1798 return;
1799
1800 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1801 RecordAction(base::UserMetricsAction("Undo"));
1802}
1803
1804void WebContentsImpl::Redo() {
1805 RenderFrameHost* focused_frame = GetFocusedFrame();
1806 if (!focused_frame)
1807 return;
1808 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1809 RecordAction(base::UserMetricsAction("Redo"));
1810}
1811
1812void WebContentsImpl::Cut() {
1813 RenderFrameHost* focused_frame = GetFocusedFrame();
1814 if (!focused_frame)
1815 return;
1816
1817 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1818 RecordAction(base::UserMetricsAction("Cut"));
1819}
1820
1821void WebContentsImpl::Copy() {
1822 RenderFrameHost* focused_frame = GetFocusedFrame();
1823 if (!focused_frame)
1824 return;
1825
1826 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1827 RecordAction(base::UserMetricsAction("Copy"));
1828}
1829
1830void WebContentsImpl::CopyToFindPboard() {
1831#if defined(OS_MACOSX)
1832 RenderFrameHost* focused_frame = GetFocusedFrame();
1833 if (!focused_frame)
1834 return;
1835
1836 // Windows/Linux don't have the concept of a find pasteboard.
1837 focused_frame->Send(
1838 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1839 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1840#endif
1841}
1842
1843void WebContentsImpl::Paste() {
1844 RenderFrameHost* focused_frame = GetFocusedFrame();
1845 if (!focused_frame)
1846 return;
1847
1848 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1849 RecordAction(base::UserMetricsAction("Paste"));
1850}
1851
1852void WebContentsImpl::PasteAndMatchStyle() {
1853 RenderFrameHost* focused_frame = GetFocusedFrame();
1854 if (!focused_frame)
1855 return;
1856
1857 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1858 focused_frame->GetRoutingID()));
1859 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1860}
1861
1862void WebContentsImpl::Delete() {
1863 RenderFrameHost* focused_frame = GetFocusedFrame();
1864 if (!focused_frame)
1865 return;
1866
1867 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1868 RecordAction(base::UserMetricsAction("DeleteSelection"));
1869}
1870
1871void WebContentsImpl::SelectAll() {
1872 RenderFrameHost* focused_frame = GetFocusedFrame();
1873 if (!focused_frame)
1874 return;
1875
1876 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1877 RecordAction(base::UserMetricsAction("SelectAll"));
1878}
1879
1880void WebContentsImpl::Unselect() {
1881 RenderFrameHost* focused_frame = GetFocusedFrame();
1882 if (!focused_frame)
1883 return;
1884
1885 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1886 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171887}
1888
1889void WebContentsImpl::Replace(const base::string16& word) {
1890 RenderFrameHost* focused_frame = GetFocusedFrame();
1891 if (!focused_frame)
1892 return;
1893
[email protected]959be4c2014-04-08 15:01:331894 focused_frame->Send(new InputMsg_Replace(
1895 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171896}
1897
1898void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1899 RenderFrameHost* focused_frame = GetFocusedFrame();
1900 if (!focused_frame)
1901 return;
1902
[email protected]959be4c2014-04-08 15:01:331903 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1904 focused_frame->GetRoutingID(), word));
1905}
1906
1907void WebContentsImpl::NotifyContextMenuClosed(
1908 const CustomContextMenuContext& context) {
1909 RenderFrameHost* focused_frame = GetFocusedFrame();
1910 if (!focused_frame)
1911 return;
1912
1913 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1914 focused_frame->GetRoutingID(), context));
1915}
1916
1917void WebContentsImpl::ExecuteCustomContextMenuCommand(
1918 int action, const CustomContextMenuContext& context) {
1919 RenderFrameHost* focused_frame = GetFocusedFrame();
1920 if (!focused_frame)
1921 return;
1922
1923 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1924 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001925}
1926
[email protected]fc2b46b2014-05-03 16:33:451927gfx::NativeView WebContentsImpl::GetNativeView() {
1928 return view_->GetNativeView();
1929}
1930
1931gfx::NativeView WebContentsImpl::GetContentNativeView() {
1932 return view_->GetContentNativeView();
1933}
1934
1935gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1936 return view_->GetTopLevelNativeWindow();
1937}
1938
1939gfx::Rect WebContentsImpl::GetViewBounds() {
1940 return view_->GetViewBounds();
1941}
1942
1943gfx::Rect WebContentsImpl::GetContainerBounds() {
1944 gfx::Rect rv;
1945 view_->GetContainerBounds(&rv);
1946 return rv;
1947}
1948
1949DropData* WebContentsImpl::GetDropData() {
1950 return view_->GetDropData();
1951}
1952
1953void WebContentsImpl::Focus() {
1954 view_->Focus();
1955}
1956
1957void WebContentsImpl::SetInitialFocus() {
1958 view_->SetInitialFocus();
1959}
1960
1961void WebContentsImpl::StoreFocus() {
1962 view_->StoreFocus();
1963}
1964
1965void WebContentsImpl::RestoreFocus() {
1966 view_->RestoreFocus();
1967}
1968
[email protected]b172aee2012-04-10 17:05:261969void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271970 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211971 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541972 return;
1973 }
[email protected]9f76c1e2012-03-05 15:15:581974 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541975}
1976
[email protected]b172aee2012-04-10 17:05:261977bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211978 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541979}
1980
[email protected]b172aee2012-04-10 17:05:261981InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211982 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221983}
1984
[email protected]b172aee2012-04-10 17:05:261985bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161986 // WebKit creates Document object when MIME type is application/xhtml+xml,
1987 // so we also support this MIME type.
1988 return contents_mime_type_ == "text/html" ||
1989 contents_mime_type_ == "text/xml" ||
1990 contents_mime_type_ == "application/xhtml+xml" ||
1991 contents_mime_type_ == "text/plain" ||
1992 contents_mime_type_ == "text/css" ||
1993 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1994}
1995
[email protected]b172aee2012-04-10 17:05:261996void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591997 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161998 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551999 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012000 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142001 return;
[email protected]c7dd2f62011-07-18 15:57:592002 }
2003
2004 Stop();
2005
2006 // Create the save package and possibly prompt the user for the name to save
2007 // the page as. The user prompt is an asynchronous operation that runs on
2008 // another thread.
2009 save_package_ = new SavePackage(this);
2010 save_package_->GetSaveInfo();
2011}
2012
2013// Used in automated testing to bypass prompting the user for file names.
2014// Instead, the names and paths are hard coded rather than running them through
2015// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342016bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2017 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212018 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592019 // Stop the page from navigating.
2020 Stop();
2021
2022 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212023 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592024}
2025
[email protected]3c71576ce2013-07-23 02:00:012026void WebContentsImpl::SaveFrame(const GURL& url,
2027 const Referrer& referrer) {
2028 if (!GetURL().is_valid())
2029 return;
2030 bool is_main_frame = (url == GetURL());
2031
2032 DownloadManager* dlm =
2033 BrowserContext::GetDownloadManager(GetBrowserContext());
2034 if (!dlm)
2035 return;
2036 int64 post_id = -1;
2037 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272038 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012039 if (entry)
2040 post_id = entry->GetPostID();
2041 }
2042 scoped_ptr<DownloadUrlParameters> params(
2043 DownloadUrlParameters::FromWebContents(this, url));
2044 params->set_referrer(referrer);
2045 params->set_post_id(post_id);
2046 params->set_prefer_cache(true);
2047 if (post_id >= 0)
2048 params->set_method("POST");
2049 params->set_prompt(true);
2050 dlm->DownloadUrl(params.Pass());
2051}
2052
[email protected]b172aee2012-04-10 17:05:262053void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342054 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482055 const base::Callback<void(int64)>& callback) {
2056 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122057}
2058
[email protected]6286a372013-10-09 04:03:272059// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262060bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272061 NavigationEntryImpl* visible_entry =
2062 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2063 return (visible_entry != NULL &&
2064 visible_entry->site_instance() == GetSiteInstance() &&
2065 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322066}
2067
[email protected]b172aee2012-04-10 17:05:262068const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272069 return contents_mime_type_;
2070}
2071
[email protected]b172aee2012-04-10 17:05:262072bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272073 return notify_disconnection_;
2074}
2075
[email protected]b172aee2012-04-10 17:05:262076void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312077 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182078 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162079}
2080
[email protected]b172aee2012-04-10 17:05:262081void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542082 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182083 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162084}
2085
[email protected]8ff00d72012-10-23 19:12:212086RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272087 return &renderer_preferences_;
2088}
2089
[email protected]e35ccd52012-05-23 16:22:472090void WebContentsImpl::Close() {
2091 Close(GetRenderViewHost());
2092}
2093
[email protected]cf200a562013-05-03 16:24:292094void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462095 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292096 if (browser_plugin_embedder_.get())
2097 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2098 screen_x, screen_y, operation);
2099 if (GetRenderViewHost())
2100 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2101 screen_x, screen_y, operation);
2102}
2103
[email protected]d60f3702013-12-26 16:30:242104void WebContentsImpl::DidGetResourceResponseStart(
2105 const ResourceRequestDetails& details) {
2106 controller_.ssl_manager()->DidStartResourceResponse(details);
2107
2108 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2109 DidGetResourceResponseStart(details));
2110
2111 // TODO(avi): Remove. http://crbug.com/170921
2112 NotificationService::current()->Notify(
2113 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2114 Source<WebContents>(this),
2115 Details<const ResourceRequestDetails>(&details));
2116}
2117
2118void WebContentsImpl::DidGetRedirectForResourceRequest(
2119 RenderViewHost* render_view_host,
2120 const ResourceRedirectDetails& details) {
2121 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2122
2123 FOR_EACH_OBSERVER(
2124 WebContentsObserver,
2125 observers_,
2126 DidGetRedirectForResourceRequest(render_view_host, details));
2127
2128 // TODO(avi): Remove. http://crbug.com/170921
2129 NotificationService::current()->Notify(
2130 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2131 Source<WebContents>(this),
2132 Details<const ResourceRedirectDetails>(&details));
2133}
2134
[email protected]b172aee2012-04-10 17:05:262135void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522136 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582137 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512138 if (delegate_)
2139 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292140 if (browser_plugin_embedder_.get())
2141 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342142}
2143
[email protected]e35ccd52012-05-23 16:22:472144void WebContentsImpl::UserGestureDone() {
2145 OnUserGesture();
2146}
2147
[email protected]b172aee2012-04-10 17:05:262148void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272149 closed_by_user_gesture_ = value;
2150}
2151
[email protected]b172aee2012-04-10 17:05:262152bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272153 return closed_by_user_gesture_;
2154}
2155
[email protected]b172aee2012-04-10 17:05:262156double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052157 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562158 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252159 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172160 return 0;
[email protected]b75b8292010-10-01 07:28:252161
2162 double zoom_level;
2163 if (temporary_zoom_settings_) {
2164 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582165 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252166 } else {
[email protected]2ae88d12011-10-14 09:11:192167 GURL url;
[email protected]6286a372013-10-09 04:03:272168 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192169 // Since zoom map is updated using rewritten URL, use rewritten URL
2170 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272171 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022172 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2173 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252174 }
[email protected]d0b8d092010-10-25 04:05:172175 return zoom_level;
2176}
[email protected]b75b8292010-10-01 07:28:252177
[email protected]b172aee2012-04-10 17:05:262178int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592179 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172180 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012181 // Calculate the zoom percent from the factor. Round up to the nearest whole
2182 // number.
[email protected]b75b8292010-10-01 07:28:252183 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492184 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252185 *enable_decrement = percent > minimum_zoom_percent_;
2186 *enable_increment = percent < maximum_zoom_percent_;
2187 return percent;
2188}
2189
[email protected]b172aee2012-04-10 17:05:262190void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502191 if (!delegate_)
2192 return;
2193
[email protected]6286a372013-10-09 04:03:272194 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2195 if (!entry)
[email protected]1788e772010-12-15 16:40:502196 return;
2197
[email protected]6286a372013-10-09 04:03:272198 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122199}
2200
[email protected]b172aee2012-04-10 17:05:262201void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042202 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272203 if (!delegate_)
2204 return;
2205
[email protected]691aa2f2013-05-28 22:52:042206 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272207}
2208
[email protected]b172aee2012-04-10 17:05:262209int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272210 return minimum_zoom_percent_;
2211}
2212
[email protected]b172aee2012-04-10 17:05:262213int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272214 return maximum_zoom_percent_;
2215}
2216
[email protected]b172aee2012-04-10 17:05:262217gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492218 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232219}
2220
[email protected]b172aee2012-04-10 17:05:262221bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052222 if (GetBrowserPluginGuest())
2223 return GetBrowserPluginGuest()->LockMouse(allowed);
2224
[email protected]0bfbf882011-12-22 18:19:272225 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582226 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272227}
2228
[email protected]b172aee2012-04-10 17:05:262229bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442230 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502231}
2232
[email protected]cb805452013-05-22 15:16:212233void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482234 if (!color_chooser_info_.get())
2235 return;
2236 RenderFrameHost* rfh = RenderFrameHost::FromID(
2237 color_chooser_info_->render_process_id,
2238 color_chooser_info_->render_frame_id);
2239 if (!rfh)
2240 return;
2241
2242 rfh->Send(new FrameMsg_DidChooseColorResponse(
2243 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202244}
2245
[email protected]cb805452013-05-22 15:16:212246void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482247 if (!color_chooser_info_.get())
2248 return;
2249 RenderFrameHost* rfh = RenderFrameHost::FromID(
2250 color_chooser_info_->render_process_id,
2251 color_chooser_info_->render_frame_id);
2252 if (!rfh)
2253 return;
2254
2255 rfh->Send(new FrameMsg_DidEndColorChooser(
2256 rfh->GetRoutingID(), color_chooser_info_->identifier));
2257 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202258}
2259
[email protected]41225fe2013-03-29 05:32:022260int WebContentsImpl::DownloadImage(const GURL& url,
2261 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302262 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022263 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582264 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022265 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392266 return id;
2267}
2268
[email protected]5dcaf8e2013-12-28 01:31:422269bool WebContentsImpl::IsSubframe() const {
2270 return is_subframe_;
2271}
2272
[email protected]9649d492014-01-10 07:15:522273void WebContentsImpl::SetZoomLevel(double level) {
2274 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2275 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2276 if (embedder)
2277 embedder->SetZoomLevel(level);
2278}
2279
[email protected]36ec24f2014-01-09 00:32:082280void WebContentsImpl::Find(int request_id,
2281 const base::string16& search_text,
2282 const blink::WebFindOptions& options) {
2283 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2284}
2285
2286void WebContentsImpl::StopFinding(StopFindAction action) {
2287 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2288}
2289
[email protected]4fe53add2014-04-08 19:53:362290void WebContentsImpl::InsertCSS(const std::string& css) {
2291 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2292 GetMainFrame()->GetRoutingID(), css));
2293}
2294
[email protected]b172aee2012-04-10 17:05:262295bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272296 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202297 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332298 return true;
2299 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272300}
2301
[email protected]b172aee2012-04-10 17:05:262302void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272303 if (delegate_)
2304 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212305}
2306
[email protected]52913802013-12-10 05:52:182307void WebContentsImpl::DidStartProvisionalLoad(
2308 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072309 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182310 const GURL& validated_url,
2311 bool is_error_page,
2312 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262313 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182314 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572315 DidChangeLoadProgress(0);
2316
[email protected]0d60f0192011-04-14 12:40:102317 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272318 int render_frame_id = render_frame_host->GetRoutingID();
2319 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252320 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072321 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272322 render_frame_id, parent_routing_id, is_main_frame,
2323 validated_url, is_error_page, is_iframe_srcdoc,
2324 render_view_host));
[email protected]400992b2012-06-14 00:03:542325
2326 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182327 FOR_EACH_OBSERVER(
2328 WebContentsObserver,
2329 observers_,
2330 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582331 render_frame_host));
[email protected]400992b2012-06-14 00:03:542332 }
2333}
2334
[email protected]3109fbb72014-01-06 23:57:152335void WebContentsImpl::DidFailProvisionalLoadWithError(
2336 RenderFrameHostImpl* render_frame_host,
2337 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2338 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272339 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262340 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272341 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152342 FOR_EACH_OBSERVER(
2343 WebContentsObserver,
2344 observers_,
[email protected]161eabd2014-03-19 19:47:272345 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152346 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262347 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152348 validated_url,
2349 params.error_code,
2350 params.error_description,
[email protected]161eabd2014-03-19 19:47:272351 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152352}
2353
[email protected]b80624c2014-02-09 02:46:552354void WebContentsImpl::DidFailLoadWithError(
2355 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552356 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552357 int error_code,
2358 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272359 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262360 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272361 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552362 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272363 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262364 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552365}
2366
[email protected]52913802013-12-10 05:52:182367void WebContentsImpl::NotifyChangedNavigationState(
2368 InvalidateTypes changed_flags) {
2369 NotifyNavigationStateChanged(changed_flags);
2370}
2371
[email protected]3691e5cf2014-01-22 10:16:202372void WebContentsImpl::AboutToNavigateRenderFrame(
2373 RenderFrameHostImpl* render_frame_host) {
2374 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272375 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202376 FOR_EACH_OBSERVER(
2377 WebContentsObserver,
2378 observers_,
[email protected]161eabd2014-03-19 19:47:272379 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202380}
2381
2382void WebContentsImpl::DidStartNavigationToPendingEntry(
2383 RenderFrameHostImpl* render_frame_host,
2384 const GURL& url,
2385 NavigationController::ReloadType reload_type) {
2386 // Notify observers about navigation.
2387 FOR_EACH_OBSERVER(
2388 WebContentsObserver,
2389 observers_,
2390 DidStartNavigationToPendingEntry(url, reload_type));
2391}
2392
[email protected]8cb834e2014-03-06 14:23:232393void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2394 const OpenURLParams& params) {
2395 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182396 WebContents* new_contents = OpenURL(params);
2397
2398 if (new_contents) {
2399 // Notify observers.
2400 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2401 DidOpenRequestedURL(new_contents,
2402 params.url,
2403 params.referrer,
2404 params.disposition,
2405 params.transition,
[email protected]8cb834e2014-03-06 14:23:232406 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182407 }
2408}
2409
[email protected]aa62afd2014-04-22 19:22:462410bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2411 if (!delegate_)
2412 return false;
2413 return delegate_->ShouldPreserveAbortedURLs(this);
2414}
2415
[email protected]400992b2012-06-14 00:03:542416void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582417 RenderFrameHostImpl* render_frame_host,
2418 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542419 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582420 FOR_EACH_OBSERVER(
2421 WebContentsObserver,
2422 observers_,
2423 ProvisionalChangeToMainFrameUrl(validated_target_url,
2424 render_frame_host));
[email protected]724159a2010-12-30 01:11:182425}
2426
[email protected]37567b432014-02-12 01:12:222427void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432428 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222429 const base::string16& frame_unique_name,
2430 bool is_main_frame,
2431 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432432 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432433 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272434 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222435 // Notify observers about the commit of the provisional load.
2436 FOR_EACH_OBSERVER(
2437 WebContentsObserver,
2438 observers_,
[email protected]27dd82fd2014-03-03 22:11:432439 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222440 frame_unique_name,
2441 is_main_frame,
2442 url,
2443 transition_type,
2444 render_view_host));
2445}
2446
[email protected]0d0f4c492014-04-02 06:42:572447void WebContentsImpl::DidNavigateMainFramePreCommit(
2448 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2449 // Ensure fullscreen mode is exited before committing the navigation to a
2450 // different page. The next page will not start out assuming it is in
2451 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192452 if (controller_.IsURLInPageNavigation(params.url,
2453 params.was_within_same_page,
2454 NAVIGATION_TYPE_UNKNOWN)) {
2455 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572456 return;
2457 }
2458 if (IsFullscreenForCurrentTab())
2459 GetRenderViewHost()->ExitFullscreen();
2460 DCHECK(!IsFullscreenForCurrentTab());
2461}
2462
[email protected]37567b432014-02-12 01:12:222463void WebContentsImpl::DidNavigateMainFramePostCommit(
2464 const LoadCommittedDetails& details,
2465 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2466 if (details.is_navigation_to_different_page()) {
2467 // Clear the status bubble. This is a workaround for a bug where WebKit
2468 // doesn't let us know that the cursor left an element during a
2469 // transition (this is also why the mouse cursor remains as a hand after
2470 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2471 // clear the bubble when a user navigates to a named anchor in the same
2472 // page.
2473 UpdateTargetURL(details.entry->GetPageID(), GURL());
2474 }
2475
2476 if (!details.is_in_page) {
2477 // Once the main frame is navigated, we're no longer considered to have
2478 // displayed insecure content.
2479 displayed_insecure_content_ = false;
2480 SSLManager::NotifySSLInternalStateChanged(
2481 GetController().GetBrowserContext());
2482 }
2483
2484 // Notify observers about navigation.
2485 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2486 DidNavigateMainFrame(details, params));
2487
2488 if (delegate_) {
2489 delegate_->DidNavigateMainFramePostCommit(this);
2490 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2491 }
2492}
2493
2494void WebContentsImpl::DidNavigateAnyFramePostCommit(
2495 RenderFrameHostImpl* render_frame_host,
2496 const LoadCommittedDetails& details,
2497 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102498 // Now that something has committed, we don't need to track whether the
2499 // initial page has been accessed.
2500 has_accessed_initial_document_ = false;
2501
[email protected]37567b432014-02-12 01:12:222502 // If we navigate off the page, close all JavaScript dialogs.
2503 if (dialog_manager_ && !details.is_in_page)
2504 dialog_manager_->CancelActiveAndPendingDialogs(this);
2505
2506 // Notify observers about navigation.
2507 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2508 DidNavigateAnyFrame(details, params));
2509}
2510
2511void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2512 contents_mime_type_ = mime_type;
2513}
2514
2515bool WebContentsImpl::CanOverscrollContent() {
2516 if (delegate_)
2517 return delegate_->CanOverscrollContent();
2518
2519 return false;
2520}
2521
[email protected]b172aee2012-04-10 17:05:262522void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182523 const GURL& url,
[email protected]70435962011-08-02 20:13:282524 const std::string& security_info,
2525 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182526 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282527 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192528 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182529 cache.Increment();
2530
2531 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082532 int cert_id = 0;
2533 net::CertStatus cert_status = 0;
2534 int security_bits = -1;
2535 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122536 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212537 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122538 &security_bits, &connection_status,
2539 &signed_certificate_timestamp_ids);
2540 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212541 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002542 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2543 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182544
[email protected]b0f724c2013-09-05 04:21:132545 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2546
2547 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2548 DidLoadResourceFromMemoryCache(details));
2549
[email protected]8bfc8272013-09-09 20:10:532550 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2551 scoped_refptr<net::URLRequestContextGetter> request_context(
2552 resource_type == ResourceType::MEDIA ?
2553 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2554 GetRenderProcessHost()->GetID()) :
2555 GetBrowserContext()->GetRequestContextForRenderProcess(
2556 GetRenderProcessHost()->GetID()));
2557 BrowserThread::PostTask(
2558 BrowserThread::IO,
2559 FROM_HERE,
2560 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2561 }
[email protected]724159a2010-12-30 01:11:182562}
2563
[email protected]b172aee2012-04-10 17:05:262564void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392565 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182566 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192567 SSLManager::NotifySSLInternalStateChanged(
2568 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182569}
2570
[email protected]b172aee2012-04-10 17:05:262571void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022572 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582573 LOG(WARNING) << security_origin << " ran insecure content from "
2574 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392575 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412576 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392577 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182578 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412579 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192580 SSLManager::NotifySSLInternalStateChanged(
2581 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182582}
2583
[email protected]501052ff2014-02-21 22:19:072584void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572585 CHECK(render_frame_message_source_);
2586 CHECK(!render_view_message_source_);
2587 RenderFrameHostImpl* rfh =
2588 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2589
[email protected]161eabd2014-03-19 19:47:272590 int render_frame_id = rfh->GetRoutingID();
2591 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572592 FOR_EACH_OBSERVER(WebContentsObserver,
2593 observers_,
[email protected]161eabd2014-03-19 19:47:272594 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182595}
2596
[email protected]b172aee2012-04-10 17:05:262597void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262598 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372599 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122600 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2601 GetRenderProcessHost()->ReceivedBadMessage();
2602 return;
2603 }
[email protected]a1b99262013-12-27 21:56:222604
[email protected]8b3af1e2014-01-24 13:29:122605 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442606 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372607 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422608 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372609
[email protected]61ac9e242014-03-21 20:55:262610 RenderFrameHostImpl* rfh =
2611 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272612 int render_frame_id = rfh->GetRoutingID();
2613 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262614 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252615 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272616 DidFinishLoad(render_frame_id, validated_url,
2617 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312618}
2619
[email protected]b172aee2012-04-10 17:05:262620void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222621 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2622 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262623}
2624
[email protected]b172aee2012-04-10 17:05:262625void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2626 int maximum_percent,
2627 bool remember) {
[email protected]216813952011-05-19 22:21:262628 minimum_zoom_percent_ = minimum_percent;
2629 maximum_zoom_percent_ = maximum_percent;
2630 temporary_zoom_settings_ = !remember;
2631}
2632
[email protected]b172aee2012-04-10 17:05:262633void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342634 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432635 if (!delegate_)
2636 return;
2637
[email protected]b9535422012-02-09 01:47:592638 ChildProcessSecurityPolicyImpl* policy =
2639 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222640 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592641 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212642}
2643
[email protected]b172aee2012-04-10 17:05:262644void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2645 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262646 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362647 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432648 if (!delegate_)
2649 return;
2650
[email protected]b9535422012-02-09 01:47:592651 ChildProcessSecurityPolicyImpl* policy =
2652 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322653 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592654 return;
[email protected]8f810632013-06-06 22:33:322655
[email protected]c125e532014-05-10 20:39:062656 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202657}
2658
[email protected]b172aee2012-04-10 17:05:262659void WebContentsImpl::OnFindReply(int request_id,
2660 int number_of_matches,
2661 const gfx::Rect& selection_rect,
2662 int active_match_ordinal,
2663 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432664 if (delegate_) {
2665 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2666 active_match_ordinal, final_update);
2667 }
[email protected]b888919c2011-09-02 00:32:162668}
2669
[email protected]59363fc92012-09-05 03:46:312670#if defined(OS_ANDROID)
2671void WebContentsImpl::OnFindMatchRectsReply(
2672 int version,
2673 const std::vector<gfx::RectF>& rects,
2674 const gfx::RectF& active_rect) {
2675 if (delegate_)
2676 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2677}
[email protected]583418cc2013-01-17 14:01:102678
[email protected]1ff427972013-02-07 21:14:072679void WebContentsImpl::OnOpenDateTimeDialog(
2680 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092681 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2682 GetRenderViewHost(),
2683 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132684 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092685 value.minimum,
2686 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172687 value.step,
2688 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102689}
2690
[email protected]59363fc92012-09-05 03:46:312691#endif
2692
[email protected]f114fa42013-12-06 17:06:442693void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2694 const base::FilePath& path,
2695 bool is_hung) {
2696 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2697
2698 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2699 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2700}
2701
2702void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422703 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442704 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422705 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452706}
2707
[email protected]cfa856d62014-02-22 07:58:402708void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2709 int automation_id) {
2710 DomOperationNotificationDetails details(json_string, automation_id);
2711 NotificationService::current()->Notify(
2712 NOTIFICATION_DOM_OPERATION_RESPONSE,
2713 Source<WebContents>(this),
2714 Details<DomOperationNotificationDetails>(&details));
2715}
2716
[email protected]b172aee2012-04-10 17:05:262717void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2718 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102719 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252720 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102721 AppCacheAccessed(manifest_url, blocked_by_policy));
2722}
2723
[email protected]8bc5ff02013-11-29 06:34:032724void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482725 int color_chooser_id,
2726 SkColor color,
2727 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462728 ColorChooser* new_color_chooser = delegate_ ?
2729 delegate_->OpenColorChooser(this, color, suggestions) :
2730 NULL;
[email protected]820957a2014-01-14 14:56:302731 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212732 return;
[email protected]8ed16472014-04-11 19:02:482733 if (color_chooser_info_.get())
2734 color_chooser_info_->chooser->End();
2735
2736 color_chooser_info_.reset(new ColorChooserInfo(
2737 render_frame_message_source_->GetProcess()->GetID(),
2738 render_frame_message_source_->GetRoutingID(),
2739 new_color_chooser,
2740 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202741}
2742
[email protected]b172aee2012-04-10 17:05:262743void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482744 if (color_chooser_info_ &&
2745 color_chooser_id == color_chooser_info_->identifier)
2746 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202747}
2748
[email protected]b172aee2012-04-10 17:05:262749void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322750 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482751 if (color_chooser_info_ &&
2752 color_chooser_id == color_chooser_info_->identifier)
2753 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202754}
2755
[email protected]d0759f492012-04-19 22:50:502756// This exists for render views that don't have a WebUI, but do have WebUI
2757// bindings enabled.
2758void WebContentsImpl::OnWebUISend(const GURL& source_url,
2759 const std::string& name,
2760 const base::ListValue& args) {
2761 if (delegate_)
2762 delegate_->WebUISend(this, source_url, name, args);
2763}
2764
[email protected]d8415ad92012-08-23 14:40:502765void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442766 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502767 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342768 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162769 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442770 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162771 return;
[email protected]d8415ad92012-08-23 14:40:502772 }
2773
[email protected]8c8fc292012-11-23 18:57:162774 if (!delegate_->RequestPpapiBrokerPermission(
2775 this, url, plugin_path,
2776 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442777 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162778 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442779 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162780 }
[email protected]d8415ad92012-08-23 14:40:502781}
2782
[email protected]ea0309c2013-08-06 19:35:442783void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502784 bool result) {
[email protected]ea0309c2013-08-06 19:35:442785 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502786}
2787
[email protected]c4538072013-03-18 02:17:552788void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372789 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082790 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552791 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392792 // For more info, see comment above classes BrowserPluginEmbedder and
2793 // BrowserPluginGuest.
2794 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142795 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082796 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372797}
2798
[email protected]41225fe2013-03-29 05:32:022799void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392800 int id,
[email protected]749fadd2013-05-15 08:37:482801 int http_status_code,
[email protected]795c28972012-12-06 06:13:392802 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302803 const std::vector<SkBitmap>& bitmaps,
2804 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132805 if (bitmaps.size() != original_bitmap_sizes.size())
2806 return;
2807
[email protected]41225fe2013-03-29 05:32:022808 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2809 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392810 // Currently WebContents notifies us of ANY downloads so that it is
2811 // possible to get here.
2812 return;
2813 }
2814 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302815 iter->second.Run(
2816 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392817 }
[email protected]41225fe2013-03-29 05:32:022818 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392819}
2820
2821void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392822 const std::vector<FaviconURL>& candidates) {
2823 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292824 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392825}
2826
[email protected]1dd0bb752014-02-01 01:16:262827void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2828 bool has_video,
2829 bool has_audio) {
2830// Chrome OS does its own detection of audio and video.
2831#if !defined(OS_CHROMEOS)
2832 scoped_ptr<PowerSaveBlocker> blocker;
2833 if (has_video) {
2834 blocker = PowerSaveBlocker::Create(
2835 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2836#if defined(OS_ANDROID)
2837 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2838 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2839#endif
2840 } else if (has_audio) {
2841 blocker = PowerSaveBlocker::Create(
2842 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2843 }
2844
2845 if (blocker) {
[email protected]96307312014-05-04 01:00:192846 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262847 blocker.release();
2848 }
2849#endif // !defined(OS_CHROMEOS)
2850}
2851
2852void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062853 // Chrome OS does its own detection of audio and video.
2854#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192855 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2856 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062857#endif // !defined(OS_CHROMEOS)
2858}
2859
[email protected]50279492014-05-05 23:24:292860void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152861 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292862 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152863}
[email protected]d9030b82013-07-19 08:26:062864
[email protected]e67ebf32013-02-13 11:07:192865void WebContentsImpl::DidChangeVisibleSSLState() {
2866 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2867 DidChangeVisibleSSLState());
2868}
2869
[email protected]17e286e2013-03-01 23:29:392870void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2871 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2872 BeforeFormRepostWarningShow());
2873}
2874
[email protected]ec6c05f2013-10-23 18:41:572875
2876void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2877 Activate();
2878 if (delegate_)
2879 delegate_->ShowRepostFormWarningDialog(this);
2880}
2881
[email protected]b4c84012014-04-28 19:51:102882bool WebContentsImpl::HasAccessedInitialDocument() {
2883 return has_accessed_initial_document_;
2884}
2885
[email protected]96d185d2009-04-24 03:28:542886// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592887// loading, or done loading.
2888void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2889 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092890 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262891 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542892 if (is_loading == is_loading_)
2893 return;
2894
2895 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262896 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2897 base::string16());
[email protected]96d185d2009-04-24 03:28:542898 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562899 upload_size_ = 0;
2900 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542901 }
2902
[email protected]fa944cb82013-11-15 17:51:212903 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542904
2905 is_loading_ = is_loading;
2906 waiting_for_response_ = is_loading;
2907
[email protected]6ebdc9b2010-09-27 16:55:572908 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092909 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212910 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542911
[email protected]eab61442013-11-14 18:35:482912 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592913 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482914 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2915 "URL", url);
[email protected]91621872013-10-08 04:04:592916 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2917 DidStartLoading(render_view_host));
2918 } else {
[email protected]eab61442013-11-14 18:35:482919 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2920 "URL", url);
[email protected]91621872013-10-08 04:04:592921 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2922 DidStopLoading(render_view_host));
2923 }
[email protected]66798902013-10-01 18:40:162924
2925 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212926 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2927 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542928 if (details)
[email protected]8ff00d72012-10-23 19:12:212929 det = Details<LoadNotificationDetails>(details);
2930 NotificationService::current()->Notify(
2931 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542932}
2933
[email protected]959be4c2014-04-08 15:01:332934void WebContentsImpl::SelectRange(const gfx::Point& start,
2935 const gfx::Point& end) {
2936 RenderFrameHost* focused_frame = GetFocusedFrame();
2937 if (!focused_frame)
2938 return;
2939
2940 focused_frame->Send(
2941 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
2942}
2943
[email protected]b172aee2012-04-10 17:05:262944void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462945 // If we are creating a RVH for a restored controller, then we need to make
2946 // sure the RenderView starts with a next_page_id_ larger than the number
2947 // of restored entries. This must be called before the RenderView starts
2948 // navigating (to avoid a race between the browser updating max_page_id and
2949 // the renderer updating next_page_id_). Because of this, we only call this
2950 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562951 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582952 if (max_restored_page_id >
2953 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2954 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2955 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322956}
2957
[email protected]b172aee2012-04-10 17:05:262958bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262959 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322960 // For file URLs without a title, use the pathname instead. In the case of a
2961 // synthesized title, we don't want the update to count toward the "one set
2962 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262963 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322964 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512965 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242966 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322967 explicit_set = false; // Don't count synthetic titles toward the set limit.
2968 } else {
[email protected]8af69c6c2014-03-03 19:05:312969 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322970 explicit_set = true;
2971 }
2972
[email protected]987fc3a2011-05-26 14:18:092973 // If a page is created via window.open and never navigated,
2974 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552975 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092976 if (entry) {
[email protected]36fc0392011-12-25 03:59:512977 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092978 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322979
[email protected]36fc0392011-12-25 03:59:512980 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092981 } else {
2982 if (page_title_when_no_navigation_entry_ == final_title)
2983 return false; // Nothing changed, don't bother.
2984
2985 page_title_when_no_navigation_entry_ = final_title;
2986 }
[email protected]420ae012009-04-24 05:16:322987
[email protected]420ae012009-04-24 05:16:322988 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232989 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322990
[email protected]66798902013-10-01 18:40:162991 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532992 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162993
2994 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212995 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462996 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212997 NotificationService::current()->Notify(
2998 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2999 Source<WebContents>(this),
3000 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043001
[email protected]420ae012009-04-24 05:16:323002 return true;
3003}
3004
[email protected]7b712ee22013-10-03 00:57:283005void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
3006 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323007 // After sending out a swap notification, we need to send a disconnect
3008 // notification so that clients that pick up a pointer to |this| can NULL the
3009 // pointer. See Bug 1230284.
3010 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113011 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283012 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113013
3014 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283015 std::pair<RenderViewHost*, RenderViewHost*> details =
3016 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213017 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283018 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213019 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283020 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393021
3022 // Ensure that the associated embedder gets cleared after a RenderViewHost
3023 // gets swapped, so we don't reuse the same embedder next time a
3024 // RenderViewHost is attached to this WebContents.
3025 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323026}
3027
[email protected]da7a7182013-09-06 08:11:113028// TODO(avi): Remove this entire function because this notification is already
3029// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263030void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323031 if (!notify_disconnection_)
3032 return;
3033
3034 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213035 NotificationService::current()->Notify(
3036 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3037 Source<WebContents>(this),
3038 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323039}
3040
[email protected]cbb1ef592013-06-05 19:49:463041void WebContentsImpl::NotifyNavigationEntryCommitted(
3042 const LoadCommittedDetails& load_details) {
3043 FOR_EACH_OBSERVER(
3044 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3045}
3046
[email protected]f114fa42013-12-06 17:06:443047bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3048 const IPC::Message& message) {
3049 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313050}
3051
[email protected]c31a84802014-04-03 15:55:493052const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3053 return GetLastCommittedURL();
3054}
3055
[email protected]b849847b2013-12-10 21:57:583056void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3057 // Note this is only for subframes, the notification for the main frame
3058 // happens in RenderViewCreated.
3059 FOR_EACH_OBSERVER(WebContentsObserver,
3060 observers_,
3061 RenderFrameCreated(render_frame_host));
3062}
3063
3064void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193065 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583066 FOR_EACH_OBSERVER(WebContentsObserver,
3067 observers_,
3068 RenderFrameDeleted(render_frame_host));
3069}
3070
[email protected]a09d53ce2014-01-31 00:46:423071void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303072 if (delegate_)
3073 delegate_->WorkerCrashed(this);
3074}
3075
[email protected]a09d53ce2014-01-31 00:46:423076void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3077 const ContextMenuParams& params) {
3078 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:403079 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:423080 return;
3081
3082 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
3083}
3084
[email protected]87de04b02014-04-08 22:14:493085void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013086 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493087 const base::string16& message,
3088 const base::string16& default_prompt,
3089 const GURL& frame_url,
3090 JavaScriptMessageType javascript_message_type,
3091 IPC::Message* reply_msg) {
3092 // Suppress JavaScript dialogs when requested. Also suppress messages when
3093 // showing an interstitial as it's shown over the previous page and we don't
3094 // want the hidden page's dialogs to interfere with the interstitial.
3095 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013096 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493097 IsSwappedOut() ||
3098 ShowingInterstitialPage() ||
3099 !delegate_ ||
3100 delegate_->ShouldSuppressDialogs() ||
3101 !delegate_->GetJavaScriptDialogManager();
3102
3103 if (!suppress_this_message) {
3104 std::string accept_lang = GetContentClient()->browser()->
3105 GetAcceptLangs(GetBrowserContext());
3106 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3107 dialog_manager_->RunJavaScriptDialog(
3108 this,
3109 frame_url.GetOrigin(),
3110 accept_lang,
3111 javascript_message_type,
3112 message,
3113 default_prompt,
3114 base::Bind(&WebContentsImpl::OnDialogClosed,
3115 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013116 render_frame_host->GetProcess()->GetID(),
3117 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493118 reply_msg,
3119 false),
3120 &suppress_this_message);
3121 }
3122
3123 if (suppress_this_message) {
3124 // If we are suppressing messages, just reply as if the user immediately
3125 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013126 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3127 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283128 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493129 }
3130
3131 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3132 // http://crbug.com/288961 ). The only safe thing to do here is return.
3133}
3134
3135void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013136 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493137 const base::string16& message,
3138 bool is_reload,
3139 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013140 RenderFrameHostImpl* rfhi =
3141 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493142 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013143 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493144 if (delegate_)
3145 delegate_->WillRunBeforeUnloadConfirm();
3146
3147 bool suppress_this_message =
3148 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3149 !delegate_ ||
3150 delegate_->ShouldSuppressDialogs() ||
3151 !delegate_->GetJavaScriptDialogManager();
3152 if (suppress_this_message) {
3153 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3154 return;
3155 }
3156
3157 is_showing_before_unload_dialog_ = true;
3158 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3159 dialog_manager_->RunBeforeUnloadDialog(
3160 this, message, is_reload,
3161 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013162 render_frame_host->GetProcess()->GetID(),
3163 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283164 false));
[email protected]87de04b02014-04-08 22:14:493165}
3166
[email protected]a86c0e962013-12-17 17:10:393167WebContents* WebContentsImpl::GetAsWebContents() {
3168 return this;
3169}
3170
[email protected]7912e822014-04-16 02:37:033171bool WebContentsImpl::IsNeverVisible() {
3172 if (!delegate_)
3173 return false;
3174 return delegate_->IsNeverVisible(this);
3175}
3176
[email protected]5a3bdf52012-05-24 15:12:573177RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3178 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323179}
3180
[email protected]8ff00d72012-10-23 19:12:213181RendererPreferences WebContentsImpl::GetRendererPrefs(
3182 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463183 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513184}
3185
[email protected]b172aee2012-04-10 17:05:263186gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173187 if (delegate_)
3188 return delegate_->GetRootWindowResizerRect();
3189 return gfx::Rect();
3190}
3191
[email protected]7a846df2012-09-20 19:17:393192void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273193 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393194 browser_plugin_embedder_.reset();
3195}
3196
[email protected]b172aee2012-04-10 17:05:263197void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443198 // Don't send notifications if we are just creating a swapped-out RVH for
3199 // the opener chain. These won't be used for view-source or WebUI, so it's
3200 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243201 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443202 return;
3203
[email protected]86f98a22013-03-20 14:35:003204 if (delegate_)
3205 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083206
[email protected]8ff00d72012-10-23 19:12:213207 NotificationService::current()->Notify(
3208 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3209 Source<WebContents>(this),
3210 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323211
3212 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353213 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213214 if (GetRenderManager()->pending_web_ui())
3215 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323216
[email protected]6286a372013-10-09 04:03:273217 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333218 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323219 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183220 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583221 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323222 }
[email protected]0666aef2009-05-13 19:48:083223
[email protected]60780f412013-02-25 16:34:103224 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263225
3226 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253227 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583228
3229 // We tell the observers now instead of when the main RenderFrameHostImpl is
3230 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3231 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363232 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583233 FOR_EACH_OBSERVER(
3234 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323235}
3236
[email protected]b172aee2012-04-10 17:05:263237void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523238 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323239 // Don't notify the world, since this came from a renderer in the
3240 // background.
3241 return;
3242 }
3243
[email protected]da7a7182013-09-06 08:11:113244 notify_disconnection_ = true;
3245 // TODO(avi): Remove. http://crbug.com/170921
3246 NotificationService::current()->Notify(
3247 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3248 Source<WebContents>(this),
3249 NotificationService::NoDetails());
3250
[email protected]be1f56ab2011-12-22 06:55:313251 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233252 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303253
3254 // Restore the focus to the tab (otherwise the focus will be on the top
3255 // window).
[email protected]484ae5912010-09-29 19:16:143256 if (was_crashed && !FocusLocationBarByDefault() &&
3257 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063258 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143259 }
[email protected]32ded2212011-11-10 18:51:433260
[email protected]d8c660432011-12-22 20:51:253261 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323262}
3263
[email protected]ec6a7eb2013-04-22 17:34:223264void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3265 base::TerminationStatus status,
3266 int error_code) {
[email protected]151a63d2011-12-20 22:32:523267 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323268 // The pending page's RenderViewHost is gone.
3269 return;
3270 }
3271
[email protected]2fcdcc32014-03-05 02:14:073272 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3273 // renderer may not have made a clean exit.
3274 if (IsFullscreenForCurrentTab())
3275 ToggleFullscreenMode(false);
3276
[email protected]698191dc2014-02-25 01:06:133277 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3278 if (dialog_manager_)
3279 dialog_manager_->CancelActiveAndPendingDialogs(this);
3280
[email protected]e3b10d12014-03-28 16:06:093281 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323282 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233283 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453284
3285#if defined(OS_ANDROID)
3286 if (GetRenderViewHostImpl()->media_player_manager())
3287 GetRenderViewHostImpl()->media_player_manager()->DestroyAllMediaPlayers();
3288#endif
[email protected]420ae012009-04-24 05:16:323289
[email protected]d8c660432011-12-22 20:51:253290 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273291 observers_,
[email protected]58d5cfe2013-07-10 02:40:523292 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323293}
3294
[email protected]b172aee2012-04-10 17:05:263295void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253296 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063297}
3298
[email protected]b172aee2012-04-10 17:05:263299void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3300 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043301 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153302 // Ensure that this state update comes from either the active RVH or one of
3303 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413304 // TODO(nasko): This should go through RenderFrameHost.
3305 // TODO(creis): We can't update state for cross-process subframes until we
3306 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3307 if (rvh != GetRenderViewHost() &&
3308 !GetRenderManager()->IsRVHOnSwappedOutList(
3309 static_cast<RenderViewHostImpl*>(rvh)))
3310 return;
[email protected]420ae012009-04-24 05:16:323311
3312 // We must be prepared to handle state updates for any page, these occur
3313 // when the user is scrolling and entering form data, as well as when we're
3314 // leaving a page, in which case our state may have already been moved to
3315 // the next page. The navigation controller will look up the appropriate
3316 // NavigationEntry and update it when it is notified via the delegate.
3317
3318 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583319 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323320 if (entry_index < 0)
3321 return;
[email protected]10f417c52011-12-28 21:04:233322 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323323
[email protected]691aa2f2013-05-28 22:52:043324 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323325 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043326 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323327 controller_.NotifyEntryChanged(entry, entry_index);
3328}
3329
[email protected]b172aee2012-04-10 17:05:263330void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513331 if (delegate_)
3332 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323333}
3334
[email protected]b172aee2012-04-10 17:05:263335void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103336#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293337 // The UI may be in an event-tracking loop, such as between the
3338 // mouse-down and mouse-up in text selection or a button click.
3339 // Defer the close until after tracking is complete, so that we
3340 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293341 // TODO(shess): This could get more fine-grained. For instance,
3342 // closing a tab in another window while selecting text in the
3343 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103344 if (view_->IsEventTracking()) {
3345 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293346 return;
3347 }
[email protected]60780f412013-02-25 16:34:103348#endif
[email protected]07707302009-11-06 00:50:293349
[email protected]420ae012009-04-24 05:16:323350 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523351 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513352 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323353}
3354
[email protected]66bbadaf2014-03-28 16:25:543355void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573356 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3357 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573358}
3359
[email protected]b172aee2012-04-10 17:05:263360void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513361 if (delegate_ && delegate_->IsPopupOrPanel(this))
3362 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323363}
3364
[email protected]e3b10d12014-03-28 16:06:093365void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3366 bool to_different_document) {
3367 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3368 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323369}
3370
[email protected]723971b2014-02-12 11:08:253371void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323372 scoped_ptr<LoadNotificationDetails> details;
3373
[email protected]9595fd82013-04-19 21:28:493374 // Use the last committed entry rather than the active one, in case a
3375 // pending entry has been created.
3376 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203377 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493378
[email protected]420ae012009-04-24 05:16:323379 // An entry may not exist for a stop when loading an initial blank page or
3380 // if an iframe injected by script into a blank page finishes loading.
3381 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203382 base::TimeDelta elapsed =
3383 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323384
3385 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513386 entry->GetVirtualURL(),
3387 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323388 elapsed,
3389 &controller_,
3390 controller_.GetCurrentEntryIndex()));
3391 }
3392
[email protected]e3b10d12014-03-28 16:06:093393 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3394 details.get());
[email protected]420ae012009-04-24 05:16:323395}
3396
[email protected]b172aee2012-04-10 17:05:263397void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163398 controller_.DiscardNonCommittedEntries();
3399
3400 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213401 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163402}
3403
[email protected]b172aee2012-04-10 17:05:263404void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513405 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133406 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403407}
3408
[email protected]59167c22013-06-03 18:07:323409void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103410 has_accessed_initial_document_ = true;
3411
[email protected]d1371bf8e2014-04-19 03:26:243412 // We may have left a failed browser-initiated navigation in the address bar
3413 // to let the user edit it and try again. Clear it now that content might
3414 // show up underneath it.
3415 if (!IsLoading() && controller_.GetPendingEntry())
3416 controller_.DiscardPendingEntry();
3417
[email protected]59167c22013-06-03 18:07:323418 // Update the URL display.
3419 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3420}
3421
[email protected]3f19f1a2014-05-02 05:23:273422void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3423 if (opener_) {
3424 // Clear our opener so that future cross-process navigations don't have an
3425 // opener assigned.
3426 RemoveDestructionObserver(opener_);
3427 opener_ = NULL;
3428 }
3429
3430 // Notify all swapped out RenderViewHosts for this tab. This is important
3431 // in case we go back to them, or if another window in those processes tries
3432 // to access window.opener.
3433 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3434}
3435
[email protected]39f2f9252014-05-03 00:54:013436void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293437 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093438 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293439 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093440
3441 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213442 NotificationService::current()->Notify(
3443 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3444 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293445 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083446}
3447
[email protected]ef3adfc2014-05-11 00:04:543448void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3449 int32 page_id,
3450 const base::string16& title,
3451 base::i18n::TextDirection title_direction) {
3452 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3453
3454 // If we have a title, that's a pretty good indication that we've started
3455 // getting useful data.
3456 SetNotWaitingForResponse();
3457
3458 // Try to find the navigation entry, which might not be the current one.
3459 // For example, it might be from a pending RVH for the pending entry.
3460 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3461 rvh->GetSiteInstance(), page_id);
3462
3463 // We can handle title updates when we don't have an entry in
3464 // UpdateTitleForEntry, but only if the update is from the current RVH.
3465 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3466 if (!entry && rvh != GetRenderViewHost())
3467 return;
3468
3469 // TODO(evan): make use of title_direction.
3470 // http://code.google.com/p/chromium/issues/detail?id=27094
3471 if (!UpdateTitleForEntry(entry, title))
3472 return;
3473
3474 // Broadcast notifications when the UI should be updated.
3475 if (entry == controller_.GetEntryAtOffset(0))
3476 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3477}
3478
3479void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3480 const std::string& encoding) {
3481 SetEncoding(encoding);
3482}
3483
[email protected]39f2f9252014-05-03 00:54:013484void WebContentsImpl::DocumentAvailableInMainFrame(
3485 RenderViewHost* render_view_host) {
3486 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3487 DocumentAvailableInMainFrame());
3488}
[email protected]e1c3a552012-05-04 20:51:323489void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3490 // Tell the active RenderViewHost to run unload handlers and close, as long
3491 // as the request came from a RenderViewHost in the same BrowsingInstance.
3492 // In most cases, we receive this from a swapped out RenderViewHost.
3493 // It is possible to receive it from one that has just been swapped in,
3494 // in which case we might as well deliver the message anyway.
3495 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3496 GetRenderViewHost()->ClosePage();
3497}
3498
[email protected]f546640b2012-05-15 00:03:493499void WebContentsImpl::RouteMessageEvent(
3500 RenderViewHost* rvh,
3501 const ViewMsg_PostMessage_Params& params) {
3502 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363503 // came from a RenderViewHost in the same BrowsingInstance or if this
3504 // WebContents is dedicated to a browser plugin guest.
3505 // Note: This check means that an embedder could theoretically receive a
3506 // postMessage from anyone (not just its own guests). However, this is
3507 // probably not a risk for apps since other pages won't have references
3508 // to App windows.
3509 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3510 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493511 return;
3512
3513 ViewMsg_PostMessage_Params new_params(params);
3514
[email protected]0bc7f3542013-10-21 15:05:533515 if (!params.message_port_ids.empty()) {
3516 MessagePortMessageFilter* message_port_message_filter =
3517 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3518 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093519 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3520 params.message_port_ids,
3521 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533522 }
3523
[email protected]f546640b2012-05-15 00:03:493524 // If there is a source_routing_id, translate it to the routing ID for
3525 // the equivalent swapped out RVH in the target process. If we need
3526 // to create a swapped out RVH for the source tab, we create its opener
3527 // chain as well, since those will also be accessible to the target page.
3528 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3529 // Try to look up the WebContents for the source page.
3530 WebContentsImpl* source_contents = NULL;
3531 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3532 rvh->GetProcess()->GetID(), params.source_routing_id);
3533 if (source_rvh) {
3534 source_contents = static_cast<WebContentsImpl*>(
3535 source_rvh->GetDelegate()->GetAsWebContents());
3536 }
3537
3538 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363539 if (GetBrowserPluginGuest()) {
3540 // We create a swapped out RenderView for the embedder in the guest's
3541 // render process but we intentionally do not expose the embedder's
3542 // opener chain to it.
3543 new_params.source_routing_id =
3544 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3545 } else {
3546 new_params.source_routing_id =
3547 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3548 }
[email protected]f546640b2012-05-15 00:03:493549 } else {
3550 // We couldn't find it, so don't pass a source frame.
3551 new_params.source_routing_id = MSG_ROUTING_NONE;
3552 }
3553 }
3554
3555 // In most cases, we receive this from a swapped out RenderViewHost.
3556 // It is possible to receive it from one that has just been swapped in,
3557 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183558 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493559}
3560
[email protected]a796f202012-05-30 14:14:253561bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263562 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253563 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263564 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253565 if (!delegate_)
3566 return false;
3567 return delegate_->AddMessageToConsole(this, level, message, line_no,
3568 source_id);
3569}
3570
[email protected]b172aee2012-04-10 17:05:263571WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273572 // We want to base the page config off of the actual URL, rather than the
3573 // virtual URL.
3574 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3575 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003576 GURL url = controller_.GetActiveEntry()
3577 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153578
[email protected]fa944cb82013-11-15 17:51:213579 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323580}
3581
[email protected]0eba810b2012-10-18 03:19:363582int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213583 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413584 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3585 true, true);
[email protected]0eba810b2012-10-18 03:19:363586}
3587
[email protected]b172aee2012-04-10 17:05:263588void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273589 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253590 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223591
[email protected]ea114722012-03-12 01:11:253592 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173593 if (rdh) // NULL in unittests.
3594 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253595}
3596
[email protected]b172aee2012-04-10 17:05:263597void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443598 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253599 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443600}
3601
[email protected]b172aee2012-04-10 17:05:263602void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563603 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263604 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153605 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523606 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153607 return;
3608
[email protected]9f76c1e2012-03-05 15:15:583609 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3610
[email protected]e5fc1632011-08-08 07:51:533611 // Ignore renderer unresponsive event if debugger is attached to the tab
3612 // since the event may be a result of the renderer sitting on a breakpoint.
3613 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363614 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533615 return;
3616
[email protected]2e9d79f2013-08-16 05:45:563617 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323618 // Hang occurred while firing the beforeunload/unload handler.
3619 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583620 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323621
[email protected]fa944cb82013-11-15 17:51:213622 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323623 return;
3624
3625 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563626 // nothing we can do to recover. If the hang is in the beforeunload handler,
3627 // pretend the beforeunload listeners have all fired and allow the delegate
3628 // to continue closing; the user will not have the option of cancelling the
3629 // close. Otherwise, pretend the unload listeners have all fired and close
3630 // the tab.
3631 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463632 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563633 delegate_->BeforeUnloadFired(this, true, &close);
3634 }
3635 if (close)
3636 Close(rvh);
[email protected]420ae012009-04-24 05:16:323637 return;
3638 }
3639
[email protected]9f76c1e2012-03-05 15:15:583640 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473641 return;
3642
[email protected]6934a702011-12-20 00:04:513643 if (delegate_)
3644 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323645}
3646
[email protected]b172aee2012-04-10 17:05:263647void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513648 if (delegate_)
3649 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323650}
3651
[email protected]b172aee2012-04-10 17:05:263652void WebContentsImpl::LoadStateChanged(
3653 const GURL& url,
3654 const net::LoadStateWithParam& load_state,
3655 uint64 upload_position,
3656 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323657 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563658 upload_position_ = upload_position;
3659 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503660 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213661 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303662 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213663 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323664 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463665 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213666 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463667 }
[email protected]420ae012009-04-24 05:16:323668}
3669
[email protected]b172aee2012-04-10 17:05:263670void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553671 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323672 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123673 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3674 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513675 if (delegate_)
3676 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093677 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323678}
3679
[email protected]58d5cfe2013-07-10 02:40:523680void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543681 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233682 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223683 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543684}
3685
[email protected]b172aee2012-04-10 17:05:263686void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103687 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213688 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263689 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3690 // here during container initialization and normal window size will be set
3691 // later. In case of tab duplication this resizing to 0x0 prevents setting
3692 // normal size later so just ignore it.
3693 if (!size.IsEmpty())
3694 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323695}
3696
[email protected]af905902013-10-01 21:38:513697void WebContentsImpl::CancelModalDialogsForRenderManager() {
3698 // We need to cancel modal dialogs when doing a process swap, since the load
3699 // deferrer would prevent us from swapping out.
3700 if (dialog_manager_)
3701 dialog_manager_->CancelActiveAndPendingDialogs(this);
3702}
3703
[email protected]7b712ee22013-10-03 00:57:283704void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3705 RenderViewHost* new_host) {
3706 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083707
3708 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003709 if (delegate_)
3710 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393711
[email protected]7b712ee22013-10-03 00:57:283712 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543713}
3714
[email protected]14392a52012-05-02 20:28:443715int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3716 SiteInstance* instance) {
3717 if (!opener_)
3718 return MSG_ROUTING_NONE;
3719
3720 // Recursively create RenderViews for anything else in the opener chain.
3721 return opener_->CreateOpenerRenderViews(instance);
3722}
3723
3724int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3725 int opener_route_id = MSG_ROUTING_NONE;
3726
3727 // If this tab has an opener, ensure it has a RenderView in the given
3728 // SiteInstance as well.
3729 if (opener_)
3730 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3731
[email protected]45a22ad2013-02-21 03:25:003732 // If any of the renderers (current, pending, or swapped out) for this
3733 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213734 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3735 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373736
[email protected]fa944cb82013-11-15 17:51:213737 if (GetRenderManager()->pending_render_view_host() &&
3738 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3739 instance)
3740 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003741
[email protected]fa944cb82013-11-15 17:51:213742 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373743 instance);
3744 if (rvh)
3745 return rvh->GetRoutingID();
3746
[email protected]14392a52012-05-02 20:28:443747 // Create a swapped out RenderView in the given SiteInstance if none exists,
3748 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413749 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3750 true, true);
[email protected]14392a52012-05-02 20:28:443751}
3752
[email protected]b172aee2012-04-10 17:05:263753NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193754 return GetController();
[email protected]3a3d47472010-07-15 21:03:543755}
3756
[email protected]b172aee2012-04-10 17:05:263757WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563758 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323759}
3760
[email protected]10f417c52011-12-28 21:04:233761NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263762 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323763 return controller_.GetLastCommittedEntry();
3764}
3765
[email protected]b172aee2012-04-10 17:05:263766bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163767 RenderViewHost* render_view_host,
3768 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043769 int proxy_routing_id,
[email protected]bffc8302014-01-23 20:52:163770 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033771 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443772 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483773 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163774 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3775 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3776 // case this because RWH is still a base class of RenderViewHost, and child
3777 // frame RWHVs are unique in that they do not have their own WebContents.
3778 if (frame_connector) {
3779 RenderWidgetHostViewChildFrame* rwh_view_child =
3780 new RenderWidgetHostViewChildFrame(render_view_host);
3781 frame_connector->set_view(rwh_view_child);
3782 rwh_view = rwh_view_child;
3783 } else {
3784 rwh_view = view_->CreateViewForWidget(render_view_host);
3785 }
[email protected]1a98a932009-11-17 00:12:523786
[email protected]420ae012009-04-24 05:16:323787 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443788 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213789 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323790
[email protected]74ce1ad2011-12-16 21:51:463791 // Make sure we use the correct starting page_id in the new RenderView.
3792 UpdateMaxPageIDIfNecessary(render_view_host);
3793 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583794 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463795
[email protected]9f76c1e2012-03-05 15:15:583796 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263797 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493798 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043799 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:493800 max_page_id,
3801 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523802 return false;
[email protected]14392a52012-05-02 20:28:443803 }
[email protected]a4127722011-04-27 23:13:523804
[email protected]a220b5932013-09-21 03:47:443805#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503806 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3807 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443808 if (rwh_view) {
3809 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3810 render_widget_host->WasResized();
3811 }
[email protected]f8233cc2011-05-31 20:24:503812#endif
3813
[email protected]420ae012009-04-24 05:16:323814 return true;
3815}
3816
[email protected]7d244f12013-08-22 21:41:513817#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453818
[email protected]155c7f22013-12-09 17:07:183819base::android::ScopedJavaLocalRef<jobject>
3820WebContentsImpl::GetJavaWebContents() {
3821 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3822
3823 WebContentsAndroid* web_contents_android =
3824 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3825 if (!web_contents_android) {
3826 web_contents_android = new WebContentsAndroid(this);
3827 SetUserData(kWebContentsAndroidKey, web_contents_android);
3828 }
3829 return web_contents_android->GetJavaObject();
3830}
3831
[email protected]7d244f12013-08-22 21:41:513832bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3833 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163834 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:043835 MSG_ROUTING_NONE,
[email protected]bffc8302014-01-23 20:52:163836 NULL);
[email protected]7d244f12013-08-22 21:41:513837}
[email protected]fc2b46b2014-05-03 16:33:453838
3839#elif defined(OS_MACOSX)
3840
3841void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
3842 view_->SetAllowOverlappingViews(overlapping);
3843}
3844
3845bool WebContentsImpl::GetAllowOverlappingViews() {
3846 return view_->GetAllowOverlappingViews();
3847}
3848
3849void WebContentsImpl::SetOverlayView(WebContents* overlay,
3850 const gfx::Point& offset) {
3851 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
3852 offset);
3853}
3854
3855void WebContentsImpl::RemoveOverlayView() {
3856 view_->RemoveOverlayView();
3857}
3858
[email protected]7d244f12013-08-22 21:41:513859#endif
3860
[email protected]6fba26d2014-04-29 09:38:283861void WebContentsImpl::OnDialogClosed(int render_process_id,
3862 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:263863 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493864 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263865 bool success,
[email protected]fcf75d42013-12-03 20:11:263866 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:283867 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3868 render_frame_id);
[email protected]87de04b02014-04-08 22:14:493869 last_dialog_suppressed_ = dialog_was_suppressed;
3870
[email protected]beb440c2009-11-06 04:08:543871 if (is_showing_before_unload_dialog_ && !success) {
3872 // If a beforeunload dialog is canceled, we need to stop the throbber from
3873 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:283874 if (rfh)
3875 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353876 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103877
[email protected]6d65a462013-06-21 21:29:123878 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3879 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543880 }
[email protected]87de04b02014-04-08 22:14:493881
[email protected]beb440c2009-11-06 04:08:543882 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:283883 if (rfh) {
3884 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3885 dialog_was_suppressed);
3886 } else {
3887 // Don't leak the sync IPC reply if the RFH or process is gone.
3888 delete reply_msg;
3889 }
[email protected]beb440c2009-11-06 04:08:543890}
3891
[email protected]b172aee2012-04-10 17:05:263892void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:543893 if (encoding == last_reported_encoding_)
3894 return;
3895 last_reported_encoding_ = encoding;
3896
3897 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123898 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103899}
[email protected]f45d2a72010-03-08 23:28:353900
[email protected]b172aee2012-04-10 17:05:263901void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:483902 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443903 // Can be NULL during tests.
3904 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:453905 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:363906}
[email protected]9f76c1e2012-03-05 15:15:583907
[email protected]1ac10dca2013-08-20 20:47:043908bool WebContentsImpl::IsHidden() {
3909 return capturer_count_ == 0 && !should_normally_be_visible_;
3910}
3911
[email protected]b0936d22013-11-28 06:47:363912RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213913 return frame_tree_.root()->render_manager();
3914}
3915
[email protected]b172aee2012-04-10 17:05:263916RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583917 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3918}
[email protected]7900bfdb2012-05-24 19:31:243919
[email protected]f8497342013-02-05 22:15:023920BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393921 return browser_plugin_guest_.get();
3922}
3923
[email protected]738f57a2013-06-29 21:06:543924void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3925 CHECK(!browser_plugin_guest_);
3926 browser_plugin_guest_.reset(guest);
3927}
3928
[email protected]f8497342013-02-05 22:15:023929BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393930 return browser_plugin_embedder_.get();
3931}
[email protected]8ff00d72012-10-23 19:12:213932
[email protected]d9030b82013-07-19 08:26:063933void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:193934 RenderFrameHost* render_frame_host) {
3935 STLDeleteValues(&power_save_blockers_[render_frame_host]);
3936 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:063937}
3938
3939void WebContentsImpl::ClearAllPowerSaveBlockers() {
3940 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3941 i != power_save_blockers_.end(); ++i)
3942 STLDeleteValues(&power_save_blockers_[i->first]);
3943 power_save_blockers_.clear();
3944}
3945
[email protected]fc2b46b2014-05-03 16:33:453946gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:213947 gfx::Size size;
3948 if (delegate_)
3949 size = delegate_->GetSizeForNewRenderView(this);
3950 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:453951 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:213952 return size;
3953}
3954
[email protected]9b159a52013-10-03 17:24:553955void WebContentsImpl::OnFrameRemoved(
3956 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583957 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553958 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583959 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553960}
3961
[email protected]222f5822014-02-05 23:40:493962void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3963 if (!delegate_)
3964 return;
3965 const gfx::Size new_size = GetPreferredSize();
3966 if (new_size != old_size)
3967 delegate_->UpdatePreferredSize(this, new_size);
3968}
3969
[email protected]8ff00d72012-10-23 19:12:213970} // namespace content