blob: d86c397522426ad882ce3bef2518e456c3f292ff [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]8eb04562013-03-06 03:41:1423#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
[email protected]b9535422012-02-09 01:47:5924#include "content/browser/child_process_security_policy_impl.h"
[email protected]70019152012-12-19 11:44:1925#include "content/browser/devtools/devtools_manager_impl.h"
[email protected]5f2aa722013-08-07 16:59:4126#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0427#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4628#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1229#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1630#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1631#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4032#include "content/browser/frame_host/interstitial_page_impl.h"
33#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0134#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1835#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1636#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[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]b3c41c0b2012-03-06 15:48:3243#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5044#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3345#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1146#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5847#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0348#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5649#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1450#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4251#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4452#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0253#include "content/common/image_messages.h"
[email protected]35be7ec2012-02-12 20:42:5154#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0255#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5756#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5857#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1158#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2059#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4460#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3661#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1762#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1463#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4664#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1565#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0066#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2767#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0068#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3769#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1470#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3271#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3472#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3873#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4274#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2575#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1076#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2177#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4878#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5479#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4980#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2081#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0382#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5783#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1684#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2985#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5386#include "net/http/http_cache.h"
87#include "net/http/http_transaction_factory.h"
88#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3489#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5690#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0191#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4192#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5293#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1894#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3195
[email protected]583418cc2013-01-17 14:01:1096#if defined(OS_ANDROID)
97#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3298#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]155c7f22013-12-09 17:07:1899#include "content/browser/web_contents/web_contents_android.h"
[email protected]a794f3a2013-10-30 17:00:32100#include "content/common/java_bridge_messages.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]795c28972012-12-06 06:13:39172static int StartDownload(content::RenderViewHost* rvh,
173 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;
177 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
178 ++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
208void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
209 IPC::Message* message_copy = new IPC::Message(*message);
210 message_copy->set_routing_id(rfh->GetRoutingID());
211 rfh->Send(message_copy);
212}
213
[email protected]420ae012009-04-24 05:16:32214} // namespace
215
[email protected]54944cde2012-12-09 09:24:59216WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15217 return WebContentsImpl::CreateWithOpener(
218 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19219}
220
221WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59222 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30223 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59224 WebContentsImpl* new_contents = new WebContentsImpl(
225 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30226
227 for (SessionStorageNamespaceMap::const_iterator it =
228 session_storage_namespace_map.begin();
229 it != session_storage_namespace_map.end();
230 ++it) {
231 new_contents->GetController()
232 .SetSessionStorageNamespace(it->first, it->second.get());
233 }
234
[email protected]54944cde2012-12-09 09:24:59235 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19236 return new_contents;
[email protected]a81343d232011-12-27 07:39:20237}
[email protected]746d3052012-05-22 15:15:47238
[email protected]e4abd3b42013-11-12 18:28:47239void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46240 g_created_callbacks.Get().push_back(callback);
241}
242
[email protected]e4abd3b42013-11-12 18:28:47243void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46244 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
245 if (g_created_callbacks.Get().at(i).Equals(callback)) {
246 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
247 return;
248 }
249 }
250}
251
[email protected]299d7f12012-05-23 05:31:15252WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47253 return rvh->GetDelegate()->GetAsWebContents();
254}
255
[email protected]a86c0e962013-12-17 17:10:39256WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
257 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
258 if (!rfh_impl)
259 return NULL;
260 return rfh_impl->delegate()->GetAsWebContents();
261}
262
[email protected]7fff43e2013-05-21 20:21:10263// WebContentsImpl::DestructionObserver ----------------------------------------
264
265class WebContentsImpl::DestructionObserver : public WebContentsObserver {
266 public:
267 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
268 : WebContentsObserver(watched_contents),
269 owner_(owner) {
270 }
271
272 // WebContentsObserver:
273 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
274 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
275 }
276
277 private:
278 WebContentsImpl* owner_;
279
280 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
281};
282
[email protected]b172aee2012-04-10 17:05:26283// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32284
[email protected]b172aee2012-04-10 17:05:26285WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21286 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19287 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42288 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22289 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57290 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44291 opener_(opener),
[email protected]2ceee8f2014-01-14 18:02:08292#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41293 accessible_parent_(NULL),
294#endif
[email protected]6ea6bdf2013-12-06 13:35:01295 frame_tree_(new NavigatorImpl(&controller_, this),
296 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34297 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23298 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
299 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34300 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26301 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56302 upload_size_(0),
303 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47304 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55305 capturer_count_(0),
306 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57307 is_being_destroyed_(false),
308 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15309 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01310 is_showing_before_unload_dialog_(false),
[email protected]ebf40a72010-07-22 01:46:38311 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21312 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
313 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00314 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21315 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44316 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42317 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
318 is_subframe_(false) {
[email protected]cbb1ef592013-06-05 19:49:46319 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
320 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55321 frame_tree_.SetFrameRemoveListener(
322 base::Bind(&WebContentsImpl::OnFrameRemoved,
323 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35324}
initial.commit09911bf2008-07-26 23:55:29325
[email protected]b172aee2012-04-10 17:05:26326WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32327 is_being_destroyed_ = true;
328
[email protected]d9030b82013-07-19 08:26:06329 ClearAllPowerSaveBlockers();
330
[email protected]b24b68a2012-09-24 21:57:26331 for (std::set<RenderWidgetHostImpl*>::iterator iter =
332 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
333 (*iter)->DetachDelegate();
334 }
335 created_widgets_.clear();
336
[email protected]3ab9cb82011-06-03 18:02:07337 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15338 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11339 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07340
[email protected]da8543762012-03-20 08:52:20341 if (color_chooser_)
342 color_chooser_->End();
343
[email protected]420ae012009-04-24 05:16:32344 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32345
[email protected]ca13a442012-04-17 14:00:12346 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21347 NotificationService::current()->Notify(
348 NOTIFICATION_WEB_CONTENTS_DESTROYED,
349 Source<WebContents>(this),
350 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32351
[email protected]fa944cb82013-11-15 17:51:21352 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27353 if (pending_rvh) {
354 FOR_EACH_OBSERVER(WebContentsObserver,
355 observers_,
356 RenderViewDeleted(pending_rvh));
357 }
358
359 FOR_EACH_OBSERVER(WebContentsObserver,
360 observers_,
[email protected]fa944cb82013-11-15 17:51:21361 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27362
[email protected]2db9bd72012-04-13 20:20:56363 FOR_EACH_OBSERVER(WebContentsObserver,
364 observers_,
365 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08366
[email protected]6934a702011-12-20 00:04:51367 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10368
369 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
370 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42371}
372
[email protected]d1198fd2012-08-13 22:50:19373WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59374 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19375 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03376 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59377 WebContentsImpl* new_contents = new WebContentsImpl(
378 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19379
[email protected]54944cde2012-12-09 09:24:59380 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19381 return new_contents;
382}
383
[email protected]b371a5652013-02-20 11:25:51384// static
[email protected]8eb04562013-03-06 03:41:14385BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36386 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53387 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54388 int guest_instance_id,
389 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39390 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39391
392 // This makes |new_contents| act as a guest.
393 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54394 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19395 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11396
[email protected]3de10bb32013-01-08 21:57:33397 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33398 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11399
[email protected]216be772013-01-25 00:22:27400 // We are instantiating a WebContents for browser plugin. Set its subframe bit
401 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42402 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27403
[email protected]8eb04562013-03-06 03:41:14404 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39405}
406
[email protected]b0936d22013-11-28 06:47:36407RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21408 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28409}
410
[email protected]7bb761892012-07-20 09:32:47411bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
412 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44413 return OnMessageReceived(render_view_host, NULL, message);
414}
415
416bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
417 RenderFrameHost* render_frame_host,
418 const IPC::Message& message) {
419 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56420 if (GetWebUI() &&
421 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17422 return true;
[email protected]d2353452012-01-19 19:53:56423 }
[email protected]f82d57b52011-04-27 19:13:17424
[email protected]d8c660432011-12-22 20:51:25425 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
426 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10427 while ((observer = it.GetNext()) != NULL)
428 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53429 return true;
[email protected]403415a2011-01-10 18:57:53430
[email protected]c80725d52013-12-06 06:22:26431 // Message handlers should be aware of which RenderViewHost sent the
[email protected]f114fa42013-12-06 17:06:44432 // message, which is temporarily stored in render_view_message_source_.
433 render_view_message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18434 bool handled = true;
435 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26436 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44437 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
438 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]724159a2010-12-30 01:11:18439 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
440 OnDidLoadResourceFromMemoryCache)
441 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
442 OnDidDisplayInsecureContent)
443 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
444 OnDidRunInsecureContent)
445 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
446 OnDocumentLoadedInFrame)
447 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26448 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
449 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25450 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26451 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21452 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20453 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
454 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
455 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16456 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10457 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20458 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
459 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
460 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
461 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50462 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50463 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
464 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55465 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
466 OnBrowserPluginMessage(message))
467 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
468 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02469 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
470 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10471#if defined(OS_ANDROID)
472 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
473 OnFindMatchRectsReply)
474 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
475 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32476 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
477 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10478#endif
[email protected]d9030b82013-07-19 08:26:06479 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
[email protected]9f268072013-11-07 00:02:15480 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
481 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07482 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
483 OnShowValidationMessage)
484 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
485 OnHideValidationMessage)
486 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
487 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18488 IPC_MESSAGE_UNHANDLED(handled = false)
489 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44490 render_view_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18491
492 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39493 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18494 GetRenderProcessHost()->ReceivedBadMessage();
495 }
496
497 return handled;
498}
499
[email protected]b172aee2012-04-10 17:05:26500void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18501 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21502 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43503 if (delegate_)
504 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18505}
506
[email protected]d1198fd2012-08-13 22:50:19507NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56508 return controller_;
509}
510
[email protected]d1198fd2012-08-13 22:50:19511const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56512 return controller_;
513}
514
[email protected]8ff00d72012-10-23 19:12:21515BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55516 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30517}
518
[email protected]b172aee2012-04-10 17:05:26519const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24520 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32521 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51522 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31523}
524
[email protected]a093ce02013-07-22 20:53:14525const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24526 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32527 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24528 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
529}
530
531const GURL& WebContentsImpl::GetLastCommittedURL() const {
532 // We may not have a navigation entry yet.
533 NavigationEntry* entry = controller_.GetLastCommittedEntry();
534 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
535}
536
[email protected]8ff00d72012-10-23 19:12:21537WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31538 return delegate_;
539}
540
[email protected]8ff00d72012-10-23 19:12:21541void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31542 // TODO(cbentzel): remove this debugging code?
543 if (delegate == delegate_)
544 return;
545 if (delegate_)
546 delegate_->Detach(this);
547 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08548 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31549 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08550 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00551 if (view_)
552 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08553 }
[email protected]be1f56ab2011-12-22 06:55:31554}
555
[email protected]8ff00d72012-10-23 19:12:21556RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21557 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41558 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16559}
560
[email protected]60eca4eb2013-12-06 00:02:16561RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41562 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16563}
564
[email protected]a86c0e962013-12-17 17:10:39565void WebContentsImpl::ForEachFrame(
566 const base::Callback<void(RenderFrameHost*)>& on_frame) {
567 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
568}
569
570void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
571 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
572 delete message;
573}
574
[email protected]b172aee2012-04-10 17:05:26575RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21576 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31577}
578
[email protected]a04c9d02012-11-14 21:04:34579void WebContentsImpl::GetRenderViewHostAtPosition(
580 int x,
581 int y,
582 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
583 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
584 if (embedder)
585 embedder->GetRenderViewHostAtPosition(x, y, callback);
586 else
587 callback.Run(GetRenderViewHost(), x, y);
588}
589
[email protected]bfcfa692013-02-07 06:17:02590WebContents* WebContentsImpl::GetEmbedderWebContents() const {
591 BrowserPluginGuest* guest = GetBrowserPluginGuest();
592 if (guest)
593 return guest->embedder_web_contents();
594 return NULL;
595}
596
597int WebContentsImpl::GetEmbeddedInstanceID() const {
598 BrowserPluginGuest* guest = GetBrowserPluginGuest();
599 if (guest)
600 return guest->instance_id();
601 return 0;
602}
603
[email protected]6b618e62012-08-16 12:59:18604int WebContentsImpl::GetRoutingID() const {
605 if (!GetRenderViewHost())
606 return MSG_ROUTING_NONE;
607
608 return GetRenderViewHost()->GetRoutingID();
609}
610
[email protected]44470a22013-01-24 01:21:54611int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
612 return fullscreen_widget_routing_id_;
613}
614
[email protected]b172aee2012-04-10 17:05:26615RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21616 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31617}
618
[email protected]f8497342013-02-05 22:15:02619RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
620 BrowserPluginGuest* guest = GetBrowserPluginGuest();
621 if (guest && guest->embedder_web_contents()) {
622 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
623 }
624 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
625}
626
[email protected]4aebbca2013-09-17 22:26:49627RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
628 const {
629 RenderWidgetHost* const widget_host =
630 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
631 GetFullscreenWidgetRoutingID());
632 return widget_host ? widget_host->GetView() : NULL;
633}
634
[email protected]8ff00d72012-10-23 19:12:21635WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31636 return view_.get();
637}
638
[email protected]8ff00d72012-10-23 19:12:21639WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56640 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03641 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
642 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22643 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58644 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22645 web_ui->SetController(controller);
646 return web_ui;
647 }
648
649 delete web_ui;
650 return NULL;
651}
652
[email protected]8ff00d72012-10-23 19:12:21653WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21654 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
655 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31656}
657
[email protected]8ff00d72012-10-23 19:12:21658WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21659 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34660}
661
[email protected]86ef6a392012-05-11 22:03:11662void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22663 if (GetUserAgentOverride() == override)
664 return;
665
666 renderer_preferences_.user_agent_override = override;
667
668 // Send the new override string to the renderer.
669 RenderViewHost* host = GetRenderViewHost();
670 if (host)
671 host->SyncRendererPrefs();
672
673 // Reload the page if a load is currently in progress to avoid having
674 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27675 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22676 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
677 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53678
679 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
680 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11681}
682
683const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22684 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11685}
686
[email protected]2ceee8f2014-01-14 18:02:08687#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41688void WebContentsImpl::SetParentNativeViewAccessible(
689gfx::NativeViewAccessible accessible_parent) {
690 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45691 if (GetRenderViewHost())
692 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41693}
694#endif
695
[email protected]fcf75d42013-12-03 20:11:26696const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55697 // Transient entries take precedence. They are used for interstitial pages
698 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23699 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08700 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21701 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30702 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23703 if (entry) {
[email protected]b5cca982011-05-26 04:42:08704 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23705 }
[email protected]fa944cb82013-11-15 17:51:21706 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
707 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58708 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54709 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32710 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54711 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35712 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26713 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54714 if (!title.empty())
715 return title;
716 }
717 }
718
719 // We use the title for the last committed entry rather than a pending
720 // navigation entry. For example, when the user types in a URL, we want to
721 // keep the old page's title until the new load has committed and we get a new
722 // title.
[email protected]96d185d2009-04-24 03:28:54723 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32724
[email protected]9eeafc012013-11-25 23:49:47725 // We make an exception for initial navigations.
726 if (controller_.IsInitialNavigation()) {
727 // We only want to use the title from the visible entry in one of two cases:
728 // 1. There's already a committed entry for an initial navigation, in which
729 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
730 // 2. The pending entry has been explicitly assigned a title to display.
731 //
732 // If there's no last committed entry and no assigned title, we should fall
733 // back to |page_title_when_no_navigation_entry_| rather than showing the
734 // URL.
735 if (entry ||
736 (controller_.GetVisibleEntry() &&
737 !controller_.GetVisibleEntry()->GetTitle().empty())) {
738 entry = controller_.GetVisibleEntry();
739 }
740 }
[email protected]59167c22013-06-03 18:07:32741
[email protected]45d0ef7f2011-01-05 13:46:23742 if (entry) {
[email protected]b5cca982011-05-26 04:42:08743 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23744 }
[email protected]987fc3a2011-05-26 14:18:09745
746 // |page_title_when_no_navigation_entry_| is finally used
747 // if no title cannot be retrieved.
748 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54749}
750
[email protected]b172aee2012-04-10 17:05:26751int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46752 return GetMaxPageIDForSiteInstance(GetSiteInstance());
753}
754
[email protected]b172aee2012-04-10 17:05:26755int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
756 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33757 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
758 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46759
[email protected]b6583592012-01-25 19:52:33760 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34761}
762
[email protected]b172aee2012-04-10 17:05:26763void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46764 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
765}
766
[email protected]b172aee2012-04-10 17:05:26767void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33768 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46769 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33770 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34771}
772
[email protected]ec6c05f2013-10-23 18:41:57773void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
774 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
775 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57776}
777
[email protected]b172aee2012-04-10 17:05:26778SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21779 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54780}
781
[email protected]b172aee2012-04-10 17:05:26782SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21783 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
784 GetRenderManager()->pending_render_view_host() :
785 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58786 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38787}
788
[email protected]b172aee2012-04-10 17:05:26789bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31790 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49791}
792
[email protected]b172aee2012-04-10 17:05:26793bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31794 return waiting_for_response_;
795}
796
[email protected]b172aee2012-04-10 17:05:26797const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31798 return load_state_;
799}
800
[email protected]fcf75d42013-12-03 20:11:26801const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31802 return load_state_host_;
803}
804
[email protected]b172aee2012-04-10 17:05:26805uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31806 return upload_size_;
807}
808
[email protected]b172aee2012-04-10 17:05:26809uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31810 return upload_position_;
811}
812
[email protected]1ae93fb2013-06-14 03:38:56813std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56814 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39815 frame_tree_.ForEach(base::Bind(&CollectSites,
816 base::Unretained(GetBrowserContext()),
817 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56818 return sites;
819}
820
[email protected]b172aee2012-04-10 17:05:26821const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31822 return encoding_;
823}
824
[email protected]b172aee2012-04-10 17:05:26825bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31826 return displayed_insecure_content_;
827}
828
[email protected]54597982013-02-06 01:59:55829void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25830 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55831 ++capturer_count_;
832 DVLOG(1) << "There are now " << capturer_count_
833 << " capturing(s) of WebContentsImpl@" << this;
834}
835
836void WebContentsImpl::DecrementCapturerCount() {
837 --capturer_count_;
838 DVLOG(1) << "There are now " << capturer_count_
839 << " capturing(s) of WebContentsImpl@" << this;
840 DCHECK_LE(0, capturer_count_);
841
[email protected]5a652232013-02-12 06:15:25842 if (is_being_destroyed_)
843 return;
844
[email protected]1ac10dca2013-08-20 20:47:04845 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55846 DVLOG(1) << "Executing delayed WasHidden().";
847 WasHidden();
848 }
[email protected]be1f56ab2011-12-22 06:55:31849}
850
[email protected]f2bd40812013-07-20 04:30:44851int WebContentsImpl::GetCapturerCount() const {
852 return capturer_count_;
853}
854
[email protected]b172aee2012-04-10 17:05:26855bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31856 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
857 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
858 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49859}
860
[email protected]b172aee2012-04-10 17:05:26861void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
862 int error_code) {
[email protected]443b80e2010-12-14 00:42:23863 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34864 return;
865
[email protected]443b80e2010-12-14 00:42:23866 crashed_status_ = status;
867 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21868 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34869}
870
[email protected]b172aee2012-04-10 17:05:26871base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31872 return crashed_status_;
873}
874
[email protected]b172aee2012-04-10 17:05:26875bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31876 return is_being_destroyed_;
877}
878
[email protected]b172aee2012-04-10 17:05:26879void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34880 if (delegate_)
881 delegate_->NavigationStateChanged(this, changed_flags);
882}
883
[email protected]3e324142012-06-25 18:26:33884base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
885 return last_selected_time_;
886}
887
[email protected]9e2e4632012-07-27 16:38:41888void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54889 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04890 RenderWidgetHostViewPort* rwhv =
891 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16892 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29893 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43894#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16895 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43896#endif
897 }
[email protected]96d185d2009-04-24 03:28:54898
[email protected]5ac20162010-11-24 23:33:11899 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38900
[email protected]b9769d82012-02-10 00:23:59901 // The resize rect might have changed while this was inactive -- send the new
902 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58903 RenderViewHostImpl* rvh =
904 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59905 if (rvh) {
906 rvh->ResizeRectChanged(GetRootWindowResizerRect());
907 }
[email protected]96d185d2009-04-24 03:28:54908
[email protected]c0d9d5672013-10-09 07:38:03909 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
910
[email protected]54597982013-02-06 01:59:55911 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31912}
913
[email protected]b172aee2012-04-10 17:05:26914void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55915 // If there are entities capturing screenshots or video (e.g., mirroring),
916 // don't activate the "disable rendering" optimization.
917 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52918 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55919 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26920 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52921 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33922 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52923 // calls us).
[email protected]c30585c2012-02-16 15:02:04924 RenderWidgetHostViewPort* rwhv =
925 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16926 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29927 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54928 }
929
[email protected]c0d9d5672013-10-09 07:38:03930 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
931
[email protected]54597982013-02-06 01:59:55932 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37933}
934
[email protected]b172aee2012-04-10 17:05:26935bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31936 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27937 return WillNotifyDisconnection() &&
938 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58939 !static_cast<RenderViewHostImpl*>(
940 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31941}
942
[email protected]b172aee2012-04-10 17:05:26943void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:21944 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:40945 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:27946}
947
[email protected]b172aee2012-04-10 17:05:26948WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44949 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:45950 // We pass our own opener so that the cloned page can access it if it was
951 // before.
[email protected]54944cde2012-12-09 09:24:59952 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:45953 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:59954 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:19955 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:22956 FOR_EACH_OBSERVER(WebContentsObserver,
957 observers_,
958 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:27959 return tc;
960}
961
[email protected]14392a52012-05-02 20:28:44962void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:21963 const NotificationSource& source,
964 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:44965 switch (type) {
[email protected]8ff00d72012-10-23 19:12:21966 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
967 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:50968 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
969 i != pending_widget_views_.end(); ++i) {
970 if (host->GetView() == i->second) {
971 pending_widget_views_.erase(i);
972 break;
973 }
974 }
975 break;
976 }
[email protected]14392a52012-05-02 20:28:44977 default:
978 NOTREACHED();
979 }
980}
981
[email protected]ec6c05f2013-10-23 18:41:57982WebContents* WebContentsImpl::GetWebContents() {
983 return this;
984}
985
[email protected]54944cde2012-12-09 09:24:59986void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:21987 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:36988 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:21989 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:43990 should_normally_be_visible_ = !params.initially_hidden;
991
[email protected]fa944cb82013-11-15 17:51:21992 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:04993 params.browser_context, params.site_instance, params.routing_id,
994 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:19995
[email protected]8ff00d72012-10-23 19:12:21996 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:19997 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:27998 if (view_) {
[email protected]d1198fd2012-08-13 22:50:19999 CHECK(render_view_host_delegate_view_);
1000 } else {
[email protected]f8497342013-02-05 22:15:021001 WebContentsViewDelegate* delegate =
1002 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1003
[email protected]59383c782013-04-17 16:43:271004 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381005 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1006 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021007
[email protected]b5a40842012-11-28 15:26:111008 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381009 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431010 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111011 render_view_host_delegate_view_ = rv;
1012 view_.reset(rv);
1013 } else {
[email protected]f8497342013-02-05 22:15:021014 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111015 view_.reset(CreateWebContentsView(
1016 this, delegate, &render_view_host_delegate_view_));
1017 }
[email protected]d1198fd2012-08-13 22:50:191018 CHECK(render_view_host_delegate_view_);
1019 }
1020 CHECK(view_.get());
1021
[email protected]ed245db2012-12-18 08:00:451022 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591023 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191024
1025 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101026 if (opener_)
1027 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191028
1029 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211030 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1031 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441032#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191033 java_bridge_dispatcher_host_manager_.reset(
1034 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101035 date_time_chooser_.reset(new DateTimeChooserAndroid());
1036#endif
[email protected]d1198fd2012-08-13 22:50:191037}
1038
[email protected]7fff43e2013-05-21 20:21:101039void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1040 RemoveDestructionObserver(web_contents);
1041
[email protected]14392a52012-05-02 20:28:441042 // Clear the opener if it has been closed.
1043 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441044 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511045 return;
[email protected]14392a52012-05-02 20:28:441046 }
[email protected]ceee8cd2013-03-08 04:59:511047 // Clear a pending contents that has been closed before being shown.
1048 for (PendingContents::iterator iter = pending_contents_.begin();
1049 iter != pending_contents_.end();
1050 ++iter) {
1051 if (iter->second != web_contents)
1052 continue;
1053 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511054 return;
1055 }
1056 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441057}
1058
[email protected]7fff43e2013-05-21 20:21:101059void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1060 if (!ContainsKey(destruction_observers_, web_contents)) {
1061 destruction_observers_[web_contents] =
1062 new DestructionObserver(this, web_contents);
1063 }
1064}
1065
1066void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1067 DestructionObservers::iterator iter =
1068 destruction_observers_.find(web_contents);
1069 if (iter != destruction_observers_.end()) {
1070 delete destruction_observers_[web_contents];
1071 destruction_observers_.erase(iter);
1072 }
1073}
1074
[email protected]b172aee2012-04-10 17:05:261075void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311076 observers_.AddObserver(observer);
1077}
1078
[email protected]b172aee2012-04-10 17:05:261079void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311080 observers_.RemoveObserver(observer);
1081}
1082
[email protected]b172aee2012-04-10 17:05:261083void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341084 if (delegate_)
1085 delegate_->ActivateContents(this);
1086}
1087
[email protected]b172aee2012-04-10 17:05:261088void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121089 if (delegate_)
1090 delegate_->DeactivateContents(this);
1091}
1092
[email protected]b172aee2012-04-10 17:05:261093void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481094 if (delegate_)
1095 delegate_->LostCapture();
1096}
1097
[email protected]b24b68a2012-09-24 21:57:261098void WebContentsImpl::RenderWidgetDeleted(
1099 RenderWidgetHostImpl* render_widget_host) {
1100 if (is_being_destroyed_) {
1101 // |created_widgets_| might have been destroyed.
1102 return;
1103 }
1104
1105 std::set<RenderWidgetHostImpl*>::iterator iter =
1106 created_widgets_.find(render_widget_host);
1107 if (iter != created_widgets_.end())
1108 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541109
1110 if (render_widget_host &&
1111 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491112 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1113 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541114 FOR_EACH_OBSERVER(WebContentsObserver,
1115 observers_,
1116 DidDestroyFullscreenWidget(
1117 fullscreen_widget_routing_id_));
1118 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1119 }
[email protected]b24b68a2012-09-24 21:57:261120}
1121
[email protected]b172aee2012-04-10 17:05:261122bool WebContentsImpl::PreHandleKeyboardEvent(
1123 const NativeWebKeyboardEvent& event,
1124 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481125 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131126 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481127}
1128
[email protected]b172aee2012-04-10 17:05:261129void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061130 if (browser_plugin_embedder_ &&
1131 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1132 return;
1133 }
1134
[email protected]63954792011-07-11 04:17:481135 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131136 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481137}
1138
[email protected]fb3f066e2013-02-12 19:12:521139bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461140 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191141#if !defined(OS_MACOSX)
1142 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1143 // isn't done for two reasons:
1144 // -the OS already has a gesture to do this through pinch-zoom
1145 // -if a user starts an inertial scroll, let's go, and presses control
1146 // (i.e. control+tab) then the OS's buffered scroll events will come in
1147 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521148 if (delegate_ &&
1149 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461150 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521151 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1152 return true;
1153 }
[email protected]bccc4472013-04-18 16:37:191154#endif
[email protected]fb3f066e2013-02-12 19:12:521155
1156 return false;
1157}
1158
[email protected]04bce562014-01-30 05:34:541159bool WebContentsImpl::PreHandleGestureEvent(
1160 const blink::WebGestureEvent& event) {
1161 return delegate_->PreHandleGestureEvent(this, event);
1162}
1163
[email protected]2ceee8f2014-01-14 18:02:081164#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411165gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1166 return accessible_parent_;
1167}
1168#endif
1169
[email protected]b172aee2012-04-10 17:05:261170void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431171 if (delegate_)
1172 delegate_->HandleMouseDown();
1173}
1174
[email protected]b172aee2012-04-10 17:05:261175void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481176 if (delegate_)
1177 delegate_->HandleMouseUp();
1178}
1179
[email protected]590a634e2012-07-19 16:38:231180void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481181 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231182 delegate_->HandlePointerActivate();
1183}
1184
1185void WebContentsImpl::HandleGestureBegin() {
1186 if (delegate_)
1187 delegate_->HandleGestureBegin();
1188}
1189
1190void WebContentsImpl::HandleGestureEnd() {
1191 if (delegate_)
1192 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481193}
1194
[email protected]b172aee2012-04-10 17:05:261195void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491196 // This method is being called to enter or leave renderer-initiated fullscreen
1197 // mode. Either way, make sure any existing fullscreen widget is shut down
1198 // first.
1199 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1200 if (widget_view)
1201 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1202
[email protected]8a5e0ca2011-08-25 06:30:471203 if (delegate_)
1204 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1205}
1206
[email protected]b172aee2012-04-10 17:05:261207bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381208 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121209}
1210
[email protected]a9c81f02012-06-01 00:15:441211void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1212 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371213 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441214 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371215 } else {
1216 GotResponseToLockMouseRequest(false);
1217 }
1218}
1219
[email protected]b172aee2012-04-10 17:05:261220void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371221 if (delegate_)
1222 delegate_->LostMouseLock();
1223}
1224
[email protected]bafe6cd2012-05-23 23:09:501225void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201226 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501227 int route_id,
[email protected]227692c52013-05-31 22:43:041228 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131229 const ViewHostMsg_CreateWindow_Params& params,
1230 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501231 // We usually create the new window in the same BrowsingInstance (group of
1232 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551233 // if the opener is being suppressed (in a non-guest), we create a new
1234 // SiteInstance in its own BrowsingInstance.
1235 bool is_guest = GetRenderProcessHost()->IsGuest();
1236
[email protected]04cbd3d2013-12-04 04:58:201237 // If the opener is to be suppressed, the new window can be in any process.
1238 // Since routing ids are process specific, we must not have one passed in
1239 // as argument here.
1240 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1241
[email protected]bafe6cd2012-05-23 23:09:501242 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551243 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571244 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501245 GetSiteInstance();
1246
[email protected]04cbd3d2013-12-04 04:58:201247 // A message to create a new window can only come from the active process for
1248 // this WebContentsImpl instance. If any other process sends the request,
1249 // it is invalid and the process must be terminated.
1250 if (GetRenderProcessHost()->GetID() != render_process_id) {
1251 base::ProcessHandle process_handle =
1252 RenderProcessHost::FromID(render_process_id)->GetHandle();
1253 if (process_handle != base::kNullProcessHandle) {
1254 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391255 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201256 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1257 }
1258 return;
1259 }
1260
[email protected]d1198fd2012-08-13 22:50:191261 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341262 //
1263 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301264 const std::string& partition_id =
1265 GetContentClient()->browser()->
1266 GetStoragePartitionIdForSite(GetBrowserContext(),
1267 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461268 StoragePartition* partition = BrowserContext::GetStoragePartition(
1269 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411270 DOMStorageContextWrapper* dom_storage_context =
1271 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191272 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1273 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1274 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371275
1276 if (delegate_ &&
1277 !delegate_->ShouldCreateWebContents(this,
1278 route_id,
1279 params.window_container_type,
1280 params.frame_name,
1281 params.target_url,
1282 partition_id,
1283 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011284 if (route_id != MSG_ROUTING_NONE &&
1285 !RenderViewHost::FromID(render_process_id, route_id)) {
1286 // If the embedder didn't create a WebContents for this route, we need to
1287 // delete the RenderView that had already been created.
1288 Send(new ViewMsg_Close(route_id));
1289 }
[email protected]dd6730412013-08-14 15:03:371290 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1291 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1292 main_frame_route_id);
1293 return;
1294 }
1295
1296 // Create the new web contents. This will automatically create the new
1297 // WebContentsView. In the future, we may want to create the view separately.
1298 WebContentsImpl* new_contents =
1299 new WebContentsImpl(GetBrowserContext(),
1300 params.opener_suppressed ? NULL : this);
1301
[email protected]d1198fd2012-08-13 22:50:191302 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301303 partition_id,
[email protected]d1198fd2012-08-13 22:50:191304 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461305 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591306 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041307 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551308 if (!is_guest) {
1309 create_params.context = view_->GetNativeView();
1310 create_params.initial_size = view_->GetContainerSize();
1311 } else {
1312 // This makes |new_contents| act as a guest.
1313 // For more info, see comment above class BrowserPluginGuest.
1314 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1315 WebContentsImpl* new_contents_impl =
1316 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461317 BrowserPluginGuest::CreateWithOpener(instance_id,
1318 new_contents_impl->opener() != NULL,
1319 new_contents_impl,
1320 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551321 }
[email protected]1ac10dca2013-08-20 20:47:041322 if (params.disposition == NEW_BACKGROUND_TAB)
1323 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591324 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191325
[email protected]c4538072013-03-18 02:17:551326 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341327 // will be shown immediately).
1328 if (!params.opener_suppressed) {
1329 if (!is_guest) {
1330 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501331
[email protected]d70bea92013-04-05 04:23:341332 // TODO(brettw): It seems bogus that we have to call this function on the
1333 // newly created object and give it one of its own member variables.
1334 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1335 }
[email protected]bafe6cd2012-05-23 23:09:501336 // Save the created window associated with the route so we can show it
1337 // later.
1338 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1339 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101340 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501341 }
1342
1343 if (delegate_) {
1344 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131345 this, params.opener_frame_id, params.frame_name,
1346 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501347 }
1348
1349 if (params.opener_suppressed) {
1350 // When the opener is suppressed, the original renderer cannot access the
1351 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001352 bool was_blocked = false;
1353 if (delegate_) {
1354 gfx::Rect initial_pos;
1355 delegate_->AddNewContents(
1356 this, new_contents, params.disposition, initial_pos,
1357 params.user_gesture, &was_blocked);
1358 }
1359 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211360 OpenURLParams open_params(params.target_url,
1361 Referrer(),
1362 CURRENT_TAB,
1363 PAGE_TRANSITION_LINK,
1364 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301365 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001366 new_contents->OpenURL(open_params);
1367 }
[email protected]bafe6cd2012-05-23 23:09:501368 }
1369}
1370
[email protected]a8504022013-12-04 20:23:511371void WebContentsImpl::CreateNewWidget(int render_process_id,
1372 int route_id,
[email protected]180ef242013-11-07 06:50:461373 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511374 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501375}
1376
[email protected]a8504022013-12-04 20:23:511377void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1378 int route_id) {
1379 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501380}
1381
[email protected]a8504022013-12-04 20:23:511382void WebContentsImpl::CreateNewWidget(int render_process_id,
1383 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501384 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461385 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211386 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511387 // A message to create a new widget can only come from the active process for
1388 // this WebContentsImpl instance. If any other process sends the request,
1389 // it is invalid and the process must be terminated.
1390 if (process->GetID() != render_process_id) {
1391 base::ProcessHandle process_handle =
1392 RenderProcessHost::FromID(render_process_id)->GetHandle();
1393 if (process_handle != base::kNullProcessHandle) {
1394 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391395 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511396 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1397 }
1398 return;
1399 }
1400
[email protected]bafe6cd2012-05-23 23:09:501401 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041402 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261403 created_widgets_.insert(widget_host);
1404
[email protected]83918ec2013-01-10 15:37:191405 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1406 view_->CreateViewForPopupWidget(widget_host));
1407 if (!widget_view)
1408 return;
[email protected]bafe6cd2012-05-23 23:09:501409 if (!is_fullscreen) {
1410 // Popups should not get activated.
1411 widget_view->SetPopupType(popup_type);
1412 }
1413 // Save the created widget associated with the route so we can show it later.
1414 pending_widget_views_[route_id] = widget_view;
1415
1416#if defined(OS_MACOSX)
1417 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1418 // to allow it to survive the trip without being hosted.
1419 base::mac::NSObjectRetain(widget_view->GetNativeView());
1420#endif
1421}
1422
1423void WebContentsImpl::ShowCreatedWindow(int route_id,
1424 WindowOpenDisposition disposition,
1425 const gfx::Rect& initial_pos,
1426 bool user_gesture) {
1427 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001428 if (contents) {
1429 WebContentsDelegate* delegate = GetDelegate();
1430 if (delegate) {
1431 delegate->AddNewContents(
1432 this, contents, disposition, initial_pos, user_gesture, NULL);
1433 }
1434 }
[email protected]bafe6cd2012-05-23 23:09:501435}
1436
1437void WebContentsImpl::ShowCreatedWidget(int route_id,
1438 const gfx::Rect& initial_pos) {
1439 ShowCreatedWidget(route_id, false, initial_pos);
1440}
1441
1442void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1443 ShowCreatedWidget(route_id, true, gfx::Rect());
1444}
1445
1446void WebContentsImpl::ShowCreatedWidget(int route_id,
1447 bool is_fullscreen,
1448 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501449 RenderWidgetHostViewPort* widget_host_view =
1450 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1451 if (!widget_host_view)
1452 return;
[email protected]4aebbca2013-09-17 22:26:491453 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311454 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1455 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491456 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1457 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1458 delegate_->ToggleFullscreenModeForTab(this, true);
1459 } else {
1460 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491461 }
[email protected]4aebbca2013-09-17 22:26:491462 FOR_EACH_OBSERVER(WebContentsObserver,
1463 observers_,
1464 DidShowFullscreenWidget(route_id));
1465 if (!widget_host_view->HasFocus())
1466 widget_host_view->Focus();
1467 } else {
[email protected]f8497342013-02-05 22:15:021468 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491469 }
[email protected]89054502012-06-03 10:29:241470
1471 RenderWidgetHostImpl* render_widget_host_impl =
1472 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1473 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311474 // Only allow privileged mouse lock for fullscreen render widget, which is
1475 // used to implement Pepper Flash fullscreen.
1476 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501477
1478#if defined(OS_MACOSX)
1479 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1480 // properly embedded (or purposefully ignored) we can release the retain we
1481 // took in CreateNewWidget().
1482 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1483#endif
1484}
1485
1486WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1487 PendingContents::iterator iter = pending_contents_.find(route_id);
1488
1489 // Certain systems can block the creation of new windows. If we didn't succeed
1490 // in creating one, just return NULL.
1491 if (iter == pending_contents_.end()) {
1492 return NULL;
1493 }
1494
1495 WebContentsImpl* new_contents = iter->second;
1496 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101497 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501498
[email protected]d70bea92013-04-05 04:23:341499 // Don't initialize the guest WebContents immediately.
1500 if (new_contents->GetRenderProcessHost()->IsGuest())
1501 return new_contents;
1502
[email protected]bafe6cd2012-05-23 23:09:501503 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1504 !new_contents->GetRenderViewHost()->GetView())
1505 return NULL;
1506
1507 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1508 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1509 return new_contents;
1510}
1511
1512RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1513 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1514 if (iter == pending_widget_views_.end()) {
1515 DCHECK(false);
1516 return NULL;
1517 }
1518
1519 RenderWidgetHostView* widget_host_view = iter->second;
1520 pending_widget_views_.erase(route_id);
1521
1522 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1523 if (!widget_host->GetProcess()->HasConnection()) {
1524 // The view has gone away or the renderer crashed. Nothing to do.
1525 return NULL;
1526 }
1527
1528 return widget_host_view;
1529}
1530
[email protected]f13b4202012-06-12 23:53:231531void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091532 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211533 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231534 if (delegate_)
1535 delegate_->RequestMediaAccessPermission(this, request, callback);
1536 else
[email protected]b5f76742013-04-29 15:05:591537 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231538}
1539
[email protected]cc9200432013-07-23 23:02:401540SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1541 SiteInstance* instance) {
1542 return controller_.GetSessionStorageNamespace(instance);
1543}
1544
[email protected]9b159a52013-10-03 17:24:551545FrameTree* WebContentsImpl::GetFrameTree() {
1546 return &frame_tree_;
1547}
1548
[email protected]edc3af82013-12-12 21:24:071549void WebContentsImpl::OnShowValidationMessage(
1550 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291551 const base::string16& main_text,
1552 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071553 if (delegate_)
1554 delegate_->ShowValidationMessage(
1555 this, anchor_in_root_view, main_text, sub_text);
1556}
1557
1558void WebContentsImpl::OnHideValidationMessage() {
1559 if (delegate_)
1560 delegate_->HideValidationMessage(this);
1561}
1562
1563void WebContentsImpl::OnMoveValidationMessage(
1564 const gfx::Rect& anchor_in_root_view) {
1565 if (delegate_)
1566 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1567}
1568
[email protected]32deec62013-05-15 23:55:041569void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1570 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441571 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041572}
1573
[email protected]b172aee2012-04-10 17:05:261574void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231575 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331576 if (delegate_)
1577 delegate_->UpdatePreferredSize(this, pref_size);
1578}
1579
[email protected]b172aee2012-04-10 17:05:261580void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341581 if (delegate_)
1582 delegate_->ResizeDueToAutoResize(this, new_size);
1583}
1584
[email protected]b172aee2012-04-10 17:05:261585WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201586 if (!delegate_)
1587 return NULL;
[email protected]00c37fc2011-08-02 00:22:501588
[email protected]e5d549d2011-12-28 01:29:201589 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201590 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341591}
1592
[email protected]6b618e62012-08-16 12:59:181593bool WebContentsImpl::Send(IPC::Message* message) {
1594 if (!GetRenderViewHost()) {
1595 delete message;
1596 return false;
1597 }
1598
1599 return GetRenderViewHost()->Send(message);
1600}
1601
[email protected]b172aee2012-04-10 17:05:261602bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501603 NavigationController::ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:201604 return frame_tree_.root()->navigator()->NavigateToPendingEntry(
1605 frame_tree_.GetMainFrame(), reload_type);
[email protected]876bc832010-09-07 16:29:541606}
[email protected]96d185d2009-04-24 03:28:541607
[email protected]a86c0e962013-12-17 17:10:391608void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1609 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441610 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391611 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441612}
1613
[email protected]20ca0382013-02-28 19:50:071614void WebContentsImpl::AttachInterstitialPage(
1615 InterstitialPageImpl* interstitial_page) {
1616 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211617 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291618
1619 // Cancel any visible dialogs so that they don't interfere with the
1620 // interstitial.
1621 if (dialog_manager_)
1622 dialog_manager_->CancelActiveAndPendingDialogs(this);
1623
[email protected]20ca0382013-02-28 19:50:071624 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1625 DidAttachInterstitialPage());
1626}
1627
1628void WebContentsImpl::DetachInterstitialPage() {
1629 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211630 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071631 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1632 DidDetachInterstitialPage());
1633}
1634
[email protected]b172aee2012-04-10 17:05:261635void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331636 const SiteInstance* site_instance,
1637 int history_length,
1638 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411639 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1640 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211641 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191642 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141643 return;
[email protected]9e1ad4b2011-08-14 16:49:191644 }
[email protected]9f76c1e2012-03-05 15:15:581645 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191646 if (!rvh) {
1647 NOTREACHED();
1648 return;
1649 }
[email protected]9f76c1e2012-03-05 15:15:581650 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191651 NOTREACHED();
1652 return;
1653 }
[email protected]6b618e62012-08-16 12:59:181654 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1655 history_length,
1656 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141657}
1658
[email protected]b172aee2012-04-10 17:05:261659void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271660 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211661 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541662 return;
1663 }
[email protected]9f76c1e2012-03-05 15:15:581664 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541665}
1666
[email protected]b172aee2012-04-10 17:05:261667bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211668 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541669}
1670
[email protected]b172aee2012-04-10 17:05:261671InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211672 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221673}
1674
[email protected]b172aee2012-04-10 17:05:261675bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161676 // WebKit creates Document object when MIME type is application/xhtml+xml,
1677 // so we also support this MIME type.
1678 return contents_mime_type_ == "text/html" ||
1679 contents_mime_type_ == "text/xml" ||
1680 contents_mime_type_ == "application/xhtml+xml" ||
1681 contents_mime_type_ == "text/plain" ||
1682 contents_mime_type_ == "text/css" ||
1683 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1684}
1685
[email protected]b172aee2012-04-10 17:05:261686void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591687 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161688 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551689 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011690 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141691 return;
[email protected]c7dd2f62011-07-18 15:57:591692 }
1693
1694 Stop();
1695
1696 // Create the save package and possibly prompt the user for the name to save
1697 // the page as. The user prompt is an asynchronous operation that runs on
1698 // another thread.
1699 save_package_ = new SavePackage(this);
1700 save_package_->GetSaveInfo();
1701}
1702
1703// Used in automated testing to bypass prompting the user for file names.
1704// Instead, the names and paths are hard coded rather than running them through
1705// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341706bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1707 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211708 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591709 // Stop the page from navigating.
1710 Stop();
1711
1712 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211713 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591714}
1715
[email protected]3c71576ce2013-07-23 02:00:011716void WebContentsImpl::SaveFrame(const GURL& url,
1717 const Referrer& referrer) {
1718 if (!GetURL().is_valid())
1719 return;
1720 bool is_main_frame = (url == GetURL());
1721
1722 DownloadManager* dlm =
1723 BrowserContext::GetDownloadManager(GetBrowserContext());
1724 if (!dlm)
1725 return;
1726 int64 post_id = -1;
1727 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271728 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011729 if (entry)
1730 post_id = entry->GetPostID();
1731 }
1732 scoped_ptr<DownloadUrlParameters> params(
1733 DownloadUrlParameters::FromWebContents(this, url));
1734 params->set_referrer(referrer);
1735 params->set_post_id(post_id);
1736 params->set_prefer_cache(true);
1737 if (post_id >= 0)
1738 params->set_method("POST");
1739 params->set_prompt(true);
1740 dlm->DownloadUrl(params.Pass());
1741}
1742
[email protected]b172aee2012-04-10 17:05:261743void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341744 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481745 const base::Callback<void(int64)>& callback) {
1746 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121747}
1748
[email protected]6286a372013-10-09 04:03:271749// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261750bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271751 NavigationEntryImpl* visible_entry =
1752 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1753 return (visible_entry != NULL &&
1754 visible_entry->site_instance() == GetSiteInstance() &&
1755 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321756}
1757
[email protected]b172aee2012-04-10 17:05:261758const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271759 return contents_mime_type_;
1760}
1761
[email protected]b172aee2012-04-10 17:05:261762bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271763 return notify_disconnection_;
1764}
1765
[email protected]b172aee2012-04-10 17:05:261766void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311767 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181768 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161769}
1770
[email protected]b172aee2012-04-10 17:05:261771void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311772 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181773 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161774}
1775
[email protected]8ff00d72012-10-23 19:12:211776RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271777 return &renderer_preferences_;
1778}
1779
[email protected]e35ccd52012-05-23 16:22:471780void WebContentsImpl::Close() {
1781 Close(GetRenderViewHost());
1782}
1783
[email protected]cf200a562013-05-03 16:24:291784void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461785 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291786 if (browser_plugin_embedder_.get())
1787 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1788 screen_x, screen_y, operation);
1789 if (GetRenderViewHost())
1790 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1791 screen_x, screen_y, operation);
1792}
1793
1794void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1795 int screen_x, int screen_y) {
1796 if (browser_plugin_embedder_.get())
1797 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1798 screen_x, screen_y);
1799 if (GetRenderViewHost())
1800 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1801 screen_x, screen_y);
1802}
1803
[email protected]d60f3702013-12-26 16:30:241804void WebContentsImpl::DidGetResourceResponseStart(
1805 const ResourceRequestDetails& details) {
1806 controller_.ssl_manager()->DidStartResourceResponse(details);
1807
1808 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1809 DidGetResourceResponseStart(details));
1810
1811 // TODO(avi): Remove. http://crbug.com/170921
1812 NotificationService::current()->Notify(
1813 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1814 Source<WebContents>(this),
1815 Details<const ResourceRequestDetails>(&details));
1816}
1817
1818void WebContentsImpl::DidGetRedirectForResourceRequest(
1819 RenderViewHost* render_view_host,
1820 const ResourceRedirectDetails& details) {
1821 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1822
1823 FOR_EACH_OBSERVER(
1824 WebContentsObserver,
1825 observers_,
1826 DidGetRedirectForResourceRequest(render_view_host, details));
1827
1828 // TODO(avi): Remove. http://crbug.com/170921
1829 NotificationService::current()->Notify(
1830 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1831 Source<WebContents>(this),
1832 Details<const ResourceRedirectDetails>(&details));
1833}
1834
[email protected]b172aee2012-04-10 17:05:261835void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521836 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581837 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511838 if (delegate_)
1839 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291840 if (browser_plugin_embedder_.get())
1841 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341842}
1843
[email protected]e35ccd52012-05-23 16:22:471844void WebContentsImpl::UserGestureDone() {
1845 OnUserGesture();
1846}
1847
[email protected]b172aee2012-04-10 17:05:261848void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271849 closed_by_user_gesture_ = value;
1850}
1851
[email protected]b172aee2012-04-10 17:05:261852bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271853 return closed_by_user_gesture_;
1854}
1855
[email protected]b172aee2012-04-10 17:05:261856double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051857 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561858 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251859 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171860 return 0;
[email protected]b75b8292010-10-01 07:28:251861
1862 double zoom_level;
1863 if (temporary_zoom_settings_) {
1864 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581865 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251866 } else {
[email protected]2ae88d12011-10-14 09:11:191867 GURL url;
[email protected]6286a372013-10-09 04:03:271868 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191869 // Since zoom map is updated using rewritten URL, use rewritten URL
1870 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271871 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021872 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1873 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251874 }
[email protected]d0b8d092010-10-25 04:05:171875 return zoom_level;
1876}
[email protected]b75b8292010-10-01 07:28:251877
[email protected]b172aee2012-04-10 17:05:261878int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591879 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171880 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011881 // Calculate the zoom percent from the factor. Round up to the nearest whole
1882 // number.
[email protected]b75b8292010-10-01 07:28:251883 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491884 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251885 *enable_decrement = percent > minimum_zoom_percent_;
1886 *enable_increment = percent < maximum_zoom_percent_;
1887 return percent;
1888}
1889
[email protected]b172aee2012-04-10 17:05:261890void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501891 if (!delegate_)
1892 return;
1893
[email protected]6286a372013-10-09 04:03:271894 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1895 if (!entry)
[email protected]1788e772010-12-15 16:40:501896 return;
1897
[email protected]6286a372013-10-09 04:03:271898 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121899}
1900
[email protected]b172aee2012-04-10 17:05:261901void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041902 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271903 if (!delegate_)
1904 return;
1905
[email protected]691aa2f2013-05-28 22:52:041906 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271907}
1908
[email protected]b172aee2012-04-10 17:05:261909int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271910 return minimum_zoom_percent_;
1911}
1912
[email protected]b172aee2012-04-10 17:05:261913int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271914 return maximum_zoom_percent_;
1915}
1916
[email protected]b172aee2012-04-10 17:05:261917gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231918 return preferred_size_;
1919}
1920
[email protected]b172aee2012-04-10 17:05:261921bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271922 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581923 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271924}
1925
[email protected]b172aee2012-04-10 17:05:261926bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441927 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501928}
1929
[email protected]cb805452013-05-22 15:16:211930void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181931 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211932 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201933}
1934
[email protected]cb805452013-05-22 15:16:211935void WebContentsImpl::DidEndColorChooser() {
1936 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1937 color_chooser_identifier_));
1938 color_chooser_.reset();
1939 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201940}
1941
[email protected]41225fe2013-03-29 05:32:021942int WebContentsImpl::DownloadImage(const GURL& url,
1943 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301944 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021945 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391946 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301947 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021948 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391949 return id;
1950}
1951
[email protected]5dcaf8e2013-12-28 01:31:421952bool WebContentsImpl::IsSubframe() const {
1953 return is_subframe_;
1954}
1955
[email protected]9649d492014-01-10 07:15:521956void WebContentsImpl::SetZoomLevel(double level) {
1957 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
1958 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
1959 if (embedder)
1960 embedder->SetZoomLevel(level);
1961}
1962
[email protected]36ec24f2014-01-09 00:32:081963void WebContentsImpl::Find(int request_id,
1964 const base::string16& search_text,
1965 const blink::WebFindOptions& options) {
1966 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
1967}
1968
1969void WebContentsImpl::StopFinding(StopFindAction action) {
1970 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
1971}
1972
[email protected]b172aee2012-04-10 17:05:261973bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:271974 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:201975 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:331976 return true;
1977 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:271978}
1979
[email protected]b172aee2012-04-10 17:05:261980void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271981 if (delegate_)
1982 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211983}
1984
[email protected]52913802013-12-10 05:52:181985void WebContentsImpl::DidStartProvisionalLoad(
1986 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:571987 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131988 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571989 bool is_main_frame,
[email protected]52913802013-12-10 05:52:181990 const GURL& validated_url,
1991 bool is_error_page,
1992 bool is_iframe_srcdoc) {
1993 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:571994 DidChangeLoadProgress(0);
1995
[email protected]0d60f0192011-04-14 12:40:101996 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251997 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:131998 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
1999 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182000 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542001
2002 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182003 FOR_EACH_OBSERVER(
2004 WebContentsObserver,
2005 observers_,
2006 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582007 render_frame_host));
[email protected]400992b2012-06-14 00:03:542008 }
2009}
2010
[email protected]3109fbb72014-01-06 23:57:152011void WebContentsImpl::DidFailProvisionalLoadWithError(
2012 RenderFrameHostImpl* render_frame_host,
2013 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2014 GURL validated_url(params.url);
2015 FOR_EACH_OBSERVER(
2016 WebContentsObserver,
2017 observers_,
2018 DidFailProvisionalLoad(params.frame_id,
2019 params.frame_unique_name,
2020 params.is_main_frame,
2021 validated_url,
2022 params.error_code,
2023 params.error_description,
2024 render_frame_host->render_view_host()));
2025}
2026
[email protected]52913802013-12-10 05:52:182027void WebContentsImpl::NotifyChangedNavigationState(
2028 InvalidateTypes changed_flags) {
2029 NotifyNavigationStateChanged(changed_flags);
2030}
2031
[email protected]3691e5cf2014-01-22 10:16:202032void WebContentsImpl::AboutToNavigateRenderFrame(
2033 RenderFrameHostImpl* render_frame_host) {
2034 // Notify observers that we will navigate in this RenderView.
2035 FOR_EACH_OBSERVER(
2036 WebContentsObserver,
2037 observers_,
2038 AboutToNavigateRenderView(render_frame_host->render_view_host()));
2039}
2040
2041void WebContentsImpl::DidStartNavigationToPendingEntry(
2042 RenderFrameHostImpl* render_frame_host,
2043 const GURL& url,
2044 NavigationController::ReloadType reload_type) {
2045 // Notify observers about navigation.
2046 FOR_EACH_OBSERVER(
2047 WebContentsObserver,
2048 observers_,
2049 DidStartNavigationToPendingEntry(url, reload_type));
2050}
2051
[email protected]400992b2012-06-14 00:03:542052void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582053 RenderFrameHostImpl* render_frame_host,
2054 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542055 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582056 FOR_EACH_OBSERVER(
2057 WebContentsObserver,
2058 observers_,
2059 ProvisionalChangeToMainFrameUrl(validated_target_url,
2060 render_frame_host));
[email protected]724159a2010-12-30 01:11:182061}
2062
[email protected]b172aee2012-04-10 17:05:262063void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182064 const GURL& url,
[email protected]70435962011-08-02 20:13:282065 const std::string& security_info,
2066 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182067 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282068 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192069 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182070 cache.Increment();
2071
2072 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082073 int cert_id = 0;
2074 net::CertStatus cert_status = 0;
2075 int security_bits = -1;
2076 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122077 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212078 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122079 &security_bits, &connection_status,
2080 &signed_certificate_timestamp_ids);
2081 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212082 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002083 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2084 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182085
[email protected]b0f724c2013-09-05 04:21:132086 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2087
2088 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2089 DidLoadResourceFromMemoryCache(details));
2090
[email protected]8bfc8272013-09-09 20:10:532091 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2092 scoped_refptr<net::URLRequestContextGetter> request_context(
2093 resource_type == ResourceType::MEDIA ?
2094 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2095 GetRenderProcessHost()->GetID()) :
2096 GetBrowserContext()->GetRequestContextForRenderProcess(
2097 GetRenderProcessHost()->GetID()));
2098 BrowserThread::PostTask(
2099 BrowserThread::IO,
2100 FROM_HERE,
2101 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2102 }
[email protected]724159a2010-12-30 01:11:182103}
2104
[email protected]b172aee2012-04-10 17:05:262105void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392106 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182107 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192108 SSLManager::NotifySSLInternalStateChanged(
2109 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182110}
2111
[email protected]b172aee2012-04-10 17:05:262112void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022113 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582114 LOG(WARNING) << security_origin << " ran insecure content from "
2115 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392116 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412117 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392118 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182119 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412120 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192121 SSLManager::NotifySSLInternalStateChanged(
2122 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182123}
2124
[email protected]b172aee2012-04-10 17:05:262125void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]f114fa42013-12-06 17:06:442126 FOR_EACH_OBSERVER(
2127 WebContentsObserver, observers_,
2128 DocumentLoadedInFrame(frame_id, render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182129}
2130
[email protected]b172aee2012-04-10 17:05:262131void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312132 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062133 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312134 bool is_main_frame) {
[email protected]8b3af1e2014-01-24 13:29:122135 if (!render_view_message_source_) {
2136 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2137 GetRenderProcessHost()->ReceivedBadMessage();
2138 return;
2139 }
[email protected]a1b99262013-12-27 21:56:222140
2141 // --site-per-process mode has a short-term hack allowing cross-process
2142 // subframe pages to commit thinking they are top-level. Correct it here to
2143 // avoid confusing the observers.
2144 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2145 render_view_message_source_ != GetRenderViewHost())
2146 is_main_frame = false;
2147
[email protected]8b3af1e2014-01-24 13:29:122148 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442149 RenderProcessHost* render_process_host =
2150 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422151 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252152 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472153 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442154 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312155}
2156
[email protected]b172aee2012-04-10 17:05:262157void WebContentsImpl::OnDidFailLoadWithError(
2158 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062159 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262160 bool is_main_frame,
2161 int error_code,
[email protected]fcf75d42013-12-03 20:11:262162 const base::string16& error_description) {
[email protected]15be9bff2014-01-25 07:19:412163 if (!render_view_message_source_) {
2164 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD3"));
2165 GetRenderProcessHost()->ReceivedBadMessage();
2166 return;
2167 }
[email protected]b502ed462013-01-08 08:20:062168 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442169 RenderProcessHost* render_process_host =
2170 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422171 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252172 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312173 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472174 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442175 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182176}
2177
[email protected]b172aee2012-04-10 17:05:262178void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262179 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232180 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252181 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262182 if (!entry)
2183 return;
2184 // Note that we don't call NavigationController::GotToOffset() as we don't
2185 // want to create a pending navigation entry (it might end up lingering
2186 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252187 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212188 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512189 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212190 PAGE_TRANSITION_FORWARD_BACK));
[email protected]3691e5cf2014-01-22 10:16:202191 frame_tree_.root()->navigator()->NavigateToEntry(
2192 frame_tree_.GetMainFrame(),
2193 *entry,
2194 NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572195
2196 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2197 // it in now that we know. This allows us to find the entry when it commits.
2198 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232199 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332200 entry->set_site_instance(
2201 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572202 }
[email protected]216813952011-05-19 22:21:262203 }
2204}
2205
[email protected]b172aee2012-04-10 17:05:262206void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2207 int maximum_percent,
2208 bool remember) {
[email protected]216813952011-05-19 22:21:262209 minimum_zoom_percent_ = minimum_percent;
2210 maximum_zoom_percent_ = maximum_percent;
2211 temporary_zoom_settings_ = !remember;
2212}
2213
[email protected]b172aee2012-04-10 17:05:262214void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342215 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432216 if (!delegate_)
2217 return;
2218
[email protected]b9535422012-02-09 01:47:592219 ChildProcessSecurityPolicyImpl* policy =
2220 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222221 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592222 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212223}
2224
[email protected]b172aee2012-04-10 17:05:262225void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432226 if (delegate_)
2227 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202228}
2229
[email protected]b172aee2012-04-10 17:05:262230void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2231 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262232 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362233 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432234 if (!delegate_)
2235 return;
2236
[email protected]b9535422012-02-09 01:47:592237 ChildProcessSecurityPolicyImpl* policy =
2238 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322239 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592240 return;
[email protected]8f810632013-06-06 22:33:322241
[email protected]3a3b75a2012-06-01 08:38:362242 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202243}
2244
[email protected]b172aee2012-04-10 17:05:262245void WebContentsImpl::OnFindReply(int request_id,
2246 int number_of_matches,
2247 const gfx::Rect& selection_rect,
2248 int active_match_ordinal,
2249 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432250 if (delegate_) {
2251 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2252 active_match_ordinal, final_update);
2253 }
[email protected]b888919c2011-09-02 00:32:162254}
2255
[email protected]59363fc92012-09-05 03:46:312256#if defined(OS_ANDROID)
2257void WebContentsImpl::OnFindMatchRectsReply(
2258 int version,
2259 const std::vector<gfx::RectF>& rects,
2260 const gfx::RectF& active_rect) {
2261 if (delegate_)
2262 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2263}
[email protected]583418cc2013-01-17 14:01:102264
[email protected]1ff427972013-02-07 21:14:072265void WebContentsImpl::OnOpenDateTimeDialog(
2266 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092267 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2268 GetRenderViewHost(),
2269 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132270 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092271 value.minimum,
2272 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172273 value.step,
2274 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102275}
2276
[email protected]a794f3a2013-10-30 17:00:322277void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2278 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442279 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322280}
2281
[email protected]59363fc92012-09-05 03:46:312282#endif
2283
[email protected]f114fa42013-12-06 17:06:442284void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2285 const base::FilePath& path,
2286 bool is_hung) {
2287 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2288
2289 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2290 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2291}
2292
2293void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422294 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442295 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422296 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452297}
2298
[email protected]b172aee2012-04-10 17:05:262299void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2300 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102301 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252302 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102303 AppCacheAccessed(manifest_url, blocked_by_policy));
2304}
2305
[email protected]8bc5ff02013-11-29 06:34:032306void WebContentsImpl::OnOpenColorChooser(
2307 int color_chooser_id,
2308 SkColor color,
2309 const std::vector<ColorSuggestion>& suggestions) {
2310 ColorChooser* new_color_chooser =
2311 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302312 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212313 return;
[email protected]820957a2014-01-14 14:56:302314 if (color_chooser_)
2315 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212316 color_chooser_.reset(new_color_chooser);
2317 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202318}
2319
[email protected]b172aee2012-04-10 17:05:262320void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202321 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212322 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202323 color_chooser_->End();
2324}
2325
[email protected]b172aee2012-04-10 17:05:262326void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322327 SkColor color) {
[email protected]da8543762012-03-20 08:52:202328 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212329 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202330 color_chooser_->SetSelectedColor(color);
2331}
2332
[email protected]d0759f492012-04-19 22:50:502333// This exists for render views that don't have a WebUI, but do have WebUI
2334// bindings enabled.
2335void WebContentsImpl::OnWebUISend(const GURL& source_url,
2336 const std::string& name,
2337 const base::ListValue& args) {
2338 if (delegate_)
2339 delegate_->WebUISend(this, source_url, name, args);
2340}
2341
[email protected]d8415ad92012-08-23 14:40:502342void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442343 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502344 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342345 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162346 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442347 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162348 return;
[email protected]d8415ad92012-08-23 14:40:502349 }
2350
[email protected]8c8fc292012-11-23 18:57:162351 if (!delegate_->RequestPpapiBrokerPermission(
2352 this, url, plugin_path,
2353 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442354 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162355 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442356 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162357 }
[email protected]d8415ad92012-08-23 14:40:502358}
2359
[email protected]ea0309c2013-08-06 19:35:442360void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502361 bool result) {
[email protected]ea0309c2013-08-06 19:35:442362 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502363}
2364
[email protected]c4538072013-03-18 02:17:552365void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372366 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082367 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552368 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392369 // For more info, see comment above classes BrowserPluginEmbedder and
2370 // BrowserPluginGuest.
2371 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142372 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082373 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372374}
2375
[email protected]41225fe2013-03-29 05:32:022376void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392377 int id,
[email protected]749fadd2013-05-15 08:37:482378 int http_status_code,
[email protected]795c28972012-12-06 06:13:392379 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302380 const std::vector<SkBitmap>& bitmaps,
2381 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132382 if (bitmaps.size() != original_bitmap_sizes.size())
2383 return;
2384
[email protected]41225fe2013-03-29 05:32:022385 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2386 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392387 // Currently WebContents notifies us of ANY downloads so that it is
2388 // possible to get here.
2389 return;
2390 }
2391 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302392 iter->second.Run(
2393 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392394 }
[email protected]41225fe2013-03-29 05:32:022395 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392396}
2397
2398void WebContentsImpl::OnUpdateFaviconURL(
2399 int32 page_id,
2400 const std::vector<FaviconURL>& candidates) {
2401 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2402 DidUpdateFaviconURL(page_id, candidates));
2403}
2404
[email protected]d9030b82013-07-19 08:26:062405void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2406 bool has_video,
2407 bool has_audio,
2408 bool is_playing) {
2409 // Chrome OS does its own detection of audio and video.
2410#if !defined(OS_CHROMEOS)
2411 if (is_playing) {
2412 scoped_ptr<PowerSaveBlocker> blocker;
2413 if (has_video) {
2414 blocker = PowerSaveBlocker::Create(
2415 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2416 "Playing video");
2417#if defined(OS_ANDROID)
2418 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382419 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062420#endif
2421 } else if (has_audio) {
2422 blocker = PowerSaveBlocker::Create(
2423 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2424 "Playing audio");
2425 }
2426
[email protected]f114fa42013-12-06 17:06:442427 if (blocker) {
2428 power_save_blockers_[render_view_message_source_][player_cookie] =
2429 blocker.release();
2430 }
[email protected]d9030b82013-07-19 08:26:062431 } else {
[email protected]f114fa42013-12-06 17:06:442432 delete power_save_blockers_[render_view_message_source_][player_cookie];
2433 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062434 }
2435#endif // !defined(OS_CHROMEOS)
2436}
2437
[email protected]9f268072013-11-07 00:02:152438void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2439 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2440 DidFirstVisuallyNonEmptyPaint(page_id));
2441}
[email protected]d9030b82013-07-19 08:26:062442
[email protected]e67ebf32013-02-13 11:07:192443void WebContentsImpl::DidChangeVisibleSSLState() {
2444 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2445 DidChangeVisibleSSLState());
2446}
2447
[email protected]17e286e2013-03-01 23:29:392448void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2449 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2450 BeforeFormRepostWarningShow());
2451}
2452
[email protected]ec6c05f2013-10-23 18:41:572453
2454void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2455 Activate();
2456 if (delegate_)
2457 delegate_->ShowRepostFormWarningDialog(this);
2458}
2459
[email protected]96d185d2009-04-24 03:28:542460// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592461// loading, or done loading.
2462void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2463 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262464 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542465 if (is_loading == is_loading_)
2466 return;
2467
2468 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262469 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2470 base::string16());
[email protected]96d185d2009-04-24 03:28:542471 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562472 upload_size_ = 0;
2473 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542474 }
2475
[email protected]fa944cb82013-11-15 17:51:212476 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542477
2478 is_loading_ = is_loading;
2479 waiting_for_response_ = is_loading;
2480
[email protected]6ebdc9b2010-09-27 16:55:572481 if (delegate_)
2482 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212483 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542484
[email protected]eab61442013-11-14 18:35:482485 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592486 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482487 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2488 "URL", url);
[email protected]91621872013-10-08 04:04:592489 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2490 DidStartLoading(render_view_host));
2491 } else {
[email protected]eab61442013-11-14 18:35:482492 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2493 "URL", url);
[email protected]91621872013-10-08 04:04:592494 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2495 DidStopLoading(render_view_host));
2496 }
[email protected]66798902013-10-01 18:40:162497
2498 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212499 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2500 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542501 if (details)
[email protected]8ff00d72012-10-23 19:12:212502 det = Details<LoadNotificationDetails>(details);
2503 NotificationService::current()->Notify(
2504 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542505}
2506
[email protected]b172aee2012-04-10 17:05:262507void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212508 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322509 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562510 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322511 // Clear the status bubble. This is a workaround for a bug where WebKit
2512 // doesn't let us know that the cursor left an element during a
2513 // transition (this is also why the mouse cursor remains as a hand after
2514 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2515 // clear the bubble when a user navigates to a named anchor in the same
2516 // page.
[email protected]36fc0392011-12-25 03:59:512517 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322518 }
2519
[email protected]a6e82fc2010-02-24 22:28:142520 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472521 // Once the main frame is navigated, we're no longer considered to have
2522 // displayed insecure content.
2523 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352524 SSLManager::NotifySSLInternalStateChanged(
2525 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172526 }
[email protected]ce5c4502009-05-06 16:46:112527
[email protected]3c9e1872010-11-18 16:17:492528 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252529 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042530 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322531}
2532
[email protected]b172aee2012-04-10 17:05:262533void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322534 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212535 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322536 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112537 // If we navigate off the page, close all JavaScript dialogs.
2538 if (dialog_manager_ && !details.is_in_page)
2539 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322540
[email protected]3c9e1872010-11-18 16:17:492541 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252542 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042543 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322544}
2545
[email protected]2f7b3c5a2013-06-21 04:59:252546bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292547 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2548 // still be used for a normal web site.
2549 if (url == GURL(kAboutBlankURL))
2550 return false;
2551
2552 // The embedder will then have the opportunity to determine if the URL
2553 // should "use up" the SiteInstance.
2554 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252555}
2556
[email protected]b172aee2012-04-10 17:05:262557void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462558 // If we are creating a RVH for a restored controller, then we need to make
2559 // sure the RenderView starts with a next_page_id_ larger than the number
2560 // of restored entries. This must be called before the RenderView starts
2561 // navigating (to avoid a race between the browser updating max_page_id and
2562 // the renderer updating next_page_id_). Because of this, we only call this
2563 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562564 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582565 if (max_restored_page_id >
2566 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2567 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2568 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322569}
2570
[email protected]b172aee2012-04-10 17:05:262571bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262572 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322573 // For file URLs without a title, use the pathname instead. In the case of a
2574 // synthesized title, we don't want the update to count toward the "one set
2575 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262576 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322577 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512578 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242579 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322580 explicit_set = false; // Don't count synthetic titles toward the set limit.
2581 } else {
[email protected]acafd272011-07-26 17:35:572582 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322583 explicit_set = true;
2584 }
2585
[email protected]987fc3a2011-05-26 14:18:092586 // If a page is created via window.open and never navigated,
2587 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552588 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092589 if (entry) {
[email protected]36fc0392011-12-25 03:59:512590 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092591 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322592
[email protected]36fc0392011-12-25 03:59:512593 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092594 } else {
2595 if (page_title_when_no_navigation_entry_ == final_title)
2596 return false; // Nothing changed, don't bother.
2597
2598 page_title_when_no_navigation_entry_ = final_title;
2599 }
[email protected]420ae012009-04-24 05:16:322600
[email protected]420ae012009-04-24 05:16:322601 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232602 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322603
[email protected]66798902013-10-01 18:40:162604 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532605 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162606
2607 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212608 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462609 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212610 NotificationService::current()->Notify(
2611 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2612 Source<WebContents>(this),
2613 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042614
[email protected]420ae012009-04-24 05:16:322615 return true;
2616}
2617
[email protected]7b712ee22013-10-03 00:57:282618void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2619 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322620 // After sending out a swap notification, we need to send a disconnect
2621 // notification so that clients that pick up a pointer to |this| can NULL the
2622 // pointer. See Bug 1230284.
2623 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112624 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282625 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112626
2627 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282628 std::pair<RenderViewHost*, RenderViewHost*> details =
2629 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212630 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282631 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212632 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282633 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392634
2635 // Ensure that the associated embedder gets cleared after a RenderViewHost
2636 // gets swapped, so we don't reuse the same embedder next time a
2637 // RenderViewHost is attached to this WebContents.
2638 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322639}
2640
[email protected]da7a7182013-09-06 08:11:112641// TODO(avi): Remove this entire function because this notification is already
2642// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262643void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322644 if (!notify_disconnection_)
2645 return;
2646
2647 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212648 NotificationService::current()->Notify(
2649 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2650 Source<WebContents>(this),
2651 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322652}
2653
[email protected]cbb1ef592013-06-05 19:49:462654void WebContentsImpl::NotifyNavigationEntryCommitted(
2655 const LoadCommittedDetails& load_details) {
2656 FOR_EACH_OBSERVER(
2657 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2658}
2659
[email protected]f114fa42013-12-06 17:06:442660bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2661 const IPC::Message& message) {
2662 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312663}
2664
[email protected]b849847b2013-12-10 21:57:582665void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2666 // Note this is only for subframes, the notification for the main frame
2667 // happens in RenderViewCreated.
2668 FOR_EACH_OBSERVER(WebContentsObserver,
2669 observers_,
2670 RenderFrameCreated(render_frame_host));
2671}
2672
2673void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2674 FOR_EACH_OBSERVER(WebContentsObserver,
2675 observers_,
2676 RenderFrameDeleted(render_frame_host));
2677}
2678
[email protected]a09d53ce2014-01-31 00:46:422679void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302680 if (delegate_)
2681 delegate_->WorkerCrashed(this);
2682}
2683
[email protected]a09d53ce2014-01-31 00:46:422684void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2685 const ContextMenuParams& params) {
2686 // Allow WebContentsDelegates to handle the context menu operation first.
2687 if (delegate_ && delegate_->HandleContextMenu(params))
2688 return;
2689
2690 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2691}
2692
[email protected]a86c0e962013-12-17 17:10:392693WebContents* WebContentsImpl::GetAsWebContents() {
2694 return this;
2695}
2696
[email protected]5a3bdf52012-05-24 15:12:572697RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2698 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322699}
2700
[email protected]8d3347f2009-07-09 22:00:212701RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262702WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212703 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212704}
2705
[email protected]8ff00d72012-10-23 19:12:212706RendererPreferences WebContentsImpl::GetRendererPrefs(
2707 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462708 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512709}
2710
[email protected]b172aee2012-04-10 17:05:262711gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172712 if (delegate_)
2713 return delegate_->GetRootWindowResizerRect();
2714 return gfx::Rect();
2715}
2716
[email protected]7a846df2012-09-20 19:17:392717void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272718 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392719 browser_plugin_embedder_.reset();
2720}
2721
[email protected]b172aee2012-04-10 17:05:262722void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442723 // Don't send notifications if we are just creating a swapped-out RVH for
2724 // the opener chain. These won't be used for view-source or WebUI, so it's
2725 // ok to return early.
2726 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2727 return;
2728
[email protected]86f98a22013-03-20 14:35:002729 if (delegate_)
2730 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082731
[email protected]8ff00d72012-10-23 19:12:212732 NotificationService::current()->Notify(
2733 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2734 Source<WebContents>(this),
2735 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322736
2737 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352738 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212739 if (GetRenderManager()->pending_web_ui())
2740 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322741
[email protected]6286a372013-10-09 04:03:272742 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332743 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322744 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182745 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582746 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322747 }
[email protected]0666aef2009-05-13 19:48:082748
[email protected]60780f412013-02-25 16:34:102749 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262750
2751 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252752 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582753
2754 // We tell the observers now instead of when the main RenderFrameHostImpl is
2755 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2756 // frame would be dropped because it's not created yet).
2757 RenderFrameHost* main_frame = GetMainFrame();
2758 FOR_EACH_OBSERVER(
2759 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322760}
2761
[email protected]b172aee2012-04-10 17:05:262762void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522763 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322764 // Don't notify the world, since this came from a renderer in the
2765 // background.
2766 return;
2767 }
2768
[email protected]da7a7182013-09-06 08:11:112769 notify_disconnection_ = true;
2770 // TODO(avi): Remove. http://crbug.com/170921
2771 NotificationService::current()->Notify(
2772 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2773 Source<WebContents>(this),
2774 NotificationService::NoDetails());
2775
[email protected]be1f56ab2011-12-22 06:55:312776 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232777 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302778
2779 // Restore the focus to the tab (otherwise the focus will be on the top
2780 // window).
[email protected]484ae5912010-09-29 19:16:142781 if (was_crashed && !FocusLocationBarByDefault() &&
2782 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062783 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142784 }
[email protected]32ded2212011-11-10 18:51:432785
[email protected]d8c660432011-12-22 20:51:252786 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322787}
2788
[email protected]ec6a7eb2013-04-22 17:34:222789void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2790 base::TerminationStatus status,
2791 int error_code) {
[email protected]151a63d2011-12-20 22:32:522792 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322793 // The pending page's RenderViewHost is gone.
2794 return;
2795 }
2796
[email protected]d9030b82013-07-19 08:26:062797 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592798 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322799 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232800 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312801 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322802
[email protected]d8c660432011-12-22 20:51:252803 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272804 observers_,
[email protected]58d5cfe2013-07-10 02:40:522805 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322806}
2807
[email protected]b172aee2012-04-10 17:05:262808void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062809 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212810 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252811 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062812}
2813
[email protected]b172aee2012-04-10 17:05:262814void WebContentsImpl::DidNavigate(
2815 RenderViewHost* rvh,
[email protected]a1b99262013-12-27 21:56:222816 const ViewHostMsg_FrameNavigate_Params& orig_params) {
2817 ViewHostMsg_FrameNavigate_Params params(orig_params);
2818 bool use_site_per_process =
2819 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess);
[email protected]9b159a52013-10-03 17:24:552820 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2821 // First navigation should be a main frame navigation.
[email protected]a1b99262013-12-27 21:56:222822 // TODO(creis): This DCHECK is currently disabled for --site-per-process
2823 // because cross-process subframe navigations still have a main frame
2824 // PageTransition.
2825 if (!use_site_per_process)
2826 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552827 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122828 }
2829
[email protected]a1b99262013-12-27 21:56:222830 // When using --site-per-process, look up the FrameTreeNode ID that the
2831 // renderer-specific frame ID corresponds to.
2832 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id();
2833 if (use_site_per_process) {
2834 FrameTreeNode* source_node = frame_tree_.FindByFrameID(params.frame_id);
2835 if (source_node)
2836 frame_tree_node_id = source_node->frame_tree_node_id();
2837
2838 // TODO(creis): In the short term, cross-process subframe navigations are
2839 // happening in the pending RenderViewHost's top-level frame. (We need to
2840 // both mirror the frame tree and get the navigation to occur in the correct
2841 // subframe to fix this.) Until then, we should check whether we have a
2842 // pending NavigationEntry with a frame ID and if so, treat the
2843 // cross-process "main frame" navigation as a subframe navigation. This
2844 // limits us to a single cross-process subframe per RVH, and it affects
2845 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and
2846 // OnDidFinishLoad.
2847 NavigationEntryImpl* pending_entry =
2848 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
2849 int root_ftn_id = frame_tree_.root()->frame_tree_node_id();
2850 if (pending_entry &&
2851 pending_entry->frame_tree_node_id() != -1 &&
2852 pending_entry->frame_tree_node_id() != root_ftn_id) {
2853 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
2854 frame_tree_node_id = pending_entry->frame_tree_node_id();
2855 }
2856 }
2857
[email protected]e3d92a7f2013-01-10 02:35:052858 if (PageTransitionIsMainFrame(params.transition)) {
2859 // When overscroll navigation gesture is enabled, a screenshot of the page
2860 // in its current state is taken so that it can be used during the
2861 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362862 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052863 // WebContents::GetRenderViewHost to return the new host, instead of the one
2864 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482865 if (delegate_ && delegate_->CanOverscrollContent())
2866 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052867
[email protected]a1b99262013-12-27 21:56:222868 if (!use_site_per_process)
2869 GetRenderManager()->DidNavigateMainFrame(rvh);
2870 }
2871
2872 // When using --site-per-process, we notify the RFHM for all navigations,
2873 // not just main frame navigations.
2874 if (use_site_per_process) {
2875 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
2876 // TODO(creis): Rename to DidNavigateFrame.
2877 frame->render_manager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052878 }
[email protected]8030f012009-09-25 18:09:372879
[email protected]434f69f2012-02-06 21:56:522880 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252881 // assigning a site is not necessary for this URL. In that case, the
2882 // SiteInstance can still be considered unused until a navigation to a real
2883 // page.
[email protected]434f69f2012-02-06 21:56:522884 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252885 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332886 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522887 }
[email protected]420ae012009-04-24 05:16:322888
2889 // Need to update MIME type here because it's referred to in
2890 // UpdateNavigationCommands() called by RendererDidNavigate() to
2891 // determine whether or not to enable the encoding menu.
2892 // It's updated only for the main frame. For a subframe,
2893 // RenderView::UpdateURL does not set params.contents_mime_type.
2894 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2895 // TODO(jungshik): Add a test for the encoding menu to avoid
2896 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212897 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322898 contents_mime_type_ = params.contents_mime_type;
2899
[email protected]8ff00d72012-10-23 19:12:212900 LoadCommittedDetails details;
[email protected]a1b99262013-12-27 21:56:222901 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details);
[email protected]3e90d4a2009-07-03 17:38:392902
[email protected]1ae93fb2013-06-14 03:38:562903 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2904 // us estimate our process count for implementing OOP iframes.
2905 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552906 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562907
[email protected]a9c0bfe2010-09-17 08:35:222908 // Send notification about committed provisional loads. This notification is
2909 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2910 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212911 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072912 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2913 // that is not recorded in the navigation history. For the purpose of
2914 // tracking navigation events, we treat this event as a sub frame navigation
2915 // event.
2916 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212917 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222918 // Whether or not a page transition was triggered by going backward or
2919 // forward in the history is only stored in the navigation controller's
2920 // entry list.
2921 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272922 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212923 PAGE_TRANSITION_FORWARD_BACK)) {
2924 transition_type = PageTransitionFromInt(
2925 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222926 }
[email protected]0d60f0192011-04-14 12:40:102927 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252928 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442929 DidCommitProvisionalLoadForFrame(
2930 params.frame_id,
2931 params.frame_unique_name,
2932 is_main_frame,
2933 params.url,
2934 transition_type,
2935 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222936 }
2937
[email protected]76543b92009-08-31 17:27:452938 if (!did_navigate)
2939 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322940
2941 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2942 // for the appropriate notification (best) or you can add it to
2943 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2944 // necessary, please).
2945
2946 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002947 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322948 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002949 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512950 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002951 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2952 }
[email protected]93f230e02011-06-01 14:40:002953 }
[email protected]420ae012009-04-24 05:16:322954 DidNavigateAnyFramePostCommit(rvh, details, params);
2955}
2956
[email protected]b172aee2012-04-10 17:05:262957void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2958 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042959 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152960 // Ensure that this state update comes from either the active RVH or one of
2961 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412962 // TODO(nasko): This should go through RenderFrameHost.
2963 // TODO(creis): We can't update state for cross-process subframes until we
2964 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2965 if (rvh != GetRenderViewHost() &&
2966 !GetRenderManager()->IsRVHOnSwappedOutList(
2967 static_cast<RenderViewHostImpl*>(rvh)))
2968 return;
[email protected]420ae012009-04-24 05:16:322969
2970 // We must be prepared to handle state updates for any page, these occur
2971 // when the user is scrolling and entering form data, as well as when we're
2972 // leaving a page, in which case our state may have already been moved to
2973 // the next page. The navigation controller will look up the appropriate
2974 // NavigationEntry and update it when it is notified via the delegate.
2975
2976 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582977 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322978 if (entry_index < 0)
2979 return;
[email protected]10f417c52011-12-28 21:04:232980 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322981
[email protected]691aa2f2013-05-28 22:52:042982 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322983 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042984 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322985 controller_.NotifyEntryChanged(entry, entry_index);
2986}
2987
[email protected]b172aee2012-04-10 17:05:262988void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2989 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262990 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262991 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322992 // If we have a title, that's a pretty good indication that we've started
2993 // getting useful data.
2994 SetNotWaitingForResponse();
2995
[email protected]73eb2602012-02-09 19:50:552996 // Try to find the navigation entry, which might not be the current one.
2997 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232998 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582999 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093000
[email protected]73eb2602012-02-09 19:50:553001 // We can handle title updates when we don't have an entry in
3002 // UpdateTitleForEntry, but only if the update is from the current RVH.
3003 if (!entry && rvh != GetRenderViewHost())
3004 return;
3005
[email protected]a49e10b2011-08-01 23:57:463006 // TODO(evan): make use of title_direction.
3007 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093008 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323009 return;
3010
3011 // Broadcast notifications when the UI should be updated.
3012 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213013 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323014}
3015
[email protected]b172aee2012-04-10 17:05:263016void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3017 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313018 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323019}
3020
[email protected]b172aee2012-04-10 17:05:263021void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513022 if (delegate_)
3023 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323024}
3025
[email protected]b172aee2012-04-10 17:05:263026void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103027#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293028 // The UI may be in an event-tracking loop, such as between the
3029 // mouse-down and mouse-up in text selection or a button click.
3030 // Defer the close until after tracking is complete, so that we
3031 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293032 // TODO(shess): This could get more fine-grained. For instance,
3033 // closing a tab in another window while selecting text in the
3034 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103035 if (view_->IsEventTracking()) {
3036 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293037 return;
3038 }
[email protected]60780f412013-02-25 16:34:103039#endif
[email protected]07707302009-11-06 00:50:293040
[email protected]420ae012009-04-24 05:16:323041 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523042 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513043 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323044}
3045
[email protected]b172aee2012-04-10 17:05:263046void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523047 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513048 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283049
3050 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213051 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573052}
3053
[email protected]b172aee2012-04-10 17:05:263054void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513055 if (delegate_ && delegate_->IsPopupOrPanel(this))
3056 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323057}
3058
[email protected]8ff00d72012-10-23 19:12:213059void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593060 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323061}
3062
[email protected]8ff00d72012-10-23 19:12:213063void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323064 scoped_ptr<LoadNotificationDetails> details;
3065
[email protected]9595fd82013-04-19 21:28:493066 // Use the last committed entry rather than the active one, in case a
3067 // pending entry has been created.
3068 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203069 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493070
[email protected]420ae012009-04-24 05:16:323071 // An entry may not exist for a stop when loading an initial blank page or
3072 // if an iframe injected by script into a blank page finishes loading.
3073 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203074 base::TimeDelta elapsed =
3075 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323076
3077 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513078 entry->GetVirtualURL(),
3079 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323080 elapsed,
3081 &controller_,
3082 controller_.GetCurrentEntryIndex()));
3083 }
3084
[email protected]91621872013-10-08 04:04:593085 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323086}
3087
[email protected]b172aee2012-04-10 17:05:263088void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163089 controller_.DiscardNonCommittedEntries();
3090
3091 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213092 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163093}
3094
[email protected]b172aee2012-04-10 17:05:263095void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513096 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133097 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403098}
3099
[email protected]7cc78902012-12-06 02:32:263100void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393101 if (opener_) {
3102 // Clear our opener so that future cross-process navigations don't have an
3103 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103104 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393105 opener_ = NULL;
3106 }
[email protected]7cc78902012-12-06 02:32:263107
3108 // Notify all swapped out RenderViewHosts for this tab. This is important
3109 // in case we go back to them, or if another window in those processes tries
3110 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213111 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263112}
3113
[email protected]59167c22013-06-03 18:07:323114void WebContentsImpl::DidAccessInitialDocument() {
3115 // Update the URL display.
3116 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3117}
3118
[email protected]87717d0e2012-04-26 02:58:433119void WebContentsImpl::DocumentAvailableInMainFrame(
3120 RenderViewHost* render_view_host) {
3121 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3122 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103123}
3124
[email protected]b172aee2012-04-10 17:05:263125void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083126 RenderViewHost* render_view_host,
3127 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093128 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3129 DocumentOnLoadCompletedInMainFrame(page_id));
3130
3131 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213132 NotificationService::current()->Notify(
3133 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3134 Source<WebContents>(this),
3135 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083136}
3137
[email protected]196159d2012-05-04 17:26:543138void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3139 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213140 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263141 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183142 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523143 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303144 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543145 // If this came from a swapped out RenderViewHost, we only allow the request
3146 // if we are still in the same BrowsingInstance.
3147 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3148 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3149 return;
3150 }
3151
[email protected]4ad5d77d2011-12-03 02:00:483152 // Delegate to RequestTransferURL because this is just the generic
3153 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573154 // TODO(creis): Pass the redirect_chain into this method to support client
3155 // redirects. http://crbug.com/311721.
3156 std::vector<GURL> redirect_chain;
3157 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3158 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523159 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483160}
3161
[email protected]b172aee2012-04-10 17:05:263162void WebContentsImpl::RequestTransferURL(
3163 const GURL& url,
[email protected]f8872902013-10-30 03:18:573164 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213165 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573166 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263167 WindowOpenDisposition disposition,
3168 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183169 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523170 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303171 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203172 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123173 GURL dest_url(url);
3174 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553175 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123176 dest_url = GURL(kAboutBlankURL);
3177
[email protected]a1b99262013-12-27 21:56:223178 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3179 int64 frame_tree_node_id = -1;
3180 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3181 source_frame_id != -1) {
3182 FrameTreeNode* source_node = frame_tree_.FindByFrameID(source_frame_id);
3183 if (source_node)
3184 frame_tree_node_id = source_node->frame_tree_node_id();
3185 }
[email protected]c80297782013-11-21 07:10:163186 OpenURLParams params(dest_url, referrer, source_frame_id,
3187 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573188 page_transition, true /* is_renderer_initiated */);
3189 if (redirect_chain.size() > 0)
3190 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553191 params.transferred_global_request_id = old_request_id;
3192 params.should_replace_current_entry = should_replace_current_entry;
3193 params.user_gesture = user_gesture;
3194
[email protected]fa944cb82013-11-15 17:51:213195 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573196 // Web UI pages sometimes want to override the page transition type for
3197 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3198 // automatically generated suggestions). We don't override other types
3199 // like TYPED because they have different implications (e.g., autocomplete).
3200 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213201 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553202
[email protected]e0112912011-02-02 22:54:353203 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163204 // want web sites to see a referrer of "chrome://blah" (and some
3205 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323206 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553207 params.referrer = Referrer();
3208
3209 // Navigations in Web UI pages count as browser-initiated navigations.
3210 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583211 }
[email protected]44d0930a2013-10-28 18:53:553212
3213 new_contents = OpenURL(params);
3214
[email protected]ae5184d62011-10-06 19:25:583215 if (new_contents) {
3216 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253217 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583218 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123219 dest_url,
[email protected]ae5184d62011-10-06 19:25:583220 referrer,
3221 disposition,
[email protected]44d0930a2013-10-28 18:53:553222 params.transition,
[email protected]ae5184d62011-10-06 19:25:583223 source_frame_id));
[email protected]420ae012009-04-24 05:16:323224 }
3225}
3226
[email protected]e1c3a552012-05-04 20:51:323227void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3228 // Tell the active RenderViewHost to run unload handlers and close, as long
3229 // as the request came from a RenderViewHost in the same BrowsingInstance.
3230 // In most cases, we receive this from a swapped out RenderViewHost.
3231 // It is possible to receive it from one that has just been swapped in,
3232 // in which case we might as well deliver the message anyway.
3233 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3234 GetRenderViewHost()->ClosePage();
3235}
3236
[email protected]f546640b2012-05-15 00:03:493237void WebContentsImpl::RouteMessageEvent(
3238 RenderViewHost* rvh,
3239 const ViewMsg_PostMessage_Params& params) {
3240 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363241 // came from a RenderViewHost in the same BrowsingInstance or if this
3242 // WebContents is dedicated to a browser plugin guest.
3243 // Note: This check means that an embedder could theoretically receive a
3244 // postMessage from anyone (not just its own guests). However, this is
3245 // probably not a risk for apps since other pages won't have references
3246 // to App windows.
3247 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3248 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493249 return;
3250
3251 ViewMsg_PostMessage_Params new_params(params);
3252
[email protected]0bc7f3542013-10-21 15:05:533253 if (!params.message_port_ids.empty()) {
3254 MessagePortMessageFilter* message_port_message_filter =
3255 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3256 ->message_port_message_filter();
3257 std::vector<int> new_routing_ids(params.message_port_ids.size());
3258 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3259 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3260 MessagePortService::GetInstance()->UpdateMessagePort(
3261 params.message_port_ids[i],
3262 message_port_message_filter,
3263 new_routing_ids[i]);
3264 }
3265 new_params.new_routing_ids = new_routing_ids;
3266 }
3267
[email protected]f546640b2012-05-15 00:03:493268 // If there is a source_routing_id, translate it to the routing ID for
3269 // the equivalent swapped out RVH in the target process. If we need
3270 // to create a swapped out RVH for the source tab, we create its opener
3271 // chain as well, since those will also be accessible to the target page.
3272 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3273 // Try to look up the WebContents for the source page.
3274 WebContentsImpl* source_contents = NULL;
3275 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3276 rvh->GetProcess()->GetID(), params.source_routing_id);
3277 if (source_rvh) {
3278 source_contents = static_cast<WebContentsImpl*>(
3279 source_rvh->GetDelegate()->GetAsWebContents());
3280 }
3281
3282 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363283 if (GetBrowserPluginGuest()) {
3284 // We create a swapped out RenderView for the embedder in the guest's
3285 // render process but we intentionally do not expose the embedder's
3286 // opener chain to it.
3287 new_params.source_routing_id =
3288 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3289 } else {
3290 new_params.source_routing_id =
3291 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3292 }
[email protected]f546640b2012-05-15 00:03:493293 } else {
3294 // We couldn't find it, so don't pass a source frame.
3295 new_params.source_routing_id = MSG_ROUTING_NONE;
3296 }
3297 }
3298
3299 // In most cases, we receive this from a swapped out RenderViewHost.
3300 // It is possible to receive it from one that has just been swapped in,
3301 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183302 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493303}
3304
[email protected]b172aee2012-04-10 17:05:263305void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343306 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263307 const base::string16& message,
3308 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323309 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213310 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323311 IPC::Message* reply_msg,
3312 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073313 // Suppress JavaScript dialogs when requested. Also suppress messages when
3314 // showing an interstitial as it's shown over the previous page and we don't
3315 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503316 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583317 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273318 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073319 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523320 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153321 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323322
3323 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213324 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433325 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153326 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3327 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433328 this,
3329 frame_url.GetOrigin(),
3330 accept_lang,
3331 javascript_message_type,
3332 message,
[email protected]51da7e32012-01-30 19:24:523333 default_prompt,
[email protected]b172aee2012-04-10 17:05:263334 base::Bind(&WebContentsImpl::OnDialogClosed,
3335 base::Unretained(this),
3336 rvh,
3337 reply_msg),
[email protected]51da7e32012-01-30 19:24:523338 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323339 }
[email protected]3ab9cb82011-06-03 18:02:073340
[email protected]6dd2f1e2013-09-11 15:06:013341 *did_suppress_message = suppress_this_message;
3342
[email protected]3ab9cb82011-06-03 18:02:073343 if (suppress_this_message) {
3344 // If we are suppressing messages, just reply as if the user immediately
3345 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263346 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073347 }
3348
[email protected]6dd2f1e2013-09-11 15:06:013349 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3350 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323351}
3352
[email protected]b172aee2012-04-10 17:05:263353void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263354 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263355 bool is_reload,
3356 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583357 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513358 if (delegate_)
3359 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073360
3361 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583362 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073363 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523364 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153365 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153366 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343367 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263368 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503369 return;
3370 }
[email protected]3ab9cb82011-06-03 18:02:073371
[email protected]7ab1e7d62009-10-14 23:32:013372 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153373 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3374 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323375 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263376 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523377 reply_msg));
[email protected]420ae012009-04-24 05:16:323378}
3379
[email protected]a796f202012-05-30 14:14:253380bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263381 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253382 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263383 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253384 if (!delegate_)
3385 return false;
3386 return delegate_->AddMessageToConsole(this, level, message, line_no,
3387 source_id);
3388}
3389
[email protected]b172aee2012-04-10 17:05:263390WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273391 // We want to base the page config off of the actual URL, rather than the
3392 // virtual URL.
3393 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3394 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003395 GURL url = controller_.GetActiveEntry()
3396 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153397
[email protected]fa944cb82013-11-15 17:51:213398 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323399}
3400
[email protected]0eba810b2012-10-18 03:19:363401int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213402 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413403 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3404 true, true);
[email protected]0eba810b2012-10-18 03:19:363405}
3406
[email protected]b172aee2012-04-10 17:05:263407void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273408 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253409 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223410
[email protected]ea114722012-03-12 01:11:253411 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173412 if (rdh) // NULL in unittests.
3413 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253414}
3415
[email protected]b172aee2012-04-10 17:05:263416void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443417 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253418 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443419}
3420
[email protected]b172aee2012-04-10 17:05:263421void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563422 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263423 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153424 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523425 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153426 return;
3427
[email protected]9f76c1e2012-03-05 15:15:583428 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3429
[email protected]e5fc1632011-08-08 07:51:533430 // Ignore renderer unresponsive event if debugger is attached to the tab
3431 // since the event may be a result of the renderer sitting on a breakpoint.
3432 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363433 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533434 return;
3435
[email protected]2e9d79f2013-08-16 05:45:563436 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323437 // Hang occurred while firing the beforeunload/unload handler.
3438 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583439 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323440
[email protected]fa944cb82013-11-15 17:51:213441 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323442 return;
3443
3444 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563445 // nothing we can do to recover. If the hang is in the beforeunload handler,
3446 // pretend the beforeunload listeners have all fired and allow the delegate
3447 // to continue closing; the user will not have the option of cancelling the
3448 // close. Otherwise, pretend the unload listeners have all fired and close
3449 // the tab.
3450 bool close = true;
3451 if (is_during_beforeunload) {
3452 delegate_->BeforeUnloadFired(this, true, &close);
3453 }
3454 if (close)
3455 Close(rvh);
[email protected]420ae012009-04-24 05:16:323456 return;
3457 }
3458
[email protected]9f76c1e2012-03-05 15:15:583459 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473460 return;
3461
[email protected]6934a702011-12-20 00:04:513462 if (delegate_)
3463 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323464}
3465
[email protected]b172aee2012-04-10 17:05:263466void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513467 if (delegate_)
3468 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323469}
3470
[email protected]b172aee2012-04-10 17:05:263471void WebContentsImpl::LoadStateChanged(
3472 const GURL& url,
3473 const net::LoadStateWithParam& load_state,
3474 uint64 upload_position,
3475 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323476 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563477 upload_position_ = upload_position;
3478 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503479 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213480 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303481 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213482 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323483 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463484 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213485 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463486 }
[email protected]420ae012009-04-24 05:16:323487}
3488
[email protected]b172aee2012-04-10 17:05:263489void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553490 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323491 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123492 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3493 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513494 if (delegate_)
3495 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093496 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323497}
3498
[email protected]58d5cfe2013-07-10 02:40:523499void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543500 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233501 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223502 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543503}
3504
[email protected]b172aee2012-04-10 17:05:263505void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103506 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213507 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263508 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3509 // here during container initialization and normal window size will be set
3510 // later. In case of tab duplication this resizing to 0x0 prevents setting
3511 // normal size later so just ignore it.
3512 if (!size.IsEmpty())
3513 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323514}
3515
[email protected]af905902013-10-01 21:38:513516void WebContentsImpl::CancelModalDialogsForRenderManager() {
3517 // We need to cancel modal dialogs when doing a process swap, since the load
3518 // deferrer would prevent us from swapping out.
3519 if (dialog_manager_)
3520 dialog_manager_->CancelActiveAndPendingDialogs(this);
3521}
3522
[email protected]7b712ee22013-10-03 00:57:283523void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3524 RenderViewHost* new_host) {
3525 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083526
3527 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003528 if (delegate_)
3529 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393530
[email protected]7b712ee22013-10-03 00:57:283531 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543532}
3533
[email protected]14392a52012-05-02 20:28:443534int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3535 SiteInstance* instance) {
3536 if (!opener_)
3537 return MSG_ROUTING_NONE;
3538
3539 // Recursively create RenderViews for anything else in the opener chain.
3540 return opener_->CreateOpenerRenderViews(instance);
3541}
3542
3543int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3544 int opener_route_id = MSG_ROUTING_NONE;
3545
3546 // If this tab has an opener, ensure it has a RenderView in the given
3547 // SiteInstance as well.
3548 if (opener_)
3549 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3550
[email protected]45a22ad2013-02-21 03:25:003551 // If any of the renderers (current, pending, or swapped out) for this
3552 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213553 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3554 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373555
[email protected]fa944cb82013-11-15 17:51:213556 if (GetRenderManager()->pending_render_view_host() &&
3557 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3558 instance)
3559 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003560
[email protected]fa944cb82013-11-15 17:51:213561 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373562 instance);
3563 if (rvh)
3564 return rvh->GetRoutingID();
3565
[email protected]14392a52012-05-02 20:28:443566 // Create a swapped out RenderView in the given SiteInstance if none exists,
3567 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413568 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3569 true, true);
[email protected]14392a52012-05-02 20:28:443570}
3571
[email protected]b172aee2012-04-10 17:05:263572NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193573 return GetController();
[email protected]3a3d47472010-07-15 21:03:543574}
3575
[email protected]b172aee2012-04-10 17:05:263576WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563577 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323578}
3579
[email protected]10f417c52011-12-28 21:04:233580NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263581 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323582 return controller_.GetLastCommittedEntry();
3583}
3584
[email protected]b172aee2012-04-10 17:05:263585bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163586 RenderViewHost* render_view_host,
3587 int opener_route_id,
3588 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033589 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443590 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163591 RenderWidgetHostView* rwh_view;
3592 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3593 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3594 // case this because RWH is still a base class of RenderViewHost, and child
3595 // frame RWHVs are unique in that they do not have their own WebContents.
3596 if (frame_connector) {
3597 RenderWidgetHostViewChildFrame* rwh_view_child =
3598 new RenderWidgetHostViewChildFrame(render_view_host);
3599 frame_connector->set_view(rwh_view_child);
3600 rwh_view = rwh_view_child;
3601 } else {
3602 rwh_view = view_->CreateViewForWidget(render_view_host);
3603 }
[email protected]1a98a932009-11-17 00:12:523604
[email protected]420ae012009-04-24 05:16:323605 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443606 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213607 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323608
[email protected]74ce1ad2011-12-16 21:51:463609 // Make sure we use the correct starting page_id in the new RenderView.
3610 UpdateMaxPageIDIfNecessary(render_view_host);
3611 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583612 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463613
[email protected]9f76c1e2012-03-05 15:15:583614 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263615 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493616 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133617 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523618 return false;
[email protected]14392a52012-05-02 20:28:443619 }
[email protected]a4127722011-04-27 23:13:523620
[email protected]a220b5932013-09-21 03:47:443621#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503622 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3623 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443624 if (rwh_view) {
3625 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3626 render_widget_host->WasResized();
3627 }
[email protected]f8233cc2011-05-31 20:24:503628#endif
3629
[email protected]420ae012009-04-24 05:16:323630 return true;
3631}
3632
[email protected]7d244f12013-08-22 21:41:513633#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183634base::android::ScopedJavaLocalRef<jobject>
3635WebContentsImpl::GetJavaWebContents() {
3636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3637
3638 WebContentsAndroid* web_contents_android =
3639 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3640 if (!web_contents_android) {
3641 web_contents_android = new WebContentsAndroid(this);
3642 SetUserData(kWebContentsAndroidKey, web_contents_android);
3643 }
3644 return web_contents_android->GetJavaObject();
3645}
3646
[email protected]7d244f12013-08-22 21:41:513647bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3648 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163649 MSG_ROUTING_NONE,
3650 NULL);
[email protected]7d244f12013-08-22 21:41:513651}
3652#endif
3653
[email protected]b172aee2012-04-10 17:05:263654void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3655 IPC::Message* reply_msg,
3656 bool success,
[email protected]fcf75d42013-12-03 20:11:263657 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543658 if (is_showing_before_unload_dialog_ && !success) {
3659 // If a beforeunload dialog is canceled, we need to stop the throbber from
3660 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293661 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353662 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103663
[email protected]6d65a462013-06-21 21:29:123664 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3665 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543666 }
3667 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583668 static_cast<RenderViewHostImpl*>(
3669 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543670}
3671
[email protected]b172aee2012-04-10 17:05:263672void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213673 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123674 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103675}
[email protected]f45d2a72010-03-08 23:28:353676
[email protected]b172aee2012-04-10 17:05:263677void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103678 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443679 // Can be NULL during tests.
3680 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213681 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363682}
[email protected]9f76c1e2012-03-05 15:15:583683
[email protected]1ac10dca2013-08-20 20:47:043684bool WebContentsImpl::IsHidden() {
3685 return capturer_count_ == 0 && !should_normally_be_visible_;
3686}
3687
[email protected]b0936d22013-11-28 06:47:363688RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213689 return frame_tree_.root()->render_manager();
3690}
3691
[email protected]b172aee2012-04-10 17:05:263692RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583693 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3694}
[email protected]7900bfdb2012-05-24 19:31:243695
[email protected]f8497342013-02-05 22:15:023696BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393697 return browser_plugin_guest_.get();
3698}
3699
[email protected]738f57a2013-06-29 21:06:543700void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3701 CHECK(!browser_plugin_guest_);
3702 browser_plugin_guest_.reset(guest);
3703}
3704
[email protected]f8497342013-02-05 22:15:023705BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393706 return browser_plugin_embedder_.get();
3707}
[email protected]8ff00d72012-10-23 19:12:213708
[email protected]8eb04562013-03-06 03:41:143709BrowserPluginGuestManager*
3710 WebContentsImpl::GetBrowserPluginGuestManager() const {
3711 return static_cast<BrowserPluginGuestManager*>(
3712 GetBrowserContext()->GetUserData(
3713 browser_plugin::kBrowserPluginGuestManagerKeyName));
3714}
3715
[email protected]d9030b82013-07-19 08:26:063716void WebContentsImpl::ClearPowerSaveBlockers(
3717 RenderViewHost* render_view_host) {
3718 STLDeleteValues(&power_save_blockers_[render_view_host]);
3719 power_save_blockers_.erase(render_view_host);
3720}
3721
3722void WebContentsImpl::ClearAllPowerSaveBlockers() {
3723 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3724 i != power_save_blockers_.end(); ++i)
3725 STLDeleteValues(&power_save_blockers_[i->first]);
3726 power_save_blockers_.clear();
3727}
3728
[email protected]dc0fd432013-08-27 15:29:213729gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3730 gfx::Size size;
3731 if (delegate_)
3732 size = delegate_->GetSizeForNewRenderView(this);
3733 if (size.IsEmpty())
3734 size = view_->GetContainerSize();
3735 return size;
3736}
3737
[email protected]9b159a52013-10-03 17:24:553738void WebContentsImpl::OnFrameRemoved(
3739 RenderViewHostImpl* render_view_host,
3740 int64 frame_id) {
3741 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3742 FrameDetached(render_view_host, frame_id));
3743}
3744
[email protected]8ff00d72012-10-23 19:12:213745} // namespace content