blob: bddc8de7b9cea9a3582fc124fc4cb921a73d0f2d [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]5a24f5802014-04-22 22:39:551226 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1227 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1228 // gestures, which are regrettably easy to trigger accidentally.
1229 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521230 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1231 return true;
1232 }
[email protected]bccc4472013-04-18 16:37:191233#endif
[email protected]fb3f066e2013-02-12 19:12:521234 return false;
1235}
1236
[email protected]04bce562014-01-30 05:34:541237bool WebContentsImpl::PreHandleGestureEvent(
1238 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031239 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541240}
1241
[email protected]bab38af2014-03-30 17:37:291242bool WebContentsImpl::HandleGestureEvent(
1243 const blink::WebGestureEvent& event) {
1244 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1245 // Use them to implement browser zoom, as for HandleWheelEvent above.
1246 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1247 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1248 // The scale difference necessary to trigger a zoom action. Derived from
1249 // experimentation to find a value that feels reasonable.
1250 const float kZoomStepValue = 0.6f;
1251
1252 // Find the (absolute) thresholds on either side of the current zoom factor,
1253 // then convert those to actual numbers to trigger a zoom in or out.
1254 // This logic deliberately makes the range around the starting zoom value
1255 // for the gesture twice as large as the other ranges (i.e., the notches are
1256 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1257 // so that it's easier to get back to your starting point than it is to
1258 // overshoot.
1259 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1260 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1261 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1262 : -backStep;
1263 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1264 : backStep;
1265
1266 totalPinchGestureAmount_ += event.data.pinchUpdate.scale;
1267 if (totalPinchGestureAmount_ > zoomInThreshold) {
1268 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461269 if (delegate_)
1270 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291271 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1272 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461273 if (delegate_)
1274 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291275 }
1276 return true;
1277 }
1278
1279 return false;
1280}
1281
[email protected]2ceee8f2014-01-14 18:02:081282#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411283gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1284 return accessible_parent_;
1285}
1286#endif
1287
[email protected]b172aee2012-04-10 17:05:261288void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431289 if (delegate_)
1290 delegate_->HandleMouseDown();
1291}
1292
[email protected]b172aee2012-04-10 17:05:261293void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481294 if (delegate_)
1295 delegate_->HandleMouseUp();
1296}
1297
[email protected]590a634e2012-07-19 16:38:231298void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481299 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231300 delegate_->HandlePointerActivate();
1301}
1302
1303void WebContentsImpl::HandleGestureBegin() {
1304 if (delegate_)
1305 delegate_->HandleGestureBegin();
1306}
1307
1308void WebContentsImpl::HandleGestureEnd() {
1309 if (delegate_)
1310 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481311}
1312
[email protected]b172aee2012-04-10 17:05:261313void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491314 // This method is being called to enter or leave renderer-initiated fullscreen
1315 // mode. Either way, make sure any existing fullscreen widget is shut down
1316 // first.
1317 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1318 if (widget_view)
1319 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1320
[email protected]8a5e0ca2011-08-25 06:30:471321 if (delegate_)
1322 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371323
1324 FOR_EACH_OBSERVER(WebContentsObserver,
1325 observers_,
1326 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471327}
1328
[email protected]b172aee2012-04-10 17:05:261329bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381330 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121331}
1332
[email protected]a9c81f02012-06-01 00:15:441333void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1334 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371335 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441336 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371337 } else {
1338 GotResponseToLockMouseRequest(false);
1339 }
1340}
1341
[email protected]b172aee2012-04-10 17:05:261342void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371343 if (delegate_)
1344 delegate_->LostMouseLock();
1345}
1346
[email protected]bafe6cd2012-05-23 23:09:501347void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201348 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501349 int route_id,
[email protected]227692c52013-05-31 22:43:041350 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131351 const ViewHostMsg_CreateWindow_Params& params,
1352 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501353 // We usually create the new window in the same BrowsingInstance (group of
1354 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551355 // if the opener is being suppressed (in a non-guest), we create a new
1356 // SiteInstance in its own BrowsingInstance.
1357 bool is_guest = GetRenderProcessHost()->IsGuest();
1358
[email protected]04cbd3d2013-12-04 04:58:201359 // If the opener is to be suppressed, the new window can be in any process.
1360 // Since routing ids are process specific, we must not have one passed in
1361 // as argument here.
1362 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1363
[email protected]bafe6cd2012-05-23 23:09:501364 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551365 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571366 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501367 GetSiteInstance();
1368
[email protected]04cbd3d2013-12-04 04:58:201369 // A message to create a new window can only come from the active process for
1370 // this WebContentsImpl instance. If any other process sends the request,
1371 // it is invalid and the process must be terminated.
1372 if (GetRenderProcessHost()->GetID() != render_process_id) {
1373 base::ProcessHandle process_handle =
1374 RenderProcessHost::FromID(render_process_id)->GetHandle();
1375 if (process_handle != base::kNullProcessHandle) {
1376 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391377 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201378 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1379 }
1380 return;
1381 }
1382
[email protected]d1198fd2012-08-13 22:50:191383 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341384 //
1385 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301386 const std::string& partition_id =
1387 GetContentClient()->browser()->
1388 GetStoragePartitionIdForSite(GetBrowserContext(),
1389 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461390 StoragePartition* partition = BrowserContext::GetStoragePartition(
1391 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411392 DOMStorageContextWrapper* dom_storage_context =
1393 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191394 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1395 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1396 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371397
1398 if (delegate_ &&
1399 !delegate_->ShouldCreateWebContents(this,
1400 route_id,
1401 params.window_container_type,
1402 params.frame_name,
1403 params.target_url,
1404 partition_id,
1405 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011406 if (route_id != MSG_ROUTING_NONE &&
1407 !RenderViewHost::FromID(render_process_id, route_id)) {
1408 // If the embedder didn't create a WebContents for this route, we need to
1409 // delete the RenderView that had already been created.
1410 Send(new ViewMsg_Close(route_id));
1411 }
[email protected]dd6730412013-08-14 15:03:371412 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1413 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1414 main_frame_route_id);
1415 return;
1416 }
1417
1418 // Create the new web contents. This will automatically create the new
1419 // WebContentsView. In the future, we may want to create the view separately.
1420 WebContentsImpl* new_contents =
1421 new WebContentsImpl(GetBrowserContext(),
1422 params.opener_suppressed ? NULL : this);
1423
[email protected]d1198fd2012-08-13 22:50:191424 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301425 partition_id,
[email protected]d1198fd2012-08-13 22:50:191426 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461427 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591428 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041429 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551430 if (!is_guest) {
1431 create_params.context = view_->GetNativeView();
1432 create_params.initial_size = view_->GetContainerSize();
1433 } else {
1434 // This makes |new_contents| act as a guest.
1435 // For more info, see comment above class BrowserPluginGuest.
1436 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1437 WebContentsImpl* new_contents_impl =
1438 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461439 BrowserPluginGuest::CreateWithOpener(instance_id,
1440 new_contents_impl->opener() != NULL,
1441 new_contents_impl,
1442 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551443 }
[email protected]1ac10dca2013-08-20 20:47:041444 if (params.disposition == NEW_BACKGROUND_TAB)
1445 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591446 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191447
[email protected]c4538072013-03-18 02:17:551448 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341449 // will be shown immediately).
1450 if (!params.opener_suppressed) {
1451 if (!is_guest) {
1452 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501453
[email protected]d70bea92013-04-05 04:23:341454 // TODO(brettw): It seems bogus that we have to call this function on the
1455 // newly created object and give it one of its own member variables.
1456 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1457 }
[email protected]bafe6cd2012-05-23 23:09:501458 // Save the created window associated with the route so we can show it
1459 // later.
1460 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1461 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101462 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501463 }
1464
1465 if (delegate_) {
1466 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071467 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131468 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501469 }
1470
1471 if (params.opener_suppressed) {
1472 // When the opener is suppressed, the original renderer cannot access the
1473 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001474 bool was_blocked = false;
1475 if (delegate_) {
1476 gfx::Rect initial_pos;
1477 delegate_->AddNewContents(
1478 this, new_contents, params.disposition, initial_pos,
1479 params.user_gesture, &was_blocked);
1480 }
1481 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211482 OpenURLParams open_params(params.target_url,
1483 Referrer(),
1484 CURRENT_TAB,
1485 PAGE_TRANSITION_LINK,
1486 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301487 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001488 new_contents->OpenURL(open_params);
1489 }
[email protected]bafe6cd2012-05-23 23:09:501490 }
1491}
1492
[email protected]a8504022013-12-04 20:23:511493void WebContentsImpl::CreateNewWidget(int render_process_id,
1494 int route_id,
[email protected]180ef242013-11-07 06:50:461495 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511496 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501497}
1498
[email protected]a8504022013-12-04 20:23:511499void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1500 int route_id) {
1501 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501502}
1503
[email protected]a8504022013-12-04 20:23:511504void WebContentsImpl::CreateNewWidget(int render_process_id,
1505 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501506 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461507 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211508 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511509 // A message to create a new widget can only come from the active process for
1510 // this WebContentsImpl instance. If any other process sends the request,
1511 // it is invalid and the process must be terminated.
1512 if (process->GetID() != render_process_id) {
1513 base::ProcessHandle process_handle =
1514 RenderProcessHost::FromID(render_process_id)->GetHandle();
1515 if (process_handle != base::kNullProcessHandle) {
1516 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391517 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511518 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1519 }
1520 return;
1521 }
1522
[email protected]bafe6cd2012-05-23 23:09:501523 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041524 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261525 created_widgets_.insert(widget_host);
1526
[email protected]83918ec2013-01-10 15:37:191527 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1528 view_->CreateViewForPopupWidget(widget_host));
1529 if (!widget_view)
1530 return;
[email protected]bafe6cd2012-05-23 23:09:501531 if (!is_fullscreen) {
1532 // Popups should not get activated.
1533 widget_view->SetPopupType(popup_type);
1534 }
1535 // Save the created widget associated with the route so we can show it later.
1536 pending_widget_views_[route_id] = widget_view;
1537
1538#if defined(OS_MACOSX)
1539 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1540 // to allow it to survive the trip without being hosted.
1541 base::mac::NSObjectRetain(widget_view->GetNativeView());
1542#endif
1543}
1544
1545void WebContentsImpl::ShowCreatedWindow(int route_id,
1546 WindowOpenDisposition disposition,
1547 const gfx::Rect& initial_pos,
1548 bool user_gesture) {
1549 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001550 if (contents) {
1551 WebContentsDelegate* delegate = GetDelegate();
1552 if (delegate) {
1553 delegate->AddNewContents(
1554 this, contents, disposition, initial_pos, user_gesture, NULL);
1555 }
1556 }
[email protected]bafe6cd2012-05-23 23:09:501557}
1558
1559void WebContentsImpl::ShowCreatedWidget(int route_id,
1560 const gfx::Rect& initial_pos) {
1561 ShowCreatedWidget(route_id, false, initial_pos);
1562}
1563
1564void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1565 ShowCreatedWidget(route_id, true, gfx::Rect());
1566}
1567
1568void WebContentsImpl::ShowCreatedWidget(int route_id,
1569 bool is_fullscreen,
1570 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501571 RenderWidgetHostViewPort* widget_host_view =
1572 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1573 if (!widget_host_view)
1574 return;
[email protected]4aebbca2013-09-17 22:26:491575 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311576 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1577 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491578 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1579 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1580 delegate_->ToggleFullscreenModeForTab(this, true);
1581 } else {
1582 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491583 }
[email protected]4aebbca2013-09-17 22:26:491584 FOR_EACH_OBSERVER(WebContentsObserver,
1585 observers_,
1586 DidShowFullscreenWidget(route_id));
1587 if (!widget_host_view->HasFocus())
1588 widget_host_view->Focus();
1589 } else {
[email protected]f8497342013-02-05 22:15:021590 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491591 }
[email protected]89054502012-06-03 10:29:241592
1593 RenderWidgetHostImpl* render_widget_host_impl =
1594 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1595 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311596 // Only allow privileged mouse lock for fullscreen render widget, which is
1597 // used to implement Pepper Flash fullscreen.
1598 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501599
1600#if defined(OS_MACOSX)
1601 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1602 // properly embedded (or purposefully ignored) we can release the retain we
1603 // took in CreateNewWidget().
1604 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1605#endif
1606}
1607
1608WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1609 PendingContents::iterator iter = pending_contents_.find(route_id);
1610
1611 // Certain systems can block the creation of new windows. If we didn't succeed
1612 // in creating one, just return NULL.
1613 if (iter == pending_contents_.end()) {
1614 return NULL;
1615 }
1616
1617 WebContentsImpl* new_contents = iter->second;
1618 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101619 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501620
[email protected]d70bea92013-04-05 04:23:341621 // Don't initialize the guest WebContents immediately.
1622 if (new_contents->GetRenderProcessHost()->IsGuest())
1623 return new_contents;
1624
[email protected]bafe6cd2012-05-23 23:09:501625 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1626 !new_contents->GetRenderViewHost()->GetView())
1627 return NULL;
1628
1629 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1630 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1631 return new_contents;
1632}
1633
1634RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1635 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1636 if (iter == pending_widget_views_.end()) {
1637 DCHECK(false);
1638 return NULL;
1639 }
1640
1641 RenderWidgetHostView* widget_host_view = iter->second;
1642 pending_widget_views_.erase(route_id);
1643
1644 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1645 if (!widget_host->GetProcess()->HasConnection()) {
1646 // The view has gone away or the renderer crashed. Nothing to do.
1647 return NULL;
1648 }
1649
1650 return widget_host_view;
1651}
1652
[email protected]f13b4202012-06-12 23:53:231653void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091654 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211655 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371656 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231657 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371658 } else {
1659 callback.Run(MediaStreamDevices(),
1660 MEDIA_DEVICE_INVALID_STATE,
1661 scoped_ptr<MediaStreamUI>());
1662 }
[email protected]f13b4202012-06-12 23:53:231663}
1664
[email protected]cc9200432013-07-23 23:02:401665SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1666 SiteInstance* instance) {
1667 return controller_.GetSessionStorageNamespace(instance);
1668}
1669
[email protected]9b159a52013-10-03 17:24:551670FrameTree* WebContentsImpl::GetFrameTree() {
1671 return &frame_tree_;
1672}
1673
[email protected]31a71eaf2014-03-13 01:47:361674void WebContentsImpl::AccessibilityEventReceived(
1675 const std::vector<AXEventNotificationDetails>& details) {
1676 FOR_EACH_OBSERVER(
1677 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1678}
1679
[email protected]edc3af82013-12-12 21:24:071680void WebContentsImpl::OnShowValidationMessage(
1681 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291682 const base::string16& main_text,
1683 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071684 if (delegate_)
1685 delegate_->ShowValidationMessage(
1686 this, anchor_in_root_view, main_text, sub_text);
1687}
1688
1689void WebContentsImpl::OnHideValidationMessage() {
1690 if (delegate_)
1691 delegate_->HideValidationMessage(this);
1692}
1693
1694void WebContentsImpl::OnMoveValidationMessage(
1695 const gfx::Rect& anchor_in_root_view) {
1696 if (delegate_)
1697 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1698}
1699
[email protected]32deec62013-05-15 23:55:041700void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1701 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441702 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041703}
1704
[email protected]b172aee2012-04-10 17:05:261705void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491706 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231707 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491708 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331709}
1710
[email protected]b172aee2012-04-10 17:05:261711void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341712 if (delegate_)
1713 delegate_->ResizeDueToAutoResize(this, new_size);
1714}
1715
[email protected]b172aee2012-04-10 17:05:261716WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201717 if (!delegate_)
1718 return NULL;
[email protected]00c37fc2011-08-02 00:22:501719
[email protected]e5d549d2011-12-28 01:29:201720 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201721 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341722}
1723
[email protected]6b618e62012-08-16 12:59:181724bool WebContentsImpl::Send(IPC::Message* message) {
1725 if (!GetRenderViewHost()) {
1726 delete message;
1727 return false;
1728 }
1729
1730 return GetRenderViewHost()->Send(message);
1731}
1732
[email protected]b172aee2012-04-10 17:05:261733bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501734 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261735 FrameTreeNode* node = frame_tree_.root();
1736
1737 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1738 // specified in the pending entry.
1739 NavigationEntryImpl* pending_entry =
1740 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1741 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1742 pending_entry->frame_tree_node_id() != -1) {
1743 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1744 }
1745
1746 return node->navigator()->NavigateToPendingEntry(
1747 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541748}
[email protected]96d185d2009-04-24 03:28:541749
[email protected]a86c0e962013-12-17 17:10:391750void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1751 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441752 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391753 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441754}
1755
[email protected]20ca0382013-02-28 19:50:071756void WebContentsImpl::AttachInterstitialPage(
1757 InterstitialPageImpl* interstitial_page) {
1758 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211759 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291760
1761 // Cancel any visible dialogs so that they don't interfere with the
1762 // interstitial.
1763 if (dialog_manager_)
1764 dialog_manager_->CancelActiveAndPendingDialogs(this);
1765
[email protected]20ca0382013-02-28 19:50:071766 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1767 DidAttachInterstitialPage());
1768}
1769
1770void WebContentsImpl::DetachInterstitialPage() {
1771 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211772 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071773 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1774 DidDetachInterstitialPage());
1775}
1776
[email protected]b172aee2012-04-10 17:05:261777void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331778 const SiteInstance* site_instance,
1779 int history_length,
1780 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411781 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1782 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211783 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191784 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141785 return;
[email protected]9e1ad4b2011-08-14 16:49:191786 }
[email protected]9f76c1e2012-03-05 15:15:581787 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191788 if (!rvh) {
1789 NOTREACHED();
1790 return;
1791 }
[email protected]9f76c1e2012-03-05 15:15:581792 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191793 NOTREACHED();
1794 return;
1795 }
[email protected]6b618e62012-08-16 12:59:181796 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1797 history_length,
1798 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141799}
1800
[email protected]4fed3702014-04-01 09:08:001801void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171802 RenderFrameHost* focused_frame = GetFocusedFrame();
1803 if (!focused_frame)
1804 return;
1805
[email protected]959be4c2014-04-08 15:01:331806 focused_frame->Send(new FrameMsg_Reload(
1807 focused_frame->GetRoutingID(), ignore_cache));
1808}
1809
1810void WebContentsImpl::Undo() {
1811 RenderFrameHost* focused_frame = GetFocusedFrame();
1812 if (!focused_frame)
1813 return;
1814
1815 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1816 RecordAction(base::UserMetricsAction("Undo"));
1817}
1818
1819void WebContentsImpl::Redo() {
1820 RenderFrameHost* focused_frame = GetFocusedFrame();
1821 if (!focused_frame)
1822 return;
1823 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1824 RecordAction(base::UserMetricsAction("Redo"));
1825}
1826
1827void WebContentsImpl::Cut() {
1828 RenderFrameHost* focused_frame = GetFocusedFrame();
1829 if (!focused_frame)
1830 return;
1831
1832 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1833 RecordAction(base::UserMetricsAction("Cut"));
1834}
1835
1836void WebContentsImpl::Copy() {
1837 RenderFrameHost* focused_frame = GetFocusedFrame();
1838 if (!focused_frame)
1839 return;
1840
1841 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1842 RecordAction(base::UserMetricsAction("Copy"));
1843}
1844
1845void WebContentsImpl::CopyToFindPboard() {
1846#if defined(OS_MACOSX)
1847 RenderFrameHost* focused_frame = GetFocusedFrame();
1848 if (!focused_frame)
1849 return;
1850
1851 // Windows/Linux don't have the concept of a find pasteboard.
1852 focused_frame->Send(
1853 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1854 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1855#endif
1856}
1857
1858void WebContentsImpl::Paste() {
1859 RenderFrameHost* focused_frame = GetFocusedFrame();
1860 if (!focused_frame)
1861 return;
1862
1863 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1864 RecordAction(base::UserMetricsAction("Paste"));
1865}
1866
1867void WebContentsImpl::PasteAndMatchStyle() {
1868 RenderFrameHost* focused_frame = GetFocusedFrame();
1869 if (!focused_frame)
1870 return;
1871
1872 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1873 focused_frame->GetRoutingID()));
1874 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1875}
1876
1877void WebContentsImpl::Delete() {
1878 RenderFrameHost* focused_frame = GetFocusedFrame();
1879 if (!focused_frame)
1880 return;
1881
1882 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1883 RecordAction(base::UserMetricsAction("DeleteSelection"));
1884}
1885
1886void WebContentsImpl::SelectAll() {
1887 RenderFrameHost* focused_frame = GetFocusedFrame();
1888 if (!focused_frame)
1889 return;
1890
1891 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1892 RecordAction(base::UserMetricsAction("SelectAll"));
1893}
1894
1895void WebContentsImpl::Unselect() {
1896 RenderFrameHost* focused_frame = GetFocusedFrame();
1897 if (!focused_frame)
1898 return;
1899
1900 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1901 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171902}
1903
1904void WebContentsImpl::Replace(const base::string16& word) {
1905 RenderFrameHost* focused_frame = GetFocusedFrame();
1906 if (!focused_frame)
1907 return;
1908
[email protected]959be4c2014-04-08 15:01:331909 focused_frame->Send(new InputMsg_Replace(
1910 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171911}
1912
1913void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1914 RenderFrameHost* focused_frame = GetFocusedFrame();
1915 if (!focused_frame)
1916 return;
1917
[email protected]959be4c2014-04-08 15:01:331918 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1919 focused_frame->GetRoutingID(), word));
1920}
1921
1922void WebContentsImpl::NotifyContextMenuClosed(
1923 const CustomContextMenuContext& context) {
1924 RenderFrameHost* focused_frame = GetFocusedFrame();
1925 if (!focused_frame)
1926 return;
1927
1928 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1929 focused_frame->GetRoutingID(), context));
1930}
1931
1932void WebContentsImpl::ExecuteCustomContextMenuCommand(
1933 int action, const CustomContextMenuContext& context) {
1934 RenderFrameHost* focused_frame = GetFocusedFrame();
1935 if (!focused_frame)
1936 return;
1937
1938 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1939 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001940}
1941
[email protected]b172aee2012-04-10 17:05:261942void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271943 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211944 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541945 return;
1946 }
[email protected]9f76c1e2012-03-05 15:15:581947 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541948}
1949
[email protected]b172aee2012-04-10 17:05:261950bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211951 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541952}
1953
[email protected]b172aee2012-04-10 17:05:261954InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211955 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221956}
1957
[email protected]b172aee2012-04-10 17:05:261958bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161959 // WebKit creates Document object when MIME type is application/xhtml+xml,
1960 // so we also support this MIME type.
1961 return contents_mime_type_ == "text/html" ||
1962 contents_mime_type_ == "text/xml" ||
1963 contents_mime_type_ == "application/xhtml+xml" ||
1964 contents_mime_type_ == "text/plain" ||
1965 contents_mime_type_ == "text/css" ||
1966 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1967}
1968
[email protected]b172aee2012-04-10 17:05:261969void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591970 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161971 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551972 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011973 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141974 return;
[email protected]c7dd2f62011-07-18 15:57:591975 }
1976
1977 Stop();
1978
1979 // Create the save package and possibly prompt the user for the name to save
1980 // the page as. The user prompt is an asynchronous operation that runs on
1981 // another thread.
1982 save_package_ = new SavePackage(this);
1983 save_package_->GetSaveInfo();
1984}
1985
1986// Used in automated testing to bypass prompting the user for file names.
1987// Instead, the names and paths are hard coded rather than running them through
1988// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341989bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1990 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211991 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591992 // Stop the page from navigating.
1993 Stop();
1994
1995 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211996 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591997}
1998
[email protected]3c71576ce2013-07-23 02:00:011999void WebContentsImpl::SaveFrame(const GURL& url,
2000 const Referrer& referrer) {
2001 if (!GetURL().is_valid())
2002 return;
2003 bool is_main_frame = (url == GetURL());
2004
2005 DownloadManager* dlm =
2006 BrowserContext::GetDownloadManager(GetBrowserContext());
2007 if (!dlm)
2008 return;
2009 int64 post_id = -1;
2010 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272011 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012012 if (entry)
2013 post_id = entry->GetPostID();
2014 }
2015 scoped_ptr<DownloadUrlParameters> params(
2016 DownloadUrlParameters::FromWebContents(this, url));
2017 params->set_referrer(referrer);
2018 params->set_post_id(post_id);
2019 params->set_prefer_cache(true);
2020 if (post_id >= 0)
2021 params->set_method("POST");
2022 params->set_prompt(true);
2023 dlm->DownloadUrl(params.Pass());
2024}
2025
[email protected]b172aee2012-04-10 17:05:262026void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342027 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482028 const base::Callback<void(int64)>& callback) {
2029 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122030}
2031
[email protected]6286a372013-10-09 04:03:272032// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262033bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272034 NavigationEntryImpl* visible_entry =
2035 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2036 return (visible_entry != NULL &&
2037 visible_entry->site_instance() == GetSiteInstance() &&
2038 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322039}
2040
[email protected]b172aee2012-04-10 17:05:262041const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272042 return contents_mime_type_;
2043}
2044
[email protected]b172aee2012-04-10 17:05:262045bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272046 return notify_disconnection_;
2047}
2048
[email protected]b172aee2012-04-10 17:05:262049void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312050 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182051 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162052}
2053
[email protected]b172aee2012-04-10 17:05:262054void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:312055 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182056 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162057}
2058
[email protected]8ff00d72012-10-23 19:12:212059RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272060 return &renderer_preferences_;
2061}
2062
[email protected]e35ccd52012-05-23 16:22:472063void WebContentsImpl::Close() {
2064 Close(GetRenderViewHost());
2065}
2066
[email protected]cf200a562013-05-03 16:24:292067void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462068 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292069 if (browser_plugin_embedder_.get())
2070 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2071 screen_x, screen_y, operation);
2072 if (GetRenderViewHost())
2073 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2074 screen_x, screen_y, operation);
2075}
2076
[email protected]d60f3702013-12-26 16:30:242077void WebContentsImpl::DidGetResourceResponseStart(
2078 const ResourceRequestDetails& details) {
2079 controller_.ssl_manager()->DidStartResourceResponse(details);
2080
2081 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2082 DidGetResourceResponseStart(details));
2083
2084 // TODO(avi): Remove. http://crbug.com/170921
2085 NotificationService::current()->Notify(
2086 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2087 Source<WebContents>(this),
2088 Details<const ResourceRequestDetails>(&details));
2089}
2090
2091void WebContentsImpl::DidGetRedirectForResourceRequest(
2092 RenderViewHost* render_view_host,
2093 const ResourceRedirectDetails& details) {
2094 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2095
2096 FOR_EACH_OBSERVER(
2097 WebContentsObserver,
2098 observers_,
2099 DidGetRedirectForResourceRequest(render_view_host, details));
2100
2101 // TODO(avi): Remove. http://crbug.com/170921
2102 NotificationService::current()->Notify(
2103 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2104 Source<WebContents>(this),
2105 Details<const ResourceRedirectDetails>(&details));
2106}
2107
[email protected]b172aee2012-04-10 17:05:262108void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522109 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582110 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512111 if (delegate_)
2112 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292113 if (browser_plugin_embedder_.get())
2114 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342115}
2116
[email protected]e35ccd52012-05-23 16:22:472117void WebContentsImpl::UserGestureDone() {
2118 OnUserGesture();
2119}
2120
[email protected]b172aee2012-04-10 17:05:262121void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272122 closed_by_user_gesture_ = value;
2123}
2124
[email protected]b172aee2012-04-10 17:05:262125bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272126 return closed_by_user_gesture_;
2127}
2128
[email protected]b172aee2012-04-10 17:05:262129double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052130 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562131 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252132 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172133 return 0;
[email protected]b75b8292010-10-01 07:28:252134
2135 double zoom_level;
2136 if (temporary_zoom_settings_) {
2137 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582138 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252139 } else {
[email protected]2ae88d12011-10-14 09:11:192140 GURL url;
[email protected]6286a372013-10-09 04:03:272141 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192142 // Since zoom map is updated using rewritten URL, use rewritten URL
2143 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272144 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022145 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2146 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252147 }
[email protected]d0b8d092010-10-25 04:05:172148 return zoom_level;
2149}
[email protected]b75b8292010-10-01 07:28:252150
[email protected]b172aee2012-04-10 17:05:262151int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592152 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172153 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012154 // Calculate the zoom percent from the factor. Round up to the nearest whole
2155 // number.
[email protected]b75b8292010-10-01 07:28:252156 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492157 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252158 *enable_decrement = percent > minimum_zoom_percent_;
2159 *enable_increment = percent < maximum_zoom_percent_;
2160 return percent;
2161}
2162
[email protected]b172aee2012-04-10 17:05:262163void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502164 if (!delegate_)
2165 return;
2166
[email protected]6286a372013-10-09 04:03:272167 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2168 if (!entry)
[email protected]1788e772010-12-15 16:40:502169 return;
2170
[email protected]6286a372013-10-09 04:03:272171 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122172}
2173
[email protected]b172aee2012-04-10 17:05:262174void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042175 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272176 if (!delegate_)
2177 return;
2178
[email protected]691aa2f2013-05-28 22:52:042179 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272180}
2181
[email protected]b172aee2012-04-10 17:05:262182int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272183 return minimum_zoom_percent_;
2184}
2185
[email protected]b172aee2012-04-10 17:05:262186int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272187 return maximum_zoom_percent_;
2188}
2189
[email protected]b172aee2012-04-10 17:05:262190gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492191 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232192}
2193
[email protected]b172aee2012-04-10 17:05:262194bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272195 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582196 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272197}
2198
[email protected]b172aee2012-04-10 17:05:262199bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442200 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502201}
2202
[email protected]cb805452013-05-22 15:16:212203void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482204 if (!color_chooser_info_.get())
2205 return;
2206 RenderFrameHost* rfh = RenderFrameHost::FromID(
2207 color_chooser_info_->render_process_id,
2208 color_chooser_info_->render_frame_id);
2209 if (!rfh)
2210 return;
2211
2212 rfh->Send(new FrameMsg_DidChooseColorResponse(
2213 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202214}
2215
[email protected]cb805452013-05-22 15:16:212216void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482217 if (!color_chooser_info_.get())
2218 return;
2219 RenderFrameHost* rfh = RenderFrameHost::FromID(
2220 color_chooser_info_->render_process_id,
2221 color_chooser_info_->render_frame_id);
2222 if (!rfh)
2223 return;
2224
2225 rfh->Send(new FrameMsg_DidEndColorChooser(
2226 rfh->GetRoutingID(), color_chooser_info_->identifier));
2227 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202228}
2229
[email protected]41225fe2013-03-29 05:32:022230int WebContentsImpl::DownloadImage(const GURL& url,
2231 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302232 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022233 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582234 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022235 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392236 return id;
2237}
2238
[email protected]5dcaf8e2013-12-28 01:31:422239bool WebContentsImpl::IsSubframe() const {
2240 return is_subframe_;
2241}
2242
[email protected]9649d492014-01-10 07:15:522243void WebContentsImpl::SetZoomLevel(double level) {
2244 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2245 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2246 if (embedder)
2247 embedder->SetZoomLevel(level);
2248}
2249
[email protected]36ec24f2014-01-09 00:32:082250void WebContentsImpl::Find(int request_id,
2251 const base::string16& search_text,
2252 const blink::WebFindOptions& options) {
2253 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2254}
2255
2256void WebContentsImpl::StopFinding(StopFindAction action) {
2257 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2258}
2259
[email protected]4fe53add2014-04-08 19:53:362260void WebContentsImpl::InsertCSS(const std::string& css) {
2261 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2262 GetMainFrame()->GetRoutingID(), css));
2263}
2264
[email protected]b172aee2012-04-10 17:05:262265bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272266 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202267 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332268 return true;
2269 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272270}
2271
[email protected]b172aee2012-04-10 17:05:262272void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272273 if (delegate_)
2274 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212275}
2276
[email protected]52913802013-12-10 05:52:182277void WebContentsImpl::DidStartProvisionalLoad(
2278 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072279 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182280 const GURL& validated_url,
2281 bool is_error_page,
2282 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262283 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182284 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572285 DidChangeLoadProgress(0);
2286
[email protected]0d60f0192011-04-14 12:40:102287 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272288 int render_frame_id = render_frame_host->GetRoutingID();
2289 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252290 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072291 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272292 render_frame_id, parent_routing_id, is_main_frame,
2293 validated_url, is_error_page, is_iframe_srcdoc,
2294 render_view_host));
[email protected]400992b2012-06-14 00:03:542295
2296 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182297 FOR_EACH_OBSERVER(
2298 WebContentsObserver,
2299 observers_,
2300 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582301 render_frame_host));
[email protected]400992b2012-06-14 00:03:542302 }
2303}
2304
[email protected]3109fbb72014-01-06 23:57:152305void WebContentsImpl::DidFailProvisionalLoadWithError(
2306 RenderFrameHostImpl* render_frame_host,
2307 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2308 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272309 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262310 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272311 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152312 FOR_EACH_OBSERVER(
2313 WebContentsObserver,
2314 observers_,
[email protected]161eabd2014-03-19 19:47:272315 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152316 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262317 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152318 validated_url,
2319 params.error_code,
2320 params.error_description,
[email protected]161eabd2014-03-19 19:47:272321 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152322}
2323
[email protected]b80624c2014-02-09 02:46:552324void WebContentsImpl::DidFailLoadWithError(
2325 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552326 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552327 int error_code,
2328 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272329 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262330 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272331 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552332 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272333 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262334 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552335}
2336
[email protected]52913802013-12-10 05:52:182337void WebContentsImpl::NotifyChangedNavigationState(
2338 InvalidateTypes changed_flags) {
2339 NotifyNavigationStateChanged(changed_flags);
2340}
2341
[email protected]3691e5cf2014-01-22 10:16:202342void WebContentsImpl::AboutToNavigateRenderFrame(
2343 RenderFrameHostImpl* render_frame_host) {
2344 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272345 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202346 FOR_EACH_OBSERVER(
2347 WebContentsObserver,
2348 observers_,
[email protected]161eabd2014-03-19 19:47:272349 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202350}
2351
2352void WebContentsImpl::DidStartNavigationToPendingEntry(
2353 RenderFrameHostImpl* render_frame_host,
2354 const GURL& url,
2355 NavigationController::ReloadType reload_type) {
2356 // Notify observers about navigation.
2357 FOR_EACH_OBSERVER(
2358 WebContentsObserver,
2359 observers_,
2360 DidStartNavigationToPendingEntry(url, reload_type));
2361}
2362
[email protected]8cb834e2014-03-06 14:23:232363void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2364 const OpenURLParams& params) {
2365 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182366 WebContents* new_contents = OpenURL(params);
2367
2368 if (new_contents) {
2369 // Notify observers.
2370 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2371 DidOpenRequestedURL(new_contents,
2372 params.url,
2373 params.referrer,
2374 params.disposition,
2375 params.transition,
[email protected]8cb834e2014-03-06 14:23:232376 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182377 }
2378}
2379
[email protected]aa62afd2014-04-22 19:22:462380bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2381 if (!delegate_)
2382 return false;
2383 return delegate_->ShouldPreserveAbortedURLs(this);
2384}
2385
[email protected]400992b2012-06-14 00:03:542386void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582387 RenderFrameHostImpl* render_frame_host,
2388 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542389 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582390 FOR_EACH_OBSERVER(
2391 WebContentsObserver,
2392 observers_,
2393 ProvisionalChangeToMainFrameUrl(validated_target_url,
2394 render_frame_host));
[email protected]724159a2010-12-30 01:11:182395}
2396
[email protected]37567b432014-02-12 01:12:222397void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432398 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222399 const base::string16& frame_unique_name,
2400 bool is_main_frame,
2401 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432402 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432403 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272404 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222405 // Notify observers about the commit of the provisional load.
2406 FOR_EACH_OBSERVER(
2407 WebContentsObserver,
2408 observers_,
[email protected]27dd82fd2014-03-03 22:11:432409 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222410 frame_unique_name,
2411 is_main_frame,
2412 url,
2413 transition_type,
2414 render_view_host));
2415}
2416
[email protected]0d0f4c492014-04-02 06:42:572417void WebContentsImpl::DidNavigateMainFramePreCommit(
2418 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2419 // Ensure fullscreen mode is exited before committing the navigation to a
2420 // different page. The next page will not start out assuming it is in
2421 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192422 if (controller_.IsURLInPageNavigation(params.url,
2423 params.was_within_same_page,
2424 NAVIGATION_TYPE_UNKNOWN)) {
2425 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572426 return;
2427 }
2428 if (IsFullscreenForCurrentTab())
2429 GetRenderViewHost()->ExitFullscreen();
2430 DCHECK(!IsFullscreenForCurrentTab());
2431}
2432
[email protected]37567b432014-02-12 01:12:222433void WebContentsImpl::DidNavigateMainFramePostCommit(
2434 const LoadCommittedDetails& details,
2435 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2436 if (details.is_navigation_to_different_page()) {
2437 // Clear the status bubble. This is a workaround for a bug where WebKit
2438 // doesn't let us know that the cursor left an element during a
2439 // transition (this is also why the mouse cursor remains as a hand after
2440 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2441 // clear the bubble when a user navigates to a named anchor in the same
2442 // page.
2443 UpdateTargetURL(details.entry->GetPageID(), GURL());
2444 }
2445
2446 if (!details.is_in_page) {
2447 // Once the main frame is navigated, we're no longer considered to have
2448 // displayed insecure content.
2449 displayed_insecure_content_ = false;
2450 SSLManager::NotifySSLInternalStateChanged(
2451 GetController().GetBrowserContext());
2452 }
2453
2454 // Notify observers about navigation.
2455 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2456 DidNavigateMainFrame(details, params));
2457
2458 if (delegate_) {
2459 delegate_->DidNavigateMainFramePostCommit(this);
2460 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2461 }
2462}
2463
2464void WebContentsImpl::DidNavigateAnyFramePostCommit(
2465 RenderFrameHostImpl* render_frame_host,
2466 const LoadCommittedDetails& details,
2467 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2468 // If we navigate off the page, close all JavaScript dialogs.
2469 if (dialog_manager_ && !details.is_in_page)
2470 dialog_manager_->CancelActiveAndPendingDialogs(this);
2471
2472 // Notify observers about navigation.
2473 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2474 DidNavigateAnyFrame(details, params));
2475}
2476
2477void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2478 contents_mime_type_ = mime_type;
2479}
2480
2481bool WebContentsImpl::CanOverscrollContent() {
2482 if (delegate_)
2483 return delegate_->CanOverscrollContent();
2484
2485 return false;
2486}
2487
[email protected]b172aee2012-04-10 17:05:262488void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182489 const GURL& url,
[email protected]70435962011-08-02 20:13:282490 const std::string& security_info,
2491 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182492 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282493 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192494 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182495 cache.Increment();
2496
2497 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082498 int cert_id = 0;
2499 net::CertStatus cert_status = 0;
2500 int security_bits = -1;
2501 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122502 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212503 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122504 &security_bits, &connection_status,
2505 &signed_certificate_timestamp_ids);
2506 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212507 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002508 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2509 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182510
[email protected]b0f724c2013-09-05 04:21:132511 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2512
2513 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2514 DidLoadResourceFromMemoryCache(details));
2515
[email protected]8bfc8272013-09-09 20:10:532516 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2517 scoped_refptr<net::URLRequestContextGetter> request_context(
2518 resource_type == ResourceType::MEDIA ?
2519 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2520 GetRenderProcessHost()->GetID()) :
2521 GetBrowserContext()->GetRequestContextForRenderProcess(
2522 GetRenderProcessHost()->GetID()));
2523 BrowserThread::PostTask(
2524 BrowserThread::IO,
2525 FROM_HERE,
2526 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2527 }
[email protected]724159a2010-12-30 01:11:182528}
2529
[email protected]b172aee2012-04-10 17:05:262530void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392531 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182532 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192533 SSLManager::NotifySSLInternalStateChanged(
2534 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182535}
2536
[email protected]b172aee2012-04-10 17:05:262537void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022538 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582539 LOG(WARNING) << security_origin << " ran insecure content from "
2540 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392541 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412542 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392543 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182544 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412545 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192546 SSLManager::NotifySSLInternalStateChanged(
2547 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182548}
2549
[email protected]501052ff2014-02-21 22:19:072550void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572551 CHECK(render_frame_message_source_);
2552 CHECK(!render_view_message_source_);
2553 RenderFrameHostImpl* rfh =
2554 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2555
[email protected]161eabd2014-03-19 19:47:272556 int render_frame_id = rfh->GetRoutingID();
2557 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572558 FOR_EACH_OBSERVER(WebContentsObserver,
2559 observers_,
[email protected]161eabd2014-03-19 19:47:272560 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182561}
2562
[email protected]b172aee2012-04-10 17:05:262563void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262564 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372565 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122566 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2567 GetRenderProcessHost()->ReceivedBadMessage();
2568 return;
2569 }
[email protected]a1b99262013-12-27 21:56:222570
[email protected]8b3af1e2014-01-24 13:29:122571 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442572 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372573 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422574 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372575
[email protected]61ac9e242014-03-21 20:55:262576 RenderFrameHostImpl* rfh =
2577 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272578 int render_frame_id = rfh->GetRoutingID();
2579 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262580 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252581 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272582 DidFinishLoad(render_frame_id, validated_url,
2583 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312584}
2585
[email protected]b172aee2012-04-10 17:05:262586void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222587 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2588 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262589}
2590
[email protected]b172aee2012-04-10 17:05:262591void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2592 int maximum_percent,
2593 bool remember) {
[email protected]216813952011-05-19 22:21:262594 minimum_zoom_percent_ = minimum_percent;
2595 maximum_zoom_percent_ = maximum_percent;
2596 temporary_zoom_settings_ = !remember;
2597}
2598
[email protected]b172aee2012-04-10 17:05:262599void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342600 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432601 if (!delegate_)
2602 return;
2603
[email protected]b9535422012-02-09 01:47:592604 ChildProcessSecurityPolicyImpl* policy =
2605 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222606 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592607 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212608}
2609
[email protected]b172aee2012-04-10 17:05:262610void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2611 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262612 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362613 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432614 if (!delegate_)
2615 return;
2616
[email protected]b9535422012-02-09 01:47:592617 ChildProcessSecurityPolicyImpl* policy =
2618 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322619 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592620 return;
[email protected]8f810632013-06-06 22:33:322621
[email protected]3a3b75a2012-06-01 08:38:362622 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202623}
2624
[email protected]b172aee2012-04-10 17:05:262625void WebContentsImpl::OnFindReply(int request_id,
2626 int number_of_matches,
2627 const gfx::Rect& selection_rect,
2628 int active_match_ordinal,
2629 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432630 if (delegate_) {
2631 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2632 active_match_ordinal, final_update);
2633 }
[email protected]b888919c2011-09-02 00:32:162634}
2635
[email protected]59363fc92012-09-05 03:46:312636#if defined(OS_ANDROID)
2637void WebContentsImpl::OnFindMatchRectsReply(
2638 int version,
2639 const std::vector<gfx::RectF>& rects,
2640 const gfx::RectF& active_rect) {
2641 if (delegate_)
2642 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2643}
[email protected]583418cc2013-01-17 14:01:102644
[email protected]1ff427972013-02-07 21:14:072645void WebContentsImpl::OnOpenDateTimeDialog(
2646 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092647 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2648 GetRenderViewHost(),
2649 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132650 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092651 value.minimum,
2652 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172653 value.step,
2654 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102655}
2656
[email protected]a794f3a2013-10-30 17:00:322657void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2658 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]c06c58c2014-03-12 20:31:592659 render_frame_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322660}
2661
[email protected]59363fc92012-09-05 03:46:312662#endif
2663
[email protected]f114fa42013-12-06 17:06:442664void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2665 const base::FilePath& path,
2666 bool is_hung) {
2667 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2668
2669 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2670 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2671}
2672
2673void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422674 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442675 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422676 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452677}
2678
[email protected]cfa856d62014-02-22 07:58:402679void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2680 int automation_id) {
2681 DomOperationNotificationDetails details(json_string, automation_id);
2682 NotificationService::current()->Notify(
2683 NOTIFICATION_DOM_OPERATION_RESPONSE,
2684 Source<WebContents>(this),
2685 Details<DomOperationNotificationDetails>(&details));
2686}
2687
[email protected]b172aee2012-04-10 17:05:262688void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2689 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102690 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252691 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102692 AppCacheAccessed(manifest_url, blocked_by_policy));
2693}
2694
[email protected]8bc5ff02013-11-29 06:34:032695void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482696 int color_chooser_id,
2697 SkColor color,
2698 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462699 ColorChooser* new_color_chooser = delegate_ ?
2700 delegate_->OpenColorChooser(this, color, suggestions) :
2701 NULL;
[email protected]820957a2014-01-14 14:56:302702 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212703 return;
[email protected]8ed16472014-04-11 19:02:482704 if (color_chooser_info_.get())
2705 color_chooser_info_->chooser->End();
2706
2707 color_chooser_info_.reset(new ColorChooserInfo(
2708 render_frame_message_source_->GetProcess()->GetID(),
2709 render_frame_message_source_->GetRoutingID(),
2710 new_color_chooser,
2711 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202712}
2713
[email protected]b172aee2012-04-10 17:05:262714void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482715 if (color_chooser_info_ &&
2716 color_chooser_id == color_chooser_info_->identifier)
2717 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202718}
2719
[email protected]b172aee2012-04-10 17:05:262720void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322721 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482722 if (color_chooser_info_ &&
2723 color_chooser_id == color_chooser_info_->identifier)
2724 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202725}
2726
[email protected]d0759f492012-04-19 22:50:502727// This exists for render views that don't have a WebUI, but do have WebUI
2728// bindings enabled.
2729void WebContentsImpl::OnWebUISend(const GURL& source_url,
2730 const std::string& name,
2731 const base::ListValue& args) {
2732 if (delegate_)
2733 delegate_->WebUISend(this, source_url, name, args);
2734}
2735
[email protected]d8415ad92012-08-23 14:40:502736void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442737 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502738 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342739 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162740 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442741 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162742 return;
[email protected]d8415ad92012-08-23 14:40:502743 }
2744
[email protected]8c8fc292012-11-23 18:57:162745 if (!delegate_->RequestPpapiBrokerPermission(
2746 this, url, plugin_path,
2747 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442748 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162749 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442750 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162751 }
[email protected]d8415ad92012-08-23 14:40:502752}
2753
[email protected]ea0309c2013-08-06 19:35:442754void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502755 bool result) {
[email protected]ea0309c2013-08-06 19:35:442756 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502757}
2758
[email protected]c4538072013-03-18 02:17:552759void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372760 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082761 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552762 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392763 // For more info, see comment above classes BrowserPluginEmbedder and
2764 // BrowserPluginGuest.
2765 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142766 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082767 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372768}
2769
[email protected]41225fe2013-03-29 05:32:022770void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392771 int id,
[email protected]749fadd2013-05-15 08:37:482772 int http_status_code,
[email protected]795c28972012-12-06 06:13:392773 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302774 const std::vector<SkBitmap>& bitmaps,
2775 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132776 if (bitmaps.size() != original_bitmap_sizes.size())
2777 return;
2778
[email protected]41225fe2013-03-29 05:32:022779 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2780 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392781 // Currently WebContents notifies us of ANY downloads so that it is
2782 // possible to get here.
2783 return;
2784 }
2785 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302786 iter->second.Run(
2787 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392788 }
[email protected]41225fe2013-03-29 05:32:022789 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392790}
2791
2792void WebContentsImpl::OnUpdateFaviconURL(
2793 int32 page_id,
2794 const std::vector<FaviconURL>& candidates) {
2795 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2796 DidUpdateFaviconURL(page_id, candidates));
2797}
2798
[email protected]1dd0bb752014-02-01 01:16:262799void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2800 bool has_video,
2801 bool has_audio) {
2802// Chrome OS does its own detection of audio and video.
2803#if !defined(OS_CHROMEOS)
2804 scoped_ptr<PowerSaveBlocker> blocker;
2805 if (has_video) {
2806 blocker = PowerSaveBlocker::Create(
2807 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2808#if defined(OS_ANDROID)
2809 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2810 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2811#endif
2812 } else if (has_audio) {
2813 blocker = PowerSaveBlocker::Create(
2814 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2815 }
2816
2817 if (blocker) {
2818 power_save_blockers_[render_view_message_source_][player_cookie] =
2819 blocker.release();
2820 }
2821#endif // !defined(OS_CHROMEOS)
2822}
2823
2824void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062825 // Chrome OS does its own detection of audio and video.
2826#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262827 delete power_save_blockers_[render_view_message_source_][player_cookie];
2828 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062829#endif // !defined(OS_CHROMEOS)
2830}
2831
[email protected]9f268072013-11-07 00:02:152832void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2833 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2834 DidFirstVisuallyNonEmptyPaint(page_id));
2835}
[email protected]d9030b82013-07-19 08:26:062836
[email protected]e67ebf32013-02-13 11:07:192837void WebContentsImpl::DidChangeVisibleSSLState() {
2838 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2839 DidChangeVisibleSSLState());
2840}
2841
[email protected]17e286e2013-03-01 23:29:392842void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2843 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2844 BeforeFormRepostWarningShow());
2845}
2846
[email protected]ec6c05f2013-10-23 18:41:572847
2848void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2849 Activate();
2850 if (delegate_)
2851 delegate_->ShowRepostFormWarningDialog(this);
2852}
2853
[email protected]96d185d2009-04-24 03:28:542854// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592855// loading, or done loading.
2856void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2857 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092858 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262859 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542860 if (is_loading == is_loading_)
2861 return;
2862
2863 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262864 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2865 base::string16());
[email protected]96d185d2009-04-24 03:28:542866 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562867 upload_size_ = 0;
2868 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542869 }
2870
[email protected]fa944cb82013-11-15 17:51:212871 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542872
2873 is_loading_ = is_loading;
2874 waiting_for_response_ = is_loading;
2875
[email protected]6ebdc9b2010-09-27 16:55:572876 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092877 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212878 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542879
[email protected]eab61442013-11-14 18:35:482880 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592881 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482882 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2883 "URL", url);
[email protected]91621872013-10-08 04:04:592884 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2885 DidStartLoading(render_view_host));
2886 } else {
[email protected]eab61442013-11-14 18:35:482887 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2888 "URL", url);
[email protected]91621872013-10-08 04:04:592889 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2890 DidStopLoading(render_view_host));
2891 }
[email protected]66798902013-10-01 18:40:162892
2893 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212894 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2895 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542896 if (details)
[email protected]8ff00d72012-10-23 19:12:212897 det = Details<LoadNotificationDetails>(details);
2898 NotificationService::current()->Notify(
2899 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542900}
2901
[email protected]959be4c2014-04-08 15:01:332902void WebContentsImpl::SelectRange(const gfx::Point& start,
2903 const gfx::Point& end) {
2904 RenderFrameHost* focused_frame = GetFocusedFrame();
2905 if (!focused_frame)
2906 return;
2907
2908 focused_frame->Send(
2909 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
2910}
2911
[email protected]b172aee2012-04-10 17:05:262912void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462913 // If we are creating a RVH for a restored controller, then we need to make
2914 // sure the RenderView starts with a next_page_id_ larger than the number
2915 // of restored entries. This must be called before the RenderView starts
2916 // navigating (to avoid a race between the browser updating max_page_id and
2917 // the renderer updating next_page_id_). Because of this, we only call this
2918 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562919 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582920 if (max_restored_page_id >
2921 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2922 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2923 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322924}
2925
[email protected]b172aee2012-04-10 17:05:262926bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262927 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322928 // For file URLs without a title, use the pathname instead. In the case of a
2929 // synthesized title, we don't want the update to count toward the "one set
2930 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262931 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322932 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512933 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242934 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322935 explicit_set = false; // Don't count synthetic titles toward the set limit.
2936 } else {
[email protected]8af69c6c2014-03-03 19:05:312937 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322938 explicit_set = true;
2939 }
2940
[email protected]987fc3a2011-05-26 14:18:092941 // If a page is created via window.open and never navigated,
2942 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552943 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092944 if (entry) {
[email protected]36fc0392011-12-25 03:59:512945 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092946 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322947
[email protected]36fc0392011-12-25 03:59:512948 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092949 } else {
2950 if (page_title_when_no_navigation_entry_ == final_title)
2951 return false; // Nothing changed, don't bother.
2952
2953 page_title_when_no_navigation_entry_ = final_title;
2954 }
[email protected]420ae012009-04-24 05:16:322955
[email protected]420ae012009-04-24 05:16:322956 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232957 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322958
[email protected]66798902013-10-01 18:40:162959 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532960 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162961
2962 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212963 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462964 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212965 NotificationService::current()->Notify(
2966 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2967 Source<WebContents>(this),
2968 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042969
[email protected]420ae012009-04-24 05:16:322970 return true;
2971}
2972
[email protected]7b712ee22013-10-03 00:57:282973void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2974 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322975 // After sending out a swap notification, we need to send a disconnect
2976 // notification so that clients that pick up a pointer to |this| can NULL the
2977 // pointer. See Bug 1230284.
2978 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112979 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282980 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112981
2982 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282983 std::pair<RenderViewHost*, RenderViewHost*> details =
2984 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212985 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282986 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212987 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282988 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392989
2990 // Ensure that the associated embedder gets cleared after a RenderViewHost
2991 // gets swapped, so we don't reuse the same embedder next time a
2992 // RenderViewHost is attached to this WebContents.
2993 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322994}
2995
[email protected]da7a7182013-09-06 08:11:112996// TODO(avi): Remove this entire function because this notification is already
2997// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262998void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322999 if (!notify_disconnection_)
3000 return;
3001
3002 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213003 NotificationService::current()->Notify(
3004 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3005 Source<WebContents>(this),
3006 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323007}
3008
[email protected]cbb1ef592013-06-05 19:49:463009void WebContentsImpl::NotifyNavigationEntryCommitted(
3010 const LoadCommittedDetails& load_details) {
3011 FOR_EACH_OBSERVER(
3012 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3013}
3014
[email protected]f114fa42013-12-06 17:06:443015bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3016 const IPC::Message& message) {
3017 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313018}
3019
[email protected]c31a84802014-04-03 15:55:493020const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3021 return GetLastCommittedURL();
3022}
3023
[email protected]b849847b2013-12-10 21:57:583024void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3025 // Note this is only for subframes, the notification for the main frame
3026 // happens in RenderViewCreated.
3027 FOR_EACH_OBSERVER(WebContentsObserver,
3028 observers_,
3029 RenderFrameCreated(render_frame_host));
3030}
3031
3032void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3033 FOR_EACH_OBSERVER(WebContentsObserver,
3034 observers_,
3035 RenderFrameDeleted(render_frame_host));
3036}
3037
[email protected]a09d53ce2014-01-31 00:46:423038void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303039 if (delegate_)
3040 delegate_->WorkerCrashed(this);
3041}
3042
[email protected]a09d53ce2014-01-31 00:46:423043void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3044 const ContextMenuParams& params) {
3045 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:403046 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:423047 return;
3048
3049 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
3050}
3051
[email protected]87de04b02014-04-08 22:14:493052void WebContentsImpl::RunJavaScriptMessage(
3053 RenderFrameHost* rfh,
3054 const base::string16& message,
3055 const base::string16& default_prompt,
3056 const GURL& frame_url,
3057 JavaScriptMessageType javascript_message_type,
3058 IPC::Message* reply_msg) {
3059 // Suppress JavaScript dialogs when requested. Also suppress messages when
3060 // showing an interstitial as it's shown over the previous page and we don't
3061 // want the hidden page's dialogs to interfere with the interstitial.
3062 bool suppress_this_message =
3063 static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost())->
3064 IsSwappedOut() ||
3065 ShowingInterstitialPage() ||
3066 !delegate_ ||
3067 delegate_->ShouldSuppressDialogs() ||
3068 !delegate_->GetJavaScriptDialogManager();
3069
3070 if (!suppress_this_message) {
3071 std::string accept_lang = GetContentClient()->browser()->
3072 GetAcceptLangs(GetBrowserContext());
3073 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3074 dialog_manager_->RunJavaScriptDialog(
3075 this,
3076 frame_url.GetOrigin(),
3077 accept_lang,
3078 javascript_message_type,
3079 message,
3080 default_prompt,
3081 base::Bind(&WebContentsImpl::OnDialogClosed,
3082 base::Unretained(this),
3083 rfh,
3084 reply_msg,
3085 false),
3086 &suppress_this_message);
3087 }
3088
3089 if (suppress_this_message) {
3090 // If we are suppressing messages, just reply as if the user immediately
3091 // pressed "Cancel", passing true to |dialog_was_suppressed|.
3092 OnDialogClosed(rfh, reply_msg, true, false, base::string16());
3093 }
3094
3095 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3096 // http://crbug.com/288961 ). The only safe thing to do here is return.
3097}
3098
3099void WebContentsImpl::RunBeforeUnloadConfirm(
3100 RenderFrameHost* rfh,
3101 const base::string16& message,
3102 bool is_reload,
3103 IPC::Message* reply_msg) {
3104 RenderFrameHostImpl* rfhi = static_cast<RenderFrameHostImpl*>(rfh);
3105 RenderViewHostImpl* rvhi =
3106 static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost());
3107 if (delegate_)
3108 delegate_->WillRunBeforeUnloadConfirm();
3109
3110 bool suppress_this_message =
3111 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3112 !delegate_ ||
3113 delegate_->ShouldSuppressDialogs() ||
3114 !delegate_->GetJavaScriptDialogManager();
3115 if (suppress_this_message) {
3116 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3117 return;
3118 }
3119
3120 is_showing_before_unload_dialog_ = true;
3121 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3122 dialog_manager_->RunBeforeUnloadDialog(
3123 this, message, is_reload,
3124 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
3125 rfh, reply_msg, false));
3126}
3127
[email protected]a86c0e962013-12-17 17:10:393128WebContents* WebContentsImpl::GetAsWebContents() {
3129 return this;
3130}
3131
[email protected]7912e822014-04-16 02:37:033132bool WebContentsImpl::IsNeverVisible() {
3133 if (!delegate_)
3134 return false;
3135 return delegate_->IsNeverVisible(this);
3136}
3137
[email protected]5a3bdf52012-05-24 15:12:573138RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3139 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323140}
3141
[email protected]8ff00d72012-10-23 19:12:213142RendererPreferences WebContentsImpl::GetRendererPrefs(
3143 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463144 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513145}
3146
[email protected]b172aee2012-04-10 17:05:263147gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173148 if (delegate_)
3149 return delegate_->GetRootWindowResizerRect();
3150 return gfx::Rect();
3151}
3152
[email protected]7a846df2012-09-20 19:17:393153void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273154 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393155 browser_plugin_embedder_.reset();
3156}
3157
[email protected]b172aee2012-04-10 17:05:263158void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443159 // Don't send notifications if we are just creating a swapped-out RVH for
3160 // the opener chain. These won't be used for view-source or WebUI, so it's
3161 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243162 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443163 return;
3164
[email protected]86f98a22013-03-20 14:35:003165 if (delegate_)
3166 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083167
[email protected]8ff00d72012-10-23 19:12:213168 NotificationService::current()->Notify(
3169 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3170 Source<WebContents>(this),
3171 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323172
3173 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353174 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213175 if (GetRenderManager()->pending_web_ui())
3176 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323177
[email protected]6286a372013-10-09 04:03:273178 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333179 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323180 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183181 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583182 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323183 }
[email protected]0666aef2009-05-13 19:48:083184
[email protected]60780f412013-02-25 16:34:103185 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263186
3187 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253188 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583189
3190 // We tell the observers now instead of when the main RenderFrameHostImpl is
3191 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3192 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363193 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583194 FOR_EACH_OBSERVER(
3195 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323196}
3197
[email protected]b172aee2012-04-10 17:05:263198void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523199 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323200 // Don't notify the world, since this came from a renderer in the
3201 // background.
3202 return;
3203 }
3204
[email protected]da7a7182013-09-06 08:11:113205 notify_disconnection_ = true;
3206 // TODO(avi): Remove. http://crbug.com/170921
3207 NotificationService::current()->Notify(
3208 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3209 Source<WebContents>(this),
3210 NotificationService::NoDetails());
3211
[email protected]be1f56ab2011-12-22 06:55:313212 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233213 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303214
3215 // Restore the focus to the tab (otherwise the focus will be on the top
3216 // window).
[email protected]484ae5912010-09-29 19:16:143217 if (was_crashed && !FocusLocationBarByDefault() &&
3218 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063219 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143220 }
[email protected]32ded2212011-11-10 18:51:433221
[email protected]d8c660432011-12-22 20:51:253222 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323223}
3224
[email protected]ec6a7eb2013-04-22 17:34:223225void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3226 base::TerminationStatus status,
3227 int error_code) {
[email protected]151a63d2011-12-20 22:32:523228 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323229 // The pending page's RenderViewHost is gone.
3230 return;
3231 }
3232
[email protected]2fcdcc32014-03-05 02:14:073233 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3234 // renderer may not have made a clean exit.
3235 if (IsFullscreenForCurrentTab())
3236 ToggleFullscreenMode(false);
3237
[email protected]698191dc2014-02-25 01:06:133238 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3239 if (dialog_manager_)
3240 dialog_manager_->CancelActiveAndPendingDialogs(this);
3241
[email protected]d9030b82013-07-19 08:26:063242 ClearPowerSaveBlockers(rvh);
[email protected]e3b10d12014-03-28 16:06:093243 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323244 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233245 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:313246 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:323247
[email protected]d8c660432011-12-22 20:51:253248 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273249 observers_,
[email protected]58d5cfe2013-07-10 02:40:523250 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323251}
3252
[email protected]b172aee2012-04-10 17:05:263253void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:063254 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:213255 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:253256 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063257}
3258
[email protected]b172aee2012-04-10 17:05:263259void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3260 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043261 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153262 // Ensure that this state update comes from either the active RVH or one of
3263 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413264 // TODO(nasko): This should go through RenderFrameHost.
3265 // TODO(creis): We can't update state for cross-process subframes until we
3266 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3267 if (rvh != GetRenderViewHost() &&
3268 !GetRenderManager()->IsRVHOnSwappedOutList(
3269 static_cast<RenderViewHostImpl*>(rvh)))
3270 return;
[email protected]420ae012009-04-24 05:16:323271
3272 // We must be prepared to handle state updates for any page, these occur
3273 // when the user is scrolling and entering form data, as well as when we're
3274 // leaving a page, in which case our state may have already been moved to
3275 // the next page. The navigation controller will look up the appropriate
3276 // NavigationEntry and update it when it is notified via the delegate.
3277
3278 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583279 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323280 if (entry_index < 0)
3281 return;
[email protected]10f417c52011-12-28 21:04:233282 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323283
[email protected]691aa2f2013-05-28 22:52:043284 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323285 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043286 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323287 controller_.NotifyEntryChanged(entry, entry_index);
3288}
3289
[email protected]b172aee2012-04-10 17:05:263290void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3291 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263292 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263293 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323294 // If we have a title, that's a pretty good indication that we've started
3295 // getting useful data.
3296 SetNotWaitingForResponse();
3297
[email protected]73eb2602012-02-09 19:50:553298 // Try to find the navigation entry, which might not be the current one.
3299 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233300 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583301 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093302
[email protected]73eb2602012-02-09 19:50:553303 // We can handle title updates when we don't have an entry in
3304 // UpdateTitleForEntry, but only if the update is from the current RVH.
3305 if (!entry && rvh != GetRenderViewHost())
3306 return;
3307
[email protected]a49e10b2011-08-01 23:57:463308 // TODO(evan): make use of title_direction.
3309 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093310 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323311 return;
3312
3313 // Broadcast notifications when the UI should be updated.
3314 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213315 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323316}
3317
[email protected]b172aee2012-04-10 17:05:263318void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3319 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313320 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323321}
3322
[email protected]b172aee2012-04-10 17:05:263323void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513324 if (delegate_)
3325 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323326}
3327
[email protected]b172aee2012-04-10 17:05:263328void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103329#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293330 // The UI may be in an event-tracking loop, such as between the
3331 // mouse-down and mouse-up in text selection or a button click.
3332 // Defer the close until after tracking is complete, so that we
3333 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293334 // TODO(shess): This could get more fine-grained. For instance,
3335 // closing a tab in another window while selecting text in the
3336 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103337 if (view_->IsEventTracking()) {
3338 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293339 return;
3340 }
[email protected]60780f412013-02-25 16:34:103341#endif
[email protected]07707302009-11-06 00:50:293342
[email protected]420ae012009-04-24 05:16:323343 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523344 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513345 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323346}
3347
[email protected]66bbadaf2014-03-28 16:25:543348void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573349 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3350 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573351}
3352
[email protected]b172aee2012-04-10 17:05:263353void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513354 if (delegate_ && delegate_->IsPopupOrPanel(this))
3355 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323356}
3357
[email protected]e3b10d12014-03-28 16:06:093358void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3359 bool to_different_document) {
3360 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3361 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323362}
3363
[email protected]723971b2014-02-12 11:08:253364void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323365 scoped_ptr<LoadNotificationDetails> details;
3366
[email protected]9595fd82013-04-19 21:28:493367 // Use the last committed entry rather than the active one, in case a
3368 // pending entry has been created.
3369 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203370 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493371
[email protected]420ae012009-04-24 05:16:323372 // An entry may not exist for a stop when loading an initial blank page or
3373 // if an iframe injected by script into a blank page finishes loading.
3374 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203375 base::TimeDelta elapsed =
3376 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323377
3378 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513379 entry->GetVirtualURL(),
3380 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323381 elapsed,
3382 &controller_,
3383 controller_.GetCurrentEntryIndex()));
3384 }
3385
[email protected]e3b10d12014-03-28 16:06:093386 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3387 details.get());
[email protected]420ae012009-04-24 05:16:323388}
3389
[email protected]b172aee2012-04-10 17:05:263390void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163391 controller_.DiscardNonCommittedEntries();
3392
3393 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213394 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163395}
3396
[email protected]b172aee2012-04-10 17:05:263397void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513398 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133399 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403400}
3401
[email protected]7cc78902012-12-06 02:32:263402void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393403 if (opener_) {
3404 // Clear our opener so that future cross-process navigations don't have an
3405 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103406 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393407 opener_ = NULL;
3408 }
[email protected]7cc78902012-12-06 02:32:263409
3410 // Notify all swapped out RenderViewHosts for this tab. This is important
3411 // in case we go back to them, or if another window in those processes tries
3412 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213413 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263414}
3415
[email protected]59167c22013-06-03 18:07:323416void WebContentsImpl::DidAccessInitialDocument() {
[email protected]d1371bf8e2014-04-19 03:26:243417 // We may have left a failed browser-initiated navigation in the address bar
3418 // to let the user edit it and try again. Clear it now that content might
3419 // show up underneath it.
3420 if (!IsLoading() && controller_.GetPendingEntry())
3421 controller_.DiscardPendingEntry();
3422
[email protected]59167c22013-06-03 18:07:323423 // Update the URL display.
3424 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3425}
3426
[email protected]87717d0e2012-04-26 02:58:433427void WebContentsImpl::DocumentAvailableInMainFrame(
3428 RenderViewHost* render_view_host) {
3429 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3430 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103431}
3432
[email protected]b172aee2012-04-10 17:05:263433void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083434 RenderViewHost* render_view_host,
3435 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093436 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3437 DocumentOnLoadCompletedInMainFrame(page_id));
3438
3439 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213440 NotificationService::current()->Notify(
3441 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3442 Source<WebContents>(this),
3443 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083444}
3445
[email protected]e1c3a552012-05-04 20:51:323446void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3447 // Tell the active RenderViewHost to run unload handlers and close, as long
3448 // as the request came from a RenderViewHost in the same BrowsingInstance.
3449 // In most cases, we receive this from a swapped out RenderViewHost.
3450 // It is possible to receive it from one that has just been swapped in,
3451 // in which case we might as well deliver the message anyway.
3452 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3453 GetRenderViewHost()->ClosePage();
3454}
3455
[email protected]f546640b2012-05-15 00:03:493456void WebContentsImpl::RouteMessageEvent(
3457 RenderViewHost* rvh,
3458 const ViewMsg_PostMessage_Params& params) {
3459 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363460 // came from a RenderViewHost in the same BrowsingInstance or if this
3461 // WebContents is dedicated to a browser plugin guest.
3462 // Note: This check means that an embedder could theoretically receive a
3463 // postMessage from anyone (not just its own guests). However, this is
3464 // probably not a risk for apps since other pages won't have references
3465 // to App windows.
3466 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3467 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493468 return;
3469
3470 ViewMsg_PostMessage_Params new_params(params);
3471
[email protected]0bc7f3542013-10-21 15:05:533472 if (!params.message_port_ids.empty()) {
3473 MessagePortMessageFilter* message_port_message_filter =
3474 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3475 ->message_port_message_filter();
3476 std::vector<int> new_routing_ids(params.message_port_ids.size());
3477 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3478 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3479 MessagePortService::GetInstance()->UpdateMessagePort(
3480 params.message_port_ids[i],
3481 message_port_message_filter,
3482 new_routing_ids[i]);
3483 }
3484 new_params.new_routing_ids = new_routing_ids;
3485 }
3486
[email protected]f546640b2012-05-15 00:03:493487 // If there is a source_routing_id, translate it to the routing ID for
3488 // the equivalent swapped out RVH in the target process. If we need
3489 // to create a swapped out RVH for the source tab, we create its opener
3490 // chain as well, since those will also be accessible to the target page.
3491 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3492 // Try to look up the WebContents for the source page.
3493 WebContentsImpl* source_contents = NULL;
3494 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3495 rvh->GetProcess()->GetID(), params.source_routing_id);
3496 if (source_rvh) {
3497 source_contents = static_cast<WebContentsImpl*>(
3498 source_rvh->GetDelegate()->GetAsWebContents());
3499 }
3500
3501 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363502 if (GetBrowserPluginGuest()) {
3503 // We create a swapped out RenderView for the embedder in the guest's
3504 // render process but we intentionally do not expose the embedder's
3505 // opener chain to it.
3506 new_params.source_routing_id =
3507 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3508 } else {
3509 new_params.source_routing_id =
3510 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3511 }
[email protected]f546640b2012-05-15 00:03:493512 } else {
3513 // We couldn't find it, so don't pass a source frame.
3514 new_params.source_routing_id = MSG_ROUTING_NONE;
3515 }
3516 }
3517
3518 // In most cases, we receive this from a swapped out RenderViewHost.
3519 // It is possible to receive it from one that has just been swapped in,
3520 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183521 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493522}
3523
[email protected]a796f202012-05-30 14:14:253524bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263525 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253526 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263527 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253528 if (!delegate_)
3529 return false;
3530 return delegate_->AddMessageToConsole(this, level, message, line_no,
3531 source_id);
3532}
3533
[email protected]b172aee2012-04-10 17:05:263534WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273535 // We want to base the page config off of the actual URL, rather than the
3536 // virtual URL.
3537 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3538 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003539 GURL url = controller_.GetActiveEntry()
3540 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153541
[email protected]fa944cb82013-11-15 17:51:213542 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323543}
3544
[email protected]0eba810b2012-10-18 03:19:363545int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213546 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413547 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3548 true, true);
[email protected]0eba810b2012-10-18 03:19:363549}
3550
[email protected]b172aee2012-04-10 17:05:263551void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273552 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253553 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223554
[email protected]ea114722012-03-12 01:11:253555 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173556 if (rdh) // NULL in unittests.
3557 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253558}
3559
[email protected]b172aee2012-04-10 17:05:263560void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443561 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253562 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443563}
3564
[email protected]b172aee2012-04-10 17:05:263565void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563566 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263567 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153568 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523569 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153570 return;
3571
[email protected]9f76c1e2012-03-05 15:15:583572 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3573
[email protected]e5fc1632011-08-08 07:51:533574 // Ignore renderer unresponsive event if debugger is attached to the tab
3575 // since the event may be a result of the renderer sitting on a breakpoint.
3576 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363577 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533578 return;
3579
[email protected]2e9d79f2013-08-16 05:45:563580 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323581 // Hang occurred while firing the beforeunload/unload handler.
3582 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583583 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323584
[email protected]fa944cb82013-11-15 17:51:213585 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323586 return;
3587
3588 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563589 // nothing we can do to recover. If the hang is in the beforeunload handler,
3590 // pretend the beforeunload listeners have all fired and allow the delegate
3591 // to continue closing; the user will not have the option of cancelling the
3592 // close. Otherwise, pretend the unload listeners have all fired and close
3593 // the tab.
3594 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463595 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563596 delegate_->BeforeUnloadFired(this, true, &close);
3597 }
3598 if (close)
3599 Close(rvh);
[email protected]420ae012009-04-24 05:16:323600 return;
3601 }
3602
[email protected]9f76c1e2012-03-05 15:15:583603 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473604 return;
3605
[email protected]6934a702011-12-20 00:04:513606 if (delegate_)
3607 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323608}
3609
[email protected]b172aee2012-04-10 17:05:263610void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513611 if (delegate_)
3612 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323613}
3614
[email protected]b172aee2012-04-10 17:05:263615void WebContentsImpl::LoadStateChanged(
3616 const GURL& url,
3617 const net::LoadStateWithParam& load_state,
3618 uint64 upload_position,
3619 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323620 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563621 upload_position_ = upload_position;
3622 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503623 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213624 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303625 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213626 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323627 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463628 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213629 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463630 }
[email protected]420ae012009-04-24 05:16:323631}
3632
[email protected]b172aee2012-04-10 17:05:263633void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553634 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323635 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123636 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3637 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513638 if (delegate_)
3639 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093640 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323641}
3642
[email protected]58d5cfe2013-07-10 02:40:523643void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543644 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233645 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223646 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543647}
3648
[email protected]b172aee2012-04-10 17:05:263649void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103650 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213651 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263652 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3653 // here during container initialization and normal window size will be set
3654 // later. In case of tab duplication this resizing to 0x0 prevents setting
3655 // normal size later so just ignore it.
3656 if (!size.IsEmpty())
3657 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323658}
3659
[email protected]af905902013-10-01 21:38:513660void WebContentsImpl::CancelModalDialogsForRenderManager() {
3661 // We need to cancel modal dialogs when doing a process swap, since the load
3662 // deferrer would prevent us from swapping out.
3663 if (dialog_manager_)
3664 dialog_manager_->CancelActiveAndPendingDialogs(this);
3665}
3666
[email protected]7b712ee22013-10-03 00:57:283667void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3668 RenderViewHost* new_host) {
3669 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083670
3671 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003672 if (delegate_)
3673 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393674
[email protected]7b712ee22013-10-03 00:57:283675 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543676}
3677
[email protected]14392a52012-05-02 20:28:443678int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3679 SiteInstance* instance) {
3680 if (!opener_)
3681 return MSG_ROUTING_NONE;
3682
3683 // Recursively create RenderViews for anything else in the opener chain.
3684 return opener_->CreateOpenerRenderViews(instance);
3685}
3686
3687int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3688 int opener_route_id = MSG_ROUTING_NONE;
3689
3690 // If this tab has an opener, ensure it has a RenderView in the given
3691 // SiteInstance as well.
3692 if (opener_)
3693 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3694
[email protected]45a22ad2013-02-21 03:25:003695 // If any of the renderers (current, pending, or swapped out) for this
3696 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213697 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3698 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373699
[email protected]fa944cb82013-11-15 17:51:213700 if (GetRenderManager()->pending_render_view_host() &&
3701 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3702 instance)
3703 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003704
[email protected]fa944cb82013-11-15 17:51:213705 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373706 instance);
3707 if (rvh)
3708 return rvh->GetRoutingID();
3709
[email protected]14392a52012-05-02 20:28:443710 // Create a swapped out RenderView in the given SiteInstance if none exists,
3711 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413712 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3713 true, true);
[email protected]14392a52012-05-02 20:28:443714}
3715
[email protected]b172aee2012-04-10 17:05:263716NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193717 return GetController();
[email protected]3a3d47472010-07-15 21:03:543718}
3719
[email protected]b172aee2012-04-10 17:05:263720WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563721 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323722}
3723
[email protected]10f417c52011-12-28 21:04:233724NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263725 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323726 return controller_.GetLastCommittedEntry();
3727}
3728
[email protected]b172aee2012-04-10 17:05:263729bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163730 RenderViewHost* render_view_host,
3731 int opener_route_id,
3732 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033733 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443734 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163735 RenderWidgetHostView* rwh_view;
3736 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3737 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3738 // case this because RWH is still a base class of RenderViewHost, and child
3739 // frame RWHVs are unique in that they do not have their own WebContents.
3740 if (frame_connector) {
3741 RenderWidgetHostViewChildFrame* rwh_view_child =
3742 new RenderWidgetHostViewChildFrame(render_view_host);
3743 frame_connector->set_view(rwh_view_child);
3744 rwh_view = rwh_view_child;
3745 } else {
3746 rwh_view = view_->CreateViewForWidget(render_view_host);
3747 }
[email protected]1a98a932009-11-17 00:12:523748
[email protected]420ae012009-04-24 05:16:323749 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443750 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213751 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323752
[email protected]74ce1ad2011-12-16 21:51:463753 // Make sure we use the correct starting page_id in the new RenderView.
3754 UpdateMaxPageIDIfNecessary(render_view_host);
3755 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583756 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463757
[email protected]9f76c1e2012-03-05 15:15:583758 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263759 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493760 opener_route_id,
[email protected]c7c0d822014-04-16 20:19:493761 max_page_id,
3762 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523763 return false;
[email protected]14392a52012-05-02 20:28:443764 }
[email protected]a4127722011-04-27 23:13:523765
[email protected]a220b5932013-09-21 03:47:443766#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503767 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3768 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443769 if (rwh_view) {
3770 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3771 render_widget_host->WasResized();
3772 }
[email protected]f8233cc2011-05-31 20:24:503773#endif
3774
[email protected]420ae012009-04-24 05:16:323775 return true;
3776}
3777
[email protected]7d244f12013-08-22 21:41:513778#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183779base::android::ScopedJavaLocalRef<jobject>
3780WebContentsImpl::GetJavaWebContents() {
3781 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3782
3783 WebContentsAndroid* web_contents_android =
3784 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3785 if (!web_contents_android) {
3786 web_contents_android = new WebContentsAndroid(this);
3787 SetUserData(kWebContentsAndroidKey, web_contents_android);
3788 }
3789 return web_contents_android->GetJavaObject();
3790}
3791
[email protected]7d244f12013-08-22 21:41:513792bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3793 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163794 MSG_ROUTING_NONE,
3795 NULL);
[email protected]7d244f12013-08-22 21:41:513796}
3797#endif
3798
[email protected]87de04b02014-04-08 22:14:493799void WebContentsImpl::OnDialogClosed(RenderFrameHost* rfh,
[email protected]b172aee2012-04-10 17:05:263800 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493801 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263802 bool success,
[email protected]fcf75d42013-12-03 20:11:263803 const base::string16& user_input) {
[email protected]87de04b02014-04-08 22:14:493804 last_dialog_suppressed_ = dialog_was_suppressed;
3805
[email protected]beb440c2009-11-06 04:08:543806 if (is_showing_before_unload_dialog_ && !success) {
3807 // If a beforeunload dialog is canceled, we need to stop the throbber from
3808 // spinning, since we forced it to start spinning in Navigate.
[email protected]87de04b02014-04-08 22:14:493809 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353810 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103811
[email protected]6d65a462013-06-21 21:29:123812 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3813 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543814 }
[email protected]87de04b02014-04-08 22:14:493815
[email protected]beb440c2009-11-06 04:08:543816 is_showing_before_unload_dialog_ = false;
[email protected]87de04b02014-04-08 22:14:493817 static_cast<RenderFrameHostImpl*>(rfh)->JavaScriptDialogClosed(
3818 reply_msg, success, user_input, dialog_was_suppressed);
[email protected]beb440c2009-11-06 04:08:543819}
3820
[email protected]b172aee2012-04-10 17:05:263821void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213822 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123823 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103824}
[email protected]f45d2a72010-03-08 23:28:353825
[email protected]b172aee2012-04-10 17:05:263826void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103827 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443828 // Can be NULL during tests.
3829 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213830 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363831}
[email protected]9f76c1e2012-03-05 15:15:583832
[email protected]1ac10dca2013-08-20 20:47:043833bool WebContentsImpl::IsHidden() {
3834 return capturer_count_ == 0 && !should_normally_be_visible_;
3835}
3836
[email protected]b0936d22013-11-28 06:47:363837RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213838 return frame_tree_.root()->render_manager();
3839}
3840
[email protected]b172aee2012-04-10 17:05:263841RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583842 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3843}
[email protected]7900bfdb2012-05-24 19:31:243844
[email protected]f8497342013-02-05 22:15:023845BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393846 return browser_plugin_guest_.get();
3847}
3848
[email protected]738f57a2013-06-29 21:06:543849void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3850 CHECK(!browser_plugin_guest_);
3851 browser_plugin_guest_.reset(guest);
3852}
3853
[email protected]f8497342013-02-05 22:15:023854BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393855 return browser_plugin_embedder_.get();
3856}
[email protected]8ff00d72012-10-23 19:12:213857
[email protected]8eb04562013-03-06 03:41:143858BrowserPluginGuestManager*
3859 WebContentsImpl::GetBrowserPluginGuestManager() const {
3860 return static_cast<BrowserPluginGuestManager*>(
3861 GetBrowserContext()->GetUserData(
3862 browser_plugin::kBrowserPluginGuestManagerKeyName));
3863}
3864
[email protected]d9030b82013-07-19 08:26:063865void WebContentsImpl::ClearPowerSaveBlockers(
3866 RenderViewHost* render_view_host) {
3867 STLDeleteValues(&power_save_blockers_[render_view_host]);
3868 power_save_blockers_.erase(render_view_host);
3869}
3870
3871void WebContentsImpl::ClearAllPowerSaveBlockers() {
3872 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3873 i != power_save_blockers_.end(); ++i)
3874 STLDeleteValues(&power_save_blockers_[i->first]);
3875 power_save_blockers_.clear();
3876}
3877
[email protected]dc0fd432013-08-27 15:29:213878gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3879 gfx::Size size;
3880 if (delegate_)
3881 size = delegate_->GetSizeForNewRenderView(this);
3882 if (size.IsEmpty())
3883 size = view_->GetContainerSize();
3884 return size;
3885}
3886
[email protected]9b159a52013-10-03 17:24:553887void WebContentsImpl::OnFrameRemoved(
3888 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583889 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553890 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583891 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553892}
3893
[email protected]222f5822014-02-05 23:40:493894void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3895 if (!delegate_)
3896 return;
3897 const gfx::Size new_size = GetPreferredSize();
3898 if (new_size != old_size)
3899 delegate_->UpdatePreferredSize(this, new_size);
3900}
3901
[email protected]8ff00d72012-10-23 19:12:213902} // namespace content