blob: c7f5f555b11df243eef32ff857deab9b5eb93ee7 [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]fb3f066e2013-02-12 19:12:521167bool WebContentsImpl::PreHandleWheelEvent(
[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
1184 return false;
1185}
1186
[email protected]04bce562014-01-30 05:34:541187bool WebContentsImpl::PreHandleGestureEvent(
1188 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031189 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541190}
1191
[email protected]2ceee8f2014-01-14 18:02:081192#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411193gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1194 return accessible_parent_;
1195}
1196#endif
1197
[email protected]b172aee2012-04-10 17:05:261198void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431199 if (delegate_)
1200 delegate_->HandleMouseDown();
1201}
1202
[email protected]b172aee2012-04-10 17:05:261203void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481204 if (delegate_)
1205 delegate_->HandleMouseUp();
1206}
1207
[email protected]590a634e2012-07-19 16:38:231208void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481209 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231210 delegate_->HandlePointerActivate();
1211}
1212
1213void WebContentsImpl::HandleGestureBegin() {
1214 if (delegate_)
1215 delegate_->HandleGestureBegin();
1216}
1217
1218void WebContentsImpl::HandleGestureEnd() {
1219 if (delegate_)
1220 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481221}
1222
[email protected]b172aee2012-04-10 17:05:261223void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491224 // This method is being called to enter or leave renderer-initiated fullscreen
1225 // mode. Either way, make sure any existing fullscreen widget is shut down
1226 // first.
1227 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1228 if (widget_view)
1229 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1230
[email protected]8a5e0ca2011-08-25 06:30:471231 if (delegate_)
1232 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1233}
1234
[email protected]b172aee2012-04-10 17:05:261235bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381236 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121237}
1238
[email protected]a9c81f02012-06-01 00:15:441239void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1240 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371241 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441242 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371243 } else {
1244 GotResponseToLockMouseRequest(false);
1245 }
1246}
1247
[email protected]b172aee2012-04-10 17:05:261248void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371249 if (delegate_)
1250 delegate_->LostMouseLock();
1251}
1252
[email protected]bafe6cd2012-05-23 23:09:501253void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201254 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501255 int route_id,
[email protected]227692c52013-05-31 22:43:041256 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131257 const ViewHostMsg_CreateWindow_Params& params,
1258 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501259 // We usually create the new window in the same BrowsingInstance (group of
1260 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551261 // if the opener is being suppressed (in a non-guest), we create a new
1262 // SiteInstance in its own BrowsingInstance.
1263 bool is_guest = GetRenderProcessHost()->IsGuest();
1264
[email protected]04cbd3d2013-12-04 04:58:201265 // If the opener is to be suppressed, the new window can be in any process.
1266 // Since routing ids are process specific, we must not have one passed in
1267 // as argument here.
1268 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1269
[email protected]bafe6cd2012-05-23 23:09:501270 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551271 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571272 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501273 GetSiteInstance();
1274
[email protected]04cbd3d2013-12-04 04:58:201275 // A message to create a new window can only come from the active process for
1276 // this WebContentsImpl instance. If any other process sends the request,
1277 // it is invalid and the process must be terminated.
1278 if (GetRenderProcessHost()->GetID() != render_process_id) {
1279 base::ProcessHandle process_handle =
1280 RenderProcessHost::FromID(render_process_id)->GetHandle();
1281 if (process_handle != base::kNullProcessHandle) {
1282 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391283 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201284 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1285 }
1286 return;
1287 }
1288
[email protected]d1198fd2012-08-13 22:50:191289 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341290 //
1291 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301292 const std::string& partition_id =
1293 GetContentClient()->browser()->
1294 GetStoragePartitionIdForSite(GetBrowserContext(),
1295 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461296 StoragePartition* partition = BrowserContext::GetStoragePartition(
1297 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411298 DOMStorageContextWrapper* dom_storage_context =
1299 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191300 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1301 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1302 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371303
1304 if (delegate_ &&
1305 !delegate_->ShouldCreateWebContents(this,
1306 route_id,
1307 params.window_container_type,
1308 params.frame_name,
1309 params.target_url,
1310 partition_id,
1311 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011312 if (route_id != MSG_ROUTING_NONE &&
1313 !RenderViewHost::FromID(render_process_id, route_id)) {
1314 // If the embedder didn't create a WebContents for this route, we need to
1315 // delete the RenderView that had already been created.
1316 Send(new ViewMsg_Close(route_id));
1317 }
[email protected]dd6730412013-08-14 15:03:371318 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1319 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1320 main_frame_route_id);
1321 return;
1322 }
1323
1324 // Create the new web contents. This will automatically create the new
1325 // WebContentsView. In the future, we may want to create the view separately.
1326 WebContentsImpl* new_contents =
1327 new WebContentsImpl(GetBrowserContext(),
1328 params.opener_suppressed ? NULL : this);
1329
[email protected]d1198fd2012-08-13 22:50:191330 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301331 partition_id,
[email protected]d1198fd2012-08-13 22:50:191332 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461333 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591334 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041335 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551336 if (!is_guest) {
1337 create_params.context = view_->GetNativeView();
1338 create_params.initial_size = view_->GetContainerSize();
1339 } else {
1340 // This makes |new_contents| act as a guest.
1341 // For more info, see comment above class BrowserPluginGuest.
1342 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1343 WebContentsImpl* new_contents_impl =
1344 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461345 BrowserPluginGuest::CreateWithOpener(instance_id,
1346 new_contents_impl->opener() != NULL,
1347 new_contents_impl,
1348 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551349 }
[email protected]1ac10dca2013-08-20 20:47:041350 if (params.disposition == NEW_BACKGROUND_TAB)
1351 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591352 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191353
[email protected]c4538072013-03-18 02:17:551354 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341355 // will be shown immediately).
1356 if (!params.opener_suppressed) {
1357 if (!is_guest) {
1358 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501359
[email protected]d70bea92013-04-05 04:23:341360 // TODO(brettw): It seems bogus that we have to call this function on the
1361 // newly created object and give it one of its own member variables.
1362 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1363 }
[email protected]bafe6cd2012-05-23 23:09:501364 // Save the created window associated with the route so we can show it
1365 // later.
1366 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1367 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101368 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501369 }
1370
1371 if (delegate_) {
1372 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131373 this, params.opener_frame_id, params.frame_name,
1374 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501375 }
1376
1377 if (params.opener_suppressed) {
1378 // When the opener is suppressed, the original renderer cannot access the
1379 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001380 bool was_blocked = false;
1381 if (delegate_) {
1382 gfx::Rect initial_pos;
1383 delegate_->AddNewContents(
1384 this, new_contents, params.disposition, initial_pos,
1385 params.user_gesture, &was_blocked);
1386 }
1387 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211388 OpenURLParams open_params(params.target_url,
1389 Referrer(),
1390 CURRENT_TAB,
1391 PAGE_TRANSITION_LINK,
1392 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301393 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001394 new_contents->OpenURL(open_params);
1395 }
[email protected]bafe6cd2012-05-23 23:09:501396 }
1397}
1398
[email protected]a8504022013-12-04 20:23:511399void WebContentsImpl::CreateNewWidget(int render_process_id,
1400 int route_id,
[email protected]180ef242013-11-07 06:50:461401 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511402 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501403}
1404
[email protected]a8504022013-12-04 20:23:511405void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1406 int route_id) {
1407 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501408}
1409
[email protected]a8504022013-12-04 20:23:511410void WebContentsImpl::CreateNewWidget(int render_process_id,
1411 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501412 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461413 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211414 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511415 // A message to create a new widget can only come from the active process for
1416 // this WebContentsImpl instance. If any other process sends the request,
1417 // it is invalid and the process must be terminated.
1418 if (process->GetID() != render_process_id) {
1419 base::ProcessHandle process_handle =
1420 RenderProcessHost::FromID(render_process_id)->GetHandle();
1421 if (process_handle != base::kNullProcessHandle) {
1422 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391423 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511424 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1425 }
1426 return;
1427 }
1428
[email protected]bafe6cd2012-05-23 23:09:501429 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041430 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261431 created_widgets_.insert(widget_host);
1432
[email protected]83918ec2013-01-10 15:37:191433 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1434 view_->CreateViewForPopupWidget(widget_host));
1435 if (!widget_view)
1436 return;
[email protected]bafe6cd2012-05-23 23:09:501437 if (!is_fullscreen) {
1438 // Popups should not get activated.
1439 widget_view->SetPopupType(popup_type);
1440 }
1441 // Save the created widget associated with the route so we can show it later.
1442 pending_widget_views_[route_id] = widget_view;
1443
1444#if defined(OS_MACOSX)
1445 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1446 // to allow it to survive the trip without being hosted.
1447 base::mac::NSObjectRetain(widget_view->GetNativeView());
1448#endif
1449}
1450
1451void WebContentsImpl::ShowCreatedWindow(int route_id,
1452 WindowOpenDisposition disposition,
1453 const gfx::Rect& initial_pos,
1454 bool user_gesture) {
1455 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001456 if (contents) {
1457 WebContentsDelegate* delegate = GetDelegate();
1458 if (delegate) {
1459 delegate->AddNewContents(
1460 this, contents, disposition, initial_pos, user_gesture, NULL);
1461 }
1462 }
[email protected]bafe6cd2012-05-23 23:09:501463}
1464
1465void WebContentsImpl::ShowCreatedWidget(int route_id,
1466 const gfx::Rect& initial_pos) {
1467 ShowCreatedWidget(route_id, false, initial_pos);
1468}
1469
1470void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1471 ShowCreatedWidget(route_id, true, gfx::Rect());
1472}
1473
1474void WebContentsImpl::ShowCreatedWidget(int route_id,
1475 bool is_fullscreen,
1476 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501477 RenderWidgetHostViewPort* widget_host_view =
1478 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1479 if (!widget_host_view)
1480 return;
[email protected]4aebbca2013-09-17 22:26:491481 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311482 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1483 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491484 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1485 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1486 delegate_->ToggleFullscreenModeForTab(this, true);
1487 } else {
1488 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491489 }
[email protected]4aebbca2013-09-17 22:26:491490 FOR_EACH_OBSERVER(WebContentsObserver,
1491 observers_,
1492 DidShowFullscreenWidget(route_id));
1493 if (!widget_host_view->HasFocus())
1494 widget_host_view->Focus();
1495 } else {
[email protected]f8497342013-02-05 22:15:021496 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491497 }
[email protected]89054502012-06-03 10:29:241498
1499 RenderWidgetHostImpl* render_widget_host_impl =
1500 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1501 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311502 // Only allow privileged mouse lock for fullscreen render widget, which is
1503 // used to implement Pepper Flash fullscreen.
1504 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501505
1506#if defined(OS_MACOSX)
1507 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1508 // properly embedded (or purposefully ignored) we can release the retain we
1509 // took in CreateNewWidget().
1510 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1511#endif
1512}
1513
1514WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1515 PendingContents::iterator iter = pending_contents_.find(route_id);
1516
1517 // Certain systems can block the creation of new windows. If we didn't succeed
1518 // in creating one, just return NULL.
1519 if (iter == pending_contents_.end()) {
1520 return NULL;
1521 }
1522
1523 WebContentsImpl* new_contents = iter->second;
1524 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101525 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501526
[email protected]d70bea92013-04-05 04:23:341527 // Don't initialize the guest WebContents immediately.
1528 if (new_contents->GetRenderProcessHost()->IsGuest())
1529 return new_contents;
1530
[email protected]bafe6cd2012-05-23 23:09:501531 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1532 !new_contents->GetRenderViewHost()->GetView())
1533 return NULL;
1534
1535 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1536 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1537 return new_contents;
1538}
1539
1540RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1541 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1542 if (iter == pending_widget_views_.end()) {
1543 DCHECK(false);
1544 return NULL;
1545 }
1546
1547 RenderWidgetHostView* widget_host_view = iter->second;
1548 pending_widget_views_.erase(route_id);
1549
1550 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1551 if (!widget_host->GetProcess()->HasConnection()) {
1552 // The view has gone away or the renderer crashed. Nothing to do.
1553 return NULL;
1554 }
1555
1556 return widget_host_view;
1557}
1558
[email protected]f13b4202012-06-12 23:53:231559void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091560 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211561 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231562 if (delegate_)
1563 delegate_->RequestMediaAccessPermission(this, request, callback);
1564 else
[email protected]b5f76742013-04-29 15:05:591565 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231566}
1567
[email protected]cc9200432013-07-23 23:02:401568SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1569 SiteInstance* instance) {
1570 return controller_.GetSessionStorageNamespace(instance);
1571}
1572
[email protected]9b159a52013-10-03 17:24:551573FrameTree* WebContentsImpl::GetFrameTree() {
1574 return &frame_tree_;
1575}
1576
[email protected]edc3af82013-12-12 21:24:071577void WebContentsImpl::OnShowValidationMessage(
1578 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291579 const base::string16& main_text,
1580 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071581 if (delegate_)
1582 delegate_->ShowValidationMessage(
1583 this, anchor_in_root_view, main_text, sub_text);
1584}
1585
1586void WebContentsImpl::OnHideValidationMessage() {
1587 if (delegate_)
1588 delegate_->HideValidationMessage(this);
1589}
1590
1591void WebContentsImpl::OnMoveValidationMessage(
1592 const gfx::Rect& anchor_in_root_view) {
1593 if (delegate_)
1594 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1595}
1596
[email protected]32deec62013-05-15 23:55:041597void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1598 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441599 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041600}
1601
[email protected]b172aee2012-04-10 17:05:261602void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491603 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231604 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491605 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331606}
1607
[email protected]b172aee2012-04-10 17:05:261608void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341609 if (delegate_)
1610 delegate_->ResizeDueToAutoResize(this, new_size);
1611}
1612
[email protected]b172aee2012-04-10 17:05:261613WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201614 if (!delegate_)
1615 return NULL;
[email protected]00c37fc2011-08-02 00:22:501616
[email protected]e5d549d2011-12-28 01:29:201617 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201618 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341619}
1620
[email protected]6b618e62012-08-16 12:59:181621bool WebContentsImpl::Send(IPC::Message* message) {
1622 if (!GetRenderViewHost()) {
1623 delete message;
1624 return false;
1625 }
1626
1627 return GetRenderViewHost()->Send(message);
1628}
1629
[email protected]b172aee2012-04-10 17:05:261630bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501631 NavigationController::ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:201632 return frame_tree_.root()->navigator()->NavigateToPendingEntry(
1633 frame_tree_.GetMainFrame(), reload_type);
[email protected]876bc832010-09-07 16:29:541634}
[email protected]96d185d2009-04-24 03:28:541635
[email protected]a86c0e962013-12-17 17:10:391636void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1637 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441638 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391639 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441640}
1641
[email protected]20ca0382013-02-28 19:50:071642void WebContentsImpl::AttachInterstitialPage(
1643 InterstitialPageImpl* interstitial_page) {
1644 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211645 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291646
1647 // Cancel any visible dialogs so that they don't interfere with the
1648 // interstitial.
1649 if (dialog_manager_)
1650 dialog_manager_->CancelActiveAndPendingDialogs(this);
1651
[email protected]20ca0382013-02-28 19:50:071652 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1653 DidAttachInterstitialPage());
1654}
1655
1656void WebContentsImpl::DetachInterstitialPage() {
1657 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211658 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071659 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1660 DidDetachInterstitialPage());
1661}
1662
[email protected]b172aee2012-04-10 17:05:261663void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331664 const SiteInstance* site_instance,
1665 int history_length,
1666 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411667 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1668 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211669 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191670 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141671 return;
[email protected]9e1ad4b2011-08-14 16:49:191672 }
[email protected]9f76c1e2012-03-05 15:15:581673 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191674 if (!rvh) {
1675 NOTREACHED();
1676 return;
1677 }
[email protected]9f76c1e2012-03-05 15:15:581678 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191679 NOTREACHED();
1680 return;
1681 }
[email protected]6b618e62012-08-16 12:59:181682 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1683 history_length,
1684 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141685}
1686
[email protected]b172aee2012-04-10 17:05:261687void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271688 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211689 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541690 return;
1691 }
[email protected]9f76c1e2012-03-05 15:15:581692 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541693}
1694
[email protected]b172aee2012-04-10 17:05:261695bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211696 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541697}
1698
[email protected]b172aee2012-04-10 17:05:261699InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211700 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221701}
1702
[email protected]b172aee2012-04-10 17:05:261703bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161704 // WebKit creates Document object when MIME type is application/xhtml+xml,
1705 // so we also support this MIME type.
1706 return contents_mime_type_ == "text/html" ||
1707 contents_mime_type_ == "text/xml" ||
1708 contents_mime_type_ == "application/xhtml+xml" ||
1709 contents_mime_type_ == "text/plain" ||
1710 contents_mime_type_ == "text/css" ||
1711 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1712}
1713
[email protected]b172aee2012-04-10 17:05:261714void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591715 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161716 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551717 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011718 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141719 return;
[email protected]c7dd2f62011-07-18 15:57:591720 }
1721
1722 Stop();
1723
1724 // Create the save package and possibly prompt the user for the name to save
1725 // the page as. The user prompt is an asynchronous operation that runs on
1726 // another thread.
1727 save_package_ = new SavePackage(this);
1728 save_package_->GetSaveInfo();
1729}
1730
1731// Used in automated testing to bypass prompting the user for file names.
1732// Instead, the names and paths are hard coded rather than running them through
1733// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341734bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1735 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211736 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591737 // Stop the page from navigating.
1738 Stop();
1739
1740 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211741 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591742}
1743
[email protected]3c71576ce2013-07-23 02:00:011744void WebContentsImpl::SaveFrame(const GURL& url,
1745 const Referrer& referrer) {
1746 if (!GetURL().is_valid())
1747 return;
1748 bool is_main_frame = (url == GetURL());
1749
1750 DownloadManager* dlm =
1751 BrowserContext::GetDownloadManager(GetBrowserContext());
1752 if (!dlm)
1753 return;
1754 int64 post_id = -1;
1755 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271756 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011757 if (entry)
1758 post_id = entry->GetPostID();
1759 }
1760 scoped_ptr<DownloadUrlParameters> params(
1761 DownloadUrlParameters::FromWebContents(this, url));
1762 params->set_referrer(referrer);
1763 params->set_post_id(post_id);
1764 params->set_prefer_cache(true);
1765 if (post_id >= 0)
1766 params->set_method("POST");
1767 params->set_prompt(true);
1768 dlm->DownloadUrl(params.Pass());
1769}
1770
[email protected]b172aee2012-04-10 17:05:261771void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341772 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481773 const base::Callback<void(int64)>& callback) {
1774 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121775}
1776
[email protected]6286a372013-10-09 04:03:271777// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261778bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271779 NavigationEntryImpl* visible_entry =
1780 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1781 return (visible_entry != NULL &&
1782 visible_entry->site_instance() == GetSiteInstance() &&
1783 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321784}
1785
[email protected]b172aee2012-04-10 17:05:261786const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271787 return contents_mime_type_;
1788}
1789
[email protected]b172aee2012-04-10 17:05:261790bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271791 return notify_disconnection_;
1792}
1793
[email protected]b172aee2012-04-10 17:05:261794void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311795 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181796 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161797}
1798
[email protected]b172aee2012-04-10 17:05:261799void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311800 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181801 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161802}
1803
[email protected]8ff00d72012-10-23 19:12:211804RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271805 return &renderer_preferences_;
1806}
1807
[email protected]e35ccd52012-05-23 16:22:471808void WebContentsImpl::Close() {
1809 Close(GetRenderViewHost());
1810}
1811
[email protected]cf200a562013-05-03 16:24:291812void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461813 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291814 if (browser_plugin_embedder_.get())
1815 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1816 screen_x, screen_y, operation);
1817 if (GetRenderViewHost())
1818 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1819 screen_x, screen_y, operation);
1820}
1821
1822void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1823 int screen_x, int screen_y) {
1824 if (browser_plugin_embedder_.get())
1825 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1826 screen_x, screen_y);
1827 if (GetRenderViewHost())
1828 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1829 screen_x, screen_y);
1830}
1831
[email protected]d60f3702013-12-26 16:30:241832void WebContentsImpl::DidGetResourceResponseStart(
1833 const ResourceRequestDetails& details) {
1834 controller_.ssl_manager()->DidStartResourceResponse(details);
1835
1836 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1837 DidGetResourceResponseStart(details));
1838
1839 // TODO(avi): Remove. http://crbug.com/170921
1840 NotificationService::current()->Notify(
1841 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1842 Source<WebContents>(this),
1843 Details<const ResourceRequestDetails>(&details));
1844}
1845
1846void WebContentsImpl::DidGetRedirectForResourceRequest(
1847 RenderViewHost* render_view_host,
1848 const ResourceRedirectDetails& details) {
1849 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1850
1851 FOR_EACH_OBSERVER(
1852 WebContentsObserver,
1853 observers_,
1854 DidGetRedirectForResourceRequest(render_view_host, details));
1855
1856 // TODO(avi): Remove. http://crbug.com/170921
1857 NotificationService::current()->Notify(
1858 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1859 Source<WebContents>(this),
1860 Details<const ResourceRedirectDetails>(&details));
1861}
1862
[email protected]b172aee2012-04-10 17:05:261863void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521864 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581865 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511866 if (delegate_)
1867 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291868 if (browser_plugin_embedder_.get())
1869 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341870}
1871
[email protected]e35ccd52012-05-23 16:22:471872void WebContentsImpl::UserGestureDone() {
1873 OnUserGesture();
1874}
1875
[email protected]b172aee2012-04-10 17:05:261876void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271877 closed_by_user_gesture_ = value;
1878}
1879
[email protected]b172aee2012-04-10 17:05:261880bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271881 return closed_by_user_gesture_;
1882}
1883
[email protected]b172aee2012-04-10 17:05:261884double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051885 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561886 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251887 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171888 return 0;
[email protected]b75b8292010-10-01 07:28:251889
1890 double zoom_level;
1891 if (temporary_zoom_settings_) {
1892 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581893 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251894 } else {
[email protected]2ae88d12011-10-14 09:11:191895 GURL url;
[email protected]6286a372013-10-09 04:03:271896 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191897 // Since zoom map is updated using rewritten URL, use rewritten URL
1898 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271899 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021900 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1901 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251902 }
[email protected]d0b8d092010-10-25 04:05:171903 return zoom_level;
1904}
[email protected]b75b8292010-10-01 07:28:251905
[email protected]b172aee2012-04-10 17:05:261906int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591907 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171908 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011909 // Calculate the zoom percent from the factor. Round up to the nearest whole
1910 // number.
[email protected]b75b8292010-10-01 07:28:251911 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491912 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251913 *enable_decrement = percent > minimum_zoom_percent_;
1914 *enable_increment = percent < maximum_zoom_percent_;
1915 return percent;
1916}
1917
[email protected]b172aee2012-04-10 17:05:261918void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501919 if (!delegate_)
1920 return;
1921
[email protected]6286a372013-10-09 04:03:271922 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1923 if (!entry)
[email protected]1788e772010-12-15 16:40:501924 return;
1925
[email protected]6286a372013-10-09 04:03:271926 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121927}
1928
[email protected]b172aee2012-04-10 17:05:261929void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041930 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271931 if (!delegate_)
1932 return;
1933
[email protected]691aa2f2013-05-28 22:52:041934 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271935}
1936
[email protected]b172aee2012-04-10 17:05:261937int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271938 return minimum_zoom_percent_;
1939}
1940
[email protected]b172aee2012-04-10 17:05:261941int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271942 return maximum_zoom_percent_;
1943}
1944
[email protected]b172aee2012-04-10 17:05:261945gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:491946 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:231947}
1948
[email protected]b172aee2012-04-10 17:05:261949bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271950 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581951 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271952}
1953
[email protected]b172aee2012-04-10 17:05:261954bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441955 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501956}
1957
[email protected]cb805452013-05-22 15:16:211958void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181959 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211960 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201961}
1962
[email protected]cb805452013-05-22 15:16:211963void WebContentsImpl::DidEndColorChooser() {
1964 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1965 color_chooser_identifier_));
1966 color_chooser_.reset();
1967 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201968}
1969
[email protected]41225fe2013-03-29 05:32:021970int WebContentsImpl::DownloadImage(const GURL& url,
1971 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301972 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021973 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391974 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301975 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021976 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391977 return id;
1978}
1979
[email protected]5dcaf8e2013-12-28 01:31:421980bool WebContentsImpl::IsSubframe() const {
1981 return is_subframe_;
1982}
1983
[email protected]9649d492014-01-10 07:15:521984void WebContentsImpl::SetZoomLevel(double level) {
1985 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
1986 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
1987 if (embedder)
1988 embedder->SetZoomLevel(level);
1989}
1990
[email protected]36ec24f2014-01-09 00:32:081991void WebContentsImpl::Find(int request_id,
1992 const base::string16& search_text,
1993 const blink::WebFindOptions& options) {
1994 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
1995}
1996
1997void WebContentsImpl::StopFinding(StopFindAction action) {
1998 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
1999}
2000
[email protected]b172aee2012-04-10 17:05:262001bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272002 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202003 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332004 return true;
2005 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272006}
2007
[email protected]b172aee2012-04-10 17:05:262008void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272009 if (delegate_)
2010 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212011}
2012
[email protected]52913802013-12-10 05:52:182013void WebContentsImpl::DidStartProvisionalLoad(
2014 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072015 int parent_routing_id,
[email protected]54047eb52012-05-08 21:45:572016 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182017 const GURL& validated_url,
2018 bool is_error_page,
2019 bool is_iframe_srcdoc) {
2020 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572021 DidChangeLoadProgress(0);
2022
[email protected]0d60f0192011-04-14 12:40:102023 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252024 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072025 DidStartProvisionalLoadForFrame(
2026 render_frame_host->GetRoutingID(), parent_routing_id,
2027 is_main_frame, validated_url, is_error_page,
2028 is_iframe_srcdoc,
2029 render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542030
2031 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182032 FOR_EACH_OBSERVER(
2033 WebContentsObserver,
2034 observers_,
2035 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582036 render_frame_host));
[email protected]400992b2012-06-14 00:03:542037 }
2038}
2039
[email protected]3109fbb72014-01-06 23:57:152040void WebContentsImpl::DidFailProvisionalLoadWithError(
2041 RenderFrameHostImpl* render_frame_host,
2042 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2043 GURL validated_url(params.url);
2044 FOR_EACH_OBSERVER(
2045 WebContentsObserver,
2046 observers_,
[email protected]501052ff2014-02-21 22:19:072047 DidFailProvisionalLoad(render_frame_host->GetRoutingID(),
[email protected]3109fbb72014-01-06 23:57:152048 params.frame_unique_name,
2049 params.is_main_frame,
2050 validated_url,
2051 params.error_code,
2052 params.error_description,
2053 render_frame_host->render_view_host()));
2054}
2055
[email protected]b80624c2014-02-09 02:46:552056void WebContentsImpl::DidFailLoadWithError(
2057 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552058 const GURL& url,
2059 bool is_main_frame,
2060 int error_code,
2061 const base::string16& error_description) {
2062 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072063 DidFailLoad(render_frame_host->GetRoutingID(),
2064 url, is_main_frame,
[email protected]b80624c2014-02-09 02:46:552065 error_code, error_description,
2066 render_frame_host->render_view_host()));
2067}
2068
[email protected]52913802013-12-10 05:52:182069void WebContentsImpl::NotifyChangedNavigationState(
2070 InvalidateTypes changed_flags) {
2071 NotifyNavigationStateChanged(changed_flags);
2072}
2073
[email protected]3691e5cf2014-01-22 10:16:202074void WebContentsImpl::AboutToNavigateRenderFrame(
2075 RenderFrameHostImpl* render_frame_host) {
2076 // Notify observers that we will navigate in this RenderView.
2077 FOR_EACH_OBSERVER(
2078 WebContentsObserver,
2079 observers_,
2080 AboutToNavigateRenderView(render_frame_host->render_view_host()));
2081}
2082
2083void WebContentsImpl::DidStartNavigationToPendingEntry(
2084 RenderFrameHostImpl* render_frame_host,
2085 const GURL& url,
2086 NavigationController::ReloadType reload_type) {
2087 // Notify observers about navigation.
2088 FOR_EACH_OBSERVER(
2089 WebContentsObserver,
2090 observers_,
2091 DidStartNavigationToPendingEntry(url, reload_type));
2092}
2093
[email protected]400992b2012-06-14 00:03:542094void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582095 RenderFrameHostImpl* render_frame_host,
2096 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542097 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582098 FOR_EACH_OBSERVER(
2099 WebContentsObserver,
2100 observers_,
2101 ProvisionalChangeToMainFrameUrl(validated_target_url,
2102 render_frame_host));
[email protected]724159a2010-12-30 01:11:182103}
2104
[email protected]37567b432014-02-12 01:12:222105void WebContentsImpl::DidCommitProvisionalLoad(
2106 int64 frame_id,
2107 const base::string16& frame_unique_name,
2108 bool is_main_frame,
2109 const GURL& url,
2110 PageTransition transition_type,
2111 RenderFrameHostImpl* render_frame_host) {
2112 RenderViewHost* render_view_host = render_frame_host->render_view_host();
2113 // Notify observers about the commit of the provisional load.
2114 FOR_EACH_OBSERVER(
2115 WebContentsObserver,
2116 observers_,
2117 DidCommitProvisionalLoadForFrame(frame_id,
2118 frame_unique_name,
2119 is_main_frame,
2120 url,
2121 transition_type,
2122 render_view_host));
2123}
2124
2125void WebContentsImpl::DidNavigateMainFramePostCommit(
2126 const LoadCommittedDetails& details,
2127 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2128 if (details.is_navigation_to_different_page()) {
2129 // Clear the status bubble. This is a workaround for a bug where WebKit
2130 // doesn't let us know that the cursor left an element during a
2131 // transition (this is also why the mouse cursor remains as a hand after
2132 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2133 // clear the bubble when a user navigates to a named anchor in the same
2134 // page.
2135 UpdateTargetURL(details.entry->GetPageID(), GURL());
2136 }
2137
2138 if (!details.is_in_page) {
2139 // Once the main frame is navigated, we're no longer considered to have
2140 // displayed insecure content.
2141 displayed_insecure_content_ = false;
2142 SSLManager::NotifySSLInternalStateChanged(
2143 GetController().GetBrowserContext());
2144 }
2145
2146 // Notify observers about navigation.
2147 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2148 DidNavigateMainFrame(details, params));
2149
2150 if (delegate_) {
2151 delegate_->DidNavigateMainFramePostCommit(this);
2152 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2153 }
2154}
2155
2156void WebContentsImpl::DidNavigateAnyFramePostCommit(
2157 RenderFrameHostImpl* render_frame_host,
2158 const LoadCommittedDetails& details,
2159 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2160 // If we navigate off the page, close all JavaScript dialogs.
2161 if (dialog_manager_ && !details.is_in_page)
2162 dialog_manager_->CancelActiveAndPendingDialogs(this);
2163
2164 // Notify observers about navigation.
2165 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2166 DidNavigateAnyFrame(details, params));
2167}
2168
2169void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2170 contents_mime_type_ = mime_type;
2171}
2172
2173bool WebContentsImpl::CanOverscrollContent() {
2174 if (delegate_)
2175 return delegate_->CanOverscrollContent();
2176
2177 return false;
2178}
2179
[email protected]b172aee2012-04-10 17:05:262180void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182181 const GURL& url,
[email protected]70435962011-08-02 20:13:282182 const std::string& security_info,
2183 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182184 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282185 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192186 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182187 cache.Increment();
2188
2189 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082190 int cert_id = 0;
2191 net::CertStatus cert_status = 0;
2192 int security_bits = -1;
2193 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122194 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212195 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122196 &security_bits, &connection_status,
2197 &signed_certificate_timestamp_ids);
2198 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212199 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002200 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2201 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182202
[email protected]b0f724c2013-09-05 04:21:132203 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2204
2205 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2206 DidLoadResourceFromMemoryCache(details));
2207
[email protected]8bfc8272013-09-09 20:10:532208 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2209 scoped_refptr<net::URLRequestContextGetter> request_context(
2210 resource_type == ResourceType::MEDIA ?
2211 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2212 GetRenderProcessHost()->GetID()) :
2213 GetBrowserContext()->GetRequestContextForRenderProcess(
2214 GetRenderProcessHost()->GetID()));
2215 BrowserThread::PostTask(
2216 BrowserThread::IO,
2217 FROM_HERE,
2218 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2219 }
[email protected]724159a2010-12-30 01:11:182220}
2221
[email protected]b172aee2012-04-10 17:05:262222void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392223 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182224 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192225 SSLManager::NotifySSLInternalStateChanged(
2226 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182227}
2228
[email protected]b172aee2012-04-10 17:05:262229void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022230 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582231 LOG(WARNING) << security_origin << " ran insecure content from "
2232 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392233 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412234 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392235 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182236 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412237 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192238 SSLManager::NotifySSLInternalStateChanged(
2239 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182240}
2241
[email protected]501052ff2014-02-21 22:19:072242void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572243 CHECK(render_frame_message_source_);
2244 CHECK(!render_view_message_source_);
2245 RenderFrameHostImpl* rfh =
2246 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2247
2248 FOR_EACH_OBSERVER(WebContentsObserver,
2249 observers_,
[email protected]501052ff2014-02-21 22:19:072250 DocumentLoadedInFrame(rfh->GetRoutingID(),
2251 rfh->render_view_host()));
[email protected]724159a2010-12-30 01:11:182252}
2253
[email protected]b172aee2012-04-10 17:05:262254void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312255 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062256 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312257 bool is_main_frame) {
[email protected]8b3af1e2014-01-24 13:29:122258 if (!render_view_message_source_) {
2259 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2260 GetRenderProcessHost()->ReceivedBadMessage();
2261 return;
2262 }
[email protected]a1b99262013-12-27 21:56:222263
2264 // --site-per-process mode has a short-term hack allowing cross-process
2265 // subframe pages to commit thinking they are top-level. Correct it here to
2266 // avoid confusing the observers.
2267 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2268 render_view_message_source_ != GetRenderViewHost())
2269 is_main_frame = false;
2270
[email protected]8b3af1e2014-01-24 13:29:122271 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442272 RenderProcessHost* render_process_host =
2273 render_view_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422274 render_process_host->FilterURL(false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252275 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472276 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]f114fa42013-12-06 17:06:442277 render_view_message_source_));
[email protected]1a55c5be2011-11-29 11:36:312278}
2279
[email protected]b172aee2012-04-10 17:05:262280void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262281 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232282 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252283 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262284 if (!entry)
2285 return;
2286 // Note that we don't call NavigationController::GotToOffset() as we don't
2287 // want to create a pending navigation entry (it might end up lingering
2288 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252289 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212290 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512291 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212292 PAGE_TRANSITION_FORWARD_BACK));
[email protected]3691e5cf2014-01-22 10:16:202293 frame_tree_.root()->navigator()->NavigateToEntry(
2294 frame_tree_.GetMainFrame(),
2295 *entry,
2296 NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572297
2298 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2299 // it in now that we know. This allows us to find the entry when it commits.
2300 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232301 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332302 entry->set_site_instance(
2303 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572304 }
[email protected]216813952011-05-19 22:21:262305 }
2306}
2307
[email protected]b172aee2012-04-10 17:05:262308void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2309 int maximum_percent,
2310 bool remember) {
[email protected]216813952011-05-19 22:21:262311 minimum_zoom_percent_ = minimum_percent;
2312 maximum_zoom_percent_ = maximum_percent;
2313 temporary_zoom_settings_ = !remember;
2314}
2315
[email protected]b172aee2012-04-10 17:05:262316void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342317 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432318 if (!delegate_)
2319 return;
2320
[email protected]b9535422012-02-09 01:47:592321 ChildProcessSecurityPolicyImpl* policy =
2322 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222323 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592324 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212325}
2326
[email protected]b172aee2012-04-10 17:05:262327void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432328 if (delegate_)
2329 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202330}
2331
[email protected]b172aee2012-04-10 17:05:262332void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2333 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262334 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362335 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432336 if (!delegate_)
2337 return;
2338
[email protected]b9535422012-02-09 01:47:592339 ChildProcessSecurityPolicyImpl* policy =
2340 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322341 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592342 return;
[email protected]8f810632013-06-06 22:33:322343
[email protected]3a3b75a2012-06-01 08:38:362344 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202345}
2346
[email protected]b172aee2012-04-10 17:05:262347void WebContentsImpl::OnFindReply(int request_id,
2348 int number_of_matches,
2349 const gfx::Rect& selection_rect,
2350 int active_match_ordinal,
2351 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432352 if (delegate_) {
2353 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2354 active_match_ordinal, final_update);
2355 }
[email protected]b888919c2011-09-02 00:32:162356}
2357
[email protected]59363fc92012-09-05 03:46:312358#if defined(OS_ANDROID)
2359void WebContentsImpl::OnFindMatchRectsReply(
2360 int version,
2361 const std::vector<gfx::RectF>& rects,
2362 const gfx::RectF& active_rect) {
2363 if (delegate_)
2364 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2365}
[email protected]583418cc2013-01-17 14:01:102366
[email protected]1ff427972013-02-07 21:14:072367void WebContentsImpl::OnOpenDateTimeDialog(
2368 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092369 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2370 GetRenderViewHost(),
2371 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132372 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092373 value.minimum,
2374 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172375 value.step,
2376 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102377}
2378
[email protected]a794f3a2013-10-30 17:00:322379void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2380 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]f114fa42013-12-06 17:06:442381 render_view_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322382}
2383
[email protected]59363fc92012-09-05 03:46:312384#endif
2385
[email protected]f114fa42013-12-06 17:06:442386void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2387 const base::FilePath& path,
2388 bool is_hung) {
2389 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2390
2391 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2392 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2393}
2394
2395void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422396 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442397 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422398 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452399}
2400
[email protected]cfa856d62014-02-22 07:58:402401void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2402 int automation_id) {
2403 DomOperationNotificationDetails details(json_string, automation_id);
2404 NotificationService::current()->Notify(
2405 NOTIFICATION_DOM_OPERATION_RESPONSE,
2406 Source<WebContents>(this),
2407 Details<DomOperationNotificationDetails>(&details));
2408}
2409
[email protected]b172aee2012-04-10 17:05:262410void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2411 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102412 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252413 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102414 AppCacheAccessed(manifest_url, blocked_by_policy));
2415}
2416
[email protected]8bc5ff02013-11-29 06:34:032417void WebContentsImpl::OnOpenColorChooser(
2418 int color_chooser_id,
2419 SkColor color,
2420 const std::vector<ColorSuggestion>& suggestions) {
2421 ColorChooser* new_color_chooser =
2422 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302423 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212424 return;
[email protected]820957a2014-01-14 14:56:302425 if (color_chooser_)
2426 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212427 color_chooser_.reset(new_color_chooser);
2428 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202429}
2430
[email protected]b172aee2012-04-10 17:05:262431void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202432 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212433 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202434 color_chooser_->End();
2435}
2436
[email protected]b172aee2012-04-10 17:05:262437void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322438 SkColor color) {
[email protected]da8543762012-03-20 08:52:202439 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212440 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202441 color_chooser_->SetSelectedColor(color);
2442}
2443
[email protected]d0759f492012-04-19 22:50:502444// This exists for render views that don't have a WebUI, but do have WebUI
2445// bindings enabled.
2446void WebContentsImpl::OnWebUISend(const GURL& source_url,
2447 const std::string& name,
2448 const base::ListValue& args) {
2449 if (delegate_)
2450 delegate_->WebUISend(this, source_url, name, args);
2451}
2452
[email protected]d8415ad92012-08-23 14:40:502453void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442454 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502455 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342456 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162457 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442458 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162459 return;
[email protected]d8415ad92012-08-23 14:40:502460 }
2461
[email protected]8c8fc292012-11-23 18:57:162462 if (!delegate_->RequestPpapiBrokerPermission(
2463 this, url, plugin_path,
2464 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442465 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162466 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442467 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162468 }
[email protected]d8415ad92012-08-23 14:40:502469}
2470
[email protected]ea0309c2013-08-06 19:35:442471void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502472 bool result) {
[email protected]ea0309c2013-08-06 19:35:442473 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502474}
2475
[email protected]c4538072013-03-18 02:17:552476void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372477 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082478 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552479 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392480 // For more info, see comment above classes BrowserPluginEmbedder and
2481 // BrowserPluginGuest.
2482 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142483 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082484 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372485}
2486
[email protected]41225fe2013-03-29 05:32:022487void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392488 int id,
[email protected]749fadd2013-05-15 08:37:482489 int http_status_code,
[email protected]795c28972012-12-06 06:13:392490 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302491 const std::vector<SkBitmap>& bitmaps,
2492 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132493 if (bitmaps.size() != original_bitmap_sizes.size())
2494 return;
2495
[email protected]41225fe2013-03-29 05:32:022496 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2497 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392498 // Currently WebContents notifies us of ANY downloads so that it is
2499 // possible to get here.
2500 return;
2501 }
2502 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302503 iter->second.Run(
2504 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392505 }
[email protected]41225fe2013-03-29 05:32:022506 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392507}
2508
2509void WebContentsImpl::OnUpdateFaviconURL(
2510 int32 page_id,
2511 const std::vector<FaviconURL>& candidates) {
2512 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2513 DidUpdateFaviconURL(page_id, candidates));
2514}
2515
[email protected]1dd0bb752014-02-01 01:16:262516void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2517 bool has_video,
2518 bool has_audio) {
2519// Chrome OS does its own detection of audio and video.
2520#if !defined(OS_CHROMEOS)
2521 scoped_ptr<PowerSaveBlocker> blocker;
2522 if (has_video) {
2523 blocker = PowerSaveBlocker::Create(
2524 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2525#if defined(OS_ANDROID)
2526 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2527 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2528#endif
2529 } else if (has_audio) {
2530 blocker = PowerSaveBlocker::Create(
2531 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2532 }
2533
2534 if (blocker) {
2535 power_save_blockers_[render_view_message_source_][player_cookie] =
2536 blocker.release();
2537 }
2538#endif // !defined(OS_CHROMEOS)
2539}
2540
2541void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062542 // Chrome OS does its own detection of audio and video.
2543#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262544 delete power_save_blockers_[render_view_message_source_][player_cookie];
2545 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062546#endif // !defined(OS_CHROMEOS)
2547}
2548
[email protected]9f268072013-11-07 00:02:152549void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2550 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2551 DidFirstVisuallyNonEmptyPaint(page_id));
2552}
[email protected]d9030b82013-07-19 08:26:062553
[email protected]e67ebf32013-02-13 11:07:192554void WebContentsImpl::DidChangeVisibleSSLState() {
2555 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2556 DidChangeVisibleSSLState());
2557}
2558
[email protected]17e286e2013-03-01 23:29:392559void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2560 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2561 BeforeFormRepostWarningShow());
2562}
2563
[email protected]ec6c05f2013-10-23 18:41:572564
2565void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2566 Activate();
2567 if (delegate_)
2568 delegate_->ShowRepostFormWarningDialog(this);
2569}
2570
[email protected]96d185d2009-04-24 03:28:542571// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592572// loading, or done loading.
2573void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2574 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262575 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542576 if (is_loading == is_loading_)
2577 return;
2578
2579 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262580 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2581 base::string16());
[email protected]96d185d2009-04-24 03:28:542582 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562583 upload_size_ = 0;
2584 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542585 }
2586
[email protected]fa944cb82013-11-15 17:51:212587 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542588
2589 is_loading_ = is_loading;
2590 waiting_for_response_ = is_loading;
2591
[email protected]6ebdc9b2010-09-27 16:55:572592 if (delegate_)
2593 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212594 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542595
[email protected]eab61442013-11-14 18:35:482596 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592597 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482598 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2599 "URL", url);
[email protected]91621872013-10-08 04:04:592600 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2601 DidStartLoading(render_view_host));
2602 } else {
[email protected]eab61442013-11-14 18:35:482603 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2604 "URL", url);
[email protected]91621872013-10-08 04:04:592605 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2606 DidStopLoading(render_view_host));
2607 }
[email protected]66798902013-10-01 18:40:162608
2609 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212610 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2611 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542612 if (details)
[email protected]8ff00d72012-10-23 19:12:212613 det = Details<LoadNotificationDetails>(details);
2614 NotificationService::current()->Notify(
2615 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542616}
2617
[email protected]b172aee2012-04-10 17:05:262618void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462619 // If we are creating a RVH for a restored controller, then we need to make
2620 // sure the RenderView starts with a next_page_id_ larger than the number
2621 // of restored entries. This must be called before the RenderView starts
2622 // navigating (to avoid a race between the browser updating max_page_id and
2623 // the renderer updating next_page_id_). Because of this, we only call this
2624 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562625 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582626 if (max_restored_page_id >
2627 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2628 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2629 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322630}
2631
[email protected]b172aee2012-04-10 17:05:262632bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262633 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322634 // For file URLs without a title, use the pathname instead. In the case of a
2635 // synthesized title, we don't want the update to count toward the "one set
2636 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262637 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322638 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512639 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242640 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322641 explicit_set = false; // Don't count synthetic titles toward the set limit.
2642 } else {
[email protected]acafd272011-07-26 17:35:572643 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322644 explicit_set = true;
2645 }
2646
[email protected]987fc3a2011-05-26 14:18:092647 // If a page is created via window.open and never navigated,
2648 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552649 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092650 if (entry) {
[email protected]36fc0392011-12-25 03:59:512651 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092652 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322653
[email protected]36fc0392011-12-25 03:59:512654 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092655 } else {
2656 if (page_title_when_no_navigation_entry_ == final_title)
2657 return false; // Nothing changed, don't bother.
2658
2659 page_title_when_no_navigation_entry_ = final_title;
2660 }
[email protected]420ae012009-04-24 05:16:322661
[email protected]420ae012009-04-24 05:16:322662 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232663 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322664
[email protected]66798902013-10-01 18:40:162665 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532666 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162667
2668 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212669 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462670 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212671 NotificationService::current()->Notify(
2672 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2673 Source<WebContents>(this),
2674 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042675
[email protected]420ae012009-04-24 05:16:322676 return true;
2677}
2678
[email protected]7b712ee22013-10-03 00:57:282679void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2680 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322681 // After sending out a swap notification, we need to send a disconnect
2682 // notification so that clients that pick up a pointer to |this| can NULL the
2683 // pointer. See Bug 1230284.
2684 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112685 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282686 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112687
2688 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282689 std::pair<RenderViewHost*, RenderViewHost*> details =
2690 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212691 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282692 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212693 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282694 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392695
2696 // Ensure that the associated embedder gets cleared after a RenderViewHost
2697 // gets swapped, so we don't reuse the same embedder next time a
2698 // RenderViewHost is attached to this WebContents.
2699 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322700}
2701
[email protected]da7a7182013-09-06 08:11:112702// TODO(avi): Remove this entire function because this notification is already
2703// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262704void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322705 if (!notify_disconnection_)
2706 return;
2707
2708 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212709 NotificationService::current()->Notify(
2710 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2711 Source<WebContents>(this),
2712 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322713}
2714
[email protected]cbb1ef592013-06-05 19:49:462715void WebContentsImpl::NotifyNavigationEntryCommitted(
2716 const LoadCommittedDetails& load_details) {
2717 FOR_EACH_OBSERVER(
2718 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2719}
2720
[email protected]f114fa42013-12-06 17:06:442721bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2722 const IPC::Message& message) {
2723 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312724}
2725
[email protected]b849847b2013-12-10 21:57:582726void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2727 // Note this is only for subframes, the notification for the main frame
2728 // happens in RenderViewCreated.
2729 FOR_EACH_OBSERVER(WebContentsObserver,
2730 observers_,
2731 RenderFrameCreated(render_frame_host));
2732}
2733
2734void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2735 FOR_EACH_OBSERVER(WebContentsObserver,
2736 observers_,
2737 RenderFrameDeleted(render_frame_host));
2738}
2739
[email protected]a09d53ce2014-01-31 00:46:422740void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302741 if (delegate_)
2742 delegate_->WorkerCrashed(this);
2743}
2744
[email protected]a09d53ce2014-01-31 00:46:422745void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2746 const ContextMenuParams& params) {
2747 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:402748 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:422749 return;
2750
2751 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2752}
2753
[email protected]a86c0e962013-12-17 17:10:392754WebContents* WebContentsImpl::GetAsWebContents() {
2755 return this;
2756}
2757
[email protected]5a3bdf52012-05-24 15:12:572758RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2759 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322760}
2761
[email protected]8d3347f2009-07-09 22:00:212762RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262763WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212764 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212765}
2766
[email protected]8ff00d72012-10-23 19:12:212767RendererPreferences WebContentsImpl::GetRendererPrefs(
2768 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462769 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512770}
2771
[email protected]b172aee2012-04-10 17:05:262772gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172773 if (delegate_)
2774 return delegate_->GetRootWindowResizerRect();
2775 return gfx::Rect();
2776}
2777
[email protected]7a846df2012-09-20 19:17:392778void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272779 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392780 browser_plugin_embedder_.reset();
2781}
2782
[email protected]b172aee2012-04-10 17:05:262783void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442784 // Don't send notifications if we are just creating a swapped-out RVH for
2785 // the opener chain. These won't be used for view-source or WebUI, so it's
2786 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:242787 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:442788 return;
2789
[email protected]86f98a22013-03-20 14:35:002790 if (delegate_)
2791 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082792
[email protected]8ff00d72012-10-23 19:12:212793 NotificationService::current()->Notify(
2794 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2795 Source<WebContents>(this),
2796 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322797
2798 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352799 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212800 if (GetRenderManager()->pending_web_ui())
2801 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322802
[email protected]6286a372013-10-09 04:03:272803 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332804 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322805 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182806 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582807 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322808 }
[email protected]0666aef2009-05-13 19:48:082809
[email protected]60780f412013-02-25 16:34:102810 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262811
2812 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252813 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582814
2815 // We tell the observers now instead of when the main RenderFrameHostImpl is
2816 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2817 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:362818 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:582819 FOR_EACH_OBSERVER(
2820 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322821}
2822
[email protected]b172aee2012-04-10 17:05:262823void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522824 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322825 // Don't notify the world, since this came from a renderer in the
2826 // background.
2827 return;
2828 }
2829
[email protected]da7a7182013-09-06 08:11:112830 notify_disconnection_ = true;
2831 // TODO(avi): Remove. http://crbug.com/170921
2832 NotificationService::current()->Notify(
2833 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2834 Source<WebContents>(this),
2835 NotificationService::NoDetails());
2836
[email protected]be1f56ab2011-12-22 06:55:312837 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232838 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302839
2840 // Restore the focus to the tab (otherwise the focus will be on the top
2841 // window).
[email protected]484ae5912010-09-29 19:16:142842 if (was_crashed && !FocusLocationBarByDefault() &&
2843 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062844 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142845 }
[email protected]32ded2212011-11-10 18:51:432846
[email protected]d8c660432011-12-22 20:51:252847 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322848}
2849
[email protected]ec6a7eb2013-04-22 17:34:222850void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2851 base::TerminationStatus status,
2852 int error_code) {
[email protected]151a63d2011-12-20 22:32:522853 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322854 // The pending page's RenderViewHost is gone.
2855 return;
2856 }
2857
[email protected]698191dc2014-02-25 01:06:132858 // Cancel any visible dialogs so they are not left dangling over the sad tab.
2859 if (dialog_manager_)
2860 dialog_manager_->CancelActiveAndPendingDialogs(this);
2861
[email protected]d9030b82013-07-19 08:26:062862 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592863 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322864 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232865 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312866 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322867
[email protected]d8c660432011-12-22 20:51:252868 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272869 observers_,
[email protected]58d5cfe2013-07-10 02:40:522870 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322871}
2872
[email protected]b172aee2012-04-10 17:05:262873void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062874 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212875 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252876 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062877}
2878
[email protected]b172aee2012-04-10 17:05:262879void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2880 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042881 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152882 // Ensure that this state update comes from either the active RVH or one of
2883 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412884 // TODO(nasko): This should go through RenderFrameHost.
2885 // TODO(creis): We can't update state for cross-process subframes until we
2886 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2887 if (rvh != GetRenderViewHost() &&
2888 !GetRenderManager()->IsRVHOnSwappedOutList(
2889 static_cast<RenderViewHostImpl*>(rvh)))
2890 return;
[email protected]420ae012009-04-24 05:16:322891
2892 // We must be prepared to handle state updates for any page, these occur
2893 // when the user is scrolling and entering form data, as well as when we're
2894 // leaving a page, in which case our state may have already been moved to
2895 // the next page. The navigation controller will look up the appropriate
2896 // NavigationEntry and update it when it is notified via the delegate.
2897
2898 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582899 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322900 if (entry_index < 0)
2901 return;
[email protected]10f417c52011-12-28 21:04:232902 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322903
[email protected]691aa2f2013-05-28 22:52:042904 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322905 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042906 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322907 controller_.NotifyEntryChanged(entry, entry_index);
2908}
2909
[email protected]b172aee2012-04-10 17:05:262910void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2911 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262912 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262913 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322914 // If we have a title, that's a pretty good indication that we've started
2915 // getting useful data.
2916 SetNotWaitingForResponse();
2917
[email protected]73eb2602012-02-09 19:50:552918 // Try to find the navigation entry, which might not be the current one.
2919 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232920 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582921 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092922
[email protected]73eb2602012-02-09 19:50:552923 // We can handle title updates when we don't have an entry in
2924 // UpdateTitleForEntry, but only if the update is from the current RVH.
2925 if (!entry && rvh != GetRenderViewHost())
2926 return;
2927
[email protected]a49e10b2011-08-01 23:57:462928 // TODO(evan): make use of title_direction.
2929 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092930 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322931 return;
2932
2933 // Broadcast notifications when the UI should be updated.
2934 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212935 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322936}
2937
[email protected]b172aee2012-04-10 17:05:262938void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2939 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312940 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322941}
2942
[email protected]b172aee2012-04-10 17:05:262943void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512944 if (delegate_)
2945 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322946}
2947
[email protected]b172aee2012-04-10 17:05:262948void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:102949#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:292950 // The UI may be in an event-tracking loop, such as between the
2951 // mouse-down and mouse-up in text selection or a button click.
2952 // Defer the close until after tracking is complete, so that we
2953 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292954 // TODO(shess): This could get more fine-grained. For instance,
2955 // closing a tab in another window while selecting text in the
2956 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:102957 if (view_->IsEventTracking()) {
2958 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292959 return;
2960 }
[email protected]60780f412013-02-25 16:34:102961#endif
[email protected]07707302009-11-06 00:50:292962
[email protected]420ae012009-04-24 05:16:322963 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522964 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512965 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322966}
2967
[email protected]b172aee2012-04-10 17:05:262968void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522969 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512970 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:282971
2972 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:212973 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:572974}
2975
[email protected]b172aee2012-04-10 17:05:262976void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512977 if (delegate_ && delegate_->IsPopupOrPanel(this))
2978 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322979}
2980
[email protected]723971b2014-02-12 11:08:252981void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host) {
2982 SetIsLoading(render_frame_host->GetRenderViewHost(), true, NULL);
[email protected]420ae012009-04-24 05:16:322983}
2984
[email protected]723971b2014-02-12 11:08:252985void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:322986 scoped_ptr<LoadNotificationDetails> details;
2987
[email protected]9595fd82013-04-19 21:28:492988 // Use the last committed entry rather than the active one, in case a
2989 // pending entry has been created.
2990 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:202991 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:492992
[email protected]420ae012009-04-24 05:16:322993 // An entry may not exist for a stop when loading an initial blank page or
2994 // if an iframe injected by script into a blank page finishes loading.
2995 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:202996 base::TimeDelta elapsed =
2997 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:322998
2999 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513000 entry->GetVirtualURL(),
3001 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323002 elapsed,
3003 &controller_,
3004 controller_.GetCurrentEntryIndex()));
3005 }
3006
[email protected]723971b2014-02-12 11:08:253007 SetIsLoading(render_frame_host->GetRenderViewHost(), false, details.get());
[email protected]420ae012009-04-24 05:16:323008}
3009
[email protected]b172aee2012-04-10 17:05:263010void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163011 controller_.DiscardNonCommittedEntries();
3012
3013 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213014 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163015}
3016
[email protected]b172aee2012-04-10 17:05:263017void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513018 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133019 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403020}
3021
[email protected]7cc78902012-12-06 02:32:263022void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393023 if (opener_) {
3024 // Clear our opener so that future cross-process navigations don't have an
3025 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103026 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393027 opener_ = NULL;
3028 }
[email protected]7cc78902012-12-06 02:32:263029
3030 // Notify all swapped out RenderViewHosts for this tab. This is important
3031 // in case we go back to them, or if another window in those processes tries
3032 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213033 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263034}
3035
[email protected]59167c22013-06-03 18:07:323036void WebContentsImpl::DidAccessInitialDocument() {
3037 // Update the URL display.
3038 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3039}
3040
[email protected]87717d0e2012-04-26 02:58:433041void WebContentsImpl::DocumentAvailableInMainFrame(
3042 RenderViewHost* render_view_host) {
3043 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3044 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103045}
3046
[email protected]b172aee2012-04-10 17:05:263047void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083048 RenderViewHost* render_view_host,
3049 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093050 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3051 DocumentOnLoadCompletedInMainFrame(page_id));
3052
3053 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213054 NotificationService::current()->Notify(
3055 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3056 Source<WebContents>(this),
3057 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083058}
3059
[email protected]196159d2012-05-04 17:26:543060void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3061 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213062 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263063 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183064 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523065 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303066 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543067 // If this came from a swapped out RenderViewHost, we only allow the request
3068 // if we are still in the same BrowsingInstance.
[email protected]21b41c7e892014-02-28 01:52:243069 if (static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() &&
[email protected]196159d2012-05-04 17:26:543070 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3071 return;
3072 }
3073
[email protected]4ad5d77d2011-12-03 02:00:483074 // Delegate to RequestTransferURL because this is just the generic
3075 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573076 // TODO(creis): Pass the redirect_chain into this method to support client
3077 // redirects. http://crbug.com/311721.
3078 std::vector<GURL> redirect_chain;
3079 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3080 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523081 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483082}
3083
[email protected]b172aee2012-04-10 17:05:263084void WebContentsImpl::RequestTransferURL(
3085 const GURL& url,
[email protected]f8872902013-10-30 03:18:573086 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213087 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573088 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263089 WindowOpenDisposition disposition,
3090 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183091 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523092 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303093 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203094 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123095 GURL dest_url(url);
3096 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553097 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123098 dest_url = GURL(kAboutBlankURL);
3099
[email protected]a1b99262013-12-27 21:56:223100 // Look up the FrameTreeNode ID corresponding to source_frame_id.
3101 int64 frame_tree_node_id = -1;
3102 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
3103 source_frame_id != -1) {
[email protected]58faf942014-02-20 21:03:583104 FrameTreeNode* source_node = frame_tree_.FindByRoutingID(
3105 source_frame_id, old_request_id.child_id);
[email protected]a1b99262013-12-27 21:56:223106 if (source_node)
3107 frame_tree_node_id = source_node->frame_tree_node_id();
3108 }
[email protected]c80297782013-11-21 07:10:163109 OpenURLParams params(dest_url, referrer, source_frame_id,
3110 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573111 page_transition, true /* is_renderer_initiated */);
3112 if (redirect_chain.size() > 0)
3113 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553114 params.transferred_global_request_id = old_request_id;
3115 params.should_replace_current_entry = should_replace_current_entry;
3116 params.user_gesture = user_gesture;
3117
[email protected]fa944cb82013-11-15 17:51:213118 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573119 // Web UI pages sometimes want to override the page transition type for
3120 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3121 // automatically generated suggestions). We don't override other types
3122 // like TYPED because they have different implications (e.g., autocomplete).
3123 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213124 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553125
[email protected]e0112912011-02-02 22:54:353126 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163127 // want web sites to see a referrer of "chrome://blah" (and some
3128 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323129 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553130 params.referrer = Referrer();
3131
3132 // Navigations in Web UI pages count as browser-initiated navigations.
3133 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583134 }
[email protected]44d0930a2013-10-28 18:53:553135
3136 new_contents = OpenURL(params);
3137
[email protected]ae5184d62011-10-06 19:25:583138 if (new_contents) {
3139 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253140 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583141 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123142 dest_url,
[email protected]ae5184d62011-10-06 19:25:583143 referrer,
3144 disposition,
[email protected]44d0930a2013-10-28 18:53:553145 params.transition,
[email protected]ae5184d62011-10-06 19:25:583146 source_frame_id));
[email protected]420ae012009-04-24 05:16:323147 }
3148}
3149
[email protected]e1c3a552012-05-04 20:51:323150void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3151 // Tell the active RenderViewHost to run unload handlers and close, as long
3152 // as the request came from a RenderViewHost in the same BrowsingInstance.
3153 // In most cases, we receive this from a swapped out RenderViewHost.
3154 // It is possible to receive it from one that has just been swapped in,
3155 // in which case we might as well deliver the message anyway.
3156 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3157 GetRenderViewHost()->ClosePage();
3158}
3159
[email protected]f546640b2012-05-15 00:03:493160void WebContentsImpl::RouteMessageEvent(
3161 RenderViewHost* rvh,
3162 const ViewMsg_PostMessage_Params& params) {
3163 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363164 // came from a RenderViewHost in the same BrowsingInstance or if this
3165 // WebContents is dedicated to a browser plugin guest.
3166 // Note: This check means that an embedder could theoretically receive a
3167 // postMessage from anyone (not just its own guests). However, this is
3168 // probably not a risk for apps since other pages won't have references
3169 // to App windows.
3170 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3171 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493172 return;
3173
3174 ViewMsg_PostMessage_Params new_params(params);
3175
[email protected]0bc7f3542013-10-21 15:05:533176 if (!params.message_port_ids.empty()) {
3177 MessagePortMessageFilter* message_port_message_filter =
3178 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3179 ->message_port_message_filter();
3180 std::vector<int> new_routing_ids(params.message_port_ids.size());
3181 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3182 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3183 MessagePortService::GetInstance()->UpdateMessagePort(
3184 params.message_port_ids[i],
3185 message_port_message_filter,
3186 new_routing_ids[i]);
3187 }
3188 new_params.new_routing_ids = new_routing_ids;
3189 }
3190
[email protected]f546640b2012-05-15 00:03:493191 // If there is a source_routing_id, translate it to the routing ID for
3192 // the equivalent swapped out RVH in the target process. If we need
3193 // to create a swapped out RVH for the source tab, we create its opener
3194 // chain as well, since those will also be accessible to the target page.
3195 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3196 // Try to look up the WebContents for the source page.
3197 WebContentsImpl* source_contents = NULL;
3198 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3199 rvh->GetProcess()->GetID(), params.source_routing_id);
3200 if (source_rvh) {
3201 source_contents = static_cast<WebContentsImpl*>(
3202 source_rvh->GetDelegate()->GetAsWebContents());
3203 }
3204
3205 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363206 if (GetBrowserPluginGuest()) {
3207 // We create a swapped out RenderView for the embedder in the guest's
3208 // render process but we intentionally do not expose the embedder's
3209 // opener chain to it.
3210 new_params.source_routing_id =
3211 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3212 } else {
3213 new_params.source_routing_id =
3214 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3215 }
[email protected]f546640b2012-05-15 00:03:493216 } else {
3217 // We couldn't find it, so don't pass a source frame.
3218 new_params.source_routing_id = MSG_ROUTING_NONE;
3219 }
3220 }
3221
3222 // In most cases, we receive this from a swapped out RenderViewHost.
3223 // It is possible to receive it from one that has just been swapped in,
3224 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183225 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493226}
3227
[email protected]b172aee2012-04-10 17:05:263228void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343229 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263230 const base::string16& message,
3231 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323232 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213233 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323234 IPC::Message* reply_msg,
3235 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073236 // Suppress JavaScript dialogs when requested. Also suppress messages when
3237 // showing an interstitial as it's shown over the previous page and we don't
3238 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503239 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243240 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() ||
[email protected]0bfbf882011-12-22 18:19:273241 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073242 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523243 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153244 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323245
3246 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213247 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433248 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153249 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3250 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433251 this,
3252 frame_url.GetOrigin(),
3253 accept_lang,
3254 javascript_message_type,
3255 message,
[email protected]51da7e32012-01-30 19:24:523256 default_prompt,
[email protected]b172aee2012-04-10 17:05:263257 base::Bind(&WebContentsImpl::OnDialogClosed,
3258 base::Unretained(this),
3259 rvh,
3260 reply_msg),
[email protected]51da7e32012-01-30 19:24:523261 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323262 }
[email protected]3ab9cb82011-06-03 18:02:073263
[email protected]6dd2f1e2013-09-11 15:06:013264 *did_suppress_message = suppress_this_message;
3265
[email protected]3ab9cb82011-06-03 18:02:073266 if (suppress_this_message) {
3267 // If we are suppressing messages, just reply as if the user immediately
3268 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263269 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073270 }
3271
[email protected]6dd2f1e2013-09-11 15:06:013272 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3273 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323274}
3275
[email protected]b172aee2012-04-10 17:05:263276void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263277 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263278 bool is_reload,
3279 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583280 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513281 if (delegate_)
3282 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073283
3284 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243285 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
[email protected]3ab9cb82011-06-03 18:02:073286 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523287 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153288 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153289 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343290 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263291 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503292 return;
3293 }
[email protected]3ab9cb82011-06-03 18:02:073294
[email protected]7ab1e7d62009-10-14 23:32:013295 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153296 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3297 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323298 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263299 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523300 reply_msg));
[email protected]420ae012009-04-24 05:16:323301}
3302
[email protected]a796f202012-05-30 14:14:253303bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263304 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253305 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263306 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253307 if (!delegate_)
3308 return false;
3309 return delegate_->AddMessageToConsole(this, level, message, line_no,
3310 source_id);
3311}
3312
[email protected]b172aee2012-04-10 17:05:263313WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273314 // We want to base the page config off of the actual URL, rather than the
3315 // virtual URL.
3316 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3317 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003318 GURL url = controller_.GetActiveEntry()
3319 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153320
[email protected]fa944cb82013-11-15 17:51:213321 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323322}
3323
[email protected]0eba810b2012-10-18 03:19:363324int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213325 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413326 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3327 true, true);
[email protected]0eba810b2012-10-18 03:19:363328}
3329
[email protected]b172aee2012-04-10 17:05:263330void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273331 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253332 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223333
[email protected]ea114722012-03-12 01:11:253334 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173335 if (rdh) // NULL in unittests.
3336 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253337}
3338
[email protected]b172aee2012-04-10 17:05:263339void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443340 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253341 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443342}
3343
[email protected]b172aee2012-04-10 17:05:263344void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563345 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263346 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153347 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523348 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153349 return;
3350
[email protected]9f76c1e2012-03-05 15:15:583351 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3352
[email protected]e5fc1632011-08-08 07:51:533353 // Ignore renderer unresponsive event if debugger is attached to the tab
3354 // since the event may be a result of the renderer sitting on a breakpoint.
3355 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363356 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533357 return;
3358
[email protected]2e9d79f2013-08-16 05:45:563359 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323360 // Hang occurred while firing the beforeunload/unload handler.
3361 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583362 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323363
[email protected]fa944cb82013-11-15 17:51:213364 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323365 return;
3366
3367 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563368 // nothing we can do to recover. If the hang is in the beforeunload handler,
3369 // pretend the beforeunload listeners have all fired and allow the delegate
3370 // to continue closing; the user will not have the option of cancelling the
3371 // close. Otherwise, pretend the unload listeners have all fired and close
3372 // the tab.
3373 bool close = true;
3374 if (is_during_beforeunload) {
3375 delegate_->BeforeUnloadFired(this, true, &close);
3376 }
3377 if (close)
3378 Close(rvh);
[email protected]420ae012009-04-24 05:16:323379 return;
3380 }
3381
[email protected]9f76c1e2012-03-05 15:15:583382 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473383 return;
3384
[email protected]6934a702011-12-20 00:04:513385 if (delegate_)
3386 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323387}
3388
[email protected]b172aee2012-04-10 17:05:263389void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513390 if (delegate_)
3391 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323392}
3393
[email protected]b172aee2012-04-10 17:05:263394void WebContentsImpl::LoadStateChanged(
3395 const GURL& url,
3396 const net::LoadStateWithParam& load_state,
3397 uint64 upload_position,
3398 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323399 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563400 upload_position_ = upload_position;
3401 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503402 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213403 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303404 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213405 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323406 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463407 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213408 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463409 }
[email protected]420ae012009-04-24 05:16:323410}
3411
[email protected]b172aee2012-04-10 17:05:263412void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553413 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323414 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123415 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3416 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513417 if (delegate_)
3418 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093419 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323420}
3421
[email protected]58d5cfe2013-07-10 02:40:523422void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543423 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233424 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223425 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543426}
3427
[email protected]b172aee2012-04-10 17:05:263428void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103429 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213430 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263431 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3432 // here during container initialization and normal window size will be set
3433 // later. In case of tab duplication this resizing to 0x0 prevents setting
3434 // normal size later so just ignore it.
3435 if (!size.IsEmpty())
3436 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323437}
3438
[email protected]af905902013-10-01 21:38:513439void WebContentsImpl::CancelModalDialogsForRenderManager() {
3440 // We need to cancel modal dialogs when doing a process swap, since the load
3441 // deferrer would prevent us from swapping out.
3442 if (dialog_manager_)
3443 dialog_manager_->CancelActiveAndPendingDialogs(this);
3444}
3445
[email protected]7b712ee22013-10-03 00:57:283446void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3447 RenderViewHost* new_host) {
3448 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083449
3450 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003451 if (delegate_)
3452 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393453
[email protected]7b712ee22013-10-03 00:57:283454 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543455}
3456
[email protected]14392a52012-05-02 20:28:443457int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3458 SiteInstance* instance) {
3459 if (!opener_)
3460 return MSG_ROUTING_NONE;
3461
3462 // Recursively create RenderViews for anything else in the opener chain.
3463 return opener_->CreateOpenerRenderViews(instance);
3464}
3465
3466int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3467 int opener_route_id = MSG_ROUTING_NONE;
3468
3469 // If this tab has an opener, ensure it has a RenderView in the given
3470 // SiteInstance as well.
3471 if (opener_)
3472 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3473
[email protected]45a22ad2013-02-21 03:25:003474 // If any of the renderers (current, pending, or swapped out) for this
3475 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213476 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3477 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373478
[email protected]fa944cb82013-11-15 17:51:213479 if (GetRenderManager()->pending_render_view_host() &&
3480 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3481 instance)
3482 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003483
[email protected]fa944cb82013-11-15 17:51:213484 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373485 instance);
3486 if (rvh)
3487 return rvh->GetRoutingID();
3488
[email protected]14392a52012-05-02 20:28:443489 // Create a swapped out RenderView in the given SiteInstance if none exists,
3490 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413491 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3492 true, true);
[email protected]14392a52012-05-02 20:28:443493}
3494
[email protected]b172aee2012-04-10 17:05:263495NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193496 return GetController();
[email protected]3a3d47472010-07-15 21:03:543497}
3498
[email protected]b172aee2012-04-10 17:05:263499WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563500 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323501}
3502
[email protected]10f417c52011-12-28 21:04:233503NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263504 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323505 return controller_.GetLastCommittedEntry();
3506}
3507
[email protected]b172aee2012-04-10 17:05:263508bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163509 RenderViewHost* render_view_host,
3510 int opener_route_id,
3511 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033512 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443513 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163514 RenderWidgetHostView* rwh_view;
3515 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3516 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3517 // case this because RWH is still a base class of RenderViewHost, and child
3518 // frame RWHVs are unique in that they do not have their own WebContents.
3519 if (frame_connector) {
3520 RenderWidgetHostViewChildFrame* rwh_view_child =
3521 new RenderWidgetHostViewChildFrame(render_view_host);
3522 frame_connector->set_view(rwh_view_child);
3523 rwh_view = rwh_view_child;
3524 } else {
3525 rwh_view = view_->CreateViewForWidget(render_view_host);
3526 }
[email protected]1a98a932009-11-17 00:12:523527
[email protected]420ae012009-04-24 05:16:323528 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443529 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213530 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323531
[email protected]74ce1ad2011-12-16 21:51:463532 // Make sure we use the correct starting page_id in the new RenderView.
3533 UpdateMaxPageIDIfNecessary(render_view_host);
3534 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583535 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463536
[email protected]9f76c1e2012-03-05 15:15:583537 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263538 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493539 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133540 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523541 return false;
[email protected]14392a52012-05-02 20:28:443542 }
[email protected]a4127722011-04-27 23:13:523543
[email protected]a220b5932013-09-21 03:47:443544#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503545 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3546 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443547 if (rwh_view) {
3548 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3549 render_widget_host->WasResized();
3550 }
[email protected]f8233cc2011-05-31 20:24:503551#endif
3552
[email protected]420ae012009-04-24 05:16:323553 return true;
3554}
3555
[email protected]7d244f12013-08-22 21:41:513556#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183557base::android::ScopedJavaLocalRef<jobject>
3558WebContentsImpl::GetJavaWebContents() {
3559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3560
3561 WebContentsAndroid* web_contents_android =
3562 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3563 if (!web_contents_android) {
3564 web_contents_android = new WebContentsAndroid(this);
3565 SetUserData(kWebContentsAndroidKey, web_contents_android);
3566 }
3567 return web_contents_android->GetJavaObject();
3568}
3569
[email protected]7d244f12013-08-22 21:41:513570bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3571 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163572 MSG_ROUTING_NONE,
3573 NULL);
[email protected]7d244f12013-08-22 21:41:513574}
3575#endif
3576
[email protected]b172aee2012-04-10 17:05:263577void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3578 IPC::Message* reply_msg,
3579 bool success,
[email protected]fcf75d42013-12-03 20:11:263580 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543581 if (is_showing_before_unload_dialog_ && !success) {
3582 // If a beforeunload dialog is canceled, we need to stop the throbber from
3583 // spinning, since we forced it to start spinning in Navigate.
[email protected]723971b2014-02-12 11:08:253584 DidStopLoading(rvh->GetMainFrame());
[email protected]15d160c02012-07-04 10:52:353585 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103586
[email protected]6d65a462013-06-21 21:29:123587 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3588 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543589 }
3590 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583591 static_cast<RenderViewHostImpl*>(
3592 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543593}
3594
[email protected]b172aee2012-04-10 17:05:263595void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213596 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123597 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103598}
[email protected]f45d2a72010-03-08 23:28:353599
[email protected]b172aee2012-04-10 17:05:263600void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103601 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443602 // Can be NULL during tests.
3603 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213604 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363605}
[email protected]9f76c1e2012-03-05 15:15:583606
[email protected]1ac10dca2013-08-20 20:47:043607bool WebContentsImpl::IsHidden() {
3608 return capturer_count_ == 0 && !should_normally_be_visible_;
3609}
3610
[email protected]b0936d22013-11-28 06:47:363611RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213612 return frame_tree_.root()->render_manager();
3613}
3614
[email protected]b172aee2012-04-10 17:05:263615RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583616 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3617}
[email protected]7900bfdb2012-05-24 19:31:243618
[email protected]f8497342013-02-05 22:15:023619BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393620 return browser_plugin_guest_.get();
3621}
3622
[email protected]738f57a2013-06-29 21:06:543623void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3624 CHECK(!browser_plugin_guest_);
3625 browser_plugin_guest_.reset(guest);
3626}
3627
[email protected]f8497342013-02-05 22:15:023628BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393629 return browser_plugin_embedder_.get();
3630}
[email protected]8ff00d72012-10-23 19:12:213631
[email protected]8eb04562013-03-06 03:41:143632BrowserPluginGuestManager*
3633 WebContentsImpl::GetBrowserPluginGuestManager() const {
3634 return static_cast<BrowserPluginGuestManager*>(
3635 GetBrowserContext()->GetUserData(
3636 browser_plugin::kBrowserPluginGuestManagerKeyName));
3637}
3638
[email protected]d9030b82013-07-19 08:26:063639void WebContentsImpl::ClearPowerSaveBlockers(
3640 RenderViewHost* render_view_host) {
3641 STLDeleteValues(&power_save_blockers_[render_view_host]);
3642 power_save_blockers_.erase(render_view_host);
3643}
3644
3645void WebContentsImpl::ClearAllPowerSaveBlockers() {
3646 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3647 i != power_save_blockers_.end(); ++i)
3648 STLDeleteValues(&power_save_blockers_[i->first]);
3649 power_save_blockers_.clear();
3650}
3651
[email protected]dc0fd432013-08-27 15:29:213652gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3653 gfx::Size size;
3654 if (delegate_)
3655 size = delegate_->GetSizeForNewRenderView(this);
3656 if (size.IsEmpty())
3657 size = view_->GetContainerSize();
3658 return size;
3659}
3660
[email protected]9b159a52013-10-03 17:24:553661void WebContentsImpl::OnFrameRemoved(
3662 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583663 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553664 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583665 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553666}
3667
[email protected]222f5822014-02-05 23:40:493668void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3669 if (!delegate_)
3670 return;
3671 const gfx::Size new_size = GetPreferredSize();
3672 if (new_size != old_size)
3673 delegate_->UpdatePreferredSize(this, new_size);
3674}
3675
[email protected]8ff00d72012-10-23 19:12:213676} // namespace content