blob: b75d8bab31dbb7b4395ebf787e18656892c0dcf0 [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]2ceee8f2014-01-14 18:02:081159#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411160gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1161 return accessible_parent_;
1162}
1163#endif
1164
[email protected]b172aee2012-04-10 17:05:261165void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431166 if (delegate_)
1167 delegate_->HandleMouseDown();
1168}
1169
[email protected]b172aee2012-04-10 17:05:261170void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481171 if (delegate_)
1172 delegate_->HandleMouseUp();
1173}
1174
[email protected]590a634e2012-07-19 16:38:231175void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481176 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231177 delegate_->HandlePointerActivate();
1178}
1179
1180void WebContentsImpl::HandleGestureBegin() {
1181 if (delegate_)
1182 delegate_->HandleGestureBegin();
1183}
1184
1185void WebContentsImpl::HandleGestureEnd() {
1186 if (delegate_)
1187 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481188}
1189
[email protected]b172aee2012-04-10 17:05:261190void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491191 // This method is being called to enter or leave renderer-initiated fullscreen
1192 // mode. Either way, make sure any existing fullscreen widget is shut down
1193 // first.
1194 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1195 if (widget_view)
1196 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1197
[email protected]8a5e0ca2011-08-25 06:30:471198 if (delegate_)
1199 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1200}
1201
[email protected]b172aee2012-04-10 17:05:261202bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381203 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121204}
1205
[email protected]a9c81f02012-06-01 00:15:441206void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1207 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371208 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441209 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371210 } else {
1211 GotResponseToLockMouseRequest(false);
1212 }
1213}
1214
[email protected]b172aee2012-04-10 17:05:261215void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371216 if (delegate_)
1217 delegate_->LostMouseLock();
1218}
1219
[email protected]bafe6cd2012-05-23 23:09:501220void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201221 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501222 int route_id,
[email protected]227692c52013-05-31 22:43:041223 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131224 const ViewHostMsg_CreateWindow_Params& params,
1225 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501226 // We usually create the new window in the same BrowsingInstance (group of
1227 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551228 // if the opener is being suppressed (in a non-guest), we create a new
1229 // SiteInstance in its own BrowsingInstance.
1230 bool is_guest = GetRenderProcessHost()->IsGuest();
1231
[email protected]04cbd3d2013-12-04 04:58:201232 // If the opener is to be suppressed, the new window can be in any process.
1233 // Since routing ids are process specific, we must not have one passed in
1234 // as argument here.
1235 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1236
[email protected]bafe6cd2012-05-23 23:09:501237 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551238 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571239 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501240 GetSiteInstance();
1241
[email protected]04cbd3d2013-12-04 04:58:201242 // A message to create a new window can only come from the active process for
1243 // this WebContentsImpl instance. If any other process sends the request,
1244 // it is invalid and the process must be terminated.
1245 if (GetRenderProcessHost()->GetID() != render_process_id) {
1246 base::ProcessHandle process_handle =
1247 RenderProcessHost::FromID(render_process_id)->GetHandle();
1248 if (process_handle != base::kNullProcessHandle) {
1249 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391250 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201251 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1252 }
1253 return;
1254 }
1255
[email protected]d1198fd2012-08-13 22:50:191256 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341257 //
1258 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301259 const std::string& partition_id =
1260 GetContentClient()->browser()->
1261 GetStoragePartitionIdForSite(GetBrowserContext(),
1262 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461263 StoragePartition* partition = BrowserContext::GetStoragePartition(
1264 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411265 DOMStorageContextWrapper* dom_storage_context =
1266 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191267 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1268 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1269 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371270
1271 if (delegate_ &&
1272 !delegate_->ShouldCreateWebContents(this,
1273 route_id,
1274 params.window_container_type,
1275 params.frame_name,
1276 params.target_url,
1277 partition_id,
1278 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011279 if (route_id != MSG_ROUTING_NONE &&
1280 !RenderViewHost::FromID(render_process_id, route_id)) {
1281 // If the embedder didn't create a WebContents for this route, we need to
1282 // delete the RenderView that had already been created.
1283 Send(new ViewMsg_Close(route_id));
1284 }
[email protected]dd6730412013-08-14 15:03:371285 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1286 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1287 main_frame_route_id);
1288 return;
1289 }
1290
1291 // Create the new web contents. This will automatically create the new
1292 // WebContentsView. In the future, we may want to create the view separately.
1293 WebContentsImpl* new_contents =
1294 new WebContentsImpl(GetBrowserContext(),
1295 params.opener_suppressed ? NULL : this);
1296
[email protected]d1198fd2012-08-13 22:50:191297 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301298 partition_id,
[email protected]d1198fd2012-08-13 22:50:191299 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461300 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591301 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041302 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551303 if (!is_guest) {
1304 create_params.context = view_->GetNativeView();
1305 create_params.initial_size = view_->GetContainerSize();
1306 } else {
1307 // This makes |new_contents| act as a guest.
1308 // For more info, see comment above class BrowserPluginGuest.
1309 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1310 WebContentsImpl* new_contents_impl =
1311 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461312 BrowserPluginGuest::CreateWithOpener(instance_id,
1313 new_contents_impl->opener() != NULL,
1314 new_contents_impl,
1315 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551316 }
[email protected]1ac10dca2013-08-20 20:47:041317 if (params.disposition == NEW_BACKGROUND_TAB)
1318 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591319 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191320
[email protected]c4538072013-03-18 02:17:551321 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341322 // will be shown immediately).
1323 if (!params.opener_suppressed) {
1324 if (!is_guest) {
1325 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501326
[email protected]d70bea92013-04-05 04:23:341327 // TODO(brettw): It seems bogus that we have to call this function on the
1328 // newly created object and give it one of its own member variables.
1329 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1330 }
[email protected]bafe6cd2012-05-23 23:09:501331 // Save the created window associated with the route so we can show it
1332 // later.
1333 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1334 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101335 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501336 }
1337
1338 if (delegate_) {
1339 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131340 this, params.opener_frame_id, params.frame_name,
1341 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501342 }
1343
1344 if (params.opener_suppressed) {
1345 // When the opener is suppressed, the original renderer cannot access the
1346 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001347 bool was_blocked = false;
1348 if (delegate_) {
1349 gfx::Rect initial_pos;
1350 delegate_->AddNewContents(
1351 this, new_contents, params.disposition, initial_pos,
1352 params.user_gesture, &was_blocked);
1353 }
1354 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211355 OpenURLParams open_params(params.target_url,
1356 Referrer(),
1357 CURRENT_TAB,
1358 PAGE_TRANSITION_LINK,
1359 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301360 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001361 new_contents->OpenURL(open_params);
1362 }
[email protected]bafe6cd2012-05-23 23:09:501363 }
1364}
1365
[email protected]a8504022013-12-04 20:23:511366void WebContentsImpl::CreateNewWidget(int render_process_id,
1367 int route_id,
[email protected]180ef242013-11-07 06:50:461368 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511369 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501370}
1371
[email protected]a8504022013-12-04 20:23:511372void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1373 int route_id) {
1374 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501375}
1376
[email protected]a8504022013-12-04 20:23:511377void WebContentsImpl::CreateNewWidget(int render_process_id,
1378 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501379 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461380 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211381 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511382 // A message to create a new widget can only come from the active process for
1383 // this WebContentsImpl instance. If any other process sends the request,
1384 // it is invalid and the process must be terminated.
1385 if (process->GetID() != render_process_id) {
1386 base::ProcessHandle process_handle =
1387 RenderProcessHost::FromID(render_process_id)->GetHandle();
1388 if (process_handle != base::kNullProcessHandle) {
1389 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391390 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511391 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1392 }
1393 return;
1394 }
1395
[email protected]bafe6cd2012-05-23 23:09:501396 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041397 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261398 created_widgets_.insert(widget_host);
1399
[email protected]83918ec2013-01-10 15:37:191400 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1401 view_->CreateViewForPopupWidget(widget_host));
1402 if (!widget_view)
1403 return;
[email protected]bafe6cd2012-05-23 23:09:501404 if (!is_fullscreen) {
1405 // Popups should not get activated.
1406 widget_view->SetPopupType(popup_type);
1407 }
1408 // Save the created widget associated with the route so we can show it later.
1409 pending_widget_views_[route_id] = widget_view;
1410
1411#if defined(OS_MACOSX)
1412 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1413 // to allow it to survive the trip without being hosted.
1414 base::mac::NSObjectRetain(widget_view->GetNativeView());
1415#endif
1416}
1417
1418void WebContentsImpl::ShowCreatedWindow(int route_id,
1419 WindowOpenDisposition disposition,
1420 const gfx::Rect& initial_pos,
1421 bool user_gesture) {
1422 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001423 if (contents) {
1424 WebContentsDelegate* delegate = GetDelegate();
1425 if (delegate) {
1426 delegate->AddNewContents(
1427 this, contents, disposition, initial_pos, user_gesture, NULL);
1428 }
1429 }
[email protected]bafe6cd2012-05-23 23:09:501430}
1431
1432void WebContentsImpl::ShowCreatedWidget(int route_id,
1433 const gfx::Rect& initial_pos) {
1434 ShowCreatedWidget(route_id, false, initial_pos);
1435}
1436
1437void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1438 ShowCreatedWidget(route_id, true, gfx::Rect());
1439}
1440
1441void WebContentsImpl::ShowCreatedWidget(int route_id,
1442 bool is_fullscreen,
1443 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501444 RenderWidgetHostViewPort* widget_host_view =
1445 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1446 if (!widget_host_view)
1447 return;
[email protected]4aebbca2013-09-17 22:26:491448 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311449 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1450 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491451 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1452 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1453 delegate_->ToggleFullscreenModeForTab(this, true);
1454 } else {
1455 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491456 }
[email protected]4aebbca2013-09-17 22:26:491457 FOR_EACH_OBSERVER(WebContentsObserver,
1458 observers_,
1459 DidShowFullscreenWidget(route_id));
1460 if (!widget_host_view->HasFocus())
1461 widget_host_view->Focus();
1462 } else {
[email protected]f8497342013-02-05 22:15:021463 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491464 }
[email protected]89054502012-06-03 10:29:241465
1466 RenderWidgetHostImpl* render_widget_host_impl =
1467 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1468 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311469 // Only allow privileged mouse lock for fullscreen render widget, which is
1470 // used to implement Pepper Flash fullscreen.
1471 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501472
1473#if defined(OS_MACOSX)
1474 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1475 // properly embedded (or purposefully ignored) we can release the retain we
1476 // took in CreateNewWidget().
1477 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1478#endif
1479}
1480
1481WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1482 PendingContents::iterator iter = pending_contents_.find(route_id);
1483
1484 // Certain systems can block the creation of new windows. If we didn't succeed
1485 // in creating one, just return NULL.
1486 if (iter == pending_contents_.end()) {
1487 return NULL;
1488 }
1489
1490 WebContentsImpl* new_contents = iter->second;
1491 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101492 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501493
[email protected]d70bea92013-04-05 04:23:341494 // Don't initialize the guest WebContents immediately.
1495 if (new_contents->GetRenderProcessHost()->IsGuest())
1496 return new_contents;
1497
[email protected]bafe6cd2012-05-23 23:09:501498 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1499 !new_contents->GetRenderViewHost()->GetView())
1500 return NULL;
1501
1502 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1503 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1504 return new_contents;
1505}
1506
1507RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1508 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1509 if (iter == pending_widget_views_.end()) {
1510 DCHECK(false);
1511 return NULL;
1512 }
1513
1514 RenderWidgetHostView* widget_host_view = iter->second;
1515 pending_widget_views_.erase(route_id);
1516
1517 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1518 if (!widget_host->GetProcess()->HasConnection()) {
1519 // The view has gone away or the renderer crashed. Nothing to do.
1520 return NULL;
1521 }
1522
1523 return widget_host_view;
1524}
1525
[email protected]f56c7872013-06-18 12:31:571526void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501527 // Allow WebContentsDelegates to handle the context menu operation first.
1528 if (delegate_ && delegate_->HandleContextMenu(params))
1529 return;
1530
[email protected]f56c7872013-06-18 12:31:571531 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501532}
1533
[email protected]f13b4202012-06-12 23:53:231534void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091535 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211536 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231537 if (delegate_)
1538 delegate_->RequestMediaAccessPermission(this, request, callback);
1539 else
[email protected]b5f76742013-04-29 15:05:591540 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231541}
1542
[email protected]cc9200432013-07-23 23:02:401543SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1544 SiteInstance* instance) {
1545 return controller_.GetSessionStorageNamespace(instance);
1546}
1547
[email protected]9b159a52013-10-03 17:24:551548FrameTree* WebContentsImpl::GetFrameTree() {
1549 return &frame_tree_;
1550}
1551
[email protected]edc3af82013-12-12 21:24:071552void WebContentsImpl::OnShowValidationMessage(
1553 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291554 const base::string16& main_text,
1555 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071556 if (delegate_)
1557 delegate_->ShowValidationMessage(
1558 this, anchor_in_root_view, main_text, sub_text);
1559}
1560
1561void WebContentsImpl::OnHideValidationMessage() {
1562 if (delegate_)
1563 delegate_->HideValidationMessage(this);
1564}
1565
1566void WebContentsImpl::OnMoveValidationMessage(
1567 const gfx::Rect& anchor_in_root_view) {
1568 if (delegate_)
1569 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1570}
1571
[email protected]32deec62013-05-15 23:55:041572void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1573 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441574 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041575}
1576
[email protected]b172aee2012-04-10 17:05:261577void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231578 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331579 if (delegate_)
1580 delegate_->UpdatePreferredSize(this, pref_size);
1581}
1582
[email protected]b172aee2012-04-10 17:05:261583void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341584 if (delegate_)
1585 delegate_->ResizeDueToAutoResize(this, new_size);
1586}
1587
[email protected]b172aee2012-04-10 17:05:261588WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201589 if (!delegate_)
1590 return NULL;
[email protected]00c37fc2011-08-02 00:22:501591
[email protected]e5d549d2011-12-28 01:29:201592 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201593 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341594}
1595
[email protected]6b618e62012-08-16 12:59:181596bool WebContentsImpl::Send(IPC::Message* message) {
1597 if (!GetRenderViewHost()) {
1598 delete message;
1599 return false;
1600 }
1601
1602 return GetRenderViewHost()->Send(message);
1603}
1604
[email protected]b172aee2012-04-10 17:05:261605bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501606 NavigationController::ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:201607 return frame_tree_.root()->navigator()->NavigateToPendingEntry(
1608 frame_tree_.GetMainFrame(), reload_type);
[email protected]876bc832010-09-07 16:29:541609}
[email protected]96d185d2009-04-24 03:28:541610
[email protected]a86c0e962013-12-17 17:10:391611void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1612 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441613 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391614 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441615}
1616
[email protected]20ca0382013-02-28 19:50:071617void WebContentsImpl::AttachInterstitialPage(
1618 InterstitialPageImpl* interstitial_page) {
1619 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211620 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291621
1622 // Cancel any visible dialogs so that they don't interfere with the
1623 // interstitial.
1624 if (dialog_manager_)
1625 dialog_manager_->CancelActiveAndPendingDialogs(this);
1626
[email protected]20ca0382013-02-28 19:50:071627 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1628 DidAttachInterstitialPage());
1629}
1630
1631void WebContentsImpl::DetachInterstitialPage() {
1632 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211633 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071634 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1635 DidDetachInterstitialPage());
1636}
1637
[email protected]b172aee2012-04-10 17:05:261638void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331639 const SiteInstance* site_instance,
1640 int history_length,
1641 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411642 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1643 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211644 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191645 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141646 return;
[email protected]9e1ad4b2011-08-14 16:49:191647 }
[email protected]9f76c1e2012-03-05 15:15:581648 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191649 if (!rvh) {
1650 NOTREACHED();
1651 return;
1652 }
[email protected]9f76c1e2012-03-05 15:15:581653 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191654 NOTREACHED();
1655 return;
1656 }
[email protected]6b618e62012-08-16 12:59:181657 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1658 history_length,
1659 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141660}
1661
[email protected]b172aee2012-04-10 17:05:261662void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271663 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211664 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541665 return;
1666 }
[email protected]9f76c1e2012-03-05 15:15:581667 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541668}
1669
[email protected]b172aee2012-04-10 17:05:261670bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211671 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541672}
1673
[email protected]b172aee2012-04-10 17:05:261674InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211675 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221676}
1677
[email protected]b172aee2012-04-10 17:05:261678bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161679 // WebKit creates Document object when MIME type is application/xhtml+xml,
1680 // so we also support this MIME type.
1681 return contents_mime_type_ == "text/html" ||
1682 contents_mime_type_ == "text/xml" ||
1683 contents_mime_type_ == "application/xhtml+xml" ||
1684 contents_mime_type_ == "text/plain" ||
1685 contents_mime_type_ == "text/css" ||
1686 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591690 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161691 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551692 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011693 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141694 return;
[email protected]c7dd2f62011-07-18 15:57:591695 }
1696
1697 Stop();
1698
1699 // Create the save package and possibly prompt the user for the name to save
1700 // the page as. The user prompt is an asynchronous operation that runs on
1701 // another thread.
1702 save_package_ = new SavePackage(this);
1703 save_package_->GetSaveInfo();
1704}
1705
1706// Used in automated testing to bypass prompting the user for file names.
1707// Instead, the names and paths are hard coded rather than running them through
1708// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341709bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1710 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211711 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591712 // Stop the page from navigating.
1713 Stop();
1714
1715 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211716 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591717}
1718
[email protected]3c71576ce2013-07-23 02:00:011719void WebContentsImpl::SaveFrame(const GURL& url,
1720 const Referrer& referrer) {
1721 if (!GetURL().is_valid())
1722 return;
1723 bool is_main_frame = (url == GetURL());
1724
1725 DownloadManager* dlm =
1726 BrowserContext::GetDownloadManager(GetBrowserContext());
1727 if (!dlm)
1728 return;
1729 int64 post_id = -1;
1730 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271731 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011732 if (entry)
1733 post_id = entry->GetPostID();
1734 }
1735 scoped_ptr<DownloadUrlParameters> params(
1736 DownloadUrlParameters::FromWebContents(this, url));
1737 params->set_referrer(referrer);
1738 params->set_post_id(post_id);
1739 params->set_prefer_cache(true);
1740 if (post_id >= 0)
1741 params->set_method("POST");
1742 params->set_prompt(true);
1743 dlm->DownloadUrl(params.Pass());
1744}
1745
[email protected]b172aee2012-04-10 17:05:261746void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341747 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481748 const base::Callback<void(int64)>& callback) {
1749 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121750}
1751
[email protected]6286a372013-10-09 04:03:271752// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261753bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271754 NavigationEntryImpl* visible_entry =
1755 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1756 return (visible_entry != NULL &&
1757 visible_entry->site_instance() == GetSiteInstance() &&
1758 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321759}
1760
[email protected]b172aee2012-04-10 17:05:261761const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271762 return contents_mime_type_;
1763}
1764
[email protected]b172aee2012-04-10 17:05:261765bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271766 return notify_disconnection_;
1767}
1768
[email protected]b172aee2012-04-10 17:05:261769void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311770 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181771 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161772}
1773
[email protected]b172aee2012-04-10 17:05:261774void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311775 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181776 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161777}
1778
[email protected]8ff00d72012-10-23 19:12:211779RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271780 return &renderer_preferences_;
1781}
1782
[email protected]e35ccd52012-05-23 16:22:471783void WebContentsImpl::Close() {
1784 Close(GetRenderViewHost());
1785}
1786
[email protected]cf200a562013-05-03 16:24:291787void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461788 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291789 if (browser_plugin_embedder_.get())
1790 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1791 screen_x, screen_y, operation);
1792 if (GetRenderViewHost())
1793 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1794 screen_x, screen_y, operation);
1795}
1796
1797void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1798 int screen_x, int screen_y) {
1799 if (browser_plugin_embedder_.get())
1800 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1801 screen_x, screen_y);
1802 if (GetRenderViewHost())
1803 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1804 screen_x, screen_y);
1805}
1806
[email protected]d60f3702013-12-26 16:30:241807void WebContentsImpl::DidGetResourceResponseStart(
1808 const ResourceRequestDetails& details) {
1809 controller_.ssl_manager()->DidStartResourceResponse(details);
1810
1811 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1812 DidGetResourceResponseStart(details));
1813
1814 // TODO(avi): Remove. http://crbug.com/170921
1815 NotificationService::current()->Notify(
1816 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1817 Source<WebContents>(this),
1818 Details<const ResourceRequestDetails>(&details));
1819}
1820
1821void WebContentsImpl::DidGetRedirectForResourceRequest(
1822 RenderViewHost* render_view_host,
1823 const ResourceRedirectDetails& details) {
1824 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1825
1826 FOR_EACH_OBSERVER(
1827 WebContentsObserver,
1828 observers_,
1829 DidGetRedirectForResourceRequest(render_view_host, details));
1830
1831 // TODO(avi): Remove. http://crbug.com/170921
1832 NotificationService::current()->Notify(
1833 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1834 Source<WebContents>(this),
1835 Details<const ResourceRedirectDetails>(&details));
1836}
1837
[email protected]b172aee2012-04-10 17:05:261838void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521839 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581840 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511841 if (delegate_)
1842 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291843 if (browser_plugin_embedder_.get())
1844 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341845}
1846
[email protected]e35ccd52012-05-23 16:22:471847void WebContentsImpl::UserGestureDone() {
1848 OnUserGesture();
1849}
1850
[email protected]b172aee2012-04-10 17:05:261851void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271852 closed_by_user_gesture_ = value;
1853}
1854
[email protected]b172aee2012-04-10 17:05:261855bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271856 return closed_by_user_gesture_;
1857}
1858
[email protected]b172aee2012-04-10 17:05:261859double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051860 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561861 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251862 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171863 return 0;
[email protected]b75b8292010-10-01 07:28:251864
1865 double zoom_level;
1866 if (temporary_zoom_settings_) {
1867 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581868 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251869 } else {
[email protected]2ae88d12011-10-14 09:11:191870 GURL url;
[email protected]6286a372013-10-09 04:03:271871 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191872 // Since zoom map is updated using rewritten URL, use rewritten URL
1873 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271874 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021875 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1876 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251877 }
[email protected]d0b8d092010-10-25 04:05:171878 return zoom_level;
1879}
[email protected]b75b8292010-10-01 07:28:251880
[email protected]b172aee2012-04-10 17:05:261881int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591882 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171883 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011884 // Calculate the zoom percent from the factor. Round up to the nearest whole
1885 // number.
[email protected]b75b8292010-10-01 07:28:251886 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491887 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251888 *enable_decrement = percent > minimum_zoom_percent_;
1889 *enable_increment = percent < maximum_zoom_percent_;
1890 return percent;
1891}
1892
[email protected]b172aee2012-04-10 17:05:261893void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501894 if (!delegate_)
1895 return;
1896
[email protected]6286a372013-10-09 04:03:271897 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1898 if (!entry)
[email protected]1788e772010-12-15 16:40:501899 return;
1900
[email protected]6286a372013-10-09 04:03:271901 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121902}
1903
[email protected]b172aee2012-04-10 17:05:261904void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041905 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271906 if (!delegate_)
1907 return;
1908
[email protected]691aa2f2013-05-28 22:52:041909 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271910}
1911
[email protected]b172aee2012-04-10 17:05:261912int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271913 return minimum_zoom_percent_;
1914}
1915
[email protected]b172aee2012-04-10 17:05:261916int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271917 return maximum_zoom_percent_;
1918}
1919
[email protected]b172aee2012-04-10 17:05:261920gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231921 return preferred_size_;
1922}
1923
[email protected]b172aee2012-04-10 17:05:261924bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271925 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581926 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271927}
1928
[email protected]b172aee2012-04-10 17:05:261929bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441930 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501931}
1932
[email protected]cb805452013-05-22 15:16:211933void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181934 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211935 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201936}
1937
[email protected]cb805452013-05-22 15:16:211938void WebContentsImpl::DidEndColorChooser() {
1939 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1940 color_chooser_identifier_));
1941 color_chooser_.reset();
1942 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201943}
1944
[email protected]41225fe2013-03-29 05:32:021945int WebContentsImpl::DownloadImage(const GURL& url,
1946 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301947 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021948 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391949 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301950 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021951 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391952 return id;
1953}
1954
[email protected]5dcaf8e2013-12-28 01:31:421955bool WebContentsImpl::IsSubframe() const {
1956 return is_subframe_;
1957}
1958
[email protected]9649d492014-01-10 07:15:521959void WebContentsImpl::SetZoomLevel(double level) {
1960 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
1961 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
1962 if (embedder)
1963 embedder->SetZoomLevel(level);
1964}
1965
[email protected]36ec24f2014-01-09 00:32:081966void WebContentsImpl::Find(int request_id,
1967 const base::string16& search_text,
1968 const blink::WebFindOptions& options) {
1969 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
1970}
1971
1972void WebContentsImpl::StopFinding(StopFindAction action) {
1973 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
1974}
1975
[email protected]b172aee2012-04-10 17:05:261976bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:271977 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:201978 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:331979 return true;
1980 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:271981}
1982
[email protected]b172aee2012-04-10 17:05:261983void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271984 if (delegate_)
1985 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211986}
1987
[email protected]52913802013-12-10 05:52:181988void WebContentsImpl::DidStartProvisionalLoad(
1989 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:571990 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131991 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571992 bool is_main_frame,
[email protected]52913802013-12-10 05:52:181993 const GURL& validated_url,
1994 bool is_error_page,
1995 bool is_iframe_srcdoc) {
1996 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:571997 DidChangeLoadProgress(0);
1998
[email protected]0d60f0192011-04-14 12:40:101999 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252000 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132001 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2002 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182003 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542004
2005 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182006 FOR_EACH_OBSERVER(
2007 WebContentsObserver,
2008 observers_,
2009 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582010 render_frame_host));
[email protected]400992b2012-06-14 00:03:542011 }
2012}
2013
[email protected]3109fbb72014-01-06 23:57:152014void WebContentsImpl::DidFailProvisionalLoadWithError(
2015 RenderFrameHostImpl* render_frame_host,
2016 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2017 GURL validated_url(params.url);
2018 FOR_EACH_OBSERVER(
2019 WebContentsObserver,
2020 observers_,
2021 DidFailProvisionalLoad(params.frame_id,
2022 params.frame_unique_name,
2023 params.is_main_frame,
2024 validated_url,
2025 params.error_code,
2026 params.error_description,
2027 render_frame_host->render_view_host()));
2028}
2029
[email protected]52913802013-12-10 05:52:182030void WebContentsImpl::NotifyChangedNavigationState(
2031 InvalidateTypes changed_flags) {
2032 NotifyNavigationStateChanged(changed_flags);
2033}
2034
[email protected]3691e5cf2014-01-22 10:16:202035void WebContentsImpl::AboutToNavigateRenderFrame(
2036 RenderFrameHostImpl* render_frame_host) {
2037 // Notify observers that we will navigate in this RenderView.
2038 FOR_EACH_OBSERVER(
2039 WebContentsObserver,
2040 observers_,
2041 AboutToNavigateRenderView(render_frame_host->render_view_host()));
2042}
2043
2044void WebContentsImpl::DidStartNavigationToPendingEntry(
2045 RenderFrameHostImpl* render_frame_host,
2046 const GURL& url,
2047 NavigationController::ReloadType reload_type) {
2048 // Notify observers about navigation.
2049 FOR_EACH_OBSERVER(
2050 WebContentsObserver,
2051 observers_,
2052 DidStartNavigationToPendingEntry(url, reload_type));
2053}
2054
[email protected]400992b2012-06-14 00:03:542055void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582056 RenderFrameHostImpl* render_frame_host,
2057 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542058 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582059 FOR_EACH_OBSERVER(
2060 WebContentsObserver,
2061 observers_,
2062 ProvisionalChangeToMainFrameUrl(validated_target_url,
2063 render_frame_host));
[email protected]724159a2010-12-30 01:11:182064}
2065
[email protected]b172aee2012-04-10 17:05:262066void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182067 const GURL& url,
[email protected]70435962011-08-02 20:13:282068 const std::string& security_info,
2069 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182070 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282071 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192072 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182073 cache.Increment();
2074
2075 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082076 int cert_id = 0;
2077 net::CertStatus cert_status = 0;
2078 int security_bits = -1;
2079 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122080 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212081 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122082 &security_bits, &connection_status,
2083 &signed_certificate_timestamp_ids);
2084 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212085 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002086 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2087 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182088
[email protected]b0f724c2013-09-05 04:21:132089 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2090
2091 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2092 DidLoadResourceFromMemoryCache(details));
2093
[email protected]8bfc8272013-09-09 20:10:532094 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2095 scoped_refptr<net::URLRequestContextGetter> request_context(
2096 resource_type == ResourceType::MEDIA ?
2097 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2098 GetRenderProcessHost()->GetID()) :
2099 GetBrowserContext()->GetRequestContextForRenderProcess(
2100 GetRenderProcessHost()->GetID()));
2101 BrowserThread::PostTask(
2102 BrowserThread::IO,
2103 FROM_HERE,
2104 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2105 }
[email protected]724159a2010-12-30 01:11:182106}
2107
[email protected]b172aee2012-04-10 17:05:262108void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392109 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182110 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192111 SSLManager::NotifySSLInternalStateChanged(
2112 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182113}
2114
[email protected]b172aee2012-04-10 17:05:262115void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022116 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582117 LOG(WARNING) << security_origin << " ran insecure content from "
2118 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392119 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412120 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392121 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182122 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412123 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192124 SSLManager::NotifySSLInternalStateChanged(
2125 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182126}
2127
[email protected]b172aee2012-04-10 17:05:262128void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]f114fa42013-12-06 17:06:442129 FOR_EACH_OBSERVER(
2130 WebContentsObserver, observers_,
2131 DocumentLoadedInFrame(frame_id, render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182132}
2133
[email protected]b172aee2012-04-10 17:05:262134void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312135 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062136 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312137 bool is_main_frame) {
[email protected]8b3af1e2014-01-24 13:29:122138 if (!render_view_message_source_) {
2139 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2140 GetRenderProcessHost()->ReceivedBadMessage();
2141 return;
2142 }
[email protected]a1b99262013-12-27 21:56:222143
2144 // --site-per-process mode has a short-term hack allowing cross-process
2145 // subframe pages to commit thinking they are top-level. Correct it here to
2146 // avoid confusing the observers.
2147 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2148 render_view_message_source_ != GetRenderViewHost())
2149 is_main_frame = false;
2150
[email protected]8b3af1e2014-01-24 13:29:122151 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442152 RenderProcessHost* render_process_host =
2153 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422154 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252155 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472156 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442157 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312158}
2159
[email protected]b172aee2012-04-10 17:05:262160void WebContentsImpl::OnDidFailLoadWithError(
2161 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062162 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262163 bool is_main_frame,
2164 int error_code,
[email protected]fcf75d42013-12-03 20:11:262165 const base::string16& error_description) {
[email protected]15be9bff2014-01-25 07:19:412166 if (!render_view_message_source_) {
2167 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD3"));
2168 GetRenderProcessHost()->ReceivedBadMessage();
2169 return;
2170 }
[email protected]b502ed462013-01-08 08:20:062171 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442172 RenderProcessHost* render_process_host =
2173 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422174 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252175 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312176 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472177 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442178 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182179}
2180
[email protected]b172aee2012-04-10 17:05:262181void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262182 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232183 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252184 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262185 if (!entry)
2186 return;
2187 // Note that we don't call NavigationController::GotToOffset() as we don't
2188 // want to create a pending navigation entry (it might end up lingering
2189 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252190 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212191 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512192 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212193 PAGE_TRANSITION_FORWARD_BACK));
[email protected]3691e5cf2014-01-22 10:16:202194 frame_tree_.root()->navigator()->NavigateToEntry(
2195 frame_tree_.GetMainFrame(),
2196 *entry,
2197 NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572198
2199 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2200 // it in now that we know. This allows us to find the entry when it commits.
2201 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232202 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332203 entry->set_site_instance(
2204 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572205 }
[email protected]216813952011-05-19 22:21:262206 }
2207}
2208
[email protected]b172aee2012-04-10 17:05:262209void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2210 int maximum_percent,
2211 bool remember) {
[email protected]216813952011-05-19 22:21:262212 minimum_zoom_percent_ = minimum_percent;
2213 maximum_zoom_percent_ = maximum_percent;
2214 temporary_zoom_settings_ = !remember;
2215}
2216
[email protected]b172aee2012-04-10 17:05:262217void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342218 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432219 if (!delegate_)
2220 return;
2221
[email protected]b9535422012-02-09 01:47:592222 ChildProcessSecurityPolicyImpl* policy =
2223 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222224 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592225 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212226}
2227
[email protected]b172aee2012-04-10 17:05:262228void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432229 if (delegate_)
2230 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202231}
2232
[email protected]b172aee2012-04-10 17:05:262233void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2234 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262235 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362236 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432237 if (!delegate_)
2238 return;
2239
[email protected]b9535422012-02-09 01:47:592240 ChildProcessSecurityPolicyImpl* policy =
2241 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322242 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592243 return;
[email protected]8f810632013-06-06 22:33:322244
[email protected]3a3b75a2012-06-01 08:38:362245 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202246}
2247
[email protected]b172aee2012-04-10 17:05:262248void WebContentsImpl::OnFindReply(int request_id,
2249 int number_of_matches,
2250 const gfx::Rect& selection_rect,
2251 int active_match_ordinal,
2252 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432253 if (delegate_) {
2254 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2255 active_match_ordinal, final_update);
2256 }
[email protected]b888919c2011-09-02 00:32:162257}
2258
[email protected]59363fc92012-09-05 03:46:312259#if defined(OS_ANDROID)
2260void WebContentsImpl::OnFindMatchRectsReply(
2261 int version,
2262 const std::vector<gfx::RectF>& rects,
2263 const gfx::RectF& active_rect) {
2264 if (delegate_)
2265 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2266}
[email protected]583418cc2013-01-17 14:01:102267
[email protected]1ff427972013-02-07 21:14:072268void WebContentsImpl::OnOpenDateTimeDialog(
2269 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092270 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2271 GetRenderViewHost(),
2272 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132273 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092274 value.minimum,
2275 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172276 value.step,
2277 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102278}
2279
[email protected]a794f3a2013-10-30 17:00:322280void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2281 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442282 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322283}
2284
[email protected]59363fc92012-09-05 03:46:312285#endif
2286
[email protected]f114fa42013-12-06 17:06:442287void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2288 const base::FilePath& path,
2289 bool is_hung) {
2290 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2291
2292 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2293 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2294}
2295
2296void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422297 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442298 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422299 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452300}
2301
[email protected]b172aee2012-04-10 17:05:262302void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2303 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102304 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252305 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102306 AppCacheAccessed(manifest_url, blocked_by_policy));
2307}
2308
[email protected]8bc5ff02013-11-29 06:34:032309void WebContentsImpl::OnOpenColorChooser(
2310 int color_chooser_id,
2311 SkColor color,
2312 const std::vector<ColorSuggestion>& suggestions) {
2313 ColorChooser* new_color_chooser =
2314 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302315 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212316 return;
[email protected]820957a2014-01-14 14:56:302317 if (color_chooser_)
2318 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212319 color_chooser_.reset(new_color_chooser);
2320 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202321}
2322
[email protected]b172aee2012-04-10 17:05:262323void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202324 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212325 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202326 color_chooser_->End();
2327}
2328
[email protected]b172aee2012-04-10 17:05:262329void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322330 SkColor color) {
[email protected]da8543762012-03-20 08:52:202331 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212332 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202333 color_chooser_->SetSelectedColor(color);
2334}
2335
[email protected]d0759f492012-04-19 22:50:502336// This exists for render views that don't have a WebUI, but do have WebUI
2337// bindings enabled.
2338void WebContentsImpl::OnWebUISend(const GURL& source_url,
2339 const std::string& name,
2340 const base::ListValue& args) {
2341 if (delegate_)
2342 delegate_->WebUISend(this, source_url, name, args);
2343}
2344
[email protected]d8415ad92012-08-23 14:40:502345void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442346 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502347 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342348 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162349 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442350 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162351 return;
[email protected]d8415ad92012-08-23 14:40:502352 }
2353
[email protected]8c8fc292012-11-23 18:57:162354 if (!delegate_->RequestPpapiBrokerPermission(
2355 this, url, plugin_path,
2356 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442357 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162358 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442359 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162360 }
[email protected]d8415ad92012-08-23 14:40:502361}
2362
[email protected]ea0309c2013-08-06 19:35:442363void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502364 bool result) {
[email protected]ea0309c2013-08-06 19:35:442365 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502366}
2367
[email protected]c4538072013-03-18 02:17:552368void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372369 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082370 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552371 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392372 // For more info, see comment above classes BrowserPluginEmbedder and
2373 // BrowserPluginGuest.
2374 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142375 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082376 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372377}
2378
[email protected]41225fe2013-03-29 05:32:022379void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392380 int id,
[email protected]749fadd2013-05-15 08:37:482381 int http_status_code,
[email protected]795c28972012-12-06 06:13:392382 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302383 const std::vector<SkBitmap>& bitmaps,
2384 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132385 if (bitmaps.size() != original_bitmap_sizes.size())
2386 return;
2387
[email protected]41225fe2013-03-29 05:32:022388 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2389 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392390 // Currently WebContents notifies us of ANY downloads so that it is
2391 // possible to get here.
2392 return;
2393 }
2394 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302395 iter->second.Run(
2396 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392397 }
[email protected]41225fe2013-03-29 05:32:022398 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392399}
2400
2401void WebContentsImpl::OnUpdateFaviconURL(
2402 int32 page_id,
2403 const std::vector<FaviconURL>& candidates) {
2404 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2405 DidUpdateFaviconURL(page_id, candidates));
2406}
2407
[email protected]d9030b82013-07-19 08:26:062408void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2409 bool has_video,
2410 bool has_audio,
2411 bool is_playing) {
2412 // Chrome OS does its own detection of audio and video.
2413#if !defined(OS_CHROMEOS)
2414 if (is_playing) {
2415 scoped_ptr<PowerSaveBlocker> blocker;
2416 if (has_video) {
2417 blocker = PowerSaveBlocker::Create(
2418 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2419 "Playing video");
2420#if defined(OS_ANDROID)
2421 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382422 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062423#endif
2424 } else if (has_audio) {
2425 blocker = PowerSaveBlocker::Create(
2426 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2427 "Playing audio");
2428 }
2429
[email protected]f114fa42013-12-06 17:06:442430 if (blocker) {
2431 power_save_blockers_[render_view_message_source_][player_cookie] =
2432 blocker.release();
2433 }
[email protected]d9030b82013-07-19 08:26:062434 } else {
[email protected]f114fa42013-12-06 17:06:442435 delete power_save_blockers_[render_view_message_source_][player_cookie];
2436 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062437 }
2438#endif // !defined(OS_CHROMEOS)
2439}
2440
[email protected]9f268072013-11-07 00:02:152441void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2442 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2443 DidFirstVisuallyNonEmptyPaint(page_id));
2444}
[email protected]d9030b82013-07-19 08:26:062445
[email protected]e67ebf32013-02-13 11:07:192446void WebContentsImpl::DidChangeVisibleSSLState() {
2447 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2448 DidChangeVisibleSSLState());
2449}
2450
[email protected]17e286e2013-03-01 23:29:392451void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2452 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2453 BeforeFormRepostWarningShow());
2454}
2455
[email protected]ec6c05f2013-10-23 18:41:572456
2457void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2458 Activate();
2459 if (delegate_)
2460 delegate_->ShowRepostFormWarningDialog(this);
2461}
2462
[email protected]96d185d2009-04-24 03:28:542463// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592464// loading, or done loading.
2465void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2466 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262467 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542468 if (is_loading == is_loading_)
2469 return;
2470
2471 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262472 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2473 base::string16());
[email protected]96d185d2009-04-24 03:28:542474 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562475 upload_size_ = 0;
2476 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542477 }
2478
[email protected]fa944cb82013-11-15 17:51:212479 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542480
2481 is_loading_ = is_loading;
2482 waiting_for_response_ = is_loading;
2483
[email protected]6ebdc9b2010-09-27 16:55:572484 if (delegate_)
2485 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212486 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542487
[email protected]eab61442013-11-14 18:35:482488 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592489 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482490 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2491 "URL", url);
[email protected]91621872013-10-08 04:04:592492 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2493 DidStartLoading(render_view_host));
2494 } else {
[email protected]eab61442013-11-14 18:35:482495 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2496 "URL", url);
[email protected]91621872013-10-08 04:04:592497 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2498 DidStopLoading(render_view_host));
2499 }
[email protected]66798902013-10-01 18:40:162500
2501 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212502 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2503 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542504 if (details)
[email protected]8ff00d72012-10-23 19:12:212505 det = Details<LoadNotificationDetails>(details);
2506 NotificationService::current()->Notify(
2507 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542508}
2509
[email protected]b172aee2012-04-10 17:05:262510void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212511 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322512 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562513 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322514 // Clear the status bubble. This is a workaround for a bug where WebKit
2515 // doesn't let us know that the cursor left an element during a
2516 // transition (this is also why the mouse cursor remains as a hand after
2517 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2518 // clear the bubble when a user navigates to a named anchor in the same
2519 // page.
[email protected]36fc0392011-12-25 03:59:512520 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322521 }
2522
[email protected]a6e82fc2010-02-24 22:28:142523 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472524 // Once the main frame is navigated, we're no longer considered to have
2525 // displayed insecure content.
2526 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352527 SSLManager::NotifySSLInternalStateChanged(
2528 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172529 }
[email protected]ce5c4502009-05-06 16:46:112530
[email protected]3c9e1872010-11-18 16:17:492531 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252532 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042533 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322534}
2535
[email protected]b172aee2012-04-10 17:05:262536void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322537 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212538 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322539 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112540 // If we navigate off the page, close all JavaScript dialogs.
2541 if (dialog_manager_ && !details.is_in_page)
2542 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322543
[email protected]3c9e1872010-11-18 16:17:492544 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252545 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042546 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322547}
2548
[email protected]2f7b3c5a2013-06-21 04:59:252549bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292550 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2551 // still be used for a normal web site.
2552 if (url == GURL(kAboutBlankURL))
2553 return false;
2554
2555 // The embedder will then have the opportunity to determine if the URL
2556 // should "use up" the SiteInstance.
2557 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252558}
2559
[email protected]b172aee2012-04-10 17:05:262560void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462561 // If we are creating a RVH for a restored controller, then we need to make
2562 // sure the RenderView starts with a next_page_id_ larger than the number
2563 // of restored entries. This must be called before the RenderView starts
2564 // navigating (to avoid a race between the browser updating max_page_id and
2565 // the renderer updating next_page_id_). Because of this, we only call this
2566 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562567 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582568 if (max_restored_page_id >
2569 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2570 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2571 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322572}
2573
[email protected]b172aee2012-04-10 17:05:262574bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262575 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322576 // For file URLs without a title, use the pathname instead. In the case of a
2577 // synthesized title, we don't want the update to count toward the "one set
2578 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262579 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322580 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512581 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242582 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322583 explicit_set = false; // Don't count synthetic titles toward the set limit.
2584 } else {
[email protected]acafd272011-07-26 17:35:572585 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322586 explicit_set = true;
2587 }
2588
[email protected]987fc3a2011-05-26 14:18:092589 // If a page is created via window.open and never navigated,
2590 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552591 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092592 if (entry) {
[email protected]36fc0392011-12-25 03:59:512593 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092594 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322595
[email protected]36fc0392011-12-25 03:59:512596 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092597 } else {
2598 if (page_title_when_no_navigation_entry_ == final_title)
2599 return false; // Nothing changed, don't bother.
2600
2601 page_title_when_no_navigation_entry_ = final_title;
2602 }
[email protected]420ae012009-04-24 05:16:322603
[email protected]420ae012009-04-24 05:16:322604 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232605 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322606
[email protected]66798902013-10-01 18:40:162607 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532608 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162609
2610 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212611 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462612 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212613 NotificationService::current()->Notify(
2614 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2615 Source<WebContents>(this),
2616 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042617
[email protected]420ae012009-04-24 05:16:322618 return true;
2619}
2620
[email protected]7b712ee22013-10-03 00:57:282621void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2622 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322623 // After sending out a swap notification, we need to send a disconnect
2624 // notification so that clients that pick up a pointer to |this| can NULL the
2625 // pointer. See Bug 1230284.
2626 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112627 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282628 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112629
2630 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282631 std::pair<RenderViewHost*, RenderViewHost*> details =
2632 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212633 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282634 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212635 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282636 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392637
2638 // Ensure that the associated embedder gets cleared after a RenderViewHost
2639 // gets swapped, so we don't reuse the same embedder next time a
2640 // RenderViewHost is attached to this WebContents.
2641 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322642}
2643
[email protected]da7a7182013-09-06 08:11:112644// TODO(avi): Remove this entire function because this notification is already
2645// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262646void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322647 if (!notify_disconnection_)
2648 return;
2649
2650 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212651 NotificationService::current()->Notify(
2652 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2653 Source<WebContents>(this),
2654 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322655}
2656
[email protected]cbb1ef592013-06-05 19:49:462657void WebContentsImpl::NotifyNavigationEntryCommitted(
2658 const LoadCommittedDetails& load_details) {
2659 FOR_EACH_OBSERVER(
2660 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2661}
2662
[email protected]f114fa42013-12-06 17:06:442663bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2664 const IPC::Message& message) {
2665 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312666}
2667
[email protected]b849847b2013-12-10 21:57:582668void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2669 // Note this is only for subframes, the notification for the main frame
2670 // happens in RenderViewCreated.
2671 FOR_EACH_OBSERVER(WebContentsObserver,
2672 observers_,
2673 RenderFrameCreated(render_frame_host));
2674}
2675
2676void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2677 FOR_EACH_OBSERVER(WebContentsObserver,
2678 observers_,
2679 RenderFrameDeleted(render_frame_host));
2680}
2681
[email protected]b765deb2013-12-18 06:43:302682void WebContentsImpl::WorkerCrashed() {
2683 if (delegate_)
2684 delegate_->WorkerCrashed(this);
2685}
2686
[email protected]a86c0e962013-12-17 17:10:392687WebContents* WebContentsImpl::GetAsWebContents() {
2688 return this;
2689}
2690
[email protected]5a3bdf52012-05-24 15:12:572691RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2692 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322693}
2694
[email protected]8d3347f2009-07-09 22:00:212695RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262696WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212697 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212698}
2699
[email protected]8ff00d72012-10-23 19:12:212700RendererPreferences WebContentsImpl::GetRendererPrefs(
2701 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462702 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512703}
2704
[email protected]b172aee2012-04-10 17:05:262705gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172706 if (delegate_)
2707 return delegate_->GetRootWindowResizerRect();
2708 return gfx::Rect();
2709}
2710
[email protected]7a846df2012-09-20 19:17:392711void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272712 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392713 browser_plugin_embedder_.reset();
2714}
2715
[email protected]b172aee2012-04-10 17:05:262716void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442717 // Don't send notifications if we are just creating a swapped-out RVH for
2718 // the opener chain. These won't be used for view-source or WebUI, so it's
2719 // ok to return early.
2720 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2721 return;
2722
[email protected]86f98a22013-03-20 14:35:002723 if (delegate_)
2724 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082725
[email protected]8ff00d72012-10-23 19:12:212726 NotificationService::current()->Notify(
2727 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2728 Source<WebContents>(this),
2729 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322730
2731 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352732 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212733 if (GetRenderManager()->pending_web_ui())
2734 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322735
[email protected]6286a372013-10-09 04:03:272736 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332737 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322738 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182739 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582740 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322741 }
[email protected]0666aef2009-05-13 19:48:082742
[email protected]60780f412013-02-25 16:34:102743 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262744
2745 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252746 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582747
2748 // We tell the observers now instead of when the main RenderFrameHostImpl is
2749 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2750 // frame would be dropped because it's not created yet).
2751 RenderFrameHost* main_frame = GetMainFrame();
2752 FOR_EACH_OBSERVER(
2753 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322754}
2755
[email protected]b172aee2012-04-10 17:05:262756void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522757 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322758 // Don't notify the world, since this came from a renderer in the
2759 // background.
2760 return;
2761 }
2762
[email protected]da7a7182013-09-06 08:11:112763 notify_disconnection_ = true;
2764 // TODO(avi): Remove. http://crbug.com/170921
2765 NotificationService::current()->Notify(
2766 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2767 Source<WebContents>(this),
2768 NotificationService::NoDetails());
2769
[email protected]be1f56ab2011-12-22 06:55:312770 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232771 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302772
2773 // Restore the focus to the tab (otherwise the focus will be on the top
2774 // window).
[email protected]484ae5912010-09-29 19:16:142775 if (was_crashed && !FocusLocationBarByDefault() &&
2776 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062777 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142778 }
[email protected]32ded2212011-11-10 18:51:432779
[email protected]d8c660432011-12-22 20:51:252780 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322781}
2782
[email protected]ec6a7eb2013-04-22 17:34:222783void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2784 base::TerminationStatus status,
2785 int error_code) {
[email protected]151a63d2011-12-20 22:32:522786 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322787 // The pending page's RenderViewHost is gone.
2788 return;
2789 }
2790
[email protected]d9030b82013-07-19 08:26:062791 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592792 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322793 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232794 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312795 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322796
[email protected]d8c660432011-12-22 20:51:252797 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272798 observers_,
[email protected]58d5cfe2013-07-10 02:40:522799 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322800}
2801
[email protected]b172aee2012-04-10 17:05:262802void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062803 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212804 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252805 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062806}
2807
[email protected]b172aee2012-04-10 17:05:262808void WebContentsImpl::DidNavigate(
2809 RenderViewHost* rvh,
[email protected]a1b99262013-12-27 21:56:222810 const ViewHostMsg_FrameNavigate_Params& orig_params) {
2811 ViewHostMsg_FrameNavigate_Params params(orig_params);
2812 bool use_site_per_process =
2813 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess);
[email protected]9b159a52013-10-03 17:24:552814 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2815 // First navigation should be a main frame navigation.
[email protected]a1b99262013-12-27 21:56:222816 // TODO(creis): This DCHECK is currently disabled for --site-per-process
2817 // because cross-process subframe navigations still have a main frame
2818 // PageTransition.
2819 if (!use_site_per_process)
2820 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552821 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122822 }
2823
[email protected]a1b99262013-12-27 21:56:222824 // When using --site-per-process, look up the FrameTreeNode ID that the
2825 // renderer-specific frame ID corresponds to.
2826 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id();
2827 if (use_site_per_process) {
2828 FrameTreeNode* source_node = frame_tree_.FindByFrameID(params.frame_id);
2829 if (source_node)
2830 frame_tree_node_id = source_node->frame_tree_node_id();
2831
2832 // TODO(creis): In the short term, cross-process subframe navigations are
2833 // happening in the pending RenderViewHost's top-level frame. (We need to
2834 // both mirror the frame tree and get the navigation to occur in the correct
2835 // subframe to fix this.) Until then, we should check whether we have a
2836 // pending NavigationEntry with a frame ID and if so, treat the
2837 // cross-process "main frame" navigation as a subframe navigation. This
2838 // limits us to a single cross-process subframe per RVH, and it affects
2839 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and
2840 // OnDidFinishLoad.
2841 NavigationEntryImpl* pending_entry =
2842 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
2843 int root_ftn_id = frame_tree_.root()->frame_tree_node_id();
2844 if (pending_entry &&
2845 pending_entry->frame_tree_node_id() != -1 &&
2846 pending_entry->frame_tree_node_id() != root_ftn_id) {
2847 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
2848 frame_tree_node_id = pending_entry->frame_tree_node_id();
2849 }
2850 }
2851
[email protected]e3d92a7f2013-01-10 02:35:052852 if (PageTransitionIsMainFrame(params.transition)) {
2853 // When overscroll navigation gesture is enabled, a screenshot of the page
2854 // in its current state is taken so that it can be used during the
2855 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362856 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052857 // WebContents::GetRenderViewHost to return the new host, instead of the one
2858 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482859 if (delegate_ && delegate_->CanOverscrollContent())
2860 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052861
[email protected]a1b99262013-12-27 21:56:222862 if (!use_site_per_process)
2863 GetRenderManager()->DidNavigateMainFrame(rvh);
2864 }
2865
2866 // When using --site-per-process, we notify the RFHM for all navigations,
2867 // not just main frame navigations.
2868 if (use_site_per_process) {
2869 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
2870 // TODO(creis): Rename to DidNavigateFrame.
2871 frame->render_manager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052872 }
[email protected]8030f012009-09-25 18:09:372873
[email protected]434f69f2012-02-06 21:56:522874 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252875 // assigning a site is not necessary for this URL. In that case, the
2876 // SiteInstance can still be considered unused until a navigation to a real
2877 // page.
[email protected]434f69f2012-02-06 21:56:522878 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252879 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332880 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522881 }
[email protected]420ae012009-04-24 05:16:322882
2883 // Need to update MIME type here because it's referred to in
2884 // UpdateNavigationCommands() called by RendererDidNavigate() to
2885 // determine whether or not to enable the encoding menu.
2886 // It's updated only for the main frame. For a subframe,
2887 // RenderView::UpdateURL does not set params.contents_mime_type.
2888 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2889 // TODO(jungshik): Add a test for the encoding menu to avoid
2890 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212891 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322892 contents_mime_type_ = params.contents_mime_type;
2893
[email protected]8ff00d72012-10-23 19:12:212894 LoadCommittedDetails details;
[email protected]a1b99262013-12-27 21:56:222895 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details);
[email protected]3e90d4a2009-07-03 17:38:392896
[email protected]1ae93fb2013-06-14 03:38:562897 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2898 // us estimate our process count for implementing OOP iframes.
2899 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552900 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562901
[email protected]a9c0bfe2010-09-17 08:35:222902 // Send notification about committed provisional loads. This notification is
2903 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2904 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212905 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072906 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2907 // that is not recorded in the navigation history. For the purpose of
2908 // tracking navigation events, we treat this event as a sub frame navigation
2909 // event.
2910 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212911 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222912 // Whether or not a page transition was triggered by going backward or
2913 // forward in the history is only stored in the navigation controller's
2914 // entry list.
2915 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272916 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212917 PAGE_TRANSITION_FORWARD_BACK)) {
2918 transition_type = PageTransitionFromInt(
2919 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222920 }
[email protected]0d60f0192011-04-14 12:40:102921 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252922 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442923 DidCommitProvisionalLoadForFrame(
2924 params.frame_id,
2925 params.frame_unique_name,
2926 is_main_frame,
2927 params.url,
2928 transition_type,
2929 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222930 }
2931
[email protected]76543b92009-08-31 17:27:452932 if (!did_navigate)
2933 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322934
2935 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2936 // for the appropriate notification (best) or you can add it to
2937 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2938 // necessary, please).
2939
2940 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002941 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322942 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002943 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512944 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002945 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2946 }
[email protected]93f230e02011-06-01 14:40:002947 }
[email protected]420ae012009-04-24 05:16:322948 DidNavigateAnyFramePostCommit(rvh, details, params);
2949}
2950
[email protected]b172aee2012-04-10 17:05:262951void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2952 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042953 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152954 // Ensure that this state update comes from either the active RVH or one of
2955 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412956 // TODO(nasko): This should go through RenderFrameHost.
2957 // TODO(creis): We can't update state for cross-process subframes until we
2958 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2959 if (rvh != GetRenderViewHost() &&
2960 !GetRenderManager()->IsRVHOnSwappedOutList(
2961 static_cast<RenderViewHostImpl*>(rvh)))
2962 return;
[email protected]420ae012009-04-24 05:16:322963
2964 // We must be prepared to handle state updates for any page, these occur
2965 // when the user is scrolling and entering form data, as well as when we're
2966 // leaving a page, in which case our state may have already been moved to
2967 // the next page. The navigation controller will look up the appropriate
2968 // NavigationEntry and update it when it is notified via the delegate.
2969
2970 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582971 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322972 if (entry_index < 0)
2973 return;
[email protected]10f417c52011-12-28 21:04:232974 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322975
[email protected]691aa2f2013-05-28 22:52:042976 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322977 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042978 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322979 controller_.NotifyEntryChanged(entry, entry_index);
2980}
2981
[email protected]b172aee2012-04-10 17:05:262982void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2983 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262984 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262985 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322986 // If we have a title, that's a pretty good indication that we've started
2987 // getting useful data.
2988 SetNotWaitingForResponse();
2989
[email protected]73eb2602012-02-09 19:50:552990 // Try to find the navigation entry, which might not be the current one.
2991 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232992 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582993 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092994
[email protected]73eb2602012-02-09 19:50:552995 // We can handle title updates when we don't have an entry in
2996 // UpdateTitleForEntry, but only if the update is from the current RVH.
2997 if (!entry && rvh != GetRenderViewHost())
2998 return;
2999
[email protected]a49e10b2011-08-01 23:57:463000 // TODO(evan): make use of title_direction.
3001 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093002 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323003 return;
3004
3005 // Broadcast notifications when the UI should be updated.
3006 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213007 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323008}
3009
[email protected]b172aee2012-04-10 17:05:263010void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3011 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313012 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323013}
3014
[email protected]b172aee2012-04-10 17:05:263015void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513016 if (delegate_)
3017 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323018}
3019
[email protected]b172aee2012-04-10 17:05:263020void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103021#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293022 // The UI may be in an event-tracking loop, such as between the
3023 // mouse-down and mouse-up in text selection or a button click.
3024 // Defer the close until after tracking is complete, so that we
3025 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293026 // TODO(shess): This could get more fine-grained. For instance,
3027 // closing a tab in another window while selecting text in the
3028 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103029 if (view_->IsEventTracking()) {
3030 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293031 return;
3032 }
[email protected]60780f412013-02-25 16:34:103033#endif
[email protected]07707302009-11-06 00:50:293034
[email protected]420ae012009-04-24 05:16:323035 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523036 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513037 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323038}
3039
[email protected]b172aee2012-04-10 17:05:263040void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523041 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513042 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283043
3044 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213045 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573046}
3047
[email protected]b172aee2012-04-10 17:05:263048void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513049 if (delegate_ && delegate_->IsPopupOrPanel(this))
3050 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323051}
3052
[email protected]8ff00d72012-10-23 19:12:213053void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593054 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323055}
3056
[email protected]8ff00d72012-10-23 19:12:213057void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323058 scoped_ptr<LoadNotificationDetails> details;
3059
[email protected]9595fd82013-04-19 21:28:493060 // Use the last committed entry rather than the active one, in case a
3061 // pending entry has been created.
3062 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203063 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493064
[email protected]420ae012009-04-24 05:16:323065 // An entry may not exist for a stop when loading an initial blank page or
3066 // if an iframe injected by script into a blank page finishes loading.
3067 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203068 base::TimeDelta elapsed =
3069 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323070
3071 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513072 entry->GetVirtualURL(),
3073 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323074 elapsed,
3075 &controller_,
3076 controller_.GetCurrentEntryIndex()));
3077 }
3078
[email protected]91621872013-10-08 04:04:593079 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323080}
3081
[email protected]b172aee2012-04-10 17:05:263082void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163083 controller_.DiscardNonCommittedEntries();
3084
3085 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213086 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163087}
3088
[email protected]b172aee2012-04-10 17:05:263089void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513090 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133091 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403092}
3093
[email protected]7cc78902012-12-06 02:32:263094void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393095 if (opener_) {
3096 // Clear our opener so that future cross-process navigations don't have an
3097 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103098 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393099 opener_ = NULL;
3100 }
[email protected]7cc78902012-12-06 02:32:263101
3102 // Notify all swapped out RenderViewHosts for this tab. This is important
3103 // in case we go back to them, or if another window in those processes tries
3104 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213105 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263106}
3107
[email protected]59167c22013-06-03 18:07:323108void WebContentsImpl::DidAccessInitialDocument() {
3109 // Update the URL display.
3110 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3111}
3112
[email protected]87717d0e2012-04-26 02:58:433113void WebContentsImpl::DocumentAvailableInMainFrame(
3114 RenderViewHost* render_view_host) {
3115 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3116 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103117}
3118
[email protected]b172aee2012-04-10 17:05:263119void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083120 RenderViewHost* render_view_host,
3121 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093122 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3123 DocumentOnLoadCompletedInMainFrame(page_id));
3124
3125 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213126 NotificationService::current()->Notify(
3127 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3128 Source<WebContents>(this),
3129 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083130}
3131
[email protected]196159d2012-05-04 17:26:543132void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3133 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213134 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263135 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183136 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523137 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303138 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543139 // If this came from a swapped out RenderViewHost, we only allow the request
3140 // if we are still in the same BrowsingInstance.
3141 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3142 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3143 return;
3144 }
3145
[email protected]4ad5d77d2011-12-03 02:00:483146 // Delegate to RequestTransferURL because this is just the generic
3147 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573148 // TODO(creis): Pass the redirect_chain into this method to support client
3149 // redirects. http://crbug.com/311721.
3150 std::vector<GURL> redirect_chain;
3151 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3152 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523153 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483154}
3155
[email protected]b172aee2012-04-10 17:05:263156void WebContentsImpl::RequestTransferURL(
3157 const GURL& url,
[email protected]f8872902013-10-30 03:18:573158 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213159 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573160 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263161 WindowOpenDisposition disposition,
3162 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183163 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523164 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303165 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203166 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123167 GURL dest_url(url);
3168 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553169 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123170 dest_url = GURL(kAboutBlankURL);
3171
[email protected]a1b99262013-12-27 21:56:223172 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3173 int64 frame_tree_node_id = -1;
3174 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3175 source_frame_id != -1) {
3176 FrameTreeNode* source_node = frame_tree_.FindByFrameID(source_frame_id);
3177 if (source_node)
3178 frame_tree_node_id = source_node->frame_tree_node_id();
3179 }
[email protected]c80297782013-11-21 07:10:163180 OpenURLParams params(dest_url, referrer, source_frame_id,
3181 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573182 page_transition, true /* is_renderer_initiated */);
3183 if (redirect_chain.size() > 0)
3184 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553185 params.transferred_global_request_id = old_request_id;
3186 params.should_replace_current_entry = should_replace_current_entry;
3187 params.user_gesture = user_gesture;
3188
[email protected]fa944cb82013-11-15 17:51:213189 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573190 // Web UI pages sometimes want to override the page transition type for
3191 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3192 // automatically generated suggestions). We don't override other types
3193 // like TYPED because they have different implications (e.g., autocomplete).
3194 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213195 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553196
[email protected]e0112912011-02-02 22:54:353197 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163198 // want web sites to see a referrer of "chrome://blah" (and some
3199 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323200 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553201 params.referrer = Referrer();
3202
3203 // Navigations in Web UI pages count as browser-initiated navigations.
3204 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583205 }
[email protected]44d0930a2013-10-28 18:53:553206
3207 new_contents = OpenURL(params);
3208
[email protected]ae5184d62011-10-06 19:25:583209 if (new_contents) {
3210 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253211 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583212 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123213 dest_url,
[email protected]ae5184d62011-10-06 19:25:583214 referrer,
3215 disposition,
[email protected]44d0930a2013-10-28 18:53:553216 params.transition,
[email protected]ae5184d62011-10-06 19:25:583217 source_frame_id));
[email protected]420ae012009-04-24 05:16:323218 }
3219}
3220
[email protected]e1c3a552012-05-04 20:51:323221void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3222 // Tell the active RenderViewHost to run unload handlers and close, as long
3223 // as the request came from a RenderViewHost in the same BrowsingInstance.
3224 // In most cases, we receive this from a swapped out RenderViewHost.
3225 // It is possible to receive it from one that has just been swapped in,
3226 // in which case we might as well deliver the message anyway.
3227 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3228 GetRenderViewHost()->ClosePage();
3229}
3230
[email protected]f546640b2012-05-15 00:03:493231void WebContentsImpl::RouteMessageEvent(
3232 RenderViewHost* rvh,
3233 const ViewMsg_PostMessage_Params& params) {
3234 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363235 // came from a RenderViewHost in the same BrowsingInstance or if this
3236 // WebContents is dedicated to a browser plugin guest.
3237 // Note: This check means that an embedder could theoretically receive a
3238 // postMessage from anyone (not just its own guests). However, this is
3239 // probably not a risk for apps since other pages won't have references
3240 // to App windows.
3241 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3242 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493243 return;
3244
3245 ViewMsg_PostMessage_Params new_params(params);
3246
[email protected]0bc7f3542013-10-21 15:05:533247 if (!params.message_port_ids.empty()) {
3248 MessagePortMessageFilter* message_port_message_filter =
3249 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3250 ->message_port_message_filter();
3251 std::vector<int> new_routing_ids(params.message_port_ids.size());
3252 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3253 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3254 MessagePortService::GetInstance()->UpdateMessagePort(
3255 params.message_port_ids[i],
3256 message_port_message_filter,
3257 new_routing_ids[i]);
3258 }
3259 new_params.new_routing_ids = new_routing_ids;
3260 }
3261
[email protected]f546640b2012-05-15 00:03:493262 // If there is a source_routing_id, translate it to the routing ID for
3263 // the equivalent swapped out RVH in the target process. If we need
3264 // to create a swapped out RVH for the source tab, we create its opener
3265 // chain as well, since those will also be accessible to the target page.
3266 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3267 // Try to look up the WebContents for the source page.
3268 WebContentsImpl* source_contents = NULL;
3269 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3270 rvh->GetProcess()->GetID(), params.source_routing_id);
3271 if (source_rvh) {
3272 source_contents = static_cast<WebContentsImpl*>(
3273 source_rvh->GetDelegate()->GetAsWebContents());
3274 }
3275
3276 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363277 if (GetBrowserPluginGuest()) {
3278 // We create a swapped out RenderView for the embedder in the guest's
3279 // render process but we intentionally do not expose the embedder's
3280 // opener chain to it.
3281 new_params.source_routing_id =
3282 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3283 } else {
3284 new_params.source_routing_id =
3285 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3286 }
[email protected]f546640b2012-05-15 00:03:493287 } else {
3288 // We couldn't find it, so don't pass a source frame.
3289 new_params.source_routing_id = MSG_ROUTING_NONE;
3290 }
3291 }
3292
3293 // In most cases, we receive this from a swapped out RenderViewHost.
3294 // It is possible to receive it from one that has just been swapped in,
3295 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183296 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493297}
3298
[email protected]b172aee2012-04-10 17:05:263299void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343300 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263301 const base::string16& message,
3302 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323303 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213304 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323305 IPC::Message* reply_msg,
3306 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073307 // Suppress JavaScript dialogs when requested. Also suppress messages when
3308 // showing an interstitial as it's shown over the previous page and we don't
3309 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503310 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583311 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273312 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073313 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523314 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153315 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323316
3317 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213318 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433319 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153320 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3321 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433322 this,
3323 frame_url.GetOrigin(),
3324 accept_lang,
3325 javascript_message_type,
3326 message,
[email protected]51da7e32012-01-30 19:24:523327 default_prompt,
[email protected]b172aee2012-04-10 17:05:263328 base::Bind(&WebContentsImpl::OnDialogClosed,
3329 base::Unretained(this),
3330 rvh,
3331 reply_msg),
[email protected]51da7e32012-01-30 19:24:523332 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323333 }
[email protected]3ab9cb82011-06-03 18:02:073334
[email protected]6dd2f1e2013-09-11 15:06:013335 *did_suppress_message = suppress_this_message;
3336
[email protected]3ab9cb82011-06-03 18:02:073337 if (suppress_this_message) {
3338 // If we are suppressing messages, just reply as if the user immediately
3339 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263340 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073341 }
3342
[email protected]6dd2f1e2013-09-11 15:06:013343 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3344 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323345}
3346
[email protected]b172aee2012-04-10 17:05:263347void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263348 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263349 bool is_reload,
3350 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583351 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513352 if (delegate_)
3353 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073354
3355 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583356 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073357 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523358 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153359 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153360 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343361 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263362 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503363 return;
3364 }
[email protected]3ab9cb82011-06-03 18:02:073365
[email protected]7ab1e7d62009-10-14 23:32:013366 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153367 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3368 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323369 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263370 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523371 reply_msg));
[email protected]420ae012009-04-24 05:16:323372}
3373
[email protected]a796f202012-05-30 14:14:253374bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263375 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253376 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263377 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253378 if (!delegate_)
3379 return false;
3380 return delegate_->AddMessageToConsole(this, level, message, line_no,
3381 source_id);
3382}
3383
[email protected]b172aee2012-04-10 17:05:263384WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273385 // We want to base the page config off of the actual URL, rather than the
3386 // virtual URL.
3387 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3388 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003389 GURL url = controller_.GetActiveEntry()
3390 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153391
[email protected]fa944cb82013-11-15 17:51:213392 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323393}
3394
[email protected]0eba810b2012-10-18 03:19:363395int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213396 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413397 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3398 true, true);
[email protected]0eba810b2012-10-18 03:19:363399}
3400
[email protected]b172aee2012-04-10 17:05:263401void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273402 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253403 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223404
[email protected]ea114722012-03-12 01:11:253405 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173406 if (rdh) // NULL in unittests.
3407 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253408}
3409
[email protected]b172aee2012-04-10 17:05:263410void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443411 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253412 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443413}
3414
[email protected]b172aee2012-04-10 17:05:263415void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563416 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263417 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153418 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523419 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153420 return;
3421
[email protected]9f76c1e2012-03-05 15:15:583422 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3423
[email protected]e5fc1632011-08-08 07:51:533424 // Ignore renderer unresponsive event if debugger is attached to the tab
3425 // since the event may be a result of the renderer sitting on a breakpoint.
3426 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363427 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533428 return;
3429
[email protected]2e9d79f2013-08-16 05:45:563430 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323431 // Hang occurred while firing the beforeunload/unload handler.
3432 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583433 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323434
[email protected]fa944cb82013-11-15 17:51:213435 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323436 return;
3437
3438 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563439 // nothing we can do to recover. If the hang is in the beforeunload handler,
3440 // pretend the beforeunload listeners have all fired and allow the delegate
3441 // to continue closing; the user will not have the option of cancelling the
3442 // close. Otherwise, pretend the unload listeners have all fired and close
3443 // the tab.
3444 bool close = true;
3445 if (is_during_beforeunload) {
3446 delegate_->BeforeUnloadFired(this, true, &close);
3447 }
3448 if (close)
3449 Close(rvh);
[email protected]420ae012009-04-24 05:16:323450 return;
3451 }
3452
[email protected]9f76c1e2012-03-05 15:15:583453 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473454 return;
3455
[email protected]6934a702011-12-20 00:04:513456 if (delegate_)
3457 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323458}
3459
[email protected]b172aee2012-04-10 17:05:263460void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513461 if (delegate_)
3462 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323463}
3464
[email protected]b172aee2012-04-10 17:05:263465void WebContentsImpl::LoadStateChanged(
3466 const GURL& url,
3467 const net::LoadStateWithParam& load_state,
3468 uint64 upload_position,
3469 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323470 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563471 upload_position_ = upload_position;
3472 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503473 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213474 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303475 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213476 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323477 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463478 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213479 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463480 }
[email protected]420ae012009-04-24 05:16:323481}
3482
[email protected]b172aee2012-04-10 17:05:263483void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553484 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323485 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123486 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3487 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513488 if (delegate_)
3489 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093490 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323491}
3492
[email protected]58d5cfe2013-07-10 02:40:523493void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543494 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233495 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223496 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543497}
3498
[email protected]b172aee2012-04-10 17:05:263499void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103500 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213501 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263502 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3503 // here during container initialization and normal window size will be set
3504 // later. In case of tab duplication this resizing to 0x0 prevents setting
3505 // normal size later so just ignore it.
3506 if (!size.IsEmpty())
3507 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323508}
3509
[email protected]af905902013-10-01 21:38:513510void WebContentsImpl::CancelModalDialogsForRenderManager() {
3511 // We need to cancel modal dialogs when doing a process swap, since the load
3512 // deferrer would prevent us from swapping out.
3513 if (dialog_manager_)
3514 dialog_manager_->CancelActiveAndPendingDialogs(this);
3515}
3516
[email protected]7b712ee22013-10-03 00:57:283517void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3518 RenderViewHost* new_host) {
3519 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083520
3521 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003522 if (delegate_)
3523 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393524
[email protected]7b712ee22013-10-03 00:57:283525 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543526}
3527
[email protected]14392a52012-05-02 20:28:443528int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3529 SiteInstance* instance) {
3530 if (!opener_)
3531 return MSG_ROUTING_NONE;
3532
3533 // Recursively create RenderViews for anything else in the opener chain.
3534 return opener_->CreateOpenerRenderViews(instance);
3535}
3536
3537int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3538 int opener_route_id = MSG_ROUTING_NONE;
3539
3540 // If this tab has an opener, ensure it has a RenderView in the given
3541 // SiteInstance as well.
3542 if (opener_)
3543 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3544
[email protected]45a22ad2013-02-21 03:25:003545 // If any of the renderers (current, pending, or swapped out) for this
3546 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213547 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3548 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373549
[email protected]fa944cb82013-11-15 17:51:213550 if (GetRenderManager()->pending_render_view_host() &&
3551 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3552 instance)
3553 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003554
[email protected]fa944cb82013-11-15 17:51:213555 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373556 instance);
3557 if (rvh)
3558 return rvh->GetRoutingID();
3559
[email protected]14392a52012-05-02 20:28:443560 // Create a swapped out RenderView in the given SiteInstance if none exists,
3561 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413562 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3563 true, true);
[email protected]14392a52012-05-02 20:28:443564}
3565
[email protected]b172aee2012-04-10 17:05:263566NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193567 return GetController();
[email protected]3a3d47472010-07-15 21:03:543568}
3569
[email protected]b172aee2012-04-10 17:05:263570WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563571 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323572}
3573
[email protected]10f417c52011-12-28 21:04:233574NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263575 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323576 return controller_.GetLastCommittedEntry();
3577}
3578
[email protected]b172aee2012-04-10 17:05:263579bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163580 RenderViewHost* render_view_host,
3581 int opener_route_id,
3582 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033583 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443584 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163585 RenderWidgetHostView* rwh_view;
3586 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3587 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3588 // case this because RWH is still a base class of RenderViewHost, and child
3589 // frame RWHVs are unique in that they do not have their own WebContents.
3590 if (frame_connector) {
3591 RenderWidgetHostViewChildFrame* rwh_view_child =
3592 new RenderWidgetHostViewChildFrame(render_view_host);
3593 frame_connector->set_view(rwh_view_child);
3594 rwh_view = rwh_view_child;
3595 } else {
3596 rwh_view = view_->CreateViewForWidget(render_view_host);
3597 }
[email protected]1a98a932009-11-17 00:12:523598
[email protected]420ae012009-04-24 05:16:323599 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443600 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213601 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323602
[email protected]74ce1ad2011-12-16 21:51:463603 // Make sure we use the correct starting page_id in the new RenderView.
3604 UpdateMaxPageIDIfNecessary(render_view_host);
3605 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583606 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463607
[email protected]9f76c1e2012-03-05 15:15:583608 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263609 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493610 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133611 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523612 return false;
[email protected]14392a52012-05-02 20:28:443613 }
[email protected]a4127722011-04-27 23:13:523614
[email protected]a220b5932013-09-21 03:47:443615#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503616 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3617 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443618 if (rwh_view) {
3619 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3620 render_widget_host->WasResized();
3621 }
[email protected]f8233cc2011-05-31 20:24:503622#endif
3623
[email protected]420ae012009-04-24 05:16:323624 return true;
3625}
3626
[email protected]7d244f12013-08-22 21:41:513627#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183628base::android::ScopedJavaLocalRef<jobject>
3629WebContentsImpl::GetJavaWebContents() {
3630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3631
3632 WebContentsAndroid* web_contents_android =
3633 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3634 if (!web_contents_android) {
3635 web_contents_android = new WebContentsAndroid(this);
3636 SetUserData(kWebContentsAndroidKey, web_contents_android);
3637 }
3638 return web_contents_android->GetJavaObject();
3639}
3640
[email protected]7d244f12013-08-22 21:41:513641bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3642 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163643 MSG_ROUTING_NONE,
3644 NULL);
[email protected]7d244f12013-08-22 21:41:513645}
3646#endif
3647
[email protected]b172aee2012-04-10 17:05:263648void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3649 IPC::Message* reply_msg,
3650 bool success,
[email protected]fcf75d42013-12-03 20:11:263651 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543652 if (is_showing_before_unload_dialog_ && !success) {
3653 // If a beforeunload dialog is canceled, we need to stop the throbber from
3654 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293655 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353656 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103657
[email protected]6d65a462013-06-21 21:29:123658 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3659 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543660 }
3661 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583662 static_cast<RenderViewHostImpl*>(
3663 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543664}
3665
[email protected]b172aee2012-04-10 17:05:263666void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213667 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123668 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103669}
[email protected]f45d2a72010-03-08 23:28:353670
[email protected]b172aee2012-04-10 17:05:263671void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103672 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443673 // Can be NULL during tests.
3674 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213675 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363676}
[email protected]9f76c1e2012-03-05 15:15:583677
[email protected]1ac10dca2013-08-20 20:47:043678bool WebContentsImpl::IsHidden() {
3679 return capturer_count_ == 0 && !should_normally_be_visible_;
3680}
3681
[email protected]b0936d22013-11-28 06:47:363682RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213683 return frame_tree_.root()->render_manager();
3684}
3685
[email protected]b172aee2012-04-10 17:05:263686RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583687 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3688}
[email protected]7900bfdb2012-05-24 19:31:243689
[email protected]f8497342013-02-05 22:15:023690BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393691 return browser_plugin_guest_.get();
3692}
3693
[email protected]738f57a2013-06-29 21:06:543694void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3695 CHECK(!browser_plugin_guest_);
3696 browser_plugin_guest_.reset(guest);
3697}
3698
[email protected]f8497342013-02-05 22:15:023699BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393700 return browser_plugin_embedder_.get();
3701}
[email protected]8ff00d72012-10-23 19:12:213702
[email protected]8eb04562013-03-06 03:41:143703BrowserPluginGuestManager*
3704 WebContentsImpl::GetBrowserPluginGuestManager() const {
3705 return static_cast<BrowserPluginGuestManager*>(
3706 GetBrowserContext()->GetUserData(
3707 browser_plugin::kBrowserPluginGuestManagerKeyName));
3708}
3709
[email protected]d9030b82013-07-19 08:26:063710void WebContentsImpl::ClearPowerSaveBlockers(
3711 RenderViewHost* render_view_host) {
3712 STLDeleteValues(&power_save_blockers_[render_view_host]);
3713 power_save_blockers_.erase(render_view_host);
3714}
3715
3716void WebContentsImpl::ClearAllPowerSaveBlockers() {
3717 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3718 i != power_save_blockers_.end(); ++i)
3719 STLDeleteValues(&power_save_blockers_[i->first]);
3720 power_save_blockers_.clear();
3721}
3722
[email protected]dc0fd432013-08-27 15:29:213723gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3724 gfx::Size size;
3725 if (delegate_)
3726 size = delegate_->GetSizeForNewRenderView(this);
3727 if (size.IsEmpty())
3728 size = view_->GetContainerSize();
3729 return size;
3730}
3731
[email protected]9b159a52013-10-03 17:24:553732void WebContentsImpl::OnFrameRemoved(
3733 RenderViewHostImpl* render_view_host,
3734 int64 frame_id) {
3735 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3736 FrameDetached(render_view_host, frame_id));
3737}
3738
[email protected]8ff00d72012-10-23 19:12:213739} // namespace content