blob: c37e3cf9aca32c1b102a380f5da78ed10253555e [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]1f3fc1d2014-04-03 14:50:1754#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5155#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0256#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5757#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5858#include "content/port/browser/render_widget_host_view_port.h"
[email protected]31a71eaf2014-03-13 01:47:3659#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1160#include "content/public/browser/browser_context.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]8ed16472014-04-11 19:02:48302WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
303 int render_frame_id,
304 ColorChooser* chooser,
305 int identifier)
306 : render_process_id(render_process_id),
307 render_frame_id(render_frame_id),
308 chooser(chooser),
309 identifier(identifier) {
310}
311
312WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
313}
314
[email protected]b172aee2012-04-10 17:05:26315// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32316
[email protected]b172aee2012-04-10 17:05:26317WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21318 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19319 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42320 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22321 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57322 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44323 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49324 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08325#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41326 accessible_parent_(NULL),
327#endif
[email protected]6ea6bdf2013-12-06 13:35:01328 frame_tree_(new NavigatorImpl(&controller_, this),
329 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34330 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23331 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
332 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34333 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26334 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56335 upload_size_(0),
336 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47337 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55338 capturer_count_(0),
339 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57340 is_being_destroyed_(false),
341 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15342 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01343 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02344 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38345 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21346 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
347 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00348 temporary_zoom_settings_(false),
[email protected]bab38af2014-03-30 17:37:29349 totalPinchGestureAmount_(0),
350 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44351 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42352 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]87de04b02014-04-08 22:14:49353 is_subframe_(false),
354 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46355 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
356 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55357 frame_tree_.SetFrameRemoveListener(
358 base::Bind(&WebContentsImpl::OnFrameRemoved,
359 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35360}
initial.commit09911bf2008-07-26 23:55:29361
[email protected]b172aee2012-04-10 17:05:26362WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32363 is_being_destroyed_ = true;
364
[email protected]21b41c7e892014-02-28 01:52:24365 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
366 // shutdown and be deleted as well.
367 frame_tree_.ForEach(
368 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
369
[email protected]d9030b82013-07-19 08:26:06370 ClearAllPowerSaveBlockers();
371
[email protected]b24b68a2012-09-24 21:57:26372 for (std::set<RenderWidgetHostImpl*>::iterator iter =
373 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
374 (*iter)->DetachDelegate();
375 }
376 created_widgets_.clear();
377
[email protected]3ab9cb82011-06-03 18:02:07378 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15379 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11380 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07381
[email protected]8ed16472014-04-11 19:02:48382 if (color_chooser_info_.get())
383 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20384
[email protected]420ae012009-04-24 05:16:32385 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32386
[email protected]ca13a442012-04-17 14:00:12387 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21388 NotificationService::current()->Notify(
389 NOTIFICATION_WEB_CONTENTS_DESTROYED,
390 Source<WebContents>(this),
391 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32392
[email protected]c06c58c2014-03-12 20:31:59393 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
394 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
395 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
396 run_render_frame_deleted_callback));
397
[email protected]fa944cb82013-11-15 17:51:21398 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27399 if (pending_rvh) {
400 FOR_EACH_OBSERVER(WebContentsObserver,
401 observers_,
402 RenderViewDeleted(pending_rvh));
403 }
404
[email protected]c06c58c2014-03-12 20:31:59405 ForEachFrame(run_render_frame_deleted_callback);
406
[email protected]f273ee52013-10-18 16:05:27407 FOR_EACH_OBSERVER(WebContentsObserver,
408 observers_,
[email protected]fa944cb82013-11-15 17:51:21409 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27410
[email protected]2db9bd72012-04-13 20:20:56411 FOR_EACH_OBSERVER(WebContentsObserver,
412 observers_,
413 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08414
[email protected]6934a702011-12-20 00:04:51415 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10416
417 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
418 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42419}
420
[email protected]d1198fd2012-08-13 22:50:19421WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59422 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19423 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03424 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59425 WebContentsImpl* new_contents = new WebContentsImpl(
426 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19427
[email protected]54944cde2012-12-09 09:24:59428 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19429 return new_contents;
430}
431
[email protected]b371a5652013-02-20 11:25:51432// static
[email protected]8eb04562013-03-06 03:41:14433BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36434 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53435 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54436 int guest_instance_id,
437 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39438 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39439
440 // This makes |new_contents| act as a guest.
441 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54442 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19443 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11444
[email protected]3de10bb32013-01-08 21:57:33445 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33446 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11447
[email protected]216be772013-01-25 00:22:27448 // We are instantiating a WebContents for browser plugin. Set its subframe bit
449 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42450 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27451
[email protected]8eb04562013-03-06 03:41:14452 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39453}
454
[email protected]b0936d22013-11-28 06:47:36455RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21456 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28457}
458
[email protected]7bb761892012-07-20 09:32:47459bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
460 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44461 return OnMessageReceived(render_view_host, NULL, message);
462}
463
464bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
465 RenderFrameHost* render_frame_host,
466 const IPC::Message& message) {
467 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56468 if (GetWebUI() &&
469 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17470 return true;
[email protected]d2353452012-01-19 19:53:56471 }
[email protected]f82d57b52011-04-27 19:13:17472
[email protected]d8c660432011-12-22 20:51:25473 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
474 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10475 while ((observer = it.GetNext()) != NULL)
476 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53477 return true;
[email protected]403415a2011-01-10 18:57:53478
[email protected]1d62cf72014-02-07 21:31:57479 // Message handlers should be aware of which
480 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
481 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43482 if (render_frame_host) {
483 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
484 render_frame_host->GetRenderViewHost(), message))
485 return true;
[email protected]1d62cf72014-02-07 21:31:57486 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43487 } else {
488 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
489 render_view_host, message))
490 return true;
[email protected]1d62cf72014-02-07 21:31:57491 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43492 }
[email protected]1d62cf72014-02-07 21:31:57493
[email protected]724159a2010-12-30 01:11:18494 bool handled = true;
495 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26496 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44497 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
498 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40499 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
500 OnDomOperationResponse)
[email protected]8ed16472014-04-11 19:02:48501 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
502 OnDocumentLoadedInFrame)
503 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
504 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
505 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
506 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
507 OnSetSelectedColorInColorChooser)
[email protected]724159a2010-12-30 01:11:18508 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
509 OnDidLoadResourceFromMemoryCache)
510 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
511 OnDidDisplayInsecureContent)
512 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
513 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25514 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26515 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21516 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20517 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
518 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16519 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10520 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50521 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50522 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
523 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55524 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
525 OnBrowserPluginMessage(message))
526 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
527 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02528 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
529 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]1dd0bb752014-02-01 01:16:26530 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
531 OnMediaPlayingNotification)
532 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
533 OnMediaPausedNotification)
[email protected]9f268072013-11-07 00:02:15534 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
535 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07536 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
537 OnShowValidationMessage)
538 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
539 OnHideValidationMessage)
540 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
541 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48542#if defined(OS_ANDROID)
543 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
544 OnFindMatchRectsReply)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
546 OnOpenDateTimeDialog)
547 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
548 OnJavaBridgeGetChannelHandle)
549#endif
[email protected]724159a2010-12-30 01:11:18550 IPC_MESSAGE_UNHANDLED(handled = false)
551 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44552 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57553 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18554
555 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39556 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18557 GetRenderProcessHost()->ReceivedBadMessage();
558 }
559
560 return handled;
561}
562
[email protected]b172aee2012-04-10 17:05:26563void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18564 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21565 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43566 if (delegate_)
567 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18568}
569
[email protected]d1198fd2012-08-13 22:50:19570NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56571 return controller_;
572}
573
[email protected]d1198fd2012-08-13 22:50:19574const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56575 return controller_;
576}
577
[email protected]8ff00d72012-10-23 19:12:21578BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55579 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30580}
581
[email protected]b172aee2012-04-10 17:05:26582const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24583 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32584 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51585 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31586}
587
[email protected]a093ce02013-07-22 20:53:14588const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24589 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32590 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24591 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
592}
593
594const GURL& WebContentsImpl::GetLastCommittedURL() const {
595 // We may not have a navigation entry yet.
596 NavigationEntry* entry = controller_.GetLastCommittedEntry();
597 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
598}
599
[email protected]8ff00d72012-10-23 19:12:21600WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31601 return delegate_;
602}
603
[email protected]8ff00d72012-10-23 19:12:21604void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31605 // TODO(cbentzel): remove this debugging code?
606 if (delegate == delegate_)
607 return;
608 if (delegate_)
609 delegate_->Detach(this);
610 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08611 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31612 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08613 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00614 if (view_)
615 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08616 }
[email protected]be1f56ab2011-12-22 06:55:31617}
618
[email protected]8ff00d72012-10-23 19:12:21619RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21620 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41621 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16622}
623
[email protected]60eca4eb2013-12-06 00:02:16624RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41625 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16626}
627
[email protected]9c9343b2014-03-08 02:56:07628RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
629 if (!frame_tree_.GetFocusedFrame())
630 return NULL;
631 return frame_tree_.GetFocusedFrame()->current_frame_host();
632}
633
[email protected]a86c0e962013-12-17 17:10:39634void WebContentsImpl::ForEachFrame(
635 const base::Callback<void(RenderFrameHost*)>& on_frame) {
636 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
637}
638
639void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
640 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
641 delete message;
642}
643
[email protected]b172aee2012-04-10 17:05:26644RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21645 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31646}
647
[email protected]bfcfa692013-02-07 06:17:02648WebContents* WebContentsImpl::GetEmbedderWebContents() const {
649 BrowserPluginGuest* guest = GetBrowserPluginGuest();
650 if (guest)
651 return guest->embedder_web_contents();
652 return NULL;
653}
654
655int WebContentsImpl::GetEmbeddedInstanceID() const {
656 BrowserPluginGuest* guest = GetBrowserPluginGuest();
657 if (guest)
658 return guest->instance_id();
659 return 0;
660}
661
[email protected]6b618e62012-08-16 12:59:18662int WebContentsImpl::GetRoutingID() const {
663 if (!GetRenderViewHost())
664 return MSG_ROUTING_NONE;
665
666 return GetRenderViewHost()->GetRoutingID();
667}
668
[email protected]44470a22013-01-24 01:21:54669int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
670 return fullscreen_widget_routing_id_;
671}
672
[email protected]b172aee2012-04-10 17:05:26673RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21674 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31675}
676
[email protected]f8497342013-02-05 22:15:02677RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
678 BrowserPluginGuest* guest = GetBrowserPluginGuest();
679 if (guest && guest->embedder_web_contents()) {
680 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
681 }
682 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
683}
684
[email protected]4aebbca2013-09-17 22:26:49685RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
686 const {
687 RenderWidgetHost* const widget_host =
688 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
689 GetFullscreenWidgetRoutingID());
690 return widget_host ? widget_host->GetView() : NULL;
691}
692
[email protected]8ff00d72012-10-23 19:12:21693WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31694 return view_.get();
695}
696
[email protected]8ff00d72012-10-23 19:12:21697WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56698 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03699 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
700 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22701 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58702 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22703 web_ui->SetController(controller);
704 return web_ui;
705 }
706
707 delete web_ui;
708 return NULL;
709}
710
[email protected]8ff00d72012-10-23 19:12:21711WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21712 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
713 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31714}
715
[email protected]8ff00d72012-10-23 19:12:21716WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21717 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34718}
719
[email protected]86ef6a392012-05-11 22:03:11720void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22721 if (GetUserAgentOverride() == override)
722 return;
723
724 renderer_preferences_.user_agent_override = override;
725
726 // Send the new override string to the renderer.
727 RenderViewHost* host = GetRenderViewHost();
728 if (host)
729 host->SyncRendererPrefs();
730
731 // Reload the page if a load is currently in progress to avoid having
732 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27733 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22734 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
735 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53736
737 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
738 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11739}
740
741const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22742 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11743}
744
[email protected]2ceee8f2014-01-14 18:02:08745#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41746void WebContentsImpl::SetParentNativeViewAccessible(
747gfx::NativeViewAccessible accessible_parent) {
748 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45749 if (GetRenderViewHost())
750 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41751}
752#endif
753
[email protected]fcf75d42013-12-03 20:11:26754const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55755 // Transient entries take precedence. They are used for interstitial pages
756 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23757 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08758 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21759 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30760 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23761 if (entry) {
[email protected]b5cca982011-05-26 04:42:08762 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23763 }
[email protected]fa944cb82013-11-15 17:51:21764 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
765 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58766 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54767 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32768 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54769 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35770 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26771 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54772 if (!title.empty())
773 return title;
774 }
775 }
776
777 // We use the title for the last committed entry rather than a pending
778 // navigation entry. For example, when the user types in a URL, we want to
779 // keep the old page's title until the new load has committed and we get a new
780 // title.
[email protected]96d185d2009-04-24 03:28:54781 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32782
[email protected]9eeafc012013-11-25 23:49:47783 // We make an exception for initial navigations.
784 if (controller_.IsInitialNavigation()) {
785 // We only want to use the title from the visible entry in one of two cases:
786 // 1. There's already a committed entry for an initial navigation, in which
787 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
788 // 2. The pending entry has been explicitly assigned a title to display.
789 //
790 // If there's no last committed entry and no assigned title, we should fall
791 // back to |page_title_when_no_navigation_entry_| rather than showing the
792 // URL.
793 if (entry ||
794 (controller_.GetVisibleEntry() &&
795 !controller_.GetVisibleEntry()->GetTitle().empty())) {
796 entry = controller_.GetVisibleEntry();
797 }
798 }
[email protected]59167c22013-06-03 18:07:32799
[email protected]45d0ef7f2011-01-05 13:46:23800 if (entry) {
[email protected]b5cca982011-05-26 04:42:08801 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23802 }
[email protected]987fc3a2011-05-26 14:18:09803
804 // |page_title_when_no_navigation_entry_| is finally used
805 // if no title cannot be retrieved.
806 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54807}
808
[email protected]b172aee2012-04-10 17:05:26809int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46810 return GetMaxPageIDForSiteInstance(GetSiteInstance());
811}
812
[email protected]b172aee2012-04-10 17:05:26813int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
814 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33815 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
816 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46817
[email protected]b6583592012-01-25 19:52:33818 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34819}
820
[email protected]b172aee2012-04-10 17:05:26821void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46822 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
823}
824
[email protected]b172aee2012-04-10 17:05:26825void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33826 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46827 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33828 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34829}
830
[email protected]ec6c05f2013-10-23 18:41:57831void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
832 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
833 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57834}
835
[email protected]b172aee2012-04-10 17:05:26836SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21837 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54838}
839
[email protected]b172aee2012-04-10 17:05:26840SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21841 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
842 GetRenderManager()->pending_render_view_host() :
843 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58844 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38845}
846
[email protected]b172aee2012-04-10 17:05:26847bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31848 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49849}
850
[email protected]b172aee2012-04-10 17:05:26851bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31852 return waiting_for_response_;
853}
854
[email protected]b172aee2012-04-10 17:05:26855const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31856 return load_state_;
857}
858
[email protected]fcf75d42013-12-03 20:11:26859const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31860 return load_state_host_;
861}
862
[email protected]b172aee2012-04-10 17:05:26863uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31864 return upload_size_;
865}
866
[email protected]b172aee2012-04-10 17:05:26867uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31868 return upload_position_;
869}
870
[email protected]1ae93fb2013-06-14 03:38:56871std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56872 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39873 frame_tree_.ForEach(base::Bind(&CollectSites,
874 base::Unretained(GetBrowserContext()),
875 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56876 return sites;
877}
878
[email protected]b172aee2012-04-10 17:05:26879const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31880 return encoding_;
881}
882
[email protected]b172aee2012-04-10 17:05:26883bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31884 return displayed_insecure_content_;
885}
886
[email protected]222f5822014-02-05 23:40:49887void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25888 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55889 ++capturer_count_;
890 DVLOG(1) << "There are now " << capturer_count_
891 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49892
893 // Note: This provides a hint to upstream code to size the views optimally
894 // for quality (e.g., to avoid scaling).
895 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
896 preferred_size_for_capture_ = capture_size;
897 OnPreferredSizeChanged(preferred_size_);
898 }
[email protected]54597982013-02-06 01:59:55899}
900
901void WebContentsImpl::DecrementCapturerCount() {
902 --capturer_count_;
903 DVLOG(1) << "There are now " << capturer_count_
904 << " capturing(s) of WebContentsImpl@" << this;
905 DCHECK_LE(0, capturer_count_);
906
[email protected]5a652232013-02-12 06:15:25907 if (is_being_destroyed_)
908 return;
909
[email protected]222f5822014-02-05 23:40:49910 if (capturer_count_ == 0) {
911 const gfx::Size old_size = preferred_size_for_capture_;
912 preferred_size_for_capture_ = gfx::Size();
913 OnPreferredSizeChanged(old_size);
914 }
915
[email protected]1ac10dca2013-08-20 20:47:04916 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55917 DVLOG(1) << "Executing delayed WasHidden().";
918 WasHidden();
919 }
[email protected]be1f56ab2011-12-22 06:55:31920}
921
[email protected]f2bd40812013-07-20 04:30:44922int WebContentsImpl::GetCapturerCount() const {
923 return capturer_count_;
924}
925
[email protected]b172aee2012-04-10 17:05:26926bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31927 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
928 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
929 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49930}
931
[email protected]b172aee2012-04-10 17:05:26932void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
933 int error_code) {
[email protected]443b80e2010-12-14 00:42:23934 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34935 return;
936
[email protected]443b80e2010-12-14 00:42:23937 crashed_status_ = status;
938 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21939 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34940}
941
[email protected]b172aee2012-04-10 17:05:26942base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31943 return crashed_status_;
944}
945
[email protected]b172aee2012-04-10 17:05:26946bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31947 return is_being_destroyed_;
948}
949
[email protected]b172aee2012-04-10 17:05:26950void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34951 if (delegate_)
952 delegate_->NavigationStateChanged(this, changed_flags);
953}
954
[email protected]9a890452014-02-13 22:21:02955base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
956 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33957}
958
[email protected]9e2e4632012-07-27 16:38:41959void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54960 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04961 RenderWidgetHostViewPort* rwhv =
962 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16963 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29964 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43965#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16966 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43967#endif
968 }
[email protected]96d185d2009-04-24 03:28:54969
[email protected]9a890452014-02-13 22:21:02970 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38971
[email protected]b9769d82012-02-10 00:23:59972 // The resize rect might have changed while this was inactive -- send the new
973 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58974 RenderViewHostImpl* rvh =
975 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59976 if (rvh) {
977 rvh->ResizeRectChanged(GetRootWindowResizerRect());
978 }
[email protected]96d185d2009-04-24 03:28:54979
[email protected]c0d9d5672013-10-09 07:38:03980 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
981
[email protected]54597982013-02-06 01:59:55982 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31983}
984
[email protected]b172aee2012-04-10 17:05:26985void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55986 // If there are entities capturing screenshots or video (e.g., mirroring),
987 // don't activate the "disable rendering" optimization.
988 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52989 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55990 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26991 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52992 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33993 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52994 // calls us).
[email protected]c30585c2012-02-16 15:02:04995 RenderWidgetHostViewPort* rwhv =
996 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16997 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29998 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54999 }
1000
[email protected]c0d9d5672013-10-09 07:38:031001 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1002
[email protected]54597982013-02-06 01:59:551003 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371004}
1005
[email protected]b172aee2012-04-10 17:05:261006bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311007 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271008 return WillNotifyDisconnection() &&
1009 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581010 !static_cast<RenderViewHostImpl*>(
1011 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311012}
1013
[email protected]1c3f80bd2014-04-08 23:02:061014void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1015 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1016 for_cross_site_transition);
1017}
1018
[email protected]b172aee2012-04-10 17:05:261019void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211020 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401021 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271022}
1023
[email protected]b172aee2012-04-10 17:05:261024WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441025 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451026 // We pass our own opener so that the cloned page can access it if it was
1027 // before.
[email protected]54944cde2012-12-09 09:24:591028 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451029 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591030 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191031 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221032 FOR_EACH_OBSERVER(WebContentsObserver,
1033 observers_,
1034 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271035 return tc;
1036}
1037
[email protected]14392a52012-05-02 20:28:441038void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211039 const NotificationSource& source,
1040 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441041 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211042 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1043 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501044 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1045 i != pending_widget_views_.end(); ++i) {
1046 if (host->GetView() == i->second) {
1047 pending_widget_views_.erase(i);
1048 break;
1049 }
1050 }
1051 break;
1052 }
[email protected]14392a52012-05-02 20:28:441053 default:
1054 NOTREACHED();
1055 }
1056}
1057
[email protected]ec6c05f2013-10-23 18:41:571058WebContents* WebContentsImpl::GetWebContents() {
1059 return this;
1060}
1061
[email protected]54944cde2012-12-09 09:24:591062void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211063 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361064 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211065 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431066 should_normally_be_visible_ = !params.initially_hidden;
1067
[email protected]fa944cb82013-11-15 17:51:211068 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041069 params.browser_context, params.site_instance, params.routing_id,
1070 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191071
[email protected]8ff00d72012-10-23 19:12:211072 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191073 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271074 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191075 CHECK(render_view_host_delegate_view_);
1076 } else {
[email protected]f8497342013-02-05 22:15:021077 WebContentsViewDelegate* delegate =
1078 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1079
[email protected]59383c782013-04-17 16:43:271080 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381081 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1082 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021083
[email protected]b5a40842012-11-28 15:26:111084 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381085 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431086 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111087 render_view_host_delegate_view_ = rv;
1088 view_.reset(rv);
1089 } else {
[email protected]f8497342013-02-05 22:15:021090 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111091 view_.reset(CreateWebContentsView(
1092 this, delegate, &render_view_host_delegate_view_));
1093 }
[email protected]d1198fd2012-08-13 22:50:191094 CHECK(render_view_host_delegate_view_);
1095 }
1096 CHECK(view_.get());
1097
[email protected]ed245db2012-12-18 08:00:451098 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591099 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191100
1101 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101102 if (opener_)
1103 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191104
1105 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211106 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1107 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441108#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191109 java_bridge_dispatcher_host_manager_.reset(
1110 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101111 date_time_chooser_.reset(new DateTimeChooserAndroid());
1112#endif
[email protected]d1198fd2012-08-13 22:50:191113}
1114
[email protected]7fff43e2013-05-21 20:21:101115void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1116 RemoveDestructionObserver(web_contents);
1117
[email protected]14392a52012-05-02 20:28:441118 // Clear the opener if it has been closed.
1119 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441120 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511121 return;
[email protected]14392a52012-05-02 20:28:441122 }
[email protected]ceee8cd2013-03-08 04:59:511123 // Clear a pending contents that has been closed before being shown.
1124 for (PendingContents::iterator iter = pending_contents_.begin();
1125 iter != pending_contents_.end();
1126 ++iter) {
1127 if (iter->second != web_contents)
1128 continue;
1129 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511130 return;
1131 }
1132 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441133}
1134
[email protected]7fff43e2013-05-21 20:21:101135void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1136 if (!ContainsKey(destruction_observers_, web_contents)) {
1137 destruction_observers_[web_contents] =
1138 new DestructionObserver(this, web_contents);
1139 }
1140}
1141
1142void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1143 DestructionObservers::iterator iter =
1144 destruction_observers_.find(web_contents);
1145 if (iter != destruction_observers_.end()) {
1146 delete destruction_observers_[web_contents];
1147 destruction_observers_.erase(iter);
1148 }
1149}
1150
[email protected]b172aee2012-04-10 17:05:261151void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311152 observers_.AddObserver(observer);
1153}
1154
[email protected]b172aee2012-04-10 17:05:261155void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311156 observers_.RemoveObserver(observer);
1157}
1158
[email protected]b172aee2012-04-10 17:05:261159void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341160 if (delegate_)
1161 delegate_->ActivateContents(this);
1162}
1163
[email protected]b172aee2012-04-10 17:05:261164void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121165 if (delegate_)
1166 delegate_->DeactivateContents(this);
1167}
1168
[email protected]b172aee2012-04-10 17:05:261169void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481170 if (delegate_)
1171 delegate_->LostCapture();
1172}
1173
[email protected]b24b68a2012-09-24 21:57:261174void WebContentsImpl::RenderWidgetDeleted(
1175 RenderWidgetHostImpl* render_widget_host) {
1176 if (is_being_destroyed_) {
1177 // |created_widgets_| might have been destroyed.
1178 return;
1179 }
1180
1181 std::set<RenderWidgetHostImpl*>::iterator iter =
1182 created_widgets_.find(render_widget_host);
1183 if (iter != created_widgets_.end())
1184 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541185
1186 if (render_widget_host &&
1187 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491188 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1189 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541190 FOR_EACH_OBSERVER(WebContentsObserver,
1191 observers_,
1192 DidDestroyFullscreenWidget(
1193 fullscreen_widget_routing_id_));
1194 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1195 }
[email protected]b24b68a2012-09-24 21:57:261196}
1197
[email protected]b172aee2012-04-10 17:05:261198bool WebContentsImpl::PreHandleKeyboardEvent(
1199 const NativeWebKeyboardEvent& event,
1200 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481201 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131202 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481203}
1204
[email protected]b172aee2012-04-10 17:05:261205void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061206 if (browser_plugin_embedder_ &&
1207 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1208 return;
1209 }
1210
[email protected]63954792011-07-11 04:17:481211 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131212 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481213}
1214
[email protected]d92026ef2014-03-03 21:04:131215bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461216 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191217#if !defined(OS_MACOSX)
1218 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1219 // isn't done for two reasons:
1220 // -the OS already has a gesture to do this through pinch-zoom
1221 // -if a user starts an inertial scroll, let's go, and presses control
1222 // (i.e. control+tab) then the OS's buffered scroll events will come in
1223 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521224 if (delegate_ &&
1225 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461226 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521227 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1228 return true;
1229 }
[email protected]bccc4472013-04-18 16:37:191230#endif
[email protected]fb3f066e2013-02-12 19:12:521231 return false;
1232}
1233
[email protected]04bce562014-01-30 05:34:541234bool WebContentsImpl::PreHandleGestureEvent(
1235 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031236 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541237}
1238
[email protected]bab38af2014-03-30 17:37:291239bool WebContentsImpl::HandleGestureEvent(
1240 const blink::WebGestureEvent& event) {
1241 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1242 // Use them to implement browser zoom, as for HandleWheelEvent above.
1243 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1244 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1245 // The scale difference necessary to trigger a zoom action. Derived from
1246 // experimentation to find a value that feels reasonable.
1247 const float kZoomStepValue = 0.6f;
1248
1249 // Find the (absolute) thresholds on either side of the current zoom factor,
1250 // then convert those to actual numbers to trigger a zoom in or out.
1251 // This logic deliberately makes the range around the starting zoom value
1252 // for the gesture twice as large as the other ranges (i.e., the notches are
1253 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1254 // so that it's easier to get back to your starting point than it is to
1255 // overshoot.
1256 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1257 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1258 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1259 : -backStep;
1260 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1261 : backStep;
1262
1263 totalPinchGestureAmount_ += event.data.pinchUpdate.scale;
1264 if (totalPinchGestureAmount_ > zoomInThreshold) {
1265 currentPinchZoomStepDelta_++;
1266 delegate_->ContentsZoomChange(true);
1267 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1268 currentPinchZoomStepDelta_--;
1269 delegate_->ContentsZoomChange(false);
1270 }
1271 return true;
1272 }
1273
1274 return false;
1275}
1276
[email protected]2ceee8f2014-01-14 18:02:081277#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411278gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1279 return accessible_parent_;
1280}
1281#endif
1282
[email protected]b172aee2012-04-10 17:05:261283void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431284 if (delegate_)
1285 delegate_->HandleMouseDown();
1286}
1287
[email protected]b172aee2012-04-10 17:05:261288void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481289 if (delegate_)
1290 delegate_->HandleMouseUp();
1291}
1292
[email protected]590a634e2012-07-19 16:38:231293void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481294 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231295 delegate_->HandlePointerActivate();
1296}
1297
1298void WebContentsImpl::HandleGestureBegin() {
1299 if (delegate_)
1300 delegate_->HandleGestureBegin();
1301}
1302
1303void WebContentsImpl::HandleGestureEnd() {
1304 if (delegate_)
1305 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481306}
1307
[email protected]b172aee2012-04-10 17:05:261308void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491309 // This method is being called to enter or leave renderer-initiated fullscreen
1310 // mode. Either way, make sure any existing fullscreen widget is shut down
1311 // first.
1312 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1313 if (widget_view)
1314 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1315
[email protected]8a5e0ca2011-08-25 06:30:471316 if (delegate_)
1317 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371318
1319 FOR_EACH_OBSERVER(WebContentsObserver,
1320 observers_,
1321 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471322}
1323
[email protected]b172aee2012-04-10 17:05:261324bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381325 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121326}
1327
[email protected]a9c81f02012-06-01 00:15:441328void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1329 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371330 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441331 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371332 } else {
1333 GotResponseToLockMouseRequest(false);
1334 }
1335}
1336
[email protected]b172aee2012-04-10 17:05:261337void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371338 if (delegate_)
1339 delegate_->LostMouseLock();
1340}
1341
[email protected]bafe6cd2012-05-23 23:09:501342void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201343 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501344 int route_id,
[email protected]227692c52013-05-31 22:43:041345 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131346 const ViewHostMsg_CreateWindow_Params& params,
1347 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501348 // We usually create the new window in the same BrowsingInstance (group of
1349 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551350 // if the opener is being suppressed (in a non-guest), we create a new
1351 // SiteInstance in its own BrowsingInstance.
1352 bool is_guest = GetRenderProcessHost()->IsGuest();
1353
[email protected]04cbd3d2013-12-04 04:58:201354 // If the opener is to be suppressed, the new window can be in any process.
1355 // Since routing ids are process specific, we must not have one passed in
1356 // as argument here.
1357 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1358
[email protected]bafe6cd2012-05-23 23:09:501359 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551360 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571361 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501362 GetSiteInstance();
1363
[email protected]04cbd3d2013-12-04 04:58:201364 // A message to create a new window can only come from the active process for
1365 // this WebContentsImpl instance. If any other process sends the request,
1366 // it is invalid and the process must be terminated.
1367 if (GetRenderProcessHost()->GetID() != render_process_id) {
1368 base::ProcessHandle process_handle =
1369 RenderProcessHost::FromID(render_process_id)->GetHandle();
1370 if (process_handle != base::kNullProcessHandle) {
1371 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391372 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201373 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1374 }
1375 return;
1376 }
1377
[email protected]d1198fd2012-08-13 22:50:191378 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341379 //
1380 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301381 const std::string& partition_id =
1382 GetContentClient()->browser()->
1383 GetStoragePartitionIdForSite(GetBrowserContext(),
1384 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461385 StoragePartition* partition = BrowserContext::GetStoragePartition(
1386 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411387 DOMStorageContextWrapper* dom_storage_context =
1388 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191389 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1390 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1391 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371392
1393 if (delegate_ &&
1394 !delegate_->ShouldCreateWebContents(this,
1395 route_id,
1396 params.window_container_type,
1397 params.frame_name,
1398 params.target_url,
1399 partition_id,
1400 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011401 if (route_id != MSG_ROUTING_NONE &&
1402 !RenderViewHost::FromID(render_process_id, route_id)) {
1403 // If the embedder didn't create a WebContents for this route, we need to
1404 // delete the RenderView that had already been created.
1405 Send(new ViewMsg_Close(route_id));
1406 }
[email protected]dd6730412013-08-14 15:03:371407 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1408 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1409 main_frame_route_id);
1410 return;
1411 }
1412
1413 // Create the new web contents. This will automatically create the new
1414 // WebContentsView. In the future, we may want to create the view separately.
1415 WebContentsImpl* new_contents =
1416 new WebContentsImpl(GetBrowserContext(),
1417 params.opener_suppressed ? NULL : this);
1418
[email protected]d1198fd2012-08-13 22:50:191419 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301420 partition_id,
[email protected]d1198fd2012-08-13 22:50:191421 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461422 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591423 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041424 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551425 if (!is_guest) {
1426 create_params.context = view_->GetNativeView();
1427 create_params.initial_size = view_->GetContainerSize();
1428 } else {
1429 // This makes |new_contents| act as a guest.
1430 // For more info, see comment above class BrowserPluginGuest.
1431 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1432 WebContentsImpl* new_contents_impl =
1433 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461434 BrowserPluginGuest::CreateWithOpener(instance_id,
1435 new_contents_impl->opener() != NULL,
1436 new_contents_impl,
1437 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551438 }
[email protected]1ac10dca2013-08-20 20:47:041439 if (params.disposition == NEW_BACKGROUND_TAB)
1440 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591441 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191442
[email protected]c4538072013-03-18 02:17:551443 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341444 // will be shown immediately).
1445 if (!params.opener_suppressed) {
1446 if (!is_guest) {
1447 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501448
[email protected]d70bea92013-04-05 04:23:341449 // TODO(brettw): It seems bogus that we have to call this function on the
1450 // newly created object and give it one of its own member variables.
1451 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1452 }
[email protected]bafe6cd2012-05-23 23:09:501453 // Save the created window associated with the route so we can show it
1454 // later.
1455 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1456 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101457 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501458 }
1459
1460 if (delegate_) {
1461 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071462 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131463 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501464 }
1465
1466 if (params.opener_suppressed) {
1467 // When the opener is suppressed, the original renderer cannot access the
1468 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001469 bool was_blocked = false;
1470 if (delegate_) {
1471 gfx::Rect initial_pos;
1472 delegate_->AddNewContents(
1473 this, new_contents, params.disposition, initial_pos,
1474 params.user_gesture, &was_blocked);
1475 }
1476 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211477 OpenURLParams open_params(params.target_url,
1478 Referrer(),
1479 CURRENT_TAB,
1480 PAGE_TRANSITION_LINK,
1481 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301482 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001483 new_contents->OpenURL(open_params);
1484 }
[email protected]bafe6cd2012-05-23 23:09:501485 }
1486}
1487
[email protected]a8504022013-12-04 20:23:511488void WebContentsImpl::CreateNewWidget(int render_process_id,
1489 int route_id,
[email protected]180ef242013-11-07 06:50:461490 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511491 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501492}
1493
[email protected]a8504022013-12-04 20:23:511494void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1495 int route_id) {
1496 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501497}
1498
[email protected]a8504022013-12-04 20:23:511499void WebContentsImpl::CreateNewWidget(int render_process_id,
1500 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501501 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461502 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211503 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511504 // A message to create a new widget can only come from the active process for
1505 // this WebContentsImpl instance. If any other process sends the request,
1506 // it is invalid and the process must be terminated.
1507 if (process->GetID() != render_process_id) {
1508 base::ProcessHandle process_handle =
1509 RenderProcessHost::FromID(render_process_id)->GetHandle();
1510 if (process_handle != base::kNullProcessHandle) {
1511 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391512 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511513 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1514 }
1515 return;
1516 }
1517
[email protected]bafe6cd2012-05-23 23:09:501518 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041519 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261520 created_widgets_.insert(widget_host);
1521
[email protected]83918ec2013-01-10 15:37:191522 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1523 view_->CreateViewForPopupWidget(widget_host));
1524 if (!widget_view)
1525 return;
[email protected]bafe6cd2012-05-23 23:09:501526 if (!is_fullscreen) {
1527 // Popups should not get activated.
1528 widget_view->SetPopupType(popup_type);
1529 }
1530 // Save the created widget associated with the route so we can show it later.
1531 pending_widget_views_[route_id] = widget_view;
1532
1533#if defined(OS_MACOSX)
1534 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1535 // to allow it to survive the trip without being hosted.
1536 base::mac::NSObjectRetain(widget_view->GetNativeView());
1537#endif
1538}
1539
1540void WebContentsImpl::ShowCreatedWindow(int route_id,
1541 WindowOpenDisposition disposition,
1542 const gfx::Rect& initial_pos,
1543 bool user_gesture) {
1544 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001545 if (contents) {
1546 WebContentsDelegate* delegate = GetDelegate();
1547 if (delegate) {
1548 delegate->AddNewContents(
1549 this, contents, disposition, initial_pos, user_gesture, NULL);
1550 }
1551 }
[email protected]bafe6cd2012-05-23 23:09:501552}
1553
1554void WebContentsImpl::ShowCreatedWidget(int route_id,
1555 const gfx::Rect& initial_pos) {
1556 ShowCreatedWidget(route_id, false, initial_pos);
1557}
1558
1559void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1560 ShowCreatedWidget(route_id, true, gfx::Rect());
1561}
1562
1563void WebContentsImpl::ShowCreatedWidget(int route_id,
1564 bool is_fullscreen,
1565 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501566 RenderWidgetHostViewPort* widget_host_view =
1567 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1568 if (!widget_host_view)
1569 return;
[email protected]4aebbca2013-09-17 22:26:491570 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311571 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1572 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491573 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1574 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1575 delegate_->ToggleFullscreenModeForTab(this, true);
1576 } else {
1577 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491578 }
[email protected]4aebbca2013-09-17 22:26:491579 FOR_EACH_OBSERVER(WebContentsObserver,
1580 observers_,
1581 DidShowFullscreenWidget(route_id));
1582 if (!widget_host_view->HasFocus())
1583 widget_host_view->Focus();
1584 } else {
[email protected]f8497342013-02-05 22:15:021585 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491586 }
[email protected]89054502012-06-03 10:29:241587
1588 RenderWidgetHostImpl* render_widget_host_impl =
1589 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1590 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311591 // Only allow privileged mouse lock for fullscreen render widget, which is
1592 // used to implement Pepper Flash fullscreen.
1593 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501594
1595#if defined(OS_MACOSX)
1596 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1597 // properly embedded (or purposefully ignored) we can release the retain we
1598 // took in CreateNewWidget().
1599 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1600#endif
1601}
1602
1603WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1604 PendingContents::iterator iter = pending_contents_.find(route_id);
1605
1606 // Certain systems can block the creation of new windows. If we didn't succeed
1607 // in creating one, just return NULL.
1608 if (iter == pending_contents_.end()) {
1609 return NULL;
1610 }
1611
1612 WebContentsImpl* new_contents = iter->second;
1613 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101614 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501615
[email protected]d70bea92013-04-05 04:23:341616 // Don't initialize the guest WebContents immediately.
1617 if (new_contents->GetRenderProcessHost()->IsGuest())
1618 return new_contents;
1619
[email protected]bafe6cd2012-05-23 23:09:501620 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1621 !new_contents->GetRenderViewHost()->GetView())
1622 return NULL;
1623
1624 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1625 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1626 return new_contents;
1627}
1628
1629RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1630 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1631 if (iter == pending_widget_views_.end()) {
1632 DCHECK(false);
1633 return NULL;
1634 }
1635
1636 RenderWidgetHostView* widget_host_view = iter->second;
1637 pending_widget_views_.erase(route_id);
1638
1639 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1640 if (!widget_host->GetProcess()->HasConnection()) {
1641 // The view has gone away or the renderer crashed. Nothing to do.
1642 return NULL;
1643 }
1644
1645 return widget_host_view;
1646}
1647
[email protected]f13b4202012-06-12 23:53:231648void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091649 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211650 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371651 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231652 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371653 } else {
1654 callback.Run(MediaStreamDevices(),
1655 MEDIA_DEVICE_INVALID_STATE,
1656 scoped_ptr<MediaStreamUI>());
1657 }
[email protected]f13b4202012-06-12 23:53:231658}
1659
[email protected]cc9200432013-07-23 23:02:401660SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1661 SiteInstance* instance) {
1662 return controller_.GetSessionStorageNamespace(instance);
1663}
1664
[email protected]9b159a52013-10-03 17:24:551665FrameTree* WebContentsImpl::GetFrameTree() {
1666 return &frame_tree_;
1667}
1668
[email protected]31a71eaf2014-03-13 01:47:361669void WebContentsImpl::AccessibilityEventReceived(
1670 const std::vector<AXEventNotificationDetails>& details) {
1671 FOR_EACH_OBSERVER(
1672 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1673}
1674
[email protected]edc3af82013-12-12 21:24:071675void WebContentsImpl::OnShowValidationMessage(
1676 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291677 const base::string16& main_text,
1678 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071679 if (delegate_)
1680 delegate_->ShowValidationMessage(
1681 this, anchor_in_root_view, main_text, sub_text);
1682}
1683
1684void WebContentsImpl::OnHideValidationMessage() {
1685 if (delegate_)
1686 delegate_->HideValidationMessage(this);
1687}
1688
1689void WebContentsImpl::OnMoveValidationMessage(
1690 const gfx::Rect& anchor_in_root_view) {
1691 if (delegate_)
1692 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1693}
1694
[email protected]32deec62013-05-15 23:55:041695void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1696 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441697 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041698}
1699
[email protected]b172aee2012-04-10 17:05:261700void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491701 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231702 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491703 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331704}
1705
[email protected]b172aee2012-04-10 17:05:261706void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341707 if (delegate_)
1708 delegate_->ResizeDueToAutoResize(this, new_size);
1709}
1710
[email protected]b172aee2012-04-10 17:05:261711WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201712 if (!delegate_)
1713 return NULL;
[email protected]00c37fc2011-08-02 00:22:501714
[email protected]e5d549d2011-12-28 01:29:201715 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201716 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341717}
1718
[email protected]6b618e62012-08-16 12:59:181719bool WebContentsImpl::Send(IPC::Message* message) {
1720 if (!GetRenderViewHost()) {
1721 delete message;
1722 return false;
1723 }
1724
1725 return GetRenderViewHost()->Send(message);
1726}
1727
[email protected]b172aee2012-04-10 17:05:261728bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501729 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261730 FrameTreeNode* node = frame_tree_.root();
1731
1732 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1733 // specified in the pending entry.
1734 NavigationEntryImpl* pending_entry =
1735 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1736 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1737 pending_entry->frame_tree_node_id() != -1) {
1738 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1739 }
1740
1741 return node->navigator()->NavigateToPendingEntry(
1742 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541743}
[email protected]96d185d2009-04-24 03:28:541744
[email protected]a86c0e962013-12-17 17:10:391745void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1746 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441747 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391748 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441749}
1750
[email protected]20ca0382013-02-28 19:50:071751void WebContentsImpl::AttachInterstitialPage(
1752 InterstitialPageImpl* interstitial_page) {
1753 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211754 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291755
1756 // Cancel any visible dialogs so that they don't interfere with the
1757 // interstitial.
1758 if (dialog_manager_)
1759 dialog_manager_->CancelActiveAndPendingDialogs(this);
1760
[email protected]20ca0382013-02-28 19:50:071761 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1762 DidAttachInterstitialPage());
1763}
1764
1765void WebContentsImpl::DetachInterstitialPage() {
1766 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211767 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071768 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1769 DidDetachInterstitialPage());
1770}
1771
[email protected]b172aee2012-04-10 17:05:261772void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331773 const SiteInstance* site_instance,
1774 int history_length,
1775 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411776 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1777 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211778 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191779 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141780 return;
[email protected]9e1ad4b2011-08-14 16:49:191781 }
[email protected]9f76c1e2012-03-05 15:15:581782 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191783 if (!rvh) {
1784 NOTREACHED();
1785 return;
1786 }
[email protected]9f76c1e2012-03-05 15:15:581787 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191788 NOTREACHED();
1789 return;
1790 }
[email protected]6b618e62012-08-16 12:59:181791 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1792 history_length,
1793 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141794}
1795
[email protected]4fed3702014-04-01 09:08:001796void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171797 RenderFrameHost* focused_frame = GetFocusedFrame();
1798 if (!focused_frame)
1799 return;
1800
[email protected]959be4c2014-04-08 15:01:331801 focused_frame->Send(new FrameMsg_Reload(
1802 focused_frame->GetRoutingID(), ignore_cache));
1803}
1804
1805void WebContentsImpl::Undo() {
1806 RenderFrameHost* focused_frame = GetFocusedFrame();
1807 if (!focused_frame)
1808 return;
1809
1810 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1811 RecordAction(base::UserMetricsAction("Undo"));
1812}
1813
1814void WebContentsImpl::Redo() {
1815 RenderFrameHost* focused_frame = GetFocusedFrame();
1816 if (!focused_frame)
1817 return;
1818 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1819 RecordAction(base::UserMetricsAction("Redo"));
1820}
1821
1822void WebContentsImpl::Cut() {
1823 RenderFrameHost* focused_frame = GetFocusedFrame();
1824 if (!focused_frame)
1825 return;
1826
1827 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1828 RecordAction(base::UserMetricsAction("Cut"));
1829}
1830
1831void WebContentsImpl::Copy() {
1832 RenderFrameHost* focused_frame = GetFocusedFrame();
1833 if (!focused_frame)
1834 return;
1835
1836 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1837 RecordAction(base::UserMetricsAction("Copy"));
1838}
1839
1840void WebContentsImpl::CopyToFindPboard() {
1841#if defined(OS_MACOSX)
1842 RenderFrameHost* focused_frame = GetFocusedFrame();
1843 if (!focused_frame)
1844 return;
1845
1846 // Windows/Linux don't have the concept of a find pasteboard.
1847 focused_frame->Send(
1848 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1849 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1850#endif
1851}
1852
1853void WebContentsImpl::Paste() {
1854 RenderFrameHost* focused_frame = GetFocusedFrame();
1855 if (!focused_frame)
1856 return;
1857
1858 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1859 RecordAction(base::UserMetricsAction("Paste"));
1860}
1861
1862void WebContentsImpl::PasteAndMatchStyle() {
1863 RenderFrameHost* focused_frame = GetFocusedFrame();
1864 if (!focused_frame)
1865 return;
1866
1867 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1868 focused_frame->GetRoutingID()));
1869 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1870}
1871
1872void WebContentsImpl::Delete() {
1873 RenderFrameHost* focused_frame = GetFocusedFrame();
1874 if (!focused_frame)
1875 return;
1876
1877 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1878 RecordAction(base::UserMetricsAction("DeleteSelection"));
1879}
1880
1881void WebContentsImpl::SelectAll() {
1882 RenderFrameHost* focused_frame = GetFocusedFrame();
1883 if (!focused_frame)
1884 return;
1885
1886 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1887 RecordAction(base::UserMetricsAction("SelectAll"));
1888}
1889
1890void WebContentsImpl::Unselect() {
1891 RenderFrameHost* focused_frame = GetFocusedFrame();
1892 if (!focused_frame)
1893 return;
1894
1895 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1896 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171897}
1898
1899void WebContentsImpl::Replace(const base::string16& word) {
1900 RenderFrameHost* focused_frame = GetFocusedFrame();
1901 if (!focused_frame)
1902 return;
1903
[email protected]959be4c2014-04-08 15:01:331904 focused_frame->Send(new InputMsg_Replace(
1905 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171906}
1907
1908void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1909 RenderFrameHost* focused_frame = GetFocusedFrame();
1910 if (!focused_frame)
1911 return;
1912
[email protected]959be4c2014-04-08 15:01:331913 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1914 focused_frame->GetRoutingID(), word));
1915}
1916
1917void WebContentsImpl::NotifyContextMenuClosed(
1918 const CustomContextMenuContext& context) {
1919 RenderFrameHost* focused_frame = GetFocusedFrame();
1920 if (!focused_frame)
1921 return;
1922
1923 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1924 focused_frame->GetRoutingID(), context));
1925}
1926
1927void WebContentsImpl::ExecuteCustomContextMenuCommand(
1928 int action, const CustomContextMenuContext& context) {
1929 RenderFrameHost* focused_frame = GetFocusedFrame();
1930 if (!focused_frame)
1931 return;
1932
1933 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1934 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001935}
1936
[email protected]b172aee2012-04-10 17:05:261937void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271938 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211939 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541940 return;
1941 }
[email protected]9f76c1e2012-03-05 15:15:581942 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541943}
1944
[email protected]b172aee2012-04-10 17:05:261945bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211946 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541947}
1948
[email protected]b172aee2012-04-10 17:05:261949InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211950 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221951}
1952
[email protected]b172aee2012-04-10 17:05:261953bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161954 // WebKit creates Document object when MIME type is application/xhtml+xml,
1955 // so we also support this MIME type.
1956 return contents_mime_type_ == "text/html" ||
1957 contents_mime_type_ == "text/xml" ||
1958 contents_mime_type_ == "application/xhtml+xml" ||
1959 contents_mime_type_ == "text/plain" ||
1960 contents_mime_type_ == "text/css" ||
1961 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1962}
1963
[email protected]b172aee2012-04-10 17:05:261964void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591965 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161966 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551967 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011968 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141969 return;
[email protected]c7dd2f62011-07-18 15:57:591970 }
1971
1972 Stop();
1973
1974 // Create the save package and possibly prompt the user for the name to save
1975 // the page as. The user prompt is an asynchronous operation that runs on
1976 // another thread.
1977 save_package_ = new SavePackage(this);
1978 save_package_->GetSaveInfo();
1979}
1980
1981// Used in automated testing to bypass prompting the user for file names.
1982// Instead, the names and paths are hard coded rather than running them through
1983// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341984bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1985 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211986 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591987 // Stop the page from navigating.
1988 Stop();
1989
1990 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211991 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591992}
1993
[email protected]3c71576ce2013-07-23 02:00:011994void WebContentsImpl::SaveFrame(const GURL& url,
1995 const Referrer& referrer) {
1996 if (!GetURL().is_valid())
1997 return;
1998 bool is_main_frame = (url == GetURL());
1999
2000 DownloadManager* dlm =
2001 BrowserContext::GetDownloadManager(GetBrowserContext());
2002 if (!dlm)
2003 return;
2004 int64 post_id = -1;
2005 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272006 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012007 if (entry)
2008 post_id = entry->GetPostID();
2009 }
2010 scoped_ptr<DownloadUrlParameters> params(
2011 DownloadUrlParameters::FromWebContents(this, url));
2012 params->set_referrer(referrer);
2013 params->set_post_id(post_id);
2014 params->set_prefer_cache(true);
2015 if (post_id >= 0)
2016 params->set_method("POST");
2017 params->set_prompt(true);
2018 dlm->DownloadUrl(params.Pass());
2019}
2020
[email protected]b172aee2012-04-10 17:05:262021void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342022 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482023 const base::Callback<void(int64)>& callback) {
2024 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122025}
2026
[email protected]6286a372013-10-09 04:03:272027// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262028bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272029 NavigationEntryImpl* visible_entry =
2030 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2031 return (visible_entry != NULL &&
2032 visible_entry->site_instance() == GetSiteInstance() &&
2033 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322034}
2035
[email protected]b172aee2012-04-10 17:05:262036const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272037 return contents_mime_type_;
2038}
2039
[email protected]b172aee2012-04-10 17:05:262040bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272041 return notify_disconnection_;
2042}
2043
[email protected]b172aee2012-04-10 17:05:262044void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312045 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182046 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162047}
2048
[email protected]b172aee2012-04-10 17:05:262049void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:312050 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182051 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162052}
2053
[email protected]8ff00d72012-10-23 19:12:212054RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272055 return &renderer_preferences_;
2056}
2057
[email protected]e35ccd52012-05-23 16:22:472058void WebContentsImpl::Close() {
2059 Close(GetRenderViewHost());
2060}
2061
[email protected]cf200a562013-05-03 16:24:292062void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462063 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292064 if (browser_plugin_embedder_.get())
2065 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2066 screen_x, screen_y, operation);
2067 if (GetRenderViewHost())
2068 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2069 screen_x, screen_y, operation);
2070}
2071
[email protected]d60f3702013-12-26 16:30:242072void WebContentsImpl::DidGetResourceResponseStart(
2073 const ResourceRequestDetails& details) {
2074 controller_.ssl_manager()->DidStartResourceResponse(details);
2075
2076 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2077 DidGetResourceResponseStart(details));
2078
2079 // TODO(avi): Remove. http://crbug.com/170921
2080 NotificationService::current()->Notify(
2081 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2082 Source<WebContents>(this),
2083 Details<const ResourceRequestDetails>(&details));
2084}
2085
2086void WebContentsImpl::DidGetRedirectForResourceRequest(
2087 RenderViewHost* render_view_host,
2088 const ResourceRedirectDetails& details) {
2089 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2090
2091 FOR_EACH_OBSERVER(
2092 WebContentsObserver,
2093 observers_,
2094 DidGetRedirectForResourceRequest(render_view_host, details));
2095
2096 // TODO(avi): Remove. http://crbug.com/170921
2097 NotificationService::current()->Notify(
2098 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2099 Source<WebContents>(this),
2100 Details<const ResourceRedirectDetails>(&details));
2101}
2102
[email protected]b172aee2012-04-10 17:05:262103void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522104 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582105 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512106 if (delegate_)
2107 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292108 if (browser_plugin_embedder_.get())
2109 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342110}
2111
[email protected]e35ccd52012-05-23 16:22:472112void WebContentsImpl::UserGestureDone() {
2113 OnUserGesture();
2114}
2115
[email protected]b172aee2012-04-10 17:05:262116void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272117 closed_by_user_gesture_ = value;
2118}
2119
[email protected]b172aee2012-04-10 17:05:262120bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272121 return closed_by_user_gesture_;
2122}
2123
[email protected]b172aee2012-04-10 17:05:262124double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052125 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562126 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252127 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172128 return 0;
[email protected]b75b8292010-10-01 07:28:252129
2130 double zoom_level;
2131 if (temporary_zoom_settings_) {
2132 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582133 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252134 } else {
[email protected]2ae88d12011-10-14 09:11:192135 GURL url;
[email protected]6286a372013-10-09 04:03:272136 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192137 // Since zoom map is updated using rewritten URL, use rewritten URL
2138 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272139 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022140 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2141 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252142 }
[email protected]d0b8d092010-10-25 04:05:172143 return zoom_level;
2144}
[email protected]b75b8292010-10-01 07:28:252145
[email protected]b172aee2012-04-10 17:05:262146int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592147 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172148 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012149 // Calculate the zoom percent from the factor. Round up to the nearest whole
2150 // number.
[email protected]b75b8292010-10-01 07:28:252151 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492152 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252153 *enable_decrement = percent > minimum_zoom_percent_;
2154 *enable_increment = percent < maximum_zoom_percent_;
2155 return percent;
2156}
2157
[email protected]b172aee2012-04-10 17:05:262158void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502159 if (!delegate_)
2160 return;
2161
[email protected]6286a372013-10-09 04:03:272162 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2163 if (!entry)
[email protected]1788e772010-12-15 16:40:502164 return;
2165
[email protected]6286a372013-10-09 04:03:272166 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122167}
2168
[email protected]b172aee2012-04-10 17:05:262169void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042170 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272171 if (!delegate_)
2172 return;
2173
[email protected]691aa2f2013-05-28 22:52:042174 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272175}
2176
[email protected]b172aee2012-04-10 17:05:262177int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272178 return minimum_zoom_percent_;
2179}
2180
[email protected]b172aee2012-04-10 17:05:262181int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272182 return maximum_zoom_percent_;
2183}
2184
[email protected]b172aee2012-04-10 17:05:262185gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492186 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232187}
2188
[email protected]b172aee2012-04-10 17:05:262189bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272190 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582191 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272192}
2193
[email protected]b172aee2012-04-10 17:05:262194bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442195 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502196}
2197
[email protected]cb805452013-05-22 15:16:212198void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482199 if (!color_chooser_info_.get())
2200 return;
2201 RenderFrameHost* rfh = RenderFrameHost::FromID(
2202 color_chooser_info_->render_process_id,
2203 color_chooser_info_->render_frame_id);
2204 if (!rfh)
2205 return;
2206
2207 rfh->Send(new FrameMsg_DidChooseColorResponse(
2208 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202209}
2210
[email protected]cb805452013-05-22 15:16:212211void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482212 if (!color_chooser_info_.get())
2213 return;
2214 RenderFrameHost* rfh = RenderFrameHost::FromID(
2215 color_chooser_info_->render_process_id,
2216 color_chooser_info_->render_frame_id);
2217 if (!rfh)
2218 return;
2219
2220 rfh->Send(new FrameMsg_DidEndColorChooser(
2221 rfh->GetRoutingID(), color_chooser_info_->identifier));
2222 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202223}
2224
[email protected]41225fe2013-03-29 05:32:022225int WebContentsImpl::DownloadImage(const GURL& url,
2226 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302227 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022228 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582229 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022230 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392231 return id;
2232}
2233
[email protected]5dcaf8e2013-12-28 01:31:422234bool WebContentsImpl::IsSubframe() const {
2235 return is_subframe_;
2236}
2237
[email protected]9649d492014-01-10 07:15:522238void WebContentsImpl::SetZoomLevel(double level) {
2239 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2240 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2241 if (embedder)
2242 embedder->SetZoomLevel(level);
2243}
2244
[email protected]36ec24f2014-01-09 00:32:082245void WebContentsImpl::Find(int request_id,
2246 const base::string16& search_text,
2247 const blink::WebFindOptions& options) {
2248 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2249}
2250
2251void WebContentsImpl::StopFinding(StopFindAction action) {
2252 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2253}
2254
[email protected]4fe53add2014-04-08 19:53:362255void WebContentsImpl::InsertCSS(const std::string& css) {
2256 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2257 GetMainFrame()->GetRoutingID(), css));
2258}
2259
[email protected]b172aee2012-04-10 17:05:262260bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272261 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202262 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332263 return true;
2264 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272265}
2266
[email protected]b172aee2012-04-10 17:05:262267void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272268 if (delegate_)
2269 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212270}
2271
[email protected]52913802013-12-10 05:52:182272void WebContentsImpl::DidStartProvisionalLoad(
2273 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072274 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182275 const GURL& validated_url,
2276 bool is_error_page,
2277 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262278 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182279 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572280 DidChangeLoadProgress(0);
2281
[email protected]0d60f0192011-04-14 12:40:102282 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272283 int render_frame_id = render_frame_host->GetRoutingID();
2284 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252285 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072286 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272287 render_frame_id, parent_routing_id, is_main_frame,
2288 validated_url, is_error_page, is_iframe_srcdoc,
2289 render_view_host));
[email protected]400992b2012-06-14 00:03:542290
2291 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182292 FOR_EACH_OBSERVER(
2293 WebContentsObserver,
2294 observers_,
2295 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582296 render_frame_host));
[email protected]400992b2012-06-14 00:03:542297 }
2298}
2299
[email protected]3109fbb72014-01-06 23:57:152300void WebContentsImpl::DidFailProvisionalLoadWithError(
2301 RenderFrameHostImpl* render_frame_host,
2302 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2303 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272304 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262305 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272306 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152307 FOR_EACH_OBSERVER(
2308 WebContentsObserver,
2309 observers_,
[email protected]161eabd2014-03-19 19:47:272310 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152311 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262312 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152313 validated_url,
2314 params.error_code,
2315 params.error_description,
[email protected]161eabd2014-03-19 19:47:272316 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152317}
2318
[email protected]b80624c2014-02-09 02:46:552319void WebContentsImpl::DidFailLoadWithError(
2320 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552321 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552322 int error_code,
2323 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272324 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262325 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272326 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552327 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272328 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262329 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552330}
2331
[email protected]52913802013-12-10 05:52:182332void WebContentsImpl::NotifyChangedNavigationState(
2333 InvalidateTypes changed_flags) {
2334 NotifyNavigationStateChanged(changed_flags);
2335}
2336
[email protected]3691e5cf2014-01-22 10:16:202337void WebContentsImpl::AboutToNavigateRenderFrame(
2338 RenderFrameHostImpl* render_frame_host) {
2339 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272340 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202341 FOR_EACH_OBSERVER(
2342 WebContentsObserver,
2343 observers_,
[email protected]161eabd2014-03-19 19:47:272344 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202345}
2346
2347void WebContentsImpl::DidStartNavigationToPendingEntry(
2348 RenderFrameHostImpl* render_frame_host,
2349 const GURL& url,
2350 NavigationController::ReloadType reload_type) {
2351 // Notify observers about navigation.
2352 FOR_EACH_OBSERVER(
2353 WebContentsObserver,
2354 observers_,
2355 DidStartNavigationToPendingEntry(url, reload_type));
2356}
2357
[email protected]8cb834e2014-03-06 14:23:232358void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2359 const OpenURLParams& params) {
2360 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182361 WebContents* new_contents = OpenURL(params);
2362
2363 if (new_contents) {
2364 // Notify observers.
2365 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2366 DidOpenRequestedURL(new_contents,
2367 params.url,
2368 params.referrer,
2369 params.disposition,
2370 params.transition,
[email protected]8cb834e2014-03-06 14:23:232371 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182372 }
2373}
2374
[email protected]400992b2012-06-14 00:03:542375void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582376 RenderFrameHostImpl* render_frame_host,
2377 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542378 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582379 FOR_EACH_OBSERVER(
2380 WebContentsObserver,
2381 observers_,
2382 ProvisionalChangeToMainFrameUrl(validated_target_url,
2383 render_frame_host));
[email protected]724159a2010-12-30 01:11:182384}
2385
[email protected]37567b432014-02-12 01:12:222386void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432387 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222388 const base::string16& frame_unique_name,
2389 bool is_main_frame,
2390 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432391 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432392 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272393 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222394 // Notify observers about the commit of the provisional load.
2395 FOR_EACH_OBSERVER(
2396 WebContentsObserver,
2397 observers_,
[email protected]27dd82fd2014-03-03 22:11:432398 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222399 frame_unique_name,
2400 is_main_frame,
2401 url,
2402 transition_type,
2403 render_view_host));
2404}
2405
[email protected]0d0f4c492014-04-02 06:42:572406void WebContentsImpl::DidNavigateMainFramePreCommit(
2407 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2408 // Ensure fullscreen mode is exited before committing the navigation to a
2409 // different page. The next page will not start out assuming it is in
2410 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192411 if (controller_.IsURLInPageNavigation(params.url,
2412 params.was_within_same_page,
2413 NAVIGATION_TYPE_UNKNOWN)) {
2414 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572415 return;
2416 }
2417 if (IsFullscreenForCurrentTab())
2418 GetRenderViewHost()->ExitFullscreen();
2419 DCHECK(!IsFullscreenForCurrentTab());
2420}
2421
[email protected]37567b432014-02-12 01:12:222422void WebContentsImpl::DidNavigateMainFramePostCommit(
2423 const LoadCommittedDetails& details,
2424 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2425 if (details.is_navigation_to_different_page()) {
2426 // Clear the status bubble. This is a workaround for a bug where WebKit
2427 // doesn't let us know that the cursor left an element during a
2428 // transition (this is also why the mouse cursor remains as a hand after
2429 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2430 // clear the bubble when a user navigates to a named anchor in the same
2431 // page.
2432 UpdateTargetURL(details.entry->GetPageID(), GURL());
2433 }
2434
2435 if (!details.is_in_page) {
2436 // Once the main frame is navigated, we're no longer considered to have
2437 // displayed insecure content.
2438 displayed_insecure_content_ = false;
2439 SSLManager::NotifySSLInternalStateChanged(
2440 GetController().GetBrowserContext());
2441 }
2442
2443 // Notify observers about navigation.
2444 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2445 DidNavigateMainFrame(details, params));
2446
2447 if (delegate_) {
2448 delegate_->DidNavigateMainFramePostCommit(this);
2449 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2450 }
2451}
2452
2453void WebContentsImpl::DidNavigateAnyFramePostCommit(
2454 RenderFrameHostImpl* render_frame_host,
2455 const LoadCommittedDetails& details,
2456 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2457 // If we navigate off the page, close all JavaScript dialogs.
2458 if (dialog_manager_ && !details.is_in_page)
2459 dialog_manager_->CancelActiveAndPendingDialogs(this);
2460
2461 // Notify observers about navigation.
2462 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2463 DidNavigateAnyFrame(details, params));
2464}
2465
2466void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2467 contents_mime_type_ = mime_type;
2468}
2469
2470bool WebContentsImpl::CanOverscrollContent() {
2471 if (delegate_)
2472 return delegate_->CanOverscrollContent();
2473
2474 return false;
2475}
2476
[email protected]b172aee2012-04-10 17:05:262477void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182478 const GURL& url,
[email protected]70435962011-08-02 20:13:282479 const std::string& security_info,
2480 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182481 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282482 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192483 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182484 cache.Increment();
2485
2486 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082487 int cert_id = 0;
2488 net::CertStatus cert_status = 0;
2489 int security_bits = -1;
2490 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122491 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212492 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122493 &security_bits, &connection_status,
2494 &signed_certificate_timestamp_ids);
2495 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212496 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002497 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2498 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182499
[email protected]b0f724c2013-09-05 04:21:132500 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2501
2502 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2503 DidLoadResourceFromMemoryCache(details));
2504
[email protected]8bfc8272013-09-09 20:10:532505 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2506 scoped_refptr<net::URLRequestContextGetter> request_context(
2507 resource_type == ResourceType::MEDIA ?
2508 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2509 GetRenderProcessHost()->GetID()) :
2510 GetBrowserContext()->GetRequestContextForRenderProcess(
2511 GetRenderProcessHost()->GetID()));
2512 BrowserThread::PostTask(
2513 BrowserThread::IO,
2514 FROM_HERE,
2515 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2516 }
[email protected]724159a2010-12-30 01:11:182517}
2518
[email protected]b172aee2012-04-10 17:05:262519void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392520 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182521 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192522 SSLManager::NotifySSLInternalStateChanged(
2523 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182524}
2525
[email protected]b172aee2012-04-10 17:05:262526void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022527 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582528 LOG(WARNING) << security_origin << " ran insecure content from "
2529 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392530 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412531 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392532 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182533 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412534 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192535 SSLManager::NotifySSLInternalStateChanged(
2536 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182537}
2538
[email protected]501052ff2014-02-21 22:19:072539void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572540 CHECK(render_frame_message_source_);
2541 CHECK(!render_view_message_source_);
2542 RenderFrameHostImpl* rfh =
2543 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2544
[email protected]161eabd2014-03-19 19:47:272545 int render_frame_id = rfh->GetRoutingID();
2546 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572547 FOR_EACH_OBSERVER(WebContentsObserver,
2548 observers_,
[email protected]161eabd2014-03-19 19:47:272549 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182550}
2551
[email protected]b172aee2012-04-10 17:05:262552void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262553 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372554 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122555 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2556 GetRenderProcessHost()->ReceivedBadMessage();
2557 return;
2558 }
[email protected]a1b99262013-12-27 21:56:222559
[email protected]8b3af1e2014-01-24 13:29:122560 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442561 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372562 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422563 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372564
[email protected]61ac9e242014-03-21 20:55:262565 RenderFrameHostImpl* rfh =
2566 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272567 int render_frame_id = rfh->GetRoutingID();
2568 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262569 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252570 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272571 DidFinishLoad(render_frame_id, validated_url,
2572 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312573}
2574
[email protected]b172aee2012-04-10 17:05:262575void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222576 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2577 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262578}
2579
[email protected]b172aee2012-04-10 17:05:262580void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2581 int maximum_percent,
2582 bool remember) {
[email protected]216813952011-05-19 22:21:262583 minimum_zoom_percent_ = minimum_percent;
2584 maximum_zoom_percent_ = maximum_percent;
2585 temporary_zoom_settings_ = !remember;
2586}
2587
[email protected]b172aee2012-04-10 17:05:262588void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342589 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432590 if (!delegate_)
2591 return;
2592
[email protected]b9535422012-02-09 01:47:592593 ChildProcessSecurityPolicyImpl* policy =
2594 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222595 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592596 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212597}
2598
[email protected]b172aee2012-04-10 17:05:262599void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2600 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262601 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362602 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432603 if (!delegate_)
2604 return;
2605
[email protected]b9535422012-02-09 01:47:592606 ChildProcessSecurityPolicyImpl* policy =
2607 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322608 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592609 return;
[email protected]8f810632013-06-06 22:33:322610
[email protected]3a3b75a2012-06-01 08:38:362611 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202612}
2613
[email protected]b172aee2012-04-10 17:05:262614void WebContentsImpl::OnFindReply(int request_id,
2615 int number_of_matches,
2616 const gfx::Rect& selection_rect,
2617 int active_match_ordinal,
2618 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432619 if (delegate_) {
2620 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2621 active_match_ordinal, final_update);
2622 }
[email protected]b888919c2011-09-02 00:32:162623}
2624
[email protected]59363fc92012-09-05 03:46:312625#if defined(OS_ANDROID)
2626void WebContentsImpl::OnFindMatchRectsReply(
2627 int version,
2628 const std::vector<gfx::RectF>& rects,
2629 const gfx::RectF& active_rect) {
2630 if (delegate_)
2631 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2632}
[email protected]583418cc2013-01-17 14:01:102633
[email protected]1ff427972013-02-07 21:14:072634void WebContentsImpl::OnOpenDateTimeDialog(
2635 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092636 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2637 GetRenderViewHost(),
2638 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132639 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092640 value.minimum,
2641 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172642 value.step,
2643 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102644}
2645
[email protected]a794f3a2013-10-30 17:00:322646void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2647 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]c06c58c2014-03-12 20:31:592648 render_frame_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322649}
2650
[email protected]59363fc92012-09-05 03:46:312651#endif
2652
[email protected]f114fa42013-12-06 17:06:442653void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2654 const base::FilePath& path,
2655 bool is_hung) {
2656 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2657
2658 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2659 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2660}
2661
2662void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422663 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442664 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422665 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452666}
2667
[email protected]cfa856d62014-02-22 07:58:402668void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2669 int automation_id) {
2670 DomOperationNotificationDetails details(json_string, automation_id);
2671 NotificationService::current()->Notify(
2672 NOTIFICATION_DOM_OPERATION_RESPONSE,
2673 Source<WebContents>(this),
2674 Details<DomOperationNotificationDetails>(&details));
2675}
2676
[email protected]b172aee2012-04-10 17:05:262677void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2678 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102679 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252680 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102681 AppCacheAccessed(manifest_url, blocked_by_policy));
2682}
2683
[email protected]8bc5ff02013-11-29 06:34:032684void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482685 int color_chooser_id,
2686 SkColor color,
2687 const std::vector<ColorSuggestion>& suggestions) {
[email protected]8bc5ff02013-11-29 06:34:032688 ColorChooser* new_color_chooser =
2689 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302690 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212691 return;
[email protected]8ed16472014-04-11 19:02:482692 if (color_chooser_info_.get())
2693 color_chooser_info_->chooser->End();
2694
2695 color_chooser_info_.reset(new ColorChooserInfo(
2696 render_frame_message_source_->GetProcess()->GetID(),
2697 render_frame_message_source_->GetRoutingID(),
2698 new_color_chooser,
2699 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202700}
2701
[email protected]b172aee2012-04-10 17:05:262702void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482703 if (color_chooser_info_ &&
2704 color_chooser_id == color_chooser_info_->identifier)
2705 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202706}
2707
[email protected]b172aee2012-04-10 17:05:262708void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322709 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482710 if (color_chooser_info_ &&
2711 color_chooser_id == color_chooser_info_->identifier)
2712 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202713}
2714
[email protected]d0759f492012-04-19 22:50:502715// This exists for render views that don't have a WebUI, but do have WebUI
2716// bindings enabled.
2717void WebContentsImpl::OnWebUISend(const GURL& source_url,
2718 const std::string& name,
2719 const base::ListValue& args) {
2720 if (delegate_)
2721 delegate_->WebUISend(this, source_url, name, args);
2722}
2723
[email protected]d8415ad92012-08-23 14:40:502724void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442725 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502726 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342727 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162728 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442729 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162730 return;
[email protected]d8415ad92012-08-23 14:40:502731 }
2732
[email protected]8c8fc292012-11-23 18:57:162733 if (!delegate_->RequestPpapiBrokerPermission(
2734 this, url, plugin_path,
2735 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442736 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162737 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442738 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162739 }
[email protected]d8415ad92012-08-23 14:40:502740}
2741
[email protected]ea0309c2013-08-06 19:35:442742void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502743 bool result) {
[email protected]ea0309c2013-08-06 19:35:442744 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502745}
2746
[email protected]c4538072013-03-18 02:17:552747void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372748 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082749 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552750 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392751 // For more info, see comment above classes BrowserPluginEmbedder and
2752 // BrowserPluginGuest.
2753 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142754 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082755 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372756}
2757
[email protected]41225fe2013-03-29 05:32:022758void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392759 int id,
[email protected]749fadd2013-05-15 08:37:482760 int http_status_code,
[email protected]795c28972012-12-06 06:13:392761 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302762 const std::vector<SkBitmap>& bitmaps,
2763 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132764 if (bitmaps.size() != original_bitmap_sizes.size())
2765 return;
2766
[email protected]41225fe2013-03-29 05:32:022767 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2768 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392769 // Currently WebContents notifies us of ANY downloads so that it is
2770 // possible to get here.
2771 return;
2772 }
2773 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302774 iter->second.Run(
2775 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392776 }
[email protected]41225fe2013-03-29 05:32:022777 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392778}
2779
2780void WebContentsImpl::OnUpdateFaviconURL(
2781 int32 page_id,
2782 const std::vector<FaviconURL>& candidates) {
2783 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2784 DidUpdateFaviconURL(page_id, candidates));
2785}
2786
[email protected]1dd0bb752014-02-01 01:16:262787void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2788 bool has_video,
2789 bool has_audio) {
2790// Chrome OS does its own detection of audio and video.
2791#if !defined(OS_CHROMEOS)
2792 scoped_ptr<PowerSaveBlocker> blocker;
2793 if (has_video) {
2794 blocker = PowerSaveBlocker::Create(
2795 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2796#if defined(OS_ANDROID)
2797 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2798 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2799#endif
2800 } else if (has_audio) {
2801 blocker = PowerSaveBlocker::Create(
2802 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2803 }
2804
2805 if (blocker) {
2806 power_save_blockers_[render_view_message_source_][player_cookie] =
2807 blocker.release();
2808 }
2809#endif // !defined(OS_CHROMEOS)
2810}
2811
2812void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062813 // Chrome OS does its own detection of audio and video.
2814#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262815 delete power_save_blockers_[render_view_message_source_][player_cookie];
2816 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062817#endif // !defined(OS_CHROMEOS)
2818}
2819
[email protected]9f268072013-11-07 00:02:152820void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2821 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2822 DidFirstVisuallyNonEmptyPaint(page_id));
2823}
[email protected]d9030b82013-07-19 08:26:062824
[email protected]e67ebf32013-02-13 11:07:192825void WebContentsImpl::DidChangeVisibleSSLState() {
2826 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2827 DidChangeVisibleSSLState());
2828}
2829
[email protected]17e286e2013-03-01 23:29:392830void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2831 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2832 BeforeFormRepostWarningShow());
2833}
2834
[email protected]ec6c05f2013-10-23 18:41:572835
2836void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2837 Activate();
2838 if (delegate_)
2839 delegate_->ShowRepostFormWarningDialog(this);
2840}
2841
[email protected]96d185d2009-04-24 03:28:542842// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592843// loading, or done loading.
2844void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2845 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092846 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262847 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542848 if (is_loading == is_loading_)
2849 return;
2850
2851 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262852 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2853 base::string16());
[email protected]96d185d2009-04-24 03:28:542854 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562855 upload_size_ = 0;
2856 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542857 }
2858
[email protected]fa944cb82013-11-15 17:51:212859 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542860
2861 is_loading_ = is_loading;
2862 waiting_for_response_ = is_loading;
2863
[email protected]6ebdc9b2010-09-27 16:55:572864 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092865 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212866 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542867
[email protected]eab61442013-11-14 18:35:482868 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592869 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482870 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2871 "URL", url);
[email protected]91621872013-10-08 04:04:592872 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2873 DidStartLoading(render_view_host));
2874 } else {
[email protected]eab61442013-11-14 18:35:482875 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2876 "URL", url);
[email protected]91621872013-10-08 04:04:592877 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2878 DidStopLoading(render_view_host));
2879 }
[email protected]66798902013-10-01 18:40:162880
2881 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212882 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2883 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542884 if (details)
[email protected]8ff00d72012-10-23 19:12:212885 det = Details<LoadNotificationDetails>(details);
2886 NotificationService::current()->Notify(
2887 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542888}
2889
[email protected]959be4c2014-04-08 15:01:332890void WebContentsImpl::SelectRange(const gfx::Point& start,
2891 const gfx::Point& end) {
2892 RenderFrameHost* focused_frame = GetFocusedFrame();
2893 if (!focused_frame)
2894 return;
2895
2896 focused_frame->Send(
2897 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
2898}
2899
[email protected]b172aee2012-04-10 17:05:262900void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462901 // If we are creating a RVH for a restored controller, then we need to make
2902 // sure the RenderView starts with a next_page_id_ larger than the number
2903 // of restored entries. This must be called before the RenderView starts
2904 // navigating (to avoid a race between the browser updating max_page_id and
2905 // the renderer updating next_page_id_). Because of this, we only call this
2906 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562907 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582908 if (max_restored_page_id >
2909 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2910 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2911 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322912}
2913
[email protected]b172aee2012-04-10 17:05:262914bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262915 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322916 // For file URLs without a title, use the pathname instead. In the case of a
2917 // synthesized title, we don't want the update to count toward the "one set
2918 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262919 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322920 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512921 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242922 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322923 explicit_set = false; // Don't count synthetic titles toward the set limit.
2924 } else {
[email protected]8af69c6c2014-03-03 19:05:312925 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322926 explicit_set = true;
2927 }
2928
[email protected]987fc3a2011-05-26 14:18:092929 // If a page is created via window.open and never navigated,
2930 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552931 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092932 if (entry) {
[email protected]36fc0392011-12-25 03:59:512933 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092934 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322935
[email protected]36fc0392011-12-25 03:59:512936 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092937 } else {
2938 if (page_title_when_no_navigation_entry_ == final_title)
2939 return false; // Nothing changed, don't bother.
2940
2941 page_title_when_no_navigation_entry_ = final_title;
2942 }
[email protected]420ae012009-04-24 05:16:322943
[email protected]420ae012009-04-24 05:16:322944 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232945 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322946
[email protected]66798902013-10-01 18:40:162947 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532948 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162949
2950 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212951 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462952 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212953 NotificationService::current()->Notify(
2954 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2955 Source<WebContents>(this),
2956 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042957
[email protected]420ae012009-04-24 05:16:322958 return true;
2959}
2960
[email protected]7b712ee22013-10-03 00:57:282961void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2962 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322963 // After sending out a swap notification, we need to send a disconnect
2964 // notification so that clients that pick up a pointer to |this| can NULL the
2965 // pointer. See Bug 1230284.
2966 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112967 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282968 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112969
2970 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282971 std::pair<RenderViewHost*, RenderViewHost*> details =
2972 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212973 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282974 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212975 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282976 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392977
2978 // Ensure that the associated embedder gets cleared after a RenderViewHost
2979 // gets swapped, so we don't reuse the same embedder next time a
2980 // RenderViewHost is attached to this WebContents.
2981 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322982}
2983
[email protected]da7a7182013-09-06 08:11:112984// TODO(avi): Remove this entire function because this notification is already
2985// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262986void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322987 if (!notify_disconnection_)
2988 return;
2989
2990 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212991 NotificationService::current()->Notify(
2992 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2993 Source<WebContents>(this),
2994 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322995}
2996
[email protected]cbb1ef592013-06-05 19:49:462997void WebContentsImpl::NotifyNavigationEntryCommitted(
2998 const LoadCommittedDetails& load_details) {
2999 FOR_EACH_OBSERVER(
3000 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3001}
3002
[email protected]f114fa42013-12-06 17:06:443003bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3004 const IPC::Message& message) {
3005 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313006}
3007
[email protected]c31a84802014-04-03 15:55:493008const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3009 return GetLastCommittedURL();
3010}
3011
[email protected]b849847b2013-12-10 21:57:583012void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3013 // Note this is only for subframes, the notification for the main frame
3014 // happens in RenderViewCreated.
3015 FOR_EACH_OBSERVER(WebContentsObserver,
3016 observers_,
3017 RenderFrameCreated(render_frame_host));
3018}
3019
3020void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3021 FOR_EACH_OBSERVER(WebContentsObserver,
3022 observers_,
3023 RenderFrameDeleted(render_frame_host));
3024}
3025
[email protected]a09d53ce2014-01-31 00:46:423026void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303027 if (delegate_)
3028 delegate_->WorkerCrashed(this);
3029}
3030
[email protected]a09d53ce2014-01-31 00:46:423031void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3032 const ContextMenuParams& params) {
3033 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:403034 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:423035 return;
3036
3037 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
3038}
3039
[email protected]87de04b02014-04-08 22:14:493040void WebContentsImpl::RunJavaScriptMessage(
3041 RenderFrameHost* rfh,
3042 const base::string16& message,
3043 const base::string16& default_prompt,
3044 const GURL& frame_url,
3045 JavaScriptMessageType javascript_message_type,
3046 IPC::Message* reply_msg) {
3047 // Suppress JavaScript dialogs when requested. Also suppress messages when
3048 // showing an interstitial as it's shown over the previous page and we don't
3049 // want the hidden page's dialogs to interfere with the interstitial.
3050 bool suppress_this_message =
3051 static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost())->
3052 IsSwappedOut() ||
3053 ShowingInterstitialPage() ||
3054 !delegate_ ||
3055 delegate_->ShouldSuppressDialogs() ||
3056 !delegate_->GetJavaScriptDialogManager();
3057
3058 if (!suppress_this_message) {
3059 std::string accept_lang = GetContentClient()->browser()->
3060 GetAcceptLangs(GetBrowserContext());
3061 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3062 dialog_manager_->RunJavaScriptDialog(
3063 this,
3064 frame_url.GetOrigin(),
3065 accept_lang,
3066 javascript_message_type,
3067 message,
3068 default_prompt,
3069 base::Bind(&WebContentsImpl::OnDialogClosed,
3070 base::Unretained(this),
3071 rfh,
3072 reply_msg,
3073 false),
3074 &suppress_this_message);
3075 }
3076
3077 if (suppress_this_message) {
3078 // If we are suppressing messages, just reply as if the user immediately
3079 // pressed "Cancel", passing true to |dialog_was_suppressed|.
3080 OnDialogClosed(rfh, reply_msg, true, false, base::string16());
3081 }
3082
3083 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3084 // http://crbug.com/288961 ). The only safe thing to do here is return.
3085}
3086
3087void WebContentsImpl::RunBeforeUnloadConfirm(
3088 RenderFrameHost* rfh,
3089 const base::string16& message,
3090 bool is_reload,
3091 IPC::Message* reply_msg) {
3092 RenderFrameHostImpl* rfhi = static_cast<RenderFrameHostImpl*>(rfh);
3093 RenderViewHostImpl* rvhi =
3094 static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost());
3095 if (delegate_)
3096 delegate_->WillRunBeforeUnloadConfirm();
3097
3098 bool suppress_this_message =
3099 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3100 !delegate_ ||
3101 delegate_->ShouldSuppressDialogs() ||
3102 !delegate_->GetJavaScriptDialogManager();
3103 if (suppress_this_message) {
3104 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3105 return;
3106 }
3107
3108 is_showing_before_unload_dialog_ = true;
3109 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3110 dialog_manager_->RunBeforeUnloadDialog(
3111 this, message, is_reload,
3112 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
3113 rfh, reply_msg, false));
3114}
3115
[email protected]a86c0e962013-12-17 17:10:393116WebContents* WebContentsImpl::GetAsWebContents() {
3117 return this;
3118}
3119
[email protected]7912e822014-04-16 02:37:033120bool WebContentsImpl::IsNeverVisible() {
3121 if (!delegate_)
3122 return false;
3123 return delegate_->IsNeverVisible(this);
3124}
3125
[email protected]5a3bdf52012-05-24 15:12:573126RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3127 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323128}
3129
[email protected]8ff00d72012-10-23 19:12:213130RendererPreferences WebContentsImpl::GetRendererPrefs(
3131 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463132 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513133}
3134
[email protected]b172aee2012-04-10 17:05:263135gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173136 if (delegate_)
3137 return delegate_->GetRootWindowResizerRect();
3138 return gfx::Rect();
3139}
3140
[email protected]7a846df2012-09-20 19:17:393141void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273142 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393143 browser_plugin_embedder_.reset();
3144}
3145
[email protected]b172aee2012-04-10 17:05:263146void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443147 // Don't send notifications if we are just creating a swapped-out RVH for
3148 // the opener chain. These won't be used for view-source or WebUI, so it's
3149 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243150 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443151 return;
3152
[email protected]86f98a22013-03-20 14:35:003153 if (delegate_)
3154 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083155
[email protected]8ff00d72012-10-23 19:12:213156 NotificationService::current()->Notify(
3157 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3158 Source<WebContents>(this),
3159 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323160
3161 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353162 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213163 if (GetRenderManager()->pending_web_ui())
3164 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323165
[email protected]6286a372013-10-09 04:03:273166 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333167 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323168 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183169 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583170 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323171 }
[email protected]0666aef2009-05-13 19:48:083172
[email protected]60780f412013-02-25 16:34:103173 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263174
3175 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253176 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583177
3178 // We tell the observers now instead of when the main RenderFrameHostImpl is
3179 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3180 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363181 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583182 FOR_EACH_OBSERVER(
3183 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323184}
3185
[email protected]b172aee2012-04-10 17:05:263186void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523187 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323188 // Don't notify the world, since this came from a renderer in the
3189 // background.
3190 return;
3191 }
3192
[email protected]da7a7182013-09-06 08:11:113193 notify_disconnection_ = true;
3194 // TODO(avi): Remove. http://crbug.com/170921
3195 NotificationService::current()->Notify(
3196 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3197 Source<WebContents>(this),
3198 NotificationService::NoDetails());
3199
[email protected]be1f56ab2011-12-22 06:55:313200 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233201 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303202
3203 // Restore the focus to the tab (otherwise the focus will be on the top
3204 // window).
[email protected]484ae5912010-09-29 19:16:143205 if (was_crashed && !FocusLocationBarByDefault() &&
3206 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063207 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143208 }
[email protected]32ded2212011-11-10 18:51:433209
[email protected]d8c660432011-12-22 20:51:253210 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323211}
3212
[email protected]ec6a7eb2013-04-22 17:34:223213void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3214 base::TerminationStatus status,
3215 int error_code) {
[email protected]151a63d2011-12-20 22:32:523216 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323217 // The pending page's RenderViewHost is gone.
3218 return;
3219 }
3220
[email protected]2fcdcc32014-03-05 02:14:073221 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3222 // renderer may not have made a clean exit.
3223 if (IsFullscreenForCurrentTab())
3224 ToggleFullscreenMode(false);
3225
[email protected]698191dc2014-02-25 01:06:133226 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3227 if (dialog_manager_)
3228 dialog_manager_->CancelActiveAndPendingDialogs(this);
3229
[email protected]d9030b82013-07-19 08:26:063230 ClearPowerSaveBlockers(rvh);
[email protected]e3b10d12014-03-28 16:06:093231 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323232 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233233 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:313234 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:323235
[email protected]d8c660432011-12-22 20:51:253236 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273237 observers_,
[email protected]58d5cfe2013-07-10 02:40:523238 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323239}
3240
[email protected]b172aee2012-04-10 17:05:263241void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:063242 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:213243 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:253244 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063245}
3246
[email protected]b172aee2012-04-10 17:05:263247void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3248 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043249 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153250 // Ensure that this state update comes from either the active RVH or one of
3251 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413252 // TODO(nasko): This should go through RenderFrameHost.
3253 // TODO(creis): We can't update state for cross-process subframes until we
3254 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3255 if (rvh != GetRenderViewHost() &&
3256 !GetRenderManager()->IsRVHOnSwappedOutList(
3257 static_cast<RenderViewHostImpl*>(rvh)))
3258 return;
[email protected]420ae012009-04-24 05:16:323259
3260 // We must be prepared to handle state updates for any page, these occur
3261 // when the user is scrolling and entering form data, as well as when we're
3262 // leaving a page, in which case our state may have already been moved to
3263 // the next page. The navigation controller will look up the appropriate
3264 // NavigationEntry and update it when it is notified via the delegate.
3265
3266 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583267 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323268 if (entry_index < 0)
3269 return;
[email protected]10f417c52011-12-28 21:04:233270 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323271
[email protected]691aa2f2013-05-28 22:52:043272 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323273 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043274 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323275 controller_.NotifyEntryChanged(entry, entry_index);
3276}
3277
[email protected]b172aee2012-04-10 17:05:263278void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3279 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263280 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263281 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323282 // If we have a title, that's a pretty good indication that we've started
3283 // getting useful data.
3284 SetNotWaitingForResponse();
3285
[email protected]73eb2602012-02-09 19:50:553286 // Try to find the navigation entry, which might not be the current one.
3287 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233288 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583289 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093290
[email protected]73eb2602012-02-09 19:50:553291 // We can handle title updates when we don't have an entry in
3292 // UpdateTitleForEntry, but only if the update is from the current RVH.
3293 if (!entry && rvh != GetRenderViewHost())
3294 return;
3295
[email protected]a49e10b2011-08-01 23:57:463296 // TODO(evan): make use of title_direction.
3297 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093298 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323299 return;
3300
3301 // Broadcast notifications when the UI should be updated.
3302 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213303 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323304}
3305
[email protected]b172aee2012-04-10 17:05:263306void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3307 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313308 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323309}
3310
[email protected]b172aee2012-04-10 17:05:263311void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513312 if (delegate_)
3313 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323314}
3315
[email protected]b172aee2012-04-10 17:05:263316void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103317#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293318 // The UI may be in an event-tracking loop, such as between the
3319 // mouse-down and mouse-up in text selection or a button click.
3320 // Defer the close until after tracking is complete, so that we
3321 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293322 // TODO(shess): This could get more fine-grained. For instance,
3323 // closing a tab in another window while selecting text in the
3324 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103325 if (view_->IsEventTracking()) {
3326 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293327 return;
3328 }
[email protected]60780f412013-02-25 16:34:103329#endif
[email protected]07707302009-11-06 00:50:293330
[email protected]420ae012009-04-24 05:16:323331 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523332 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513333 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323334}
3335
[email protected]66bbadaf2014-03-28 16:25:543336void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573337 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3338 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573339}
3340
[email protected]b172aee2012-04-10 17:05:263341void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513342 if (delegate_ && delegate_->IsPopupOrPanel(this))
3343 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323344}
3345
[email protected]e3b10d12014-03-28 16:06:093346void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3347 bool to_different_document) {
3348 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3349 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323350}
3351
[email protected]723971b2014-02-12 11:08:253352void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323353 scoped_ptr<LoadNotificationDetails> details;
3354
[email protected]9595fd82013-04-19 21:28:493355 // Use the last committed entry rather than the active one, in case a
3356 // pending entry has been created.
3357 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203358 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493359
[email protected]420ae012009-04-24 05:16:323360 // An entry may not exist for a stop when loading an initial blank page or
3361 // if an iframe injected by script into a blank page finishes loading.
3362 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203363 base::TimeDelta elapsed =
3364 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323365
3366 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513367 entry->GetVirtualURL(),
3368 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323369 elapsed,
3370 &controller_,
3371 controller_.GetCurrentEntryIndex()));
3372 }
3373
[email protected]e3b10d12014-03-28 16:06:093374 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3375 details.get());
[email protected]420ae012009-04-24 05:16:323376}
3377
[email protected]b172aee2012-04-10 17:05:263378void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163379 controller_.DiscardNonCommittedEntries();
3380
3381 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213382 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163383}
3384
[email protected]b172aee2012-04-10 17:05:263385void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513386 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133387 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403388}
3389
[email protected]7cc78902012-12-06 02:32:263390void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393391 if (opener_) {
3392 // Clear our opener so that future cross-process navigations don't have an
3393 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103394 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393395 opener_ = NULL;
3396 }
[email protected]7cc78902012-12-06 02:32:263397
3398 // Notify all swapped out RenderViewHosts for this tab. This is important
3399 // in case we go back to them, or if another window in those processes tries
3400 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213401 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263402}
3403
[email protected]59167c22013-06-03 18:07:323404void WebContentsImpl::DidAccessInitialDocument() {
3405 // Update the URL display.
3406 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3407}
3408
[email protected]87717d0e2012-04-26 02:58:433409void WebContentsImpl::DocumentAvailableInMainFrame(
3410 RenderViewHost* render_view_host) {
3411 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3412 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103413}
3414
[email protected]b172aee2012-04-10 17:05:263415void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083416 RenderViewHost* render_view_host,
3417 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093418 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3419 DocumentOnLoadCompletedInMainFrame(page_id));
3420
3421 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213422 NotificationService::current()->Notify(
3423 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3424 Source<WebContents>(this),
3425 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083426}
3427
[email protected]e1c3a552012-05-04 20:51:323428void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3429 // Tell the active RenderViewHost to run unload handlers and close, as long
3430 // as the request came from a RenderViewHost in the same BrowsingInstance.
3431 // In most cases, we receive this from a swapped out RenderViewHost.
3432 // It is possible to receive it from one that has just been swapped in,
3433 // in which case we might as well deliver the message anyway.
3434 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3435 GetRenderViewHost()->ClosePage();
3436}
3437
[email protected]f546640b2012-05-15 00:03:493438void WebContentsImpl::RouteMessageEvent(
3439 RenderViewHost* rvh,
3440 const ViewMsg_PostMessage_Params& params) {
3441 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363442 // came from a RenderViewHost in the same BrowsingInstance or if this
3443 // WebContents is dedicated to a browser plugin guest.
3444 // Note: This check means that an embedder could theoretically receive a
3445 // postMessage from anyone (not just its own guests). However, this is
3446 // probably not a risk for apps since other pages won't have references
3447 // to App windows.
3448 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3449 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493450 return;
3451
3452 ViewMsg_PostMessage_Params new_params(params);
3453
[email protected]0bc7f3542013-10-21 15:05:533454 if (!params.message_port_ids.empty()) {
3455 MessagePortMessageFilter* message_port_message_filter =
3456 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3457 ->message_port_message_filter();
3458 std::vector<int> new_routing_ids(params.message_port_ids.size());
3459 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3460 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3461 MessagePortService::GetInstance()->UpdateMessagePort(
3462 params.message_port_ids[i],
3463 message_port_message_filter,
3464 new_routing_ids[i]);
3465 }
3466 new_params.new_routing_ids = new_routing_ids;
3467 }
3468
[email protected]f546640b2012-05-15 00:03:493469 // If there is a source_routing_id, translate it to the routing ID for
3470 // the equivalent swapped out RVH in the target process. If we need
3471 // to create a swapped out RVH for the source tab, we create its opener
3472 // chain as well, since those will also be accessible to the target page.
3473 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3474 // Try to look up the WebContents for the source page.
3475 WebContentsImpl* source_contents = NULL;
3476 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3477 rvh->GetProcess()->GetID(), params.source_routing_id);
3478 if (source_rvh) {
3479 source_contents = static_cast<WebContentsImpl*>(
3480 source_rvh->GetDelegate()->GetAsWebContents());
3481 }
3482
3483 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363484 if (GetBrowserPluginGuest()) {
3485 // We create a swapped out RenderView for the embedder in the guest's
3486 // render process but we intentionally do not expose the embedder's
3487 // opener chain to it.
3488 new_params.source_routing_id =
3489 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3490 } else {
3491 new_params.source_routing_id =
3492 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3493 }
[email protected]f546640b2012-05-15 00:03:493494 } else {
3495 // We couldn't find it, so don't pass a source frame.
3496 new_params.source_routing_id = MSG_ROUTING_NONE;
3497 }
3498 }
3499
3500 // In most cases, we receive this from a swapped out RenderViewHost.
3501 // It is possible to receive it from one that has just been swapped in,
3502 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183503 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493504}
3505
[email protected]a796f202012-05-30 14:14:253506bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263507 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253508 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263509 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253510 if (!delegate_)
3511 return false;
3512 return delegate_->AddMessageToConsole(this, level, message, line_no,
3513 source_id);
3514}
3515
[email protected]b172aee2012-04-10 17:05:263516WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273517 // We want to base the page config off of the actual URL, rather than the
3518 // virtual URL.
3519 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3520 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003521 GURL url = controller_.GetActiveEntry()
3522 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153523
[email protected]fa944cb82013-11-15 17:51:213524 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323525}
3526
[email protected]0eba810b2012-10-18 03:19:363527int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213528 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413529 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3530 true, true);
[email protected]0eba810b2012-10-18 03:19:363531}
3532
[email protected]b172aee2012-04-10 17:05:263533void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273534 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253535 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223536
[email protected]ea114722012-03-12 01:11:253537 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173538 if (rdh) // NULL in unittests.
3539 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253540}
3541
[email protected]b172aee2012-04-10 17:05:263542void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443543 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253544 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443545}
3546
[email protected]b172aee2012-04-10 17:05:263547void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563548 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263549 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153550 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523551 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153552 return;
3553
[email protected]9f76c1e2012-03-05 15:15:583554 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3555
[email protected]e5fc1632011-08-08 07:51:533556 // Ignore renderer unresponsive event if debugger is attached to the tab
3557 // since the event may be a result of the renderer sitting on a breakpoint.
3558 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363559 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533560 return;
3561
[email protected]2e9d79f2013-08-16 05:45:563562 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323563 // Hang occurred while firing the beforeunload/unload handler.
3564 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583565 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323566
[email protected]fa944cb82013-11-15 17:51:213567 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323568 return;
3569
3570 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563571 // nothing we can do to recover. If the hang is in the beforeunload handler,
3572 // pretend the beforeunload listeners have all fired and allow the delegate
3573 // to continue closing; the user will not have the option of cancelling the
3574 // close. Otherwise, pretend the unload listeners have all fired and close
3575 // the tab.
3576 bool close = true;
3577 if (is_during_beforeunload) {
3578 delegate_->BeforeUnloadFired(this, true, &close);
3579 }
3580 if (close)
3581 Close(rvh);
[email protected]420ae012009-04-24 05:16:323582 return;
3583 }
3584
[email protected]9f76c1e2012-03-05 15:15:583585 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473586 return;
3587
[email protected]6934a702011-12-20 00:04:513588 if (delegate_)
3589 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323590}
3591
[email protected]b172aee2012-04-10 17:05:263592void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513593 if (delegate_)
3594 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323595}
3596
[email protected]b172aee2012-04-10 17:05:263597void WebContentsImpl::LoadStateChanged(
3598 const GURL& url,
3599 const net::LoadStateWithParam& load_state,
3600 uint64 upload_position,
3601 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323602 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563603 upload_position_ = upload_position;
3604 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503605 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213606 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303607 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213608 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323609 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463610 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213611 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463612 }
[email protected]420ae012009-04-24 05:16:323613}
3614
[email protected]b172aee2012-04-10 17:05:263615void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553616 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323617 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123618 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3619 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513620 if (delegate_)
3621 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093622 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323623}
3624
[email protected]58d5cfe2013-07-10 02:40:523625void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543626 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233627 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223628 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543629}
3630
[email protected]b172aee2012-04-10 17:05:263631void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103632 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213633 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263634 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3635 // here during container initialization and normal window size will be set
3636 // later. In case of tab duplication this resizing to 0x0 prevents setting
3637 // normal size later so just ignore it.
3638 if (!size.IsEmpty())
3639 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323640}
3641
[email protected]af905902013-10-01 21:38:513642void WebContentsImpl::CancelModalDialogsForRenderManager() {
3643 // We need to cancel modal dialogs when doing a process swap, since the load
3644 // deferrer would prevent us from swapping out.
3645 if (dialog_manager_)
3646 dialog_manager_->CancelActiveAndPendingDialogs(this);
3647}
3648
[email protected]7b712ee22013-10-03 00:57:283649void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3650 RenderViewHost* new_host) {
3651 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083652
3653 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003654 if (delegate_)
3655 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393656
[email protected]7b712ee22013-10-03 00:57:283657 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543658}
3659
[email protected]14392a52012-05-02 20:28:443660int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3661 SiteInstance* instance) {
3662 if (!opener_)
3663 return MSG_ROUTING_NONE;
3664
3665 // Recursively create RenderViews for anything else in the opener chain.
3666 return opener_->CreateOpenerRenderViews(instance);
3667}
3668
3669int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3670 int opener_route_id = MSG_ROUTING_NONE;
3671
3672 // If this tab has an opener, ensure it has a RenderView in the given
3673 // SiteInstance as well.
3674 if (opener_)
3675 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3676
[email protected]45a22ad2013-02-21 03:25:003677 // If any of the renderers (current, pending, or swapped out) for this
3678 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213679 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3680 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373681
[email protected]fa944cb82013-11-15 17:51:213682 if (GetRenderManager()->pending_render_view_host() &&
3683 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3684 instance)
3685 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003686
[email protected]fa944cb82013-11-15 17:51:213687 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373688 instance);
3689 if (rvh)
3690 return rvh->GetRoutingID();
3691
[email protected]14392a52012-05-02 20:28:443692 // Create a swapped out RenderView in the given SiteInstance if none exists,
3693 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413694 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3695 true, true);
[email protected]14392a52012-05-02 20:28:443696}
3697
[email protected]b172aee2012-04-10 17:05:263698NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193699 return GetController();
[email protected]3a3d47472010-07-15 21:03:543700}
3701
[email protected]b172aee2012-04-10 17:05:263702WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563703 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323704}
3705
[email protected]10f417c52011-12-28 21:04:233706NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263707 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323708 return controller_.GetLastCommittedEntry();
3709}
3710
[email protected]b172aee2012-04-10 17:05:263711bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163712 RenderViewHost* render_view_host,
3713 int opener_route_id,
3714 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033715 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443716 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163717 RenderWidgetHostView* rwh_view;
3718 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3719 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3720 // case this because RWH is still a base class of RenderViewHost, and child
3721 // frame RWHVs are unique in that they do not have their own WebContents.
3722 if (frame_connector) {
3723 RenderWidgetHostViewChildFrame* rwh_view_child =
3724 new RenderWidgetHostViewChildFrame(render_view_host);
3725 frame_connector->set_view(rwh_view_child);
3726 rwh_view = rwh_view_child;
3727 } else {
3728 rwh_view = view_->CreateViewForWidget(render_view_host);
3729 }
[email protected]1a98a932009-11-17 00:12:523730
[email protected]420ae012009-04-24 05:16:323731 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443732 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213733 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323734
[email protected]74ce1ad2011-12-16 21:51:463735 // Make sure we use the correct starting page_id in the new RenderView.
3736 UpdateMaxPageIDIfNecessary(render_view_host);
3737 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583738 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463739
[email protected]9f76c1e2012-03-05 15:15:583740 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263741 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493742 opener_route_id,
[email protected]c7c0d822014-04-16 20:19:493743 max_page_id,
3744 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523745 return false;
[email protected]14392a52012-05-02 20:28:443746 }
[email protected]a4127722011-04-27 23:13:523747
[email protected]a220b5932013-09-21 03:47:443748#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503749 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3750 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443751 if (rwh_view) {
3752 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3753 render_widget_host->WasResized();
3754 }
[email protected]f8233cc2011-05-31 20:24:503755#endif
3756
[email protected]420ae012009-04-24 05:16:323757 return true;
3758}
3759
[email protected]7d244f12013-08-22 21:41:513760#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183761base::android::ScopedJavaLocalRef<jobject>
3762WebContentsImpl::GetJavaWebContents() {
3763 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3764
3765 WebContentsAndroid* web_contents_android =
3766 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3767 if (!web_contents_android) {
3768 web_contents_android = new WebContentsAndroid(this);
3769 SetUserData(kWebContentsAndroidKey, web_contents_android);
3770 }
3771 return web_contents_android->GetJavaObject();
3772}
3773
[email protected]7d244f12013-08-22 21:41:513774bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3775 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163776 MSG_ROUTING_NONE,
3777 NULL);
[email protected]7d244f12013-08-22 21:41:513778}
3779#endif
3780
[email protected]87de04b02014-04-08 22:14:493781void WebContentsImpl::OnDialogClosed(RenderFrameHost* rfh,
[email protected]b172aee2012-04-10 17:05:263782 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493783 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263784 bool success,
[email protected]fcf75d42013-12-03 20:11:263785 const base::string16& user_input) {
[email protected]87de04b02014-04-08 22:14:493786 last_dialog_suppressed_ = dialog_was_suppressed;
3787
[email protected]beb440c2009-11-06 04:08:543788 if (is_showing_before_unload_dialog_ && !success) {
3789 // If a beforeunload dialog is canceled, we need to stop the throbber from
3790 // spinning, since we forced it to start spinning in Navigate.
[email protected]87de04b02014-04-08 22:14:493791 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353792 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103793
[email protected]6d65a462013-06-21 21:29:123794 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3795 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543796 }
[email protected]87de04b02014-04-08 22:14:493797
[email protected]beb440c2009-11-06 04:08:543798 is_showing_before_unload_dialog_ = false;
[email protected]87de04b02014-04-08 22:14:493799 static_cast<RenderFrameHostImpl*>(rfh)->JavaScriptDialogClosed(
3800 reply_msg, success, user_input, dialog_was_suppressed);
[email protected]beb440c2009-11-06 04:08:543801}
3802
[email protected]b172aee2012-04-10 17:05:263803void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213804 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123805 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103806}
[email protected]f45d2a72010-03-08 23:28:353807
[email protected]b172aee2012-04-10 17:05:263808void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103809 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443810 // Can be NULL during tests.
3811 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213812 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363813}
[email protected]9f76c1e2012-03-05 15:15:583814
[email protected]1ac10dca2013-08-20 20:47:043815bool WebContentsImpl::IsHidden() {
3816 return capturer_count_ == 0 && !should_normally_be_visible_;
3817}
3818
[email protected]b0936d22013-11-28 06:47:363819RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213820 return frame_tree_.root()->render_manager();
3821}
3822
[email protected]b172aee2012-04-10 17:05:263823RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583824 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3825}
[email protected]7900bfdb2012-05-24 19:31:243826
[email protected]f8497342013-02-05 22:15:023827BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393828 return browser_plugin_guest_.get();
3829}
3830
[email protected]738f57a2013-06-29 21:06:543831void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3832 CHECK(!browser_plugin_guest_);
3833 browser_plugin_guest_.reset(guest);
3834}
3835
[email protected]f8497342013-02-05 22:15:023836BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393837 return browser_plugin_embedder_.get();
3838}
[email protected]8ff00d72012-10-23 19:12:213839
[email protected]8eb04562013-03-06 03:41:143840BrowserPluginGuestManager*
3841 WebContentsImpl::GetBrowserPluginGuestManager() const {
3842 return static_cast<BrowserPluginGuestManager*>(
3843 GetBrowserContext()->GetUserData(
3844 browser_plugin::kBrowserPluginGuestManagerKeyName));
3845}
3846
[email protected]d9030b82013-07-19 08:26:063847void WebContentsImpl::ClearPowerSaveBlockers(
3848 RenderViewHost* render_view_host) {
3849 STLDeleteValues(&power_save_blockers_[render_view_host]);
3850 power_save_blockers_.erase(render_view_host);
3851}
3852
3853void WebContentsImpl::ClearAllPowerSaveBlockers() {
3854 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3855 i != power_save_blockers_.end(); ++i)
3856 STLDeleteValues(&power_save_blockers_[i->first]);
3857 power_save_blockers_.clear();
3858}
3859
[email protected]dc0fd432013-08-27 15:29:213860gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3861 gfx::Size size;
3862 if (delegate_)
3863 size = delegate_->GetSizeForNewRenderView(this);
3864 if (size.IsEmpty())
3865 size = view_->GetContainerSize();
3866 return size;
3867}
3868
[email protected]9b159a52013-10-03 17:24:553869void WebContentsImpl::OnFrameRemoved(
3870 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583871 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553872 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583873 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553874}
3875
[email protected]222f5822014-02-05 23:40:493876void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3877 if (!delegate_)
3878 return;
3879 const gfx::Size new_size = GetPreferredSize();
3880 if (new_size != old_size)
3881 delegate_->UpdatePreferredSize(this, new_size);
3882}
3883
[email protected]8ff00d72012-10-23 19:12:213884} // namespace content