blob: 8dac42d29f9d94af2feab5c61f5f5934aa6a5533 [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]1dd0bb752014-02-01 01:16:26479 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
480 OnMediaPlayingNotification)
481 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
482 OnMediaPausedNotification)
[email protected]9f268072013-11-07 00:02:15483 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
484 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07485 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
486 OnShowValidationMessage)
487 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
488 OnHideValidationMessage)
489 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
490 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18491 IPC_MESSAGE_UNHANDLED(handled = false)
492 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44493 render_view_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18494
495 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39496 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18497 GetRenderProcessHost()->ReceivedBadMessage();
498 }
499
500 return handled;
501}
502
[email protected]b172aee2012-04-10 17:05:26503void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18504 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21505 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43506 if (delegate_)
507 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18508}
509
[email protected]d1198fd2012-08-13 22:50:19510NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56511 return controller_;
512}
513
[email protected]d1198fd2012-08-13 22:50:19514const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56515 return controller_;
516}
517
[email protected]8ff00d72012-10-23 19:12:21518BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55519 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30520}
521
[email protected]b172aee2012-04-10 17:05:26522const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24523 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32524 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51525 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31526}
527
[email protected]a093ce02013-07-22 20:53:14528const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24529 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32530 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24531 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
532}
533
534const GURL& WebContentsImpl::GetLastCommittedURL() const {
535 // We may not have a navigation entry yet.
536 NavigationEntry* entry = controller_.GetLastCommittedEntry();
537 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
538}
539
[email protected]8ff00d72012-10-23 19:12:21540WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31541 return delegate_;
542}
543
[email protected]8ff00d72012-10-23 19:12:21544void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31545 // TODO(cbentzel): remove this debugging code?
546 if (delegate == delegate_)
547 return;
548 if (delegate_)
549 delegate_->Detach(this);
550 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08551 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31552 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08553 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00554 if (view_)
555 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08556 }
[email protected]be1f56ab2011-12-22 06:55:31557}
558
[email protected]8ff00d72012-10-23 19:12:21559RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21560 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41561 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16562}
563
[email protected]60eca4eb2013-12-06 00:02:16564RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41565 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16566}
567
[email protected]a86c0e962013-12-17 17:10:39568void WebContentsImpl::ForEachFrame(
569 const base::Callback<void(RenderFrameHost*)>& on_frame) {
570 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
571}
572
573void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
574 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
575 delete message;
576}
577
[email protected]b172aee2012-04-10 17:05:26578RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21579 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31580}
581
[email protected]a04c9d02012-11-14 21:04:34582void WebContentsImpl::GetRenderViewHostAtPosition(
583 int x,
584 int y,
585 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
586 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
587 if (embedder)
588 embedder->GetRenderViewHostAtPosition(x, y, callback);
589 else
590 callback.Run(GetRenderViewHost(), x, y);
591}
592
[email protected]bfcfa692013-02-07 06:17:02593WebContents* WebContentsImpl::GetEmbedderWebContents() const {
594 BrowserPluginGuest* guest = GetBrowserPluginGuest();
595 if (guest)
596 return guest->embedder_web_contents();
597 return NULL;
598}
599
600int WebContentsImpl::GetEmbeddedInstanceID() const {
601 BrowserPluginGuest* guest = GetBrowserPluginGuest();
602 if (guest)
603 return guest->instance_id();
604 return 0;
605}
606
[email protected]6b618e62012-08-16 12:59:18607int WebContentsImpl::GetRoutingID() const {
608 if (!GetRenderViewHost())
609 return MSG_ROUTING_NONE;
610
611 return GetRenderViewHost()->GetRoutingID();
612}
613
[email protected]44470a22013-01-24 01:21:54614int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
615 return fullscreen_widget_routing_id_;
616}
617
[email protected]b172aee2012-04-10 17:05:26618RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21619 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31620}
621
[email protected]f8497342013-02-05 22:15:02622RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
623 BrowserPluginGuest* guest = GetBrowserPluginGuest();
624 if (guest && guest->embedder_web_contents()) {
625 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
626 }
627 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
628}
629
[email protected]4aebbca2013-09-17 22:26:49630RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
631 const {
632 RenderWidgetHost* const widget_host =
633 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
634 GetFullscreenWidgetRoutingID());
635 return widget_host ? widget_host->GetView() : NULL;
636}
637
[email protected]8ff00d72012-10-23 19:12:21638WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31639 return view_.get();
640}
641
[email protected]8ff00d72012-10-23 19:12:21642WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56643 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03644 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
645 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22646 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58647 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22648 web_ui->SetController(controller);
649 return web_ui;
650 }
651
652 delete web_ui;
653 return NULL;
654}
655
[email protected]8ff00d72012-10-23 19:12:21656WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21657 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
658 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31659}
660
[email protected]8ff00d72012-10-23 19:12:21661WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21662 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34663}
664
[email protected]86ef6a392012-05-11 22:03:11665void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22666 if (GetUserAgentOverride() == override)
667 return;
668
669 renderer_preferences_.user_agent_override = override;
670
671 // Send the new override string to the renderer.
672 RenderViewHost* host = GetRenderViewHost();
673 if (host)
674 host->SyncRendererPrefs();
675
676 // Reload the page if a load is currently in progress to avoid having
677 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27678 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22679 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
680 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53681
682 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
683 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11684}
685
686const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22687 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11688}
689
[email protected]2ceee8f2014-01-14 18:02:08690#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41691void WebContentsImpl::SetParentNativeViewAccessible(
692gfx::NativeViewAccessible accessible_parent) {
693 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45694 if (GetRenderViewHost())
695 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41696}
697#endif
698
[email protected]fcf75d42013-12-03 20:11:26699const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55700 // Transient entries take precedence. They are used for interstitial pages
701 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23702 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08703 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21704 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30705 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23706 if (entry) {
[email protected]b5cca982011-05-26 04:42:08707 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23708 }
[email protected]fa944cb82013-11-15 17:51:21709 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
710 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58711 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54712 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32713 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54714 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35715 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26716 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54717 if (!title.empty())
718 return title;
719 }
720 }
721
722 // We use the title for the last committed entry rather than a pending
723 // navigation entry. For example, when the user types in a URL, we want to
724 // keep the old page's title until the new load has committed and we get a new
725 // title.
[email protected]96d185d2009-04-24 03:28:54726 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32727
[email protected]9eeafc012013-11-25 23:49:47728 // We make an exception for initial navigations.
729 if (controller_.IsInitialNavigation()) {
730 // We only want to use the title from the visible entry in one of two cases:
731 // 1. There's already a committed entry for an initial navigation, in which
732 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
733 // 2. The pending entry has been explicitly assigned a title to display.
734 //
735 // If there's no last committed entry and no assigned title, we should fall
736 // back to |page_title_when_no_navigation_entry_| rather than showing the
737 // URL.
738 if (entry ||
739 (controller_.GetVisibleEntry() &&
740 !controller_.GetVisibleEntry()->GetTitle().empty())) {
741 entry = controller_.GetVisibleEntry();
742 }
743 }
[email protected]59167c22013-06-03 18:07:32744
[email protected]45d0ef7f2011-01-05 13:46:23745 if (entry) {
[email protected]b5cca982011-05-26 04:42:08746 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23747 }
[email protected]987fc3a2011-05-26 14:18:09748
749 // |page_title_when_no_navigation_entry_| is finally used
750 // if no title cannot be retrieved.
751 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54752}
753
[email protected]b172aee2012-04-10 17:05:26754int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46755 return GetMaxPageIDForSiteInstance(GetSiteInstance());
756}
757
[email protected]b172aee2012-04-10 17:05:26758int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
759 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33760 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
761 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46762
[email protected]b6583592012-01-25 19:52:33763 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34764}
765
[email protected]b172aee2012-04-10 17:05:26766void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46767 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
768}
769
[email protected]b172aee2012-04-10 17:05:26770void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33771 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46772 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33773 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34774}
775
[email protected]ec6c05f2013-10-23 18:41:57776void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
777 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
778 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57779}
780
[email protected]b172aee2012-04-10 17:05:26781SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21782 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54783}
784
[email protected]b172aee2012-04-10 17:05:26785SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21786 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
787 GetRenderManager()->pending_render_view_host() :
788 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58789 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38790}
791
[email protected]b172aee2012-04-10 17:05:26792bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31793 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49794}
795
[email protected]b172aee2012-04-10 17:05:26796bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31797 return waiting_for_response_;
798}
799
[email protected]b172aee2012-04-10 17:05:26800const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31801 return load_state_;
802}
803
[email protected]fcf75d42013-12-03 20:11:26804const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31805 return load_state_host_;
806}
807
[email protected]b172aee2012-04-10 17:05:26808uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31809 return upload_size_;
810}
811
[email protected]b172aee2012-04-10 17:05:26812uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31813 return upload_position_;
814}
815
[email protected]1ae93fb2013-06-14 03:38:56816std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56817 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39818 frame_tree_.ForEach(base::Bind(&CollectSites,
819 base::Unretained(GetBrowserContext()),
820 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56821 return sites;
822}
823
[email protected]b172aee2012-04-10 17:05:26824const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31825 return encoding_;
826}
827
[email protected]b172aee2012-04-10 17:05:26828bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31829 return displayed_insecure_content_;
830}
831
[email protected]54597982013-02-06 01:59:55832void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25833 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55834 ++capturer_count_;
835 DVLOG(1) << "There are now " << capturer_count_
836 << " capturing(s) of WebContentsImpl@" << this;
837}
838
839void WebContentsImpl::DecrementCapturerCount() {
840 --capturer_count_;
841 DVLOG(1) << "There are now " << capturer_count_
842 << " capturing(s) of WebContentsImpl@" << this;
843 DCHECK_LE(0, capturer_count_);
844
[email protected]5a652232013-02-12 06:15:25845 if (is_being_destroyed_)
846 return;
847
[email protected]1ac10dca2013-08-20 20:47:04848 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55849 DVLOG(1) << "Executing delayed WasHidden().";
850 WasHidden();
851 }
[email protected]be1f56ab2011-12-22 06:55:31852}
853
[email protected]f2bd40812013-07-20 04:30:44854int WebContentsImpl::GetCapturerCount() const {
855 return capturer_count_;
856}
857
[email protected]b172aee2012-04-10 17:05:26858bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31859 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
860 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
861 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49862}
863
[email protected]b172aee2012-04-10 17:05:26864void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
865 int error_code) {
[email protected]443b80e2010-12-14 00:42:23866 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34867 return;
868
[email protected]443b80e2010-12-14 00:42:23869 crashed_status_ = status;
870 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21871 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34872}
873
[email protected]b172aee2012-04-10 17:05:26874base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31875 return crashed_status_;
876}
877
[email protected]b172aee2012-04-10 17:05:26878bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31879 return is_being_destroyed_;
880}
881
[email protected]b172aee2012-04-10 17:05:26882void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34883 if (delegate_)
884 delegate_->NavigationStateChanged(this, changed_flags);
885}
886
[email protected]3e324142012-06-25 18:26:33887base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
888 return last_selected_time_;
889}
890
[email protected]9e2e4632012-07-27 16:38:41891void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54892 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04893 RenderWidgetHostViewPort* rwhv =
894 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16895 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29896 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43897#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16898 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43899#endif
900 }
[email protected]96d185d2009-04-24 03:28:54901
[email protected]5ac20162010-11-24 23:33:11902 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38903
[email protected]b9769d82012-02-10 00:23:59904 // The resize rect might have changed while this was inactive -- send the new
905 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58906 RenderViewHostImpl* rvh =
907 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59908 if (rvh) {
909 rvh->ResizeRectChanged(GetRootWindowResizerRect());
910 }
[email protected]96d185d2009-04-24 03:28:54911
[email protected]c0d9d5672013-10-09 07:38:03912 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
913
[email protected]54597982013-02-06 01:59:55914 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31915}
916
[email protected]b172aee2012-04-10 17:05:26917void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55918 // If there are entities capturing screenshots or video (e.g., mirroring),
919 // don't activate the "disable rendering" optimization.
920 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52921 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55922 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26923 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52924 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33925 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52926 // calls us).
[email protected]c30585c2012-02-16 15:02:04927 RenderWidgetHostViewPort* rwhv =
928 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16929 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29930 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54931 }
932
[email protected]c0d9d5672013-10-09 07:38:03933 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
934
[email protected]54597982013-02-06 01:59:55935 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37936}
937
[email protected]b172aee2012-04-10 17:05:26938bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31939 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27940 return WillNotifyDisconnection() &&
941 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58942 !static_cast<RenderViewHostImpl*>(
943 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31944}
945
[email protected]b172aee2012-04-10 17:05:26946void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:21947 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:40948 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:27949}
950
[email protected]b172aee2012-04-10 17:05:26951WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44952 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:45953 // We pass our own opener so that the cloned page can access it if it was
954 // before.
[email protected]54944cde2012-12-09 09:24:59955 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:45956 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:59957 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:19958 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:22959 FOR_EACH_OBSERVER(WebContentsObserver,
960 observers_,
961 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:27962 return tc;
963}
964
[email protected]14392a52012-05-02 20:28:44965void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:21966 const NotificationSource& source,
967 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:44968 switch (type) {
[email protected]8ff00d72012-10-23 19:12:21969 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
970 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:50971 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
972 i != pending_widget_views_.end(); ++i) {
973 if (host->GetView() == i->second) {
974 pending_widget_views_.erase(i);
975 break;
976 }
977 }
978 break;
979 }
[email protected]14392a52012-05-02 20:28:44980 default:
981 NOTREACHED();
982 }
983}
984
[email protected]ec6c05f2013-10-23 18:41:57985WebContents* WebContentsImpl::GetWebContents() {
986 return this;
987}
988
[email protected]54944cde2012-12-09 09:24:59989void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:21990 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:36991 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:21992 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:43993 should_normally_be_visible_ = !params.initially_hidden;
994
[email protected]fa944cb82013-11-15 17:51:21995 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:04996 params.browser_context, params.site_instance, params.routing_id,
997 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:19998
[email protected]8ff00d72012-10-23 19:12:21999 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191000 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271001 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191002 CHECK(render_view_host_delegate_view_);
1003 } else {
[email protected]f8497342013-02-05 22:15:021004 WebContentsViewDelegate* delegate =
1005 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1006
[email protected]59383c782013-04-17 16:43:271007 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381008 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1009 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021010
[email protected]b5a40842012-11-28 15:26:111011 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381012 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431013 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111014 render_view_host_delegate_view_ = rv;
1015 view_.reset(rv);
1016 } else {
[email protected]f8497342013-02-05 22:15:021017 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111018 view_.reset(CreateWebContentsView(
1019 this, delegate, &render_view_host_delegate_view_));
1020 }
[email protected]d1198fd2012-08-13 22:50:191021 CHECK(render_view_host_delegate_view_);
1022 }
1023 CHECK(view_.get());
1024
[email protected]ed245db2012-12-18 08:00:451025 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591026 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191027
1028 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101029 if (opener_)
1030 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191031
1032 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211033 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1034 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441035#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191036 java_bridge_dispatcher_host_manager_.reset(
1037 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101038 date_time_chooser_.reset(new DateTimeChooserAndroid());
1039#endif
[email protected]d1198fd2012-08-13 22:50:191040}
1041
[email protected]7fff43e2013-05-21 20:21:101042void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1043 RemoveDestructionObserver(web_contents);
1044
[email protected]14392a52012-05-02 20:28:441045 // Clear the opener if it has been closed.
1046 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441047 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511048 return;
[email protected]14392a52012-05-02 20:28:441049 }
[email protected]ceee8cd2013-03-08 04:59:511050 // Clear a pending contents that has been closed before being shown.
1051 for (PendingContents::iterator iter = pending_contents_.begin();
1052 iter != pending_contents_.end();
1053 ++iter) {
1054 if (iter->second != web_contents)
1055 continue;
1056 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511057 return;
1058 }
1059 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441060}
1061
[email protected]7fff43e2013-05-21 20:21:101062void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1063 if (!ContainsKey(destruction_observers_, web_contents)) {
1064 destruction_observers_[web_contents] =
1065 new DestructionObserver(this, web_contents);
1066 }
1067}
1068
1069void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1070 DestructionObservers::iterator iter =
1071 destruction_observers_.find(web_contents);
1072 if (iter != destruction_observers_.end()) {
1073 delete destruction_observers_[web_contents];
1074 destruction_observers_.erase(iter);
1075 }
1076}
1077
[email protected]b172aee2012-04-10 17:05:261078void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311079 observers_.AddObserver(observer);
1080}
1081
[email protected]b172aee2012-04-10 17:05:261082void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311083 observers_.RemoveObserver(observer);
1084}
1085
[email protected]b172aee2012-04-10 17:05:261086void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341087 if (delegate_)
1088 delegate_->ActivateContents(this);
1089}
1090
[email protected]b172aee2012-04-10 17:05:261091void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121092 if (delegate_)
1093 delegate_->DeactivateContents(this);
1094}
1095
[email protected]b172aee2012-04-10 17:05:261096void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481097 if (delegate_)
1098 delegate_->LostCapture();
1099}
1100
[email protected]b24b68a2012-09-24 21:57:261101void WebContentsImpl::RenderWidgetDeleted(
1102 RenderWidgetHostImpl* render_widget_host) {
1103 if (is_being_destroyed_) {
1104 // |created_widgets_| might have been destroyed.
1105 return;
1106 }
1107
1108 std::set<RenderWidgetHostImpl*>::iterator iter =
1109 created_widgets_.find(render_widget_host);
1110 if (iter != created_widgets_.end())
1111 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541112
1113 if (render_widget_host &&
1114 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491115 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1116 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541117 FOR_EACH_OBSERVER(WebContentsObserver,
1118 observers_,
1119 DidDestroyFullscreenWidget(
1120 fullscreen_widget_routing_id_));
1121 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1122 }
[email protected]b24b68a2012-09-24 21:57:261123}
1124
[email protected]b172aee2012-04-10 17:05:261125bool WebContentsImpl::PreHandleKeyboardEvent(
1126 const NativeWebKeyboardEvent& event,
1127 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481128 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131129 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481130}
1131
[email protected]b172aee2012-04-10 17:05:261132void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061133 if (browser_plugin_embedder_ &&
1134 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1135 return;
1136 }
1137
[email protected]63954792011-07-11 04:17:481138 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131139 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481140}
1141
[email protected]fb3f066e2013-02-12 19:12:521142bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461143 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191144#if !defined(OS_MACOSX)
1145 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1146 // isn't done for two reasons:
1147 // -the OS already has a gesture to do this through pinch-zoom
1148 // -if a user starts an inertial scroll, let's go, and presses control
1149 // (i.e. control+tab) then the OS's buffered scroll events will come in
1150 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521151 if (delegate_ &&
1152 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461153 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521154 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1155 return true;
1156 }
[email protected]bccc4472013-04-18 16:37:191157#endif
[email protected]fb3f066e2013-02-12 19:12:521158
1159 return false;
1160}
1161
[email protected]04bce562014-01-30 05:34:541162bool WebContentsImpl::PreHandleGestureEvent(
1163 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031164 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541165}
1166
[email protected]2ceee8f2014-01-14 18:02:081167#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411168gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1169 return accessible_parent_;
1170}
1171#endif
1172
[email protected]b172aee2012-04-10 17:05:261173void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431174 if (delegate_)
1175 delegate_->HandleMouseDown();
1176}
1177
[email protected]b172aee2012-04-10 17:05:261178void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481179 if (delegate_)
1180 delegate_->HandleMouseUp();
1181}
1182
[email protected]590a634e2012-07-19 16:38:231183void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481184 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231185 delegate_->HandlePointerActivate();
1186}
1187
1188void WebContentsImpl::HandleGestureBegin() {
1189 if (delegate_)
1190 delegate_->HandleGestureBegin();
1191}
1192
1193void WebContentsImpl::HandleGestureEnd() {
1194 if (delegate_)
1195 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481196}
1197
[email protected]b172aee2012-04-10 17:05:261198void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491199 // This method is being called to enter or leave renderer-initiated fullscreen
1200 // mode. Either way, make sure any existing fullscreen widget is shut down
1201 // first.
1202 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1203 if (widget_view)
1204 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1205
[email protected]8a5e0ca2011-08-25 06:30:471206 if (delegate_)
1207 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1208}
1209
[email protected]b172aee2012-04-10 17:05:261210bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381211 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121212}
1213
[email protected]a9c81f02012-06-01 00:15:441214void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1215 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371216 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441217 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371218 } else {
1219 GotResponseToLockMouseRequest(false);
1220 }
1221}
1222
[email protected]b172aee2012-04-10 17:05:261223void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371224 if (delegate_)
1225 delegate_->LostMouseLock();
1226}
1227
[email protected]bafe6cd2012-05-23 23:09:501228void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201229 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501230 int route_id,
[email protected]227692c52013-05-31 22:43:041231 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131232 const ViewHostMsg_CreateWindow_Params& params,
1233 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501234 // We usually create the new window in the same BrowsingInstance (group of
1235 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551236 // if the opener is being suppressed (in a non-guest), we create a new
1237 // SiteInstance in its own BrowsingInstance.
1238 bool is_guest = GetRenderProcessHost()->IsGuest();
1239
[email protected]04cbd3d2013-12-04 04:58:201240 // If the opener is to be suppressed, the new window can be in any process.
1241 // Since routing ids are process specific, we must not have one passed in
1242 // as argument here.
1243 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1244
[email protected]bafe6cd2012-05-23 23:09:501245 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551246 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571247 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501248 GetSiteInstance();
1249
[email protected]04cbd3d2013-12-04 04:58:201250 // A message to create a new window can only come from the active process for
1251 // this WebContentsImpl instance. If any other process sends the request,
1252 // it is invalid and the process must be terminated.
1253 if (GetRenderProcessHost()->GetID() != render_process_id) {
1254 base::ProcessHandle process_handle =
1255 RenderProcessHost::FromID(render_process_id)->GetHandle();
1256 if (process_handle != base::kNullProcessHandle) {
1257 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391258 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201259 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1260 }
1261 return;
1262 }
1263
[email protected]d1198fd2012-08-13 22:50:191264 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341265 //
1266 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301267 const std::string& partition_id =
1268 GetContentClient()->browser()->
1269 GetStoragePartitionIdForSite(GetBrowserContext(),
1270 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461271 StoragePartition* partition = BrowserContext::GetStoragePartition(
1272 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411273 DOMStorageContextWrapper* dom_storage_context =
1274 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191275 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1276 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1277 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371278
1279 if (delegate_ &&
1280 !delegate_->ShouldCreateWebContents(this,
1281 route_id,
1282 params.window_container_type,
1283 params.frame_name,
1284 params.target_url,
1285 partition_id,
1286 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011287 if (route_id != MSG_ROUTING_NONE &&
1288 !RenderViewHost::FromID(render_process_id, route_id)) {
1289 // If the embedder didn't create a WebContents for this route, we need to
1290 // delete the RenderView that had already been created.
1291 Send(new ViewMsg_Close(route_id));
1292 }
[email protected]dd6730412013-08-14 15:03:371293 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1294 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1295 main_frame_route_id);
1296 return;
1297 }
1298
1299 // Create the new web contents. This will automatically create the new
1300 // WebContentsView. In the future, we may want to create the view separately.
1301 WebContentsImpl* new_contents =
1302 new WebContentsImpl(GetBrowserContext(),
1303 params.opener_suppressed ? NULL : this);
1304
[email protected]d1198fd2012-08-13 22:50:191305 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301306 partition_id,
[email protected]d1198fd2012-08-13 22:50:191307 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461308 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591309 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041310 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551311 if (!is_guest) {
1312 create_params.context = view_->GetNativeView();
1313 create_params.initial_size = view_->GetContainerSize();
1314 } else {
1315 // This makes |new_contents| act as a guest.
1316 // For more info, see comment above class BrowserPluginGuest.
1317 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1318 WebContentsImpl* new_contents_impl =
1319 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461320 BrowserPluginGuest::CreateWithOpener(instance_id,
1321 new_contents_impl->opener() != NULL,
1322 new_contents_impl,
1323 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551324 }
[email protected]1ac10dca2013-08-20 20:47:041325 if (params.disposition == NEW_BACKGROUND_TAB)
1326 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591327 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191328
[email protected]c4538072013-03-18 02:17:551329 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341330 // will be shown immediately).
1331 if (!params.opener_suppressed) {
1332 if (!is_guest) {
1333 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501334
[email protected]d70bea92013-04-05 04:23:341335 // TODO(brettw): It seems bogus that we have to call this function on the
1336 // newly created object and give it one of its own member variables.
1337 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1338 }
[email protected]bafe6cd2012-05-23 23:09:501339 // Save the created window associated with the route so we can show it
1340 // later.
1341 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1342 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101343 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501344 }
1345
1346 if (delegate_) {
1347 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131348 this, params.opener_frame_id, params.frame_name,
1349 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501350 }
1351
1352 if (params.opener_suppressed) {
1353 // When the opener is suppressed, the original renderer cannot access the
1354 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001355 bool was_blocked = false;
1356 if (delegate_) {
1357 gfx::Rect initial_pos;
1358 delegate_->AddNewContents(
1359 this, new_contents, params.disposition, initial_pos,
1360 params.user_gesture, &was_blocked);
1361 }
1362 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211363 OpenURLParams open_params(params.target_url,
1364 Referrer(),
1365 CURRENT_TAB,
1366 PAGE_TRANSITION_LINK,
1367 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301368 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001369 new_contents->OpenURL(open_params);
1370 }
[email protected]bafe6cd2012-05-23 23:09:501371 }
1372}
1373
[email protected]a8504022013-12-04 20:23:511374void WebContentsImpl::CreateNewWidget(int render_process_id,
1375 int route_id,
[email protected]180ef242013-11-07 06:50:461376 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511377 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501378}
1379
[email protected]a8504022013-12-04 20:23:511380void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1381 int route_id) {
1382 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501383}
1384
[email protected]a8504022013-12-04 20:23:511385void WebContentsImpl::CreateNewWidget(int render_process_id,
1386 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501387 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461388 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211389 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511390 // A message to create a new widget can only come from the active process for
1391 // this WebContentsImpl instance. If any other process sends the request,
1392 // it is invalid and the process must be terminated.
1393 if (process->GetID() != render_process_id) {
1394 base::ProcessHandle process_handle =
1395 RenderProcessHost::FromID(render_process_id)->GetHandle();
1396 if (process_handle != base::kNullProcessHandle) {
1397 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391398 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511399 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1400 }
1401 return;
1402 }
1403
[email protected]bafe6cd2012-05-23 23:09:501404 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041405 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261406 created_widgets_.insert(widget_host);
1407
[email protected]83918ec2013-01-10 15:37:191408 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1409 view_->CreateViewForPopupWidget(widget_host));
1410 if (!widget_view)
1411 return;
[email protected]bafe6cd2012-05-23 23:09:501412 if (!is_fullscreen) {
1413 // Popups should not get activated.
1414 widget_view->SetPopupType(popup_type);
1415 }
1416 // Save the created widget associated with the route so we can show it later.
1417 pending_widget_views_[route_id] = widget_view;
1418
1419#if defined(OS_MACOSX)
1420 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1421 // to allow it to survive the trip without being hosted.
1422 base::mac::NSObjectRetain(widget_view->GetNativeView());
1423#endif
1424}
1425
1426void WebContentsImpl::ShowCreatedWindow(int route_id,
1427 WindowOpenDisposition disposition,
1428 const gfx::Rect& initial_pos,
1429 bool user_gesture) {
1430 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001431 if (contents) {
1432 WebContentsDelegate* delegate = GetDelegate();
1433 if (delegate) {
1434 delegate->AddNewContents(
1435 this, contents, disposition, initial_pos, user_gesture, NULL);
1436 }
1437 }
[email protected]bafe6cd2012-05-23 23:09:501438}
1439
1440void WebContentsImpl::ShowCreatedWidget(int route_id,
1441 const gfx::Rect& initial_pos) {
1442 ShowCreatedWidget(route_id, false, initial_pos);
1443}
1444
1445void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1446 ShowCreatedWidget(route_id, true, gfx::Rect());
1447}
1448
1449void WebContentsImpl::ShowCreatedWidget(int route_id,
1450 bool is_fullscreen,
1451 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501452 RenderWidgetHostViewPort* widget_host_view =
1453 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1454 if (!widget_host_view)
1455 return;
[email protected]4aebbca2013-09-17 22:26:491456 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311457 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1458 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491459 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1460 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1461 delegate_->ToggleFullscreenModeForTab(this, true);
1462 } else {
1463 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491464 }
[email protected]4aebbca2013-09-17 22:26:491465 FOR_EACH_OBSERVER(WebContentsObserver,
1466 observers_,
1467 DidShowFullscreenWidget(route_id));
1468 if (!widget_host_view->HasFocus())
1469 widget_host_view->Focus();
1470 } else {
[email protected]f8497342013-02-05 22:15:021471 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491472 }
[email protected]89054502012-06-03 10:29:241473
1474 RenderWidgetHostImpl* render_widget_host_impl =
1475 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1476 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311477 // Only allow privileged mouse lock for fullscreen render widget, which is
1478 // used to implement Pepper Flash fullscreen.
1479 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501480
1481#if defined(OS_MACOSX)
1482 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1483 // properly embedded (or purposefully ignored) we can release the retain we
1484 // took in CreateNewWidget().
1485 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1486#endif
1487}
1488
1489WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1490 PendingContents::iterator iter = pending_contents_.find(route_id);
1491
1492 // Certain systems can block the creation of new windows. If we didn't succeed
1493 // in creating one, just return NULL.
1494 if (iter == pending_contents_.end()) {
1495 return NULL;
1496 }
1497
1498 WebContentsImpl* new_contents = iter->second;
1499 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101500 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501501
[email protected]d70bea92013-04-05 04:23:341502 // Don't initialize the guest WebContents immediately.
1503 if (new_contents->GetRenderProcessHost()->IsGuest())
1504 return new_contents;
1505
[email protected]bafe6cd2012-05-23 23:09:501506 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1507 !new_contents->GetRenderViewHost()->GetView())
1508 return NULL;
1509
1510 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1511 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1512 return new_contents;
1513}
1514
1515RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1516 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1517 if (iter == pending_widget_views_.end()) {
1518 DCHECK(false);
1519 return NULL;
1520 }
1521
1522 RenderWidgetHostView* widget_host_view = iter->second;
1523 pending_widget_views_.erase(route_id);
1524
1525 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1526 if (!widget_host->GetProcess()->HasConnection()) {
1527 // The view has gone away or the renderer crashed. Nothing to do.
1528 return NULL;
1529 }
1530
1531 return widget_host_view;
1532}
1533
[email protected]f13b4202012-06-12 23:53:231534void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091535 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211536 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231537 if (delegate_)
1538 delegate_->RequestMediaAccessPermission(this, request, callback);
1539 else
[email protected]b5f76742013-04-29 15:05:591540 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231541}
1542
[email protected]cc9200432013-07-23 23:02:401543SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1544 SiteInstance* instance) {
1545 return controller_.GetSessionStorageNamespace(instance);
1546}
1547
[email protected]9b159a52013-10-03 17:24:551548FrameTree* WebContentsImpl::GetFrameTree() {
1549 return &frame_tree_;
1550}
1551
[email protected]edc3af82013-12-12 21:24:071552void WebContentsImpl::OnShowValidationMessage(
1553 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291554 const base::string16& main_text,
1555 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071556 if (delegate_)
1557 delegate_->ShowValidationMessage(
1558 this, anchor_in_root_view, main_text, sub_text);
1559}
1560
1561void WebContentsImpl::OnHideValidationMessage() {
1562 if (delegate_)
1563 delegate_->HideValidationMessage(this);
1564}
1565
1566void WebContentsImpl::OnMoveValidationMessage(
1567 const gfx::Rect& anchor_in_root_view) {
1568 if (delegate_)
1569 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1570}
1571
[email protected]32deec62013-05-15 23:55:041572void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1573 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441574 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041575}
1576
[email protected]b172aee2012-04-10 17:05:261577void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231578 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331579 if (delegate_)
1580 delegate_->UpdatePreferredSize(this, pref_size);
1581}
1582
[email protected]b172aee2012-04-10 17:05:261583void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341584 if (delegate_)
1585 delegate_->ResizeDueToAutoResize(this, new_size);
1586}
1587
[email protected]b172aee2012-04-10 17:05:261588WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201589 if (!delegate_)
1590 return NULL;
[email protected]00c37fc2011-08-02 00:22:501591
[email protected]e5d549d2011-12-28 01:29:201592 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201593 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341594}
1595
[email protected]6b618e62012-08-16 12:59:181596bool WebContentsImpl::Send(IPC::Message* message) {
1597 if (!GetRenderViewHost()) {
1598 delete message;
1599 return false;
1600 }
1601
1602 return GetRenderViewHost()->Send(message);
1603}
1604
[email protected]b172aee2012-04-10 17:05:261605bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501606 NavigationController::ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:201607 return frame_tree_.root()->navigator()->NavigateToPendingEntry(
1608 frame_tree_.GetMainFrame(), reload_type);
[email protected]876bc832010-09-07 16:29:541609}
[email protected]96d185d2009-04-24 03:28:541610
[email protected]a86c0e962013-12-17 17:10:391611void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1612 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441613 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391614 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441615}
1616
[email protected]20ca0382013-02-28 19:50:071617void WebContentsImpl::AttachInterstitialPage(
1618 InterstitialPageImpl* interstitial_page) {
1619 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211620 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291621
1622 // Cancel any visible dialogs so that they don't interfere with the
1623 // interstitial.
1624 if (dialog_manager_)
1625 dialog_manager_->CancelActiveAndPendingDialogs(this);
1626
[email protected]20ca0382013-02-28 19:50:071627 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1628 DidAttachInterstitialPage());
1629}
1630
1631void WebContentsImpl::DetachInterstitialPage() {
1632 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211633 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071634 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1635 DidDetachInterstitialPage());
1636}
1637
[email protected]b172aee2012-04-10 17:05:261638void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331639 const SiteInstance* site_instance,
1640 int history_length,
1641 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411642 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1643 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211644 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191645 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141646 return;
[email protected]9e1ad4b2011-08-14 16:49:191647 }
[email protected]9f76c1e2012-03-05 15:15:581648 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191649 if (!rvh) {
1650 NOTREACHED();
1651 return;
1652 }
[email protected]9f76c1e2012-03-05 15:15:581653 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191654 NOTREACHED();
1655 return;
1656 }
[email protected]6b618e62012-08-16 12:59:181657 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1658 history_length,
1659 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141660}
1661
[email protected]b172aee2012-04-10 17:05:261662void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271663 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211664 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541665 return;
1666 }
[email protected]9f76c1e2012-03-05 15:15:581667 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541668}
1669
[email protected]b172aee2012-04-10 17:05:261670bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211671 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541672}
1673
[email protected]b172aee2012-04-10 17:05:261674InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211675 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221676}
1677
[email protected]b172aee2012-04-10 17:05:261678bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161679 // WebKit creates Document object when MIME type is application/xhtml+xml,
1680 // so we also support this MIME type.
1681 return contents_mime_type_ == "text/html" ||
1682 contents_mime_type_ == "text/xml" ||
1683 contents_mime_type_ == "application/xhtml+xml" ||
1684 contents_mime_type_ == "text/plain" ||
1685 contents_mime_type_ == "text/css" ||
1686 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591690 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161691 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551692 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011693 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141694 return;
[email protected]c7dd2f62011-07-18 15:57:591695 }
1696
1697 Stop();
1698
1699 // Create the save package and possibly prompt the user for the name to save
1700 // the page as. The user prompt is an asynchronous operation that runs on
1701 // another thread.
1702 save_package_ = new SavePackage(this);
1703 save_package_->GetSaveInfo();
1704}
1705
1706// Used in automated testing to bypass prompting the user for file names.
1707// Instead, the names and paths are hard coded rather than running them through
1708// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341709bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1710 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211711 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591712 // Stop the page from navigating.
1713 Stop();
1714
1715 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211716 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591717}
1718
[email protected]3c71576ce2013-07-23 02:00:011719void WebContentsImpl::SaveFrame(const GURL& url,
1720 const Referrer& referrer) {
1721 if (!GetURL().is_valid())
1722 return;
1723 bool is_main_frame = (url == GetURL());
1724
1725 DownloadManager* dlm =
1726 BrowserContext::GetDownloadManager(GetBrowserContext());
1727 if (!dlm)
1728 return;
1729 int64 post_id = -1;
1730 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271731 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011732 if (entry)
1733 post_id = entry->GetPostID();
1734 }
1735 scoped_ptr<DownloadUrlParameters> params(
1736 DownloadUrlParameters::FromWebContents(this, url));
1737 params->set_referrer(referrer);
1738 params->set_post_id(post_id);
1739 params->set_prefer_cache(true);
1740 if (post_id >= 0)
1741 params->set_method("POST");
1742 params->set_prompt(true);
1743 dlm->DownloadUrl(params.Pass());
1744}
1745
[email protected]b172aee2012-04-10 17:05:261746void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341747 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481748 const base::Callback<void(int64)>& callback) {
1749 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121750}
1751
[email protected]6286a372013-10-09 04:03:271752// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261753bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271754 NavigationEntryImpl* visible_entry =
1755 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1756 return (visible_entry != NULL &&
1757 visible_entry->site_instance() == GetSiteInstance() &&
1758 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321759}
1760
[email protected]b172aee2012-04-10 17:05:261761const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271762 return contents_mime_type_;
1763}
1764
[email protected]b172aee2012-04-10 17:05:261765bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271766 return notify_disconnection_;
1767}
1768
[email protected]b172aee2012-04-10 17:05:261769void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311770 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181771 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161772}
1773
[email protected]b172aee2012-04-10 17:05:261774void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311775 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181776 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161777}
1778
[email protected]8ff00d72012-10-23 19:12:211779RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271780 return &renderer_preferences_;
1781}
1782
[email protected]e35ccd52012-05-23 16:22:471783void WebContentsImpl::Close() {
1784 Close(GetRenderViewHost());
1785}
1786
[email protected]cf200a562013-05-03 16:24:291787void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461788 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291789 if (browser_plugin_embedder_.get())
1790 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1791 screen_x, screen_y, operation);
1792 if (GetRenderViewHost())
1793 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1794 screen_x, screen_y, operation);
1795}
1796
1797void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1798 int screen_x, int screen_y) {
1799 if (browser_plugin_embedder_.get())
1800 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1801 screen_x, screen_y);
1802 if (GetRenderViewHost())
1803 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1804 screen_x, screen_y);
1805}
1806
[email protected]d60f3702013-12-26 16:30:241807void WebContentsImpl::DidGetResourceResponseStart(
1808 const ResourceRequestDetails& details) {
1809 controller_.ssl_manager()->DidStartResourceResponse(details);
1810
1811 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1812 DidGetResourceResponseStart(details));
1813
1814 // TODO(avi): Remove. http://crbug.com/170921
1815 NotificationService::current()->Notify(
1816 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1817 Source<WebContents>(this),
1818 Details<const ResourceRequestDetails>(&details));
1819}
1820
1821void WebContentsImpl::DidGetRedirectForResourceRequest(
1822 RenderViewHost* render_view_host,
1823 const ResourceRedirectDetails& details) {
1824 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1825
1826 FOR_EACH_OBSERVER(
1827 WebContentsObserver,
1828 observers_,
1829 DidGetRedirectForResourceRequest(render_view_host, details));
1830
1831 // TODO(avi): Remove. http://crbug.com/170921
1832 NotificationService::current()->Notify(
1833 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1834 Source<WebContents>(this),
1835 Details<const ResourceRedirectDetails>(&details));
1836}
1837
[email protected]b172aee2012-04-10 17:05:261838void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521839 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581840 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511841 if (delegate_)
1842 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291843 if (browser_plugin_embedder_.get())
1844 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341845}
1846
[email protected]e35ccd52012-05-23 16:22:471847void WebContentsImpl::UserGestureDone() {
1848 OnUserGesture();
1849}
1850
[email protected]b172aee2012-04-10 17:05:261851void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271852 closed_by_user_gesture_ = value;
1853}
1854
[email protected]b172aee2012-04-10 17:05:261855bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271856 return closed_by_user_gesture_;
1857}
1858
[email protected]b172aee2012-04-10 17:05:261859double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051860 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561861 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251862 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171863 return 0;
[email protected]b75b8292010-10-01 07:28:251864
1865 double zoom_level;
1866 if (temporary_zoom_settings_) {
1867 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581868 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251869 } else {
[email protected]2ae88d12011-10-14 09:11:191870 GURL url;
[email protected]6286a372013-10-09 04:03:271871 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191872 // Since zoom map is updated using rewritten URL, use rewritten URL
1873 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271874 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021875 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1876 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251877 }
[email protected]d0b8d092010-10-25 04:05:171878 return zoom_level;
1879}
[email protected]b75b8292010-10-01 07:28:251880
[email protected]b172aee2012-04-10 17:05:261881int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591882 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171883 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011884 // Calculate the zoom percent from the factor. Round up to the nearest whole
1885 // number.
[email protected]b75b8292010-10-01 07:28:251886 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491887 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251888 *enable_decrement = percent > minimum_zoom_percent_;
1889 *enable_increment = percent < maximum_zoom_percent_;
1890 return percent;
1891}
1892
[email protected]b172aee2012-04-10 17:05:261893void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501894 if (!delegate_)
1895 return;
1896
[email protected]6286a372013-10-09 04:03:271897 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1898 if (!entry)
[email protected]1788e772010-12-15 16:40:501899 return;
1900
[email protected]6286a372013-10-09 04:03:271901 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121902}
1903
[email protected]b172aee2012-04-10 17:05:261904void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041905 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271906 if (!delegate_)
1907 return;
1908
[email protected]691aa2f2013-05-28 22:52:041909 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271910}
1911
[email protected]b172aee2012-04-10 17:05:261912int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271913 return minimum_zoom_percent_;
1914}
1915
[email protected]b172aee2012-04-10 17:05:261916int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271917 return maximum_zoom_percent_;
1918}
1919
[email protected]b172aee2012-04-10 17:05:261920gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231921 return preferred_size_;
1922}
1923
[email protected]b172aee2012-04-10 17:05:261924bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271925 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581926 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271927}
1928
[email protected]b172aee2012-04-10 17:05:261929bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441930 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501931}
1932
[email protected]cb805452013-05-22 15:16:211933void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181934 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211935 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201936}
1937
[email protected]cb805452013-05-22 15:16:211938void WebContentsImpl::DidEndColorChooser() {
1939 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1940 color_chooser_identifier_));
1941 color_chooser_.reset();
1942 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201943}
1944
[email protected]41225fe2013-03-29 05:32:021945int WebContentsImpl::DownloadImage(const GURL& url,
1946 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301947 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021948 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391949 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301950 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021951 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391952 return id;
1953}
1954
[email protected]5dcaf8e2013-12-28 01:31:421955bool WebContentsImpl::IsSubframe() const {
1956 return is_subframe_;
1957}
1958
[email protected]9649d492014-01-10 07:15:521959void WebContentsImpl::SetZoomLevel(double level) {
1960 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
1961 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
1962 if (embedder)
1963 embedder->SetZoomLevel(level);
1964}
1965
[email protected]36ec24f2014-01-09 00:32:081966void WebContentsImpl::Find(int request_id,
1967 const base::string16& search_text,
1968 const blink::WebFindOptions& options) {
1969 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
1970}
1971
1972void WebContentsImpl::StopFinding(StopFindAction action) {
1973 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
1974}
1975
[email protected]b172aee2012-04-10 17:05:261976bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:271977 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:201978 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:331979 return true;
1980 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:271981}
1982
[email protected]b172aee2012-04-10 17:05:261983void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271984 if (delegate_)
1985 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211986}
1987
[email protected]52913802013-12-10 05:52:181988void WebContentsImpl::DidStartProvisionalLoad(
1989 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:571990 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131991 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571992 bool is_main_frame,
[email protected]52913802013-12-10 05:52:181993 const GURL& validated_url,
1994 bool is_error_page,
1995 bool is_iframe_srcdoc) {
1996 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:571997 DidChangeLoadProgress(0);
1998
[email protected]0d60f0192011-04-14 12:40:101999 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252000 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132001 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2002 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182003 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542004
2005 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182006 FOR_EACH_OBSERVER(
2007 WebContentsObserver,
2008 observers_,
2009 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582010 render_frame_host));
[email protected]400992b2012-06-14 00:03:542011 }
2012}
2013
[email protected]3109fbb72014-01-06 23:57:152014void WebContentsImpl::DidFailProvisionalLoadWithError(
2015 RenderFrameHostImpl* render_frame_host,
2016 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2017 GURL validated_url(params.url);
2018 FOR_EACH_OBSERVER(
2019 WebContentsObserver,
2020 observers_,
2021 DidFailProvisionalLoad(params.frame_id,
2022 params.frame_unique_name,
2023 params.is_main_frame,
2024 validated_url,
2025 params.error_code,
2026 params.error_description,
2027 render_frame_host->render_view_host()));
2028}
2029
[email protected]52913802013-12-10 05:52:182030void WebContentsImpl::NotifyChangedNavigationState(
2031 InvalidateTypes changed_flags) {
2032 NotifyNavigationStateChanged(changed_flags);
2033}
2034
[email protected]3691e5cf2014-01-22 10:16:202035void WebContentsImpl::AboutToNavigateRenderFrame(
2036 RenderFrameHostImpl* render_frame_host) {
2037 // Notify observers that we will navigate in this RenderView.
2038 FOR_EACH_OBSERVER(
2039 WebContentsObserver,
2040 observers_,
2041 AboutToNavigateRenderView(render_frame_host->render_view_host()));
2042}
2043
2044void WebContentsImpl::DidStartNavigationToPendingEntry(
2045 RenderFrameHostImpl* render_frame_host,
2046 const GURL& url,
2047 NavigationController::ReloadType reload_type) {
2048 // Notify observers about navigation.
2049 FOR_EACH_OBSERVER(
2050 WebContentsObserver,
2051 observers_,
2052 DidStartNavigationToPendingEntry(url, reload_type));
2053}
2054
[email protected]400992b2012-06-14 00:03:542055void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582056 RenderFrameHostImpl* render_frame_host,
2057 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542058 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582059 FOR_EACH_OBSERVER(
2060 WebContentsObserver,
2061 observers_,
2062 ProvisionalChangeToMainFrameUrl(validated_target_url,
2063 render_frame_host));
[email protected]724159a2010-12-30 01:11:182064}
2065
[email protected]b172aee2012-04-10 17:05:262066void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182067 const GURL& url,
[email protected]70435962011-08-02 20:13:282068 const std::string& security_info,
2069 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182070 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282071 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192072 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182073 cache.Increment();
2074
2075 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082076 int cert_id = 0;
2077 net::CertStatus cert_status = 0;
2078 int security_bits = -1;
2079 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122080 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212081 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122082 &security_bits, &connection_status,
2083 &signed_certificate_timestamp_ids);
2084 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212085 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002086 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2087 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182088
[email protected]b0f724c2013-09-05 04:21:132089 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2090
2091 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2092 DidLoadResourceFromMemoryCache(details));
2093
[email protected]8bfc8272013-09-09 20:10:532094 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2095 scoped_refptr<net::URLRequestContextGetter> request_context(
2096 resource_type == ResourceType::MEDIA ?
2097 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2098 GetRenderProcessHost()->GetID()) :
2099 GetBrowserContext()->GetRequestContextForRenderProcess(
2100 GetRenderProcessHost()->GetID()));
2101 BrowserThread::PostTask(
2102 BrowserThread::IO,
2103 FROM_HERE,
2104 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2105 }
[email protected]724159a2010-12-30 01:11:182106}
2107
[email protected]b172aee2012-04-10 17:05:262108void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392109 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182110 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192111 SSLManager::NotifySSLInternalStateChanged(
2112 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182113}
2114
[email protected]b172aee2012-04-10 17:05:262115void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022116 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582117 LOG(WARNING) << security_origin << " ran insecure content from "
2118 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392119 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412120 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392121 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182122 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412123 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192124 SSLManager::NotifySSLInternalStateChanged(
2125 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182126}
2127
[email protected]b172aee2012-04-10 17:05:262128void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]f114fa42013-12-06 17:06:442129 FOR_EACH_OBSERVER(
2130 WebContentsObserver, observers_,
2131 DocumentLoadedInFrame(frame_id, render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182132}
2133
[email protected]b172aee2012-04-10 17:05:262134void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312135 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062136 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312137 bool is_main_frame) {
[email protected]8b3af1e2014-01-24 13:29:122138 if (!render_view_message_source_) {
2139 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2140 GetRenderProcessHost()->ReceivedBadMessage();
2141 return;
2142 }
[email protected]a1b99262013-12-27 21:56:222143
2144 // --site-per-process mode has a short-term hack allowing cross-process
2145 // subframe pages to commit thinking they are top-level. Correct it here to
2146 // avoid confusing the observers.
2147 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2148 render_view_message_source_ != GetRenderViewHost())
2149 is_main_frame = false;
2150
[email protected]8b3af1e2014-01-24 13:29:122151 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442152 RenderProcessHost* render_process_host =
2153 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422154 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252155 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472156 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442157 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312158}
2159
[email protected]b172aee2012-04-10 17:05:262160void WebContentsImpl::OnDidFailLoadWithError(
2161 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062162 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262163 bool is_main_frame,
2164 int error_code,
[email protected]fcf75d42013-12-03 20:11:262165 const base::string16& error_description) {
[email protected]15be9bff2014-01-25 07:19:412166 if (!render_view_message_source_) {
2167 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD3"));
2168 GetRenderProcessHost()->ReceivedBadMessage();
2169 return;
2170 }
[email protected]b502ed462013-01-08 08:20:062171 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442172 RenderProcessHost* render_process_host =
2173 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422174 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252175 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312176 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472177 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442178 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182179}
2180
[email protected]b172aee2012-04-10 17:05:262181void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262182 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232183 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252184 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262185 if (!entry)
2186 return;
2187 // Note that we don't call NavigationController::GotToOffset() as we don't
2188 // want to create a pending navigation entry (it might end up lingering
2189 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252190 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212191 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512192 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212193 PAGE_TRANSITION_FORWARD_BACK));
[email protected]3691e5cf2014-01-22 10:16:202194 frame_tree_.root()->navigator()->NavigateToEntry(
2195 frame_tree_.GetMainFrame(),
2196 *entry,
2197 NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572198
2199 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2200 // it in now that we know. This allows us to find the entry when it commits.
2201 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232202 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332203 entry->set_site_instance(
2204 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572205 }
[email protected]216813952011-05-19 22:21:262206 }
2207}
2208
[email protected]b172aee2012-04-10 17:05:262209void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2210 int maximum_percent,
2211 bool remember) {
[email protected]216813952011-05-19 22:21:262212 minimum_zoom_percent_ = minimum_percent;
2213 maximum_zoom_percent_ = maximum_percent;
2214 temporary_zoom_settings_ = !remember;
2215}
2216
[email protected]b172aee2012-04-10 17:05:262217void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342218 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432219 if (!delegate_)
2220 return;
2221
[email protected]b9535422012-02-09 01:47:592222 ChildProcessSecurityPolicyImpl* policy =
2223 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222224 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592225 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212226}
2227
[email protected]b172aee2012-04-10 17:05:262228void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432229 if (delegate_)
2230 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202231}
2232
[email protected]b172aee2012-04-10 17:05:262233void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2234 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262235 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362236 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432237 if (!delegate_)
2238 return;
2239
[email protected]b9535422012-02-09 01:47:592240 ChildProcessSecurityPolicyImpl* policy =
2241 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322242 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592243 return;
[email protected]8f810632013-06-06 22:33:322244
[email protected]3a3b75a2012-06-01 08:38:362245 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202246}
2247
[email protected]b172aee2012-04-10 17:05:262248void WebContentsImpl::OnFindReply(int request_id,
2249 int number_of_matches,
2250 const gfx::Rect& selection_rect,
2251 int active_match_ordinal,
2252 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432253 if (delegate_) {
2254 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2255 active_match_ordinal, final_update);
2256 }
[email protected]b888919c2011-09-02 00:32:162257}
2258
[email protected]59363fc92012-09-05 03:46:312259#if defined(OS_ANDROID)
2260void WebContentsImpl::OnFindMatchRectsReply(
2261 int version,
2262 const std::vector<gfx::RectF>& rects,
2263 const gfx::RectF& active_rect) {
2264 if (delegate_)
2265 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2266}
[email protected]583418cc2013-01-17 14:01:102267
[email protected]1ff427972013-02-07 21:14:072268void WebContentsImpl::OnOpenDateTimeDialog(
2269 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092270 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2271 GetRenderViewHost(),
2272 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132273 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092274 value.minimum,
2275 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172276 value.step,
2277 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102278}
2279
[email protected]a794f3a2013-10-30 17:00:322280void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2281 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442282 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322283}
2284
[email protected]59363fc92012-09-05 03:46:312285#endif
2286
[email protected]f114fa42013-12-06 17:06:442287void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2288 const base::FilePath& path,
2289 bool is_hung) {
2290 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2291
2292 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2293 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2294}
2295
2296void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422297 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442298 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422299 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452300}
2301
[email protected]b172aee2012-04-10 17:05:262302void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2303 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102304 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252305 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102306 AppCacheAccessed(manifest_url, blocked_by_policy));
2307}
2308
[email protected]8bc5ff02013-11-29 06:34:032309void WebContentsImpl::OnOpenColorChooser(
2310 int color_chooser_id,
2311 SkColor color,
2312 const std::vector<ColorSuggestion>& suggestions) {
2313 ColorChooser* new_color_chooser =
2314 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302315 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212316 return;
[email protected]820957a2014-01-14 14:56:302317 if (color_chooser_)
2318 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212319 color_chooser_.reset(new_color_chooser);
2320 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202321}
2322
[email protected]b172aee2012-04-10 17:05:262323void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202324 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212325 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202326 color_chooser_->End();
2327}
2328
[email protected]b172aee2012-04-10 17:05:262329void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322330 SkColor color) {
[email protected]da8543762012-03-20 08:52:202331 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212332 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202333 color_chooser_->SetSelectedColor(color);
2334}
2335
[email protected]d0759f492012-04-19 22:50:502336// This exists for render views that don't have a WebUI, but do have WebUI
2337// bindings enabled.
2338void WebContentsImpl::OnWebUISend(const GURL& source_url,
2339 const std::string& name,
2340 const base::ListValue& args) {
2341 if (delegate_)
2342 delegate_->WebUISend(this, source_url, name, args);
2343}
2344
[email protected]d8415ad92012-08-23 14:40:502345void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442346 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502347 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342348 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162349 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442350 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162351 return;
[email protected]d8415ad92012-08-23 14:40:502352 }
2353
[email protected]8c8fc292012-11-23 18:57:162354 if (!delegate_->RequestPpapiBrokerPermission(
2355 this, url, plugin_path,
2356 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442357 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162358 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442359 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162360 }
[email protected]d8415ad92012-08-23 14:40:502361}
2362
[email protected]ea0309c2013-08-06 19:35:442363void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502364 bool result) {
[email protected]ea0309c2013-08-06 19:35:442365 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502366}
2367
[email protected]c4538072013-03-18 02:17:552368void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372369 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082370 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552371 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392372 // For more info, see comment above classes BrowserPluginEmbedder and
2373 // BrowserPluginGuest.
2374 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142375 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082376 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372377}
2378
[email protected]41225fe2013-03-29 05:32:022379void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392380 int id,
[email protected]749fadd2013-05-15 08:37:482381 int http_status_code,
[email protected]795c28972012-12-06 06:13:392382 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302383 const std::vector<SkBitmap>& bitmaps,
2384 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132385 if (bitmaps.size() != original_bitmap_sizes.size())
2386 return;
2387
[email protected]41225fe2013-03-29 05:32:022388 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2389 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392390 // Currently WebContents notifies us of ANY downloads so that it is
2391 // possible to get here.
2392 return;
2393 }
2394 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302395 iter->second.Run(
2396 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392397 }
[email protected]41225fe2013-03-29 05:32:022398 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392399}
2400
2401void WebContentsImpl::OnUpdateFaviconURL(
2402 int32 page_id,
2403 const std::vector<FaviconURL>& candidates) {
2404 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2405 DidUpdateFaviconURL(page_id, candidates));
2406}
2407
[email protected]1dd0bb752014-02-01 01:16:262408void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2409 bool has_video,
2410 bool has_audio) {
2411// Chrome OS does its own detection of audio and video.
2412#if !defined(OS_CHROMEOS)
2413 scoped_ptr<PowerSaveBlocker> blocker;
2414 if (has_video) {
2415 blocker = PowerSaveBlocker::Create(
2416 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2417#if defined(OS_ANDROID)
2418 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2419 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2420#endif
2421 } else if (has_audio) {
2422 blocker = PowerSaveBlocker::Create(
2423 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2424 }
2425
2426 if (blocker) {
2427 power_save_blockers_[render_view_message_source_][player_cookie] =
2428 blocker.release();
2429 }
2430#endif // !defined(OS_CHROMEOS)
2431}
2432
2433void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062434 // Chrome OS does its own detection of audio and video.
2435#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262436 delete power_save_blockers_[render_view_message_source_][player_cookie];
2437 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062438#endif // !defined(OS_CHROMEOS)
2439}
2440
[email protected]9f268072013-11-07 00:02:152441void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2442 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2443 DidFirstVisuallyNonEmptyPaint(page_id));
2444}
[email protected]d9030b82013-07-19 08:26:062445
[email protected]e67ebf32013-02-13 11:07:192446void WebContentsImpl::DidChangeVisibleSSLState() {
2447 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2448 DidChangeVisibleSSLState());
2449}
2450
[email protected]17e286e2013-03-01 23:29:392451void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2452 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2453 BeforeFormRepostWarningShow());
2454}
2455
[email protected]ec6c05f2013-10-23 18:41:572456
2457void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2458 Activate();
2459 if (delegate_)
2460 delegate_->ShowRepostFormWarningDialog(this);
2461}
2462
[email protected]96d185d2009-04-24 03:28:542463// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592464// loading, or done loading.
2465void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2466 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262467 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542468 if (is_loading == is_loading_)
2469 return;
2470
2471 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262472 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2473 base::string16());
[email protected]96d185d2009-04-24 03:28:542474 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562475 upload_size_ = 0;
2476 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542477 }
2478
[email protected]fa944cb82013-11-15 17:51:212479 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542480
2481 is_loading_ = is_loading;
2482 waiting_for_response_ = is_loading;
2483
[email protected]6ebdc9b2010-09-27 16:55:572484 if (delegate_)
2485 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212486 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542487
[email protected]eab61442013-11-14 18:35:482488 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592489 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482490 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2491 "URL", url);
[email protected]91621872013-10-08 04:04:592492 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2493 DidStartLoading(render_view_host));
2494 } else {
[email protected]eab61442013-11-14 18:35:482495 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2496 "URL", url);
[email protected]91621872013-10-08 04:04:592497 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2498 DidStopLoading(render_view_host));
2499 }
[email protected]66798902013-10-01 18:40:162500
2501 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212502 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2503 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542504 if (details)
[email protected]8ff00d72012-10-23 19:12:212505 det = Details<LoadNotificationDetails>(details);
2506 NotificationService::current()->Notify(
2507 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542508}
2509
[email protected]b172aee2012-04-10 17:05:262510void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212511 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322512 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562513 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322514 // Clear the status bubble. This is a workaround for a bug where WebKit
2515 // doesn't let us know that the cursor left an element during a
2516 // transition (this is also why the mouse cursor remains as a hand after
2517 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2518 // clear the bubble when a user navigates to a named anchor in the same
2519 // page.
[email protected]36fc0392011-12-25 03:59:512520 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322521 }
2522
[email protected]a6e82fc2010-02-24 22:28:142523 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472524 // Once the main frame is navigated, we're no longer considered to have
2525 // displayed insecure content.
2526 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352527 SSLManager::NotifySSLInternalStateChanged(
2528 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172529 }
[email protected]ce5c4502009-05-06 16:46:112530
[email protected]3c9e1872010-11-18 16:17:492531 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252532 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042533 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322534}
2535
[email protected]b172aee2012-04-10 17:05:262536void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322537 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212538 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322539 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112540 // If we navigate off the page, close all JavaScript dialogs.
2541 if (dialog_manager_ && !details.is_in_page)
2542 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322543
[email protected]3c9e1872010-11-18 16:17:492544 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252545 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042546 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322547}
2548
[email protected]2f7b3c5a2013-06-21 04:59:252549bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292550 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2551 // still be used for a normal web site.
2552 if (url == GURL(kAboutBlankURL))
2553 return false;
2554
2555 // The embedder will then have the opportunity to determine if the URL
2556 // should "use up" the SiteInstance.
2557 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252558}
2559
[email protected]b172aee2012-04-10 17:05:262560void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462561 // If we are creating a RVH for a restored controller, then we need to make
2562 // sure the RenderView starts with a next_page_id_ larger than the number
2563 // of restored entries. This must be called before the RenderView starts
2564 // navigating (to avoid a race between the browser updating max_page_id and
2565 // the renderer updating next_page_id_). Because of this, we only call this
2566 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562567 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582568 if (max_restored_page_id >
2569 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2570 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2571 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322572}
2573
[email protected]b172aee2012-04-10 17:05:262574bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262575 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322576 // For file URLs without a title, use the pathname instead. In the case of a
2577 // synthesized title, we don't want the update to count toward the "one set
2578 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262579 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322580 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512581 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242582 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322583 explicit_set = false; // Don't count synthetic titles toward the set limit.
2584 } else {
[email protected]acafd272011-07-26 17:35:572585 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322586 explicit_set = true;
2587 }
2588
[email protected]987fc3a2011-05-26 14:18:092589 // If a page is created via window.open and never navigated,
2590 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552591 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092592 if (entry) {
[email protected]36fc0392011-12-25 03:59:512593 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092594 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322595
[email protected]36fc0392011-12-25 03:59:512596 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092597 } else {
2598 if (page_title_when_no_navigation_entry_ == final_title)
2599 return false; // Nothing changed, don't bother.
2600
2601 page_title_when_no_navigation_entry_ = final_title;
2602 }
[email protected]420ae012009-04-24 05:16:322603
[email protected]420ae012009-04-24 05:16:322604 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232605 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322606
[email protected]66798902013-10-01 18:40:162607 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532608 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162609
2610 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212611 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462612 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212613 NotificationService::current()->Notify(
2614 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2615 Source<WebContents>(this),
2616 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042617
[email protected]420ae012009-04-24 05:16:322618 return true;
2619}
2620
[email protected]7b712ee22013-10-03 00:57:282621void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2622 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322623 // After sending out a swap notification, we need to send a disconnect
2624 // notification so that clients that pick up a pointer to |this| can NULL the
2625 // pointer. See Bug 1230284.
2626 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112627 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282628 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112629
2630 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282631 std::pair<RenderViewHost*, RenderViewHost*> details =
2632 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212633 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282634 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212635 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282636 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392637
2638 // Ensure that the associated embedder gets cleared after a RenderViewHost
2639 // gets swapped, so we don't reuse the same embedder next time a
2640 // RenderViewHost is attached to this WebContents.
2641 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322642}
2643
[email protected]da7a7182013-09-06 08:11:112644// TODO(avi): Remove this entire function because this notification is already
2645// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262646void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322647 if (!notify_disconnection_)
2648 return;
2649
2650 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212651 NotificationService::current()->Notify(
2652 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2653 Source<WebContents>(this),
2654 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322655}
2656
[email protected]cbb1ef592013-06-05 19:49:462657void WebContentsImpl::NotifyNavigationEntryCommitted(
2658 const LoadCommittedDetails& load_details) {
2659 FOR_EACH_OBSERVER(
2660 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2661}
2662
[email protected]f114fa42013-12-06 17:06:442663bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2664 const IPC::Message& message) {
2665 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312666}
2667
[email protected]b849847b2013-12-10 21:57:582668void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2669 // Note this is only for subframes, the notification for the main frame
2670 // happens in RenderViewCreated.
2671 FOR_EACH_OBSERVER(WebContentsObserver,
2672 observers_,
2673 RenderFrameCreated(render_frame_host));
2674}
2675
2676void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2677 FOR_EACH_OBSERVER(WebContentsObserver,
2678 observers_,
2679 RenderFrameDeleted(render_frame_host));
2680}
2681
[email protected]a09d53ce2014-01-31 00:46:422682void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302683 if (delegate_)
2684 delegate_->WorkerCrashed(this);
2685}
2686
[email protected]a09d53ce2014-01-31 00:46:422687void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2688 const ContextMenuParams& params) {
2689 // Allow WebContentsDelegates to handle the context menu operation first.
2690 if (delegate_ && delegate_->HandleContextMenu(params))
2691 return;
2692
2693 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2694}
2695
[email protected]a86c0e962013-12-17 17:10:392696WebContents* WebContentsImpl::GetAsWebContents() {
2697 return this;
2698}
2699
[email protected]5a3bdf52012-05-24 15:12:572700RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2701 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322702}
2703
[email protected]8d3347f2009-07-09 22:00:212704RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262705WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212706 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212707}
2708
[email protected]8ff00d72012-10-23 19:12:212709RendererPreferences WebContentsImpl::GetRendererPrefs(
2710 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462711 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512712}
2713
[email protected]b172aee2012-04-10 17:05:262714gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172715 if (delegate_)
2716 return delegate_->GetRootWindowResizerRect();
2717 return gfx::Rect();
2718}
2719
[email protected]7a846df2012-09-20 19:17:392720void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272721 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392722 browser_plugin_embedder_.reset();
2723}
2724
[email protected]b172aee2012-04-10 17:05:262725void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442726 // Don't send notifications if we are just creating a swapped-out RVH for
2727 // the opener chain. These won't be used for view-source or WebUI, so it's
2728 // ok to return early.
2729 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2730 return;
2731
[email protected]86f98a22013-03-20 14:35:002732 if (delegate_)
2733 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082734
[email protected]8ff00d72012-10-23 19:12:212735 NotificationService::current()->Notify(
2736 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2737 Source<WebContents>(this),
2738 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322739
2740 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352741 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212742 if (GetRenderManager()->pending_web_ui())
2743 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322744
[email protected]6286a372013-10-09 04:03:272745 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332746 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322747 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182748 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582749 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322750 }
[email protected]0666aef2009-05-13 19:48:082751
[email protected]60780f412013-02-25 16:34:102752 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262753
2754 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252755 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582756
2757 // We tell the observers now instead of when the main RenderFrameHostImpl is
2758 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2759 // frame would be dropped because it's not created yet).
2760 RenderFrameHost* main_frame = GetMainFrame();
2761 FOR_EACH_OBSERVER(
2762 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322763}
2764
[email protected]b172aee2012-04-10 17:05:262765void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522766 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322767 // Don't notify the world, since this came from a renderer in the
2768 // background.
2769 return;
2770 }
2771
[email protected]da7a7182013-09-06 08:11:112772 notify_disconnection_ = true;
2773 // TODO(avi): Remove. http://crbug.com/170921
2774 NotificationService::current()->Notify(
2775 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2776 Source<WebContents>(this),
2777 NotificationService::NoDetails());
2778
[email protected]be1f56ab2011-12-22 06:55:312779 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232780 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302781
2782 // Restore the focus to the tab (otherwise the focus will be on the top
2783 // window).
[email protected]484ae5912010-09-29 19:16:142784 if (was_crashed && !FocusLocationBarByDefault() &&
2785 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062786 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142787 }
[email protected]32ded2212011-11-10 18:51:432788
[email protected]d8c660432011-12-22 20:51:252789 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322790}
2791
[email protected]ec6a7eb2013-04-22 17:34:222792void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2793 base::TerminationStatus status,
2794 int error_code) {
[email protected]151a63d2011-12-20 22:32:522795 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322796 // The pending page's RenderViewHost is gone.
2797 return;
2798 }
2799
[email protected]d9030b82013-07-19 08:26:062800 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592801 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322802 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232803 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312804 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322805
[email protected]d8c660432011-12-22 20:51:252806 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272807 observers_,
[email protected]58d5cfe2013-07-10 02:40:522808 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322809}
2810
[email protected]b172aee2012-04-10 17:05:262811void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062812 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212813 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252814 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062815}
2816
[email protected]b172aee2012-04-10 17:05:262817void WebContentsImpl::DidNavigate(
2818 RenderViewHost* rvh,
[email protected]a1b99262013-12-27 21:56:222819 const ViewHostMsg_FrameNavigate_Params& orig_params) {
2820 ViewHostMsg_FrameNavigate_Params params(orig_params);
2821 bool use_site_per_process =
2822 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess);
[email protected]9b159a52013-10-03 17:24:552823 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2824 // First navigation should be a main frame navigation.
[email protected]a1b99262013-12-27 21:56:222825 // TODO(creis): This DCHECK is currently disabled for --site-per-process
2826 // because cross-process subframe navigations still have a main frame
2827 // PageTransition.
2828 if (!use_site_per_process)
2829 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552830 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122831 }
2832
[email protected]a1b99262013-12-27 21:56:222833 // When using --site-per-process, look up the FrameTreeNode ID that the
2834 // renderer-specific frame ID corresponds to.
2835 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id();
2836 if (use_site_per_process) {
2837 FrameTreeNode* source_node = frame_tree_.FindByFrameID(params.frame_id);
2838 if (source_node)
2839 frame_tree_node_id = source_node->frame_tree_node_id();
2840
2841 // TODO(creis): In the short term, cross-process subframe navigations are
2842 // happening in the pending RenderViewHost's top-level frame. (We need to
2843 // both mirror the frame tree and get the navigation to occur in the correct
2844 // subframe to fix this.) Until then, we should check whether we have a
2845 // pending NavigationEntry with a frame ID and if so, treat the
2846 // cross-process "main frame" navigation as a subframe navigation. This
2847 // limits us to a single cross-process subframe per RVH, and it affects
2848 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and
2849 // OnDidFinishLoad.
2850 NavigationEntryImpl* pending_entry =
2851 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
2852 int root_ftn_id = frame_tree_.root()->frame_tree_node_id();
2853 if (pending_entry &&
2854 pending_entry->frame_tree_node_id() != -1 &&
2855 pending_entry->frame_tree_node_id() != root_ftn_id) {
2856 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
2857 frame_tree_node_id = pending_entry->frame_tree_node_id();
2858 }
2859 }
2860
[email protected]e3d92a7f2013-01-10 02:35:052861 if (PageTransitionIsMainFrame(params.transition)) {
2862 // When overscroll navigation gesture is enabled, a screenshot of the page
2863 // in its current state is taken so that it can be used during the
2864 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362865 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052866 // WebContents::GetRenderViewHost to return the new host, instead of the one
2867 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482868 if (delegate_ && delegate_->CanOverscrollContent())
2869 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052870
[email protected]a1b99262013-12-27 21:56:222871 if (!use_site_per_process)
2872 GetRenderManager()->DidNavigateMainFrame(rvh);
2873 }
2874
2875 // When using --site-per-process, we notify the RFHM for all navigations,
2876 // not just main frame navigations.
2877 if (use_site_per_process) {
2878 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
2879 // TODO(creis): Rename to DidNavigateFrame.
2880 frame->render_manager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052881 }
[email protected]8030f012009-09-25 18:09:372882
[email protected]434f69f2012-02-06 21:56:522883 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252884 // assigning a site is not necessary for this URL. In that case, the
2885 // SiteInstance can still be considered unused until a navigation to a real
2886 // page.
[email protected]434f69f2012-02-06 21:56:522887 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252888 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332889 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522890 }
[email protected]420ae012009-04-24 05:16:322891
2892 // Need to update MIME type here because it's referred to in
2893 // UpdateNavigationCommands() called by RendererDidNavigate() to
2894 // determine whether or not to enable the encoding menu.
2895 // It's updated only for the main frame. For a subframe,
2896 // RenderView::UpdateURL does not set params.contents_mime_type.
2897 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2898 // TODO(jungshik): Add a test for the encoding menu to avoid
2899 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212900 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322901 contents_mime_type_ = params.contents_mime_type;
2902
[email protected]8ff00d72012-10-23 19:12:212903 LoadCommittedDetails details;
[email protected]a1b99262013-12-27 21:56:222904 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details);
[email protected]3e90d4a2009-07-03 17:38:392905
[email protected]1ae93fb2013-06-14 03:38:562906 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2907 // us estimate our process count for implementing OOP iframes.
2908 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552909 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562910
[email protected]a9c0bfe2010-09-17 08:35:222911 // Send notification about committed provisional loads. This notification is
2912 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2913 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212914 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072915 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2916 // that is not recorded in the navigation history. For the purpose of
2917 // tracking navigation events, we treat this event as a sub frame navigation
2918 // event.
2919 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212920 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222921 // Whether or not a page transition was triggered by going backward or
2922 // forward in the history is only stored in the navigation controller's
2923 // entry list.
2924 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272925 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212926 PAGE_TRANSITION_FORWARD_BACK)) {
2927 transition_type = PageTransitionFromInt(
2928 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222929 }
[email protected]0d60f0192011-04-14 12:40:102930 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252931 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442932 DidCommitProvisionalLoadForFrame(
2933 params.frame_id,
2934 params.frame_unique_name,
2935 is_main_frame,
2936 params.url,
2937 transition_type,
2938 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222939 }
2940
[email protected]76543b92009-08-31 17:27:452941 if (!did_navigate)
2942 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322943
2944 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2945 // for the appropriate notification (best) or you can add it to
2946 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2947 // necessary, please).
2948
2949 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002950 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322951 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002952 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512953 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002954 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2955 }
[email protected]93f230e02011-06-01 14:40:002956 }
[email protected]420ae012009-04-24 05:16:322957 DidNavigateAnyFramePostCommit(rvh, details, params);
2958}
2959
[email protected]b172aee2012-04-10 17:05:262960void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2961 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042962 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152963 // Ensure that this state update comes from either the active RVH or one of
2964 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412965 // TODO(nasko): This should go through RenderFrameHost.
2966 // TODO(creis): We can't update state for cross-process subframes until we
2967 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2968 if (rvh != GetRenderViewHost() &&
2969 !GetRenderManager()->IsRVHOnSwappedOutList(
2970 static_cast<RenderViewHostImpl*>(rvh)))
2971 return;
[email protected]420ae012009-04-24 05:16:322972
2973 // We must be prepared to handle state updates for any page, these occur
2974 // when the user is scrolling and entering form data, as well as when we're
2975 // leaving a page, in which case our state may have already been moved to
2976 // the next page. The navigation controller will look up the appropriate
2977 // NavigationEntry and update it when it is notified via the delegate.
2978
2979 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582980 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322981 if (entry_index < 0)
2982 return;
[email protected]10f417c52011-12-28 21:04:232983 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322984
[email protected]691aa2f2013-05-28 22:52:042985 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322986 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042987 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322988 controller_.NotifyEntryChanged(entry, entry_index);
2989}
2990
[email protected]b172aee2012-04-10 17:05:262991void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2992 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262993 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262994 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322995 // If we have a title, that's a pretty good indication that we've started
2996 // getting useful data.
2997 SetNotWaitingForResponse();
2998
[email protected]73eb2602012-02-09 19:50:552999 // Try to find the navigation entry, which might not be the current one.
3000 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233001 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583002 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093003
[email protected]73eb2602012-02-09 19:50:553004 // We can handle title updates when we don't have an entry in
3005 // UpdateTitleForEntry, but only if the update is from the current RVH.
3006 if (!entry && rvh != GetRenderViewHost())
3007 return;
3008
[email protected]a49e10b2011-08-01 23:57:463009 // TODO(evan): make use of title_direction.
3010 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093011 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323012 return;
3013
3014 // Broadcast notifications when the UI should be updated.
3015 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213016 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323017}
3018
[email protected]b172aee2012-04-10 17:05:263019void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3020 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313021 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323022}
3023
[email protected]b172aee2012-04-10 17:05:263024void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513025 if (delegate_)
3026 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323027}
3028
[email protected]b172aee2012-04-10 17:05:263029void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103030#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293031 // The UI may be in an event-tracking loop, such as between the
3032 // mouse-down and mouse-up in text selection or a button click.
3033 // Defer the close until after tracking is complete, so that we
3034 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293035 // TODO(shess): This could get more fine-grained. For instance,
3036 // closing a tab in another window while selecting text in the
3037 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103038 if (view_->IsEventTracking()) {
3039 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293040 return;
3041 }
[email protected]60780f412013-02-25 16:34:103042#endif
[email protected]07707302009-11-06 00:50:293043
[email protected]420ae012009-04-24 05:16:323044 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523045 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513046 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323047}
3048
[email protected]b172aee2012-04-10 17:05:263049void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523050 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513051 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283052
3053 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213054 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573055}
3056
[email protected]b172aee2012-04-10 17:05:263057void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513058 if (delegate_ && delegate_->IsPopupOrPanel(this))
3059 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323060}
3061
[email protected]8ff00d72012-10-23 19:12:213062void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593063 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323064}
3065
[email protected]8ff00d72012-10-23 19:12:213066void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323067 scoped_ptr<LoadNotificationDetails> details;
3068
[email protected]9595fd82013-04-19 21:28:493069 // Use the last committed entry rather than the active one, in case a
3070 // pending entry has been created.
3071 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203072 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493073
[email protected]420ae012009-04-24 05:16:323074 // An entry may not exist for a stop when loading an initial blank page or
3075 // if an iframe injected by script into a blank page finishes loading.
3076 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203077 base::TimeDelta elapsed =
3078 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323079
3080 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513081 entry->GetVirtualURL(),
3082 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323083 elapsed,
3084 &controller_,
3085 controller_.GetCurrentEntryIndex()));
3086 }
3087
[email protected]91621872013-10-08 04:04:593088 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323089}
3090
[email protected]b172aee2012-04-10 17:05:263091void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163092 controller_.DiscardNonCommittedEntries();
3093
3094 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213095 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163096}
3097
[email protected]b172aee2012-04-10 17:05:263098void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513099 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133100 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403101}
3102
[email protected]7cc78902012-12-06 02:32:263103void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393104 if (opener_) {
3105 // Clear our opener so that future cross-process navigations don't have an
3106 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103107 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393108 opener_ = NULL;
3109 }
[email protected]7cc78902012-12-06 02:32:263110
3111 // Notify all swapped out RenderViewHosts for this tab. This is important
3112 // in case we go back to them, or if another window in those processes tries
3113 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213114 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263115}
3116
[email protected]59167c22013-06-03 18:07:323117void WebContentsImpl::DidAccessInitialDocument() {
3118 // Update the URL display.
3119 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3120}
3121
[email protected]87717d0e2012-04-26 02:58:433122void WebContentsImpl::DocumentAvailableInMainFrame(
3123 RenderViewHost* render_view_host) {
3124 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3125 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103126}
3127
[email protected]b172aee2012-04-10 17:05:263128void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083129 RenderViewHost* render_view_host,
3130 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093131 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3132 DocumentOnLoadCompletedInMainFrame(page_id));
3133
3134 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213135 NotificationService::current()->Notify(
3136 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3137 Source<WebContents>(this),
3138 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083139}
3140
[email protected]196159d2012-05-04 17:26:543141void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3142 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213143 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263144 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183145 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523146 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303147 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543148 // If this came from a swapped out RenderViewHost, we only allow the request
3149 // if we are still in the same BrowsingInstance.
3150 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3151 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3152 return;
3153 }
3154
[email protected]4ad5d77d2011-12-03 02:00:483155 // Delegate to RequestTransferURL because this is just the generic
3156 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573157 // TODO(creis): Pass the redirect_chain into this method to support client
3158 // redirects. http://crbug.com/311721.
3159 std::vector<GURL> redirect_chain;
3160 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3161 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523162 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483163}
3164
[email protected]b172aee2012-04-10 17:05:263165void WebContentsImpl::RequestTransferURL(
3166 const GURL& url,
[email protected]f8872902013-10-30 03:18:573167 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213168 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573169 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263170 WindowOpenDisposition disposition,
3171 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183172 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523173 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303174 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203175 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123176 GURL dest_url(url);
3177 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553178 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123179 dest_url = GURL(kAboutBlankURL);
3180
[email protected]a1b99262013-12-27 21:56:223181 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3182 int64 frame_tree_node_id = -1;
3183 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3184 source_frame_id != -1) {
3185 FrameTreeNode* source_node = frame_tree_.FindByFrameID(source_frame_id);
3186 if (source_node)
3187 frame_tree_node_id = source_node->frame_tree_node_id();
3188 }
[email protected]c80297782013-11-21 07:10:163189 OpenURLParams params(dest_url, referrer, source_frame_id,
3190 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573191 page_transition, true /* is_renderer_initiated */);
3192 if (redirect_chain.size() > 0)
3193 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553194 params.transferred_global_request_id = old_request_id;
3195 params.should_replace_current_entry = should_replace_current_entry;
3196 params.user_gesture = user_gesture;
3197
[email protected]fa944cb82013-11-15 17:51:213198 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573199 // Web UI pages sometimes want to override the page transition type for
3200 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3201 // automatically generated suggestions). We don't override other types
3202 // like TYPED because they have different implications (e.g., autocomplete).
3203 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213204 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553205
[email protected]e0112912011-02-02 22:54:353206 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163207 // want web sites to see a referrer of "chrome://blah" (and some
3208 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323209 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553210 params.referrer = Referrer();
3211
3212 // Navigations in Web UI pages count as browser-initiated navigations.
3213 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583214 }
[email protected]44d0930a2013-10-28 18:53:553215
3216 new_contents = OpenURL(params);
3217
[email protected]ae5184d62011-10-06 19:25:583218 if (new_contents) {
3219 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253220 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583221 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123222 dest_url,
[email protected]ae5184d62011-10-06 19:25:583223 referrer,
3224 disposition,
[email protected]44d0930a2013-10-28 18:53:553225 params.transition,
[email protected]ae5184d62011-10-06 19:25:583226 source_frame_id));
[email protected]420ae012009-04-24 05:16:323227 }
3228}
3229
[email protected]e1c3a552012-05-04 20:51:323230void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3231 // Tell the active RenderViewHost to run unload handlers and close, as long
3232 // as the request came from a RenderViewHost in the same BrowsingInstance.
3233 // In most cases, we receive this from a swapped out RenderViewHost.
3234 // It is possible to receive it from one that has just been swapped in,
3235 // in which case we might as well deliver the message anyway.
3236 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3237 GetRenderViewHost()->ClosePage();
3238}
3239
[email protected]f546640b2012-05-15 00:03:493240void WebContentsImpl::RouteMessageEvent(
3241 RenderViewHost* rvh,
3242 const ViewMsg_PostMessage_Params& params) {
3243 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363244 // came from a RenderViewHost in the same BrowsingInstance or if this
3245 // WebContents is dedicated to a browser plugin guest.
3246 // Note: This check means that an embedder could theoretically receive a
3247 // postMessage from anyone (not just its own guests). However, this is
3248 // probably not a risk for apps since other pages won't have references
3249 // to App windows.
3250 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3251 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493252 return;
3253
3254 ViewMsg_PostMessage_Params new_params(params);
3255
[email protected]0bc7f3542013-10-21 15:05:533256 if (!params.message_port_ids.empty()) {
3257 MessagePortMessageFilter* message_port_message_filter =
3258 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3259 ->message_port_message_filter();
3260 std::vector<int> new_routing_ids(params.message_port_ids.size());
3261 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3262 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3263 MessagePortService::GetInstance()->UpdateMessagePort(
3264 params.message_port_ids[i],
3265 message_port_message_filter,
3266 new_routing_ids[i]);
3267 }
3268 new_params.new_routing_ids = new_routing_ids;
3269 }
3270
[email protected]f546640b2012-05-15 00:03:493271 // If there is a source_routing_id, translate it to the routing ID for
3272 // the equivalent swapped out RVH in the target process. If we need
3273 // to create a swapped out RVH for the source tab, we create its opener
3274 // chain as well, since those will also be accessible to the target page.
3275 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3276 // Try to look up the WebContents for the source page.
3277 WebContentsImpl* source_contents = NULL;
3278 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3279 rvh->GetProcess()->GetID(), params.source_routing_id);
3280 if (source_rvh) {
3281 source_contents = static_cast<WebContentsImpl*>(
3282 source_rvh->GetDelegate()->GetAsWebContents());
3283 }
3284
3285 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363286 if (GetBrowserPluginGuest()) {
3287 // We create a swapped out RenderView for the embedder in the guest's
3288 // render process but we intentionally do not expose the embedder's
3289 // opener chain to it.
3290 new_params.source_routing_id =
3291 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3292 } else {
3293 new_params.source_routing_id =
3294 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3295 }
[email protected]f546640b2012-05-15 00:03:493296 } else {
3297 // We couldn't find it, so don't pass a source frame.
3298 new_params.source_routing_id = MSG_ROUTING_NONE;
3299 }
3300 }
3301
3302 // In most cases, we receive this from a swapped out RenderViewHost.
3303 // It is possible to receive it from one that has just been swapped in,
3304 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183305 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493306}
3307
[email protected]b172aee2012-04-10 17:05:263308void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343309 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263310 const base::string16& message,
3311 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323312 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213313 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323314 IPC::Message* reply_msg,
3315 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073316 // Suppress JavaScript dialogs when requested. Also suppress messages when
3317 // showing an interstitial as it's shown over the previous page and we don't
3318 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503319 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583320 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273321 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073322 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523323 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153324 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323325
3326 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213327 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433328 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153329 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3330 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433331 this,
3332 frame_url.GetOrigin(),
3333 accept_lang,
3334 javascript_message_type,
3335 message,
[email protected]51da7e32012-01-30 19:24:523336 default_prompt,
[email protected]b172aee2012-04-10 17:05:263337 base::Bind(&WebContentsImpl::OnDialogClosed,
3338 base::Unretained(this),
3339 rvh,
3340 reply_msg),
[email protected]51da7e32012-01-30 19:24:523341 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323342 }
[email protected]3ab9cb82011-06-03 18:02:073343
[email protected]6dd2f1e2013-09-11 15:06:013344 *did_suppress_message = suppress_this_message;
3345
[email protected]3ab9cb82011-06-03 18:02:073346 if (suppress_this_message) {
3347 // If we are suppressing messages, just reply as if the user immediately
3348 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263349 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073350 }
3351
[email protected]6dd2f1e2013-09-11 15:06:013352 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3353 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323354}
3355
[email protected]b172aee2012-04-10 17:05:263356void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263357 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263358 bool is_reload,
3359 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583360 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513361 if (delegate_)
3362 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073363
3364 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583365 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073366 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523367 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153368 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153369 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343370 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263371 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503372 return;
3373 }
[email protected]3ab9cb82011-06-03 18:02:073374
[email protected]7ab1e7d62009-10-14 23:32:013375 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153376 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3377 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323378 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263379 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523380 reply_msg));
[email protected]420ae012009-04-24 05:16:323381}
3382
[email protected]a796f202012-05-30 14:14:253383bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263384 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253385 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263386 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253387 if (!delegate_)
3388 return false;
3389 return delegate_->AddMessageToConsole(this, level, message, line_no,
3390 source_id);
3391}
3392
[email protected]b172aee2012-04-10 17:05:263393WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273394 // We want to base the page config off of the actual URL, rather than the
3395 // virtual URL.
3396 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3397 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003398 GURL url = controller_.GetActiveEntry()
3399 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153400
[email protected]fa944cb82013-11-15 17:51:213401 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323402}
3403
[email protected]0eba810b2012-10-18 03:19:363404int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213405 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413406 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3407 true, true);
[email protected]0eba810b2012-10-18 03:19:363408}
3409
[email protected]b172aee2012-04-10 17:05:263410void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273411 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253412 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223413
[email protected]ea114722012-03-12 01:11:253414 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173415 if (rdh) // NULL in unittests.
3416 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253417}
3418
[email protected]b172aee2012-04-10 17:05:263419void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443420 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253421 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443422}
3423
[email protected]b172aee2012-04-10 17:05:263424void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563425 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263426 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153427 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523428 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153429 return;
3430
[email protected]9f76c1e2012-03-05 15:15:583431 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3432
[email protected]e5fc1632011-08-08 07:51:533433 // Ignore renderer unresponsive event if debugger is attached to the tab
3434 // since the event may be a result of the renderer sitting on a breakpoint.
3435 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363436 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533437 return;
3438
[email protected]2e9d79f2013-08-16 05:45:563439 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323440 // Hang occurred while firing the beforeunload/unload handler.
3441 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583442 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323443
[email protected]fa944cb82013-11-15 17:51:213444 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323445 return;
3446
3447 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563448 // nothing we can do to recover. If the hang is in the beforeunload handler,
3449 // pretend the beforeunload listeners have all fired and allow the delegate
3450 // to continue closing; the user will not have the option of cancelling the
3451 // close. Otherwise, pretend the unload listeners have all fired and close
3452 // the tab.
3453 bool close = true;
3454 if (is_during_beforeunload) {
3455 delegate_->BeforeUnloadFired(this, true, &close);
3456 }
3457 if (close)
3458 Close(rvh);
[email protected]420ae012009-04-24 05:16:323459 return;
3460 }
3461
[email protected]9f76c1e2012-03-05 15:15:583462 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473463 return;
3464
[email protected]6934a702011-12-20 00:04:513465 if (delegate_)
3466 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323467}
3468
[email protected]b172aee2012-04-10 17:05:263469void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513470 if (delegate_)
3471 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323472}
3473
[email protected]b172aee2012-04-10 17:05:263474void WebContentsImpl::LoadStateChanged(
3475 const GURL& url,
3476 const net::LoadStateWithParam& load_state,
3477 uint64 upload_position,
3478 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323479 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563480 upload_position_ = upload_position;
3481 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503482 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213483 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303484 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213485 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323486 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463487 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213488 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463489 }
[email protected]420ae012009-04-24 05:16:323490}
3491
[email protected]b172aee2012-04-10 17:05:263492void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553493 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323494 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123495 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3496 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513497 if (delegate_)
3498 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093499 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323500}
3501
[email protected]58d5cfe2013-07-10 02:40:523502void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543503 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233504 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223505 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543506}
3507
[email protected]b172aee2012-04-10 17:05:263508void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103509 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213510 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263511 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3512 // here during container initialization and normal window size will be set
3513 // later. In case of tab duplication this resizing to 0x0 prevents setting
3514 // normal size later so just ignore it.
3515 if (!size.IsEmpty())
3516 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323517}
3518
[email protected]af905902013-10-01 21:38:513519void WebContentsImpl::CancelModalDialogsForRenderManager() {
3520 // We need to cancel modal dialogs when doing a process swap, since the load
3521 // deferrer would prevent us from swapping out.
3522 if (dialog_manager_)
3523 dialog_manager_->CancelActiveAndPendingDialogs(this);
3524}
3525
[email protected]7b712ee22013-10-03 00:57:283526void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3527 RenderViewHost* new_host) {
3528 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083529
3530 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003531 if (delegate_)
3532 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393533
[email protected]7b712ee22013-10-03 00:57:283534 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543535}
3536
[email protected]14392a52012-05-02 20:28:443537int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3538 SiteInstance* instance) {
3539 if (!opener_)
3540 return MSG_ROUTING_NONE;
3541
3542 // Recursively create RenderViews for anything else in the opener chain.
3543 return opener_->CreateOpenerRenderViews(instance);
3544}
3545
3546int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3547 int opener_route_id = MSG_ROUTING_NONE;
3548
3549 // If this tab has an opener, ensure it has a RenderView in the given
3550 // SiteInstance as well.
3551 if (opener_)
3552 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3553
[email protected]45a22ad2013-02-21 03:25:003554 // If any of the renderers (current, pending, or swapped out) for this
3555 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213556 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3557 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373558
[email protected]fa944cb82013-11-15 17:51:213559 if (GetRenderManager()->pending_render_view_host() &&
3560 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3561 instance)
3562 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003563
[email protected]fa944cb82013-11-15 17:51:213564 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373565 instance);
3566 if (rvh)
3567 return rvh->GetRoutingID();
3568
[email protected]14392a52012-05-02 20:28:443569 // Create a swapped out RenderView in the given SiteInstance if none exists,
3570 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413571 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3572 true, true);
[email protected]14392a52012-05-02 20:28:443573}
3574
[email protected]b172aee2012-04-10 17:05:263575NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193576 return GetController();
[email protected]3a3d47472010-07-15 21:03:543577}
3578
[email protected]b172aee2012-04-10 17:05:263579WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563580 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323581}
3582
[email protected]10f417c52011-12-28 21:04:233583NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263584 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323585 return controller_.GetLastCommittedEntry();
3586}
3587
[email protected]b172aee2012-04-10 17:05:263588bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163589 RenderViewHost* render_view_host,
3590 int opener_route_id,
3591 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033592 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443593 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163594 RenderWidgetHostView* rwh_view;
3595 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3596 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3597 // case this because RWH is still a base class of RenderViewHost, and child
3598 // frame RWHVs are unique in that they do not have their own WebContents.
3599 if (frame_connector) {
3600 RenderWidgetHostViewChildFrame* rwh_view_child =
3601 new RenderWidgetHostViewChildFrame(render_view_host);
3602 frame_connector->set_view(rwh_view_child);
3603 rwh_view = rwh_view_child;
3604 } else {
3605 rwh_view = view_->CreateViewForWidget(render_view_host);
3606 }
[email protected]1a98a932009-11-17 00:12:523607
[email protected]420ae012009-04-24 05:16:323608 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443609 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213610 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323611
[email protected]74ce1ad2011-12-16 21:51:463612 // Make sure we use the correct starting page_id in the new RenderView.
3613 UpdateMaxPageIDIfNecessary(render_view_host);
3614 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583615 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463616
[email protected]9f76c1e2012-03-05 15:15:583617 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263618 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493619 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133620 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523621 return false;
[email protected]14392a52012-05-02 20:28:443622 }
[email protected]a4127722011-04-27 23:13:523623
[email protected]a220b5932013-09-21 03:47:443624#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503625 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3626 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443627 if (rwh_view) {
3628 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3629 render_widget_host->WasResized();
3630 }
[email protected]f8233cc2011-05-31 20:24:503631#endif
3632
[email protected]420ae012009-04-24 05:16:323633 return true;
3634}
3635
[email protected]7d244f12013-08-22 21:41:513636#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183637base::android::ScopedJavaLocalRef<jobject>
3638WebContentsImpl::GetJavaWebContents() {
3639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3640
3641 WebContentsAndroid* web_contents_android =
3642 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3643 if (!web_contents_android) {
3644 web_contents_android = new WebContentsAndroid(this);
3645 SetUserData(kWebContentsAndroidKey, web_contents_android);
3646 }
3647 return web_contents_android->GetJavaObject();
3648}
3649
[email protected]7d244f12013-08-22 21:41:513650bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3651 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163652 MSG_ROUTING_NONE,
3653 NULL);
[email protected]7d244f12013-08-22 21:41:513654}
3655#endif
3656
[email protected]b172aee2012-04-10 17:05:263657void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3658 IPC::Message* reply_msg,
3659 bool success,
[email protected]fcf75d42013-12-03 20:11:263660 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543661 if (is_showing_before_unload_dialog_ && !success) {
3662 // If a beforeunload dialog is canceled, we need to stop the throbber from
3663 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293664 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353665 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103666
[email protected]6d65a462013-06-21 21:29:123667 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3668 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543669 }
3670 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583671 static_cast<RenderViewHostImpl*>(
3672 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543673}
3674
[email protected]b172aee2012-04-10 17:05:263675void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213676 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123677 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103678}
[email protected]f45d2a72010-03-08 23:28:353679
[email protected]b172aee2012-04-10 17:05:263680void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103681 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443682 // Can be NULL during tests.
3683 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213684 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363685}
[email protected]9f76c1e2012-03-05 15:15:583686
[email protected]1ac10dca2013-08-20 20:47:043687bool WebContentsImpl::IsHidden() {
3688 return capturer_count_ == 0 && !should_normally_be_visible_;
3689}
3690
[email protected]b0936d22013-11-28 06:47:363691RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213692 return frame_tree_.root()->render_manager();
3693}
3694
[email protected]b172aee2012-04-10 17:05:263695RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583696 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3697}
[email protected]7900bfdb2012-05-24 19:31:243698
[email protected]f8497342013-02-05 22:15:023699BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393700 return browser_plugin_guest_.get();
3701}
3702
[email protected]738f57a2013-06-29 21:06:543703void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3704 CHECK(!browser_plugin_guest_);
3705 browser_plugin_guest_.reset(guest);
3706}
3707
[email protected]f8497342013-02-05 22:15:023708BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393709 return browser_plugin_embedder_.get();
3710}
[email protected]8ff00d72012-10-23 19:12:213711
[email protected]8eb04562013-03-06 03:41:143712BrowserPluginGuestManager*
3713 WebContentsImpl::GetBrowserPluginGuestManager() const {
3714 return static_cast<BrowserPluginGuestManager*>(
3715 GetBrowserContext()->GetUserData(
3716 browser_plugin::kBrowserPluginGuestManagerKeyName));
3717}
3718
[email protected]d9030b82013-07-19 08:26:063719void WebContentsImpl::ClearPowerSaveBlockers(
3720 RenderViewHost* render_view_host) {
3721 STLDeleteValues(&power_save_blockers_[render_view_host]);
3722 power_save_blockers_.erase(render_view_host);
3723}
3724
3725void WebContentsImpl::ClearAllPowerSaveBlockers() {
3726 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3727 i != power_save_blockers_.end(); ++i)
3728 STLDeleteValues(&power_save_blockers_[i->first]);
3729 power_save_blockers_.clear();
3730}
3731
[email protected]dc0fd432013-08-27 15:29:213732gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3733 gfx::Size size;
3734 if (delegate_)
3735 size = delegate_->GetSizeForNewRenderView(this);
3736 if (size.IsEmpty())
3737 size = view_->GetContainerSize();
3738 return size;
3739}
3740
[email protected]9b159a52013-10-03 17:24:553741void WebContentsImpl::OnFrameRemoved(
3742 RenderViewHostImpl* render_view_host,
3743 int64 frame_id) {
3744 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3745 FrameDetached(render_view_host, frame_id));
3746}
3747
[email protected]8ff00d72012-10-23 19:12:213748} // namespace content