blob: 3bc565d3f9c06b493478cba0be7f1a5beaac296a [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]b502ed462013-01-08 08:20:062166 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442167 RenderProcessHost* render_process_host =
2168 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422169 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252170 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312171 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472172 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442173 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182174}
2175
[email protected]b172aee2012-04-10 17:05:262176void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262177 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232178 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252179 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262180 if (!entry)
2181 return;
2182 // Note that we don't call NavigationController::GotToOffset() as we don't
2183 // want to create a pending navigation entry (it might end up lingering
2184 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252185 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212186 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512187 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212188 PAGE_TRANSITION_FORWARD_BACK));
[email protected]3691e5cf2014-01-22 10:16:202189 frame_tree_.root()->navigator()->NavigateToEntry(
2190 frame_tree_.GetMainFrame(),
2191 *entry,
2192 NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572193
2194 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2195 // it in now that we know. This allows us to find the entry when it commits.
2196 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232197 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332198 entry->set_site_instance(
2199 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572200 }
[email protected]216813952011-05-19 22:21:262201 }
2202}
2203
[email protected]b172aee2012-04-10 17:05:262204void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2205 int maximum_percent,
2206 bool remember) {
[email protected]216813952011-05-19 22:21:262207 minimum_zoom_percent_ = minimum_percent;
2208 maximum_zoom_percent_ = maximum_percent;
2209 temporary_zoom_settings_ = !remember;
2210}
2211
[email protected]b172aee2012-04-10 17:05:262212void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342213 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432214 if (!delegate_)
2215 return;
2216
[email protected]b9535422012-02-09 01:47:592217 ChildProcessSecurityPolicyImpl* policy =
2218 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222219 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592220 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212221}
2222
[email protected]b172aee2012-04-10 17:05:262223void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432224 if (delegate_)
2225 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202226}
2227
[email protected]b172aee2012-04-10 17:05:262228void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2229 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262230 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362231 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432232 if (!delegate_)
2233 return;
2234
[email protected]b9535422012-02-09 01:47:592235 ChildProcessSecurityPolicyImpl* policy =
2236 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322237 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592238 return;
[email protected]8f810632013-06-06 22:33:322239
[email protected]3a3b75a2012-06-01 08:38:362240 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202241}
2242
[email protected]b172aee2012-04-10 17:05:262243void WebContentsImpl::OnFindReply(int request_id,
2244 int number_of_matches,
2245 const gfx::Rect& selection_rect,
2246 int active_match_ordinal,
2247 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432248 if (delegate_) {
2249 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2250 active_match_ordinal, final_update);
2251 }
[email protected]b888919c2011-09-02 00:32:162252}
2253
[email protected]59363fc92012-09-05 03:46:312254#if defined(OS_ANDROID)
2255void WebContentsImpl::OnFindMatchRectsReply(
2256 int version,
2257 const std::vector<gfx::RectF>& rects,
2258 const gfx::RectF& active_rect) {
2259 if (delegate_)
2260 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2261}
[email protected]583418cc2013-01-17 14:01:102262
[email protected]1ff427972013-02-07 21:14:072263void WebContentsImpl::OnOpenDateTimeDialog(
2264 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092265 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2266 GetRenderViewHost(),
2267 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132268 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092269 value.minimum,
2270 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172271 value.step,
2272 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102273}
2274
[email protected]a794f3a2013-10-30 17:00:322275void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2276 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442277 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322278}
2279
[email protected]59363fc92012-09-05 03:46:312280#endif
2281
[email protected]f114fa42013-12-06 17:06:442282void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2283 const base::FilePath& path,
2284 bool is_hung) {
2285 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2286
2287 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2288 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2289}
2290
2291void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422292 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442293 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422294 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452295}
2296
[email protected]b172aee2012-04-10 17:05:262297void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2298 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102299 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252300 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102301 AppCacheAccessed(manifest_url, blocked_by_policy));
2302}
2303
[email protected]8bc5ff02013-11-29 06:34:032304void WebContentsImpl::OnOpenColorChooser(
2305 int color_chooser_id,
2306 SkColor color,
2307 const std::vector<ColorSuggestion>& suggestions) {
2308 ColorChooser* new_color_chooser =
2309 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302310 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212311 return;
[email protected]820957a2014-01-14 14:56:302312 if (color_chooser_)
2313 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212314 color_chooser_.reset(new_color_chooser);
2315 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202316}
2317
[email protected]b172aee2012-04-10 17:05:262318void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202319 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212320 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202321 color_chooser_->End();
2322}
2323
[email protected]b172aee2012-04-10 17:05:262324void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322325 SkColor color) {
[email protected]da8543762012-03-20 08:52:202326 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212327 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202328 color_chooser_->SetSelectedColor(color);
2329}
2330
[email protected]d0759f492012-04-19 22:50:502331// This exists for render views that don't have a WebUI, but do have WebUI
2332// bindings enabled.
2333void WebContentsImpl::OnWebUISend(const GURL& source_url,
2334 const std::string& name,
2335 const base::ListValue& args) {
2336 if (delegate_)
2337 delegate_->WebUISend(this, source_url, name, args);
2338}
2339
[email protected]d8415ad92012-08-23 14:40:502340void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442341 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502342 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342343 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162344 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442345 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162346 return;
[email protected]d8415ad92012-08-23 14:40:502347 }
2348
[email protected]8c8fc292012-11-23 18:57:162349 if (!delegate_->RequestPpapiBrokerPermission(
2350 this, url, plugin_path,
2351 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442352 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162353 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442354 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162355 }
[email protected]d8415ad92012-08-23 14:40:502356}
2357
[email protected]ea0309c2013-08-06 19:35:442358void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502359 bool result) {
[email protected]ea0309c2013-08-06 19:35:442360 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502361}
2362
[email protected]c4538072013-03-18 02:17:552363void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372364 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082365 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552366 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392367 // For more info, see comment above classes BrowserPluginEmbedder and
2368 // BrowserPluginGuest.
2369 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142370 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082371 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372372}
2373
[email protected]41225fe2013-03-29 05:32:022374void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392375 int id,
[email protected]749fadd2013-05-15 08:37:482376 int http_status_code,
[email protected]795c28972012-12-06 06:13:392377 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302378 const std::vector<SkBitmap>& bitmaps,
2379 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132380 if (bitmaps.size() != original_bitmap_sizes.size())
2381 return;
2382
[email protected]41225fe2013-03-29 05:32:022383 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2384 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392385 // Currently WebContents notifies us of ANY downloads so that it is
2386 // possible to get here.
2387 return;
2388 }
2389 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302390 iter->second.Run(
2391 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392392 }
[email protected]41225fe2013-03-29 05:32:022393 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392394}
2395
2396void WebContentsImpl::OnUpdateFaviconURL(
2397 int32 page_id,
2398 const std::vector<FaviconURL>& candidates) {
2399 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2400 DidUpdateFaviconURL(page_id, candidates));
2401}
2402
[email protected]d9030b82013-07-19 08:26:062403void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2404 bool has_video,
2405 bool has_audio,
2406 bool is_playing) {
2407 // Chrome OS does its own detection of audio and video.
2408#if !defined(OS_CHROMEOS)
2409 if (is_playing) {
2410 scoped_ptr<PowerSaveBlocker> blocker;
2411 if (has_video) {
2412 blocker = PowerSaveBlocker::Create(
2413 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2414 "Playing video");
2415#if defined(OS_ANDROID)
2416 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382417 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062418#endif
2419 } else if (has_audio) {
2420 blocker = PowerSaveBlocker::Create(
2421 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2422 "Playing audio");
2423 }
2424
[email protected]f114fa42013-12-06 17:06:442425 if (blocker) {
2426 power_save_blockers_[render_view_message_source_][player_cookie] =
2427 blocker.release();
2428 }
[email protected]d9030b82013-07-19 08:26:062429 } else {
[email protected]f114fa42013-12-06 17:06:442430 delete power_save_blockers_[render_view_message_source_][player_cookie];
2431 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062432 }
2433#endif // !defined(OS_CHROMEOS)
2434}
2435
[email protected]9f268072013-11-07 00:02:152436void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2437 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2438 DidFirstVisuallyNonEmptyPaint(page_id));
2439}
[email protected]d9030b82013-07-19 08:26:062440
[email protected]e67ebf32013-02-13 11:07:192441void WebContentsImpl::DidChangeVisibleSSLState() {
2442 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2443 DidChangeVisibleSSLState());
2444}
2445
[email protected]17e286e2013-03-01 23:29:392446void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2447 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2448 BeforeFormRepostWarningShow());
2449}
2450
[email protected]ec6c05f2013-10-23 18:41:572451
2452void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2453 Activate();
2454 if (delegate_)
2455 delegate_->ShowRepostFormWarningDialog(this);
2456}
2457
[email protected]96d185d2009-04-24 03:28:542458// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592459// loading, or done loading.
2460void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2461 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262462 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542463 if (is_loading == is_loading_)
2464 return;
2465
2466 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262467 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2468 base::string16());
[email protected]96d185d2009-04-24 03:28:542469 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562470 upload_size_ = 0;
2471 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542472 }
2473
[email protected]fa944cb82013-11-15 17:51:212474 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542475
2476 is_loading_ = is_loading;
2477 waiting_for_response_ = is_loading;
2478
[email protected]6ebdc9b2010-09-27 16:55:572479 if (delegate_)
2480 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212481 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542482
[email protected]eab61442013-11-14 18:35:482483 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592484 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482485 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2486 "URL", url);
[email protected]91621872013-10-08 04:04:592487 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2488 DidStartLoading(render_view_host));
2489 } else {
[email protected]eab61442013-11-14 18:35:482490 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2491 "URL", url);
[email protected]91621872013-10-08 04:04:592492 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2493 DidStopLoading(render_view_host));
2494 }
[email protected]66798902013-10-01 18:40:162495
2496 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212497 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2498 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542499 if (details)
[email protected]8ff00d72012-10-23 19:12:212500 det = Details<LoadNotificationDetails>(details);
2501 NotificationService::current()->Notify(
2502 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542503}
2504
[email protected]b172aee2012-04-10 17:05:262505void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212506 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322507 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562508 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322509 // Clear the status bubble. This is a workaround for a bug where WebKit
2510 // doesn't let us know that the cursor left an element during a
2511 // transition (this is also why the mouse cursor remains as a hand after
2512 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2513 // clear the bubble when a user navigates to a named anchor in the same
2514 // page.
[email protected]36fc0392011-12-25 03:59:512515 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322516 }
2517
[email protected]a6e82fc2010-02-24 22:28:142518 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472519 // Once the main frame is navigated, we're no longer considered to have
2520 // displayed insecure content.
2521 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352522 SSLManager::NotifySSLInternalStateChanged(
2523 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172524 }
[email protected]ce5c4502009-05-06 16:46:112525
[email protected]3c9e1872010-11-18 16:17:492526 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252527 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042528 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322529}
2530
[email protected]b172aee2012-04-10 17:05:262531void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322532 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212533 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322534 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112535 // If we navigate off the page, close all JavaScript dialogs.
2536 if (dialog_manager_ && !details.is_in_page)
2537 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322538
[email protected]3c9e1872010-11-18 16:17:492539 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252540 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042541 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322542}
2543
[email protected]2f7b3c5a2013-06-21 04:59:252544bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292545 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2546 // still be used for a normal web site.
2547 if (url == GURL(kAboutBlankURL))
2548 return false;
2549
2550 // The embedder will then have the opportunity to determine if the URL
2551 // should "use up" the SiteInstance.
2552 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252553}
2554
[email protected]b172aee2012-04-10 17:05:262555void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462556 // If we are creating a RVH for a restored controller, then we need to make
2557 // sure the RenderView starts with a next_page_id_ larger than the number
2558 // of restored entries. This must be called before the RenderView starts
2559 // navigating (to avoid a race between the browser updating max_page_id and
2560 // the renderer updating next_page_id_). Because of this, we only call this
2561 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562562 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582563 if (max_restored_page_id >
2564 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2565 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2566 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322567}
2568
[email protected]b172aee2012-04-10 17:05:262569bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262570 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322571 // For file URLs without a title, use the pathname instead. In the case of a
2572 // synthesized title, we don't want the update to count toward the "one set
2573 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262574 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322575 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512576 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242577 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322578 explicit_set = false; // Don't count synthetic titles toward the set limit.
2579 } else {
[email protected]acafd272011-07-26 17:35:572580 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322581 explicit_set = true;
2582 }
2583
[email protected]987fc3a2011-05-26 14:18:092584 // If a page is created via window.open and never navigated,
2585 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552586 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092587 if (entry) {
[email protected]36fc0392011-12-25 03:59:512588 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092589 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322590
[email protected]36fc0392011-12-25 03:59:512591 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092592 } else {
2593 if (page_title_when_no_navigation_entry_ == final_title)
2594 return false; // Nothing changed, don't bother.
2595
2596 page_title_when_no_navigation_entry_ = final_title;
2597 }
[email protected]420ae012009-04-24 05:16:322598
[email protected]420ae012009-04-24 05:16:322599 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232600 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322601
[email protected]66798902013-10-01 18:40:162602 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532603 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162604
2605 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212606 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462607 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212608 NotificationService::current()->Notify(
2609 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2610 Source<WebContents>(this),
2611 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042612
[email protected]420ae012009-04-24 05:16:322613 return true;
2614}
2615
[email protected]7b712ee22013-10-03 00:57:282616void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2617 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322618 // After sending out a swap notification, we need to send a disconnect
2619 // notification so that clients that pick up a pointer to |this| can NULL the
2620 // pointer. See Bug 1230284.
2621 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112622 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282623 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112624
2625 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282626 std::pair<RenderViewHost*, RenderViewHost*> details =
2627 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212628 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282629 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212630 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282631 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392632
2633 // Ensure that the associated embedder gets cleared after a RenderViewHost
2634 // gets swapped, so we don't reuse the same embedder next time a
2635 // RenderViewHost is attached to this WebContents.
2636 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322637}
2638
[email protected]da7a7182013-09-06 08:11:112639// TODO(avi): Remove this entire function because this notification is already
2640// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262641void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322642 if (!notify_disconnection_)
2643 return;
2644
2645 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212646 NotificationService::current()->Notify(
2647 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2648 Source<WebContents>(this),
2649 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322650}
2651
[email protected]cbb1ef592013-06-05 19:49:462652void WebContentsImpl::NotifyNavigationEntryCommitted(
2653 const LoadCommittedDetails& load_details) {
2654 FOR_EACH_OBSERVER(
2655 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2656}
2657
[email protected]f114fa42013-12-06 17:06:442658bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2659 const IPC::Message& message) {
2660 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312661}
2662
[email protected]b849847b2013-12-10 21:57:582663void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2664 // Note this is only for subframes, the notification for the main frame
2665 // happens in RenderViewCreated.
2666 FOR_EACH_OBSERVER(WebContentsObserver,
2667 observers_,
2668 RenderFrameCreated(render_frame_host));
2669}
2670
2671void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2672 FOR_EACH_OBSERVER(WebContentsObserver,
2673 observers_,
2674 RenderFrameDeleted(render_frame_host));
2675}
2676
[email protected]b765deb2013-12-18 06:43:302677void WebContentsImpl::WorkerCrashed() {
2678 if (delegate_)
2679 delegate_->WorkerCrashed(this);
2680}
2681
[email protected]a86c0e962013-12-17 17:10:392682WebContents* WebContentsImpl::GetAsWebContents() {
2683 return this;
2684}
2685
[email protected]5a3bdf52012-05-24 15:12:572686RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2687 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322688}
2689
[email protected]8d3347f2009-07-09 22:00:212690RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262691WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212692 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212693}
2694
[email protected]8ff00d72012-10-23 19:12:212695RendererPreferences WebContentsImpl::GetRendererPrefs(
2696 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462697 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512698}
2699
[email protected]b172aee2012-04-10 17:05:262700gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172701 if (delegate_)
2702 return delegate_->GetRootWindowResizerRect();
2703 return gfx::Rect();
2704}
2705
[email protected]7a846df2012-09-20 19:17:392706void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272707 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392708 browser_plugin_embedder_.reset();
2709}
2710
[email protected]b172aee2012-04-10 17:05:262711void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442712 // Don't send notifications if we are just creating a swapped-out RVH for
2713 // the opener chain. These won't be used for view-source or WebUI, so it's
2714 // ok to return early.
2715 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2716 return;
2717
[email protected]86f98a22013-03-20 14:35:002718 if (delegate_)
2719 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082720
[email protected]8ff00d72012-10-23 19:12:212721 NotificationService::current()->Notify(
2722 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2723 Source<WebContents>(this),
2724 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322725
2726 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352727 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212728 if (GetRenderManager()->pending_web_ui())
2729 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322730
[email protected]6286a372013-10-09 04:03:272731 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332732 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322733 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182734 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582735 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322736 }
[email protected]0666aef2009-05-13 19:48:082737
[email protected]60780f412013-02-25 16:34:102738 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262739
2740 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252741 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582742
2743 // We tell the observers now instead of when the main RenderFrameHostImpl is
2744 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2745 // frame would be dropped because it's not created yet).
2746 RenderFrameHost* main_frame = GetMainFrame();
2747 FOR_EACH_OBSERVER(
2748 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322749}
2750
[email protected]b172aee2012-04-10 17:05:262751void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522752 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322753 // Don't notify the world, since this came from a renderer in the
2754 // background.
2755 return;
2756 }
2757
[email protected]da7a7182013-09-06 08:11:112758 notify_disconnection_ = true;
2759 // TODO(avi): Remove. http://crbug.com/170921
2760 NotificationService::current()->Notify(
2761 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2762 Source<WebContents>(this),
2763 NotificationService::NoDetails());
2764
[email protected]be1f56ab2011-12-22 06:55:312765 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232766 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302767
2768 // Restore the focus to the tab (otherwise the focus will be on the top
2769 // window).
[email protected]484ae5912010-09-29 19:16:142770 if (was_crashed && !FocusLocationBarByDefault() &&
2771 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062772 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142773 }
[email protected]32ded2212011-11-10 18:51:432774
[email protected]d8c660432011-12-22 20:51:252775 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322776}
2777
[email protected]ec6a7eb2013-04-22 17:34:222778void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2779 base::TerminationStatus status,
2780 int error_code) {
[email protected]151a63d2011-12-20 22:32:522781 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322782 // The pending page's RenderViewHost is gone.
2783 return;
2784 }
2785
[email protected]d9030b82013-07-19 08:26:062786 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592787 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322788 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232789 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312790 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322791
[email protected]d8c660432011-12-22 20:51:252792 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272793 observers_,
[email protected]58d5cfe2013-07-10 02:40:522794 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322795}
2796
[email protected]b172aee2012-04-10 17:05:262797void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062798 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212799 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252800 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062801}
2802
[email protected]b172aee2012-04-10 17:05:262803void WebContentsImpl::DidNavigate(
2804 RenderViewHost* rvh,
[email protected]a1b99262013-12-27 21:56:222805 const ViewHostMsg_FrameNavigate_Params& orig_params) {
2806 ViewHostMsg_FrameNavigate_Params params(orig_params);
2807 bool use_site_per_process =
2808 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess);
[email protected]9b159a52013-10-03 17:24:552809 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2810 // First navigation should be a main frame navigation.
[email protected]a1b99262013-12-27 21:56:222811 // TODO(creis): This DCHECK is currently disabled for --site-per-process
2812 // because cross-process subframe navigations still have a main frame
2813 // PageTransition.
2814 if (!use_site_per_process)
2815 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552816 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122817 }
2818
[email protected]a1b99262013-12-27 21:56:222819 // When using --site-per-process, look up the FrameTreeNode ID that the
2820 // renderer-specific frame ID corresponds to.
2821 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id();
2822 if (use_site_per_process) {
2823 FrameTreeNode* source_node = frame_tree_.FindByFrameID(params.frame_id);
2824 if (source_node)
2825 frame_tree_node_id = source_node->frame_tree_node_id();
2826
2827 // TODO(creis): In the short term, cross-process subframe navigations are
2828 // happening in the pending RenderViewHost's top-level frame. (We need to
2829 // both mirror the frame tree and get the navigation to occur in the correct
2830 // subframe to fix this.) Until then, we should check whether we have a
2831 // pending NavigationEntry with a frame ID and if so, treat the
2832 // cross-process "main frame" navigation as a subframe navigation. This
2833 // limits us to a single cross-process subframe per RVH, and it affects
2834 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and
2835 // OnDidFinishLoad.
2836 NavigationEntryImpl* pending_entry =
2837 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
2838 int root_ftn_id = frame_tree_.root()->frame_tree_node_id();
2839 if (pending_entry &&
2840 pending_entry->frame_tree_node_id() != -1 &&
2841 pending_entry->frame_tree_node_id() != root_ftn_id) {
2842 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
2843 frame_tree_node_id = pending_entry->frame_tree_node_id();
2844 }
2845 }
2846
[email protected]e3d92a7f2013-01-10 02:35:052847 if (PageTransitionIsMainFrame(params.transition)) {
2848 // When overscroll navigation gesture is enabled, a screenshot of the page
2849 // in its current state is taken so that it can be used during the
2850 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362851 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052852 // WebContents::GetRenderViewHost to return the new host, instead of the one
2853 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482854 if (delegate_ && delegate_->CanOverscrollContent())
2855 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052856
[email protected]a1b99262013-12-27 21:56:222857 if (!use_site_per_process)
2858 GetRenderManager()->DidNavigateMainFrame(rvh);
2859 }
2860
2861 // When using --site-per-process, we notify the RFHM for all navigations,
2862 // not just main frame navigations.
2863 if (use_site_per_process) {
2864 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
2865 // TODO(creis): Rename to DidNavigateFrame.
2866 frame->render_manager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052867 }
[email protected]8030f012009-09-25 18:09:372868
[email protected]434f69f2012-02-06 21:56:522869 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252870 // assigning a site is not necessary for this URL. In that case, the
2871 // SiteInstance can still be considered unused until a navigation to a real
2872 // page.
[email protected]434f69f2012-02-06 21:56:522873 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252874 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332875 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522876 }
[email protected]420ae012009-04-24 05:16:322877
2878 // Need to update MIME type here because it's referred to in
2879 // UpdateNavigationCommands() called by RendererDidNavigate() to
2880 // determine whether or not to enable the encoding menu.
2881 // It's updated only for the main frame. For a subframe,
2882 // RenderView::UpdateURL does not set params.contents_mime_type.
2883 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2884 // TODO(jungshik): Add a test for the encoding menu to avoid
2885 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212886 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322887 contents_mime_type_ = params.contents_mime_type;
2888
[email protected]8ff00d72012-10-23 19:12:212889 LoadCommittedDetails details;
[email protected]a1b99262013-12-27 21:56:222890 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details);
[email protected]3e90d4a2009-07-03 17:38:392891
[email protected]1ae93fb2013-06-14 03:38:562892 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2893 // us estimate our process count for implementing OOP iframes.
2894 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552895 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562896
[email protected]a9c0bfe2010-09-17 08:35:222897 // Send notification about committed provisional loads. This notification is
2898 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2899 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212900 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072901 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2902 // that is not recorded in the navigation history. For the purpose of
2903 // tracking navigation events, we treat this event as a sub frame navigation
2904 // event.
2905 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212906 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222907 // Whether or not a page transition was triggered by going backward or
2908 // forward in the history is only stored in the navigation controller's
2909 // entry list.
2910 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272911 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212912 PAGE_TRANSITION_FORWARD_BACK)) {
2913 transition_type = PageTransitionFromInt(
2914 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222915 }
[email protected]0d60f0192011-04-14 12:40:102916 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252917 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442918 DidCommitProvisionalLoadForFrame(
2919 params.frame_id,
2920 params.frame_unique_name,
2921 is_main_frame,
2922 params.url,
2923 transition_type,
2924 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222925 }
2926
[email protected]76543b92009-08-31 17:27:452927 if (!did_navigate)
2928 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322929
2930 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2931 // for the appropriate notification (best) or you can add it to
2932 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2933 // necessary, please).
2934
2935 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002936 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322937 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002938 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512939 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002940 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2941 }
[email protected]93f230e02011-06-01 14:40:002942 }
[email protected]420ae012009-04-24 05:16:322943 DidNavigateAnyFramePostCommit(rvh, details, params);
2944}
2945
[email protected]b172aee2012-04-10 17:05:262946void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2947 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042948 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152949 // Ensure that this state update comes from either the active RVH or one of
2950 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412951 // TODO(nasko): This should go through RenderFrameHost.
2952 // TODO(creis): We can't update state for cross-process subframes until we
2953 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2954 if (rvh != GetRenderViewHost() &&
2955 !GetRenderManager()->IsRVHOnSwappedOutList(
2956 static_cast<RenderViewHostImpl*>(rvh)))
2957 return;
[email protected]420ae012009-04-24 05:16:322958
2959 // We must be prepared to handle state updates for any page, these occur
2960 // when the user is scrolling and entering form data, as well as when we're
2961 // leaving a page, in which case our state may have already been moved to
2962 // the next page. The navigation controller will look up the appropriate
2963 // NavigationEntry and update it when it is notified via the delegate.
2964
2965 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582966 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322967 if (entry_index < 0)
2968 return;
[email protected]10f417c52011-12-28 21:04:232969 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322970
[email protected]691aa2f2013-05-28 22:52:042971 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322972 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042973 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322974 controller_.NotifyEntryChanged(entry, entry_index);
2975}
2976
[email protected]b172aee2012-04-10 17:05:262977void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2978 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262979 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262980 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322981 // If we have a title, that's a pretty good indication that we've started
2982 // getting useful data.
2983 SetNotWaitingForResponse();
2984
[email protected]73eb2602012-02-09 19:50:552985 // Try to find the navigation entry, which might not be the current one.
2986 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232987 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582988 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092989
[email protected]73eb2602012-02-09 19:50:552990 // We can handle title updates when we don't have an entry in
2991 // UpdateTitleForEntry, but only if the update is from the current RVH.
2992 if (!entry && rvh != GetRenderViewHost())
2993 return;
2994
[email protected]a49e10b2011-08-01 23:57:462995 // TODO(evan): make use of title_direction.
2996 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092997 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322998 return;
2999
3000 // Broadcast notifications when the UI should be updated.
3001 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213002 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323003}
3004
[email protected]b172aee2012-04-10 17:05:263005void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3006 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313007 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323008}
3009
[email protected]b172aee2012-04-10 17:05:263010void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513011 if (delegate_)
3012 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323013}
3014
[email protected]b172aee2012-04-10 17:05:263015void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103016#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293017 // The UI may be in an event-tracking loop, such as between the
3018 // mouse-down and mouse-up in text selection or a button click.
3019 // Defer the close until after tracking is complete, so that we
3020 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293021 // TODO(shess): This could get more fine-grained. For instance,
3022 // closing a tab in another window while selecting text in the
3023 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103024 if (view_->IsEventTracking()) {
3025 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293026 return;
3027 }
[email protected]60780f412013-02-25 16:34:103028#endif
[email protected]07707302009-11-06 00:50:293029
[email protected]420ae012009-04-24 05:16:323030 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523031 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513032 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323033}
3034
[email protected]b172aee2012-04-10 17:05:263035void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523036 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513037 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283038
3039 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213040 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573041}
3042
[email protected]b172aee2012-04-10 17:05:263043void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513044 if (delegate_ && delegate_->IsPopupOrPanel(this))
3045 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323046}
3047
[email protected]8ff00d72012-10-23 19:12:213048void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593049 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323050}
3051
[email protected]8ff00d72012-10-23 19:12:213052void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323053 scoped_ptr<LoadNotificationDetails> details;
3054
[email protected]9595fd82013-04-19 21:28:493055 // Use the last committed entry rather than the active one, in case a
3056 // pending entry has been created.
3057 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203058 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493059
[email protected]420ae012009-04-24 05:16:323060 // An entry may not exist for a stop when loading an initial blank page or
3061 // if an iframe injected by script into a blank page finishes loading.
3062 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203063 base::TimeDelta elapsed =
3064 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323065
3066 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513067 entry->GetVirtualURL(),
3068 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323069 elapsed,
3070 &controller_,
3071 controller_.GetCurrentEntryIndex()));
3072 }
3073
[email protected]91621872013-10-08 04:04:593074 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323075}
3076
[email protected]b172aee2012-04-10 17:05:263077void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163078 controller_.DiscardNonCommittedEntries();
3079
3080 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213081 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163082}
3083
[email protected]b172aee2012-04-10 17:05:263084void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513085 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133086 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403087}
3088
[email protected]7cc78902012-12-06 02:32:263089void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393090 if (opener_) {
3091 // Clear our opener so that future cross-process navigations don't have an
3092 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103093 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393094 opener_ = NULL;
3095 }
[email protected]7cc78902012-12-06 02:32:263096
3097 // Notify all swapped out RenderViewHosts for this tab. This is important
3098 // in case we go back to them, or if another window in those processes tries
3099 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213100 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263101}
3102
[email protected]59167c22013-06-03 18:07:323103void WebContentsImpl::DidAccessInitialDocument() {
3104 // Update the URL display.
3105 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3106}
3107
[email protected]87717d0e2012-04-26 02:58:433108void WebContentsImpl::DocumentAvailableInMainFrame(
3109 RenderViewHost* render_view_host) {
3110 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3111 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103112}
3113
[email protected]b172aee2012-04-10 17:05:263114void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083115 RenderViewHost* render_view_host,
3116 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093117 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3118 DocumentOnLoadCompletedInMainFrame(page_id));
3119
3120 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213121 NotificationService::current()->Notify(
3122 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3123 Source<WebContents>(this),
3124 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083125}
3126
[email protected]196159d2012-05-04 17:26:543127void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3128 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213129 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263130 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183131 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523132 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303133 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543134 // If this came from a swapped out RenderViewHost, we only allow the request
3135 // if we are still in the same BrowsingInstance.
3136 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3137 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3138 return;
3139 }
3140
[email protected]4ad5d77d2011-12-03 02:00:483141 // Delegate to RequestTransferURL because this is just the generic
3142 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573143 // TODO(creis): Pass the redirect_chain into this method to support client
3144 // redirects. http://crbug.com/311721.
3145 std::vector<GURL> redirect_chain;
3146 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3147 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523148 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483149}
3150
[email protected]b172aee2012-04-10 17:05:263151void WebContentsImpl::RequestTransferURL(
3152 const GURL& url,
[email protected]f8872902013-10-30 03:18:573153 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213154 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573155 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263156 WindowOpenDisposition disposition,
3157 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183158 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523159 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303160 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203161 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123162 GURL dest_url(url);
3163 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553164 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123165 dest_url = GURL(kAboutBlankURL);
3166
[email protected]a1b99262013-12-27 21:56:223167 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3168 int64 frame_tree_node_id = -1;
3169 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3170 source_frame_id != -1) {
3171 FrameTreeNode* source_node = frame_tree_.FindByFrameID(source_frame_id);
3172 if (source_node)
3173 frame_tree_node_id = source_node->frame_tree_node_id();
3174 }
[email protected]c80297782013-11-21 07:10:163175 OpenURLParams params(dest_url, referrer, source_frame_id,
3176 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573177 page_transition, true /* is_renderer_initiated */);
3178 if (redirect_chain.size() > 0)
3179 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553180 params.transferred_global_request_id = old_request_id;
3181 params.should_replace_current_entry = should_replace_current_entry;
3182 params.user_gesture = user_gesture;
3183
[email protected]fa944cb82013-11-15 17:51:213184 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573185 // Web UI pages sometimes want to override the page transition type for
3186 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3187 // automatically generated suggestions). We don't override other types
3188 // like TYPED because they have different implications (e.g., autocomplete).
3189 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213190 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553191
[email protected]e0112912011-02-02 22:54:353192 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163193 // want web sites to see a referrer of "chrome://blah" (and some
3194 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323195 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553196 params.referrer = Referrer();
3197
3198 // Navigations in Web UI pages count as browser-initiated navigations.
3199 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583200 }
[email protected]44d0930a2013-10-28 18:53:553201
3202 new_contents = OpenURL(params);
3203
[email protected]ae5184d62011-10-06 19:25:583204 if (new_contents) {
3205 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253206 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583207 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123208 dest_url,
[email protected]ae5184d62011-10-06 19:25:583209 referrer,
3210 disposition,
[email protected]44d0930a2013-10-28 18:53:553211 params.transition,
[email protected]ae5184d62011-10-06 19:25:583212 source_frame_id));
[email protected]420ae012009-04-24 05:16:323213 }
3214}
3215
[email protected]e1c3a552012-05-04 20:51:323216void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3217 // Tell the active RenderViewHost to run unload handlers and close, as long
3218 // as the request came from a RenderViewHost in the same BrowsingInstance.
3219 // In most cases, we receive this from a swapped out RenderViewHost.
3220 // It is possible to receive it from one that has just been swapped in,
3221 // in which case we might as well deliver the message anyway.
3222 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3223 GetRenderViewHost()->ClosePage();
3224}
3225
[email protected]f546640b2012-05-15 00:03:493226void WebContentsImpl::RouteMessageEvent(
3227 RenderViewHost* rvh,
3228 const ViewMsg_PostMessage_Params& params) {
3229 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363230 // came from a RenderViewHost in the same BrowsingInstance or if this
3231 // WebContents is dedicated to a browser plugin guest.
3232 // Note: This check means that an embedder could theoretically receive a
3233 // postMessage from anyone (not just its own guests). However, this is
3234 // probably not a risk for apps since other pages won't have references
3235 // to App windows.
3236 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3237 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493238 return;
3239
3240 ViewMsg_PostMessage_Params new_params(params);
3241
[email protected]0bc7f3542013-10-21 15:05:533242 if (!params.message_port_ids.empty()) {
3243 MessagePortMessageFilter* message_port_message_filter =
3244 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3245 ->message_port_message_filter();
3246 std::vector<int> new_routing_ids(params.message_port_ids.size());
3247 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3248 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3249 MessagePortService::GetInstance()->UpdateMessagePort(
3250 params.message_port_ids[i],
3251 message_port_message_filter,
3252 new_routing_ids[i]);
3253 }
3254 new_params.new_routing_ids = new_routing_ids;
3255 }
3256
[email protected]f546640b2012-05-15 00:03:493257 // If there is a source_routing_id, translate it to the routing ID for
3258 // the equivalent swapped out RVH in the target process. If we need
3259 // to create a swapped out RVH for the source tab, we create its opener
3260 // chain as well, since those will also be accessible to the target page.
3261 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3262 // Try to look up the WebContents for the source page.
3263 WebContentsImpl* source_contents = NULL;
3264 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3265 rvh->GetProcess()->GetID(), params.source_routing_id);
3266 if (source_rvh) {
3267 source_contents = static_cast<WebContentsImpl*>(
3268 source_rvh->GetDelegate()->GetAsWebContents());
3269 }
3270
3271 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363272 if (GetBrowserPluginGuest()) {
3273 // We create a swapped out RenderView for the embedder in the guest's
3274 // render process but we intentionally do not expose the embedder's
3275 // opener chain to it.
3276 new_params.source_routing_id =
3277 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3278 } else {
3279 new_params.source_routing_id =
3280 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3281 }
[email protected]f546640b2012-05-15 00:03:493282 } else {
3283 // We couldn't find it, so don't pass a source frame.
3284 new_params.source_routing_id = MSG_ROUTING_NONE;
3285 }
3286 }
3287
3288 // In most cases, we receive this from a swapped out RenderViewHost.
3289 // It is possible to receive it from one that has just been swapped in,
3290 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183291 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493292}
3293
[email protected]b172aee2012-04-10 17:05:263294void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343295 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263296 const base::string16& message,
3297 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323298 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213299 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323300 IPC::Message* reply_msg,
3301 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073302 // Suppress JavaScript dialogs when requested. Also suppress messages when
3303 // showing an interstitial as it's shown over the previous page and we don't
3304 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503305 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583306 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273307 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073308 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523309 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153310 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323311
3312 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213313 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433314 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153315 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3316 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433317 this,
3318 frame_url.GetOrigin(),
3319 accept_lang,
3320 javascript_message_type,
3321 message,
[email protected]51da7e32012-01-30 19:24:523322 default_prompt,
[email protected]b172aee2012-04-10 17:05:263323 base::Bind(&WebContentsImpl::OnDialogClosed,
3324 base::Unretained(this),
3325 rvh,
3326 reply_msg),
[email protected]51da7e32012-01-30 19:24:523327 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323328 }
[email protected]3ab9cb82011-06-03 18:02:073329
[email protected]6dd2f1e2013-09-11 15:06:013330 *did_suppress_message = suppress_this_message;
3331
[email protected]3ab9cb82011-06-03 18:02:073332 if (suppress_this_message) {
3333 // If we are suppressing messages, just reply as if the user immediately
3334 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263335 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073336 }
3337
[email protected]6dd2f1e2013-09-11 15:06:013338 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3339 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323340}
3341
[email protected]b172aee2012-04-10 17:05:263342void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263343 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263344 bool is_reload,
3345 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583346 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513347 if (delegate_)
3348 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073349
3350 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583351 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073352 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523353 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153354 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153355 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343356 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263357 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503358 return;
3359 }
[email protected]3ab9cb82011-06-03 18:02:073360
[email protected]7ab1e7d62009-10-14 23:32:013361 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153362 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3363 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323364 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263365 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523366 reply_msg));
[email protected]420ae012009-04-24 05:16:323367}
3368
[email protected]a796f202012-05-30 14:14:253369bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263370 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253371 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263372 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253373 if (!delegate_)
3374 return false;
3375 return delegate_->AddMessageToConsole(this, level, message, line_no,
3376 source_id);
3377}
3378
[email protected]b172aee2012-04-10 17:05:263379WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273380 // We want to base the page config off of the actual URL, rather than the
3381 // virtual URL.
3382 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3383 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003384 GURL url = controller_.GetActiveEntry()
3385 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153386
[email protected]fa944cb82013-11-15 17:51:213387 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323388}
3389
[email protected]0eba810b2012-10-18 03:19:363390int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213391 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413392 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3393 true, true);
[email protected]0eba810b2012-10-18 03:19:363394}
3395
[email protected]b172aee2012-04-10 17:05:263396void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273397 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253398 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223399
[email protected]ea114722012-03-12 01:11:253400 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173401 if (rdh) // NULL in unittests.
3402 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253403}
3404
[email protected]b172aee2012-04-10 17:05:263405void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443406 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253407 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443408}
3409
[email protected]b172aee2012-04-10 17:05:263410void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563411 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263412 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153413 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523414 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153415 return;
3416
[email protected]9f76c1e2012-03-05 15:15:583417 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3418
[email protected]e5fc1632011-08-08 07:51:533419 // Ignore renderer unresponsive event if debugger is attached to the tab
3420 // since the event may be a result of the renderer sitting on a breakpoint.
3421 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363422 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533423 return;
3424
[email protected]2e9d79f2013-08-16 05:45:563425 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323426 // Hang occurred while firing the beforeunload/unload handler.
3427 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583428 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323429
[email protected]fa944cb82013-11-15 17:51:213430 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323431 return;
3432
3433 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563434 // nothing we can do to recover. If the hang is in the beforeunload handler,
3435 // pretend the beforeunload listeners have all fired and allow the delegate
3436 // to continue closing; the user will not have the option of cancelling the
3437 // close. Otherwise, pretend the unload listeners have all fired and close
3438 // the tab.
3439 bool close = true;
3440 if (is_during_beforeunload) {
3441 delegate_->BeforeUnloadFired(this, true, &close);
3442 }
3443 if (close)
3444 Close(rvh);
[email protected]420ae012009-04-24 05:16:323445 return;
3446 }
3447
[email protected]9f76c1e2012-03-05 15:15:583448 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473449 return;
3450
[email protected]6934a702011-12-20 00:04:513451 if (delegate_)
3452 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323453}
3454
[email protected]b172aee2012-04-10 17:05:263455void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513456 if (delegate_)
3457 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323458}
3459
[email protected]b172aee2012-04-10 17:05:263460void WebContentsImpl::LoadStateChanged(
3461 const GURL& url,
3462 const net::LoadStateWithParam& load_state,
3463 uint64 upload_position,
3464 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323465 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563466 upload_position_ = upload_position;
3467 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503468 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213469 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303470 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213471 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323472 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463473 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213474 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463475 }
[email protected]420ae012009-04-24 05:16:323476}
3477
[email protected]b172aee2012-04-10 17:05:263478void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553479 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323480 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123481 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3482 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513483 if (delegate_)
3484 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093485 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323486}
3487
[email protected]58d5cfe2013-07-10 02:40:523488void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543489 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233490 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223491 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543492}
3493
[email protected]b172aee2012-04-10 17:05:263494void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103495 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213496 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263497 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3498 // here during container initialization and normal window size will be set
3499 // later. In case of tab duplication this resizing to 0x0 prevents setting
3500 // normal size later so just ignore it.
3501 if (!size.IsEmpty())
3502 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323503}
3504
[email protected]af905902013-10-01 21:38:513505void WebContentsImpl::CancelModalDialogsForRenderManager() {
3506 // We need to cancel modal dialogs when doing a process swap, since the load
3507 // deferrer would prevent us from swapping out.
3508 if (dialog_manager_)
3509 dialog_manager_->CancelActiveAndPendingDialogs(this);
3510}
3511
[email protected]7b712ee22013-10-03 00:57:283512void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3513 RenderViewHost* new_host) {
3514 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083515
3516 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003517 if (delegate_)
3518 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393519
[email protected]7b712ee22013-10-03 00:57:283520 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543521}
3522
[email protected]14392a52012-05-02 20:28:443523int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3524 SiteInstance* instance) {
3525 if (!opener_)
3526 return MSG_ROUTING_NONE;
3527
3528 // Recursively create RenderViews for anything else in the opener chain.
3529 return opener_->CreateOpenerRenderViews(instance);
3530}
3531
3532int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3533 int opener_route_id = MSG_ROUTING_NONE;
3534
3535 // If this tab has an opener, ensure it has a RenderView in the given
3536 // SiteInstance as well.
3537 if (opener_)
3538 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3539
[email protected]45a22ad2013-02-21 03:25:003540 // If any of the renderers (current, pending, or swapped out) for this
3541 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213542 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3543 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373544
[email protected]fa944cb82013-11-15 17:51:213545 if (GetRenderManager()->pending_render_view_host() &&
3546 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3547 instance)
3548 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003549
[email protected]fa944cb82013-11-15 17:51:213550 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373551 instance);
3552 if (rvh)
3553 return rvh->GetRoutingID();
3554
[email protected]14392a52012-05-02 20:28:443555 // Create a swapped out RenderView in the given SiteInstance if none exists,
3556 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413557 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3558 true, true);
[email protected]14392a52012-05-02 20:28:443559}
3560
[email protected]b172aee2012-04-10 17:05:263561NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193562 return GetController();
[email protected]3a3d47472010-07-15 21:03:543563}
3564
[email protected]b172aee2012-04-10 17:05:263565WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563566 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323567}
3568
[email protected]10f417c52011-12-28 21:04:233569NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263570 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323571 return controller_.GetLastCommittedEntry();
3572}
3573
[email protected]b172aee2012-04-10 17:05:263574bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163575 RenderViewHost* render_view_host,
3576 int opener_route_id,
3577 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033578 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443579 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163580 RenderWidgetHostView* rwh_view;
3581 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3582 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3583 // case this because RWH is still a base class of RenderViewHost, and child
3584 // frame RWHVs are unique in that they do not have their own WebContents.
3585 if (frame_connector) {
3586 RenderWidgetHostViewChildFrame* rwh_view_child =
3587 new RenderWidgetHostViewChildFrame(render_view_host);
3588 frame_connector->set_view(rwh_view_child);
3589 rwh_view = rwh_view_child;
3590 } else {
3591 rwh_view = view_->CreateViewForWidget(render_view_host);
3592 }
[email protected]1a98a932009-11-17 00:12:523593
[email protected]420ae012009-04-24 05:16:323594 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443595 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213596 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323597
[email protected]74ce1ad2011-12-16 21:51:463598 // Make sure we use the correct starting page_id in the new RenderView.
3599 UpdateMaxPageIDIfNecessary(render_view_host);
3600 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583601 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463602
[email protected]9f76c1e2012-03-05 15:15:583603 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263604 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493605 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133606 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523607 return false;
[email protected]14392a52012-05-02 20:28:443608 }
[email protected]a4127722011-04-27 23:13:523609
[email protected]a220b5932013-09-21 03:47:443610#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503611 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3612 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443613 if (rwh_view) {
3614 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3615 render_widget_host->WasResized();
3616 }
[email protected]f8233cc2011-05-31 20:24:503617#endif
3618
[email protected]420ae012009-04-24 05:16:323619 return true;
3620}
3621
[email protected]7d244f12013-08-22 21:41:513622#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183623base::android::ScopedJavaLocalRef<jobject>
3624WebContentsImpl::GetJavaWebContents() {
3625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3626
3627 WebContentsAndroid* web_contents_android =
3628 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3629 if (!web_contents_android) {
3630 web_contents_android = new WebContentsAndroid(this);
3631 SetUserData(kWebContentsAndroidKey, web_contents_android);
3632 }
3633 return web_contents_android->GetJavaObject();
3634}
3635
[email protected]7d244f12013-08-22 21:41:513636bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3637 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163638 MSG_ROUTING_NONE,
3639 NULL);
[email protected]7d244f12013-08-22 21:41:513640}
3641#endif
3642
[email protected]b172aee2012-04-10 17:05:263643void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3644 IPC::Message* reply_msg,
3645 bool success,
[email protected]fcf75d42013-12-03 20:11:263646 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543647 if (is_showing_before_unload_dialog_ && !success) {
3648 // If a beforeunload dialog is canceled, we need to stop the throbber from
3649 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293650 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353651 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103652
[email protected]6d65a462013-06-21 21:29:123653 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3654 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543655 }
3656 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583657 static_cast<RenderViewHostImpl*>(
3658 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543659}
3660
[email protected]b172aee2012-04-10 17:05:263661void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213662 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123663 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103664}
[email protected]f45d2a72010-03-08 23:28:353665
[email protected]b172aee2012-04-10 17:05:263666void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103667 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443668 // Can be NULL during tests.
3669 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213670 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363671}
[email protected]9f76c1e2012-03-05 15:15:583672
[email protected]1ac10dca2013-08-20 20:47:043673bool WebContentsImpl::IsHidden() {
3674 return capturer_count_ == 0 && !should_normally_be_visible_;
3675}
3676
[email protected]b0936d22013-11-28 06:47:363677RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213678 return frame_tree_.root()->render_manager();
3679}
3680
[email protected]b172aee2012-04-10 17:05:263681RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583682 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3683}
[email protected]7900bfdb2012-05-24 19:31:243684
[email protected]f8497342013-02-05 22:15:023685BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393686 return browser_plugin_guest_.get();
3687}
3688
[email protected]738f57a2013-06-29 21:06:543689void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3690 CHECK(!browser_plugin_guest_);
3691 browser_plugin_guest_.reset(guest);
3692}
3693
[email protected]f8497342013-02-05 22:15:023694BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393695 return browser_plugin_embedder_.get();
3696}
[email protected]8ff00d72012-10-23 19:12:213697
[email protected]8eb04562013-03-06 03:41:143698BrowserPluginGuestManager*
3699 WebContentsImpl::GetBrowserPluginGuestManager() const {
3700 return static_cast<BrowserPluginGuestManager*>(
3701 GetBrowserContext()->GetUserData(
3702 browser_plugin::kBrowserPluginGuestManagerKeyName));
3703}
3704
[email protected]d9030b82013-07-19 08:26:063705void WebContentsImpl::ClearPowerSaveBlockers(
3706 RenderViewHost* render_view_host) {
3707 STLDeleteValues(&power_save_blockers_[render_view_host]);
3708 power_save_blockers_.erase(render_view_host);
3709}
3710
3711void WebContentsImpl::ClearAllPowerSaveBlockers() {
3712 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3713 i != power_save_blockers_.end(); ++i)
3714 STLDeleteValues(&power_save_blockers_[i->first]);
3715 power_save_blockers_.clear();
3716}
3717
[email protected]dc0fd432013-08-27 15:29:213718gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3719 gfx::Size size;
3720 if (delegate_)
3721 size = delegate_->GetSizeForNewRenderView(this);
3722 if (size.IsEmpty())
3723 size = view_->GetContainerSize();
3724 return size;
3725}
3726
[email protected]9b159a52013-10-03 17:24:553727void WebContentsImpl::OnFrameRemoved(
3728 RenderViewHostImpl* render_view_host,
3729 int64 frame_id) {
3730 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3731 FrameDetached(render_view_host, frame_id));
3732}
3733
[email protected]8ff00d72012-10-23 19:12:213734} // namespace content