blob: 1661fbbb880130b1079eec01c26e64f4ddea7603 [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]1d62cf72014-02-07 21:31:57431 // Message handlers should be aware of which
432 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
433 // stored in render_(view|frame)_message_source_.
434 if (render_frame_host)
435 render_frame_message_source_ = render_frame_host;
436 else
437 render_view_message_source_ = render_view_host;
438
[email protected]724159a2010-12-30 01:11:18439 bool handled = true;
440 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26441 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44442 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
443 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]724159a2010-12-30 01:11:18444 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
445 OnDidLoadResourceFromMemoryCache)
446 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
447 OnDidDisplayInsecureContent)
448 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
449 OnDidRunInsecureContent)
[email protected]1d62cf72014-02-07 21:31:57450 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
[email protected]724159a2010-12-30 01:11:18451 OnDocumentLoadedInFrame)
452 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26453 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
454 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25455 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26456 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21457 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20458 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
459 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
460 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16461 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10462 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20463 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
464 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
465 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
466 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50467 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50468 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
469 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55470 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
471 OnBrowserPluginMessage(message))
472 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
473 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02474 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
475 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10476#if defined(OS_ANDROID)
477 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
478 OnFindMatchRectsReply)
479 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
480 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32481 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
482 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10483#endif
[email protected]1dd0bb752014-02-01 01:16:26484 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
485 OnMediaPlayingNotification)
486 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
487 OnMediaPausedNotification)
[email protected]9f268072013-11-07 00:02:15488 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
489 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07490 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
491 OnShowValidationMessage)
492 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
493 OnHideValidationMessage)
494 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
495 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18496 IPC_MESSAGE_UNHANDLED(handled = false)
497 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44498 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57499 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18500
501 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39502 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18503 GetRenderProcessHost()->ReceivedBadMessage();
504 }
505
506 return handled;
507}
508
[email protected]b172aee2012-04-10 17:05:26509void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18510 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21511 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43512 if (delegate_)
513 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18514}
515
[email protected]d1198fd2012-08-13 22:50:19516NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56517 return controller_;
518}
519
[email protected]d1198fd2012-08-13 22:50:19520const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56521 return controller_;
522}
523
[email protected]8ff00d72012-10-23 19:12:21524BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55525 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30526}
527
[email protected]b172aee2012-04-10 17:05:26528const GURL& WebContentsImpl::GetURL() 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]36fc0392011-12-25 03:59:51531 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31532}
533
[email protected]a093ce02013-07-22 20:53:14534const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24535 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32536 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24537 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
538}
539
540const GURL& WebContentsImpl::GetLastCommittedURL() const {
541 // We may not have a navigation entry yet.
542 NavigationEntry* entry = controller_.GetLastCommittedEntry();
543 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
544}
545
[email protected]8ff00d72012-10-23 19:12:21546WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31547 return delegate_;
548}
549
[email protected]8ff00d72012-10-23 19:12:21550void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31551 // TODO(cbentzel): remove this debugging code?
552 if (delegate == delegate_)
553 return;
554 if (delegate_)
555 delegate_->Detach(this);
556 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08557 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31558 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08559 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00560 if (view_)
561 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08562 }
[email protected]be1f56ab2011-12-22 06:55:31563}
564
[email protected]8ff00d72012-10-23 19:12:21565RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21566 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41567 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16568}
569
[email protected]60eca4eb2013-12-06 00:02:16570RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41571 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16572}
573
[email protected]a86c0e962013-12-17 17:10:39574void WebContentsImpl::ForEachFrame(
575 const base::Callback<void(RenderFrameHost*)>& on_frame) {
576 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
577}
578
579void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
580 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
581 delete message;
582}
583
[email protected]b172aee2012-04-10 17:05:26584RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21585 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31586}
587
[email protected]a04c9d02012-11-14 21:04:34588void WebContentsImpl::GetRenderViewHostAtPosition(
589 int x,
590 int y,
591 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
592 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
593 if (embedder)
594 embedder->GetRenderViewHostAtPosition(x, y, callback);
595 else
596 callback.Run(GetRenderViewHost(), x, y);
597}
598
[email protected]bfcfa692013-02-07 06:17:02599WebContents* WebContentsImpl::GetEmbedderWebContents() const {
600 BrowserPluginGuest* guest = GetBrowserPluginGuest();
601 if (guest)
602 return guest->embedder_web_contents();
603 return NULL;
604}
605
606int WebContentsImpl::GetEmbeddedInstanceID() const {
607 BrowserPluginGuest* guest = GetBrowserPluginGuest();
608 if (guest)
609 return guest->instance_id();
610 return 0;
611}
612
[email protected]6b618e62012-08-16 12:59:18613int WebContentsImpl::GetRoutingID() const {
614 if (!GetRenderViewHost())
615 return MSG_ROUTING_NONE;
616
617 return GetRenderViewHost()->GetRoutingID();
618}
619
[email protected]44470a22013-01-24 01:21:54620int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
621 return fullscreen_widget_routing_id_;
622}
623
[email protected]b172aee2012-04-10 17:05:26624RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21625 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31626}
627
[email protected]f8497342013-02-05 22:15:02628RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
629 BrowserPluginGuest* guest = GetBrowserPluginGuest();
630 if (guest && guest->embedder_web_contents()) {
631 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
632 }
633 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
634}
635
[email protected]4aebbca2013-09-17 22:26:49636RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
637 const {
638 RenderWidgetHost* const widget_host =
639 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
640 GetFullscreenWidgetRoutingID());
641 return widget_host ? widget_host->GetView() : NULL;
642}
643
[email protected]8ff00d72012-10-23 19:12:21644WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31645 return view_.get();
646}
647
[email protected]8ff00d72012-10-23 19:12:21648WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56649 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03650 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
651 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22652 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58653 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22654 web_ui->SetController(controller);
655 return web_ui;
656 }
657
658 delete web_ui;
659 return NULL;
660}
661
[email protected]8ff00d72012-10-23 19:12:21662WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21663 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
664 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31665}
666
[email protected]8ff00d72012-10-23 19:12:21667WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21668 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34669}
670
[email protected]86ef6a392012-05-11 22:03:11671void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22672 if (GetUserAgentOverride() == override)
673 return;
674
675 renderer_preferences_.user_agent_override = override;
676
677 // Send the new override string to the renderer.
678 RenderViewHost* host = GetRenderViewHost();
679 if (host)
680 host->SyncRendererPrefs();
681
682 // Reload the page if a load is currently in progress to avoid having
683 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27684 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22685 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
686 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53687
688 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
689 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11690}
691
692const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22693 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11694}
695
[email protected]2ceee8f2014-01-14 18:02:08696#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41697void WebContentsImpl::SetParentNativeViewAccessible(
698gfx::NativeViewAccessible accessible_parent) {
699 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45700 if (GetRenderViewHost())
701 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41702}
703#endif
704
[email protected]fcf75d42013-12-03 20:11:26705const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55706 // Transient entries take precedence. They are used for interstitial pages
707 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23708 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08709 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21710 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30711 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23712 if (entry) {
[email protected]b5cca982011-05-26 04:42:08713 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23714 }
[email protected]fa944cb82013-11-15 17:51:21715 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
716 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58717 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54718 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32719 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54720 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35721 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26722 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54723 if (!title.empty())
724 return title;
725 }
726 }
727
728 // We use the title for the last committed entry rather than a pending
729 // navigation entry. For example, when the user types in a URL, we want to
730 // keep the old page's title until the new load has committed and we get a new
731 // title.
[email protected]96d185d2009-04-24 03:28:54732 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32733
[email protected]9eeafc012013-11-25 23:49:47734 // We make an exception for initial navigations.
735 if (controller_.IsInitialNavigation()) {
736 // We only want to use the title from the visible entry in one of two cases:
737 // 1. There's already a committed entry for an initial navigation, in which
738 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
739 // 2. The pending entry has been explicitly assigned a title to display.
740 //
741 // If there's no last committed entry and no assigned title, we should fall
742 // back to |page_title_when_no_navigation_entry_| rather than showing the
743 // URL.
744 if (entry ||
745 (controller_.GetVisibleEntry() &&
746 !controller_.GetVisibleEntry()->GetTitle().empty())) {
747 entry = controller_.GetVisibleEntry();
748 }
749 }
[email protected]59167c22013-06-03 18:07:32750
[email protected]45d0ef7f2011-01-05 13:46:23751 if (entry) {
[email protected]b5cca982011-05-26 04:42:08752 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23753 }
[email protected]987fc3a2011-05-26 14:18:09754
755 // |page_title_when_no_navigation_entry_| is finally used
756 // if no title cannot be retrieved.
757 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54758}
759
[email protected]b172aee2012-04-10 17:05:26760int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46761 return GetMaxPageIDForSiteInstance(GetSiteInstance());
762}
763
[email protected]b172aee2012-04-10 17:05:26764int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
765 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33766 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
767 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46768
[email protected]b6583592012-01-25 19:52:33769 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34770}
771
[email protected]b172aee2012-04-10 17:05:26772void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46773 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
774}
775
[email protected]b172aee2012-04-10 17:05:26776void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33777 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46778 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33779 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34780}
781
[email protected]ec6c05f2013-10-23 18:41:57782void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
783 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
784 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57785}
786
[email protected]b172aee2012-04-10 17:05:26787SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21788 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54789}
790
[email protected]b172aee2012-04-10 17:05:26791SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21792 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
793 GetRenderManager()->pending_render_view_host() :
794 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58795 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38796}
797
[email protected]b172aee2012-04-10 17:05:26798bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31799 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49800}
801
[email protected]b172aee2012-04-10 17:05:26802bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31803 return waiting_for_response_;
804}
805
[email protected]b172aee2012-04-10 17:05:26806const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31807 return load_state_;
808}
809
[email protected]fcf75d42013-12-03 20:11:26810const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31811 return load_state_host_;
812}
813
[email protected]b172aee2012-04-10 17:05:26814uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31815 return upload_size_;
816}
817
[email protected]b172aee2012-04-10 17:05:26818uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31819 return upload_position_;
820}
821
[email protected]1ae93fb2013-06-14 03:38:56822std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56823 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39824 frame_tree_.ForEach(base::Bind(&CollectSites,
825 base::Unretained(GetBrowserContext()),
826 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56827 return sites;
828}
829
[email protected]b172aee2012-04-10 17:05:26830const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31831 return encoding_;
832}
833
[email protected]b172aee2012-04-10 17:05:26834bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31835 return displayed_insecure_content_;
836}
837
[email protected]222f5822014-02-05 23:40:49838void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25839 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55840 ++capturer_count_;
841 DVLOG(1) << "There are now " << capturer_count_
842 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49843
844 // Note: This provides a hint to upstream code to size the views optimally
845 // for quality (e.g., to avoid scaling).
846 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
847 preferred_size_for_capture_ = capture_size;
848 OnPreferredSizeChanged(preferred_size_);
849 }
[email protected]54597982013-02-06 01:59:55850}
851
852void WebContentsImpl::DecrementCapturerCount() {
853 --capturer_count_;
854 DVLOG(1) << "There are now " << capturer_count_
855 << " capturing(s) of WebContentsImpl@" << this;
856 DCHECK_LE(0, capturer_count_);
857
[email protected]5a652232013-02-12 06:15:25858 if (is_being_destroyed_)
859 return;
860
[email protected]222f5822014-02-05 23:40:49861 if (capturer_count_ == 0) {
862 const gfx::Size old_size = preferred_size_for_capture_;
863 preferred_size_for_capture_ = gfx::Size();
864 OnPreferredSizeChanged(old_size);
865 }
866
[email protected]1ac10dca2013-08-20 20:47:04867 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55868 DVLOG(1) << "Executing delayed WasHidden().";
869 WasHidden();
870 }
[email protected]be1f56ab2011-12-22 06:55:31871}
872
[email protected]f2bd40812013-07-20 04:30:44873int WebContentsImpl::GetCapturerCount() const {
874 return capturer_count_;
875}
876
[email protected]b172aee2012-04-10 17:05:26877bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31878 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
879 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
880 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49881}
882
[email protected]b172aee2012-04-10 17:05:26883void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
884 int error_code) {
[email protected]443b80e2010-12-14 00:42:23885 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34886 return;
887
[email protected]443b80e2010-12-14 00:42:23888 crashed_status_ = status;
889 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21890 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34891}
892
[email protected]b172aee2012-04-10 17:05:26893base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31894 return crashed_status_;
895}
896
[email protected]b172aee2012-04-10 17:05:26897bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31898 return is_being_destroyed_;
899}
900
[email protected]b172aee2012-04-10 17:05:26901void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34902 if (delegate_)
903 delegate_->NavigationStateChanged(this, changed_flags);
904}
905
[email protected]3e324142012-06-25 18:26:33906base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
907 return last_selected_time_;
908}
909
[email protected]9e2e4632012-07-27 16:38:41910void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54911 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04912 RenderWidgetHostViewPort* rwhv =
913 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16914 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29915 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43916#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16917 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43918#endif
919 }
[email protected]96d185d2009-04-24 03:28:54920
[email protected]5ac20162010-11-24 23:33:11921 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38922
[email protected]b9769d82012-02-10 00:23:59923 // The resize rect might have changed while this was inactive -- send the new
924 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58925 RenderViewHostImpl* rvh =
926 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59927 if (rvh) {
928 rvh->ResizeRectChanged(GetRootWindowResizerRect());
929 }
[email protected]96d185d2009-04-24 03:28:54930
[email protected]c0d9d5672013-10-09 07:38:03931 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
932
[email protected]54597982013-02-06 01:59:55933 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31934}
935
[email protected]b172aee2012-04-10 17:05:26936void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55937 // If there are entities capturing screenshots or video (e.g., mirroring),
938 // don't activate the "disable rendering" optimization.
939 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52940 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55941 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26942 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52943 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33944 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52945 // calls us).
[email protected]c30585c2012-02-16 15:02:04946 RenderWidgetHostViewPort* rwhv =
947 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16948 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29949 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54950 }
951
[email protected]c0d9d5672013-10-09 07:38:03952 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
953
[email protected]54597982013-02-06 01:59:55954 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37955}
956
[email protected]b172aee2012-04-10 17:05:26957bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31958 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27959 return WillNotifyDisconnection() &&
960 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58961 !static_cast<RenderViewHostImpl*>(
962 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31963}
964
[email protected]b172aee2012-04-10 17:05:26965void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:21966 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:40967 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:27968}
969
[email protected]b172aee2012-04-10 17:05:26970WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44971 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:45972 // We pass our own opener so that the cloned page can access it if it was
973 // before.
[email protected]54944cde2012-12-09 09:24:59974 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:45975 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:59976 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:19977 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:22978 FOR_EACH_OBSERVER(WebContentsObserver,
979 observers_,
980 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:27981 return tc;
982}
983
[email protected]14392a52012-05-02 20:28:44984void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:21985 const NotificationSource& source,
986 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:44987 switch (type) {
[email protected]8ff00d72012-10-23 19:12:21988 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
989 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:50990 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
991 i != pending_widget_views_.end(); ++i) {
992 if (host->GetView() == i->second) {
993 pending_widget_views_.erase(i);
994 break;
995 }
996 }
997 break;
998 }
[email protected]14392a52012-05-02 20:28:44999 default:
1000 NOTREACHED();
1001 }
1002}
1003
[email protected]ec6c05f2013-10-23 18:41:571004WebContents* WebContentsImpl::GetWebContents() {
1005 return this;
1006}
1007
[email protected]54944cde2012-12-09 09:24:591008void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211009 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361010 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211011 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431012 should_normally_be_visible_ = !params.initially_hidden;
1013
[email protected]fa944cb82013-11-15 17:51:211014 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041015 params.browser_context, params.site_instance, params.routing_id,
1016 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191017
[email protected]8ff00d72012-10-23 19:12:211018 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191019 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271020 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191021 CHECK(render_view_host_delegate_view_);
1022 } else {
[email protected]f8497342013-02-05 22:15:021023 WebContentsViewDelegate* delegate =
1024 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1025
[email protected]59383c782013-04-17 16:43:271026 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381027 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1028 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021029
[email protected]b5a40842012-11-28 15:26:111030 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381031 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431032 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111033 render_view_host_delegate_view_ = rv;
1034 view_.reset(rv);
1035 } else {
[email protected]f8497342013-02-05 22:15:021036 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111037 view_.reset(CreateWebContentsView(
1038 this, delegate, &render_view_host_delegate_view_));
1039 }
[email protected]d1198fd2012-08-13 22:50:191040 CHECK(render_view_host_delegate_view_);
1041 }
1042 CHECK(view_.get());
1043
[email protected]ed245db2012-12-18 08:00:451044 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591045 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191046
1047 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101048 if (opener_)
1049 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191050
1051 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211052 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1053 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441054#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191055 java_bridge_dispatcher_host_manager_.reset(
1056 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101057 date_time_chooser_.reset(new DateTimeChooserAndroid());
1058#endif
[email protected]d1198fd2012-08-13 22:50:191059}
1060
[email protected]7fff43e2013-05-21 20:21:101061void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1062 RemoveDestructionObserver(web_contents);
1063
[email protected]14392a52012-05-02 20:28:441064 // Clear the opener if it has been closed.
1065 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441066 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511067 return;
[email protected]14392a52012-05-02 20:28:441068 }
[email protected]ceee8cd2013-03-08 04:59:511069 // Clear a pending contents that has been closed before being shown.
1070 for (PendingContents::iterator iter = pending_contents_.begin();
1071 iter != pending_contents_.end();
1072 ++iter) {
1073 if (iter->second != web_contents)
1074 continue;
1075 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511076 return;
1077 }
1078 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441079}
1080
[email protected]7fff43e2013-05-21 20:21:101081void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1082 if (!ContainsKey(destruction_observers_, web_contents)) {
1083 destruction_observers_[web_contents] =
1084 new DestructionObserver(this, web_contents);
1085 }
1086}
1087
1088void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1089 DestructionObservers::iterator iter =
1090 destruction_observers_.find(web_contents);
1091 if (iter != destruction_observers_.end()) {
1092 delete destruction_observers_[web_contents];
1093 destruction_observers_.erase(iter);
1094 }
1095}
1096
[email protected]b172aee2012-04-10 17:05:261097void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311098 observers_.AddObserver(observer);
1099}
1100
[email protected]b172aee2012-04-10 17:05:261101void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311102 observers_.RemoveObserver(observer);
1103}
1104
[email protected]b172aee2012-04-10 17:05:261105void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341106 if (delegate_)
1107 delegate_->ActivateContents(this);
1108}
1109
[email protected]b172aee2012-04-10 17:05:261110void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121111 if (delegate_)
1112 delegate_->DeactivateContents(this);
1113}
1114
[email protected]b172aee2012-04-10 17:05:261115void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481116 if (delegate_)
1117 delegate_->LostCapture();
1118}
1119
[email protected]b24b68a2012-09-24 21:57:261120void WebContentsImpl::RenderWidgetDeleted(
1121 RenderWidgetHostImpl* render_widget_host) {
1122 if (is_being_destroyed_) {
1123 // |created_widgets_| might have been destroyed.
1124 return;
1125 }
1126
1127 std::set<RenderWidgetHostImpl*>::iterator iter =
1128 created_widgets_.find(render_widget_host);
1129 if (iter != created_widgets_.end())
1130 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541131
1132 if (render_widget_host &&
1133 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491134 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1135 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541136 FOR_EACH_OBSERVER(WebContentsObserver,
1137 observers_,
1138 DidDestroyFullscreenWidget(
1139 fullscreen_widget_routing_id_));
1140 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1141 }
[email protected]b24b68a2012-09-24 21:57:261142}
1143
[email protected]b172aee2012-04-10 17:05:261144bool WebContentsImpl::PreHandleKeyboardEvent(
1145 const NativeWebKeyboardEvent& event,
1146 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481147 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131148 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481149}
1150
[email protected]b172aee2012-04-10 17:05:261151void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061152 if (browser_plugin_embedder_ &&
1153 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1154 return;
1155 }
1156
[email protected]63954792011-07-11 04:17:481157 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131158 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481159}
1160
[email protected]fb3f066e2013-02-12 19:12:521161bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461162 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191163#if !defined(OS_MACOSX)
1164 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1165 // isn't done for two reasons:
1166 // -the OS already has a gesture to do this through pinch-zoom
1167 // -if a user starts an inertial scroll, let's go, and presses control
1168 // (i.e. control+tab) then the OS's buffered scroll events will come in
1169 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521170 if (delegate_ &&
1171 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461172 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521173 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1174 return true;
1175 }
[email protected]bccc4472013-04-18 16:37:191176#endif
[email protected]fb3f066e2013-02-12 19:12:521177
1178 return false;
1179}
1180
[email protected]04bce562014-01-30 05:34:541181bool WebContentsImpl::PreHandleGestureEvent(
1182 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031183 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541184}
1185
[email protected]2ceee8f2014-01-14 18:02:081186#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411187gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1188 return accessible_parent_;
1189}
1190#endif
1191
[email protected]b172aee2012-04-10 17:05:261192void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431193 if (delegate_)
1194 delegate_->HandleMouseDown();
1195}
1196
[email protected]b172aee2012-04-10 17:05:261197void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481198 if (delegate_)
1199 delegate_->HandleMouseUp();
1200}
1201
[email protected]590a634e2012-07-19 16:38:231202void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481203 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231204 delegate_->HandlePointerActivate();
1205}
1206
1207void WebContentsImpl::HandleGestureBegin() {
1208 if (delegate_)
1209 delegate_->HandleGestureBegin();
1210}
1211
1212void WebContentsImpl::HandleGestureEnd() {
1213 if (delegate_)
1214 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481215}
1216
[email protected]b172aee2012-04-10 17:05:261217void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491218 // This method is being called to enter or leave renderer-initiated fullscreen
1219 // mode. Either way, make sure any existing fullscreen widget is shut down
1220 // first.
1221 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1222 if (widget_view)
1223 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1224
[email protected]8a5e0ca2011-08-25 06:30:471225 if (delegate_)
1226 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1227}
1228
[email protected]b172aee2012-04-10 17:05:261229bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381230 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121231}
1232
[email protected]a9c81f02012-06-01 00:15:441233void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1234 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371235 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441236 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371237 } else {
1238 GotResponseToLockMouseRequest(false);
1239 }
1240}
1241
[email protected]b172aee2012-04-10 17:05:261242void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371243 if (delegate_)
1244 delegate_->LostMouseLock();
1245}
1246
[email protected]bafe6cd2012-05-23 23:09:501247void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201248 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501249 int route_id,
[email protected]227692c52013-05-31 22:43:041250 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131251 const ViewHostMsg_CreateWindow_Params& params,
1252 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501253 // We usually create the new window in the same BrowsingInstance (group of
1254 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551255 // if the opener is being suppressed (in a non-guest), we create a new
1256 // SiteInstance in its own BrowsingInstance.
1257 bool is_guest = GetRenderProcessHost()->IsGuest();
1258
[email protected]04cbd3d2013-12-04 04:58:201259 // If the opener is to be suppressed, the new window can be in any process.
1260 // Since routing ids are process specific, we must not have one passed in
1261 // as argument here.
1262 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1263
[email protected]bafe6cd2012-05-23 23:09:501264 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551265 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571266 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501267 GetSiteInstance();
1268
[email protected]04cbd3d2013-12-04 04:58:201269 // A message to create a new window can only come from the active process for
1270 // this WebContentsImpl instance. If any other process sends the request,
1271 // it is invalid and the process must be terminated.
1272 if (GetRenderProcessHost()->GetID() != render_process_id) {
1273 base::ProcessHandle process_handle =
1274 RenderProcessHost::FromID(render_process_id)->GetHandle();
1275 if (process_handle != base::kNullProcessHandle) {
1276 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391277 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201278 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1279 }
1280 return;
1281 }
1282
[email protected]d1198fd2012-08-13 22:50:191283 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341284 //
1285 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301286 const std::string& partition_id =
1287 GetContentClient()->browser()->
1288 GetStoragePartitionIdForSite(GetBrowserContext(),
1289 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461290 StoragePartition* partition = BrowserContext::GetStoragePartition(
1291 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411292 DOMStorageContextWrapper* dom_storage_context =
1293 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191294 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1295 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1296 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371297
1298 if (delegate_ &&
1299 !delegate_->ShouldCreateWebContents(this,
1300 route_id,
1301 params.window_container_type,
1302 params.frame_name,
1303 params.target_url,
1304 partition_id,
1305 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011306 if (route_id != MSG_ROUTING_NONE &&
1307 !RenderViewHost::FromID(render_process_id, route_id)) {
1308 // If the embedder didn't create a WebContents for this route, we need to
1309 // delete the RenderView that had already been created.
1310 Send(new ViewMsg_Close(route_id));
1311 }
[email protected]dd6730412013-08-14 15:03:371312 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1313 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1314 main_frame_route_id);
1315 return;
1316 }
1317
1318 // Create the new web contents. This will automatically create the new
1319 // WebContentsView. In the future, we may want to create the view separately.
1320 WebContentsImpl* new_contents =
1321 new WebContentsImpl(GetBrowserContext(),
1322 params.opener_suppressed ? NULL : this);
1323
[email protected]d1198fd2012-08-13 22:50:191324 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301325 partition_id,
[email protected]d1198fd2012-08-13 22:50:191326 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461327 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591328 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041329 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551330 if (!is_guest) {
1331 create_params.context = view_->GetNativeView();
1332 create_params.initial_size = view_->GetContainerSize();
1333 } else {
1334 // This makes |new_contents| act as a guest.
1335 // For more info, see comment above class BrowserPluginGuest.
1336 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1337 WebContentsImpl* new_contents_impl =
1338 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461339 BrowserPluginGuest::CreateWithOpener(instance_id,
1340 new_contents_impl->opener() != NULL,
1341 new_contents_impl,
1342 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551343 }
[email protected]1ac10dca2013-08-20 20:47:041344 if (params.disposition == NEW_BACKGROUND_TAB)
1345 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591346 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191347
[email protected]c4538072013-03-18 02:17:551348 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341349 // will be shown immediately).
1350 if (!params.opener_suppressed) {
1351 if (!is_guest) {
1352 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501353
[email protected]d70bea92013-04-05 04:23:341354 // TODO(brettw): It seems bogus that we have to call this function on the
1355 // newly created object and give it one of its own member variables.
1356 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1357 }
[email protected]bafe6cd2012-05-23 23:09:501358 // Save the created window associated with the route so we can show it
1359 // later.
1360 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1361 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101362 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501363 }
1364
1365 if (delegate_) {
1366 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131367 this, params.opener_frame_id, params.frame_name,
1368 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501369 }
1370
1371 if (params.opener_suppressed) {
1372 // When the opener is suppressed, the original renderer cannot access the
1373 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001374 bool was_blocked = false;
1375 if (delegate_) {
1376 gfx::Rect initial_pos;
1377 delegate_->AddNewContents(
1378 this, new_contents, params.disposition, initial_pos,
1379 params.user_gesture, &was_blocked);
1380 }
1381 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211382 OpenURLParams open_params(params.target_url,
1383 Referrer(),
1384 CURRENT_TAB,
1385 PAGE_TRANSITION_LINK,
1386 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301387 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001388 new_contents->OpenURL(open_params);
1389 }
[email protected]bafe6cd2012-05-23 23:09:501390 }
1391}
1392
[email protected]a8504022013-12-04 20:23:511393void WebContentsImpl::CreateNewWidget(int render_process_id,
1394 int route_id,
[email protected]180ef242013-11-07 06:50:461395 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511396 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501397}
1398
[email protected]a8504022013-12-04 20:23:511399void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1400 int route_id) {
1401 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501402}
1403
[email protected]a8504022013-12-04 20:23:511404void WebContentsImpl::CreateNewWidget(int render_process_id,
1405 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501406 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461407 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211408 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511409 // A message to create a new widget can only come from the active process for
1410 // this WebContentsImpl instance. If any other process sends the request,
1411 // it is invalid and the process must be terminated.
1412 if (process->GetID() != render_process_id) {
1413 base::ProcessHandle process_handle =
1414 RenderProcessHost::FromID(render_process_id)->GetHandle();
1415 if (process_handle != base::kNullProcessHandle) {
1416 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391417 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511418 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1419 }
1420 return;
1421 }
1422
[email protected]bafe6cd2012-05-23 23:09:501423 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041424 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261425 created_widgets_.insert(widget_host);
1426
[email protected]83918ec2013-01-10 15:37:191427 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1428 view_->CreateViewForPopupWidget(widget_host));
1429 if (!widget_view)
1430 return;
[email protected]bafe6cd2012-05-23 23:09:501431 if (!is_fullscreen) {
1432 // Popups should not get activated.
1433 widget_view->SetPopupType(popup_type);
1434 }
1435 // Save the created widget associated with the route so we can show it later.
1436 pending_widget_views_[route_id] = widget_view;
1437
1438#if defined(OS_MACOSX)
1439 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1440 // to allow it to survive the trip without being hosted.
1441 base::mac::NSObjectRetain(widget_view->GetNativeView());
1442#endif
1443}
1444
1445void WebContentsImpl::ShowCreatedWindow(int route_id,
1446 WindowOpenDisposition disposition,
1447 const gfx::Rect& initial_pos,
1448 bool user_gesture) {
1449 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001450 if (contents) {
1451 WebContentsDelegate* delegate = GetDelegate();
1452 if (delegate) {
1453 delegate->AddNewContents(
1454 this, contents, disposition, initial_pos, user_gesture, NULL);
1455 }
1456 }
[email protected]bafe6cd2012-05-23 23:09:501457}
1458
1459void WebContentsImpl::ShowCreatedWidget(int route_id,
1460 const gfx::Rect& initial_pos) {
1461 ShowCreatedWidget(route_id, false, initial_pos);
1462}
1463
1464void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1465 ShowCreatedWidget(route_id, true, gfx::Rect());
1466}
1467
1468void WebContentsImpl::ShowCreatedWidget(int route_id,
1469 bool is_fullscreen,
1470 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501471 RenderWidgetHostViewPort* widget_host_view =
1472 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1473 if (!widget_host_view)
1474 return;
[email protected]4aebbca2013-09-17 22:26:491475 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311476 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1477 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491478 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1479 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1480 delegate_->ToggleFullscreenModeForTab(this, true);
1481 } else {
1482 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491483 }
[email protected]4aebbca2013-09-17 22:26:491484 FOR_EACH_OBSERVER(WebContentsObserver,
1485 observers_,
1486 DidShowFullscreenWidget(route_id));
1487 if (!widget_host_view->HasFocus())
1488 widget_host_view->Focus();
1489 } else {
[email protected]f8497342013-02-05 22:15:021490 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491491 }
[email protected]89054502012-06-03 10:29:241492
1493 RenderWidgetHostImpl* render_widget_host_impl =
1494 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1495 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311496 // Only allow privileged mouse lock for fullscreen render widget, which is
1497 // used to implement Pepper Flash fullscreen.
1498 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501499
1500#if defined(OS_MACOSX)
1501 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1502 // properly embedded (or purposefully ignored) we can release the retain we
1503 // took in CreateNewWidget().
1504 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1505#endif
1506}
1507
1508WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1509 PendingContents::iterator iter = pending_contents_.find(route_id);
1510
1511 // Certain systems can block the creation of new windows. If we didn't succeed
1512 // in creating one, just return NULL.
1513 if (iter == pending_contents_.end()) {
1514 return NULL;
1515 }
1516
1517 WebContentsImpl* new_contents = iter->second;
1518 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101519 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501520
[email protected]d70bea92013-04-05 04:23:341521 // Don't initialize the guest WebContents immediately.
1522 if (new_contents->GetRenderProcessHost()->IsGuest())
1523 return new_contents;
1524
[email protected]bafe6cd2012-05-23 23:09:501525 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1526 !new_contents->GetRenderViewHost()->GetView())
1527 return NULL;
1528
1529 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1530 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1531 return new_contents;
1532}
1533
1534RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1535 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1536 if (iter == pending_widget_views_.end()) {
1537 DCHECK(false);
1538 return NULL;
1539 }
1540
1541 RenderWidgetHostView* widget_host_view = iter->second;
1542 pending_widget_views_.erase(route_id);
1543
1544 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1545 if (!widget_host->GetProcess()->HasConnection()) {
1546 // The view has gone away or the renderer crashed. Nothing to do.
1547 return NULL;
1548 }
1549
1550 return widget_host_view;
1551}
1552
[email protected]f13b4202012-06-12 23:53:231553void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091554 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211555 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231556 if (delegate_)
1557 delegate_->RequestMediaAccessPermission(this, request, callback);
1558 else
[email protected]b5f76742013-04-29 15:05:591559 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231560}
1561
[email protected]cc9200432013-07-23 23:02:401562SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1563 SiteInstance* instance) {
1564 return controller_.GetSessionStorageNamespace(instance);
1565}
1566
[email protected]9b159a52013-10-03 17:24:551567FrameTree* WebContentsImpl::GetFrameTree() {
1568 return &frame_tree_;
1569}
1570
[email protected]edc3af82013-12-12 21:24:071571void WebContentsImpl::OnShowValidationMessage(
1572 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291573 const base::string16& main_text,
1574 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071575 if (delegate_)
1576 delegate_->ShowValidationMessage(
1577 this, anchor_in_root_view, main_text, sub_text);
1578}
1579
1580void WebContentsImpl::OnHideValidationMessage() {
1581 if (delegate_)
1582 delegate_->HideValidationMessage(this);
1583}
1584
1585void WebContentsImpl::OnMoveValidationMessage(
1586 const gfx::Rect& anchor_in_root_view) {
1587 if (delegate_)
1588 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1589}
1590
[email protected]32deec62013-05-15 23:55:041591void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1592 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441593 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041594}
1595
[email protected]b172aee2012-04-10 17:05:261596void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491597 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231598 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491599 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331600}
1601
[email protected]b172aee2012-04-10 17:05:261602void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341603 if (delegate_)
1604 delegate_->ResizeDueToAutoResize(this, new_size);
1605}
1606
[email protected]b172aee2012-04-10 17:05:261607WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201608 if (!delegate_)
1609 return NULL;
[email protected]00c37fc2011-08-02 00:22:501610
[email protected]e5d549d2011-12-28 01:29:201611 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201612 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341613}
1614
[email protected]6b618e62012-08-16 12:59:181615bool WebContentsImpl::Send(IPC::Message* message) {
1616 if (!GetRenderViewHost()) {
1617 delete message;
1618 return false;
1619 }
1620
1621 return GetRenderViewHost()->Send(message);
1622}
1623
[email protected]b172aee2012-04-10 17:05:261624bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501625 NavigationController::ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:201626 return frame_tree_.root()->navigator()->NavigateToPendingEntry(
1627 frame_tree_.GetMainFrame(), reload_type);
[email protected]876bc832010-09-07 16:29:541628}
[email protected]96d185d2009-04-24 03:28:541629
[email protected]a86c0e962013-12-17 17:10:391630void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1631 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441632 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391633 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441634}
1635
[email protected]20ca0382013-02-28 19:50:071636void WebContentsImpl::AttachInterstitialPage(
1637 InterstitialPageImpl* interstitial_page) {
1638 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211639 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291640
1641 // Cancel any visible dialogs so that they don't interfere with the
1642 // interstitial.
1643 if (dialog_manager_)
1644 dialog_manager_->CancelActiveAndPendingDialogs(this);
1645
[email protected]20ca0382013-02-28 19:50:071646 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1647 DidAttachInterstitialPage());
1648}
1649
1650void WebContentsImpl::DetachInterstitialPage() {
1651 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211652 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071653 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1654 DidDetachInterstitialPage());
1655}
1656
[email protected]b172aee2012-04-10 17:05:261657void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331658 const SiteInstance* site_instance,
1659 int history_length,
1660 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411661 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1662 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211663 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191664 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141665 return;
[email protected]9e1ad4b2011-08-14 16:49:191666 }
[email protected]9f76c1e2012-03-05 15:15:581667 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191668 if (!rvh) {
1669 NOTREACHED();
1670 return;
1671 }
[email protected]9f76c1e2012-03-05 15:15:581672 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191673 NOTREACHED();
1674 return;
1675 }
[email protected]6b618e62012-08-16 12:59:181676 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1677 history_length,
1678 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141679}
1680
[email protected]b172aee2012-04-10 17:05:261681void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271682 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211683 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541684 return;
1685 }
[email protected]9f76c1e2012-03-05 15:15:581686 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541687}
1688
[email protected]b172aee2012-04-10 17:05:261689bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211690 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541691}
1692
[email protected]b172aee2012-04-10 17:05:261693InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211694 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221695}
1696
[email protected]b172aee2012-04-10 17:05:261697bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161698 // WebKit creates Document object when MIME type is application/xhtml+xml,
1699 // so we also support this MIME type.
1700 return contents_mime_type_ == "text/html" ||
1701 contents_mime_type_ == "text/xml" ||
1702 contents_mime_type_ == "application/xhtml+xml" ||
1703 contents_mime_type_ == "text/plain" ||
1704 contents_mime_type_ == "text/css" ||
1705 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1706}
1707
[email protected]b172aee2012-04-10 17:05:261708void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591709 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161710 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551711 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011712 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141713 return;
[email protected]c7dd2f62011-07-18 15:57:591714 }
1715
1716 Stop();
1717
1718 // Create the save package and possibly prompt the user for the name to save
1719 // the page as. The user prompt is an asynchronous operation that runs on
1720 // another thread.
1721 save_package_ = new SavePackage(this);
1722 save_package_->GetSaveInfo();
1723}
1724
1725// Used in automated testing to bypass prompting the user for file names.
1726// Instead, the names and paths are hard coded rather than running them through
1727// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341728bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1729 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211730 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591731 // Stop the page from navigating.
1732 Stop();
1733
1734 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211735 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591736}
1737
[email protected]3c71576ce2013-07-23 02:00:011738void WebContentsImpl::SaveFrame(const GURL& url,
1739 const Referrer& referrer) {
1740 if (!GetURL().is_valid())
1741 return;
1742 bool is_main_frame = (url == GetURL());
1743
1744 DownloadManager* dlm =
1745 BrowserContext::GetDownloadManager(GetBrowserContext());
1746 if (!dlm)
1747 return;
1748 int64 post_id = -1;
1749 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271750 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011751 if (entry)
1752 post_id = entry->GetPostID();
1753 }
1754 scoped_ptr<DownloadUrlParameters> params(
1755 DownloadUrlParameters::FromWebContents(this, url));
1756 params->set_referrer(referrer);
1757 params->set_post_id(post_id);
1758 params->set_prefer_cache(true);
1759 if (post_id >= 0)
1760 params->set_method("POST");
1761 params->set_prompt(true);
1762 dlm->DownloadUrl(params.Pass());
1763}
1764
[email protected]b172aee2012-04-10 17:05:261765void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341766 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481767 const base::Callback<void(int64)>& callback) {
1768 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121769}
1770
[email protected]6286a372013-10-09 04:03:271771// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261772bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271773 NavigationEntryImpl* visible_entry =
1774 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1775 return (visible_entry != NULL &&
1776 visible_entry->site_instance() == GetSiteInstance() &&
1777 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321778}
1779
[email protected]b172aee2012-04-10 17:05:261780const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271781 return contents_mime_type_;
1782}
1783
[email protected]b172aee2012-04-10 17:05:261784bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271785 return notify_disconnection_;
1786}
1787
[email protected]b172aee2012-04-10 17:05:261788void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311789 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181790 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161791}
1792
[email protected]b172aee2012-04-10 17:05:261793void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311794 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181795 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161796}
1797
[email protected]8ff00d72012-10-23 19:12:211798RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271799 return &renderer_preferences_;
1800}
1801
[email protected]e35ccd52012-05-23 16:22:471802void WebContentsImpl::Close() {
1803 Close(GetRenderViewHost());
1804}
1805
[email protected]cf200a562013-05-03 16:24:291806void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461807 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291808 if (browser_plugin_embedder_.get())
1809 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1810 screen_x, screen_y, operation);
1811 if (GetRenderViewHost())
1812 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1813 screen_x, screen_y, operation);
1814}
1815
1816void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1817 int screen_x, int screen_y) {
1818 if (browser_plugin_embedder_.get())
1819 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1820 screen_x, screen_y);
1821 if (GetRenderViewHost())
1822 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1823 screen_x, screen_y);
1824}
1825
[email protected]d60f3702013-12-26 16:30:241826void WebContentsImpl::DidGetResourceResponseStart(
1827 const ResourceRequestDetails& details) {
1828 controller_.ssl_manager()->DidStartResourceResponse(details);
1829
1830 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1831 DidGetResourceResponseStart(details));
1832
1833 // TODO(avi): Remove. http://crbug.com/170921
1834 NotificationService::current()->Notify(
1835 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1836 Source<WebContents>(this),
1837 Details<const ResourceRequestDetails>(&details));
1838}
1839
1840void WebContentsImpl::DidGetRedirectForResourceRequest(
1841 RenderViewHost* render_view_host,
1842 const ResourceRedirectDetails& details) {
1843 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1844
1845 FOR_EACH_OBSERVER(
1846 WebContentsObserver,
1847 observers_,
1848 DidGetRedirectForResourceRequest(render_view_host, details));
1849
1850 // TODO(avi): Remove. http://crbug.com/170921
1851 NotificationService::current()->Notify(
1852 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1853 Source<WebContents>(this),
1854 Details<const ResourceRedirectDetails>(&details));
1855}
1856
[email protected]b172aee2012-04-10 17:05:261857void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521858 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581859 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511860 if (delegate_)
1861 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291862 if (browser_plugin_embedder_.get())
1863 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341864}
1865
[email protected]e35ccd52012-05-23 16:22:471866void WebContentsImpl::UserGestureDone() {
1867 OnUserGesture();
1868}
1869
[email protected]b172aee2012-04-10 17:05:261870void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271871 closed_by_user_gesture_ = value;
1872}
1873
[email protected]b172aee2012-04-10 17:05:261874bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271875 return closed_by_user_gesture_;
1876}
1877
[email protected]b172aee2012-04-10 17:05:261878double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051879 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561880 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251881 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171882 return 0;
[email protected]b75b8292010-10-01 07:28:251883
1884 double zoom_level;
1885 if (temporary_zoom_settings_) {
1886 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581887 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251888 } else {
[email protected]2ae88d12011-10-14 09:11:191889 GURL url;
[email protected]6286a372013-10-09 04:03:271890 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191891 // Since zoom map is updated using rewritten URL, use rewritten URL
1892 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271893 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021894 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1895 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251896 }
[email protected]d0b8d092010-10-25 04:05:171897 return zoom_level;
1898}
[email protected]b75b8292010-10-01 07:28:251899
[email protected]b172aee2012-04-10 17:05:261900int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591901 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171902 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011903 // Calculate the zoom percent from the factor. Round up to the nearest whole
1904 // number.
[email protected]b75b8292010-10-01 07:28:251905 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491906 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251907 *enable_decrement = percent > minimum_zoom_percent_;
1908 *enable_increment = percent < maximum_zoom_percent_;
1909 return percent;
1910}
1911
[email protected]b172aee2012-04-10 17:05:261912void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501913 if (!delegate_)
1914 return;
1915
[email protected]6286a372013-10-09 04:03:271916 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1917 if (!entry)
[email protected]1788e772010-12-15 16:40:501918 return;
1919
[email protected]6286a372013-10-09 04:03:271920 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121921}
1922
[email protected]b172aee2012-04-10 17:05:261923void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041924 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271925 if (!delegate_)
1926 return;
1927
[email protected]691aa2f2013-05-28 22:52:041928 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271929}
1930
[email protected]b172aee2012-04-10 17:05:261931int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271932 return minimum_zoom_percent_;
1933}
1934
[email protected]b172aee2012-04-10 17:05:261935int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271936 return maximum_zoom_percent_;
1937}
1938
[email protected]b172aee2012-04-10 17:05:261939gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:491940 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:231941}
1942
[email protected]b172aee2012-04-10 17:05:261943bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271944 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581945 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271946}
1947
[email protected]b172aee2012-04-10 17:05:261948bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441949 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501950}
1951
[email protected]cb805452013-05-22 15:16:211952void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181953 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211954 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201955}
1956
[email protected]cb805452013-05-22 15:16:211957void WebContentsImpl::DidEndColorChooser() {
1958 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1959 color_chooser_identifier_));
1960 color_chooser_.reset();
1961 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201962}
1963
[email protected]41225fe2013-03-29 05:32:021964int WebContentsImpl::DownloadImage(const GURL& url,
1965 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301966 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021967 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391968 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301969 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021970 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391971 return id;
1972}
1973
[email protected]5dcaf8e2013-12-28 01:31:421974bool WebContentsImpl::IsSubframe() const {
1975 return is_subframe_;
1976}
1977
[email protected]9649d492014-01-10 07:15:521978void WebContentsImpl::SetZoomLevel(double level) {
1979 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
1980 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
1981 if (embedder)
1982 embedder->SetZoomLevel(level);
1983}
1984
[email protected]36ec24f2014-01-09 00:32:081985void WebContentsImpl::Find(int request_id,
1986 const base::string16& search_text,
1987 const blink::WebFindOptions& options) {
1988 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
1989}
1990
1991void WebContentsImpl::StopFinding(StopFindAction action) {
1992 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
1993}
1994
[email protected]b172aee2012-04-10 17:05:261995bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:271996 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:201997 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:331998 return true;
1999 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272000}
2001
[email protected]b172aee2012-04-10 17:05:262002void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272003 if (delegate_)
2004 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212005}
2006
[email protected]52913802013-12-10 05:52:182007void WebContentsImpl::DidStartProvisionalLoad(
2008 RenderFrameHostImpl* render_frame_host,
[email protected]54047eb52012-05-08 21:45:572009 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132010 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572011 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182012 const GURL& validated_url,
2013 bool is_error_page,
2014 bool is_iframe_srcdoc) {
2015 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572016 DidChangeLoadProgress(0);
2017
[email protected]0d60f0192011-04-14 12:40:102018 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252019 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132020 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2021 is_main_frame, validated_url, is_error_page,
[email protected]52913802013-12-10 05:52:182022 is_iframe_srcdoc, render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542023
2024 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182025 FOR_EACH_OBSERVER(
2026 WebContentsObserver,
2027 observers_,
2028 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582029 render_frame_host));
[email protected]400992b2012-06-14 00:03:542030 }
2031}
2032
[email protected]3109fbb72014-01-06 23:57:152033void WebContentsImpl::DidFailProvisionalLoadWithError(
2034 RenderFrameHostImpl* render_frame_host,
2035 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2036 GURL validated_url(params.url);
2037 FOR_EACH_OBSERVER(
2038 WebContentsObserver,
2039 observers_,
2040 DidFailProvisionalLoad(params.frame_id,
2041 params.frame_unique_name,
2042 params.is_main_frame,
2043 validated_url,
2044 params.error_code,
2045 params.error_description,
2046 render_frame_host->render_view_host()));
2047}
2048
[email protected]52913802013-12-10 05:52:182049void WebContentsImpl::NotifyChangedNavigationState(
2050 InvalidateTypes changed_flags) {
2051 NotifyNavigationStateChanged(changed_flags);
2052}
2053
[email protected]3691e5cf2014-01-22 10:16:202054void WebContentsImpl::AboutToNavigateRenderFrame(
2055 RenderFrameHostImpl* render_frame_host) {
2056 // Notify observers that we will navigate in this RenderView.
2057 FOR_EACH_OBSERVER(
2058 WebContentsObserver,
2059 observers_,
2060 AboutToNavigateRenderView(render_frame_host->render_view_host()));
2061}
2062
2063void WebContentsImpl::DidStartNavigationToPendingEntry(
2064 RenderFrameHostImpl* render_frame_host,
2065 const GURL& url,
2066 NavigationController::ReloadType reload_type) {
2067 // Notify observers about navigation.
2068 FOR_EACH_OBSERVER(
2069 WebContentsObserver,
2070 observers_,
2071 DidStartNavigationToPendingEntry(url, reload_type));
2072}
2073
[email protected]400992b2012-06-14 00:03:542074void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582075 RenderFrameHostImpl* render_frame_host,
2076 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542077 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582078 FOR_EACH_OBSERVER(
2079 WebContentsObserver,
2080 observers_,
2081 ProvisionalChangeToMainFrameUrl(validated_target_url,
2082 render_frame_host));
[email protected]724159a2010-12-30 01:11:182083}
2084
[email protected]b172aee2012-04-10 17:05:262085void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182086 const GURL& url,
[email protected]70435962011-08-02 20:13:282087 const std::string& security_info,
2088 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182089 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282090 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192091 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182092 cache.Increment();
2093
2094 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082095 int cert_id = 0;
2096 net::CertStatus cert_status = 0;
2097 int security_bits = -1;
2098 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122099 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212100 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122101 &security_bits, &connection_status,
2102 &signed_certificate_timestamp_ids);
2103 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212104 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002105 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2106 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182107
[email protected]b0f724c2013-09-05 04:21:132108 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2109
2110 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2111 DidLoadResourceFromMemoryCache(details));
2112
[email protected]8bfc8272013-09-09 20:10:532113 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2114 scoped_refptr<net::URLRequestContextGetter> request_context(
2115 resource_type == ResourceType::MEDIA ?
2116 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2117 GetRenderProcessHost()->GetID()) :
2118 GetBrowserContext()->GetRequestContextForRenderProcess(
2119 GetRenderProcessHost()->GetID()));
2120 BrowserThread::PostTask(
2121 BrowserThread::IO,
2122 FROM_HERE,
2123 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2124 }
[email protected]724159a2010-12-30 01:11:182125}
2126
[email protected]b172aee2012-04-10 17:05:262127void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392128 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182129 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192130 SSLManager::NotifySSLInternalStateChanged(
2131 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182132}
2133
[email protected]b172aee2012-04-10 17:05:262134void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022135 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582136 LOG(WARNING) << security_origin << " ran insecure content from "
2137 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392138 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412139 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392140 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182141 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412142 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192143 SSLManager::NotifySSLInternalStateChanged(
2144 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182145}
2146
[email protected]b172aee2012-04-10 17:05:262147void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]1d62cf72014-02-07 21:31:572148 CHECK(render_frame_message_source_);
2149 CHECK(!render_view_message_source_);
2150 RenderFrameHostImpl* rfh =
2151 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2152
2153 FOR_EACH_OBSERVER(WebContentsObserver,
2154 observers_,
2155 DocumentLoadedInFrame(frame_id, rfh->render_view_host()));
[email protected]724159a2010-12-30 01:11:182156}
2157
[email protected]b172aee2012-04-10 17:05:262158void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312159 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062160 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312161 bool is_main_frame) {
[email protected]8b3af1e2014-01-24 13:29:122162 if (!render_view_message_source_) {
2163 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2164 GetRenderProcessHost()->ReceivedBadMessage();
2165 return;
2166 }
[email protected]a1b99262013-12-27 21:56:222167
2168 // --site-per-process mode has a short-term hack allowing cross-process
2169 // subframe pages to commit thinking they are top-level. Correct it here to
2170 // avoid confusing the observers.
2171 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2172 render_view_message_source_ != GetRenderViewHost())
2173 is_main_frame = false;
2174
[email protected]8b3af1e2014-01-24 13:29:122175 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442176 RenderProcessHost* render_process_host =
2177 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422178 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252179 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472180 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442181 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312182}
2183
[email protected]b172aee2012-04-10 17:05:262184void WebContentsImpl::OnDidFailLoadWithError(
2185 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062186 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262187 bool is_main_frame,
2188 int error_code,
[email protected]fcf75d42013-12-03 20:11:262189 const base::string16& error_description) {
[email protected]15be9bff2014-01-25 07:19:412190 if (!render_view_message_source_) {
2191 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD3"));
2192 GetRenderProcessHost()->ReceivedBadMessage();
2193 return;
2194 }
[email protected]b502ed462013-01-08 08:20:062195 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442196 RenderProcessHost* render_process_host =
2197 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422198 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252199 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312200 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472201 error_code, error_description,
[email protected]f114fa42013-12-06 17:06:442202 render_view_message_source_));
[email protected]724159a2010-12-30 01:11:182203}
2204
[email protected]b172aee2012-04-10 17:05:262205void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262206 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232207 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252208 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262209 if (!entry)
2210 return;
2211 // Note that we don't call NavigationController::GotToOffset() as we don't
2212 // want to create a pending navigation entry (it might end up lingering
2213 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252214 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212215 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512216 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212217 PAGE_TRANSITION_FORWARD_BACK));
[email protected]3691e5cf2014-01-22 10:16:202218 frame_tree_.root()->navigator()->NavigateToEntry(
2219 frame_tree_.GetMainFrame(),
2220 *entry,
2221 NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572222
2223 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2224 // it in now that we know. This allows us to find the entry when it commits.
2225 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232226 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332227 entry->set_site_instance(
2228 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572229 }
[email protected]216813952011-05-19 22:21:262230 }
2231}
2232
[email protected]b172aee2012-04-10 17:05:262233void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2234 int maximum_percent,
2235 bool remember) {
[email protected]216813952011-05-19 22:21:262236 minimum_zoom_percent_ = minimum_percent;
2237 maximum_zoom_percent_ = maximum_percent;
2238 temporary_zoom_settings_ = !remember;
2239}
2240
[email protected]b172aee2012-04-10 17:05:262241void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342242 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432243 if (!delegate_)
2244 return;
2245
[email protected]b9535422012-02-09 01:47:592246 ChildProcessSecurityPolicyImpl* policy =
2247 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222248 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592249 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212250}
2251
[email protected]b172aee2012-04-10 17:05:262252void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432253 if (delegate_)
2254 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202255}
2256
[email protected]b172aee2012-04-10 17:05:262257void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2258 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262259 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362260 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432261 if (!delegate_)
2262 return;
2263
[email protected]b9535422012-02-09 01:47:592264 ChildProcessSecurityPolicyImpl* policy =
2265 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322266 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592267 return;
[email protected]8f810632013-06-06 22:33:322268
[email protected]3a3b75a2012-06-01 08:38:362269 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202270}
2271
[email protected]b172aee2012-04-10 17:05:262272void WebContentsImpl::OnFindReply(int request_id,
2273 int number_of_matches,
2274 const gfx::Rect& selection_rect,
2275 int active_match_ordinal,
2276 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432277 if (delegate_) {
2278 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2279 active_match_ordinal, final_update);
2280 }
[email protected]b888919c2011-09-02 00:32:162281}
2282
[email protected]59363fc92012-09-05 03:46:312283#if defined(OS_ANDROID)
2284void WebContentsImpl::OnFindMatchRectsReply(
2285 int version,
2286 const std::vector<gfx::RectF>& rects,
2287 const gfx::RectF& active_rect) {
2288 if (delegate_)
2289 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2290}
[email protected]583418cc2013-01-17 14:01:102291
[email protected]1ff427972013-02-07 21:14:072292void WebContentsImpl::OnOpenDateTimeDialog(
2293 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092294 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2295 GetRenderViewHost(),
2296 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132297 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092298 value.minimum,
2299 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172300 value.step,
2301 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102302}
2303
[email protected]a794f3a2013-10-30 17:00:322304void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2305 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442306 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322307}
2308
[email protected]59363fc92012-09-05 03:46:312309#endif
2310
[email protected]f114fa42013-12-06 17:06:442311void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2312 const base::FilePath& path,
2313 bool is_hung) {
2314 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2315
2316 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2317 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2318}
2319
2320void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422321 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442322 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422323 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452324}
2325
[email protected]b172aee2012-04-10 17:05:262326void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2327 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102328 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252329 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102330 AppCacheAccessed(manifest_url, blocked_by_policy));
2331}
2332
[email protected]8bc5ff02013-11-29 06:34:032333void WebContentsImpl::OnOpenColorChooser(
2334 int color_chooser_id,
2335 SkColor color,
2336 const std::vector<ColorSuggestion>& suggestions) {
2337 ColorChooser* new_color_chooser =
2338 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302339 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212340 return;
[email protected]820957a2014-01-14 14:56:302341 if (color_chooser_)
2342 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212343 color_chooser_.reset(new_color_chooser);
2344 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202345}
2346
[email protected]b172aee2012-04-10 17:05:262347void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202348 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212349 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202350 color_chooser_->End();
2351}
2352
[email protected]b172aee2012-04-10 17:05:262353void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322354 SkColor color) {
[email protected]da8543762012-03-20 08:52:202355 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212356 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202357 color_chooser_->SetSelectedColor(color);
2358}
2359
[email protected]d0759f492012-04-19 22:50:502360// This exists for render views that don't have a WebUI, but do have WebUI
2361// bindings enabled.
2362void WebContentsImpl::OnWebUISend(const GURL& source_url,
2363 const std::string& name,
2364 const base::ListValue& args) {
2365 if (delegate_)
2366 delegate_->WebUISend(this, source_url, name, args);
2367}
2368
[email protected]d8415ad92012-08-23 14:40:502369void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442370 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502371 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342372 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162373 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442374 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162375 return;
[email protected]d8415ad92012-08-23 14:40:502376 }
2377
[email protected]8c8fc292012-11-23 18:57:162378 if (!delegate_->RequestPpapiBrokerPermission(
2379 this, url, plugin_path,
2380 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442381 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162382 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442383 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162384 }
[email protected]d8415ad92012-08-23 14:40:502385}
2386
[email protected]ea0309c2013-08-06 19:35:442387void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502388 bool result) {
[email protected]ea0309c2013-08-06 19:35:442389 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502390}
2391
[email protected]c4538072013-03-18 02:17:552392void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372393 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082394 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552395 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392396 // For more info, see comment above classes BrowserPluginEmbedder and
2397 // BrowserPluginGuest.
2398 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142399 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082400 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372401}
2402
[email protected]41225fe2013-03-29 05:32:022403void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392404 int id,
[email protected]749fadd2013-05-15 08:37:482405 int http_status_code,
[email protected]795c28972012-12-06 06:13:392406 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302407 const std::vector<SkBitmap>& bitmaps,
2408 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132409 if (bitmaps.size() != original_bitmap_sizes.size())
2410 return;
2411
[email protected]41225fe2013-03-29 05:32:022412 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2413 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392414 // Currently WebContents notifies us of ANY downloads so that it is
2415 // possible to get here.
2416 return;
2417 }
2418 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302419 iter->second.Run(
2420 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392421 }
[email protected]41225fe2013-03-29 05:32:022422 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392423}
2424
2425void WebContentsImpl::OnUpdateFaviconURL(
2426 int32 page_id,
2427 const std::vector<FaviconURL>& candidates) {
2428 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2429 DidUpdateFaviconURL(page_id, candidates));
2430}
2431
[email protected]1dd0bb752014-02-01 01:16:262432void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2433 bool has_video,
2434 bool has_audio) {
2435// Chrome OS does its own detection of audio and video.
2436#if !defined(OS_CHROMEOS)
2437 scoped_ptr<PowerSaveBlocker> blocker;
2438 if (has_video) {
2439 blocker = PowerSaveBlocker::Create(
2440 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2441#if defined(OS_ANDROID)
2442 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2443 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2444#endif
2445 } else if (has_audio) {
2446 blocker = PowerSaveBlocker::Create(
2447 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2448 }
2449
2450 if (blocker) {
2451 power_save_blockers_[render_view_message_source_][player_cookie] =
2452 blocker.release();
2453 }
2454#endif // !defined(OS_CHROMEOS)
2455}
2456
2457void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062458 // Chrome OS does its own detection of audio and video.
2459#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262460 delete power_save_blockers_[render_view_message_source_][player_cookie];
2461 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062462#endif // !defined(OS_CHROMEOS)
2463}
2464
[email protected]9f268072013-11-07 00:02:152465void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2466 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2467 DidFirstVisuallyNonEmptyPaint(page_id));
2468}
[email protected]d9030b82013-07-19 08:26:062469
[email protected]e67ebf32013-02-13 11:07:192470void WebContentsImpl::DidChangeVisibleSSLState() {
2471 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2472 DidChangeVisibleSSLState());
2473}
2474
[email protected]17e286e2013-03-01 23:29:392475void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2476 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2477 BeforeFormRepostWarningShow());
2478}
2479
[email protected]ec6c05f2013-10-23 18:41:572480
2481void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2482 Activate();
2483 if (delegate_)
2484 delegate_->ShowRepostFormWarningDialog(this);
2485}
2486
[email protected]96d185d2009-04-24 03:28:542487// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592488// loading, or done loading.
2489void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2490 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262491 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542492 if (is_loading == is_loading_)
2493 return;
2494
2495 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262496 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2497 base::string16());
[email protected]96d185d2009-04-24 03:28:542498 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562499 upload_size_ = 0;
2500 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542501 }
2502
[email protected]fa944cb82013-11-15 17:51:212503 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542504
2505 is_loading_ = is_loading;
2506 waiting_for_response_ = is_loading;
2507
[email protected]6ebdc9b2010-09-27 16:55:572508 if (delegate_)
2509 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212510 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542511
[email protected]eab61442013-11-14 18:35:482512 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592513 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482514 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2515 "URL", url);
[email protected]91621872013-10-08 04:04:592516 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2517 DidStartLoading(render_view_host));
2518 } else {
[email protected]eab61442013-11-14 18:35:482519 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2520 "URL", url);
[email protected]91621872013-10-08 04:04:592521 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2522 DidStopLoading(render_view_host));
2523 }
[email protected]66798902013-10-01 18:40:162524
2525 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212526 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2527 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542528 if (details)
[email protected]8ff00d72012-10-23 19:12:212529 det = Details<LoadNotificationDetails>(details);
2530 NotificationService::current()->Notify(
2531 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542532}
2533
[email protected]f17986f482014-02-07 01:50:402534void WebContentsImpl::DidNavigateMainFramePostCommit(
2535 const LoadCommittedDetails& details,
2536 const ViewHostMsg_FrameNavigate_Params& params) {
2537 if (details.is_navigation_to_different_page()) {
2538 // Clear the status bubble. This is a workaround for a bug where WebKit
2539 // doesn't let us know that the cursor left an element during a
2540 // transition (this is also why the mouse cursor remains as a hand after
2541 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2542 // clear the bubble when a user navigates to a named anchor in the same
2543 // page.
2544 UpdateTargetURL(details.entry->GetPageID(), GURL());
2545 }
2546
2547 if (!details.is_in_page) {
2548 // Once the main frame is navigated, we're no longer considered to have
2549 // displayed insecure content.
2550 displayed_insecure_content_ = false;
2551 SSLManager::NotifySSLInternalStateChanged(
2552 GetController().GetBrowserContext());
2553 }
2554
2555 // Notify observers about navigation.
2556 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2557 DidNavigateMainFrame(details, params));
2558}
2559
2560void WebContentsImpl::DidNavigateAnyFramePostCommit(
2561 RenderViewHost* render_view_host,
2562 const LoadCommittedDetails& details,
2563 const ViewHostMsg_FrameNavigate_Params& params) {
2564 // If we navigate off the page, close all JavaScript dialogs.
2565 if (dialog_manager_ && !details.is_in_page)
2566 dialog_manager_->CancelActiveAndPendingDialogs(this);
2567
2568 // Notify observers about navigation.
2569 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2570 DidNavigateAnyFrame(details, params));
2571}
2572
2573bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
2574 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2575 // still be used for a normal web site.
2576 if (url == GURL(kAboutBlankURL))
2577 return false;
2578
2579 // The embedder will then have the opportunity to determine if the URL
2580 // should "use up" the SiteInstance.
2581 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
2582}
2583
[email protected]b172aee2012-04-10 17:05:262584void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462585 // If we are creating a RVH for a restored controller, then we need to make
2586 // sure the RenderView starts with a next_page_id_ larger than the number
2587 // of restored entries. This must be called before the RenderView starts
2588 // navigating (to avoid a race between the browser updating max_page_id and
2589 // the renderer updating next_page_id_). Because of this, we only call this
2590 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562591 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582592 if (max_restored_page_id >
2593 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2594 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2595 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322596}
2597
[email protected]b172aee2012-04-10 17:05:262598bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262599 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322600 // For file URLs without a title, use the pathname instead. In the case of a
2601 // synthesized title, we don't want the update to count toward the "one set
2602 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262603 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322604 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512605 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242606 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322607 explicit_set = false; // Don't count synthetic titles toward the set limit.
2608 } else {
[email protected]acafd272011-07-26 17:35:572609 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322610 explicit_set = true;
2611 }
2612
[email protected]987fc3a2011-05-26 14:18:092613 // If a page is created via window.open and never navigated,
2614 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552615 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092616 if (entry) {
[email protected]36fc0392011-12-25 03:59:512617 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092618 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322619
[email protected]36fc0392011-12-25 03:59:512620 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092621 } else {
2622 if (page_title_when_no_navigation_entry_ == final_title)
2623 return false; // Nothing changed, don't bother.
2624
2625 page_title_when_no_navigation_entry_ = final_title;
2626 }
[email protected]420ae012009-04-24 05:16:322627
[email protected]420ae012009-04-24 05:16:322628 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232629 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322630
[email protected]66798902013-10-01 18:40:162631 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532632 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162633
2634 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212635 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462636 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212637 NotificationService::current()->Notify(
2638 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2639 Source<WebContents>(this),
2640 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042641
[email protected]420ae012009-04-24 05:16:322642 return true;
2643}
2644
[email protected]7b712ee22013-10-03 00:57:282645void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2646 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322647 // After sending out a swap notification, we need to send a disconnect
2648 // notification so that clients that pick up a pointer to |this| can NULL the
2649 // pointer. See Bug 1230284.
2650 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112651 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282652 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112653
2654 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282655 std::pair<RenderViewHost*, RenderViewHost*> details =
2656 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212657 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282658 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212659 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282660 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392661
2662 // Ensure that the associated embedder gets cleared after a RenderViewHost
2663 // gets swapped, so we don't reuse the same embedder next time a
2664 // RenderViewHost is attached to this WebContents.
2665 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322666}
2667
[email protected]da7a7182013-09-06 08:11:112668// TODO(avi): Remove this entire function because this notification is already
2669// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262670void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322671 if (!notify_disconnection_)
2672 return;
2673
2674 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212675 NotificationService::current()->Notify(
2676 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2677 Source<WebContents>(this),
2678 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322679}
2680
[email protected]cbb1ef592013-06-05 19:49:462681void WebContentsImpl::NotifyNavigationEntryCommitted(
2682 const LoadCommittedDetails& load_details) {
2683 FOR_EACH_OBSERVER(
2684 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2685}
2686
[email protected]f114fa42013-12-06 17:06:442687bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2688 const IPC::Message& message) {
2689 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312690}
2691
[email protected]b849847b2013-12-10 21:57:582692void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2693 // Note this is only for subframes, the notification for the main frame
2694 // happens in RenderViewCreated.
2695 FOR_EACH_OBSERVER(WebContentsObserver,
2696 observers_,
2697 RenderFrameCreated(render_frame_host));
2698}
2699
2700void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2701 FOR_EACH_OBSERVER(WebContentsObserver,
2702 observers_,
2703 RenderFrameDeleted(render_frame_host));
2704}
2705
[email protected]a09d53ce2014-01-31 00:46:422706void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302707 if (delegate_)
2708 delegate_->WorkerCrashed(this);
2709}
2710
[email protected]a09d53ce2014-01-31 00:46:422711void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2712 const ContextMenuParams& params) {
2713 // Allow WebContentsDelegates to handle the context menu operation first.
2714 if (delegate_ && delegate_->HandleContextMenu(params))
2715 return;
2716
2717 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2718}
2719
[email protected]a86c0e962013-12-17 17:10:392720WebContents* WebContentsImpl::GetAsWebContents() {
2721 return this;
2722}
2723
[email protected]5a3bdf52012-05-24 15:12:572724RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2725 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322726}
2727
[email protected]8d3347f2009-07-09 22:00:212728RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262729WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212730 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212731}
2732
[email protected]8ff00d72012-10-23 19:12:212733RendererPreferences WebContentsImpl::GetRendererPrefs(
2734 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462735 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512736}
2737
[email protected]b172aee2012-04-10 17:05:262738gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172739 if (delegate_)
2740 return delegate_->GetRootWindowResizerRect();
2741 return gfx::Rect();
2742}
2743
[email protected]7a846df2012-09-20 19:17:392744void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272745 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392746 browser_plugin_embedder_.reset();
2747}
2748
[email protected]b172aee2012-04-10 17:05:262749void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442750 // Don't send notifications if we are just creating a swapped-out RVH for
2751 // the opener chain. These won't be used for view-source or WebUI, so it's
2752 // ok to return early.
[email protected]04c2576d2014-02-07 12:11:582753 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:442754 return;
2755
[email protected]86f98a22013-03-20 14:35:002756 if (delegate_)
2757 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082758
[email protected]8ff00d72012-10-23 19:12:212759 NotificationService::current()->Notify(
2760 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2761 Source<WebContents>(this),
2762 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322763
2764 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352765 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212766 if (GetRenderManager()->pending_web_ui())
2767 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322768
[email protected]6286a372013-10-09 04:03:272769 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332770 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322771 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182772 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582773 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322774 }
[email protected]0666aef2009-05-13 19:48:082775
[email protected]60780f412013-02-25 16:34:102776 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262777
2778 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252779 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582780
2781 // We tell the observers now instead of when the main RenderFrameHostImpl is
2782 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2783 // frame would be dropped because it's not created yet).
2784 RenderFrameHost* main_frame = GetMainFrame();
2785 FOR_EACH_OBSERVER(
2786 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322787}
2788
[email protected]b172aee2012-04-10 17:05:262789void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522790 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322791 // Don't notify the world, since this came from a renderer in the
2792 // background.
2793 return;
2794 }
2795
[email protected]da7a7182013-09-06 08:11:112796 notify_disconnection_ = true;
2797 // TODO(avi): Remove. http://crbug.com/170921
2798 NotificationService::current()->Notify(
2799 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2800 Source<WebContents>(this),
2801 NotificationService::NoDetails());
2802
[email protected]be1f56ab2011-12-22 06:55:312803 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232804 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302805
2806 // Restore the focus to the tab (otherwise the focus will be on the top
2807 // window).
[email protected]484ae5912010-09-29 19:16:142808 if (was_crashed && !FocusLocationBarByDefault() &&
2809 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062810 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142811 }
[email protected]32ded2212011-11-10 18:51:432812
[email protected]d8c660432011-12-22 20:51:252813 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322814}
2815
[email protected]ec6a7eb2013-04-22 17:34:222816void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2817 base::TerminationStatus status,
2818 int error_code) {
[email protected]151a63d2011-12-20 22:32:522819 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322820 // The pending page's RenderViewHost is gone.
2821 return;
2822 }
2823
[email protected]d9030b82013-07-19 08:26:062824 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592825 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322826 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232827 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312828 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322829
[email protected]d8c660432011-12-22 20:51:252830 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272831 observers_,
[email protected]58d5cfe2013-07-10 02:40:522832 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322833}
2834
[email protected]b172aee2012-04-10 17:05:262835void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062836 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212837 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252838 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062839}
2840
[email protected]f17986f482014-02-07 01:50:402841void WebContentsImpl::DidNavigate(
2842 RenderViewHost* rvh,
2843 const ViewHostMsg_FrameNavigate_Params& orig_params) {
2844 ViewHostMsg_FrameNavigate_Params params(orig_params);
2845 bool use_site_per_process =
2846 CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess);
2847 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2848 // First navigation should be a main frame navigation.
2849 // TODO(creis): This DCHECK is currently disabled for --site-per-process
2850 // because cross-process subframe navigations still have a main frame
2851 // PageTransition.
2852 if (!use_site_per_process)
2853 DCHECK(PageTransitionIsMainFrame(params.transition));
2854 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
2855 }
2856
2857 // When using --site-per-process, look up the FrameTreeNode ID that the
2858 // renderer-specific frame ID corresponds to.
2859 int64 frame_tree_node_id = frame_tree_.root()->frame_tree_node_id();
2860 if (use_site_per_process) {
2861 FrameTreeNode* source_node = frame_tree_.FindByFrameID(params.frame_id);
2862 if (source_node)
2863 frame_tree_node_id = source_node->frame_tree_node_id();
2864
2865 // TODO(creis): In the short term, cross-process subframe navigations are
2866 // happening in the pending RenderViewHost's top-level frame. (We need to
2867 // both mirror the frame tree and get the navigation to occur in the correct
2868 // subframe to fix this.) Until then, we should check whether we have a
2869 // pending NavigationEntry with a frame ID and if so, treat the
2870 // cross-process "main frame" navigation as a subframe navigation. This
2871 // limits us to a single cross-process subframe per RVH, and it affects
2872 // NavigateToEntry, NavigatorImpl::DidStartProvisionalLoad, and
2873 // OnDidFinishLoad.
2874 NavigationEntryImpl* pending_entry =
2875 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
2876 int root_ftn_id = frame_tree_.root()->frame_tree_node_id();
2877 if (pending_entry &&
2878 pending_entry->frame_tree_node_id() != -1 &&
2879 pending_entry->frame_tree_node_id() != root_ftn_id) {
2880 params.transition = PAGE_TRANSITION_AUTO_SUBFRAME;
2881 frame_tree_node_id = pending_entry->frame_tree_node_id();
2882 }
2883 }
2884
2885 if (PageTransitionIsMainFrame(params.transition)) {
2886 // When overscroll navigation gesture is enabled, a screenshot of the page
2887 // in its current state is taken so that it can be used during the
2888 // nav-gesture. It is necessary to take the screenshot here, before calling
2889 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
2890 // WebContents::GetRenderViewHost to return the new host, instead of the one
2891 // that may have just been swapped out.
2892 if (delegate_ && delegate_->CanOverscrollContent())
2893 controller_.TakeScreenshot();
2894
2895 if (!use_site_per_process)
2896 GetRenderManager()->DidNavigateMainFrame(rvh);
2897 }
2898
2899 // When using --site-per-process, we notify the RFHM for all navigations,
2900 // not just main frame navigations.
2901 if (use_site_per_process) {
2902 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
2903 // TODO(creis): Rename to DidNavigateFrame.
2904 frame->render_manager()->DidNavigateMainFrame(rvh);
2905 }
2906
2907 // Update the site of the SiteInstance if it doesn't have one yet, unless
2908 // assigning a site is not necessary for this URL. In that case, the
2909 // SiteInstance can still be considered unused until a navigation to a real
2910 // page.
2911 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2912 ShouldAssignSiteForURL(params.url)) {
2913 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
2914 }
2915
2916 // Need to update MIME type here because it's referred to in
2917 // UpdateNavigationCommands() called by RendererDidNavigate() to
2918 // determine whether or not to enable the encoding menu.
2919 // It's updated only for the main frame. For a subframe,
2920 // RenderView::UpdateURL does not set params.contents_mime_type.
2921 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2922 // TODO(jungshik): Add a test for the encoding menu to avoid
2923 // regressing it again.
2924 if (PageTransitionIsMainFrame(params.transition))
2925 contents_mime_type_ = params.contents_mime_type;
2926
2927 LoadCommittedDetails details;
2928 bool did_navigate = controller_.RendererDidNavigate(rvh, params, &details);
2929
2930 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2931 // us estimate our process count for implementing OOP iframes.
2932 // TODO(creis): Remove this when we track which pages commit in each frame.
2933 frame_tree_.SetFrameUrl(params.frame_id, params.url);
2934
2935 // Send notification about committed provisional loads. This notification is
2936 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2937 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2938 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
2939 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2940 // that is not recorded in the navigation history. For the purpose of
2941 // tracking navigation events, we treat this event as a sub frame navigation
2942 // event.
2943 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2944 PageTransition transition_type = params.transition;
2945 // Whether or not a page transition was triggered by going backward or
2946 // forward in the history is only stored in the navigation controller's
2947 // entry list.
2948 if (did_navigate &&
2949 (controller_.GetLastCommittedEntry()->GetTransitionType() &
2950 PAGE_TRANSITION_FORWARD_BACK)) {
2951 transition_type = PageTransitionFromInt(
2952 params.transition | PAGE_TRANSITION_FORWARD_BACK);
2953 }
2954 // Notify observers about the commit of the provisional load.
2955 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2956 DidCommitProvisionalLoadForFrame(
2957 params.frame_id,
2958 params.frame_unique_name,
2959 is_main_frame,
2960 params.url,
2961 transition_type,
2962 rvh));
2963 }
2964
2965 if (!did_navigate)
2966 return; // No navigation happened.
2967
2968 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2969 // for the appropriate notification (best) or you can add it to
2970 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2971 // necessary, please).
2972
2973 // Run post-commit tasks.
2974 if (details.is_main_frame) {
2975 DidNavigateMainFramePostCommit(details, params);
2976 if (delegate_) {
2977 delegate_->DidNavigateMainFramePostCommit(this);
2978 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2979 }
2980 }
2981 DidNavigateAnyFramePostCommit(rvh, details, params);
2982}
2983
[email protected]b172aee2012-04-10 17:05:262984void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2985 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042986 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152987 // Ensure that this state update comes from either the active RVH or one of
2988 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412989 // TODO(nasko): This should go through RenderFrameHost.
2990 // TODO(creis): We can't update state for cross-process subframes until we
2991 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2992 if (rvh != GetRenderViewHost() &&
2993 !GetRenderManager()->IsRVHOnSwappedOutList(
2994 static_cast<RenderViewHostImpl*>(rvh)))
2995 return;
[email protected]420ae012009-04-24 05:16:322996
2997 // We must be prepared to handle state updates for any page, these occur
2998 // when the user is scrolling and entering form data, as well as when we're
2999 // leaving a page, in which case our state may have already been moved to
3000 // the next page. The navigation controller will look up the appropriate
3001 // NavigationEntry and update it when it is notified via the delegate.
3002
3003 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583004 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323005 if (entry_index < 0)
3006 return;
[email protected]10f417c52011-12-28 21:04:233007 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323008
[email protected]691aa2f2013-05-28 22:52:043009 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323010 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043011 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323012 controller_.NotifyEntryChanged(entry, entry_index);
3013}
3014
[email protected]b172aee2012-04-10 17:05:263015void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3016 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263017 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263018 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323019 // If we have a title, that's a pretty good indication that we've started
3020 // getting useful data.
3021 SetNotWaitingForResponse();
3022
[email protected]73eb2602012-02-09 19:50:553023 // Try to find the navigation entry, which might not be the current one.
3024 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233025 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583026 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093027
[email protected]73eb2602012-02-09 19:50:553028 // We can handle title updates when we don't have an entry in
3029 // UpdateTitleForEntry, but only if the update is from the current RVH.
3030 if (!entry && rvh != GetRenderViewHost())
3031 return;
3032
[email protected]a49e10b2011-08-01 23:57:463033 // TODO(evan): make use of title_direction.
3034 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093035 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323036 return;
3037
3038 // Broadcast notifications when the UI should be updated.
3039 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213040 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323041}
3042
[email protected]b172aee2012-04-10 17:05:263043void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3044 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313045 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323046}
3047
[email protected]b172aee2012-04-10 17:05:263048void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513049 if (delegate_)
3050 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323051}
3052
[email protected]b172aee2012-04-10 17:05:263053void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103054#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293055 // The UI may be in an event-tracking loop, such as between the
3056 // mouse-down and mouse-up in text selection or a button click.
3057 // Defer the close until after tracking is complete, so that we
3058 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293059 // TODO(shess): This could get more fine-grained. For instance,
3060 // closing a tab in another window while selecting text in the
3061 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103062 if (view_->IsEventTracking()) {
3063 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293064 return;
3065 }
[email protected]60780f412013-02-25 16:34:103066#endif
[email protected]07707302009-11-06 00:50:293067
[email protected]420ae012009-04-24 05:16:323068 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523069 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513070 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323071}
3072
[email protected]b172aee2012-04-10 17:05:263073void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523074 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513075 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283076
3077 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213078 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573079}
3080
[email protected]b172aee2012-04-10 17:05:263081void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513082 if (delegate_ && delegate_->IsPopupOrPanel(this))
3083 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323084}
3085
[email protected]8ff00d72012-10-23 19:12:213086void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593087 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323088}
3089
[email protected]8ff00d72012-10-23 19:12:213090void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323091 scoped_ptr<LoadNotificationDetails> details;
3092
[email protected]9595fd82013-04-19 21:28:493093 // Use the last committed entry rather than the active one, in case a
3094 // pending entry has been created.
3095 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203096 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493097
[email protected]420ae012009-04-24 05:16:323098 // An entry may not exist for a stop when loading an initial blank page or
3099 // if an iframe injected by script into a blank page finishes loading.
3100 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203101 base::TimeDelta elapsed =
3102 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323103
3104 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513105 entry->GetVirtualURL(),
3106 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323107 elapsed,
3108 &controller_,
3109 controller_.GetCurrentEntryIndex()));
3110 }
3111
[email protected]91621872013-10-08 04:04:593112 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323113}
3114
[email protected]b172aee2012-04-10 17:05:263115void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163116 controller_.DiscardNonCommittedEntries();
3117
3118 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213119 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163120}
3121
[email protected]b172aee2012-04-10 17:05:263122void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513123 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133124 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403125}
3126
[email protected]7cc78902012-12-06 02:32:263127void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393128 if (opener_) {
3129 // Clear our opener so that future cross-process navigations don't have an
3130 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103131 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393132 opener_ = NULL;
3133 }
[email protected]7cc78902012-12-06 02:32:263134
3135 // Notify all swapped out RenderViewHosts for this tab. This is important
3136 // in case we go back to them, or if another window in those processes tries
3137 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213138 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263139}
3140
[email protected]59167c22013-06-03 18:07:323141void WebContentsImpl::DidAccessInitialDocument() {
3142 // Update the URL display.
3143 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3144}
3145
[email protected]87717d0e2012-04-26 02:58:433146void WebContentsImpl::DocumentAvailableInMainFrame(
3147 RenderViewHost* render_view_host) {
3148 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3149 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103150}
3151
[email protected]b172aee2012-04-10 17:05:263152void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083153 RenderViewHost* render_view_host,
3154 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093155 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3156 DocumentOnLoadCompletedInMainFrame(page_id));
3157
3158 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213159 NotificationService::current()->Notify(
3160 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3161 Source<WebContents>(this),
3162 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083163}
3164
[email protected]196159d2012-05-04 17:26:543165void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3166 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213167 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263168 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183169 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523170 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303171 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543172 // If this came from a swapped out RenderViewHost, we only allow the request
3173 // if we are still in the same BrowsingInstance.
[email protected]04c2576d2014-02-07 12:11:583174 if (static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() &&
[email protected]196159d2012-05-04 17:26:543175 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3176 return;
3177 }
3178
[email protected]4ad5d77d2011-12-03 02:00:483179 // Delegate to RequestTransferURL because this is just the generic
3180 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573181 // TODO(creis): Pass the redirect_chain into this method to support client
3182 // redirects. http://crbug.com/311721.
3183 std::vector<GURL> redirect_chain;
3184 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3185 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523186 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483187}
3188
[email protected]b172aee2012-04-10 17:05:263189void WebContentsImpl::RequestTransferURL(
3190 const GURL& url,
[email protected]f8872902013-10-30 03:18:573191 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213192 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573193 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263194 WindowOpenDisposition disposition,
3195 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183196 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523197 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303198 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203199 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123200 GURL dest_url(url);
3201 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553202 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123203 dest_url = GURL(kAboutBlankURL);
3204
[email protected]a1b99262013-12-27 21:56:223205 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3206 int64 frame_tree_node_id = -1;
3207 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3208 source_frame_id != -1) {
3209 FrameTreeNode* source_node = frame_tree_.FindByFrameID(source_frame_id);
3210 if (source_node)
3211 frame_tree_node_id = source_node->frame_tree_node_id();
3212 }
[email protected]c80297782013-11-21 07:10:163213 OpenURLParams params(dest_url, referrer, source_frame_id,
3214 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573215 page_transition, true /* is_renderer_initiated */);
3216 if (redirect_chain.size() > 0)
3217 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553218 params.transferred_global_request_id = old_request_id;
3219 params.should_replace_current_entry = should_replace_current_entry;
3220 params.user_gesture = user_gesture;
3221
[email protected]fa944cb82013-11-15 17:51:213222 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573223 // Web UI pages sometimes want to override the page transition type for
3224 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3225 // automatically generated suggestions). We don't override other types
3226 // like TYPED because they have different implications (e.g., autocomplete).
3227 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213228 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553229
[email protected]e0112912011-02-02 22:54:353230 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163231 // want web sites to see a referrer of "chrome://blah" (and some
3232 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323233 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553234 params.referrer = Referrer();
3235
3236 // Navigations in Web UI pages count as browser-initiated navigations.
3237 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583238 }
[email protected]44d0930a2013-10-28 18:53:553239
3240 new_contents = OpenURL(params);
3241
[email protected]ae5184d62011-10-06 19:25:583242 if (new_contents) {
3243 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253244 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583245 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123246 dest_url,
[email protected]ae5184d62011-10-06 19:25:583247 referrer,
3248 disposition,
[email protected]44d0930a2013-10-28 18:53:553249 params.transition,
[email protected]ae5184d62011-10-06 19:25:583250 source_frame_id));
[email protected]420ae012009-04-24 05:16:323251 }
3252}
3253
[email protected]e1c3a552012-05-04 20:51:323254void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3255 // Tell the active RenderViewHost to run unload handlers and close, as long
3256 // as the request came from a RenderViewHost in the same BrowsingInstance.
3257 // In most cases, we receive this from a swapped out RenderViewHost.
3258 // It is possible to receive it from one that has just been swapped in,
3259 // in which case we might as well deliver the message anyway.
3260 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3261 GetRenderViewHost()->ClosePage();
3262}
3263
[email protected]f546640b2012-05-15 00:03:493264void WebContentsImpl::RouteMessageEvent(
3265 RenderViewHost* rvh,
3266 const ViewMsg_PostMessage_Params& params) {
3267 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363268 // came from a RenderViewHost in the same BrowsingInstance or if this
3269 // WebContents is dedicated to a browser plugin guest.
3270 // Note: This check means that an embedder could theoretically receive a
3271 // postMessage from anyone (not just its own guests). However, this is
3272 // probably not a risk for apps since other pages won't have references
3273 // to App windows.
3274 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3275 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493276 return;
3277
3278 ViewMsg_PostMessage_Params new_params(params);
3279
[email protected]0bc7f3542013-10-21 15:05:533280 if (!params.message_port_ids.empty()) {
3281 MessagePortMessageFilter* message_port_message_filter =
3282 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3283 ->message_port_message_filter();
3284 std::vector<int> new_routing_ids(params.message_port_ids.size());
3285 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3286 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3287 MessagePortService::GetInstance()->UpdateMessagePort(
3288 params.message_port_ids[i],
3289 message_port_message_filter,
3290 new_routing_ids[i]);
3291 }
3292 new_params.new_routing_ids = new_routing_ids;
3293 }
3294
[email protected]f546640b2012-05-15 00:03:493295 // If there is a source_routing_id, translate it to the routing ID for
3296 // the equivalent swapped out RVH in the target process. If we need
3297 // to create a swapped out RVH for the source tab, we create its opener
3298 // chain as well, since those will also be accessible to the target page.
3299 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3300 // Try to look up the WebContents for the source page.
3301 WebContentsImpl* source_contents = NULL;
3302 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3303 rvh->GetProcess()->GetID(), params.source_routing_id);
3304 if (source_rvh) {
3305 source_contents = static_cast<WebContentsImpl*>(
3306 source_rvh->GetDelegate()->GetAsWebContents());
3307 }
3308
3309 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363310 if (GetBrowserPluginGuest()) {
3311 // We create a swapped out RenderView for the embedder in the guest's
3312 // render process but we intentionally do not expose the embedder's
3313 // opener chain to it.
3314 new_params.source_routing_id =
3315 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3316 } else {
3317 new_params.source_routing_id =
3318 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3319 }
[email protected]f546640b2012-05-15 00:03:493320 } else {
3321 // We couldn't find it, so don't pass a source frame.
3322 new_params.source_routing_id = MSG_ROUTING_NONE;
3323 }
3324 }
3325
3326 // In most cases, we receive this from a swapped out RenderViewHost.
3327 // It is possible to receive it from one that has just been swapped in,
3328 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183329 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493330}
3331
[email protected]b172aee2012-04-10 17:05:263332void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343333 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263334 const base::string16& message,
3335 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323336 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213337 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323338 IPC::Message* reply_msg,
3339 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073340 // Suppress JavaScript dialogs when requested. Also suppress messages when
3341 // showing an interstitial as it's shown over the previous page and we don't
3342 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503343 bool suppress_this_message =
[email protected]04c2576d2014-02-07 12:11:583344 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() ||
[email protected]0bfbf882011-12-22 18:19:273345 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073346 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523347 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153348 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323349
3350 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213351 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433352 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153353 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3354 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433355 this,
3356 frame_url.GetOrigin(),
3357 accept_lang,
3358 javascript_message_type,
3359 message,
[email protected]51da7e32012-01-30 19:24:523360 default_prompt,
[email protected]b172aee2012-04-10 17:05:263361 base::Bind(&WebContentsImpl::OnDialogClosed,
3362 base::Unretained(this),
3363 rvh,
3364 reply_msg),
[email protected]51da7e32012-01-30 19:24:523365 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323366 }
[email protected]3ab9cb82011-06-03 18:02:073367
[email protected]6dd2f1e2013-09-11 15:06:013368 *did_suppress_message = suppress_this_message;
3369
[email protected]3ab9cb82011-06-03 18:02:073370 if (suppress_this_message) {
3371 // If we are suppressing messages, just reply as if the user immediately
3372 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263373 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073374 }
3375
[email protected]6dd2f1e2013-09-11 15:06:013376 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3377 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323378}
3379
[email protected]b172aee2012-04-10 17:05:263380void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263381 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263382 bool is_reload,
3383 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583384 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513385 if (delegate_)
3386 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073387
3388 bool suppress_this_message =
[email protected]04c2576d2014-02-07 12:11:583389 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
[email protected]3ab9cb82011-06-03 18:02:073390 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523391 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153392 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153393 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343394 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263395 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503396 return;
3397 }
[email protected]3ab9cb82011-06-03 18:02:073398
[email protected]7ab1e7d62009-10-14 23:32:013399 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153400 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3401 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323402 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263403 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523404 reply_msg));
[email protected]420ae012009-04-24 05:16:323405}
3406
[email protected]a796f202012-05-30 14:14:253407bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263408 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253409 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263410 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253411 if (!delegate_)
3412 return false;
3413 return delegate_->AddMessageToConsole(this, level, message, line_no,
3414 source_id);
3415}
3416
[email protected]b172aee2012-04-10 17:05:263417WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273418 // We want to base the page config off of the actual URL, rather than the
3419 // virtual URL.
3420 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3421 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003422 GURL url = controller_.GetActiveEntry()
3423 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153424
[email protected]fa944cb82013-11-15 17:51:213425 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323426}
3427
[email protected]0eba810b2012-10-18 03:19:363428int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213429 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413430 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3431 true, true);
[email protected]0eba810b2012-10-18 03:19:363432}
3433
[email protected]b172aee2012-04-10 17:05:263434void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273435 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253436 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223437
[email protected]ea114722012-03-12 01:11:253438 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173439 if (rdh) // NULL in unittests.
3440 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253441}
3442
[email protected]b172aee2012-04-10 17:05:263443void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443444 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253445 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443446}
3447
[email protected]b172aee2012-04-10 17:05:263448void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563449 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263450 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153451 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523452 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153453 return;
3454
[email protected]9f76c1e2012-03-05 15:15:583455 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3456
[email protected]e5fc1632011-08-08 07:51:533457 // Ignore renderer unresponsive event if debugger is attached to the tab
3458 // since the event may be a result of the renderer sitting on a breakpoint.
3459 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363460 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533461 return;
3462
[email protected]2e9d79f2013-08-16 05:45:563463 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323464 // Hang occurred while firing the beforeunload/unload handler.
3465 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583466 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323467
[email protected]fa944cb82013-11-15 17:51:213468 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323469 return;
3470
3471 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563472 // nothing we can do to recover. If the hang is in the beforeunload handler,
3473 // pretend the beforeunload listeners have all fired and allow the delegate
3474 // to continue closing; the user will not have the option of cancelling the
3475 // close. Otherwise, pretend the unload listeners have all fired and close
3476 // the tab.
3477 bool close = true;
3478 if (is_during_beforeunload) {
3479 delegate_->BeforeUnloadFired(this, true, &close);
3480 }
3481 if (close)
3482 Close(rvh);
[email protected]420ae012009-04-24 05:16:323483 return;
3484 }
3485
[email protected]9f76c1e2012-03-05 15:15:583486 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473487 return;
3488
[email protected]6934a702011-12-20 00:04:513489 if (delegate_)
3490 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323491}
3492
[email protected]b172aee2012-04-10 17:05:263493void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513494 if (delegate_)
3495 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323496}
3497
[email protected]b172aee2012-04-10 17:05:263498void WebContentsImpl::LoadStateChanged(
3499 const GURL& url,
3500 const net::LoadStateWithParam& load_state,
3501 uint64 upload_position,
3502 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323503 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563504 upload_position_ = upload_position;
3505 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503506 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213507 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303508 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213509 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323510 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463511 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213512 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463513 }
[email protected]420ae012009-04-24 05:16:323514}
3515
[email protected]b172aee2012-04-10 17:05:263516void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553517 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323518 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123519 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3520 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513521 if (delegate_)
3522 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093523 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323524}
3525
[email protected]58d5cfe2013-07-10 02:40:523526void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543527 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233528 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223529 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543530}
3531
[email protected]b172aee2012-04-10 17:05:263532void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103533 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213534 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263535 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3536 // here during container initialization and normal window size will be set
3537 // later. In case of tab duplication this resizing to 0x0 prevents setting
3538 // normal size later so just ignore it.
3539 if (!size.IsEmpty())
3540 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323541}
3542
[email protected]af905902013-10-01 21:38:513543void WebContentsImpl::CancelModalDialogsForRenderManager() {
3544 // We need to cancel modal dialogs when doing a process swap, since the load
3545 // deferrer would prevent us from swapping out.
3546 if (dialog_manager_)
3547 dialog_manager_->CancelActiveAndPendingDialogs(this);
3548}
3549
[email protected]7b712ee22013-10-03 00:57:283550void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3551 RenderViewHost* new_host) {
3552 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083553
3554 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003555 if (delegate_)
3556 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393557
[email protected]7b712ee22013-10-03 00:57:283558 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543559}
3560
[email protected]14392a52012-05-02 20:28:443561int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3562 SiteInstance* instance) {
3563 if (!opener_)
3564 return MSG_ROUTING_NONE;
3565
3566 // Recursively create RenderViews for anything else in the opener chain.
3567 return opener_->CreateOpenerRenderViews(instance);
3568}
3569
3570int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3571 int opener_route_id = MSG_ROUTING_NONE;
3572
3573 // If this tab has an opener, ensure it has a RenderView in the given
3574 // SiteInstance as well.
3575 if (opener_)
3576 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3577
[email protected]45a22ad2013-02-21 03:25:003578 // If any of the renderers (current, pending, or swapped out) for this
3579 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213580 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3581 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373582
[email protected]fa944cb82013-11-15 17:51:213583 if (GetRenderManager()->pending_render_view_host() &&
3584 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3585 instance)
3586 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003587
[email protected]fa944cb82013-11-15 17:51:213588 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373589 instance);
3590 if (rvh)
3591 return rvh->GetRoutingID();
3592
[email protected]14392a52012-05-02 20:28:443593 // Create a swapped out RenderView in the given SiteInstance if none exists,
3594 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413595 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3596 true, true);
[email protected]14392a52012-05-02 20:28:443597}
3598
[email protected]b172aee2012-04-10 17:05:263599NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193600 return GetController();
[email protected]3a3d47472010-07-15 21:03:543601}
3602
[email protected]b172aee2012-04-10 17:05:263603WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563604 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323605}
3606
[email protected]10f417c52011-12-28 21:04:233607NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263608 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323609 return controller_.GetLastCommittedEntry();
3610}
3611
[email protected]b172aee2012-04-10 17:05:263612bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163613 RenderViewHost* render_view_host,
3614 int opener_route_id,
3615 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033616 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443617 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163618 RenderWidgetHostView* rwh_view;
3619 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3620 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3621 // case this because RWH is still a base class of RenderViewHost, and child
3622 // frame RWHVs are unique in that they do not have their own WebContents.
3623 if (frame_connector) {
3624 RenderWidgetHostViewChildFrame* rwh_view_child =
3625 new RenderWidgetHostViewChildFrame(render_view_host);
3626 frame_connector->set_view(rwh_view_child);
3627 rwh_view = rwh_view_child;
3628 } else {
3629 rwh_view = view_->CreateViewForWidget(render_view_host);
3630 }
[email protected]1a98a932009-11-17 00:12:523631
[email protected]420ae012009-04-24 05:16:323632 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443633 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213634 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323635
[email protected]74ce1ad2011-12-16 21:51:463636 // Make sure we use the correct starting page_id in the new RenderView.
3637 UpdateMaxPageIDIfNecessary(render_view_host);
3638 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583639 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463640
[email protected]9f76c1e2012-03-05 15:15:583641 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263642 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493643 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133644 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523645 return false;
[email protected]14392a52012-05-02 20:28:443646 }
[email protected]a4127722011-04-27 23:13:523647
[email protected]a220b5932013-09-21 03:47:443648#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503649 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3650 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443651 if (rwh_view) {
3652 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3653 render_widget_host->WasResized();
3654 }
[email protected]f8233cc2011-05-31 20:24:503655#endif
3656
[email protected]420ae012009-04-24 05:16:323657 return true;
3658}
3659
[email protected]7d244f12013-08-22 21:41:513660#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183661base::android::ScopedJavaLocalRef<jobject>
3662WebContentsImpl::GetJavaWebContents() {
3663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3664
3665 WebContentsAndroid* web_contents_android =
3666 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3667 if (!web_contents_android) {
3668 web_contents_android = new WebContentsAndroid(this);
3669 SetUserData(kWebContentsAndroidKey, web_contents_android);
3670 }
3671 return web_contents_android->GetJavaObject();
3672}
3673
[email protected]7d244f12013-08-22 21:41:513674bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3675 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163676 MSG_ROUTING_NONE,
3677 NULL);
[email protected]7d244f12013-08-22 21:41:513678}
3679#endif
3680
[email protected]b172aee2012-04-10 17:05:263681void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3682 IPC::Message* reply_msg,
3683 bool success,
[email protected]fcf75d42013-12-03 20:11:263684 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543685 if (is_showing_before_unload_dialog_ && !success) {
3686 // If a beforeunload dialog is canceled, we need to stop the throbber from
3687 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293688 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353689 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103690
[email protected]6d65a462013-06-21 21:29:123691 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3692 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543693 }
3694 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583695 static_cast<RenderViewHostImpl*>(
3696 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543697}
3698
[email protected]b172aee2012-04-10 17:05:263699void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213700 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123701 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103702}
[email protected]f45d2a72010-03-08 23:28:353703
[email protected]b172aee2012-04-10 17:05:263704void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103705 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443706 // Can be NULL during tests.
3707 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213708 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363709}
[email protected]9f76c1e2012-03-05 15:15:583710
[email protected]1ac10dca2013-08-20 20:47:043711bool WebContentsImpl::IsHidden() {
3712 return capturer_count_ == 0 && !should_normally_be_visible_;
3713}
3714
[email protected]b0936d22013-11-28 06:47:363715RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213716 return frame_tree_.root()->render_manager();
3717}
3718
[email protected]b172aee2012-04-10 17:05:263719RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583720 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3721}
[email protected]7900bfdb2012-05-24 19:31:243722
[email protected]f8497342013-02-05 22:15:023723BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393724 return browser_plugin_guest_.get();
3725}
3726
[email protected]738f57a2013-06-29 21:06:543727void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3728 CHECK(!browser_plugin_guest_);
3729 browser_plugin_guest_.reset(guest);
3730}
3731
[email protected]f8497342013-02-05 22:15:023732BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393733 return browser_plugin_embedder_.get();
3734}
[email protected]8ff00d72012-10-23 19:12:213735
[email protected]8eb04562013-03-06 03:41:143736BrowserPluginGuestManager*
3737 WebContentsImpl::GetBrowserPluginGuestManager() const {
3738 return static_cast<BrowserPluginGuestManager*>(
3739 GetBrowserContext()->GetUserData(
3740 browser_plugin::kBrowserPluginGuestManagerKeyName));
3741}
3742
[email protected]d9030b82013-07-19 08:26:063743void WebContentsImpl::ClearPowerSaveBlockers(
3744 RenderViewHost* render_view_host) {
3745 STLDeleteValues(&power_save_blockers_[render_view_host]);
3746 power_save_blockers_.erase(render_view_host);
3747}
3748
3749void WebContentsImpl::ClearAllPowerSaveBlockers() {
3750 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3751 i != power_save_blockers_.end(); ++i)
3752 STLDeleteValues(&power_save_blockers_[i->first]);
3753 power_save_blockers_.clear();
3754}
3755
[email protected]dc0fd432013-08-27 15:29:213756gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3757 gfx::Size size;
3758 if (delegate_)
3759 size = delegate_->GetSizeForNewRenderView(this);
3760 if (size.IsEmpty())
3761 size = view_->GetContainerSize();
3762 return size;
3763}
3764
[email protected]9b159a52013-10-03 17:24:553765void WebContentsImpl::OnFrameRemoved(
3766 RenderViewHostImpl* render_view_host,
3767 int64 frame_id) {
3768 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3769 FrameDetached(render_view_host, frame_id));
3770}
3771
[email protected]222f5822014-02-05 23:40:493772void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3773 if (!delegate_)
3774 return;
3775 const gfx::Size new_size = GetPreferredSize();
3776 if (new_size != old_size)
3777 delegate_->UpdatePreferredSize(this, new_size);
3778}
3779
[email protected]8ff00d72012-10-23 19:12:213780} // namespace content