blob: 6d3609f72ccf3f7e3ce86c258ea5c9abfe250fb4 [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]9a890452014-02-13 22:21:02311 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38312 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21313 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
314 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00315 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21316 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44317 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42318 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
319 is_subframe_(false) {
[email protected]cbb1ef592013-06-05 19:49:46320 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
321 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55322 frame_tree_.SetFrameRemoveListener(
323 base::Bind(&WebContentsImpl::OnFrameRemoved,
324 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35325}
initial.commit09911bf2008-07-26 23:55:29326
[email protected]b172aee2012-04-10 17:05:26327WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32328 is_being_destroyed_ = true;
329
[email protected]21b41c7e892014-02-28 01:52:24330 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
331 // shutdown and be deleted as well.
332 frame_tree_.ForEach(
333 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
334
[email protected]d9030b82013-07-19 08:26:06335 ClearAllPowerSaveBlockers();
336
[email protected]b24b68a2012-09-24 21:57:26337 for (std::set<RenderWidgetHostImpl*>::iterator iter =
338 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
339 (*iter)->DetachDelegate();
340 }
341 created_widgets_.clear();
342
[email protected]3ab9cb82011-06-03 18:02:07343 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15344 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11345 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07346
[email protected]da8543762012-03-20 08:52:20347 if (color_chooser_)
348 color_chooser_->End();
349
[email protected]420ae012009-04-24 05:16:32350 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32351
[email protected]ca13a442012-04-17 14:00:12352 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21353 NotificationService::current()->Notify(
354 NOTIFICATION_WEB_CONTENTS_DESTROYED,
355 Source<WebContents>(this),
356 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32357
[email protected]fa944cb82013-11-15 17:51:21358 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27359 if (pending_rvh) {
360 FOR_EACH_OBSERVER(WebContentsObserver,
361 observers_,
362 RenderViewDeleted(pending_rvh));
363 }
364
365 FOR_EACH_OBSERVER(WebContentsObserver,
366 observers_,
[email protected]fa944cb82013-11-15 17:51:21367 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27368
[email protected]2db9bd72012-04-13 20:20:56369 FOR_EACH_OBSERVER(WebContentsObserver,
370 observers_,
371 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08372
[email protected]6934a702011-12-20 00:04:51373 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10374
375 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
376 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42377}
378
[email protected]d1198fd2012-08-13 22:50:19379WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59380 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19381 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03382 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59383 WebContentsImpl* new_contents = new WebContentsImpl(
384 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19385
[email protected]54944cde2012-12-09 09:24:59386 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19387 return new_contents;
388}
389
[email protected]b371a5652013-02-20 11:25:51390// static
[email protected]8eb04562013-03-06 03:41:14391BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36392 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53393 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54394 int guest_instance_id,
395 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39396 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39397
398 // This makes |new_contents| act as a guest.
399 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54400 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19401 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11402
[email protected]3de10bb32013-01-08 21:57:33403 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33404 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11405
[email protected]216be772013-01-25 00:22:27406 // We are instantiating a WebContents for browser plugin. Set its subframe bit
407 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42408 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27409
[email protected]8eb04562013-03-06 03:41:14410 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39411}
412
[email protected]b0936d22013-11-28 06:47:36413RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21414 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28415}
416
[email protected]7bb761892012-07-20 09:32:47417bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
418 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44419 return OnMessageReceived(render_view_host, NULL, message);
420}
421
422bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
423 RenderFrameHost* render_frame_host,
424 const IPC::Message& message) {
425 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56426 if (GetWebUI() &&
427 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17428 return true;
[email protected]d2353452012-01-19 19:53:56429 }
[email protected]f82d57b52011-04-27 19:13:17430
[email protected]d8c660432011-12-22 20:51:25431 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
432 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10433 while ((observer = it.GetNext()) != NULL)
434 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53435 return true;
[email protected]403415a2011-01-10 18:57:53436
[email protected]1d62cf72014-02-07 21:31:57437 // Message handlers should be aware of which
438 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
439 // stored in render_(view|frame)_message_source_.
440 if (render_frame_host)
441 render_frame_message_source_ = render_frame_host;
442 else
443 render_view_message_source_ = render_view_host;
444
[email protected]724159a2010-12-30 01:11:18445 bool handled = true;
446 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26447 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44448 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
449 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40450 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
451 OnDomOperationResponse)
[email protected]724159a2010-12-30 01:11:18452 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
453 OnDidLoadResourceFromMemoryCache)
454 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
455 OnDidDisplayInsecureContent)
456 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
457 OnDidRunInsecureContent)
[email protected]1d62cf72014-02-07 21:31:57458 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
[email protected]724159a2010-12-30 01:11:18459 OnDocumentLoadedInFrame)
460 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]7d472472011-01-22 01:30:25461 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26462 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21463 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20464 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
465 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
466 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16467 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10468 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20469 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
470 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
471 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
472 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50473 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50474 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
475 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55476 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
477 OnBrowserPluginMessage(message))
478 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
479 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02480 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
481 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10482#if defined(OS_ANDROID)
483 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
484 OnFindMatchRectsReply)
485 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
486 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32487 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
488 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10489#endif
[email protected]1dd0bb752014-02-01 01:16:26490 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
491 OnMediaPlayingNotification)
492 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
493 OnMediaPausedNotification)
[email protected]9f268072013-11-07 00:02:15494 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
495 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07496 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
497 OnShowValidationMessage)
498 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
499 OnHideValidationMessage)
500 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
501 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18502 IPC_MESSAGE_UNHANDLED(handled = false)
503 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44504 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57505 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18506
507 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39508 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18509 GetRenderProcessHost()->ReceivedBadMessage();
510 }
511
512 return handled;
513}
514
[email protected]b172aee2012-04-10 17:05:26515void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18516 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21517 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43518 if (delegate_)
519 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18520}
521
[email protected]d1198fd2012-08-13 22:50:19522NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56523 return controller_;
524}
525
[email protected]d1198fd2012-08-13 22:50:19526const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56527 return controller_;
528}
529
[email protected]8ff00d72012-10-23 19:12:21530BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55531 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30532}
533
[email protected]b172aee2012-04-10 17:05:26534const GURL& WebContentsImpl::GetURL() 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]36fc0392011-12-25 03:59:51537 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31538}
539
[email protected]a093ce02013-07-22 20:53:14540const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24541 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32542 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24543 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
544}
545
546const GURL& WebContentsImpl::GetLastCommittedURL() const {
547 // We may not have a navigation entry yet.
548 NavigationEntry* entry = controller_.GetLastCommittedEntry();
549 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
550}
551
[email protected]8ff00d72012-10-23 19:12:21552WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31553 return delegate_;
554}
555
[email protected]8ff00d72012-10-23 19:12:21556void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31557 // TODO(cbentzel): remove this debugging code?
558 if (delegate == delegate_)
559 return;
560 if (delegate_)
561 delegate_->Detach(this);
562 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08563 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31564 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08565 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00566 if (view_)
567 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08568 }
[email protected]be1f56ab2011-12-22 06:55:31569}
570
[email protected]8ff00d72012-10-23 19:12:21571RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21572 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41573 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16574}
575
[email protected]60eca4eb2013-12-06 00:02:16576RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41577 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16578}
579
[email protected]a86c0e962013-12-17 17:10:39580void WebContentsImpl::ForEachFrame(
581 const base::Callback<void(RenderFrameHost*)>& on_frame) {
582 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
583}
584
585void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
586 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
587 delete message;
588}
589
[email protected]b172aee2012-04-10 17:05:26590RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21591 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31592}
593
[email protected]a04c9d02012-11-14 21:04:34594void WebContentsImpl::GetRenderViewHostAtPosition(
595 int x,
596 int y,
597 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
598 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
599 if (embedder)
600 embedder->GetRenderViewHostAtPosition(x, y, callback);
601 else
602 callback.Run(GetRenderViewHost(), x, y);
603}
604
[email protected]bfcfa692013-02-07 06:17:02605WebContents* WebContentsImpl::GetEmbedderWebContents() const {
606 BrowserPluginGuest* guest = GetBrowserPluginGuest();
607 if (guest)
608 return guest->embedder_web_contents();
609 return NULL;
610}
611
612int WebContentsImpl::GetEmbeddedInstanceID() const {
613 BrowserPluginGuest* guest = GetBrowserPluginGuest();
614 if (guest)
615 return guest->instance_id();
616 return 0;
617}
618
[email protected]6b618e62012-08-16 12:59:18619int WebContentsImpl::GetRoutingID() const {
620 if (!GetRenderViewHost())
621 return MSG_ROUTING_NONE;
622
623 return GetRenderViewHost()->GetRoutingID();
624}
625
[email protected]44470a22013-01-24 01:21:54626int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
627 return fullscreen_widget_routing_id_;
628}
629
[email protected]b172aee2012-04-10 17:05:26630RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21631 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31632}
633
[email protected]f8497342013-02-05 22:15:02634RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
635 BrowserPluginGuest* guest = GetBrowserPluginGuest();
636 if (guest && guest->embedder_web_contents()) {
637 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
638 }
639 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
640}
641
[email protected]4aebbca2013-09-17 22:26:49642RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
643 const {
644 RenderWidgetHost* const widget_host =
645 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
646 GetFullscreenWidgetRoutingID());
647 return widget_host ? widget_host->GetView() : NULL;
648}
649
[email protected]8ff00d72012-10-23 19:12:21650WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31651 return view_.get();
652}
653
[email protected]8ff00d72012-10-23 19:12:21654WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56655 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03656 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
657 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22658 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58659 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22660 web_ui->SetController(controller);
661 return web_ui;
662 }
663
664 delete web_ui;
665 return NULL;
666}
667
[email protected]8ff00d72012-10-23 19:12:21668WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21669 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
670 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31671}
672
[email protected]8ff00d72012-10-23 19:12:21673WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21674 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34675}
676
[email protected]86ef6a392012-05-11 22:03:11677void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22678 if (GetUserAgentOverride() == override)
679 return;
680
681 renderer_preferences_.user_agent_override = override;
682
683 // Send the new override string to the renderer.
684 RenderViewHost* host = GetRenderViewHost();
685 if (host)
686 host->SyncRendererPrefs();
687
688 // Reload the page if a load is currently in progress to avoid having
689 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27690 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22691 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
692 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53693
694 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
695 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11696}
697
698const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22699 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11700}
701
[email protected]2ceee8f2014-01-14 18:02:08702#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41703void WebContentsImpl::SetParentNativeViewAccessible(
704gfx::NativeViewAccessible accessible_parent) {
705 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45706 if (GetRenderViewHost())
707 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41708}
709#endif
710
[email protected]fcf75d42013-12-03 20:11:26711const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55712 // Transient entries take precedence. They are used for interstitial pages
713 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23714 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08715 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21716 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30717 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23718 if (entry) {
[email protected]b5cca982011-05-26 04:42:08719 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23720 }
[email protected]fa944cb82013-11-15 17:51:21721 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
722 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58723 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54724 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32725 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54726 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35727 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26728 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54729 if (!title.empty())
730 return title;
731 }
732 }
733
734 // We use the title for the last committed entry rather than a pending
735 // navigation entry. For example, when the user types in a URL, we want to
736 // keep the old page's title until the new load has committed and we get a new
737 // title.
[email protected]96d185d2009-04-24 03:28:54738 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32739
[email protected]9eeafc012013-11-25 23:49:47740 // We make an exception for initial navigations.
741 if (controller_.IsInitialNavigation()) {
742 // We only want to use the title from the visible entry in one of two cases:
743 // 1. There's already a committed entry for an initial navigation, in which
744 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
745 // 2. The pending entry has been explicitly assigned a title to display.
746 //
747 // If there's no last committed entry and no assigned title, we should fall
748 // back to |page_title_when_no_navigation_entry_| rather than showing the
749 // URL.
750 if (entry ||
751 (controller_.GetVisibleEntry() &&
752 !controller_.GetVisibleEntry()->GetTitle().empty())) {
753 entry = controller_.GetVisibleEntry();
754 }
755 }
[email protected]59167c22013-06-03 18:07:32756
[email protected]45d0ef7f2011-01-05 13:46:23757 if (entry) {
[email protected]b5cca982011-05-26 04:42:08758 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23759 }
[email protected]987fc3a2011-05-26 14:18:09760
761 // |page_title_when_no_navigation_entry_| is finally used
762 // if no title cannot be retrieved.
763 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54764}
765
[email protected]b172aee2012-04-10 17:05:26766int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46767 return GetMaxPageIDForSiteInstance(GetSiteInstance());
768}
769
[email protected]b172aee2012-04-10 17:05:26770int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
771 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33772 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
773 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46774
[email protected]b6583592012-01-25 19:52:33775 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34776}
777
[email protected]b172aee2012-04-10 17:05:26778void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46779 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
780}
781
[email protected]b172aee2012-04-10 17:05:26782void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33783 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46784 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33785 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34786}
787
[email protected]ec6c05f2013-10-23 18:41:57788void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
789 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
790 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57791}
792
[email protected]b172aee2012-04-10 17:05:26793SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21794 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54795}
796
[email protected]b172aee2012-04-10 17:05:26797SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21798 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
799 GetRenderManager()->pending_render_view_host() :
800 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58801 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38802}
803
[email protected]b172aee2012-04-10 17:05:26804bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31805 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49806}
807
[email protected]b172aee2012-04-10 17:05:26808bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31809 return waiting_for_response_;
810}
811
[email protected]b172aee2012-04-10 17:05:26812const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31813 return load_state_;
814}
815
[email protected]fcf75d42013-12-03 20:11:26816const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31817 return load_state_host_;
818}
819
[email protected]b172aee2012-04-10 17:05:26820uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31821 return upload_size_;
822}
823
[email protected]b172aee2012-04-10 17:05:26824uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31825 return upload_position_;
826}
827
[email protected]1ae93fb2013-06-14 03:38:56828std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56829 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39830 frame_tree_.ForEach(base::Bind(&CollectSites,
831 base::Unretained(GetBrowserContext()),
832 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56833 return sites;
834}
835
[email protected]b172aee2012-04-10 17:05:26836const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31837 return encoding_;
838}
839
[email protected]b172aee2012-04-10 17:05:26840bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31841 return displayed_insecure_content_;
842}
843
[email protected]222f5822014-02-05 23:40:49844void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25845 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55846 ++capturer_count_;
847 DVLOG(1) << "There are now " << capturer_count_
848 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49849
850 // Note: This provides a hint to upstream code to size the views optimally
851 // for quality (e.g., to avoid scaling).
852 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
853 preferred_size_for_capture_ = capture_size;
854 OnPreferredSizeChanged(preferred_size_);
855 }
[email protected]54597982013-02-06 01:59:55856}
857
858void WebContentsImpl::DecrementCapturerCount() {
859 --capturer_count_;
860 DVLOG(1) << "There are now " << capturer_count_
861 << " capturing(s) of WebContentsImpl@" << this;
862 DCHECK_LE(0, capturer_count_);
863
[email protected]5a652232013-02-12 06:15:25864 if (is_being_destroyed_)
865 return;
866
[email protected]222f5822014-02-05 23:40:49867 if (capturer_count_ == 0) {
868 const gfx::Size old_size = preferred_size_for_capture_;
869 preferred_size_for_capture_ = gfx::Size();
870 OnPreferredSizeChanged(old_size);
871 }
872
[email protected]1ac10dca2013-08-20 20:47:04873 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55874 DVLOG(1) << "Executing delayed WasHidden().";
875 WasHidden();
876 }
[email protected]be1f56ab2011-12-22 06:55:31877}
878
[email protected]f2bd40812013-07-20 04:30:44879int WebContentsImpl::GetCapturerCount() const {
880 return capturer_count_;
881}
882
[email protected]b172aee2012-04-10 17:05:26883bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31884 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
885 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
886 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49887}
888
[email protected]b172aee2012-04-10 17:05:26889void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
890 int error_code) {
[email protected]443b80e2010-12-14 00:42:23891 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34892 return;
893
[email protected]443b80e2010-12-14 00:42:23894 crashed_status_ = status;
895 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21896 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34897}
898
[email protected]b172aee2012-04-10 17:05:26899base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31900 return crashed_status_;
901}
902
[email protected]b172aee2012-04-10 17:05:26903bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31904 return is_being_destroyed_;
905}
906
[email protected]b172aee2012-04-10 17:05:26907void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34908 if (delegate_)
909 delegate_->NavigationStateChanged(this, changed_flags);
910}
911
[email protected]9a890452014-02-13 22:21:02912base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
913 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33914}
915
[email protected]9e2e4632012-07-27 16:38:41916void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54917 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04918 RenderWidgetHostViewPort* rwhv =
919 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16920 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29921 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43922#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16923 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43924#endif
925 }
[email protected]96d185d2009-04-24 03:28:54926
[email protected]9a890452014-02-13 22:21:02927 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38928
[email protected]b9769d82012-02-10 00:23:59929 // The resize rect might have changed while this was inactive -- send the new
930 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58931 RenderViewHostImpl* rvh =
932 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59933 if (rvh) {
934 rvh->ResizeRectChanged(GetRootWindowResizerRect());
935 }
[email protected]96d185d2009-04-24 03:28:54936
[email protected]c0d9d5672013-10-09 07:38:03937 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
938
[email protected]54597982013-02-06 01:59:55939 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31940}
941
[email protected]b172aee2012-04-10 17:05:26942void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55943 // If there are entities capturing screenshots or video (e.g., mirroring),
944 // don't activate the "disable rendering" optimization.
945 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52946 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55947 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26948 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52949 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33950 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52951 // calls us).
[email protected]c30585c2012-02-16 15:02:04952 RenderWidgetHostViewPort* rwhv =
953 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16954 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29955 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54956 }
957
[email protected]c0d9d5672013-10-09 07:38:03958 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
959
[email protected]54597982013-02-06 01:59:55960 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37961}
962
[email protected]b172aee2012-04-10 17:05:26963bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31964 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27965 return WillNotifyDisconnection() &&
966 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58967 !static_cast<RenderViewHostImpl*>(
968 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31969}
970
[email protected]b172aee2012-04-10 17:05:26971void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:21972 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:40973 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:27974}
975
[email protected]b172aee2012-04-10 17:05:26976WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44977 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:45978 // We pass our own opener so that the cloned page can access it if it was
979 // before.
[email protected]54944cde2012-12-09 09:24:59980 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:45981 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:59982 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:19983 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:22984 FOR_EACH_OBSERVER(WebContentsObserver,
985 observers_,
986 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:27987 return tc;
988}
989
[email protected]14392a52012-05-02 20:28:44990void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:21991 const NotificationSource& source,
992 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:44993 switch (type) {
[email protected]8ff00d72012-10-23 19:12:21994 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
995 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:50996 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
997 i != pending_widget_views_.end(); ++i) {
998 if (host->GetView() == i->second) {
999 pending_widget_views_.erase(i);
1000 break;
1001 }
1002 }
1003 break;
1004 }
[email protected]14392a52012-05-02 20:28:441005 default:
1006 NOTREACHED();
1007 }
1008}
1009
[email protected]ec6c05f2013-10-23 18:41:571010WebContents* WebContentsImpl::GetWebContents() {
1011 return this;
1012}
1013
[email protected]54944cde2012-12-09 09:24:591014void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211015 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361016 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211017 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431018 should_normally_be_visible_ = !params.initially_hidden;
1019
[email protected]fa944cb82013-11-15 17:51:211020 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041021 params.browser_context, params.site_instance, params.routing_id,
1022 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191023
[email protected]8ff00d72012-10-23 19:12:211024 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191025 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271026 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191027 CHECK(render_view_host_delegate_view_);
1028 } else {
[email protected]f8497342013-02-05 22:15:021029 WebContentsViewDelegate* delegate =
1030 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1031
[email protected]59383c782013-04-17 16:43:271032 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381033 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1034 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021035
[email protected]b5a40842012-11-28 15:26:111036 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381037 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431038 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111039 render_view_host_delegate_view_ = rv;
1040 view_.reset(rv);
1041 } else {
[email protected]f8497342013-02-05 22:15:021042 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111043 view_.reset(CreateWebContentsView(
1044 this, delegate, &render_view_host_delegate_view_));
1045 }
[email protected]d1198fd2012-08-13 22:50:191046 CHECK(render_view_host_delegate_view_);
1047 }
1048 CHECK(view_.get());
1049
[email protected]ed245db2012-12-18 08:00:451050 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591051 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191052
1053 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101054 if (opener_)
1055 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191056
1057 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211058 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1059 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441060#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191061 java_bridge_dispatcher_host_manager_.reset(
1062 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101063 date_time_chooser_.reset(new DateTimeChooserAndroid());
1064#endif
[email protected]d1198fd2012-08-13 22:50:191065}
1066
[email protected]7fff43e2013-05-21 20:21:101067void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1068 RemoveDestructionObserver(web_contents);
1069
[email protected]14392a52012-05-02 20:28:441070 // Clear the opener if it has been closed.
1071 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441072 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511073 return;
[email protected]14392a52012-05-02 20:28:441074 }
[email protected]ceee8cd2013-03-08 04:59:511075 // Clear a pending contents that has been closed before being shown.
1076 for (PendingContents::iterator iter = pending_contents_.begin();
1077 iter != pending_contents_.end();
1078 ++iter) {
1079 if (iter->second != web_contents)
1080 continue;
1081 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511082 return;
1083 }
1084 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441085}
1086
[email protected]7fff43e2013-05-21 20:21:101087void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1088 if (!ContainsKey(destruction_observers_, web_contents)) {
1089 destruction_observers_[web_contents] =
1090 new DestructionObserver(this, web_contents);
1091 }
1092}
1093
1094void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1095 DestructionObservers::iterator iter =
1096 destruction_observers_.find(web_contents);
1097 if (iter != destruction_observers_.end()) {
1098 delete destruction_observers_[web_contents];
1099 destruction_observers_.erase(iter);
1100 }
1101}
1102
[email protected]b172aee2012-04-10 17:05:261103void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311104 observers_.AddObserver(observer);
1105}
1106
[email protected]b172aee2012-04-10 17:05:261107void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311108 observers_.RemoveObserver(observer);
1109}
1110
[email protected]b172aee2012-04-10 17:05:261111void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341112 if (delegate_)
1113 delegate_->ActivateContents(this);
1114}
1115
[email protected]b172aee2012-04-10 17:05:261116void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121117 if (delegate_)
1118 delegate_->DeactivateContents(this);
1119}
1120
[email protected]b172aee2012-04-10 17:05:261121void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481122 if (delegate_)
1123 delegate_->LostCapture();
1124}
1125
[email protected]b24b68a2012-09-24 21:57:261126void WebContentsImpl::RenderWidgetDeleted(
1127 RenderWidgetHostImpl* render_widget_host) {
1128 if (is_being_destroyed_) {
1129 // |created_widgets_| might have been destroyed.
1130 return;
1131 }
1132
1133 std::set<RenderWidgetHostImpl*>::iterator iter =
1134 created_widgets_.find(render_widget_host);
1135 if (iter != created_widgets_.end())
1136 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541137
1138 if (render_widget_host &&
1139 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491140 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1141 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541142 FOR_EACH_OBSERVER(WebContentsObserver,
1143 observers_,
1144 DidDestroyFullscreenWidget(
1145 fullscreen_widget_routing_id_));
1146 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1147 }
[email protected]b24b68a2012-09-24 21:57:261148}
1149
[email protected]b172aee2012-04-10 17:05:261150bool WebContentsImpl::PreHandleKeyboardEvent(
1151 const NativeWebKeyboardEvent& event,
1152 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481153 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131154 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481155}
1156
[email protected]b172aee2012-04-10 17:05:261157void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061158 if (browser_plugin_embedder_ &&
1159 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1160 return;
1161 }
1162
[email protected]63954792011-07-11 04:17:481163 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131164 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481165}
1166
[email protected]d92026ef2014-03-03 21:04:131167bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461168 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191169#if !defined(OS_MACOSX)
1170 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1171 // isn't done for two reasons:
1172 // -the OS already has a gesture to do this through pinch-zoom
1173 // -if a user starts an inertial scroll, let's go, and presses control
1174 // (i.e. control+tab) then the OS's buffered scroll events will come in
1175 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521176 if (delegate_ &&
1177 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461178 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521179 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1180 return true;
1181 }
[email protected]bccc4472013-04-18 16:37:191182#endif
[email protected]fb3f066e2013-02-12 19:12:521183 return false;
1184}
1185
[email protected]04bce562014-01-30 05:34:541186bool WebContentsImpl::PreHandleGestureEvent(
1187 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031188 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541189}
1190
[email protected]2ceee8f2014-01-14 18:02:081191#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411192gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1193 return accessible_parent_;
1194}
1195#endif
1196
[email protected]b172aee2012-04-10 17:05:261197void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431198 if (delegate_)
1199 delegate_->HandleMouseDown();
1200}
1201
[email protected]b172aee2012-04-10 17:05:261202void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481203 if (delegate_)
1204 delegate_->HandleMouseUp();
1205}
1206
[email protected]590a634e2012-07-19 16:38:231207void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481208 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231209 delegate_->HandlePointerActivate();
1210}
1211
1212void WebContentsImpl::HandleGestureBegin() {
1213 if (delegate_)
1214 delegate_->HandleGestureBegin();
1215}
1216
1217void WebContentsImpl::HandleGestureEnd() {
1218 if (delegate_)
1219 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481220}
1221
[email protected]b172aee2012-04-10 17:05:261222void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491223 // This method is being called to enter or leave renderer-initiated fullscreen
1224 // mode. Either way, make sure any existing fullscreen widget is shut down
1225 // first.
1226 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1227 if (widget_view)
1228 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1229
[email protected]8a5e0ca2011-08-25 06:30:471230 if (delegate_)
1231 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1232}
1233
[email protected]b172aee2012-04-10 17:05:261234bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381235 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121236}
1237
[email protected]a9c81f02012-06-01 00:15:441238void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1239 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371240 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441241 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371242 } else {
1243 GotResponseToLockMouseRequest(false);
1244 }
1245}
1246
[email protected]b172aee2012-04-10 17:05:261247void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371248 if (delegate_)
1249 delegate_->LostMouseLock();
1250}
1251
[email protected]bafe6cd2012-05-23 23:09:501252void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201253 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501254 int route_id,
[email protected]227692c52013-05-31 22:43:041255 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131256 const ViewHostMsg_CreateWindow_Params& params,
1257 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501258 // We usually create the new window in the same BrowsingInstance (group of
1259 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551260 // if the opener is being suppressed (in a non-guest), we create a new
1261 // SiteInstance in its own BrowsingInstance.
1262 bool is_guest = GetRenderProcessHost()->IsGuest();
1263
[email protected]04cbd3d2013-12-04 04:58:201264 // If the opener is to be suppressed, the new window can be in any process.
1265 // Since routing ids are process specific, we must not have one passed in
1266 // as argument here.
1267 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1268
[email protected]bafe6cd2012-05-23 23:09:501269 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551270 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571271 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501272 GetSiteInstance();
1273
[email protected]04cbd3d2013-12-04 04:58:201274 // A message to create a new window can only come from the active process for
1275 // this WebContentsImpl instance. If any other process sends the request,
1276 // it is invalid and the process must be terminated.
1277 if (GetRenderProcessHost()->GetID() != render_process_id) {
1278 base::ProcessHandle process_handle =
1279 RenderProcessHost::FromID(render_process_id)->GetHandle();
1280 if (process_handle != base::kNullProcessHandle) {
1281 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391282 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201283 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1284 }
1285 return;
1286 }
1287
[email protected]d1198fd2012-08-13 22:50:191288 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341289 //
1290 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301291 const std::string& partition_id =
1292 GetContentClient()->browser()->
1293 GetStoragePartitionIdForSite(GetBrowserContext(),
1294 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461295 StoragePartition* partition = BrowserContext::GetStoragePartition(
1296 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411297 DOMStorageContextWrapper* dom_storage_context =
1298 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191299 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1300 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1301 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371302
1303 if (delegate_ &&
1304 !delegate_->ShouldCreateWebContents(this,
1305 route_id,
1306 params.window_container_type,
1307 params.frame_name,
1308 params.target_url,
1309 partition_id,
1310 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011311 if (route_id != MSG_ROUTING_NONE &&
1312 !RenderViewHost::FromID(render_process_id, route_id)) {
1313 // If the embedder didn't create a WebContents for this route, we need to
1314 // delete the RenderView that had already been created.
1315 Send(new ViewMsg_Close(route_id));
1316 }
[email protected]dd6730412013-08-14 15:03:371317 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1318 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1319 main_frame_route_id);
1320 return;
1321 }
1322
1323 // Create the new web contents. This will automatically create the new
1324 // WebContentsView. In the future, we may want to create the view separately.
1325 WebContentsImpl* new_contents =
1326 new WebContentsImpl(GetBrowserContext(),
1327 params.opener_suppressed ? NULL : this);
1328
[email protected]d1198fd2012-08-13 22:50:191329 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301330 partition_id,
[email protected]d1198fd2012-08-13 22:50:191331 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461332 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591333 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041334 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551335 if (!is_guest) {
1336 create_params.context = view_->GetNativeView();
1337 create_params.initial_size = view_->GetContainerSize();
1338 } else {
1339 // This makes |new_contents| act as a guest.
1340 // For more info, see comment above class BrowserPluginGuest.
1341 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1342 WebContentsImpl* new_contents_impl =
1343 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461344 BrowserPluginGuest::CreateWithOpener(instance_id,
1345 new_contents_impl->opener() != NULL,
1346 new_contents_impl,
1347 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551348 }
[email protected]1ac10dca2013-08-20 20:47:041349 if (params.disposition == NEW_BACKGROUND_TAB)
1350 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591351 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191352
[email protected]c4538072013-03-18 02:17:551353 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341354 // will be shown immediately).
1355 if (!params.opener_suppressed) {
1356 if (!is_guest) {
1357 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501358
[email protected]d70bea92013-04-05 04:23:341359 // TODO(brettw): It seems bogus that we have to call this function on the
1360 // newly created object and give it one of its own member variables.
1361 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1362 }
[email protected]bafe6cd2012-05-23 23:09:501363 // Save the created window associated with the route so we can show it
1364 // later.
1365 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1366 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101367 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501368 }
1369
1370 if (delegate_) {
1371 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131372 this, params.opener_frame_id, params.frame_name,
1373 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501374 }
1375
1376 if (params.opener_suppressed) {
1377 // When the opener is suppressed, the original renderer cannot access the
1378 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001379 bool was_blocked = false;
1380 if (delegate_) {
1381 gfx::Rect initial_pos;
1382 delegate_->AddNewContents(
1383 this, new_contents, params.disposition, initial_pos,
1384 params.user_gesture, &was_blocked);
1385 }
1386 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211387 OpenURLParams open_params(params.target_url,
1388 Referrer(),
1389 CURRENT_TAB,
1390 PAGE_TRANSITION_LINK,
1391 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301392 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001393 new_contents->OpenURL(open_params);
1394 }
[email protected]bafe6cd2012-05-23 23:09:501395 }
1396}
1397
[email protected]a8504022013-12-04 20:23:511398void WebContentsImpl::CreateNewWidget(int render_process_id,
1399 int route_id,
[email protected]180ef242013-11-07 06:50:461400 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511401 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501402}
1403
[email protected]a8504022013-12-04 20:23:511404void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1405 int route_id) {
1406 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501407}
1408
[email protected]a8504022013-12-04 20:23:511409void WebContentsImpl::CreateNewWidget(int render_process_id,
1410 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501411 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461412 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211413 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511414 // A message to create a new widget can only come from the active process for
1415 // this WebContentsImpl instance. If any other process sends the request,
1416 // it is invalid and the process must be terminated.
1417 if (process->GetID() != render_process_id) {
1418 base::ProcessHandle process_handle =
1419 RenderProcessHost::FromID(render_process_id)->GetHandle();
1420 if (process_handle != base::kNullProcessHandle) {
1421 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391422 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511423 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1424 }
1425 return;
1426 }
1427
[email protected]bafe6cd2012-05-23 23:09:501428 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041429 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261430 created_widgets_.insert(widget_host);
1431
[email protected]83918ec2013-01-10 15:37:191432 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1433 view_->CreateViewForPopupWidget(widget_host));
1434 if (!widget_view)
1435 return;
[email protected]bafe6cd2012-05-23 23:09:501436 if (!is_fullscreen) {
1437 // Popups should not get activated.
1438 widget_view->SetPopupType(popup_type);
1439 }
1440 // Save the created widget associated with the route so we can show it later.
1441 pending_widget_views_[route_id] = widget_view;
1442
1443#if defined(OS_MACOSX)
1444 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1445 // to allow it to survive the trip without being hosted.
1446 base::mac::NSObjectRetain(widget_view->GetNativeView());
1447#endif
1448}
1449
1450void WebContentsImpl::ShowCreatedWindow(int route_id,
1451 WindowOpenDisposition disposition,
1452 const gfx::Rect& initial_pos,
1453 bool user_gesture) {
1454 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001455 if (contents) {
1456 WebContentsDelegate* delegate = GetDelegate();
1457 if (delegate) {
1458 delegate->AddNewContents(
1459 this, contents, disposition, initial_pos, user_gesture, NULL);
1460 }
1461 }
[email protected]bafe6cd2012-05-23 23:09:501462}
1463
1464void WebContentsImpl::ShowCreatedWidget(int route_id,
1465 const gfx::Rect& initial_pos) {
1466 ShowCreatedWidget(route_id, false, initial_pos);
1467}
1468
1469void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1470 ShowCreatedWidget(route_id, true, gfx::Rect());
1471}
1472
1473void WebContentsImpl::ShowCreatedWidget(int route_id,
1474 bool is_fullscreen,
1475 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501476 RenderWidgetHostViewPort* widget_host_view =
1477 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1478 if (!widget_host_view)
1479 return;
[email protected]4aebbca2013-09-17 22:26:491480 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311481 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1482 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491483 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1484 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1485 delegate_->ToggleFullscreenModeForTab(this, true);
1486 } else {
1487 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491488 }
[email protected]4aebbca2013-09-17 22:26:491489 FOR_EACH_OBSERVER(WebContentsObserver,
1490 observers_,
1491 DidShowFullscreenWidget(route_id));
1492 if (!widget_host_view->HasFocus())
1493 widget_host_view->Focus();
1494 } else {
[email protected]f8497342013-02-05 22:15:021495 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491496 }
[email protected]89054502012-06-03 10:29:241497
1498 RenderWidgetHostImpl* render_widget_host_impl =
1499 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1500 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311501 // Only allow privileged mouse lock for fullscreen render widget, which is
1502 // used to implement Pepper Flash fullscreen.
1503 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501504
1505#if defined(OS_MACOSX)
1506 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1507 // properly embedded (or purposefully ignored) we can release the retain we
1508 // took in CreateNewWidget().
1509 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1510#endif
1511}
1512
1513WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1514 PendingContents::iterator iter = pending_contents_.find(route_id);
1515
1516 // Certain systems can block the creation of new windows. If we didn't succeed
1517 // in creating one, just return NULL.
1518 if (iter == pending_contents_.end()) {
1519 return NULL;
1520 }
1521
1522 WebContentsImpl* new_contents = iter->second;
1523 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101524 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501525
[email protected]d70bea92013-04-05 04:23:341526 // Don't initialize the guest WebContents immediately.
1527 if (new_contents->GetRenderProcessHost()->IsGuest())
1528 return new_contents;
1529
[email protected]bafe6cd2012-05-23 23:09:501530 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1531 !new_contents->GetRenderViewHost()->GetView())
1532 return NULL;
1533
1534 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1535 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1536 return new_contents;
1537}
1538
1539RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1540 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1541 if (iter == pending_widget_views_.end()) {
1542 DCHECK(false);
1543 return NULL;
1544 }
1545
1546 RenderWidgetHostView* widget_host_view = iter->second;
1547 pending_widget_views_.erase(route_id);
1548
1549 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1550 if (!widget_host->GetProcess()->HasConnection()) {
1551 // The view has gone away or the renderer crashed. Nothing to do.
1552 return NULL;
1553 }
1554
1555 return widget_host_view;
1556}
1557
[email protected]f13b4202012-06-12 23:53:231558void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091559 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211560 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231561 if (delegate_)
1562 delegate_->RequestMediaAccessPermission(this, request, callback);
1563 else
[email protected]b5f76742013-04-29 15:05:591564 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231565}
1566
[email protected]cc9200432013-07-23 23:02:401567SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1568 SiteInstance* instance) {
1569 return controller_.GetSessionStorageNamespace(instance);
1570}
1571
[email protected]9b159a52013-10-03 17:24:551572FrameTree* WebContentsImpl::GetFrameTree() {
1573 return &frame_tree_;
1574}
1575
[email protected]edc3af82013-12-12 21:24:071576void WebContentsImpl::OnShowValidationMessage(
1577 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291578 const base::string16& main_text,
1579 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071580 if (delegate_)
1581 delegate_->ShowValidationMessage(
1582 this, anchor_in_root_view, main_text, sub_text);
1583}
1584
1585void WebContentsImpl::OnHideValidationMessage() {
1586 if (delegate_)
1587 delegate_->HideValidationMessage(this);
1588}
1589
1590void WebContentsImpl::OnMoveValidationMessage(
1591 const gfx::Rect& anchor_in_root_view) {
1592 if (delegate_)
1593 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1594}
1595
[email protected]32deec62013-05-15 23:55:041596void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1597 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441598 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041599}
1600
[email protected]b172aee2012-04-10 17:05:261601void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491602 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231603 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491604 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331605}
1606
[email protected]b172aee2012-04-10 17:05:261607void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341608 if (delegate_)
1609 delegate_->ResizeDueToAutoResize(this, new_size);
1610}
1611
[email protected]b172aee2012-04-10 17:05:261612WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201613 if (!delegate_)
1614 return NULL;
[email protected]00c37fc2011-08-02 00:22:501615
[email protected]e5d549d2011-12-28 01:29:201616 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201617 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341618}
1619
[email protected]6b618e62012-08-16 12:59:181620bool WebContentsImpl::Send(IPC::Message* message) {
1621 if (!GetRenderViewHost()) {
1622 delete message;
1623 return false;
1624 }
1625
1626 return GetRenderViewHost()->Send(message);
1627}
1628
[email protected]b172aee2012-04-10 17:05:261629bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501630 NavigationController::ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:201631 return frame_tree_.root()->navigator()->NavigateToPendingEntry(
1632 frame_tree_.GetMainFrame(), reload_type);
[email protected]876bc832010-09-07 16:29:541633}
[email protected]96d185d2009-04-24 03:28:541634
[email protected]a86c0e962013-12-17 17:10:391635void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1636 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441637 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391638 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441639}
1640
[email protected]20ca0382013-02-28 19:50:071641void WebContentsImpl::AttachInterstitialPage(
1642 InterstitialPageImpl* interstitial_page) {
1643 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211644 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291645
1646 // Cancel any visible dialogs so that they don't interfere with the
1647 // interstitial.
1648 if (dialog_manager_)
1649 dialog_manager_->CancelActiveAndPendingDialogs(this);
1650
[email protected]20ca0382013-02-28 19:50:071651 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1652 DidAttachInterstitialPage());
1653}
1654
1655void WebContentsImpl::DetachInterstitialPage() {
1656 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211657 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071658 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1659 DidDetachInterstitialPage());
1660}
1661
[email protected]b172aee2012-04-10 17:05:261662void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331663 const SiteInstance* site_instance,
1664 int history_length,
1665 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411666 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1667 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211668 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191669 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141670 return;
[email protected]9e1ad4b2011-08-14 16:49:191671 }
[email protected]9f76c1e2012-03-05 15:15:581672 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191673 if (!rvh) {
1674 NOTREACHED();
1675 return;
1676 }
[email protected]9f76c1e2012-03-05 15:15:581677 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191678 NOTREACHED();
1679 return;
1680 }
[email protected]6b618e62012-08-16 12:59:181681 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1682 history_length,
1683 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141684}
1685
[email protected]b172aee2012-04-10 17:05:261686void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271687 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211688 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541689 return;
1690 }
[email protected]9f76c1e2012-03-05 15:15:581691 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541692}
1693
[email protected]b172aee2012-04-10 17:05:261694bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211695 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541696}
1697
[email protected]b172aee2012-04-10 17:05:261698InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211699 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221700}
1701
[email protected]b172aee2012-04-10 17:05:261702bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161703 // WebKit creates Document object when MIME type is application/xhtml+xml,
1704 // so we also support this MIME type.
1705 return contents_mime_type_ == "text/html" ||
1706 contents_mime_type_ == "text/xml" ||
1707 contents_mime_type_ == "application/xhtml+xml" ||
1708 contents_mime_type_ == "text/plain" ||
1709 contents_mime_type_ == "text/css" ||
1710 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1711}
1712
[email protected]b172aee2012-04-10 17:05:261713void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591714 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161715 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551716 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011717 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141718 return;
[email protected]c7dd2f62011-07-18 15:57:591719 }
1720
1721 Stop();
1722
1723 // Create the save package and possibly prompt the user for the name to save
1724 // the page as. The user prompt is an asynchronous operation that runs on
1725 // another thread.
1726 save_package_ = new SavePackage(this);
1727 save_package_->GetSaveInfo();
1728}
1729
1730// Used in automated testing to bypass prompting the user for file names.
1731// Instead, the names and paths are hard coded rather than running them through
1732// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341733bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1734 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211735 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591736 // Stop the page from navigating.
1737 Stop();
1738
1739 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211740 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591741}
1742
[email protected]3c71576ce2013-07-23 02:00:011743void WebContentsImpl::SaveFrame(const GURL& url,
1744 const Referrer& referrer) {
1745 if (!GetURL().is_valid())
1746 return;
1747 bool is_main_frame = (url == GetURL());
1748
1749 DownloadManager* dlm =
1750 BrowserContext::GetDownloadManager(GetBrowserContext());
1751 if (!dlm)
1752 return;
1753 int64 post_id = -1;
1754 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271755 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011756 if (entry)
1757 post_id = entry->GetPostID();
1758 }
1759 scoped_ptr<DownloadUrlParameters> params(
1760 DownloadUrlParameters::FromWebContents(this, url));
1761 params->set_referrer(referrer);
1762 params->set_post_id(post_id);
1763 params->set_prefer_cache(true);
1764 if (post_id >= 0)
1765 params->set_method("POST");
1766 params->set_prompt(true);
1767 dlm->DownloadUrl(params.Pass());
1768}
1769
[email protected]b172aee2012-04-10 17:05:261770void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341771 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481772 const base::Callback<void(int64)>& callback) {
1773 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121774}
1775
[email protected]6286a372013-10-09 04:03:271776// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261777bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271778 NavigationEntryImpl* visible_entry =
1779 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1780 return (visible_entry != NULL &&
1781 visible_entry->site_instance() == GetSiteInstance() &&
1782 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321783}
1784
[email protected]b172aee2012-04-10 17:05:261785const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271786 return contents_mime_type_;
1787}
1788
[email protected]b172aee2012-04-10 17:05:261789bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271790 return notify_disconnection_;
1791}
1792
[email protected]b172aee2012-04-10 17:05:261793void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311794 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181795 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161796}
1797
[email protected]b172aee2012-04-10 17:05:261798void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311799 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181800 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161801}
1802
[email protected]8ff00d72012-10-23 19:12:211803RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271804 return &renderer_preferences_;
1805}
1806
[email protected]e35ccd52012-05-23 16:22:471807void WebContentsImpl::Close() {
1808 Close(GetRenderViewHost());
1809}
1810
[email protected]cf200a562013-05-03 16:24:291811void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461812 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291813 if (browser_plugin_embedder_.get())
1814 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1815 screen_x, screen_y, operation);
1816 if (GetRenderViewHost())
1817 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1818 screen_x, screen_y, operation);
1819}
1820
1821void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1822 int screen_x, int screen_y) {
1823 if (browser_plugin_embedder_.get())
1824 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1825 screen_x, screen_y);
1826 if (GetRenderViewHost())
1827 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1828 screen_x, screen_y);
1829}
1830
[email protected]d60f3702013-12-26 16:30:241831void WebContentsImpl::DidGetResourceResponseStart(
1832 const ResourceRequestDetails& details) {
1833 controller_.ssl_manager()->DidStartResourceResponse(details);
1834
1835 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1836 DidGetResourceResponseStart(details));
1837
1838 // TODO(avi): Remove. http://crbug.com/170921
1839 NotificationService::current()->Notify(
1840 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1841 Source<WebContents>(this),
1842 Details<const ResourceRequestDetails>(&details));
1843}
1844
1845void WebContentsImpl::DidGetRedirectForResourceRequest(
1846 RenderViewHost* render_view_host,
1847 const ResourceRedirectDetails& details) {
1848 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1849
1850 FOR_EACH_OBSERVER(
1851 WebContentsObserver,
1852 observers_,
1853 DidGetRedirectForResourceRequest(render_view_host, details));
1854
1855 // TODO(avi): Remove. http://crbug.com/170921
1856 NotificationService::current()->Notify(
1857 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1858 Source<WebContents>(this),
1859 Details<const ResourceRedirectDetails>(&details));
1860}
1861
[email protected]b172aee2012-04-10 17:05:261862void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521863 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581864 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511865 if (delegate_)
1866 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291867 if (browser_plugin_embedder_.get())
1868 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341869}
1870
[email protected]e35ccd52012-05-23 16:22:471871void WebContentsImpl::UserGestureDone() {
1872 OnUserGesture();
1873}
1874
[email protected]b172aee2012-04-10 17:05:261875void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271876 closed_by_user_gesture_ = value;
1877}
1878
[email protected]b172aee2012-04-10 17:05:261879bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271880 return closed_by_user_gesture_;
1881}
1882
[email protected]b172aee2012-04-10 17:05:261883double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051884 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561885 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251886 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171887 return 0;
[email protected]b75b8292010-10-01 07:28:251888
1889 double zoom_level;
1890 if (temporary_zoom_settings_) {
1891 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581892 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251893 } else {
[email protected]2ae88d12011-10-14 09:11:191894 GURL url;
[email protected]6286a372013-10-09 04:03:271895 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191896 // Since zoom map is updated using rewritten URL, use rewritten URL
1897 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271898 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021899 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1900 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251901 }
[email protected]d0b8d092010-10-25 04:05:171902 return zoom_level;
1903}
[email protected]b75b8292010-10-01 07:28:251904
[email protected]b172aee2012-04-10 17:05:261905int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591906 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171907 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011908 // Calculate the zoom percent from the factor. Round up to the nearest whole
1909 // number.
[email protected]b75b8292010-10-01 07:28:251910 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491911 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251912 *enable_decrement = percent > minimum_zoom_percent_;
1913 *enable_increment = percent < maximum_zoom_percent_;
1914 return percent;
1915}
1916
[email protected]b172aee2012-04-10 17:05:261917void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501918 if (!delegate_)
1919 return;
1920
[email protected]6286a372013-10-09 04:03:271921 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1922 if (!entry)
[email protected]1788e772010-12-15 16:40:501923 return;
1924
[email protected]6286a372013-10-09 04:03:271925 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121926}
1927
[email protected]b172aee2012-04-10 17:05:261928void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041929 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271930 if (!delegate_)
1931 return;
1932
[email protected]691aa2f2013-05-28 22:52:041933 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271934}
1935
[email protected]b172aee2012-04-10 17:05:261936int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271937 return minimum_zoom_percent_;
1938}
1939
[email protected]b172aee2012-04-10 17:05:261940int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271941 return maximum_zoom_percent_;
1942}
1943
[email protected]b172aee2012-04-10 17:05:261944gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:491945 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:231946}
1947
[email protected]b172aee2012-04-10 17:05:261948bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271949 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581950 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271951}
1952
[email protected]b172aee2012-04-10 17:05:261953bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441954 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501955}
1956
[email protected]cb805452013-05-22 15:16:211957void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181958 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211959 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201960}
1961
[email protected]cb805452013-05-22 15:16:211962void WebContentsImpl::DidEndColorChooser() {
1963 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1964 color_chooser_identifier_));
1965 color_chooser_.reset();
1966 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201967}
1968
[email protected]41225fe2013-03-29 05:32:021969int WebContentsImpl::DownloadImage(const GURL& url,
1970 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301971 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021972 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391973 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301974 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021975 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391976 return id;
1977}
1978
[email protected]5dcaf8e2013-12-28 01:31:421979bool WebContentsImpl::IsSubframe() const {
1980 return is_subframe_;
1981}
1982
[email protected]9649d492014-01-10 07:15:521983void WebContentsImpl::SetZoomLevel(double level) {
1984 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
1985 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
1986 if (embedder)
1987 embedder->SetZoomLevel(level);
1988}
1989
[email protected]36ec24f2014-01-09 00:32:081990void WebContentsImpl::Find(int request_id,
1991 const base::string16& search_text,
1992 const blink::WebFindOptions& options) {
1993 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
1994}
1995
1996void WebContentsImpl::StopFinding(StopFindAction action) {
1997 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
1998}
1999
[email protected]b172aee2012-04-10 17:05:262000bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272001 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202002 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332003 return true;
2004 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272005}
2006
[email protected]b172aee2012-04-10 17:05:262007void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272008 if (delegate_)
2009 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212010}
2011
[email protected]52913802013-12-10 05:52:182012void WebContentsImpl::DidStartProvisionalLoad(
2013 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072014 int parent_routing_id,
[email protected]54047eb52012-05-08 21:45:572015 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182016 const GURL& validated_url,
2017 bool is_error_page,
2018 bool is_iframe_srcdoc) {
2019 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572020 DidChangeLoadProgress(0);
2021
[email protected]0d60f0192011-04-14 12:40:102022 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252023 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072024 DidStartProvisionalLoadForFrame(
2025 render_frame_host->GetRoutingID(), parent_routing_id,
2026 is_main_frame, validated_url, is_error_page,
2027 is_iframe_srcdoc,
2028 render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542029
2030 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182031 FOR_EACH_OBSERVER(
2032 WebContentsObserver,
2033 observers_,
2034 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582035 render_frame_host));
[email protected]400992b2012-06-14 00:03:542036 }
2037}
2038
[email protected]3109fbb72014-01-06 23:57:152039void WebContentsImpl::DidFailProvisionalLoadWithError(
2040 RenderFrameHostImpl* render_frame_host,
2041 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2042 GURL validated_url(params.url);
2043 FOR_EACH_OBSERVER(
2044 WebContentsObserver,
2045 observers_,
[email protected]501052ff2014-02-21 22:19:072046 DidFailProvisionalLoad(render_frame_host->GetRoutingID(),
[email protected]3109fbb72014-01-06 23:57:152047 params.frame_unique_name,
2048 params.is_main_frame,
2049 validated_url,
2050 params.error_code,
2051 params.error_description,
2052 render_frame_host->render_view_host()));
2053}
2054
[email protected]b80624c2014-02-09 02:46:552055void WebContentsImpl::DidFailLoadWithError(
2056 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552057 const GURL& url,
2058 bool is_main_frame,
2059 int error_code,
2060 const base::string16& error_description) {
2061 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072062 DidFailLoad(render_frame_host->GetRoutingID(),
2063 url, is_main_frame,
[email protected]b80624c2014-02-09 02:46:552064 error_code, error_description,
2065 render_frame_host->render_view_host()));
2066}
2067
[email protected]52913802013-12-10 05:52:182068void WebContentsImpl::NotifyChangedNavigationState(
2069 InvalidateTypes changed_flags) {
2070 NotifyNavigationStateChanged(changed_flags);
2071}
2072
[email protected]3691e5cf2014-01-22 10:16:202073void WebContentsImpl::AboutToNavigateRenderFrame(
2074 RenderFrameHostImpl* render_frame_host) {
2075 // Notify observers that we will navigate in this RenderView.
2076 FOR_EACH_OBSERVER(
2077 WebContentsObserver,
2078 observers_,
2079 AboutToNavigateRenderView(render_frame_host->render_view_host()));
2080}
2081
2082void WebContentsImpl::DidStartNavigationToPendingEntry(
2083 RenderFrameHostImpl* render_frame_host,
2084 const GURL& url,
2085 NavigationController::ReloadType reload_type) {
2086 // Notify observers about navigation.
2087 FOR_EACH_OBSERVER(
2088 WebContentsObserver,
2089 observers_,
2090 DidStartNavigationToPendingEntry(url, reload_type));
2091}
2092
[email protected]400992b2012-06-14 00:03:542093void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582094 RenderFrameHostImpl* render_frame_host,
2095 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542096 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582097 FOR_EACH_OBSERVER(
2098 WebContentsObserver,
2099 observers_,
2100 ProvisionalChangeToMainFrameUrl(validated_target_url,
2101 render_frame_host));
[email protected]724159a2010-12-30 01:11:182102}
2103
[email protected]37567b432014-02-12 01:12:222104void WebContentsImpl::DidCommitProvisionalLoad(
2105 int64 frame_id,
2106 const base::string16& frame_unique_name,
2107 bool is_main_frame,
2108 const GURL& url,
2109 PageTransition transition_type,
2110 RenderFrameHostImpl* render_frame_host) {
2111 RenderViewHost* render_view_host = render_frame_host->render_view_host();
2112 // Notify observers about the commit of the provisional load.
2113 FOR_EACH_OBSERVER(
2114 WebContentsObserver,
2115 observers_,
2116 DidCommitProvisionalLoadForFrame(frame_id,
2117 frame_unique_name,
2118 is_main_frame,
2119 url,
2120 transition_type,
2121 render_view_host));
2122}
2123
2124void WebContentsImpl::DidNavigateMainFramePostCommit(
2125 const LoadCommittedDetails& details,
2126 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2127 if (details.is_navigation_to_different_page()) {
2128 // Clear the status bubble. This is a workaround for a bug where WebKit
2129 // doesn't let us know that the cursor left an element during a
2130 // transition (this is also why the mouse cursor remains as a hand after
2131 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2132 // clear the bubble when a user navigates to a named anchor in the same
2133 // page.
2134 UpdateTargetURL(details.entry->GetPageID(), GURL());
2135 }
2136
2137 if (!details.is_in_page) {
2138 // Once the main frame is navigated, we're no longer considered to have
2139 // displayed insecure content.
2140 displayed_insecure_content_ = false;
2141 SSLManager::NotifySSLInternalStateChanged(
2142 GetController().GetBrowserContext());
2143 }
2144
2145 // Notify observers about navigation.
2146 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2147 DidNavigateMainFrame(details, params));
2148
2149 if (delegate_) {
2150 delegate_->DidNavigateMainFramePostCommit(this);
2151 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2152 }
2153}
2154
2155void WebContentsImpl::DidNavigateAnyFramePostCommit(
2156 RenderFrameHostImpl* render_frame_host,
2157 const LoadCommittedDetails& details,
2158 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2159 // If we navigate off the page, close all JavaScript dialogs.
2160 if (dialog_manager_ && !details.is_in_page)
2161 dialog_manager_->CancelActiveAndPendingDialogs(this);
2162
2163 // Notify observers about navigation.
2164 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2165 DidNavigateAnyFrame(details, params));
2166}
2167
2168void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2169 contents_mime_type_ = mime_type;
2170}
2171
2172bool WebContentsImpl::CanOverscrollContent() {
2173 if (delegate_)
2174 return delegate_->CanOverscrollContent();
2175
2176 return false;
2177}
2178
[email protected]b172aee2012-04-10 17:05:262179void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182180 const GURL& url,
[email protected]70435962011-08-02 20:13:282181 const std::string& security_info,
2182 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182183 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282184 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192185 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182186 cache.Increment();
2187
2188 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082189 int cert_id = 0;
2190 net::CertStatus cert_status = 0;
2191 int security_bits = -1;
2192 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122193 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212194 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122195 &security_bits, &connection_status,
2196 &signed_certificate_timestamp_ids);
2197 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212198 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002199 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2200 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182201
[email protected]b0f724c2013-09-05 04:21:132202 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2203
2204 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2205 DidLoadResourceFromMemoryCache(details));
2206
[email protected]8bfc8272013-09-09 20:10:532207 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2208 scoped_refptr<net::URLRequestContextGetter> request_context(
2209 resource_type == ResourceType::MEDIA ?
2210 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2211 GetRenderProcessHost()->GetID()) :
2212 GetBrowserContext()->GetRequestContextForRenderProcess(
2213 GetRenderProcessHost()->GetID()));
2214 BrowserThread::PostTask(
2215 BrowserThread::IO,
2216 FROM_HERE,
2217 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2218 }
[email protected]724159a2010-12-30 01:11:182219}
2220
[email protected]b172aee2012-04-10 17:05:262221void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392222 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182223 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192224 SSLManager::NotifySSLInternalStateChanged(
2225 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182226}
2227
[email protected]b172aee2012-04-10 17:05:262228void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022229 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582230 LOG(WARNING) << security_origin << " ran insecure content from "
2231 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392232 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412233 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392234 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182235 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412236 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192237 SSLManager::NotifySSLInternalStateChanged(
2238 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182239}
2240
[email protected]501052ff2014-02-21 22:19:072241void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572242 CHECK(render_frame_message_source_);
2243 CHECK(!render_view_message_source_);
2244 RenderFrameHostImpl* rfh =
2245 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2246
2247 FOR_EACH_OBSERVER(WebContentsObserver,
2248 observers_,
[email protected]501052ff2014-02-21 22:19:072249 DocumentLoadedInFrame(rfh->GetRoutingID(),
2250 rfh->render_view_host()));
[email protected]724159a2010-12-30 01:11:182251}
2252
[email protected]b172aee2012-04-10 17:05:262253void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312254 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062255 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312256 bool is_main_frame) {
[email protected]8b3af1e2014-01-24 13:29:122257 if (!render_view_message_source_) {
2258 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2259 GetRenderProcessHost()->ReceivedBadMessage();
2260 return;
2261 }
[email protected]a1b99262013-12-27 21:56:222262
2263 // --site-per-process mode has a short-term hack allowing cross-process
2264 // subframe pages to commit thinking they are top-level. Correct it here to
2265 // avoid confusing the observers.
2266 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2267 render_view_message_source_ != GetRenderViewHost())
2268 is_main_frame = false;
2269
[email protected]8b3af1e2014-01-24 13:29:122270 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442271 RenderProcessHost* render_process_host =
2272 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422273 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252274 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472275 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442276 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312277}
2278
[email protected]b172aee2012-04-10 17:05:262279void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222280 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2281 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262282}
2283
[email protected]b172aee2012-04-10 17:05:262284void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2285 int maximum_percent,
2286 bool remember) {
[email protected]216813952011-05-19 22:21:262287 minimum_zoom_percent_ = minimum_percent;
2288 maximum_zoom_percent_ = maximum_percent;
2289 temporary_zoom_settings_ = !remember;
2290}
2291
[email protected]b172aee2012-04-10 17:05:262292void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342293 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432294 if (!delegate_)
2295 return;
2296
[email protected]b9535422012-02-09 01:47:592297 ChildProcessSecurityPolicyImpl* policy =
2298 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222299 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592300 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212301}
2302
[email protected]b172aee2012-04-10 17:05:262303void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432304 if (delegate_)
2305 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202306}
2307
[email protected]b172aee2012-04-10 17:05:262308void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2309 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262310 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362311 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432312 if (!delegate_)
2313 return;
2314
[email protected]b9535422012-02-09 01:47:592315 ChildProcessSecurityPolicyImpl* policy =
2316 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322317 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592318 return;
[email protected]8f810632013-06-06 22:33:322319
[email protected]3a3b75a2012-06-01 08:38:362320 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202321}
2322
[email protected]b172aee2012-04-10 17:05:262323void WebContentsImpl::OnFindReply(int request_id,
2324 int number_of_matches,
2325 const gfx::Rect& selection_rect,
2326 int active_match_ordinal,
2327 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432328 if (delegate_) {
2329 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2330 active_match_ordinal, final_update);
2331 }
[email protected]b888919c2011-09-02 00:32:162332}
2333
[email protected]59363fc92012-09-05 03:46:312334#if defined(OS_ANDROID)
2335void WebContentsImpl::OnFindMatchRectsReply(
2336 int version,
2337 const std::vector<gfx::RectF>& rects,
2338 const gfx::RectF& active_rect) {
2339 if (delegate_)
2340 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2341}
[email protected]583418cc2013-01-17 14:01:102342
[email protected]1ff427972013-02-07 21:14:072343void WebContentsImpl::OnOpenDateTimeDialog(
2344 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092345 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2346 GetRenderViewHost(),
2347 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132348 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092349 value.minimum,
2350 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172351 value.step,
2352 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102353}
2354
[email protected]a794f3a2013-10-30 17:00:322355void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2356 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442357 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322358}
2359
[email protected]59363fc92012-09-05 03:46:312360#endif
2361
[email protected]f114fa42013-12-06 17:06:442362void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2363 const base::FilePath& path,
2364 bool is_hung) {
2365 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2366
2367 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2368 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2369}
2370
2371void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422372 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442373 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422374 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452375}
2376
[email protected]cfa856d62014-02-22 07:58:402377void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2378 int automation_id) {
2379 DomOperationNotificationDetails details(json_string, automation_id);
2380 NotificationService::current()->Notify(
2381 NOTIFICATION_DOM_OPERATION_RESPONSE,
2382 Source<WebContents>(this),
2383 Details<DomOperationNotificationDetails>(&details));
2384}
2385
[email protected]b172aee2012-04-10 17:05:262386void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2387 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102388 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252389 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102390 AppCacheAccessed(manifest_url, blocked_by_policy));
2391}
2392
[email protected]8bc5ff02013-11-29 06:34:032393void WebContentsImpl::OnOpenColorChooser(
2394 int color_chooser_id,
2395 SkColor color,
2396 const std::vector<ColorSuggestion>& suggestions) {
2397 ColorChooser* new_color_chooser =
2398 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302399 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212400 return;
[email protected]820957a2014-01-14 14:56:302401 if (color_chooser_)
2402 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212403 color_chooser_.reset(new_color_chooser);
2404 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202405}
2406
[email protected]b172aee2012-04-10 17:05:262407void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202408 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212409 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202410 color_chooser_->End();
2411}
2412
[email protected]b172aee2012-04-10 17:05:262413void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322414 SkColor color) {
[email protected]da8543762012-03-20 08:52:202415 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212416 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202417 color_chooser_->SetSelectedColor(color);
2418}
2419
[email protected]d0759f492012-04-19 22:50:502420// This exists for render views that don't have a WebUI, but do have WebUI
2421// bindings enabled.
2422void WebContentsImpl::OnWebUISend(const GURL& source_url,
2423 const std::string& name,
2424 const base::ListValue& args) {
2425 if (delegate_)
2426 delegate_->WebUISend(this, source_url, name, args);
2427}
2428
[email protected]d8415ad92012-08-23 14:40:502429void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442430 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502431 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342432 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162433 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442434 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162435 return;
[email protected]d8415ad92012-08-23 14:40:502436 }
2437
[email protected]8c8fc292012-11-23 18:57:162438 if (!delegate_->RequestPpapiBrokerPermission(
2439 this, url, plugin_path,
2440 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442441 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162442 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442443 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162444 }
[email protected]d8415ad92012-08-23 14:40:502445}
2446
[email protected]ea0309c2013-08-06 19:35:442447void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502448 bool result) {
[email protected]ea0309c2013-08-06 19:35:442449 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502450}
2451
[email protected]c4538072013-03-18 02:17:552452void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372453 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082454 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552455 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392456 // For more info, see comment above classes BrowserPluginEmbedder and
2457 // BrowserPluginGuest.
2458 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142459 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082460 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372461}
2462
[email protected]41225fe2013-03-29 05:32:022463void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392464 int id,
[email protected]749fadd2013-05-15 08:37:482465 int http_status_code,
[email protected]795c28972012-12-06 06:13:392466 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302467 const std::vector<SkBitmap>& bitmaps,
2468 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132469 if (bitmaps.size() != original_bitmap_sizes.size())
2470 return;
2471
[email protected]41225fe2013-03-29 05:32:022472 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2473 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392474 // Currently WebContents notifies us of ANY downloads so that it is
2475 // possible to get here.
2476 return;
2477 }
2478 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302479 iter->second.Run(
2480 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392481 }
[email protected]41225fe2013-03-29 05:32:022482 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392483}
2484
2485void WebContentsImpl::OnUpdateFaviconURL(
2486 int32 page_id,
2487 const std::vector<FaviconURL>& candidates) {
2488 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2489 DidUpdateFaviconURL(page_id, candidates));
2490}
2491
[email protected]1dd0bb752014-02-01 01:16:262492void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2493 bool has_video,
2494 bool has_audio) {
2495// Chrome OS does its own detection of audio and video.
2496#if !defined(OS_CHROMEOS)
2497 scoped_ptr<PowerSaveBlocker> blocker;
2498 if (has_video) {
2499 blocker = PowerSaveBlocker::Create(
2500 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2501#if defined(OS_ANDROID)
2502 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2503 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2504#endif
2505 } else if (has_audio) {
2506 blocker = PowerSaveBlocker::Create(
2507 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2508 }
2509
2510 if (blocker) {
2511 power_save_blockers_[render_view_message_source_][player_cookie] =
2512 blocker.release();
2513 }
2514#endif // !defined(OS_CHROMEOS)
2515}
2516
2517void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062518 // Chrome OS does its own detection of audio and video.
2519#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262520 delete power_save_blockers_[render_view_message_source_][player_cookie];
2521 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062522#endif // !defined(OS_CHROMEOS)
2523}
2524
[email protected]9f268072013-11-07 00:02:152525void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2526 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2527 DidFirstVisuallyNonEmptyPaint(page_id));
2528}
[email protected]d9030b82013-07-19 08:26:062529
[email protected]e67ebf32013-02-13 11:07:192530void WebContentsImpl::DidChangeVisibleSSLState() {
2531 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2532 DidChangeVisibleSSLState());
2533}
2534
[email protected]17e286e2013-03-01 23:29:392535void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2536 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2537 BeforeFormRepostWarningShow());
2538}
2539
[email protected]ec6c05f2013-10-23 18:41:572540
2541void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2542 Activate();
2543 if (delegate_)
2544 delegate_->ShowRepostFormWarningDialog(this);
2545}
2546
[email protected]96d185d2009-04-24 03:28:542547// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592548// loading, or done loading.
2549void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2550 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262551 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542552 if (is_loading == is_loading_)
2553 return;
2554
2555 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262556 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2557 base::string16());
[email protected]96d185d2009-04-24 03:28:542558 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562559 upload_size_ = 0;
2560 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542561 }
2562
[email protected]fa944cb82013-11-15 17:51:212563 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542564
2565 is_loading_ = is_loading;
2566 waiting_for_response_ = is_loading;
2567
[email protected]6ebdc9b2010-09-27 16:55:572568 if (delegate_)
2569 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212570 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542571
[email protected]eab61442013-11-14 18:35:482572 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592573 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482574 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2575 "URL", url);
[email protected]91621872013-10-08 04:04:592576 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2577 DidStartLoading(render_view_host));
2578 } else {
[email protected]eab61442013-11-14 18:35:482579 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2580 "URL", url);
[email protected]91621872013-10-08 04:04:592581 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2582 DidStopLoading(render_view_host));
2583 }
[email protected]66798902013-10-01 18:40:162584
2585 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212586 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2587 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542588 if (details)
[email protected]8ff00d72012-10-23 19:12:212589 det = Details<LoadNotificationDetails>(details);
2590 NotificationService::current()->Notify(
2591 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542592}
2593
[email protected]b172aee2012-04-10 17:05:262594void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462595 // If we are creating a RVH for a restored controller, then we need to make
2596 // sure the RenderView starts with a next_page_id_ larger than the number
2597 // of restored entries. This must be called before the RenderView starts
2598 // navigating (to avoid a race between the browser updating max_page_id and
2599 // the renderer updating next_page_id_). Because of this, we only call this
2600 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562601 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582602 if (max_restored_page_id >
2603 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2604 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2605 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322606}
2607
[email protected]b172aee2012-04-10 17:05:262608bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262609 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322610 // For file URLs without a title, use the pathname instead. In the case of a
2611 // synthesized title, we don't want the update to count toward the "one set
2612 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262613 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322614 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512615 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242616 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322617 explicit_set = false; // Don't count synthetic titles toward the set limit.
2618 } else {
[email protected]8af69c6c2014-03-03 19:05:312619 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322620 explicit_set = true;
2621 }
2622
[email protected]987fc3a2011-05-26 14:18:092623 // If a page is created via window.open and never navigated,
2624 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552625 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092626 if (entry) {
[email protected]36fc0392011-12-25 03:59:512627 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092628 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322629
[email protected]36fc0392011-12-25 03:59:512630 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092631 } else {
2632 if (page_title_when_no_navigation_entry_ == final_title)
2633 return false; // Nothing changed, don't bother.
2634
2635 page_title_when_no_navigation_entry_ = final_title;
2636 }
[email protected]420ae012009-04-24 05:16:322637
[email protected]420ae012009-04-24 05:16:322638 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232639 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322640
[email protected]66798902013-10-01 18:40:162641 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532642 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162643
2644 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212645 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462646 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212647 NotificationService::current()->Notify(
2648 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2649 Source<WebContents>(this),
2650 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042651
[email protected]420ae012009-04-24 05:16:322652 return true;
2653}
2654
[email protected]7b712ee22013-10-03 00:57:282655void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2656 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322657 // After sending out a swap notification, we need to send a disconnect
2658 // notification so that clients that pick up a pointer to |this| can NULL the
2659 // pointer. See Bug 1230284.
2660 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112661 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282662 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112663
2664 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282665 std::pair<RenderViewHost*, RenderViewHost*> details =
2666 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212667 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282668 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212669 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282670 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392671
2672 // Ensure that the associated embedder gets cleared after a RenderViewHost
2673 // gets swapped, so we don't reuse the same embedder next time a
2674 // RenderViewHost is attached to this WebContents.
2675 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322676}
2677
[email protected]da7a7182013-09-06 08:11:112678// TODO(avi): Remove this entire function because this notification is already
2679// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262680void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322681 if (!notify_disconnection_)
2682 return;
2683
2684 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212685 NotificationService::current()->Notify(
2686 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2687 Source<WebContents>(this),
2688 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322689}
2690
[email protected]cbb1ef592013-06-05 19:49:462691void WebContentsImpl::NotifyNavigationEntryCommitted(
2692 const LoadCommittedDetails& load_details) {
2693 FOR_EACH_OBSERVER(
2694 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2695}
2696
[email protected]f114fa42013-12-06 17:06:442697bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2698 const IPC::Message& message) {
2699 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312700}
2701
[email protected]b849847b2013-12-10 21:57:582702void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2703 // Note this is only for subframes, the notification for the main frame
2704 // happens in RenderViewCreated.
2705 FOR_EACH_OBSERVER(WebContentsObserver,
2706 observers_,
2707 RenderFrameCreated(render_frame_host));
2708}
2709
2710void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2711 FOR_EACH_OBSERVER(WebContentsObserver,
2712 observers_,
2713 RenderFrameDeleted(render_frame_host));
2714}
2715
[email protected]a09d53ce2014-01-31 00:46:422716void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302717 if (delegate_)
2718 delegate_->WorkerCrashed(this);
2719}
2720
[email protected]a09d53ce2014-01-31 00:46:422721void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2722 const ContextMenuParams& params) {
2723 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:402724 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:422725 return;
2726
2727 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2728}
2729
[email protected]a86c0e962013-12-17 17:10:392730WebContents* WebContentsImpl::GetAsWebContents() {
2731 return this;
2732}
2733
[email protected]5a3bdf52012-05-24 15:12:572734RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2735 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322736}
2737
[email protected]8d3347f2009-07-09 22:00:212738RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262739WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212740 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212741}
2742
[email protected]8ff00d72012-10-23 19:12:212743RendererPreferences WebContentsImpl::GetRendererPrefs(
2744 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462745 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512746}
2747
[email protected]b172aee2012-04-10 17:05:262748gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172749 if (delegate_)
2750 return delegate_->GetRootWindowResizerRect();
2751 return gfx::Rect();
2752}
2753
[email protected]7a846df2012-09-20 19:17:392754void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272755 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392756 browser_plugin_embedder_.reset();
2757}
2758
[email protected]b172aee2012-04-10 17:05:262759void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442760 // Don't send notifications if we are just creating a swapped-out RVH for
2761 // the opener chain. These won't be used for view-source or WebUI, so it's
2762 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:242763 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:442764 return;
2765
[email protected]86f98a22013-03-20 14:35:002766 if (delegate_)
2767 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082768
[email protected]8ff00d72012-10-23 19:12:212769 NotificationService::current()->Notify(
2770 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2771 Source<WebContents>(this),
2772 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322773
2774 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352775 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212776 if (GetRenderManager()->pending_web_ui())
2777 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322778
[email protected]6286a372013-10-09 04:03:272779 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332780 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322781 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182782 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582783 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322784 }
[email protected]0666aef2009-05-13 19:48:082785
[email protected]60780f412013-02-25 16:34:102786 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262787
2788 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252789 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582790
2791 // We tell the observers now instead of when the main RenderFrameHostImpl is
2792 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2793 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:362794 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:582795 FOR_EACH_OBSERVER(
2796 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322797}
2798
[email protected]b172aee2012-04-10 17:05:262799void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522800 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322801 // Don't notify the world, since this came from a renderer in the
2802 // background.
2803 return;
2804 }
2805
[email protected]da7a7182013-09-06 08:11:112806 notify_disconnection_ = true;
2807 // TODO(avi): Remove. http://crbug.com/170921
2808 NotificationService::current()->Notify(
2809 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2810 Source<WebContents>(this),
2811 NotificationService::NoDetails());
2812
[email protected]be1f56ab2011-12-22 06:55:312813 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232814 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302815
2816 // Restore the focus to the tab (otherwise the focus will be on the top
2817 // window).
[email protected]484ae5912010-09-29 19:16:142818 if (was_crashed && !FocusLocationBarByDefault() &&
2819 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062820 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142821 }
[email protected]32ded2212011-11-10 18:51:432822
[email protected]d8c660432011-12-22 20:51:252823 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322824}
2825
[email protected]ec6a7eb2013-04-22 17:34:222826void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2827 base::TerminationStatus status,
2828 int error_code) {
[email protected]151a63d2011-12-20 22:32:522829 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322830 // The pending page's RenderViewHost is gone.
2831 return;
2832 }
2833
[email protected]698191dc2014-02-25 01:06:132834 // Cancel any visible dialogs so they are not left dangling over the sad tab.
2835 if (dialog_manager_)
2836 dialog_manager_->CancelActiveAndPendingDialogs(this);
2837
[email protected]d9030b82013-07-19 08:26:062838 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592839 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322840 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232841 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312842 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322843
[email protected]d8c660432011-12-22 20:51:252844 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272845 observers_,
[email protected]58d5cfe2013-07-10 02:40:522846 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322847}
2848
[email protected]b172aee2012-04-10 17:05:262849void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062850 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212851 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252852 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062853}
2854
[email protected]b172aee2012-04-10 17:05:262855void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2856 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042857 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152858 // Ensure that this state update comes from either the active RVH or one of
2859 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412860 // TODO(nasko): This should go through RenderFrameHost.
2861 // TODO(creis): We can't update state for cross-process subframes until we
2862 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2863 if (rvh != GetRenderViewHost() &&
2864 !GetRenderManager()->IsRVHOnSwappedOutList(
2865 static_cast<RenderViewHostImpl*>(rvh)))
2866 return;
[email protected]420ae012009-04-24 05:16:322867
2868 // We must be prepared to handle state updates for any page, these occur
2869 // when the user is scrolling and entering form data, as well as when we're
2870 // leaving a page, in which case our state may have already been moved to
2871 // the next page. The navigation controller will look up the appropriate
2872 // NavigationEntry and update it when it is notified via the delegate.
2873
2874 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582875 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322876 if (entry_index < 0)
2877 return;
[email protected]10f417c52011-12-28 21:04:232878 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322879
[email protected]691aa2f2013-05-28 22:52:042880 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322881 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042882 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322883 controller_.NotifyEntryChanged(entry, entry_index);
2884}
2885
[email protected]b172aee2012-04-10 17:05:262886void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2887 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262888 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262889 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322890 // If we have a title, that's a pretty good indication that we've started
2891 // getting useful data.
2892 SetNotWaitingForResponse();
2893
[email protected]73eb2602012-02-09 19:50:552894 // Try to find the navigation entry, which might not be the current one.
2895 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232896 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582897 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092898
[email protected]73eb2602012-02-09 19:50:552899 // We can handle title updates when we don't have an entry in
2900 // UpdateTitleForEntry, but only if the update is from the current RVH.
2901 if (!entry && rvh != GetRenderViewHost())
2902 return;
2903
[email protected]a49e10b2011-08-01 23:57:462904 // TODO(evan): make use of title_direction.
2905 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092906 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322907 return;
2908
2909 // Broadcast notifications when the UI should be updated.
2910 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212911 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322912}
2913
[email protected]b172aee2012-04-10 17:05:262914void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2915 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312916 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322917}
2918
[email protected]b172aee2012-04-10 17:05:262919void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512920 if (delegate_)
2921 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322922}
2923
[email protected]b172aee2012-04-10 17:05:262924void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:102925#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:292926 // The UI may be in an event-tracking loop, such as between the
2927 // mouse-down and mouse-up in text selection or a button click.
2928 // Defer the close until after tracking is complete, so that we
2929 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292930 // TODO(shess): This could get more fine-grained. For instance,
2931 // closing a tab in another window while selecting text in the
2932 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:102933 if (view_->IsEventTracking()) {
2934 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292935 return;
2936 }
[email protected]60780f412013-02-25 16:34:102937#endif
[email protected]07707302009-11-06 00:50:292938
[email protected]420ae012009-04-24 05:16:322939 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522940 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512941 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322942}
2943
[email protected]b172aee2012-04-10 17:05:262944void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522945 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512946 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:282947
2948 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:212949 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:572950}
2951
[email protected]b172aee2012-04-10 17:05:262952void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512953 if (delegate_ && delegate_->IsPopupOrPanel(this))
2954 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322955}
2956
[email protected]723971b2014-02-12 11:08:252957void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host) {
2958 SetIsLoading(render_frame_host->GetRenderViewHost(), true, NULL);
[email protected]420ae012009-04-24 05:16:322959}
2960
[email protected]723971b2014-02-12 11:08:252961void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:322962 scoped_ptr<LoadNotificationDetails> details;
2963
[email protected]9595fd82013-04-19 21:28:492964 // Use the last committed entry rather than the active one, in case a
2965 // pending entry has been created.
2966 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:202967 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:492968
[email protected]420ae012009-04-24 05:16:322969 // An entry may not exist for a stop when loading an initial blank page or
2970 // if an iframe injected by script into a blank page finishes loading.
2971 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:202972 base::TimeDelta elapsed =
2973 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:322974
2975 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512976 entry->GetVirtualURL(),
2977 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322978 elapsed,
2979 &controller_,
2980 controller_.GetCurrentEntryIndex()));
2981 }
2982
[email protected]723971b2014-02-12 11:08:252983 SetIsLoading(render_frame_host->GetRenderViewHost(), false, details.get());
[email protected]420ae012009-04-24 05:16:322984}
2985
[email protected]b172aee2012-04-10 17:05:262986void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162987 controller_.DiscardNonCommittedEntries();
2988
2989 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:212990 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162991}
2992
[email protected]b172aee2012-04-10 17:05:262993void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512994 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:132995 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:402996}
2997
[email protected]7cc78902012-12-06 02:32:262998void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:392999 if (opener_) {
3000 // Clear our opener so that future cross-process navigations don't have an
3001 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103002 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393003 opener_ = NULL;
3004 }
[email protected]7cc78902012-12-06 02:32:263005
3006 // Notify all swapped out RenderViewHosts for this tab. This is important
3007 // in case we go back to them, or if another window in those processes tries
3008 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213009 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263010}
3011
[email protected]59167c22013-06-03 18:07:323012void WebContentsImpl::DidAccessInitialDocument() {
3013 // Update the URL display.
3014 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3015}
3016
[email protected]87717d0e2012-04-26 02:58:433017void WebContentsImpl::DocumentAvailableInMainFrame(
3018 RenderViewHost* render_view_host) {
3019 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3020 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103021}
3022
[email protected]b172aee2012-04-10 17:05:263023void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083024 RenderViewHost* render_view_host,
3025 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093026 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3027 DocumentOnLoadCompletedInMainFrame(page_id));
3028
3029 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213030 NotificationService::current()->Notify(
3031 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3032 Source<WebContents>(this),
3033 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083034}
3035
[email protected]196159d2012-05-04 17:26:543036void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3037 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213038 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263039 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183040 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523041 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303042 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543043 // If this came from a swapped out RenderViewHost, we only allow the request
3044 // if we are still in the same BrowsingInstance.
[email protected]21b41c7e892014-02-28 01:52:243045 if (static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() &&
[email protected]196159d2012-05-04 17:26:543046 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3047 return;
3048 }
3049
[email protected]4ad5d77d2011-12-03 02:00:483050 // Delegate to RequestTransferURL because this is just the generic
3051 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573052 // TODO(creis): Pass the redirect_chain into this method to support client
3053 // redirects. http://crbug.com/311721.
3054 std::vector<GURL> redirect_chain;
3055 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3056 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523057 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483058}
3059
[email protected]b172aee2012-04-10 17:05:263060void WebContentsImpl::RequestTransferURL(
3061 const GURL& url,
[email protected]f8872902013-10-30 03:18:573062 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213063 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573064 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263065 WindowOpenDisposition disposition,
3066 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183067 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523068 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303069 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203070 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123071 GURL dest_url(url);
3072 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553073 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123074 dest_url = GURL(kAboutBlankURL);
3075
[email protected]a1b99262013-12-27 21:56:223076 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3077 int64 frame_tree_node_id = -1;
3078 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3079 source_frame_id != -1) {
[email protected]58faf942014-02-20 21:03:583080 FrameTreeNode* source_node = frame_tree_.FindByRoutingID(
3081 source_frame_id, old_request_id.child_id);
[email protected]a1b99262013-12-27 21:56:223082 if (source_node)
3083 frame_tree_node_id = source_node->frame_tree_node_id();
3084 }
[email protected]c80297782013-11-21 07:10:163085 OpenURLParams params(dest_url, referrer, source_frame_id,
3086 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573087 page_transition, true /* is_renderer_initiated */);
3088 if (redirect_chain.size() > 0)
3089 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553090 params.transferred_global_request_id = old_request_id;
3091 params.should_replace_current_entry = should_replace_current_entry;
3092 params.user_gesture = user_gesture;
3093
[email protected]fa944cb82013-11-15 17:51:213094 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573095 // Web UI pages sometimes want to override the page transition type for
3096 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3097 // automatically generated suggestions). We don't override other types
3098 // like TYPED because they have different implications (e.g., autocomplete).
3099 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213100 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553101
[email protected]e0112912011-02-02 22:54:353102 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163103 // want web sites to see a referrer of "chrome://blah" (and some
3104 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323105 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553106 params.referrer = Referrer();
3107
3108 // Navigations in Web UI pages count as browser-initiated navigations.
3109 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583110 }
[email protected]44d0930a2013-10-28 18:53:553111
3112 new_contents = OpenURL(params);
3113
[email protected]ae5184d62011-10-06 19:25:583114 if (new_contents) {
3115 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253116 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583117 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123118 dest_url,
[email protected]ae5184d62011-10-06 19:25:583119 referrer,
3120 disposition,
[email protected]44d0930a2013-10-28 18:53:553121 params.transition,
[email protected]ae5184d62011-10-06 19:25:583122 source_frame_id));
[email protected]420ae012009-04-24 05:16:323123 }
3124}
3125
[email protected]e1c3a552012-05-04 20:51:323126void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3127 // Tell the active RenderViewHost to run unload handlers and close, as long
3128 // as the request came from a RenderViewHost in the same BrowsingInstance.
3129 // In most cases, we receive this from a swapped out RenderViewHost.
3130 // It is possible to receive it from one that has just been swapped in,
3131 // in which case we might as well deliver the message anyway.
3132 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3133 GetRenderViewHost()->ClosePage();
3134}
3135
[email protected]f546640b2012-05-15 00:03:493136void WebContentsImpl::RouteMessageEvent(
3137 RenderViewHost* rvh,
3138 const ViewMsg_PostMessage_Params& params) {
3139 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363140 // came from a RenderViewHost in the same BrowsingInstance or if this
3141 // WebContents is dedicated to a browser plugin guest.
3142 // Note: This check means that an embedder could theoretically receive a
3143 // postMessage from anyone (not just its own guests). However, this is
3144 // probably not a risk for apps since other pages won't have references
3145 // to App windows.
3146 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3147 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493148 return;
3149
3150 ViewMsg_PostMessage_Params new_params(params);
3151
[email protected]0bc7f3542013-10-21 15:05:533152 if (!params.message_port_ids.empty()) {
3153 MessagePortMessageFilter* message_port_message_filter =
3154 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3155 ->message_port_message_filter();
3156 std::vector<int> new_routing_ids(params.message_port_ids.size());
3157 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3158 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3159 MessagePortService::GetInstance()->UpdateMessagePort(
3160 params.message_port_ids[i],
3161 message_port_message_filter,
3162 new_routing_ids[i]);
3163 }
3164 new_params.new_routing_ids = new_routing_ids;
3165 }
3166
[email protected]f546640b2012-05-15 00:03:493167 // If there is a source_routing_id, translate it to the routing ID for
3168 // the equivalent swapped out RVH in the target process. If we need
3169 // to create a swapped out RVH for the source tab, we create its opener
3170 // chain as well, since those will also be accessible to the target page.
3171 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3172 // Try to look up the WebContents for the source page.
3173 WebContentsImpl* source_contents = NULL;
3174 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3175 rvh->GetProcess()->GetID(), params.source_routing_id);
3176 if (source_rvh) {
3177 source_contents = static_cast<WebContentsImpl*>(
3178 source_rvh->GetDelegate()->GetAsWebContents());
3179 }
3180
3181 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363182 if (GetBrowserPluginGuest()) {
3183 // We create a swapped out RenderView for the embedder in the guest's
3184 // render process but we intentionally do not expose the embedder's
3185 // opener chain to it.
3186 new_params.source_routing_id =
3187 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3188 } else {
3189 new_params.source_routing_id =
3190 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3191 }
[email protected]f546640b2012-05-15 00:03:493192 } else {
3193 // We couldn't find it, so don't pass a source frame.
3194 new_params.source_routing_id = MSG_ROUTING_NONE;
3195 }
3196 }
3197
3198 // In most cases, we receive this from a swapped out RenderViewHost.
3199 // It is possible to receive it from one that has just been swapped in,
3200 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183201 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493202}
3203
[email protected]b172aee2012-04-10 17:05:263204void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343205 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263206 const base::string16& message,
3207 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323208 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213209 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323210 IPC::Message* reply_msg,
3211 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073212 // Suppress JavaScript dialogs when requested. Also suppress messages when
3213 // showing an interstitial as it's shown over the previous page and we don't
3214 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503215 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243216 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() ||
[email protected]0bfbf882011-12-22 18:19:273217 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073218 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523219 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153220 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323221
3222 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213223 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433224 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153225 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3226 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433227 this,
3228 frame_url.GetOrigin(),
3229 accept_lang,
3230 javascript_message_type,
3231 message,
[email protected]51da7e32012-01-30 19:24:523232 default_prompt,
[email protected]b172aee2012-04-10 17:05:263233 base::Bind(&WebContentsImpl::OnDialogClosed,
3234 base::Unretained(this),
3235 rvh,
3236 reply_msg),
[email protected]51da7e32012-01-30 19:24:523237 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323238 }
[email protected]3ab9cb82011-06-03 18:02:073239
[email protected]6dd2f1e2013-09-11 15:06:013240 *did_suppress_message = suppress_this_message;
3241
[email protected]3ab9cb82011-06-03 18:02:073242 if (suppress_this_message) {
3243 // If we are suppressing messages, just reply as if the user immediately
3244 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263245 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073246 }
3247
[email protected]6dd2f1e2013-09-11 15:06:013248 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3249 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323250}
3251
[email protected]b172aee2012-04-10 17:05:263252void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263253 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263254 bool is_reload,
3255 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583256 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513257 if (delegate_)
3258 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073259
3260 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243261 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
[email protected]3ab9cb82011-06-03 18:02:073262 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523263 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153264 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153265 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343266 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263267 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503268 return;
3269 }
[email protected]3ab9cb82011-06-03 18:02:073270
[email protected]7ab1e7d62009-10-14 23:32:013271 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153272 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3273 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323274 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263275 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523276 reply_msg));
[email protected]420ae012009-04-24 05:16:323277}
3278
[email protected]a796f202012-05-30 14:14:253279bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263280 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253281 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263282 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253283 if (!delegate_)
3284 return false;
3285 return delegate_->AddMessageToConsole(this, level, message, line_no,
3286 source_id);
3287}
3288
[email protected]b172aee2012-04-10 17:05:263289WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273290 // We want to base the page config off of the actual URL, rather than the
3291 // virtual URL.
3292 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3293 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003294 GURL url = controller_.GetActiveEntry()
3295 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153296
[email protected]fa944cb82013-11-15 17:51:213297 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323298}
3299
[email protected]0eba810b2012-10-18 03:19:363300int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213301 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413302 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3303 true, true);
[email protected]0eba810b2012-10-18 03:19:363304}
3305
[email protected]b172aee2012-04-10 17:05:263306void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273307 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253308 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223309
[email protected]ea114722012-03-12 01:11:253310 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173311 if (rdh) // NULL in unittests.
3312 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253313}
3314
[email protected]b172aee2012-04-10 17:05:263315void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443316 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253317 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443318}
3319
[email protected]b172aee2012-04-10 17:05:263320void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563321 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263322 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153323 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523324 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153325 return;
3326
[email protected]9f76c1e2012-03-05 15:15:583327 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3328
[email protected]e5fc1632011-08-08 07:51:533329 // Ignore renderer unresponsive event if debugger is attached to the tab
3330 // since the event may be a result of the renderer sitting on a breakpoint.
3331 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363332 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533333 return;
3334
[email protected]2e9d79f2013-08-16 05:45:563335 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323336 // Hang occurred while firing the beforeunload/unload handler.
3337 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583338 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323339
[email protected]fa944cb82013-11-15 17:51:213340 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323341 return;
3342
3343 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563344 // nothing we can do to recover. If the hang is in the beforeunload handler,
3345 // pretend the beforeunload listeners have all fired and allow the delegate
3346 // to continue closing; the user will not have the option of cancelling the
3347 // close. Otherwise, pretend the unload listeners have all fired and close
3348 // the tab.
3349 bool close = true;
3350 if (is_during_beforeunload) {
3351 delegate_->BeforeUnloadFired(this, true, &close);
3352 }
3353 if (close)
3354 Close(rvh);
[email protected]420ae012009-04-24 05:16:323355 return;
3356 }
3357
[email protected]9f76c1e2012-03-05 15:15:583358 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473359 return;
3360
[email protected]6934a702011-12-20 00:04:513361 if (delegate_)
3362 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323363}
3364
[email protected]b172aee2012-04-10 17:05:263365void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513366 if (delegate_)
3367 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323368}
3369
[email protected]b172aee2012-04-10 17:05:263370void WebContentsImpl::LoadStateChanged(
3371 const GURL& url,
3372 const net::LoadStateWithParam& load_state,
3373 uint64 upload_position,
3374 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323375 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563376 upload_position_ = upload_position;
3377 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503378 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213379 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303380 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213381 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323382 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463383 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213384 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463385 }
[email protected]420ae012009-04-24 05:16:323386}
3387
[email protected]b172aee2012-04-10 17:05:263388void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553389 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323390 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123391 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3392 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513393 if (delegate_)
3394 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093395 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323396}
3397
[email protected]58d5cfe2013-07-10 02:40:523398void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543399 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233400 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223401 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543402}
3403
[email protected]b172aee2012-04-10 17:05:263404void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103405 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213406 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263407 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3408 // here during container initialization and normal window size will be set
3409 // later. In case of tab duplication this resizing to 0x0 prevents setting
3410 // normal size later so just ignore it.
3411 if (!size.IsEmpty())
3412 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323413}
3414
[email protected]af905902013-10-01 21:38:513415void WebContentsImpl::CancelModalDialogsForRenderManager() {
3416 // We need to cancel modal dialogs when doing a process swap, since the load
3417 // deferrer would prevent us from swapping out.
3418 if (dialog_manager_)
3419 dialog_manager_->CancelActiveAndPendingDialogs(this);
3420}
3421
[email protected]7b712ee22013-10-03 00:57:283422void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3423 RenderViewHost* new_host) {
3424 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083425
3426 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003427 if (delegate_)
3428 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393429
[email protected]7b712ee22013-10-03 00:57:283430 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543431}
3432
[email protected]14392a52012-05-02 20:28:443433int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3434 SiteInstance* instance) {
3435 if (!opener_)
3436 return MSG_ROUTING_NONE;
3437
3438 // Recursively create RenderViews for anything else in the opener chain.
3439 return opener_->CreateOpenerRenderViews(instance);
3440}
3441
3442int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3443 int opener_route_id = MSG_ROUTING_NONE;
3444
3445 // If this tab has an opener, ensure it has a RenderView in the given
3446 // SiteInstance as well.
3447 if (opener_)
3448 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3449
[email protected]45a22ad2013-02-21 03:25:003450 // If any of the renderers (current, pending, or swapped out) for this
3451 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213452 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3453 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373454
[email protected]fa944cb82013-11-15 17:51:213455 if (GetRenderManager()->pending_render_view_host() &&
3456 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3457 instance)
3458 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003459
[email protected]fa944cb82013-11-15 17:51:213460 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373461 instance);
3462 if (rvh)
3463 return rvh->GetRoutingID();
3464
[email protected]14392a52012-05-02 20:28:443465 // Create a swapped out RenderView in the given SiteInstance if none exists,
3466 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413467 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3468 true, true);
[email protected]14392a52012-05-02 20:28:443469}
3470
[email protected]b172aee2012-04-10 17:05:263471NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193472 return GetController();
[email protected]3a3d47472010-07-15 21:03:543473}
3474
[email protected]b172aee2012-04-10 17:05:263475WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563476 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323477}
3478
[email protected]10f417c52011-12-28 21:04:233479NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263480 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323481 return controller_.GetLastCommittedEntry();
3482}
3483
[email protected]b172aee2012-04-10 17:05:263484bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163485 RenderViewHost* render_view_host,
3486 int opener_route_id,
3487 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033488 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443489 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163490 RenderWidgetHostView* rwh_view;
3491 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3492 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3493 // case this because RWH is still a base class of RenderViewHost, and child
3494 // frame RWHVs are unique in that they do not have their own WebContents.
3495 if (frame_connector) {
3496 RenderWidgetHostViewChildFrame* rwh_view_child =
3497 new RenderWidgetHostViewChildFrame(render_view_host);
3498 frame_connector->set_view(rwh_view_child);
3499 rwh_view = rwh_view_child;
3500 } else {
3501 rwh_view = view_->CreateViewForWidget(render_view_host);
3502 }
[email protected]1a98a932009-11-17 00:12:523503
[email protected]420ae012009-04-24 05:16:323504 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443505 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213506 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323507
[email protected]74ce1ad2011-12-16 21:51:463508 // Make sure we use the correct starting page_id in the new RenderView.
3509 UpdateMaxPageIDIfNecessary(render_view_host);
3510 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583511 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463512
[email protected]9f76c1e2012-03-05 15:15:583513 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263514 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493515 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133516 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523517 return false;
[email protected]14392a52012-05-02 20:28:443518 }
[email protected]a4127722011-04-27 23:13:523519
[email protected]a220b5932013-09-21 03:47:443520#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503521 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3522 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443523 if (rwh_view) {
3524 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3525 render_widget_host->WasResized();
3526 }
[email protected]f8233cc2011-05-31 20:24:503527#endif
3528
[email protected]420ae012009-04-24 05:16:323529 return true;
3530}
3531
[email protected]7d244f12013-08-22 21:41:513532#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183533base::android::ScopedJavaLocalRef<jobject>
3534WebContentsImpl::GetJavaWebContents() {
3535 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3536
3537 WebContentsAndroid* web_contents_android =
3538 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3539 if (!web_contents_android) {
3540 web_contents_android = new WebContentsAndroid(this);
3541 SetUserData(kWebContentsAndroidKey, web_contents_android);
3542 }
3543 return web_contents_android->GetJavaObject();
3544}
3545
[email protected]7d244f12013-08-22 21:41:513546bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3547 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163548 MSG_ROUTING_NONE,
3549 NULL);
[email protected]7d244f12013-08-22 21:41:513550}
3551#endif
3552
[email protected]b172aee2012-04-10 17:05:263553void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3554 IPC::Message* reply_msg,
3555 bool success,
[email protected]fcf75d42013-12-03 20:11:263556 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543557 if (is_showing_before_unload_dialog_ && !success) {
3558 // If a beforeunload dialog is canceled, we need to stop the throbber from
3559 // spinning, since we forced it to start spinning in Navigate.
[email protected]723971b2014-02-12 11:08:253560 DidStopLoading(rvh->GetMainFrame());
[email protected]15d160c02012-07-04 10:52:353561 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103562
[email protected]6d65a462013-06-21 21:29:123563 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3564 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543565 }
3566 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583567 static_cast<RenderViewHostImpl*>(
3568 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543569}
3570
[email protected]b172aee2012-04-10 17:05:263571void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213572 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123573 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103574}
[email protected]f45d2a72010-03-08 23:28:353575
[email protected]b172aee2012-04-10 17:05:263576void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103577 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443578 // Can be NULL during tests.
3579 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213580 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363581}
[email protected]9f76c1e2012-03-05 15:15:583582
[email protected]1ac10dca2013-08-20 20:47:043583bool WebContentsImpl::IsHidden() {
3584 return capturer_count_ == 0 && !should_normally_be_visible_;
3585}
3586
[email protected]b0936d22013-11-28 06:47:363587RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213588 return frame_tree_.root()->render_manager();
3589}
3590
[email protected]b172aee2012-04-10 17:05:263591RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583592 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3593}
[email protected]7900bfdb2012-05-24 19:31:243594
[email protected]f8497342013-02-05 22:15:023595BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393596 return browser_plugin_guest_.get();
3597}
3598
[email protected]738f57a2013-06-29 21:06:543599void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3600 CHECK(!browser_plugin_guest_);
3601 browser_plugin_guest_.reset(guest);
3602}
3603
[email protected]f8497342013-02-05 22:15:023604BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393605 return browser_plugin_embedder_.get();
3606}
[email protected]8ff00d72012-10-23 19:12:213607
[email protected]8eb04562013-03-06 03:41:143608BrowserPluginGuestManager*
3609 WebContentsImpl::GetBrowserPluginGuestManager() const {
3610 return static_cast<BrowserPluginGuestManager*>(
3611 GetBrowserContext()->GetUserData(
3612 browser_plugin::kBrowserPluginGuestManagerKeyName));
3613}
3614
[email protected]d9030b82013-07-19 08:26:063615void WebContentsImpl::ClearPowerSaveBlockers(
3616 RenderViewHost* render_view_host) {
3617 STLDeleteValues(&power_save_blockers_[render_view_host]);
3618 power_save_blockers_.erase(render_view_host);
3619}
3620
3621void WebContentsImpl::ClearAllPowerSaveBlockers() {
3622 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3623 i != power_save_blockers_.end(); ++i)
3624 STLDeleteValues(&power_save_blockers_[i->first]);
3625 power_save_blockers_.clear();
3626}
3627
[email protected]dc0fd432013-08-27 15:29:213628gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3629 gfx::Size size;
3630 if (delegate_)
3631 size = delegate_->GetSizeForNewRenderView(this);
3632 if (size.IsEmpty())
3633 size = view_->GetContainerSize();
3634 return size;
3635}
3636
[email protected]9b159a52013-10-03 17:24:553637void WebContentsImpl::OnFrameRemoved(
3638 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583639 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553640 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583641 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553642}
3643
[email protected]222f5822014-02-05 23:40:493644void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3645 if (!delegate_)
3646 return;
3647 const gfx::Size new_size = GetPreferredSize();
3648 if (new_size != old_size)
3649 delegate_->UpdatePreferredSize(this, new_size);
3650}
3651
[email protected]8ff00d72012-10-23 19:12:213652} // namespace content