blob: 32eef988f7e4050f62c7b769a3908a444c000aa3 [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]49413ca52014-03-05 14:13:4325#include "content/browser/devtools/render_view_devtools_agent_host.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]31a71eaf2014-03-13 01:47:3658#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1159#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2060#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4461#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3662#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1763#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1464#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4665#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1566#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0067#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2768#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0069#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3770#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1471#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3272#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3473#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3874#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4275#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2576#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1077#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2178#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4879#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5480#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4981#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2082#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0383#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5784#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1685#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2986#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5387#include "net/http/http_cache.h"
88#include "net/http/http_transaction_factory.h"
89#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3490#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5691#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0192#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4193#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5294#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1895#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3196
[email protected]583418cc2013-01-17 14:01:1097#if defined(OS_ANDROID)
98#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3299#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]155c7f22013-12-09 17:07:18100#include "content/browser/web_contents/web_contents_android.h"
[email protected]a794f3a2013-10-30 17:00:32101#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:00102#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10103#endif
104
[email protected]f66df822012-05-18 16:52:17105#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50106#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27107#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57108#endif
[email protected]3e45ba92009-02-20 21:09:00109
[email protected]420ae012009-04-24 05:16:32110// Cross-Site Navigations
111//
[email protected]b172aee2012-04-10 17:05:26112// If a WebContentsImpl is told to navigate to a different web site (as
113// determined by SiteInstance), it will replace its current RenderViewHost with
114// a new RenderViewHost dedicated to the new SiteInstance. This works as
115// follows:
[email protected]420ae012009-04-24 05:16:32116//
[email protected]fc6c1872013-10-03 01:22:35117// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46118// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32119// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35120// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32121// run in the current RVH.
122// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35123// that it has a pending cross-site request. We will check this on the IO
124// thread when deciding how to handle the response.
125// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46126// cancel all the pending logic. Otherwise we allow the pending RVH to send
127// the navigation request to its renderer.
128// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35129// main resource load on the pending RVH. It creates a
130// CrossSiteResourceHandler to check whether a process swap is needed when
131// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46132// - When RDH receives a response, the BufferedResourceHandler determines
133// whether it is a download. If so, it sends a message to the new renderer
134// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26135// pending RVH remains until the next DidNavigate event for this
136// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32137// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35138// download, the CrossSiteResourceHandler checks whether a process swap is
139// needed (either because CrossSiteRequestManager has state for it or because
140// a transfer was needed for a redirect).
141// - If so, CrossSiteResourceHandler pauses the response to first run the old
142// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36143// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
144// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35145// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
146// to a new process is needed, based on the stored pending_nav_params_. (This
147// is independent of whether we started out with a cross-process navigation.)
148// - If not, it just tells the ResourceDispatcherHost to resume the response
149// to its current RenderViewHost.
150// - If so, it cancels the current pending RenderViewHost and sets up a new
151// navigation using RequestTransferURL. When the transferred request
152// arrives in the ResourceDispatcherHost, we transfer the response and
153// resume it.
[email protected]420ae012009-04-24 05:16:32154// - The pending renderer sends a FrameNavigate message that invokes the
155// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46156// pending RVH.
[email protected]b0936d22013-11-28 06:47:36157// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15158// the user goes back. The process only stays live if another tab is using
159// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32160
[email protected]8ff00d72012-10-23 19:12:21161namespace content {
[email protected]420ae012009-04-24 05:16:32162namespace {
163
[email protected]82114f52012-03-20 22:53:41164const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05165
[email protected]155c7f22013-12-09 17:07:18166#if defined(OS_ANDROID)
167const char kWebContentsAndroidKey[] = "web_contents_android";
168#endif // OS_ANDROID
169
[email protected]e4abd3b42013-11-12 18:28:47170base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46171g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
172
[email protected]988ed7132014-03-31 16:25:58173static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39174 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29175 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30176 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02177 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58178 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02179 ++g_next_image_download_id,
180 url,
181 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30182 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02183 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39184}
185
[email protected]8bfc8272013-09-09 20:10:53186void NotifyCacheOnIO(
187 scoped_refptr<net::URLRequestContextGetter> request_context,
188 const GURL& url,
189 const std::string& http_method) {
190 request_context->GetURLRequestContext()->http_transaction_factory()->
191 GetCache()->OnExternalCacheHit(url, http_method);
192}
193
[email protected]9b159a52013-10-03 17:24:55194// Helper function for retrieving all the sites in a frame tree.
195bool CollectSites(BrowserContext* context,
196 std::set<GURL>* sites,
197 FrameTreeNode* node) {
198 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
199 return true;
200}
201
[email protected]a86c0e962013-12-17 17:10:39202bool ForEachFrameInternal(
203 const base::Callback<void(RenderFrameHost*)>& on_frame,
204 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41205 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39206 return true;
207}
208
[email protected]c06c58c2014-03-12 20:31:59209bool ForEachPendingFrameInternal(
210 const base::Callback<void(RenderFrameHost*)>& on_frame,
211 FrameTreeNode* node) {
212 RenderFrameHost* pending_frame_host =
213 node->render_manager()->pending_frame_host();
214 if (pending_frame_host)
215 on_frame.Run(pending_frame_host);
216 return true;
217}
218
[email protected]a86c0e962013-12-17 17:10:39219void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
220 IPC::Message* message_copy = new IPC::Message(*message);
221 message_copy->set_routing_id(rfh->GetRoutingID());
222 rfh->Send(message_copy);
223}
224
[email protected]c06c58c2014-03-12 20:31:59225void RunRenderFrameDeleted(
226 ObserverList<WebContentsObserver>* observer_list,
227 RenderFrameHost* render_frame_host) {
228 FOR_EACH_OBSERVER(WebContentsObserver,
229 *observer_list,
230 RenderFrameDeleted(render_frame_host));
231}
232
[email protected]420ae012009-04-24 05:16:32233} // namespace
234
[email protected]54944cde2012-12-09 09:24:59235WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15236 return WebContentsImpl::CreateWithOpener(
237 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19238}
239
240WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59241 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30242 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59243 WebContentsImpl* new_contents = new WebContentsImpl(
244 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30245
246 for (SessionStorageNamespaceMap::const_iterator it =
247 session_storage_namespace_map.begin();
248 it != session_storage_namespace_map.end();
249 ++it) {
250 new_contents->GetController()
251 .SetSessionStorageNamespace(it->first, it->second.get());
252 }
253
[email protected]54944cde2012-12-09 09:24:59254 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19255 return new_contents;
[email protected]a81343d232011-12-27 07:39:20256}
[email protected]746d3052012-05-22 15:15:47257
[email protected]e4abd3b42013-11-12 18:28:47258void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46259 g_created_callbacks.Get().push_back(callback);
260}
261
[email protected]e4abd3b42013-11-12 18:28:47262void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46263 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
264 if (g_created_callbacks.Get().at(i).Equals(callback)) {
265 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
266 return;
267 }
268 }
269}
270
[email protected]299d7f12012-05-23 05:31:15271WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47272 return rvh->GetDelegate()->GetAsWebContents();
273}
274
[email protected]a86c0e962013-12-17 17:10:39275WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
276 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
277 if (!rfh_impl)
278 return NULL;
279 return rfh_impl->delegate()->GetAsWebContents();
280}
281
[email protected]7fff43e2013-05-21 20:21:10282// WebContentsImpl::DestructionObserver ----------------------------------------
283
284class WebContentsImpl::DestructionObserver : public WebContentsObserver {
285 public:
286 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
287 : WebContentsObserver(watched_contents),
288 owner_(owner) {
289 }
290
291 // WebContentsObserver:
292 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
293 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
294 }
295
296 private:
297 WebContentsImpl* owner_;
298
299 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
300};
301
[email protected]b172aee2012-04-10 17:05:26302// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32303
[email protected]b172aee2012-04-10 17:05:26304WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21305 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19306 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42307 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22308 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57309 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44310 opener_(opener),
[email protected]2ceee8f2014-01-14 18:02:08311#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41312 accessible_parent_(NULL),
313#endif
[email protected]6ea6bdf2013-12-06 13:35:01314 frame_tree_(new NavigatorImpl(&controller_, this),
315 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34316 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23317 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
318 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34319 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26320 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56321 upload_size_(0),
322 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47323 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55324 capturer_count_(0),
325 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57326 is_being_destroyed_(false),
327 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15328 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01329 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02330 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38331 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21332 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
333 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00334 temporary_zoom_settings_(false),
[email protected]bab38af2014-03-30 17:37:29335 totalPinchGestureAmount_(0),
336 currentPinchZoomStepDelta_(0),
[email protected]cb805452013-05-22 15:16:21337 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44338 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42339 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
340 is_subframe_(false) {
[email protected]cbb1ef592013-06-05 19:49:46341 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
342 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55343 frame_tree_.SetFrameRemoveListener(
344 base::Bind(&WebContentsImpl::OnFrameRemoved,
345 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35346}
initial.commit09911bf2008-07-26 23:55:29347
[email protected]b172aee2012-04-10 17:05:26348WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32349 is_being_destroyed_ = true;
350
[email protected]21b41c7e892014-02-28 01:52:24351 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
352 // shutdown and be deleted as well.
353 frame_tree_.ForEach(
354 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
355
[email protected]d9030b82013-07-19 08:26:06356 ClearAllPowerSaveBlockers();
357
[email protected]b24b68a2012-09-24 21:57:26358 for (std::set<RenderWidgetHostImpl*>::iterator iter =
359 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
360 (*iter)->DetachDelegate();
361 }
362 created_widgets_.clear();
363
[email protected]3ab9cb82011-06-03 18:02:07364 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15365 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11366 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07367
[email protected]da8543762012-03-20 08:52:20368 if (color_chooser_)
369 color_chooser_->End();
370
[email protected]420ae012009-04-24 05:16:32371 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32372
[email protected]ca13a442012-04-17 14:00:12373 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21374 NotificationService::current()->Notify(
375 NOTIFICATION_WEB_CONTENTS_DESTROYED,
376 Source<WebContents>(this),
377 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32378
[email protected]c06c58c2014-03-12 20:31:59379 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
380 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
381 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
382 run_render_frame_deleted_callback));
383
[email protected]fa944cb82013-11-15 17:51:21384 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27385 if (pending_rvh) {
386 FOR_EACH_OBSERVER(WebContentsObserver,
387 observers_,
388 RenderViewDeleted(pending_rvh));
389 }
390
[email protected]c06c58c2014-03-12 20:31:59391 ForEachFrame(run_render_frame_deleted_callback);
392
[email protected]f273ee52013-10-18 16:05:27393 FOR_EACH_OBSERVER(WebContentsObserver,
394 observers_,
[email protected]fa944cb82013-11-15 17:51:21395 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27396
[email protected]2db9bd72012-04-13 20:20:56397 FOR_EACH_OBSERVER(WebContentsObserver,
398 observers_,
399 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08400
[email protected]6934a702011-12-20 00:04:51401 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10402
403 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
404 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42405}
406
[email protected]d1198fd2012-08-13 22:50:19407WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59408 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19409 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03410 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59411 WebContentsImpl* new_contents = new WebContentsImpl(
412 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19413
[email protected]54944cde2012-12-09 09:24:59414 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19415 return new_contents;
416}
417
[email protected]b371a5652013-02-20 11:25:51418// static
[email protected]8eb04562013-03-06 03:41:14419BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36420 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53421 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54422 int guest_instance_id,
423 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39424 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39425
426 // This makes |new_contents| act as a guest.
427 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54428 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19429 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11430
[email protected]3de10bb32013-01-08 21:57:33431 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33432 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11433
[email protected]216be772013-01-25 00:22:27434 // We are instantiating a WebContents for browser plugin. Set its subframe bit
435 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42436 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27437
[email protected]8eb04562013-03-06 03:41:14438 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39439}
440
[email protected]b0936d22013-11-28 06:47:36441RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21442 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28443}
444
[email protected]7bb761892012-07-20 09:32:47445bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
446 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44447 return OnMessageReceived(render_view_host, NULL, message);
448}
449
450bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
451 RenderFrameHost* render_frame_host,
452 const IPC::Message& message) {
453 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56454 if (GetWebUI() &&
455 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17456 return true;
[email protected]d2353452012-01-19 19:53:56457 }
[email protected]f82d57b52011-04-27 19:13:17458
[email protected]d8c660432011-12-22 20:51:25459 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
460 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10461 while ((observer = it.GetNext()) != NULL)
462 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53463 return true;
[email protected]403415a2011-01-10 18:57:53464
[email protected]1d62cf72014-02-07 21:31:57465 // Message handlers should be aware of which
466 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
467 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43468 if (render_frame_host) {
469 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
470 render_frame_host->GetRenderViewHost(), message))
471 return true;
[email protected]1d62cf72014-02-07 21:31:57472 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43473 } else {
474 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
475 render_view_host, message))
476 return true;
[email protected]1d62cf72014-02-07 21:31:57477 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43478 }
[email protected]1d62cf72014-02-07 21:31:57479
[email protected]724159a2010-12-30 01:11:18480 bool handled = true;
481 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26482 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44483 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
484 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40485 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
486 OnDomOperationResponse)
[email protected]724159a2010-12-30 01:11:18487 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
488 OnDidLoadResourceFromMemoryCache)
489 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
490 OnDidDisplayInsecureContent)
491 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
492 OnDidRunInsecureContent)
[email protected]1d62cf72014-02-07 21:31:57493 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
[email protected]724159a2010-12-30 01:11:18494 OnDocumentLoadedInFrame)
[email protected]028053d42014-03-05 22:20:37495 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]7d472472011-01-22 01:30:25496 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26497 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21498 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20499 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
500 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16501 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10502 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20503 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
504 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
505 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
506 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50507 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50508 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
509 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55510 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
511 OnBrowserPluginMessage(message))
512 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
513 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02514 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
515 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10516#if defined(OS_ANDROID)
517 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
518 OnFindMatchRectsReply)
519 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
520 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32521 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
522 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10523#endif
[email protected]1dd0bb752014-02-01 01:16:26524 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
525 OnMediaPlayingNotification)
526 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
527 OnMediaPausedNotification)
[email protected]9f268072013-11-07 00:02:15528 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
529 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07530 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
531 OnShowValidationMessage)
532 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
533 OnHideValidationMessage)
534 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
535 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18536 IPC_MESSAGE_UNHANDLED(handled = false)
537 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44538 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57539 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18540
541 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39542 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18543 GetRenderProcessHost()->ReceivedBadMessage();
544 }
545
546 return handled;
547}
548
[email protected]b172aee2012-04-10 17:05:26549void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18550 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21551 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43552 if (delegate_)
553 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18554}
555
[email protected]d1198fd2012-08-13 22:50:19556NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56557 return controller_;
558}
559
[email protected]d1198fd2012-08-13 22:50:19560const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56561 return controller_;
562}
563
[email protected]8ff00d72012-10-23 19:12:21564BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55565 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30566}
567
[email protected]b172aee2012-04-10 17:05:26568const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24569 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32570 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51571 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31572}
573
[email protected]a093ce02013-07-22 20:53:14574const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24575 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32576 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24577 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
578}
579
580const GURL& WebContentsImpl::GetLastCommittedURL() const {
581 // We may not have a navigation entry yet.
582 NavigationEntry* entry = controller_.GetLastCommittedEntry();
583 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
584}
585
[email protected]8ff00d72012-10-23 19:12:21586WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31587 return delegate_;
588}
589
[email protected]8ff00d72012-10-23 19:12:21590void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31591 // TODO(cbentzel): remove this debugging code?
592 if (delegate == delegate_)
593 return;
594 if (delegate_)
595 delegate_->Detach(this);
596 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08597 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31598 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08599 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00600 if (view_)
601 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08602 }
[email protected]be1f56ab2011-12-22 06:55:31603}
604
[email protected]8ff00d72012-10-23 19:12:21605RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21606 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41607 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16608}
609
[email protected]60eca4eb2013-12-06 00:02:16610RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41611 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16612}
613
[email protected]9c9343b2014-03-08 02:56:07614RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
615 if (!frame_tree_.GetFocusedFrame())
616 return NULL;
617 return frame_tree_.GetFocusedFrame()->current_frame_host();
618}
619
[email protected]a86c0e962013-12-17 17:10:39620void WebContentsImpl::ForEachFrame(
621 const base::Callback<void(RenderFrameHost*)>& on_frame) {
622 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
623}
624
625void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
626 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
627 delete message;
628}
629
[email protected]b172aee2012-04-10 17:05:26630RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21631 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31632}
633
[email protected]bfcfa692013-02-07 06:17:02634WebContents* WebContentsImpl::GetEmbedderWebContents() const {
635 BrowserPluginGuest* guest = GetBrowserPluginGuest();
636 if (guest)
637 return guest->embedder_web_contents();
638 return NULL;
639}
640
641int WebContentsImpl::GetEmbeddedInstanceID() const {
642 BrowserPluginGuest* guest = GetBrowserPluginGuest();
643 if (guest)
644 return guest->instance_id();
645 return 0;
646}
647
[email protected]6b618e62012-08-16 12:59:18648int WebContentsImpl::GetRoutingID() const {
649 if (!GetRenderViewHost())
650 return MSG_ROUTING_NONE;
651
652 return GetRenderViewHost()->GetRoutingID();
653}
654
[email protected]44470a22013-01-24 01:21:54655int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
656 return fullscreen_widget_routing_id_;
657}
658
[email protected]b172aee2012-04-10 17:05:26659RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21660 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31661}
662
[email protected]f8497342013-02-05 22:15:02663RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
664 BrowserPluginGuest* guest = GetBrowserPluginGuest();
665 if (guest && guest->embedder_web_contents()) {
666 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
667 }
668 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
669}
670
[email protected]4aebbca2013-09-17 22:26:49671RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
672 const {
673 RenderWidgetHost* const widget_host =
674 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
675 GetFullscreenWidgetRoutingID());
676 return widget_host ? widget_host->GetView() : NULL;
677}
678
[email protected]8ff00d72012-10-23 19:12:21679WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31680 return view_.get();
681}
682
[email protected]8ff00d72012-10-23 19:12:21683WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56684 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03685 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
686 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22687 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58688 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22689 web_ui->SetController(controller);
690 return web_ui;
691 }
692
693 delete web_ui;
694 return NULL;
695}
696
[email protected]8ff00d72012-10-23 19:12:21697WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21698 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
699 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31700}
701
[email protected]8ff00d72012-10-23 19:12:21702WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21703 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34704}
705
[email protected]86ef6a392012-05-11 22:03:11706void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22707 if (GetUserAgentOverride() == override)
708 return;
709
710 renderer_preferences_.user_agent_override = override;
711
712 // Send the new override string to the renderer.
713 RenderViewHost* host = GetRenderViewHost();
714 if (host)
715 host->SyncRendererPrefs();
716
717 // Reload the page if a load is currently in progress to avoid having
718 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27719 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22720 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
721 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53722
723 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
724 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11725}
726
727const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22728 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11729}
730
[email protected]2ceee8f2014-01-14 18:02:08731#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41732void WebContentsImpl::SetParentNativeViewAccessible(
733gfx::NativeViewAccessible accessible_parent) {
734 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45735 if (GetRenderViewHost())
736 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41737}
738#endif
739
[email protected]fcf75d42013-12-03 20:11:26740const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55741 // Transient entries take precedence. They are used for interstitial pages
742 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23743 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08744 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21745 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30746 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23747 if (entry) {
[email protected]b5cca982011-05-26 04:42:08748 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23749 }
[email protected]fa944cb82013-11-15 17:51:21750 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
751 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58752 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54753 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32754 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54755 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35756 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26757 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54758 if (!title.empty())
759 return title;
760 }
761 }
762
763 // We use the title for the last committed entry rather than a pending
764 // navigation entry. For example, when the user types in a URL, we want to
765 // keep the old page's title until the new load has committed and we get a new
766 // title.
[email protected]96d185d2009-04-24 03:28:54767 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32768
[email protected]9eeafc012013-11-25 23:49:47769 // We make an exception for initial navigations.
770 if (controller_.IsInitialNavigation()) {
771 // We only want to use the title from the visible entry in one of two cases:
772 // 1. There's already a committed entry for an initial navigation, in which
773 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
774 // 2. The pending entry has been explicitly assigned a title to display.
775 //
776 // If there's no last committed entry and no assigned title, we should fall
777 // back to |page_title_when_no_navigation_entry_| rather than showing the
778 // URL.
779 if (entry ||
780 (controller_.GetVisibleEntry() &&
781 !controller_.GetVisibleEntry()->GetTitle().empty())) {
782 entry = controller_.GetVisibleEntry();
783 }
784 }
[email protected]59167c22013-06-03 18:07:32785
[email protected]45d0ef7f2011-01-05 13:46:23786 if (entry) {
[email protected]b5cca982011-05-26 04:42:08787 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23788 }
[email protected]987fc3a2011-05-26 14:18:09789
790 // |page_title_when_no_navigation_entry_| is finally used
791 // if no title cannot be retrieved.
792 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54793}
794
[email protected]b172aee2012-04-10 17:05:26795int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46796 return GetMaxPageIDForSiteInstance(GetSiteInstance());
797}
798
[email protected]b172aee2012-04-10 17:05:26799int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
800 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33801 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
802 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46803
[email protected]b6583592012-01-25 19:52:33804 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34805}
806
[email protected]b172aee2012-04-10 17:05:26807void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46808 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
809}
810
[email protected]b172aee2012-04-10 17:05:26811void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33812 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46813 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33814 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34815}
816
[email protected]ec6c05f2013-10-23 18:41:57817void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
818 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
819 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57820}
821
[email protected]b172aee2012-04-10 17:05:26822SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21823 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54824}
825
[email protected]b172aee2012-04-10 17:05:26826SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21827 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
828 GetRenderManager()->pending_render_view_host() :
829 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58830 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38831}
832
[email protected]b172aee2012-04-10 17:05:26833bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31834 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49835}
836
[email protected]b172aee2012-04-10 17:05:26837bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31838 return waiting_for_response_;
839}
840
[email protected]b172aee2012-04-10 17:05:26841const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31842 return load_state_;
843}
844
[email protected]fcf75d42013-12-03 20:11:26845const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31846 return load_state_host_;
847}
848
[email protected]b172aee2012-04-10 17:05:26849uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31850 return upload_size_;
851}
852
[email protected]b172aee2012-04-10 17:05:26853uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31854 return upload_position_;
855}
856
[email protected]1ae93fb2013-06-14 03:38:56857std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56858 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39859 frame_tree_.ForEach(base::Bind(&CollectSites,
860 base::Unretained(GetBrowserContext()),
861 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56862 return sites;
863}
864
[email protected]b172aee2012-04-10 17:05:26865const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31866 return encoding_;
867}
868
[email protected]b172aee2012-04-10 17:05:26869bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31870 return displayed_insecure_content_;
871}
872
[email protected]222f5822014-02-05 23:40:49873void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25874 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55875 ++capturer_count_;
876 DVLOG(1) << "There are now " << capturer_count_
877 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49878
879 // Note: This provides a hint to upstream code to size the views optimally
880 // for quality (e.g., to avoid scaling).
881 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
882 preferred_size_for_capture_ = capture_size;
883 OnPreferredSizeChanged(preferred_size_);
884 }
[email protected]54597982013-02-06 01:59:55885}
886
887void WebContentsImpl::DecrementCapturerCount() {
888 --capturer_count_;
889 DVLOG(1) << "There are now " << capturer_count_
890 << " capturing(s) of WebContentsImpl@" << this;
891 DCHECK_LE(0, capturer_count_);
892
[email protected]5a652232013-02-12 06:15:25893 if (is_being_destroyed_)
894 return;
895
[email protected]222f5822014-02-05 23:40:49896 if (capturer_count_ == 0) {
897 const gfx::Size old_size = preferred_size_for_capture_;
898 preferred_size_for_capture_ = gfx::Size();
899 OnPreferredSizeChanged(old_size);
900 }
901
[email protected]1ac10dca2013-08-20 20:47:04902 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55903 DVLOG(1) << "Executing delayed WasHidden().";
904 WasHidden();
905 }
[email protected]be1f56ab2011-12-22 06:55:31906}
907
[email protected]f2bd40812013-07-20 04:30:44908int WebContentsImpl::GetCapturerCount() const {
909 return capturer_count_;
910}
911
[email protected]b172aee2012-04-10 17:05:26912bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31913 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
914 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
915 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49916}
917
[email protected]b172aee2012-04-10 17:05:26918void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
919 int error_code) {
[email protected]443b80e2010-12-14 00:42:23920 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34921 return;
922
[email protected]443b80e2010-12-14 00:42:23923 crashed_status_ = status;
924 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21925 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34926}
927
[email protected]b172aee2012-04-10 17:05:26928base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31929 return crashed_status_;
930}
931
[email protected]b172aee2012-04-10 17:05:26932bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31933 return is_being_destroyed_;
934}
935
[email protected]b172aee2012-04-10 17:05:26936void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34937 if (delegate_)
938 delegate_->NavigationStateChanged(this, changed_flags);
939}
940
[email protected]9a890452014-02-13 22:21:02941base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
942 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33943}
944
[email protected]9e2e4632012-07-27 16:38:41945void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54946 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04947 RenderWidgetHostViewPort* rwhv =
948 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16949 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29950 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43951#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16952 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43953#endif
954 }
[email protected]96d185d2009-04-24 03:28:54955
[email protected]9a890452014-02-13 22:21:02956 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38957
[email protected]b9769d82012-02-10 00:23:59958 // The resize rect might have changed while this was inactive -- send the new
959 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58960 RenderViewHostImpl* rvh =
961 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59962 if (rvh) {
963 rvh->ResizeRectChanged(GetRootWindowResizerRect());
964 }
[email protected]96d185d2009-04-24 03:28:54965
[email protected]c0d9d5672013-10-09 07:38:03966 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
967
[email protected]54597982013-02-06 01:59:55968 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31969}
970
[email protected]b172aee2012-04-10 17:05:26971void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55972 // If there are entities capturing screenshots or video (e.g., mirroring),
973 // don't activate the "disable rendering" optimization.
974 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52975 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55976 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26977 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52978 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33979 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52980 // calls us).
[email protected]c30585c2012-02-16 15:02:04981 RenderWidgetHostViewPort* rwhv =
982 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16983 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29984 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54985 }
986
[email protected]c0d9d5672013-10-09 07:38:03987 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
988
[email protected]54597982013-02-06 01:59:55989 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37990}
991
[email protected]b172aee2012-04-10 17:05:26992bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31993 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27994 return WillNotifyDisconnection() &&
995 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58996 !static_cast<RenderViewHostImpl*>(
997 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31998}
999
[email protected]b172aee2012-04-10 17:05:261000void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211001 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401002 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271003}
1004
[email protected]b172aee2012-04-10 17:05:261005WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441006 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451007 // We pass our own opener so that the cloned page can access it if it was
1008 // before.
[email protected]54944cde2012-12-09 09:24:591009 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451010 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591011 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191012 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221013 FOR_EACH_OBSERVER(WebContentsObserver,
1014 observers_,
1015 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271016 return tc;
1017}
1018
[email protected]14392a52012-05-02 20:28:441019void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211020 const NotificationSource& source,
1021 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441022 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211023 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1024 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501025 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1026 i != pending_widget_views_.end(); ++i) {
1027 if (host->GetView() == i->second) {
1028 pending_widget_views_.erase(i);
1029 break;
1030 }
1031 }
1032 break;
1033 }
[email protected]14392a52012-05-02 20:28:441034 default:
1035 NOTREACHED();
1036 }
1037}
1038
[email protected]ec6c05f2013-10-23 18:41:571039WebContents* WebContentsImpl::GetWebContents() {
1040 return this;
1041}
1042
[email protected]54944cde2012-12-09 09:24:591043void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211044 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361045 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211046 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431047 should_normally_be_visible_ = !params.initially_hidden;
1048
[email protected]fa944cb82013-11-15 17:51:211049 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041050 params.browser_context, params.site_instance, params.routing_id,
1051 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191052
[email protected]8ff00d72012-10-23 19:12:211053 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191054 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271055 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191056 CHECK(render_view_host_delegate_view_);
1057 } else {
[email protected]f8497342013-02-05 22:15:021058 WebContentsViewDelegate* delegate =
1059 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1060
[email protected]59383c782013-04-17 16:43:271061 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381062 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1063 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021064
[email protected]b5a40842012-11-28 15:26:111065 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381066 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431067 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111068 render_view_host_delegate_view_ = rv;
1069 view_.reset(rv);
1070 } else {
[email protected]f8497342013-02-05 22:15:021071 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111072 view_.reset(CreateWebContentsView(
1073 this, delegate, &render_view_host_delegate_view_));
1074 }
[email protected]d1198fd2012-08-13 22:50:191075 CHECK(render_view_host_delegate_view_);
1076 }
1077 CHECK(view_.get());
1078
[email protected]ed245db2012-12-18 08:00:451079 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591080 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191081
1082 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101083 if (opener_)
1084 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191085
1086 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211087 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1088 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441089#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191090 java_bridge_dispatcher_host_manager_.reset(
1091 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101092 date_time_chooser_.reset(new DateTimeChooserAndroid());
1093#endif
[email protected]d1198fd2012-08-13 22:50:191094}
1095
[email protected]7fff43e2013-05-21 20:21:101096void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1097 RemoveDestructionObserver(web_contents);
1098
[email protected]14392a52012-05-02 20:28:441099 // Clear the opener if it has been closed.
1100 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441101 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511102 return;
[email protected]14392a52012-05-02 20:28:441103 }
[email protected]ceee8cd2013-03-08 04:59:511104 // Clear a pending contents that has been closed before being shown.
1105 for (PendingContents::iterator iter = pending_contents_.begin();
1106 iter != pending_contents_.end();
1107 ++iter) {
1108 if (iter->second != web_contents)
1109 continue;
1110 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511111 return;
1112 }
1113 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441114}
1115
[email protected]7fff43e2013-05-21 20:21:101116void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1117 if (!ContainsKey(destruction_observers_, web_contents)) {
1118 destruction_observers_[web_contents] =
1119 new DestructionObserver(this, web_contents);
1120 }
1121}
1122
1123void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1124 DestructionObservers::iterator iter =
1125 destruction_observers_.find(web_contents);
1126 if (iter != destruction_observers_.end()) {
1127 delete destruction_observers_[web_contents];
1128 destruction_observers_.erase(iter);
1129 }
1130}
1131
[email protected]b172aee2012-04-10 17:05:261132void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311133 observers_.AddObserver(observer);
1134}
1135
[email protected]b172aee2012-04-10 17:05:261136void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311137 observers_.RemoveObserver(observer);
1138}
1139
[email protected]b172aee2012-04-10 17:05:261140void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341141 if (delegate_)
1142 delegate_->ActivateContents(this);
1143}
1144
[email protected]b172aee2012-04-10 17:05:261145void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121146 if (delegate_)
1147 delegate_->DeactivateContents(this);
1148}
1149
[email protected]b172aee2012-04-10 17:05:261150void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481151 if (delegate_)
1152 delegate_->LostCapture();
1153}
1154
[email protected]b24b68a2012-09-24 21:57:261155void WebContentsImpl::RenderWidgetDeleted(
1156 RenderWidgetHostImpl* render_widget_host) {
1157 if (is_being_destroyed_) {
1158 // |created_widgets_| might have been destroyed.
1159 return;
1160 }
1161
1162 std::set<RenderWidgetHostImpl*>::iterator iter =
1163 created_widgets_.find(render_widget_host);
1164 if (iter != created_widgets_.end())
1165 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541166
1167 if (render_widget_host &&
1168 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491169 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1170 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541171 FOR_EACH_OBSERVER(WebContentsObserver,
1172 observers_,
1173 DidDestroyFullscreenWidget(
1174 fullscreen_widget_routing_id_));
1175 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1176 }
[email protected]b24b68a2012-09-24 21:57:261177}
1178
[email protected]b172aee2012-04-10 17:05:261179bool WebContentsImpl::PreHandleKeyboardEvent(
1180 const NativeWebKeyboardEvent& event,
1181 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481182 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131183 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481184}
1185
[email protected]b172aee2012-04-10 17:05:261186void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061187 if (browser_plugin_embedder_ &&
1188 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1189 return;
1190 }
1191
[email protected]63954792011-07-11 04:17:481192 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131193 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481194}
1195
[email protected]d92026ef2014-03-03 21:04:131196bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461197 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191198#if !defined(OS_MACOSX)
1199 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1200 // isn't done for two reasons:
1201 // -the OS already has a gesture to do this through pinch-zoom
1202 // -if a user starts an inertial scroll, let's go, and presses control
1203 // (i.e. control+tab) then the OS's buffered scroll events will come in
1204 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521205 if (delegate_ &&
1206 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461207 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521208 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1209 return true;
1210 }
[email protected]bccc4472013-04-18 16:37:191211#endif
[email protected]fb3f066e2013-02-12 19:12:521212 return false;
1213}
1214
[email protected]04bce562014-01-30 05:34:541215bool WebContentsImpl::PreHandleGestureEvent(
1216 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031217 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541218}
1219
[email protected]bab38af2014-03-30 17:37:291220bool WebContentsImpl::HandleGestureEvent(
1221 const blink::WebGestureEvent& event) {
1222 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1223 // Use them to implement browser zoom, as for HandleWheelEvent above.
1224 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1225 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1226 // The scale difference necessary to trigger a zoom action. Derived from
1227 // experimentation to find a value that feels reasonable.
1228 const float kZoomStepValue = 0.6f;
1229
1230 // Find the (absolute) thresholds on either side of the current zoom factor,
1231 // then convert those to actual numbers to trigger a zoom in or out.
1232 // This logic deliberately makes the range around the starting zoom value
1233 // for the gesture twice as large as the other ranges (i.e., the notches are
1234 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1235 // so that it's easier to get back to your starting point than it is to
1236 // overshoot.
1237 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1238 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1239 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1240 : -backStep;
1241 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1242 : backStep;
1243
1244 totalPinchGestureAmount_ += event.data.pinchUpdate.scale;
1245 if (totalPinchGestureAmount_ > zoomInThreshold) {
1246 currentPinchZoomStepDelta_++;
1247 delegate_->ContentsZoomChange(true);
1248 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1249 currentPinchZoomStepDelta_--;
1250 delegate_->ContentsZoomChange(false);
1251 }
1252 return true;
1253 }
1254
1255 return false;
1256}
1257
[email protected]2ceee8f2014-01-14 18:02:081258#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411259gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1260 return accessible_parent_;
1261}
1262#endif
1263
[email protected]b172aee2012-04-10 17:05:261264void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431265 if (delegate_)
1266 delegate_->HandleMouseDown();
1267}
1268
[email protected]b172aee2012-04-10 17:05:261269void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481270 if (delegate_)
1271 delegate_->HandleMouseUp();
1272}
1273
[email protected]590a634e2012-07-19 16:38:231274void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481275 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231276 delegate_->HandlePointerActivate();
1277}
1278
1279void WebContentsImpl::HandleGestureBegin() {
1280 if (delegate_)
1281 delegate_->HandleGestureBegin();
1282}
1283
1284void WebContentsImpl::HandleGestureEnd() {
1285 if (delegate_)
1286 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481287}
1288
[email protected]b172aee2012-04-10 17:05:261289void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491290 // This method is being called to enter or leave renderer-initiated fullscreen
1291 // mode. Either way, make sure any existing fullscreen widget is shut down
1292 // first.
1293 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1294 if (widget_view)
1295 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1296
[email protected]8a5e0ca2011-08-25 06:30:471297 if (delegate_)
1298 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371299
1300 FOR_EACH_OBSERVER(WebContentsObserver,
1301 observers_,
1302 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471303}
1304
[email protected]b172aee2012-04-10 17:05:261305bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381306 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121307}
1308
[email protected]a9c81f02012-06-01 00:15:441309void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1310 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371311 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441312 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371313 } else {
1314 GotResponseToLockMouseRequest(false);
1315 }
1316}
1317
[email protected]b172aee2012-04-10 17:05:261318void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371319 if (delegate_)
1320 delegate_->LostMouseLock();
1321}
1322
[email protected]bafe6cd2012-05-23 23:09:501323void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201324 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501325 int route_id,
[email protected]227692c52013-05-31 22:43:041326 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131327 const ViewHostMsg_CreateWindow_Params& params,
1328 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501329 // We usually create the new window in the same BrowsingInstance (group of
1330 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551331 // if the opener is being suppressed (in a non-guest), we create a new
1332 // SiteInstance in its own BrowsingInstance.
1333 bool is_guest = GetRenderProcessHost()->IsGuest();
1334
[email protected]04cbd3d2013-12-04 04:58:201335 // If the opener is to be suppressed, the new window can be in any process.
1336 // Since routing ids are process specific, we must not have one passed in
1337 // as argument here.
1338 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1339
[email protected]bafe6cd2012-05-23 23:09:501340 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551341 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571342 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501343 GetSiteInstance();
1344
[email protected]04cbd3d2013-12-04 04:58:201345 // A message to create a new window can only come from the active process for
1346 // this WebContentsImpl instance. If any other process sends the request,
1347 // it is invalid and the process must be terminated.
1348 if (GetRenderProcessHost()->GetID() != render_process_id) {
1349 base::ProcessHandle process_handle =
1350 RenderProcessHost::FromID(render_process_id)->GetHandle();
1351 if (process_handle != base::kNullProcessHandle) {
1352 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391353 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201354 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1355 }
1356 return;
1357 }
1358
[email protected]d1198fd2012-08-13 22:50:191359 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341360 //
1361 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301362 const std::string& partition_id =
1363 GetContentClient()->browser()->
1364 GetStoragePartitionIdForSite(GetBrowserContext(),
1365 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461366 StoragePartition* partition = BrowserContext::GetStoragePartition(
1367 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411368 DOMStorageContextWrapper* dom_storage_context =
1369 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191370 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1371 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1372 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371373
1374 if (delegate_ &&
1375 !delegate_->ShouldCreateWebContents(this,
1376 route_id,
1377 params.window_container_type,
1378 params.frame_name,
1379 params.target_url,
1380 partition_id,
1381 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011382 if (route_id != MSG_ROUTING_NONE &&
1383 !RenderViewHost::FromID(render_process_id, route_id)) {
1384 // If the embedder didn't create a WebContents for this route, we need to
1385 // delete the RenderView that had already been created.
1386 Send(new ViewMsg_Close(route_id));
1387 }
[email protected]dd6730412013-08-14 15:03:371388 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1389 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1390 main_frame_route_id);
1391 return;
1392 }
1393
1394 // Create the new web contents. This will automatically create the new
1395 // WebContentsView. In the future, we may want to create the view separately.
1396 WebContentsImpl* new_contents =
1397 new WebContentsImpl(GetBrowserContext(),
1398 params.opener_suppressed ? NULL : this);
1399
[email protected]d1198fd2012-08-13 22:50:191400 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301401 partition_id,
[email protected]d1198fd2012-08-13 22:50:191402 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461403 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591404 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041405 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551406 if (!is_guest) {
1407 create_params.context = view_->GetNativeView();
1408 create_params.initial_size = view_->GetContainerSize();
1409 } else {
1410 // This makes |new_contents| act as a guest.
1411 // For more info, see comment above class BrowserPluginGuest.
1412 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1413 WebContentsImpl* new_contents_impl =
1414 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461415 BrowserPluginGuest::CreateWithOpener(instance_id,
1416 new_contents_impl->opener() != NULL,
1417 new_contents_impl,
1418 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551419 }
[email protected]1ac10dca2013-08-20 20:47:041420 if (params.disposition == NEW_BACKGROUND_TAB)
1421 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591422 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191423
[email protected]c4538072013-03-18 02:17:551424 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341425 // will be shown immediately).
1426 if (!params.opener_suppressed) {
1427 if (!is_guest) {
1428 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501429
[email protected]d70bea92013-04-05 04:23:341430 // TODO(brettw): It seems bogus that we have to call this function on the
1431 // newly created object and give it one of its own member variables.
1432 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1433 }
[email protected]bafe6cd2012-05-23 23:09:501434 // Save the created window associated with the route so we can show it
1435 // later.
1436 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1437 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101438 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501439 }
1440
1441 if (delegate_) {
1442 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071443 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131444 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501445 }
1446
1447 if (params.opener_suppressed) {
1448 // When the opener is suppressed, the original renderer cannot access the
1449 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001450 bool was_blocked = false;
1451 if (delegate_) {
1452 gfx::Rect initial_pos;
1453 delegate_->AddNewContents(
1454 this, new_contents, params.disposition, initial_pos,
1455 params.user_gesture, &was_blocked);
1456 }
1457 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211458 OpenURLParams open_params(params.target_url,
1459 Referrer(),
1460 CURRENT_TAB,
1461 PAGE_TRANSITION_LINK,
1462 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301463 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001464 new_contents->OpenURL(open_params);
1465 }
[email protected]bafe6cd2012-05-23 23:09:501466 }
1467}
1468
[email protected]a8504022013-12-04 20:23:511469void WebContentsImpl::CreateNewWidget(int render_process_id,
1470 int route_id,
[email protected]180ef242013-11-07 06:50:461471 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511472 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501473}
1474
[email protected]a8504022013-12-04 20:23:511475void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1476 int route_id) {
1477 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501478}
1479
[email protected]a8504022013-12-04 20:23:511480void WebContentsImpl::CreateNewWidget(int render_process_id,
1481 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501482 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461483 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211484 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511485 // A message to create a new widget can only come from the active process for
1486 // this WebContentsImpl instance. If any other process sends the request,
1487 // it is invalid and the process must be terminated.
1488 if (process->GetID() != render_process_id) {
1489 base::ProcessHandle process_handle =
1490 RenderProcessHost::FromID(render_process_id)->GetHandle();
1491 if (process_handle != base::kNullProcessHandle) {
1492 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391493 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511494 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1495 }
1496 return;
1497 }
1498
[email protected]bafe6cd2012-05-23 23:09:501499 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041500 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261501 created_widgets_.insert(widget_host);
1502
[email protected]83918ec2013-01-10 15:37:191503 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1504 view_->CreateViewForPopupWidget(widget_host));
1505 if (!widget_view)
1506 return;
[email protected]bafe6cd2012-05-23 23:09:501507 if (!is_fullscreen) {
1508 // Popups should not get activated.
1509 widget_view->SetPopupType(popup_type);
1510 }
1511 // Save the created widget associated with the route so we can show it later.
1512 pending_widget_views_[route_id] = widget_view;
1513
1514#if defined(OS_MACOSX)
1515 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1516 // to allow it to survive the trip without being hosted.
1517 base::mac::NSObjectRetain(widget_view->GetNativeView());
1518#endif
1519}
1520
1521void WebContentsImpl::ShowCreatedWindow(int route_id,
1522 WindowOpenDisposition disposition,
1523 const gfx::Rect& initial_pos,
1524 bool user_gesture) {
1525 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001526 if (contents) {
1527 WebContentsDelegate* delegate = GetDelegate();
1528 if (delegate) {
1529 delegate->AddNewContents(
1530 this, contents, disposition, initial_pos, user_gesture, NULL);
1531 }
1532 }
[email protected]bafe6cd2012-05-23 23:09:501533}
1534
1535void WebContentsImpl::ShowCreatedWidget(int route_id,
1536 const gfx::Rect& initial_pos) {
1537 ShowCreatedWidget(route_id, false, initial_pos);
1538}
1539
1540void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1541 ShowCreatedWidget(route_id, true, gfx::Rect());
1542}
1543
1544void WebContentsImpl::ShowCreatedWidget(int route_id,
1545 bool is_fullscreen,
1546 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501547 RenderWidgetHostViewPort* widget_host_view =
1548 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1549 if (!widget_host_view)
1550 return;
[email protected]4aebbca2013-09-17 22:26:491551 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311552 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1553 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491554 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1555 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1556 delegate_->ToggleFullscreenModeForTab(this, true);
1557 } else {
1558 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491559 }
[email protected]4aebbca2013-09-17 22:26:491560 FOR_EACH_OBSERVER(WebContentsObserver,
1561 observers_,
1562 DidShowFullscreenWidget(route_id));
1563 if (!widget_host_view->HasFocus())
1564 widget_host_view->Focus();
1565 } else {
[email protected]f8497342013-02-05 22:15:021566 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491567 }
[email protected]89054502012-06-03 10:29:241568
1569 RenderWidgetHostImpl* render_widget_host_impl =
1570 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1571 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311572 // Only allow privileged mouse lock for fullscreen render widget, which is
1573 // used to implement Pepper Flash fullscreen.
1574 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501575
1576#if defined(OS_MACOSX)
1577 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1578 // properly embedded (or purposefully ignored) we can release the retain we
1579 // took in CreateNewWidget().
1580 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1581#endif
1582}
1583
1584WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1585 PendingContents::iterator iter = pending_contents_.find(route_id);
1586
1587 // Certain systems can block the creation of new windows. If we didn't succeed
1588 // in creating one, just return NULL.
1589 if (iter == pending_contents_.end()) {
1590 return NULL;
1591 }
1592
1593 WebContentsImpl* new_contents = iter->second;
1594 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101595 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501596
[email protected]d70bea92013-04-05 04:23:341597 // Don't initialize the guest WebContents immediately.
1598 if (new_contents->GetRenderProcessHost()->IsGuest())
1599 return new_contents;
1600
[email protected]bafe6cd2012-05-23 23:09:501601 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1602 !new_contents->GetRenderViewHost()->GetView())
1603 return NULL;
1604
1605 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1606 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1607 return new_contents;
1608}
1609
1610RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1611 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1612 if (iter == pending_widget_views_.end()) {
1613 DCHECK(false);
1614 return NULL;
1615 }
1616
1617 RenderWidgetHostView* widget_host_view = iter->second;
1618 pending_widget_views_.erase(route_id);
1619
1620 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1621 if (!widget_host->GetProcess()->HasConnection()) {
1622 // The view has gone away or the renderer crashed. Nothing to do.
1623 return NULL;
1624 }
1625
1626 return widget_host_view;
1627}
1628
[email protected]f13b4202012-06-12 23:53:231629void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091630 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211631 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371632 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231633 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371634 } else {
1635 callback.Run(MediaStreamDevices(),
1636 MEDIA_DEVICE_INVALID_STATE,
1637 scoped_ptr<MediaStreamUI>());
1638 }
[email protected]f13b4202012-06-12 23:53:231639}
1640
[email protected]cc9200432013-07-23 23:02:401641SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1642 SiteInstance* instance) {
1643 return controller_.GetSessionStorageNamespace(instance);
1644}
1645
[email protected]9b159a52013-10-03 17:24:551646FrameTree* WebContentsImpl::GetFrameTree() {
1647 return &frame_tree_;
1648}
1649
[email protected]31a71eaf2014-03-13 01:47:361650void WebContentsImpl::AccessibilityEventReceived(
1651 const std::vector<AXEventNotificationDetails>& details) {
1652 FOR_EACH_OBSERVER(
1653 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1654}
1655
[email protected]edc3af82013-12-12 21:24:071656void WebContentsImpl::OnShowValidationMessage(
1657 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291658 const base::string16& main_text,
1659 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071660 if (delegate_)
1661 delegate_->ShowValidationMessage(
1662 this, anchor_in_root_view, main_text, sub_text);
1663}
1664
1665void WebContentsImpl::OnHideValidationMessage() {
1666 if (delegate_)
1667 delegate_->HideValidationMessage(this);
1668}
1669
1670void WebContentsImpl::OnMoveValidationMessage(
1671 const gfx::Rect& anchor_in_root_view) {
1672 if (delegate_)
1673 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1674}
1675
[email protected]32deec62013-05-15 23:55:041676void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1677 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441678 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041679}
1680
[email protected]b172aee2012-04-10 17:05:261681void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491682 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231683 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491684 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331685}
1686
[email protected]b172aee2012-04-10 17:05:261687void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341688 if (delegate_)
1689 delegate_->ResizeDueToAutoResize(this, new_size);
1690}
1691
[email protected]b172aee2012-04-10 17:05:261692WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201693 if (!delegate_)
1694 return NULL;
[email protected]00c37fc2011-08-02 00:22:501695
[email protected]e5d549d2011-12-28 01:29:201696 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201697 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341698}
1699
[email protected]6b618e62012-08-16 12:59:181700bool WebContentsImpl::Send(IPC::Message* message) {
1701 if (!GetRenderViewHost()) {
1702 delete message;
1703 return false;
1704 }
1705
1706 return GetRenderViewHost()->Send(message);
1707}
1708
[email protected]b172aee2012-04-10 17:05:261709bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501710 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261711 FrameTreeNode* node = frame_tree_.root();
1712
1713 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1714 // specified in the pending entry.
1715 NavigationEntryImpl* pending_entry =
1716 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1717 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1718 pending_entry->frame_tree_node_id() != -1) {
1719 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1720 }
1721
1722 return node->navigator()->NavigateToPendingEntry(
1723 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541724}
[email protected]96d185d2009-04-24 03:28:541725
[email protected]a86c0e962013-12-17 17:10:391726void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1727 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441728 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391729 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441730}
1731
[email protected]20ca0382013-02-28 19:50:071732void WebContentsImpl::AttachInterstitialPage(
1733 InterstitialPageImpl* interstitial_page) {
1734 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211735 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291736
1737 // Cancel any visible dialogs so that they don't interfere with the
1738 // interstitial.
1739 if (dialog_manager_)
1740 dialog_manager_->CancelActiveAndPendingDialogs(this);
1741
[email protected]20ca0382013-02-28 19:50:071742 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1743 DidAttachInterstitialPage());
1744}
1745
1746void WebContentsImpl::DetachInterstitialPage() {
1747 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211748 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071749 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1750 DidDetachInterstitialPage());
1751}
1752
[email protected]b172aee2012-04-10 17:05:261753void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331754 const SiteInstance* site_instance,
1755 int history_length,
1756 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411757 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1758 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211759 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191760 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141761 return;
[email protected]9e1ad4b2011-08-14 16:49:191762 }
[email protected]9f76c1e2012-03-05 15:15:581763 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191764 if (!rvh) {
1765 NOTREACHED();
1766 return;
1767 }
[email protected]9f76c1e2012-03-05 15:15:581768 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191769 NOTREACHED();
1770 return;
1771 }
[email protected]6b618e62012-08-16 12:59:181772 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1773 history_length,
1774 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141775}
1776
[email protected]b172aee2012-04-10 17:05:261777void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271778 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211779 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541780 return;
1781 }
[email protected]9f76c1e2012-03-05 15:15:581782 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541783}
1784
[email protected]b172aee2012-04-10 17:05:261785bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211786 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541787}
1788
[email protected]b172aee2012-04-10 17:05:261789InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211790 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221791}
1792
[email protected]b172aee2012-04-10 17:05:261793bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161794 // WebKit creates Document object when MIME type is application/xhtml+xml,
1795 // so we also support this MIME type.
1796 return contents_mime_type_ == "text/html" ||
1797 contents_mime_type_ == "text/xml" ||
1798 contents_mime_type_ == "application/xhtml+xml" ||
1799 contents_mime_type_ == "text/plain" ||
1800 contents_mime_type_ == "text/css" ||
1801 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1802}
1803
[email protected]b172aee2012-04-10 17:05:261804void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591805 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161806 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551807 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011808 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141809 return;
[email protected]c7dd2f62011-07-18 15:57:591810 }
1811
1812 Stop();
1813
1814 // Create the save package and possibly prompt the user for the name to save
1815 // the page as. The user prompt is an asynchronous operation that runs on
1816 // another thread.
1817 save_package_ = new SavePackage(this);
1818 save_package_->GetSaveInfo();
1819}
1820
1821// Used in automated testing to bypass prompting the user for file names.
1822// Instead, the names and paths are hard coded rather than running them through
1823// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341824bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1825 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211826 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591827 // Stop the page from navigating.
1828 Stop();
1829
1830 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211831 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591832}
1833
[email protected]3c71576ce2013-07-23 02:00:011834void WebContentsImpl::SaveFrame(const GURL& url,
1835 const Referrer& referrer) {
1836 if (!GetURL().is_valid())
1837 return;
1838 bool is_main_frame = (url == GetURL());
1839
1840 DownloadManager* dlm =
1841 BrowserContext::GetDownloadManager(GetBrowserContext());
1842 if (!dlm)
1843 return;
1844 int64 post_id = -1;
1845 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271846 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011847 if (entry)
1848 post_id = entry->GetPostID();
1849 }
1850 scoped_ptr<DownloadUrlParameters> params(
1851 DownloadUrlParameters::FromWebContents(this, url));
1852 params->set_referrer(referrer);
1853 params->set_post_id(post_id);
1854 params->set_prefer_cache(true);
1855 if (post_id >= 0)
1856 params->set_method("POST");
1857 params->set_prompt(true);
1858 dlm->DownloadUrl(params.Pass());
1859}
1860
[email protected]b172aee2012-04-10 17:05:261861void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341862 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481863 const base::Callback<void(int64)>& callback) {
1864 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121865}
1866
[email protected]6286a372013-10-09 04:03:271867// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261868bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271869 NavigationEntryImpl* visible_entry =
1870 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1871 return (visible_entry != NULL &&
1872 visible_entry->site_instance() == GetSiteInstance() &&
1873 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321874}
1875
[email protected]b172aee2012-04-10 17:05:261876const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271877 return contents_mime_type_;
1878}
1879
[email protected]b172aee2012-04-10 17:05:261880bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271881 return notify_disconnection_;
1882}
1883
[email protected]b172aee2012-04-10 17:05:261884void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311885 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181886 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161887}
1888
[email protected]b172aee2012-04-10 17:05:261889void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311890 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181891 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161892}
1893
[email protected]8ff00d72012-10-23 19:12:211894RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271895 return &renderer_preferences_;
1896}
1897
[email protected]e35ccd52012-05-23 16:22:471898void WebContentsImpl::Close() {
1899 Close(GetRenderViewHost());
1900}
1901
[email protected]cf200a562013-05-03 16:24:291902void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461903 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291904 if (browser_plugin_embedder_.get())
1905 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1906 screen_x, screen_y, operation);
1907 if (GetRenderViewHost())
1908 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1909 screen_x, screen_y, operation);
1910}
1911
1912void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1913 int screen_x, int screen_y) {
1914 if (browser_plugin_embedder_.get())
1915 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1916 screen_x, screen_y);
1917 if (GetRenderViewHost())
1918 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1919 screen_x, screen_y);
1920}
1921
[email protected]d60f3702013-12-26 16:30:241922void WebContentsImpl::DidGetResourceResponseStart(
1923 const ResourceRequestDetails& details) {
1924 controller_.ssl_manager()->DidStartResourceResponse(details);
1925
1926 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1927 DidGetResourceResponseStart(details));
1928
1929 // TODO(avi): Remove. http://crbug.com/170921
1930 NotificationService::current()->Notify(
1931 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1932 Source<WebContents>(this),
1933 Details<const ResourceRequestDetails>(&details));
1934}
1935
1936void WebContentsImpl::DidGetRedirectForResourceRequest(
1937 RenderViewHost* render_view_host,
1938 const ResourceRedirectDetails& details) {
1939 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1940
1941 FOR_EACH_OBSERVER(
1942 WebContentsObserver,
1943 observers_,
1944 DidGetRedirectForResourceRequest(render_view_host, details));
1945
1946 // TODO(avi): Remove. http://crbug.com/170921
1947 NotificationService::current()->Notify(
1948 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1949 Source<WebContents>(this),
1950 Details<const ResourceRedirectDetails>(&details));
1951}
1952
[email protected]b172aee2012-04-10 17:05:261953void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521954 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581955 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511956 if (delegate_)
1957 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291958 if (browser_plugin_embedder_.get())
1959 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341960}
1961
[email protected]e35ccd52012-05-23 16:22:471962void WebContentsImpl::UserGestureDone() {
1963 OnUserGesture();
1964}
1965
[email protected]b172aee2012-04-10 17:05:261966void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271967 closed_by_user_gesture_ = value;
1968}
1969
[email protected]b172aee2012-04-10 17:05:261970bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271971 return closed_by_user_gesture_;
1972}
1973
[email protected]b172aee2012-04-10 17:05:261974double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051975 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561976 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251977 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171978 return 0;
[email protected]b75b8292010-10-01 07:28:251979
1980 double zoom_level;
1981 if (temporary_zoom_settings_) {
1982 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581983 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251984 } else {
[email protected]2ae88d12011-10-14 09:11:191985 GURL url;
[email protected]6286a372013-10-09 04:03:271986 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191987 // Since zoom map is updated using rewritten URL, use rewritten URL
1988 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271989 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021990 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1991 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251992 }
[email protected]d0b8d092010-10-25 04:05:171993 return zoom_level;
1994}
[email protected]b75b8292010-10-01 07:28:251995
[email protected]b172aee2012-04-10 17:05:261996int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591997 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171998 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011999 // Calculate the zoom percent from the factor. Round up to the nearest whole
2000 // number.
[email protected]b75b8292010-10-01 07:28:252001 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492002 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252003 *enable_decrement = percent > minimum_zoom_percent_;
2004 *enable_increment = percent < maximum_zoom_percent_;
2005 return percent;
2006}
2007
[email protected]b172aee2012-04-10 17:05:262008void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502009 if (!delegate_)
2010 return;
2011
[email protected]6286a372013-10-09 04:03:272012 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2013 if (!entry)
[email protected]1788e772010-12-15 16:40:502014 return;
2015
[email protected]6286a372013-10-09 04:03:272016 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122017}
2018
[email protected]b172aee2012-04-10 17:05:262019void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042020 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272021 if (!delegate_)
2022 return;
2023
[email protected]691aa2f2013-05-28 22:52:042024 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272025}
2026
[email protected]b172aee2012-04-10 17:05:262027int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272028 return minimum_zoom_percent_;
2029}
2030
[email protected]b172aee2012-04-10 17:05:262031int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272032 return maximum_zoom_percent_;
2033}
2034
[email protected]b172aee2012-04-10 17:05:262035gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492036 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232037}
2038
[email protected]b172aee2012-04-10 17:05:262039bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272040 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582041 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272042}
2043
[email protected]b172aee2012-04-10 17:05:262044bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442045 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502046}
2047
[email protected]cb805452013-05-22 15:16:212048void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182049 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212050 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202051}
2052
[email protected]cb805452013-05-22 15:16:212053void WebContentsImpl::DidEndColorChooser() {
2054 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2055 color_chooser_identifier_));
2056 color_chooser_.reset();
2057 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202058}
2059
[email protected]41225fe2013-03-29 05:32:022060int WebContentsImpl::DownloadImage(const GURL& url,
2061 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302062 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022063 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582064 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022065 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392066 return id;
2067}
2068
[email protected]5dcaf8e2013-12-28 01:31:422069bool WebContentsImpl::IsSubframe() const {
2070 return is_subframe_;
2071}
2072
[email protected]9649d492014-01-10 07:15:522073void WebContentsImpl::SetZoomLevel(double level) {
2074 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2075 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2076 if (embedder)
2077 embedder->SetZoomLevel(level);
2078}
2079
[email protected]36ec24f2014-01-09 00:32:082080void WebContentsImpl::Find(int request_id,
2081 const base::string16& search_text,
2082 const blink::WebFindOptions& options) {
2083 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2084}
2085
2086void WebContentsImpl::StopFinding(StopFindAction action) {
2087 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2088}
2089
[email protected]b172aee2012-04-10 17:05:262090bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272091 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202092 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332093 return true;
2094 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272095}
2096
[email protected]b172aee2012-04-10 17:05:262097void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272098 if (delegate_)
2099 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212100}
2101
[email protected]52913802013-12-10 05:52:182102void WebContentsImpl::DidStartProvisionalLoad(
2103 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072104 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182105 const GURL& validated_url,
2106 bool is_error_page,
2107 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262108 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182109 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572110 DidChangeLoadProgress(0);
2111
[email protected]0d60f0192011-04-14 12:40:102112 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272113 int render_frame_id = render_frame_host->GetRoutingID();
2114 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252115 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072116 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272117 render_frame_id, parent_routing_id, is_main_frame,
2118 validated_url, is_error_page, is_iframe_srcdoc,
2119 render_view_host));
[email protected]400992b2012-06-14 00:03:542120
2121 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182122 FOR_EACH_OBSERVER(
2123 WebContentsObserver,
2124 observers_,
2125 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582126 render_frame_host));
[email protected]400992b2012-06-14 00:03:542127 }
2128}
2129
[email protected]3109fbb72014-01-06 23:57:152130void WebContentsImpl::DidFailProvisionalLoadWithError(
2131 RenderFrameHostImpl* render_frame_host,
2132 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2133 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272134 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262135 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272136 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152137 FOR_EACH_OBSERVER(
2138 WebContentsObserver,
2139 observers_,
[email protected]161eabd2014-03-19 19:47:272140 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152141 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262142 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152143 validated_url,
2144 params.error_code,
2145 params.error_description,
[email protected]161eabd2014-03-19 19:47:272146 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152147}
2148
[email protected]b80624c2014-02-09 02:46:552149void WebContentsImpl::DidFailLoadWithError(
2150 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552151 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552152 int error_code,
2153 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272154 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262155 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272156 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552157 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272158 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262159 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552160}
2161
[email protected]52913802013-12-10 05:52:182162void WebContentsImpl::NotifyChangedNavigationState(
2163 InvalidateTypes changed_flags) {
2164 NotifyNavigationStateChanged(changed_flags);
2165}
2166
[email protected]3691e5cf2014-01-22 10:16:202167void WebContentsImpl::AboutToNavigateRenderFrame(
2168 RenderFrameHostImpl* render_frame_host) {
2169 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272170 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202171 FOR_EACH_OBSERVER(
2172 WebContentsObserver,
2173 observers_,
[email protected]161eabd2014-03-19 19:47:272174 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202175}
2176
2177void WebContentsImpl::DidStartNavigationToPendingEntry(
2178 RenderFrameHostImpl* render_frame_host,
2179 const GURL& url,
2180 NavigationController::ReloadType reload_type) {
2181 // Notify observers about navigation.
2182 FOR_EACH_OBSERVER(
2183 WebContentsObserver,
2184 observers_,
2185 DidStartNavigationToPendingEntry(url, reload_type));
2186}
2187
[email protected]8cb834e2014-03-06 14:23:232188void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2189 const OpenURLParams& params) {
2190 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182191 WebContents* new_contents = OpenURL(params);
2192
2193 if (new_contents) {
2194 // Notify observers.
2195 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2196 DidOpenRequestedURL(new_contents,
2197 params.url,
2198 params.referrer,
2199 params.disposition,
2200 params.transition,
[email protected]8cb834e2014-03-06 14:23:232201 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182202 }
2203}
2204
[email protected]400992b2012-06-14 00:03:542205void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582206 RenderFrameHostImpl* render_frame_host,
2207 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542208 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582209 FOR_EACH_OBSERVER(
2210 WebContentsObserver,
2211 observers_,
2212 ProvisionalChangeToMainFrameUrl(validated_target_url,
2213 render_frame_host));
[email protected]724159a2010-12-30 01:11:182214}
2215
[email protected]37567b432014-02-12 01:12:222216void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432217 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222218 const base::string16& frame_unique_name,
2219 bool is_main_frame,
2220 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432221 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432222 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272223 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222224 // Notify observers about the commit of the provisional load.
2225 FOR_EACH_OBSERVER(
2226 WebContentsObserver,
2227 observers_,
[email protected]27dd82fd2014-03-03 22:11:432228 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222229 frame_unique_name,
2230 is_main_frame,
2231 url,
2232 transition_type,
2233 render_view_host));
2234}
2235
2236void WebContentsImpl::DidNavigateMainFramePostCommit(
2237 const LoadCommittedDetails& details,
2238 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2239 if (details.is_navigation_to_different_page()) {
2240 // Clear the status bubble. This is a workaround for a bug where WebKit
2241 // doesn't let us know that the cursor left an element during a
2242 // transition (this is also why the mouse cursor remains as a hand after
2243 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2244 // clear the bubble when a user navigates to a named anchor in the same
2245 // page.
2246 UpdateTargetURL(details.entry->GetPageID(), GURL());
2247 }
2248
2249 if (!details.is_in_page) {
2250 // Once the main frame is navigated, we're no longer considered to have
2251 // displayed insecure content.
2252 displayed_insecure_content_ = false;
2253 SSLManager::NotifySSLInternalStateChanged(
2254 GetController().GetBrowserContext());
2255 }
2256
2257 // Notify observers about navigation.
2258 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2259 DidNavigateMainFrame(details, params));
2260
2261 if (delegate_) {
2262 delegate_->DidNavigateMainFramePostCommit(this);
2263 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2264 }
2265}
2266
2267void WebContentsImpl::DidNavigateAnyFramePostCommit(
2268 RenderFrameHostImpl* render_frame_host,
2269 const LoadCommittedDetails& details,
2270 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2271 // If we navigate off the page, close all JavaScript dialogs.
2272 if (dialog_manager_ && !details.is_in_page)
2273 dialog_manager_->CancelActiveAndPendingDialogs(this);
2274
2275 // Notify observers about navigation.
2276 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2277 DidNavigateAnyFrame(details, params));
2278}
2279
2280void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2281 contents_mime_type_ = mime_type;
2282}
2283
2284bool WebContentsImpl::CanOverscrollContent() {
2285 if (delegate_)
2286 return delegate_->CanOverscrollContent();
2287
2288 return false;
2289}
2290
[email protected]b172aee2012-04-10 17:05:262291void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182292 const GURL& url,
[email protected]70435962011-08-02 20:13:282293 const std::string& security_info,
2294 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182295 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282296 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192297 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182298 cache.Increment();
2299
2300 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082301 int cert_id = 0;
2302 net::CertStatus cert_status = 0;
2303 int security_bits = -1;
2304 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122305 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212306 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122307 &security_bits, &connection_status,
2308 &signed_certificate_timestamp_ids);
2309 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212310 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002311 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2312 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182313
[email protected]b0f724c2013-09-05 04:21:132314 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2315
2316 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2317 DidLoadResourceFromMemoryCache(details));
2318
[email protected]8bfc8272013-09-09 20:10:532319 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2320 scoped_refptr<net::URLRequestContextGetter> request_context(
2321 resource_type == ResourceType::MEDIA ?
2322 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2323 GetRenderProcessHost()->GetID()) :
2324 GetBrowserContext()->GetRequestContextForRenderProcess(
2325 GetRenderProcessHost()->GetID()));
2326 BrowserThread::PostTask(
2327 BrowserThread::IO,
2328 FROM_HERE,
2329 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2330 }
[email protected]724159a2010-12-30 01:11:182331}
2332
[email protected]b172aee2012-04-10 17:05:262333void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392334 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182335 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192336 SSLManager::NotifySSLInternalStateChanged(
2337 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182338}
2339
[email protected]b172aee2012-04-10 17:05:262340void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022341 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582342 LOG(WARNING) << security_origin << " ran insecure content from "
2343 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392344 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412345 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392346 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182347 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412348 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192349 SSLManager::NotifySSLInternalStateChanged(
2350 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182351}
2352
[email protected]501052ff2014-02-21 22:19:072353void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572354 CHECK(render_frame_message_source_);
2355 CHECK(!render_view_message_source_);
2356 RenderFrameHostImpl* rfh =
2357 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2358
[email protected]161eabd2014-03-19 19:47:272359 int render_frame_id = rfh->GetRoutingID();
2360 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572361 FOR_EACH_OBSERVER(WebContentsObserver,
2362 observers_,
[email protected]161eabd2014-03-19 19:47:272363 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182364}
2365
[email protected]b172aee2012-04-10 17:05:262366void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262367 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372368 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122369 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2370 GetRenderProcessHost()->ReceivedBadMessage();
2371 return;
2372 }
[email protected]a1b99262013-12-27 21:56:222373
[email protected]8b3af1e2014-01-24 13:29:122374 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442375 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372376 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422377 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372378
[email protected]61ac9e242014-03-21 20:55:262379 RenderFrameHostImpl* rfh =
2380 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272381 int render_frame_id = rfh->GetRoutingID();
2382 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262383 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252384 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272385 DidFinishLoad(render_frame_id, validated_url,
2386 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312387}
2388
[email protected]b172aee2012-04-10 17:05:262389void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222390 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2391 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262392}
2393
[email protected]b172aee2012-04-10 17:05:262394void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2395 int maximum_percent,
2396 bool remember) {
[email protected]216813952011-05-19 22:21:262397 minimum_zoom_percent_ = minimum_percent;
2398 maximum_zoom_percent_ = maximum_percent;
2399 temporary_zoom_settings_ = !remember;
2400}
2401
[email protected]b172aee2012-04-10 17:05:262402void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342403 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432404 if (!delegate_)
2405 return;
2406
[email protected]b9535422012-02-09 01:47:592407 ChildProcessSecurityPolicyImpl* policy =
2408 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222409 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592410 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212411}
2412
[email protected]b172aee2012-04-10 17:05:262413void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2414 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262415 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362416 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432417 if (!delegate_)
2418 return;
2419
[email protected]b9535422012-02-09 01:47:592420 ChildProcessSecurityPolicyImpl* policy =
2421 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322422 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592423 return;
[email protected]8f810632013-06-06 22:33:322424
[email protected]3a3b75a2012-06-01 08:38:362425 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202426}
2427
[email protected]b172aee2012-04-10 17:05:262428void WebContentsImpl::OnFindReply(int request_id,
2429 int number_of_matches,
2430 const gfx::Rect& selection_rect,
2431 int active_match_ordinal,
2432 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432433 if (delegate_) {
2434 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2435 active_match_ordinal, final_update);
2436 }
[email protected]b888919c2011-09-02 00:32:162437}
2438
[email protected]59363fc92012-09-05 03:46:312439#if defined(OS_ANDROID)
2440void WebContentsImpl::OnFindMatchRectsReply(
2441 int version,
2442 const std::vector<gfx::RectF>& rects,
2443 const gfx::RectF& active_rect) {
2444 if (delegate_)
2445 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2446}
[email protected]583418cc2013-01-17 14:01:102447
[email protected]1ff427972013-02-07 21:14:072448void WebContentsImpl::OnOpenDateTimeDialog(
2449 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092450 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2451 GetRenderViewHost(),
2452 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132453 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092454 value.minimum,
2455 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172456 value.step,
2457 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102458}
2459
[email protected]a794f3a2013-10-30 17:00:322460void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2461 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]c06c58c2014-03-12 20:31:592462 render_frame_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322463}
2464
[email protected]59363fc92012-09-05 03:46:312465#endif
2466
[email protected]f114fa42013-12-06 17:06:442467void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2468 const base::FilePath& path,
2469 bool is_hung) {
2470 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2471
2472 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2473 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2474}
2475
2476void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422477 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442478 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422479 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452480}
2481
[email protected]cfa856d62014-02-22 07:58:402482void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2483 int automation_id) {
2484 DomOperationNotificationDetails details(json_string, automation_id);
2485 NotificationService::current()->Notify(
2486 NOTIFICATION_DOM_OPERATION_RESPONSE,
2487 Source<WebContents>(this),
2488 Details<DomOperationNotificationDetails>(&details));
2489}
2490
[email protected]b172aee2012-04-10 17:05:262491void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2492 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102493 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252494 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102495 AppCacheAccessed(manifest_url, blocked_by_policy));
2496}
2497
[email protected]8bc5ff02013-11-29 06:34:032498void WebContentsImpl::OnOpenColorChooser(
2499 int color_chooser_id,
2500 SkColor color,
2501 const std::vector<ColorSuggestion>& suggestions) {
2502 ColorChooser* new_color_chooser =
2503 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302504 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212505 return;
[email protected]820957a2014-01-14 14:56:302506 if (color_chooser_)
2507 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212508 color_chooser_.reset(new_color_chooser);
2509 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202510}
2511
[email protected]b172aee2012-04-10 17:05:262512void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202513 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212514 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202515 color_chooser_->End();
2516}
2517
[email protected]b172aee2012-04-10 17:05:262518void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322519 SkColor color) {
[email protected]da8543762012-03-20 08:52:202520 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212521 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202522 color_chooser_->SetSelectedColor(color);
2523}
2524
[email protected]d0759f492012-04-19 22:50:502525// This exists for render views that don't have a WebUI, but do have WebUI
2526// bindings enabled.
2527void WebContentsImpl::OnWebUISend(const GURL& source_url,
2528 const std::string& name,
2529 const base::ListValue& args) {
2530 if (delegate_)
2531 delegate_->WebUISend(this, source_url, name, args);
2532}
2533
[email protected]d8415ad92012-08-23 14:40:502534void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442535 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502536 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342537 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162538 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442539 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162540 return;
[email protected]d8415ad92012-08-23 14:40:502541 }
2542
[email protected]8c8fc292012-11-23 18:57:162543 if (!delegate_->RequestPpapiBrokerPermission(
2544 this, url, plugin_path,
2545 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442546 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162547 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442548 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162549 }
[email protected]d8415ad92012-08-23 14:40:502550}
2551
[email protected]ea0309c2013-08-06 19:35:442552void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502553 bool result) {
[email protected]ea0309c2013-08-06 19:35:442554 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502555}
2556
[email protected]c4538072013-03-18 02:17:552557void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372558 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082559 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552560 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392561 // For more info, see comment above classes BrowserPluginEmbedder and
2562 // BrowserPluginGuest.
2563 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142564 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082565 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372566}
2567
[email protected]41225fe2013-03-29 05:32:022568void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392569 int id,
[email protected]749fadd2013-05-15 08:37:482570 int http_status_code,
[email protected]795c28972012-12-06 06:13:392571 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302572 const std::vector<SkBitmap>& bitmaps,
2573 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132574 if (bitmaps.size() != original_bitmap_sizes.size())
2575 return;
2576
[email protected]41225fe2013-03-29 05:32:022577 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2578 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392579 // Currently WebContents notifies us of ANY downloads so that it is
2580 // possible to get here.
2581 return;
2582 }
2583 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302584 iter->second.Run(
2585 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392586 }
[email protected]41225fe2013-03-29 05:32:022587 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392588}
2589
2590void WebContentsImpl::OnUpdateFaviconURL(
2591 int32 page_id,
2592 const std::vector<FaviconURL>& candidates) {
2593 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2594 DidUpdateFaviconURL(page_id, candidates));
2595}
2596
[email protected]1dd0bb752014-02-01 01:16:262597void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2598 bool has_video,
2599 bool has_audio) {
2600// Chrome OS does its own detection of audio and video.
2601#if !defined(OS_CHROMEOS)
2602 scoped_ptr<PowerSaveBlocker> blocker;
2603 if (has_video) {
2604 blocker = PowerSaveBlocker::Create(
2605 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2606#if defined(OS_ANDROID)
2607 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2608 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2609#endif
2610 } else if (has_audio) {
2611 blocker = PowerSaveBlocker::Create(
2612 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2613 }
2614
2615 if (blocker) {
2616 power_save_blockers_[render_view_message_source_][player_cookie] =
2617 blocker.release();
2618 }
2619#endif // !defined(OS_CHROMEOS)
2620}
2621
2622void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062623 // Chrome OS does its own detection of audio and video.
2624#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262625 delete power_save_blockers_[render_view_message_source_][player_cookie];
2626 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062627#endif // !defined(OS_CHROMEOS)
2628}
2629
[email protected]9f268072013-11-07 00:02:152630void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2631 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2632 DidFirstVisuallyNonEmptyPaint(page_id));
2633}
[email protected]d9030b82013-07-19 08:26:062634
[email protected]e67ebf32013-02-13 11:07:192635void WebContentsImpl::DidChangeVisibleSSLState() {
2636 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2637 DidChangeVisibleSSLState());
2638}
2639
[email protected]17e286e2013-03-01 23:29:392640void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2641 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2642 BeforeFormRepostWarningShow());
2643}
2644
[email protected]ec6c05f2013-10-23 18:41:572645
2646void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2647 Activate();
2648 if (delegate_)
2649 delegate_->ShowRepostFormWarningDialog(this);
2650}
2651
[email protected]96d185d2009-04-24 03:28:542652// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592653// loading, or done loading.
2654void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2655 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092656 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262657 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542658 if (is_loading == is_loading_)
2659 return;
2660
2661 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262662 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2663 base::string16());
[email protected]96d185d2009-04-24 03:28:542664 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562665 upload_size_ = 0;
2666 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542667 }
2668
[email protected]fa944cb82013-11-15 17:51:212669 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542670
2671 is_loading_ = is_loading;
2672 waiting_for_response_ = is_loading;
2673
[email protected]6ebdc9b2010-09-27 16:55:572674 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092675 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212676 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542677
[email protected]eab61442013-11-14 18:35:482678 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592679 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482680 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2681 "URL", url);
[email protected]91621872013-10-08 04:04:592682 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2683 DidStartLoading(render_view_host));
2684 } else {
[email protected]eab61442013-11-14 18:35:482685 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2686 "URL", url);
[email protected]91621872013-10-08 04:04:592687 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2688 DidStopLoading(render_view_host));
2689 }
[email protected]66798902013-10-01 18:40:162690
2691 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212692 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2693 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542694 if (details)
[email protected]8ff00d72012-10-23 19:12:212695 det = Details<LoadNotificationDetails>(details);
2696 NotificationService::current()->Notify(
2697 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542698}
2699
[email protected]b172aee2012-04-10 17:05:262700void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462701 // If we are creating a RVH for a restored controller, then we need to make
2702 // sure the RenderView starts with a next_page_id_ larger than the number
2703 // of restored entries. This must be called before the RenderView starts
2704 // navigating (to avoid a race between the browser updating max_page_id and
2705 // the renderer updating next_page_id_). Because of this, we only call this
2706 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562707 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582708 if (max_restored_page_id >
2709 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2710 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2711 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322712}
2713
[email protected]b172aee2012-04-10 17:05:262714bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262715 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322716 // For file URLs without a title, use the pathname instead. In the case of a
2717 // synthesized title, we don't want the update to count toward the "one set
2718 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262719 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322720 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512721 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242722 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322723 explicit_set = false; // Don't count synthetic titles toward the set limit.
2724 } else {
[email protected]8af69c6c2014-03-03 19:05:312725 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322726 explicit_set = true;
2727 }
2728
[email protected]987fc3a2011-05-26 14:18:092729 // If a page is created via window.open and never navigated,
2730 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552731 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092732 if (entry) {
[email protected]36fc0392011-12-25 03:59:512733 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092734 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322735
[email protected]36fc0392011-12-25 03:59:512736 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092737 } else {
2738 if (page_title_when_no_navigation_entry_ == final_title)
2739 return false; // Nothing changed, don't bother.
2740
2741 page_title_when_no_navigation_entry_ = final_title;
2742 }
[email protected]420ae012009-04-24 05:16:322743
[email protected]420ae012009-04-24 05:16:322744 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232745 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322746
[email protected]66798902013-10-01 18:40:162747 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532748 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162749
2750 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212751 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462752 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212753 NotificationService::current()->Notify(
2754 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2755 Source<WebContents>(this),
2756 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042757
[email protected]420ae012009-04-24 05:16:322758 return true;
2759}
2760
[email protected]7b712ee22013-10-03 00:57:282761void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2762 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322763 // After sending out a swap notification, we need to send a disconnect
2764 // notification so that clients that pick up a pointer to |this| can NULL the
2765 // pointer. See Bug 1230284.
2766 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112767 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282768 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112769
2770 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282771 std::pair<RenderViewHost*, RenderViewHost*> details =
2772 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212773 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282774 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212775 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282776 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392777
2778 // Ensure that the associated embedder gets cleared after a RenderViewHost
2779 // gets swapped, so we don't reuse the same embedder next time a
2780 // RenderViewHost is attached to this WebContents.
2781 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322782}
2783
[email protected]da7a7182013-09-06 08:11:112784// TODO(avi): Remove this entire function because this notification is already
2785// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262786void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322787 if (!notify_disconnection_)
2788 return;
2789
2790 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212791 NotificationService::current()->Notify(
2792 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2793 Source<WebContents>(this),
2794 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322795}
2796
[email protected]cbb1ef592013-06-05 19:49:462797void WebContentsImpl::NotifyNavigationEntryCommitted(
2798 const LoadCommittedDetails& load_details) {
2799 FOR_EACH_OBSERVER(
2800 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2801}
2802
[email protected]f114fa42013-12-06 17:06:442803bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2804 const IPC::Message& message) {
2805 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312806}
2807
[email protected]b849847b2013-12-10 21:57:582808void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2809 // Note this is only for subframes, the notification for the main frame
2810 // happens in RenderViewCreated.
2811 FOR_EACH_OBSERVER(WebContentsObserver,
2812 observers_,
2813 RenderFrameCreated(render_frame_host));
2814}
2815
2816void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2817 FOR_EACH_OBSERVER(WebContentsObserver,
2818 observers_,
2819 RenderFrameDeleted(render_frame_host));
2820}
2821
[email protected]a09d53ce2014-01-31 00:46:422822void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302823 if (delegate_)
2824 delegate_->WorkerCrashed(this);
2825}
2826
[email protected]a09d53ce2014-01-31 00:46:422827void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2828 const ContextMenuParams& params) {
2829 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:402830 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:422831 return;
2832
2833 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2834}
2835
[email protected]a86c0e962013-12-17 17:10:392836WebContents* WebContentsImpl::GetAsWebContents() {
2837 return this;
2838}
2839
[email protected]5a3bdf52012-05-24 15:12:572840RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2841 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322842}
2843
[email protected]8ff00d72012-10-23 19:12:212844RendererPreferences WebContentsImpl::GetRendererPrefs(
2845 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462846 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512847}
2848
[email protected]b172aee2012-04-10 17:05:262849gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172850 if (delegate_)
2851 return delegate_->GetRootWindowResizerRect();
2852 return gfx::Rect();
2853}
2854
[email protected]7a846df2012-09-20 19:17:392855void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272856 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392857 browser_plugin_embedder_.reset();
2858}
2859
[email protected]b172aee2012-04-10 17:05:262860void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442861 // Don't send notifications if we are just creating a swapped-out RVH for
2862 // the opener chain. These won't be used for view-source or WebUI, so it's
2863 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:242864 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:442865 return;
2866
[email protected]86f98a22013-03-20 14:35:002867 if (delegate_)
2868 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082869
[email protected]8ff00d72012-10-23 19:12:212870 NotificationService::current()->Notify(
2871 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2872 Source<WebContents>(this),
2873 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322874
2875 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352876 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212877 if (GetRenderManager()->pending_web_ui())
2878 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322879
[email protected]6286a372013-10-09 04:03:272880 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332881 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322882 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182883 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582884 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322885 }
[email protected]0666aef2009-05-13 19:48:082886
[email protected]60780f412013-02-25 16:34:102887 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262888
2889 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252890 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582891
2892 // We tell the observers now instead of when the main RenderFrameHostImpl is
2893 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2894 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:362895 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:582896 FOR_EACH_OBSERVER(
2897 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322898}
2899
[email protected]b172aee2012-04-10 17:05:262900void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522901 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322902 // Don't notify the world, since this came from a renderer in the
2903 // background.
2904 return;
2905 }
2906
[email protected]da7a7182013-09-06 08:11:112907 notify_disconnection_ = true;
2908 // TODO(avi): Remove. http://crbug.com/170921
2909 NotificationService::current()->Notify(
2910 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2911 Source<WebContents>(this),
2912 NotificationService::NoDetails());
2913
[email protected]be1f56ab2011-12-22 06:55:312914 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232915 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302916
2917 // Restore the focus to the tab (otherwise the focus will be on the top
2918 // window).
[email protected]484ae5912010-09-29 19:16:142919 if (was_crashed && !FocusLocationBarByDefault() &&
2920 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062921 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142922 }
[email protected]32ded2212011-11-10 18:51:432923
[email protected]d8c660432011-12-22 20:51:252924 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322925}
2926
[email protected]ec6a7eb2013-04-22 17:34:222927void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2928 base::TerminationStatus status,
2929 int error_code) {
[email protected]151a63d2011-12-20 22:32:522930 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322931 // The pending page's RenderViewHost is gone.
2932 return;
2933 }
2934
[email protected]2fcdcc32014-03-05 02:14:072935 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
2936 // renderer may not have made a clean exit.
2937 if (IsFullscreenForCurrentTab())
2938 ToggleFullscreenMode(false);
2939
[email protected]698191dc2014-02-25 01:06:132940 // Cancel any visible dialogs so they are not left dangling over the sad tab.
2941 if (dialog_manager_)
2942 dialog_manager_->CancelActiveAndPendingDialogs(this);
2943
[email protected]d9030b82013-07-19 08:26:062944 ClearPowerSaveBlockers(rvh);
[email protected]e3b10d12014-03-28 16:06:092945 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:322946 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232947 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312948 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322949
[email protected]d8c660432011-12-22 20:51:252950 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272951 observers_,
[email protected]58d5cfe2013-07-10 02:40:522952 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322953}
2954
[email protected]b172aee2012-04-10 17:05:262955void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062956 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212957 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252958 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062959}
2960
[email protected]b172aee2012-04-10 17:05:262961void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2962 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042963 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152964 // Ensure that this state update comes from either the active RVH or one of
2965 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412966 // TODO(nasko): This should go through RenderFrameHost.
2967 // TODO(creis): We can't update state for cross-process subframes until we
2968 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2969 if (rvh != GetRenderViewHost() &&
2970 !GetRenderManager()->IsRVHOnSwappedOutList(
2971 static_cast<RenderViewHostImpl*>(rvh)))
2972 return;
[email protected]420ae012009-04-24 05:16:322973
2974 // We must be prepared to handle state updates for any page, these occur
2975 // when the user is scrolling and entering form data, as well as when we're
2976 // leaving a page, in which case our state may have already been moved to
2977 // the next page. The navigation controller will look up the appropriate
2978 // NavigationEntry and update it when it is notified via the delegate.
2979
2980 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582981 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322982 if (entry_index < 0)
2983 return;
[email protected]10f417c52011-12-28 21:04:232984 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322985
[email protected]691aa2f2013-05-28 22:52:042986 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322987 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042988 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322989 controller_.NotifyEntryChanged(entry, entry_index);
2990}
2991
[email protected]b172aee2012-04-10 17:05:262992void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2993 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262994 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262995 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322996 // If we have a title, that's a pretty good indication that we've started
2997 // getting useful data.
2998 SetNotWaitingForResponse();
2999
[email protected]73eb2602012-02-09 19:50:553000 // Try to find the navigation entry, which might not be the current one.
3001 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233002 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583003 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093004
[email protected]73eb2602012-02-09 19:50:553005 // We can handle title updates when we don't have an entry in
3006 // UpdateTitleForEntry, but only if the update is from the current RVH.
3007 if (!entry && rvh != GetRenderViewHost())
3008 return;
3009
[email protected]a49e10b2011-08-01 23:57:463010 // TODO(evan): make use of title_direction.
3011 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093012 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323013 return;
3014
3015 // Broadcast notifications when the UI should be updated.
3016 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213017 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323018}
3019
[email protected]b172aee2012-04-10 17:05:263020void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3021 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313022 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323023}
3024
[email protected]b172aee2012-04-10 17:05:263025void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513026 if (delegate_)
3027 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323028}
3029
[email protected]b172aee2012-04-10 17:05:263030void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103031#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293032 // The UI may be in an event-tracking loop, such as between the
3033 // mouse-down and mouse-up in text selection or a button click.
3034 // Defer the close until after tracking is complete, so that we
3035 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293036 // TODO(shess): This could get more fine-grained. For instance,
3037 // closing a tab in another window while selecting text in the
3038 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103039 if (view_->IsEventTracking()) {
3040 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293041 return;
3042 }
[email protected]60780f412013-02-25 16:34:103043#endif
[email protected]07707302009-11-06 00:50:293044
[email protected]420ae012009-04-24 05:16:323045 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523046 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513047 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323048}
3049
[email protected]66bbadaf2014-03-28 16:25:543050void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
3051 // TODO(creis): Handle subframes that go fullscreen.
3052 if (rfh->GetRenderViewHost() == GetRenderViewHost()) {
[email protected]2fcdcc32014-03-05 02:14:073053 // Exit fullscreen mode before the current RVH is swapped out. For numerous
3054 // cases, there is no guarantee the renderer would/could initiate an exit.
3055 // Example: http://crbug.com/347232
3056 if (IsFullscreenForCurrentTab()) {
[email protected]66bbadaf2014-03-28 16:25:543057 rfh->GetRenderViewHost()->ExitFullscreen();
[email protected]2fcdcc32014-03-05 02:14:073058 DCHECK(!IsFullscreenForCurrentTab());
3059 }
3060
3061 if (delegate_)
3062 delegate_->SwappedOut(this);
3063 }
[email protected]cd9ed79d2011-11-15 19:22:573064}
3065
[email protected]b172aee2012-04-10 17:05:263066void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513067 if (delegate_ && delegate_->IsPopupOrPanel(this))
3068 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323069}
3070
[email protected]e3b10d12014-03-28 16:06:093071void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3072 bool to_different_document) {
3073 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3074 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323075}
3076
[email protected]723971b2014-02-12 11:08:253077void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323078 scoped_ptr<LoadNotificationDetails> details;
3079
[email protected]9595fd82013-04-19 21:28:493080 // Use the last committed entry rather than the active one, in case a
3081 // pending entry has been created.
3082 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203083 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493084
[email protected]420ae012009-04-24 05:16:323085 // An entry may not exist for a stop when loading an initial blank page or
3086 // if an iframe injected by script into a blank page finishes loading.
3087 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203088 base::TimeDelta elapsed =
3089 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323090
3091 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513092 entry->GetVirtualURL(),
3093 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323094 elapsed,
3095 &controller_,
3096 controller_.GetCurrentEntryIndex()));
3097 }
3098
[email protected]e3b10d12014-03-28 16:06:093099 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3100 details.get());
[email protected]420ae012009-04-24 05:16:323101}
3102
[email protected]b172aee2012-04-10 17:05:263103void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163104 controller_.DiscardNonCommittedEntries();
3105
3106 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213107 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163108}
3109
[email protected]b172aee2012-04-10 17:05:263110void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513111 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133112 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403113}
3114
[email protected]7cc78902012-12-06 02:32:263115void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393116 if (opener_) {
3117 // Clear our opener so that future cross-process navigations don't have an
3118 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103119 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393120 opener_ = NULL;
3121 }
[email protected]7cc78902012-12-06 02:32:263122
3123 // Notify all swapped out RenderViewHosts for this tab. This is important
3124 // in case we go back to them, or if another window in those processes tries
3125 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213126 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263127}
3128
[email protected]59167c22013-06-03 18:07:323129void WebContentsImpl::DidAccessInitialDocument() {
3130 // Update the URL display.
3131 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3132}
3133
[email protected]87717d0e2012-04-26 02:58:433134void WebContentsImpl::DocumentAvailableInMainFrame(
3135 RenderViewHost* render_view_host) {
3136 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3137 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103138}
3139
[email protected]b172aee2012-04-10 17:05:263140void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083141 RenderViewHost* render_view_host,
3142 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093143 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3144 DocumentOnLoadCompletedInMainFrame(page_id));
3145
3146 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213147 NotificationService::current()->Notify(
3148 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3149 Source<WebContents>(this),
3150 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083151}
3152
[email protected]e1c3a552012-05-04 20:51:323153void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3154 // Tell the active RenderViewHost to run unload handlers and close, as long
3155 // as the request came from a RenderViewHost in the same BrowsingInstance.
3156 // In most cases, we receive this from a swapped out RenderViewHost.
3157 // It is possible to receive it from one that has just been swapped in,
3158 // in which case we might as well deliver the message anyway.
3159 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3160 GetRenderViewHost()->ClosePage();
3161}
3162
[email protected]f546640b2012-05-15 00:03:493163void WebContentsImpl::RouteMessageEvent(
3164 RenderViewHost* rvh,
3165 const ViewMsg_PostMessage_Params& params) {
3166 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363167 // came from a RenderViewHost in the same BrowsingInstance or if this
3168 // WebContents is dedicated to a browser plugin guest.
3169 // Note: This check means that an embedder could theoretically receive a
3170 // postMessage from anyone (not just its own guests). However, this is
3171 // probably not a risk for apps since other pages won't have references
3172 // to App windows.
3173 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3174 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493175 return;
3176
3177 ViewMsg_PostMessage_Params new_params(params);
3178
[email protected]0bc7f3542013-10-21 15:05:533179 if (!params.message_port_ids.empty()) {
3180 MessagePortMessageFilter* message_port_message_filter =
3181 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3182 ->message_port_message_filter();
3183 std::vector<int> new_routing_ids(params.message_port_ids.size());
3184 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3185 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3186 MessagePortService::GetInstance()->UpdateMessagePort(
3187 params.message_port_ids[i],
3188 message_port_message_filter,
3189 new_routing_ids[i]);
3190 }
3191 new_params.new_routing_ids = new_routing_ids;
3192 }
3193
[email protected]f546640b2012-05-15 00:03:493194 // If there is a source_routing_id, translate it to the routing ID for
3195 // the equivalent swapped out RVH in the target process. If we need
3196 // to create a swapped out RVH for the source tab, we create its opener
3197 // chain as well, since those will also be accessible to the target page.
3198 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3199 // Try to look up the WebContents for the source page.
3200 WebContentsImpl* source_contents = NULL;
3201 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3202 rvh->GetProcess()->GetID(), params.source_routing_id);
3203 if (source_rvh) {
3204 source_contents = static_cast<WebContentsImpl*>(
3205 source_rvh->GetDelegate()->GetAsWebContents());
3206 }
3207
3208 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363209 if (GetBrowserPluginGuest()) {
3210 // We create a swapped out RenderView for the embedder in the guest's
3211 // render process but we intentionally do not expose the embedder's
3212 // opener chain to it.
3213 new_params.source_routing_id =
3214 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3215 } else {
3216 new_params.source_routing_id =
3217 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3218 }
[email protected]f546640b2012-05-15 00:03:493219 } else {
3220 // We couldn't find it, so don't pass a source frame.
3221 new_params.source_routing_id = MSG_ROUTING_NONE;
3222 }
3223 }
3224
3225 // In most cases, we receive this from a swapped out RenderViewHost.
3226 // It is possible to receive it from one that has just been swapped in,
3227 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183228 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493229}
3230
[email protected]b172aee2012-04-10 17:05:263231void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343232 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263233 const base::string16& message,
3234 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323235 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213236 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323237 IPC::Message* reply_msg,
3238 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073239 // Suppress JavaScript dialogs when requested. Also suppress messages when
3240 // showing an interstitial as it's shown over the previous page and we don't
3241 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503242 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243243 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() ||
[email protected]0bfbf882011-12-22 18:19:273244 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073245 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523246 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153247 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323248
3249 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213250 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433251 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153252 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3253 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433254 this,
3255 frame_url.GetOrigin(),
3256 accept_lang,
3257 javascript_message_type,
3258 message,
[email protected]51da7e32012-01-30 19:24:523259 default_prompt,
[email protected]b172aee2012-04-10 17:05:263260 base::Bind(&WebContentsImpl::OnDialogClosed,
3261 base::Unretained(this),
3262 rvh,
3263 reply_msg),
[email protected]51da7e32012-01-30 19:24:523264 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323265 }
[email protected]3ab9cb82011-06-03 18:02:073266
[email protected]6dd2f1e2013-09-11 15:06:013267 *did_suppress_message = suppress_this_message;
3268
[email protected]3ab9cb82011-06-03 18:02:073269 if (suppress_this_message) {
3270 // If we are suppressing messages, just reply as if the user immediately
3271 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263272 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073273 }
3274
[email protected]6dd2f1e2013-09-11 15:06:013275 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3276 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323277}
3278
[email protected]b172aee2012-04-10 17:05:263279void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263280 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263281 bool is_reload,
3282 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583283 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513284 if (delegate_)
3285 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073286
3287 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243288 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
[email protected]3ab9cb82011-06-03 18:02:073289 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523290 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153291 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153292 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343293 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263294 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503295 return;
3296 }
[email protected]3ab9cb82011-06-03 18:02:073297
[email protected]7ab1e7d62009-10-14 23:32:013298 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153299 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3300 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323301 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263302 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523303 reply_msg));
[email protected]420ae012009-04-24 05:16:323304}
3305
[email protected]a796f202012-05-30 14:14:253306bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263307 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253308 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263309 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253310 if (!delegate_)
3311 return false;
3312 return delegate_->AddMessageToConsole(this, level, message, line_no,
3313 source_id);
3314}
3315
[email protected]b172aee2012-04-10 17:05:263316WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273317 // We want to base the page config off of the actual URL, rather than the
3318 // virtual URL.
3319 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3320 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003321 GURL url = controller_.GetActiveEntry()
3322 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153323
[email protected]fa944cb82013-11-15 17:51:213324 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323325}
3326
[email protected]0eba810b2012-10-18 03:19:363327int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213328 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413329 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3330 true, true);
[email protected]0eba810b2012-10-18 03:19:363331}
3332
[email protected]b172aee2012-04-10 17:05:263333void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273334 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253335 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223336
[email protected]ea114722012-03-12 01:11:253337 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173338 if (rdh) // NULL in unittests.
3339 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253340}
3341
[email protected]b172aee2012-04-10 17:05:263342void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443343 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253344 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443345}
3346
[email protected]b172aee2012-04-10 17:05:263347void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563348 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263349 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153350 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523351 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153352 return;
3353
[email protected]9f76c1e2012-03-05 15:15:583354 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3355
[email protected]e5fc1632011-08-08 07:51:533356 // Ignore renderer unresponsive event if debugger is attached to the tab
3357 // since the event may be a result of the renderer sitting on a breakpoint.
3358 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363359 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533360 return;
3361
[email protected]2e9d79f2013-08-16 05:45:563362 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323363 // Hang occurred while firing the beforeunload/unload handler.
3364 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583365 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323366
[email protected]fa944cb82013-11-15 17:51:213367 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323368 return;
3369
3370 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563371 // nothing we can do to recover. If the hang is in the beforeunload handler,
3372 // pretend the beforeunload listeners have all fired and allow the delegate
3373 // to continue closing; the user will not have the option of cancelling the
3374 // close. Otherwise, pretend the unload listeners have all fired and close
3375 // the tab.
3376 bool close = true;
3377 if (is_during_beforeunload) {
3378 delegate_->BeforeUnloadFired(this, true, &close);
3379 }
3380 if (close)
3381 Close(rvh);
[email protected]420ae012009-04-24 05:16:323382 return;
3383 }
3384
[email protected]9f76c1e2012-03-05 15:15:583385 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473386 return;
3387
[email protected]6934a702011-12-20 00:04:513388 if (delegate_)
3389 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323390}
3391
[email protected]b172aee2012-04-10 17:05:263392void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513393 if (delegate_)
3394 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323395}
3396
[email protected]b172aee2012-04-10 17:05:263397void WebContentsImpl::LoadStateChanged(
3398 const GURL& url,
3399 const net::LoadStateWithParam& load_state,
3400 uint64 upload_position,
3401 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323402 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563403 upload_position_ = upload_position;
3404 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503405 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213406 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303407 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213408 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323409 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463410 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213411 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463412 }
[email protected]420ae012009-04-24 05:16:323413}
3414
[email protected]b172aee2012-04-10 17:05:263415void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553416 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323417 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123418 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3419 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513420 if (delegate_)
3421 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093422 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323423}
3424
[email protected]58d5cfe2013-07-10 02:40:523425void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543426 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233427 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223428 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543429}
3430
[email protected]b172aee2012-04-10 17:05:263431void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103432 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213433 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263434 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3435 // here during container initialization and normal window size will be set
3436 // later. In case of tab duplication this resizing to 0x0 prevents setting
3437 // normal size later so just ignore it.
3438 if (!size.IsEmpty())
3439 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323440}
3441
[email protected]af905902013-10-01 21:38:513442void WebContentsImpl::CancelModalDialogsForRenderManager() {
3443 // We need to cancel modal dialogs when doing a process swap, since the load
3444 // deferrer would prevent us from swapping out.
3445 if (dialog_manager_)
3446 dialog_manager_->CancelActiveAndPendingDialogs(this);
3447}
3448
[email protected]7b712ee22013-10-03 00:57:283449void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3450 RenderViewHost* new_host) {
3451 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083452
3453 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003454 if (delegate_)
3455 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393456
[email protected]7b712ee22013-10-03 00:57:283457 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543458}
3459
[email protected]14392a52012-05-02 20:28:443460int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3461 SiteInstance* instance) {
3462 if (!opener_)
3463 return MSG_ROUTING_NONE;
3464
3465 // Recursively create RenderViews for anything else in the opener chain.
3466 return opener_->CreateOpenerRenderViews(instance);
3467}
3468
3469int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3470 int opener_route_id = MSG_ROUTING_NONE;
3471
3472 // If this tab has an opener, ensure it has a RenderView in the given
3473 // SiteInstance as well.
3474 if (opener_)
3475 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3476
[email protected]45a22ad2013-02-21 03:25:003477 // If any of the renderers (current, pending, or swapped out) for this
3478 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213479 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3480 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373481
[email protected]fa944cb82013-11-15 17:51:213482 if (GetRenderManager()->pending_render_view_host() &&
3483 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3484 instance)
3485 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003486
[email protected]fa944cb82013-11-15 17:51:213487 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373488 instance);
3489 if (rvh)
3490 return rvh->GetRoutingID();
3491
[email protected]14392a52012-05-02 20:28:443492 // Create a swapped out RenderView in the given SiteInstance if none exists,
3493 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413494 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3495 true, true);
[email protected]14392a52012-05-02 20:28:443496}
3497
[email protected]b172aee2012-04-10 17:05:263498NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193499 return GetController();
[email protected]3a3d47472010-07-15 21:03:543500}
3501
[email protected]b172aee2012-04-10 17:05:263502WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563503 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323504}
3505
[email protected]10f417c52011-12-28 21:04:233506NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263507 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323508 return controller_.GetLastCommittedEntry();
3509}
3510
[email protected]b172aee2012-04-10 17:05:263511bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163512 RenderViewHost* render_view_host,
3513 int opener_route_id,
3514 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033515 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443516 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163517 RenderWidgetHostView* rwh_view;
3518 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3519 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3520 // case this because RWH is still a base class of RenderViewHost, and child
3521 // frame RWHVs are unique in that they do not have their own WebContents.
3522 if (frame_connector) {
3523 RenderWidgetHostViewChildFrame* rwh_view_child =
3524 new RenderWidgetHostViewChildFrame(render_view_host);
3525 frame_connector->set_view(rwh_view_child);
3526 rwh_view = rwh_view_child;
3527 } else {
3528 rwh_view = view_->CreateViewForWidget(render_view_host);
3529 }
[email protected]1a98a932009-11-17 00:12:523530
[email protected]420ae012009-04-24 05:16:323531 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443532 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213533 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323534
[email protected]74ce1ad2011-12-16 21:51:463535 // Make sure we use the correct starting page_id in the new RenderView.
3536 UpdateMaxPageIDIfNecessary(render_view_host);
3537 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583538 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463539
[email protected]9f76c1e2012-03-05 15:15:583540 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263541 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493542 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133543 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523544 return false;
[email protected]14392a52012-05-02 20:28:443545 }
[email protected]a4127722011-04-27 23:13:523546
[email protected]a220b5932013-09-21 03:47:443547#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503548 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3549 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443550 if (rwh_view) {
3551 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3552 render_widget_host->WasResized();
3553 }
[email protected]f8233cc2011-05-31 20:24:503554#endif
3555
[email protected]420ae012009-04-24 05:16:323556 return true;
3557}
3558
[email protected]7d244f12013-08-22 21:41:513559#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183560base::android::ScopedJavaLocalRef<jobject>
3561WebContentsImpl::GetJavaWebContents() {
3562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3563
3564 WebContentsAndroid* web_contents_android =
3565 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3566 if (!web_contents_android) {
3567 web_contents_android = new WebContentsAndroid(this);
3568 SetUserData(kWebContentsAndroidKey, web_contents_android);
3569 }
3570 return web_contents_android->GetJavaObject();
3571}
3572
[email protected]7d244f12013-08-22 21:41:513573bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3574 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163575 MSG_ROUTING_NONE,
3576 NULL);
[email protected]7d244f12013-08-22 21:41:513577}
3578#endif
3579
[email protected]b172aee2012-04-10 17:05:263580void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3581 IPC::Message* reply_msg,
3582 bool success,
[email protected]fcf75d42013-12-03 20:11:263583 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543584 if (is_showing_before_unload_dialog_ && !success) {
3585 // If a beforeunload dialog is canceled, we need to stop the throbber from
3586 // spinning, since we forced it to start spinning in Navigate.
[email protected]723971b2014-02-12 11:08:253587 DidStopLoading(rvh->GetMainFrame());
[email protected]15d160c02012-07-04 10:52:353588 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103589
[email protected]6d65a462013-06-21 21:29:123590 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3591 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543592 }
3593 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583594 static_cast<RenderViewHostImpl*>(
3595 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543596}
3597
[email protected]b172aee2012-04-10 17:05:263598void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213599 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123600 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103601}
[email protected]f45d2a72010-03-08 23:28:353602
[email protected]b172aee2012-04-10 17:05:263603void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103604 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443605 // Can be NULL during tests.
3606 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213607 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363608}
[email protected]9f76c1e2012-03-05 15:15:583609
[email protected]1ac10dca2013-08-20 20:47:043610bool WebContentsImpl::IsHidden() {
3611 return capturer_count_ == 0 && !should_normally_be_visible_;
3612}
3613
[email protected]b0936d22013-11-28 06:47:363614RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213615 return frame_tree_.root()->render_manager();
3616}
3617
[email protected]b172aee2012-04-10 17:05:263618RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583619 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3620}
[email protected]7900bfdb2012-05-24 19:31:243621
[email protected]f8497342013-02-05 22:15:023622BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393623 return browser_plugin_guest_.get();
3624}
3625
[email protected]738f57a2013-06-29 21:06:543626void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3627 CHECK(!browser_plugin_guest_);
3628 browser_plugin_guest_.reset(guest);
3629}
3630
[email protected]f8497342013-02-05 22:15:023631BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393632 return browser_plugin_embedder_.get();
3633}
[email protected]8ff00d72012-10-23 19:12:213634
[email protected]8eb04562013-03-06 03:41:143635BrowserPluginGuestManager*
3636 WebContentsImpl::GetBrowserPluginGuestManager() const {
3637 return static_cast<BrowserPluginGuestManager*>(
3638 GetBrowserContext()->GetUserData(
3639 browser_plugin::kBrowserPluginGuestManagerKeyName));
3640}
3641
[email protected]d9030b82013-07-19 08:26:063642void WebContentsImpl::ClearPowerSaveBlockers(
3643 RenderViewHost* render_view_host) {
3644 STLDeleteValues(&power_save_blockers_[render_view_host]);
3645 power_save_blockers_.erase(render_view_host);
3646}
3647
3648void WebContentsImpl::ClearAllPowerSaveBlockers() {
3649 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3650 i != power_save_blockers_.end(); ++i)
3651 STLDeleteValues(&power_save_blockers_[i->first]);
3652 power_save_blockers_.clear();
3653}
3654
[email protected]dc0fd432013-08-27 15:29:213655gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3656 gfx::Size size;
3657 if (delegate_)
3658 size = delegate_->GetSizeForNewRenderView(this);
3659 if (size.IsEmpty())
3660 size = view_->GetContainerSize();
3661 return size;
3662}
3663
[email protected]9b159a52013-10-03 17:24:553664void WebContentsImpl::OnFrameRemoved(
3665 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583666 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553667 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583668 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553669}
3670
[email protected]222f5822014-02-05 23:40:493671void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3672 if (!delegate_)
3673 return;
3674 const gfx::Size new_size = GetPreferredSize();
3675 if (new_size != old_size)
3676 delegate_->UpdatePreferredSize(this, new_size);
3677}
3678
[email protected]8ff00d72012-10-23 19:12:213679} // namespace content