blob: 623cb4639b966144f8a23a66edd1a010e1a72fe1 [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]da8543762012-03-20 08:52:2061#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4462#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3663#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1764#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1465#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4666#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1567#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0068#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2769#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0070#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3771#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1472#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3273#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3474#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3875#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4276#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2577#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1078#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2179#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4880#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5481#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4982#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2083#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0384#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5785#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1686#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2987#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5388#include "net/http/http_cache.h"
89#include "net/http/http_transaction_factory.h"
90#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3491#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5692#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0193#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4194#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5295#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1896#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3197
[email protected]583418cc2013-01-17 14:01:1098#if defined(OS_ANDROID)
99#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:32100#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]155c7f22013-12-09 17:07:18101#include "content/browser/web_contents/web_contents_android.h"
[email protected]a794f3a2013-10-30 17:00:32102#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:00103#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10104#endif
105
[email protected]f66df822012-05-18 16:52:17106#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50107#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27108#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57109#endif
[email protected]3e45ba92009-02-20 21:09:00110
[email protected]420ae012009-04-24 05:16:32111// Cross-Site Navigations
112//
[email protected]b172aee2012-04-10 17:05:26113// If a WebContentsImpl is told to navigate to a different web site (as
114// determined by SiteInstance), it will replace its current RenderViewHost with
115// a new RenderViewHost dedicated to the new SiteInstance. This works as
116// follows:
[email protected]420ae012009-04-24 05:16:32117//
[email protected]fc6c1872013-10-03 01:22:35118// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46119// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32120// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35121// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32122// run in the current RVH.
123// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35124// that it has a pending cross-site request. We will check this on the IO
125// thread when deciding how to handle the response.
126// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46127// cancel all the pending logic. Otherwise we allow the pending RVH to send
128// the navigation request to its renderer.
129// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35130// main resource load on the pending RVH. It creates a
131// CrossSiteResourceHandler to check whether a process swap is needed when
132// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46133// - When RDH receives a response, the BufferedResourceHandler determines
134// whether it is a download. If so, it sends a message to the new renderer
135// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26136// pending RVH remains until the next DidNavigate event for this
137// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32138// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35139// download, the CrossSiteResourceHandler checks whether a process swap is
140// needed (either because CrossSiteRequestManager has state for it or because
141// a transfer was needed for a redirect).
142// - If so, CrossSiteResourceHandler pauses the response to first run the old
143// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36144// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
145// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35146// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
147// to a new process is needed, based on the stored pending_nav_params_. (This
148// is independent of whether we started out with a cross-process navigation.)
149// - If not, it just tells the ResourceDispatcherHost to resume the response
150// to its current RenderViewHost.
151// - If so, it cancels the current pending RenderViewHost and sets up a new
152// navigation using RequestTransferURL. When the transferred request
153// arrives in the ResourceDispatcherHost, we transfer the response and
154// resume it.
[email protected]420ae012009-04-24 05:16:32155// - The pending renderer sends a FrameNavigate message that invokes the
156// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46157// pending RVH.
[email protected]b0936d22013-11-28 06:47:36158// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15159// the user goes back. The process only stays live if another tab is using
160// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32161
[email protected]8ff00d72012-10-23 19:12:21162namespace content {
[email protected]420ae012009-04-24 05:16:32163namespace {
164
[email protected]82114f52012-03-20 22:53:41165const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05166
[email protected]155c7f22013-12-09 17:07:18167#if defined(OS_ANDROID)
168const char kWebContentsAndroidKey[] = "web_contents_android";
169#endif // OS_ANDROID
170
[email protected]e4abd3b42013-11-12 18:28:47171base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46172g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
173
[email protected]988ed7132014-03-31 16:25:58174static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39175 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29176 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30177 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02178 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58179 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02180 ++g_next_image_download_id,
181 url,
182 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30183 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02184 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39185}
186
[email protected]8bfc8272013-09-09 20:10:53187void NotifyCacheOnIO(
188 scoped_refptr<net::URLRequestContextGetter> request_context,
189 const GURL& url,
190 const std::string& http_method) {
191 request_context->GetURLRequestContext()->http_transaction_factory()->
192 GetCache()->OnExternalCacheHit(url, http_method);
193}
194
[email protected]9b159a52013-10-03 17:24:55195// Helper function for retrieving all the sites in a frame tree.
196bool CollectSites(BrowserContext* context,
197 std::set<GURL>* sites,
198 FrameTreeNode* node) {
199 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
200 return true;
201}
202
[email protected]a86c0e962013-12-17 17:10:39203bool ForEachFrameInternal(
204 const base::Callback<void(RenderFrameHost*)>& on_frame,
205 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41206 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39207 return true;
208}
209
[email protected]c06c58c2014-03-12 20:31:59210bool ForEachPendingFrameInternal(
211 const base::Callback<void(RenderFrameHost*)>& on_frame,
212 FrameTreeNode* node) {
213 RenderFrameHost* pending_frame_host =
214 node->render_manager()->pending_frame_host();
215 if (pending_frame_host)
216 on_frame.Run(pending_frame_host);
217 return true;
218}
219
[email protected]a86c0e962013-12-17 17:10:39220void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
221 IPC::Message* message_copy = new IPC::Message(*message);
222 message_copy->set_routing_id(rfh->GetRoutingID());
223 rfh->Send(message_copy);
224}
225
[email protected]c06c58c2014-03-12 20:31:59226void RunRenderFrameDeleted(
227 ObserverList<WebContentsObserver>* observer_list,
228 RenderFrameHost* render_frame_host) {
229 FOR_EACH_OBSERVER(WebContentsObserver,
230 *observer_list,
231 RenderFrameDeleted(render_frame_host));
232}
233
[email protected]420ae012009-04-24 05:16:32234} // namespace
235
[email protected]54944cde2012-12-09 09:24:59236WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15237 return WebContentsImpl::CreateWithOpener(
238 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19239}
240
241WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59242 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30243 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59244 WebContentsImpl* new_contents = new WebContentsImpl(
245 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30246
247 for (SessionStorageNamespaceMap::const_iterator it =
248 session_storage_namespace_map.begin();
249 it != session_storage_namespace_map.end();
250 ++it) {
251 new_contents->GetController()
252 .SetSessionStorageNamespace(it->first, it->second.get());
253 }
254
[email protected]54944cde2012-12-09 09:24:59255 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19256 return new_contents;
[email protected]a81343d232011-12-27 07:39:20257}
[email protected]746d3052012-05-22 15:15:47258
[email protected]e4abd3b42013-11-12 18:28:47259void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46260 g_created_callbacks.Get().push_back(callback);
261}
262
[email protected]e4abd3b42013-11-12 18:28:47263void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46264 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
265 if (g_created_callbacks.Get().at(i).Equals(callback)) {
266 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
267 return;
268 }
269 }
270}
271
[email protected]299d7f12012-05-23 05:31:15272WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47273 return rvh->GetDelegate()->GetAsWebContents();
274}
275
[email protected]a86c0e962013-12-17 17:10:39276WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
277 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
278 if (!rfh_impl)
279 return NULL;
280 return rfh_impl->delegate()->GetAsWebContents();
281}
282
[email protected]7fff43e2013-05-21 20:21:10283// WebContentsImpl::DestructionObserver ----------------------------------------
284
285class WebContentsImpl::DestructionObserver : public WebContentsObserver {
286 public:
287 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
288 : WebContentsObserver(watched_contents),
289 owner_(owner) {
290 }
291
292 // WebContentsObserver:
293 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
294 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
295 }
296
297 private:
298 WebContentsImpl* owner_;
299
300 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
301};
302
[email protected]b172aee2012-04-10 17:05:26303// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32304
[email protected]b172aee2012-04-10 17:05:26305WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21306 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19307 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42308 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22309 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57310 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44311 opener_(opener),
[email protected]2ceee8f2014-01-14 18:02:08312#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41313 accessible_parent_(NULL),
314#endif
[email protected]6ea6bdf2013-12-06 13:35:01315 frame_tree_(new NavigatorImpl(&controller_, this),
316 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34317 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23318 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
319 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34320 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26321 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56322 upload_size_(0),
323 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47324 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55325 capturer_count_(0),
326 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57327 is_being_destroyed_(false),
328 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15329 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01330 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02331 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38332 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21333 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
334 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00335 temporary_zoom_settings_(false),
[email protected]bab38af2014-03-30 17:37:29336 totalPinchGestureAmount_(0),
337 currentPinchZoomStepDelta_(0),
[email protected]cb805452013-05-22 15:16:21338 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44339 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42340 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
341 is_subframe_(false) {
[email protected]cbb1ef592013-06-05 19:49:46342 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
343 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55344 frame_tree_.SetFrameRemoveListener(
345 base::Bind(&WebContentsImpl::OnFrameRemoved,
346 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35347}
initial.commit09911bf2008-07-26 23:55:29348
[email protected]b172aee2012-04-10 17:05:26349WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32350 is_being_destroyed_ = true;
351
[email protected]21b41c7e892014-02-28 01:52:24352 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
353 // shutdown and be deleted as well.
354 frame_tree_.ForEach(
355 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
356
[email protected]d9030b82013-07-19 08:26:06357 ClearAllPowerSaveBlockers();
358
[email protected]b24b68a2012-09-24 21:57:26359 for (std::set<RenderWidgetHostImpl*>::iterator iter =
360 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
361 (*iter)->DetachDelegate();
362 }
363 created_widgets_.clear();
364
[email protected]3ab9cb82011-06-03 18:02:07365 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15366 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11367 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07368
[email protected]da8543762012-03-20 08:52:20369 if (color_chooser_)
370 color_chooser_->End();
371
[email protected]420ae012009-04-24 05:16:32372 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32373
[email protected]ca13a442012-04-17 14:00:12374 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21375 NotificationService::current()->Notify(
376 NOTIFICATION_WEB_CONTENTS_DESTROYED,
377 Source<WebContents>(this),
378 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32379
[email protected]c06c58c2014-03-12 20:31:59380 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
381 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
382 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
383 run_render_frame_deleted_callback));
384
[email protected]fa944cb82013-11-15 17:51:21385 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27386 if (pending_rvh) {
387 FOR_EACH_OBSERVER(WebContentsObserver,
388 observers_,
389 RenderViewDeleted(pending_rvh));
390 }
391
[email protected]c06c58c2014-03-12 20:31:59392 ForEachFrame(run_render_frame_deleted_callback);
393
[email protected]f273ee52013-10-18 16:05:27394 FOR_EACH_OBSERVER(WebContentsObserver,
395 observers_,
[email protected]fa944cb82013-11-15 17:51:21396 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27397
[email protected]2db9bd72012-04-13 20:20:56398 FOR_EACH_OBSERVER(WebContentsObserver,
399 observers_,
400 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08401
[email protected]6934a702011-12-20 00:04:51402 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10403
404 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
405 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42406}
407
[email protected]d1198fd2012-08-13 22:50:19408WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59409 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19410 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03411 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59412 WebContentsImpl* new_contents = new WebContentsImpl(
413 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19414
[email protected]54944cde2012-12-09 09:24:59415 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19416 return new_contents;
417}
418
[email protected]b371a5652013-02-20 11:25:51419// static
[email protected]8eb04562013-03-06 03:41:14420BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36421 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53422 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54423 int guest_instance_id,
424 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39425 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39426
427 // This makes |new_contents| act as a guest.
428 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54429 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19430 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11431
[email protected]3de10bb32013-01-08 21:57:33432 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33433 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11434
[email protected]216be772013-01-25 00:22:27435 // We are instantiating a WebContents for browser plugin. Set its subframe bit
436 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42437 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27438
[email protected]8eb04562013-03-06 03:41:14439 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39440}
441
[email protected]b0936d22013-11-28 06:47:36442RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21443 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28444}
445
[email protected]7bb761892012-07-20 09:32:47446bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
447 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44448 return OnMessageReceived(render_view_host, NULL, message);
449}
450
451bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
452 RenderFrameHost* render_frame_host,
453 const IPC::Message& message) {
454 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56455 if (GetWebUI() &&
456 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17457 return true;
[email protected]d2353452012-01-19 19:53:56458 }
[email protected]f82d57b52011-04-27 19:13:17459
[email protected]d8c660432011-12-22 20:51:25460 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
461 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10462 while ((observer = it.GetNext()) != NULL)
463 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53464 return true;
[email protected]403415a2011-01-10 18:57:53465
[email protected]1d62cf72014-02-07 21:31:57466 // Message handlers should be aware of which
467 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
468 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43469 if (render_frame_host) {
470 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
471 render_frame_host->GetRenderViewHost(), message))
472 return true;
[email protected]1d62cf72014-02-07 21:31:57473 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43474 } else {
475 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
476 render_view_host, message))
477 return true;
[email protected]1d62cf72014-02-07 21:31:57478 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43479 }
[email protected]1d62cf72014-02-07 21:31:57480
[email protected]724159a2010-12-30 01:11:18481 bool handled = true;
482 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26483 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44484 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
485 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40486 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
487 OnDomOperationResponse)
[email protected]724159a2010-12-30 01:11:18488 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
489 OnDidLoadResourceFromMemoryCache)
490 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
491 OnDidDisplayInsecureContent)
492 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
493 OnDidRunInsecureContent)
[email protected]1d62cf72014-02-07 21:31:57494 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
[email protected]724159a2010-12-30 01:11:18495 OnDocumentLoadedInFrame)
[email protected]028053d42014-03-05 22:20:37496 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]7d472472011-01-22 01:30:25497 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26498 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21499 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20500 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
501 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16502 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10503 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20504 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
505 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
506 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
507 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50508 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50509 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
510 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55511 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
512 OnBrowserPluginMessage(message))
513 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
514 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02515 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
516 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10517#if defined(OS_ANDROID)
518 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
519 OnFindMatchRectsReply)
520 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
521 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32522 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
523 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10524#endif
[email protected]1dd0bb752014-02-01 01:16:26525 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
526 OnMediaPlayingNotification)
527 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
528 OnMediaPausedNotification)
[email protected]9f268072013-11-07 00:02:15529 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
530 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07531 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
532 OnShowValidationMessage)
533 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
534 OnHideValidationMessage)
535 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
536 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18537 IPC_MESSAGE_UNHANDLED(handled = false)
538 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44539 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57540 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18541
542 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39543 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18544 GetRenderProcessHost()->ReceivedBadMessage();
545 }
546
547 return handled;
548}
549
[email protected]b172aee2012-04-10 17:05:26550void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18551 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21552 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43553 if (delegate_)
554 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18555}
556
[email protected]d1198fd2012-08-13 22:50:19557NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56558 return controller_;
559}
560
[email protected]d1198fd2012-08-13 22:50:19561const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56562 return controller_;
563}
564
[email protected]8ff00d72012-10-23 19:12:21565BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55566 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30567}
568
[email protected]b172aee2012-04-10 17:05:26569const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24570 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32571 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51572 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31573}
574
[email protected]a093ce02013-07-22 20:53:14575const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24576 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32577 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24578 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
579}
580
581const GURL& WebContentsImpl::GetLastCommittedURL() const {
582 // We may not have a navigation entry yet.
583 NavigationEntry* entry = controller_.GetLastCommittedEntry();
584 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
585}
586
[email protected]8ff00d72012-10-23 19:12:21587WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31588 return delegate_;
589}
590
[email protected]8ff00d72012-10-23 19:12:21591void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31592 // TODO(cbentzel): remove this debugging code?
593 if (delegate == delegate_)
594 return;
595 if (delegate_)
596 delegate_->Detach(this);
597 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08598 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31599 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08600 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00601 if (view_)
602 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08603 }
[email protected]be1f56ab2011-12-22 06:55:31604}
605
[email protected]8ff00d72012-10-23 19:12:21606RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21607 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41608 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16609}
610
[email protected]60eca4eb2013-12-06 00:02:16611RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41612 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16613}
614
[email protected]9c9343b2014-03-08 02:56:07615RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
616 if (!frame_tree_.GetFocusedFrame())
617 return NULL;
618 return frame_tree_.GetFocusedFrame()->current_frame_host();
619}
620
[email protected]a86c0e962013-12-17 17:10:39621void WebContentsImpl::ForEachFrame(
622 const base::Callback<void(RenderFrameHost*)>& on_frame) {
623 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
624}
625
626void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
627 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
628 delete message;
629}
630
[email protected]b172aee2012-04-10 17:05:26631RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21632 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31633}
634
[email protected]bfcfa692013-02-07 06:17:02635WebContents* WebContentsImpl::GetEmbedderWebContents() const {
636 BrowserPluginGuest* guest = GetBrowserPluginGuest();
637 if (guest)
638 return guest->embedder_web_contents();
639 return NULL;
640}
641
642int WebContentsImpl::GetEmbeddedInstanceID() const {
643 BrowserPluginGuest* guest = GetBrowserPluginGuest();
644 if (guest)
645 return guest->instance_id();
646 return 0;
647}
648
[email protected]6b618e62012-08-16 12:59:18649int WebContentsImpl::GetRoutingID() const {
650 if (!GetRenderViewHost())
651 return MSG_ROUTING_NONE;
652
653 return GetRenderViewHost()->GetRoutingID();
654}
655
[email protected]44470a22013-01-24 01:21:54656int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
657 return fullscreen_widget_routing_id_;
658}
659
[email protected]b172aee2012-04-10 17:05:26660RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21661 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31662}
663
[email protected]f8497342013-02-05 22:15:02664RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
665 BrowserPluginGuest* guest = GetBrowserPluginGuest();
666 if (guest && guest->embedder_web_contents()) {
667 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
668 }
669 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
670}
671
[email protected]4aebbca2013-09-17 22:26:49672RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
673 const {
674 RenderWidgetHost* const widget_host =
675 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
676 GetFullscreenWidgetRoutingID());
677 return widget_host ? widget_host->GetView() : NULL;
678}
679
[email protected]8ff00d72012-10-23 19:12:21680WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31681 return view_.get();
682}
683
[email protected]8ff00d72012-10-23 19:12:21684WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56685 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03686 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
687 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22688 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58689 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22690 web_ui->SetController(controller);
691 return web_ui;
692 }
693
694 delete web_ui;
695 return NULL;
696}
697
[email protected]8ff00d72012-10-23 19:12:21698WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21699 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
700 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31701}
702
[email protected]8ff00d72012-10-23 19:12:21703WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21704 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34705}
706
[email protected]86ef6a392012-05-11 22:03:11707void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22708 if (GetUserAgentOverride() == override)
709 return;
710
711 renderer_preferences_.user_agent_override = override;
712
713 // Send the new override string to the renderer.
714 RenderViewHost* host = GetRenderViewHost();
715 if (host)
716 host->SyncRendererPrefs();
717
718 // Reload the page if a load is currently in progress to avoid having
719 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27720 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22721 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
722 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53723
724 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
725 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11726}
727
728const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22729 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11730}
731
[email protected]2ceee8f2014-01-14 18:02:08732#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41733void WebContentsImpl::SetParentNativeViewAccessible(
734gfx::NativeViewAccessible accessible_parent) {
735 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45736 if (GetRenderViewHost())
737 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41738}
739#endif
740
[email protected]fcf75d42013-12-03 20:11:26741const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55742 // Transient entries take precedence. They are used for interstitial pages
743 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23744 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08745 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21746 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30747 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23748 if (entry) {
[email protected]b5cca982011-05-26 04:42:08749 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23750 }
[email protected]fa944cb82013-11-15 17:51:21751 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
752 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58753 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54754 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32755 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54756 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35757 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26758 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54759 if (!title.empty())
760 return title;
761 }
762 }
763
764 // We use the title for the last committed entry rather than a pending
765 // navigation entry. For example, when the user types in a URL, we want to
766 // keep the old page's title until the new load has committed and we get a new
767 // title.
[email protected]96d185d2009-04-24 03:28:54768 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32769
[email protected]9eeafc012013-11-25 23:49:47770 // We make an exception for initial navigations.
771 if (controller_.IsInitialNavigation()) {
772 // We only want to use the title from the visible entry in one of two cases:
773 // 1. There's already a committed entry for an initial navigation, in which
774 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
775 // 2. The pending entry has been explicitly assigned a title to display.
776 //
777 // If there's no last committed entry and no assigned title, we should fall
778 // back to |page_title_when_no_navigation_entry_| rather than showing the
779 // URL.
780 if (entry ||
781 (controller_.GetVisibleEntry() &&
782 !controller_.GetVisibleEntry()->GetTitle().empty())) {
783 entry = controller_.GetVisibleEntry();
784 }
785 }
[email protected]59167c22013-06-03 18:07:32786
[email protected]45d0ef7f2011-01-05 13:46:23787 if (entry) {
[email protected]b5cca982011-05-26 04:42:08788 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23789 }
[email protected]987fc3a2011-05-26 14:18:09790
791 // |page_title_when_no_navigation_entry_| is finally used
792 // if no title cannot be retrieved.
793 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54794}
795
[email protected]b172aee2012-04-10 17:05:26796int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46797 return GetMaxPageIDForSiteInstance(GetSiteInstance());
798}
799
[email protected]b172aee2012-04-10 17:05:26800int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
801 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33802 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
803 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46804
[email protected]b6583592012-01-25 19:52:33805 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34806}
807
[email protected]b172aee2012-04-10 17:05:26808void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46809 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
810}
811
[email protected]b172aee2012-04-10 17:05:26812void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33813 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46814 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33815 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34816}
817
[email protected]ec6c05f2013-10-23 18:41:57818void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
819 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
820 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57821}
822
[email protected]b172aee2012-04-10 17:05:26823SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21824 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54825}
826
[email protected]b172aee2012-04-10 17:05:26827SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21828 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
829 GetRenderManager()->pending_render_view_host() :
830 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58831 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38832}
833
[email protected]b172aee2012-04-10 17:05:26834bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31835 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49836}
837
[email protected]b172aee2012-04-10 17:05:26838bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31839 return waiting_for_response_;
840}
841
[email protected]b172aee2012-04-10 17:05:26842const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31843 return load_state_;
844}
845
[email protected]fcf75d42013-12-03 20:11:26846const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31847 return load_state_host_;
848}
849
[email protected]b172aee2012-04-10 17:05:26850uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31851 return upload_size_;
852}
853
[email protected]b172aee2012-04-10 17:05:26854uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31855 return upload_position_;
856}
857
[email protected]1ae93fb2013-06-14 03:38:56858std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56859 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39860 frame_tree_.ForEach(base::Bind(&CollectSites,
861 base::Unretained(GetBrowserContext()),
862 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56863 return sites;
864}
865
[email protected]b172aee2012-04-10 17:05:26866const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31867 return encoding_;
868}
869
[email protected]b172aee2012-04-10 17:05:26870bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31871 return displayed_insecure_content_;
872}
873
[email protected]222f5822014-02-05 23:40:49874void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25875 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55876 ++capturer_count_;
877 DVLOG(1) << "There are now " << capturer_count_
878 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49879
880 // Note: This provides a hint to upstream code to size the views optimally
881 // for quality (e.g., to avoid scaling).
882 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
883 preferred_size_for_capture_ = capture_size;
884 OnPreferredSizeChanged(preferred_size_);
885 }
[email protected]54597982013-02-06 01:59:55886}
887
888void WebContentsImpl::DecrementCapturerCount() {
889 --capturer_count_;
890 DVLOG(1) << "There are now " << capturer_count_
891 << " capturing(s) of WebContentsImpl@" << this;
892 DCHECK_LE(0, capturer_count_);
893
[email protected]5a652232013-02-12 06:15:25894 if (is_being_destroyed_)
895 return;
896
[email protected]222f5822014-02-05 23:40:49897 if (capturer_count_ == 0) {
898 const gfx::Size old_size = preferred_size_for_capture_;
899 preferred_size_for_capture_ = gfx::Size();
900 OnPreferredSizeChanged(old_size);
901 }
902
[email protected]1ac10dca2013-08-20 20:47:04903 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55904 DVLOG(1) << "Executing delayed WasHidden().";
905 WasHidden();
906 }
[email protected]be1f56ab2011-12-22 06:55:31907}
908
[email protected]f2bd40812013-07-20 04:30:44909int WebContentsImpl::GetCapturerCount() const {
910 return capturer_count_;
911}
912
[email protected]b172aee2012-04-10 17:05:26913bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31914 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
915 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
916 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49917}
918
[email protected]b172aee2012-04-10 17:05:26919void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
920 int error_code) {
[email protected]443b80e2010-12-14 00:42:23921 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34922 return;
923
[email protected]443b80e2010-12-14 00:42:23924 crashed_status_ = status;
925 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21926 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34927}
928
[email protected]b172aee2012-04-10 17:05:26929base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31930 return crashed_status_;
931}
932
[email protected]b172aee2012-04-10 17:05:26933bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31934 return is_being_destroyed_;
935}
936
[email protected]b172aee2012-04-10 17:05:26937void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34938 if (delegate_)
939 delegate_->NavigationStateChanged(this, changed_flags);
940}
941
[email protected]9a890452014-02-13 22:21:02942base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
943 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33944}
945
[email protected]9e2e4632012-07-27 16:38:41946void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54947 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04948 RenderWidgetHostViewPort* rwhv =
949 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16950 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29951 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43952#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16953 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43954#endif
955 }
[email protected]96d185d2009-04-24 03:28:54956
[email protected]9a890452014-02-13 22:21:02957 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38958
[email protected]b9769d82012-02-10 00:23:59959 // The resize rect might have changed while this was inactive -- send the new
960 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58961 RenderViewHostImpl* rvh =
962 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59963 if (rvh) {
964 rvh->ResizeRectChanged(GetRootWindowResizerRect());
965 }
[email protected]96d185d2009-04-24 03:28:54966
[email protected]c0d9d5672013-10-09 07:38:03967 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
968
[email protected]54597982013-02-06 01:59:55969 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31970}
971
[email protected]b172aee2012-04-10 17:05:26972void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55973 // If there are entities capturing screenshots or video (e.g., mirroring),
974 // don't activate the "disable rendering" optimization.
975 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52976 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55977 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26978 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52979 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33980 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52981 // calls us).
[email protected]c30585c2012-02-16 15:02:04982 RenderWidgetHostViewPort* rwhv =
983 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16984 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29985 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54986 }
987
[email protected]c0d9d5672013-10-09 07:38:03988 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
989
[email protected]54597982013-02-06 01:59:55990 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37991}
992
[email protected]b172aee2012-04-10 17:05:26993bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31994 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27995 return WillNotifyDisconnection() &&
996 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58997 !static_cast<RenderViewHostImpl*>(
998 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31999}
1000
[email protected]b172aee2012-04-10 17:05:261001void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211002 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401003 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271004}
1005
[email protected]b172aee2012-04-10 17:05:261006WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441007 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451008 // We pass our own opener so that the cloned page can access it if it was
1009 // before.
[email protected]54944cde2012-12-09 09:24:591010 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451011 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591012 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191013 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221014 FOR_EACH_OBSERVER(WebContentsObserver,
1015 observers_,
1016 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271017 return tc;
1018}
1019
[email protected]14392a52012-05-02 20:28:441020void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211021 const NotificationSource& source,
1022 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441023 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211024 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1025 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501026 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1027 i != pending_widget_views_.end(); ++i) {
1028 if (host->GetView() == i->second) {
1029 pending_widget_views_.erase(i);
1030 break;
1031 }
1032 }
1033 break;
1034 }
[email protected]14392a52012-05-02 20:28:441035 default:
1036 NOTREACHED();
1037 }
1038}
1039
[email protected]ec6c05f2013-10-23 18:41:571040WebContents* WebContentsImpl::GetWebContents() {
1041 return this;
1042}
1043
[email protected]54944cde2012-12-09 09:24:591044void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211045 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361046 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211047 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431048 should_normally_be_visible_ = !params.initially_hidden;
1049
[email protected]fa944cb82013-11-15 17:51:211050 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041051 params.browser_context, params.site_instance, params.routing_id,
1052 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191053
[email protected]8ff00d72012-10-23 19:12:211054 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191055 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271056 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191057 CHECK(render_view_host_delegate_view_);
1058 } else {
[email protected]f8497342013-02-05 22:15:021059 WebContentsViewDelegate* delegate =
1060 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1061
[email protected]59383c782013-04-17 16:43:271062 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381063 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1064 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021065
[email protected]b5a40842012-11-28 15:26:111066 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381067 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431068 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111069 render_view_host_delegate_view_ = rv;
1070 view_.reset(rv);
1071 } else {
[email protected]f8497342013-02-05 22:15:021072 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111073 view_.reset(CreateWebContentsView(
1074 this, delegate, &render_view_host_delegate_view_));
1075 }
[email protected]d1198fd2012-08-13 22:50:191076 CHECK(render_view_host_delegate_view_);
1077 }
1078 CHECK(view_.get());
1079
[email protected]ed245db2012-12-18 08:00:451080 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591081 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191082
1083 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101084 if (opener_)
1085 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191086
1087 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211088 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1089 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441090#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191091 java_bridge_dispatcher_host_manager_.reset(
1092 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101093 date_time_chooser_.reset(new DateTimeChooserAndroid());
1094#endif
[email protected]d1198fd2012-08-13 22:50:191095}
1096
[email protected]7fff43e2013-05-21 20:21:101097void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1098 RemoveDestructionObserver(web_contents);
1099
[email protected]14392a52012-05-02 20:28:441100 // Clear the opener if it has been closed.
1101 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441102 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511103 return;
[email protected]14392a52012-05-02 20:28:441104 }
[email protected]ceee8cd2013-03-08 04:59:511105 // Clear a pending contents that has been closed before being shown.
1106 for (PendingContents::iterator iter = pending_contents_.begin();
1107 iter != pending_contents_.end();
1108 ++iter) {
1109 if (iter->second != web_contents)
1110 continue;
1111 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511112 return;
1113 }
1114 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441115}
1116
[email protected]7fff43e2013-05-21 20:21:101117void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1118 if (!ContainsKey(destruction_observers_, web_contents)) {
1119 destruction_observers_[web_contents] =
1120 new DestructionObserver(this, web_contents);
1121 }
1122}
1123
1124void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1125 DestructionObservers::iterator iter =
1126 destruction_observers_.find(web_contents);
1127 if (iter != destruction_observers_.end()) {
1128 delete destruction_observers_[web_contents];
1129 destruction_observers_.erase(iter);
1130 }
1131}
1132
[email protected]b172aee2012-04-10 17:05:261133void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311134 observers_.AddObserver(observer);
1135}
1136
[email protected]b172aee2012-04-10 17:05:261137void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311138 observers_.RemoveObserver(observer);
1139}
1140
[email protected]b172aee2012-04-10 17:05:261141void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341142 if (delegate_)
1143 delegate_->ActivateContents(this);
1144}
1145
[email protected]b172aee2012-04-10 17:05:261146void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121147 if (delegate_)
1148 delegate_->DeactivateContents(this);
1149}
1150
[email protected]b172aee2012-04-10 17:05:261151void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481152 if (delegate_)
1153 delegate_->LostCapture();
1154}
1155
[email protected]b24b68a2012-09-24 21:57:261156void WebContentsImpl::RenderWidgetDeleted(
1157 RenderWidgetHostImpl* render_widget_host) {
1158 if (is_being_destroyed_) {
1159 // |created_widgets_| might have been destroyed.
1160 return;
1161 }
1162
1163 std::set<RenderWidgetHostImpl*>::iterator iter =
1164 created_widgets_.find(render_widget_host);
1165 if (iter != created_widgets_.end())
1166 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541167
1168 if (render_widget_host &&
1169 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491170 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1171 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541172 FOR_EACH_OBSERVER(WebContentsObserver,
1173 observers_,
1174 DidDestroyFullscreenWidget(
1175 fullscreen_widget_routing_id_));
1176 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1177 }
[email protected]b24b68a2012-09-24 21:57:261178}
1179
[email protected]b172aee2012-04-10 17:05:261180bool WebContentsImpl::PreHandleKeyboardEvent(
1181 const NativeWebKeyboardEvent& event,
1182 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481183 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131184 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481185}
1186
[email protected]b172aee2012-04-10 17:05:261187void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061188 if (browser_plugin_embedder_ &&
1189 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1190 return;
1191 }
1192
[email protected]63954792011-07-11 04:17:481193 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131194 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481195}
1196
[email protected]d92026ef2014-03-03 21:04:131197bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461198 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191199#if !defined(OS_MACOSX)
1200 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1201 // isn't done for two reasons:
1202 // -the OS already has a gesture to do this through pinch-zoom
1203 // -if a user starts an inertial scroll, let's go, and presses control
1204 // (i.e. control+tab) then the OS's buffered scroll events will come in
1205 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521206 if (delegate_ &&
1207 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461208 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521209 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1210 return true;
1211 }
[email protected]bccc4472013-04-18 16:37:191212#endif
[email protected]fb3f066e2013-02-12 19:12:521213 return false;
1214}
1215
[email protected]04bce562014-01-30 05:34:541216bool WebContentsImpl::PreHandleGestureEvent(
1217 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031218 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541219}
1220
[email protected]bab38af2014-03-30 17:37:291221bool WebContentsImpl::HandleGestureEvent(
1222 const blink::WebGestureEvent& event) {
1223 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1224 // Use them to implement browser zoom, as for HandleWheelEvent above.
1225 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1226 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1227 // The scale difference necessary to trigger a zoom action. Derived from
1228 // experimentation to find a value that feels reasonable.
1229 const float kZoomStepValue = 0.6f;
1230
1231 // Find the (absolute) thresholds on either side of the current zoom factor,
1232 // then convert those to actual numbers to trigger a zoom in or out.
1233 // This logic deliberately makes the range around the starting zoom value
1234 // for the gesture twice as large as the other ranges (i.e., the notches are
1235 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1236 // so that it's easier to get back to your starting point than it is to
1237 // overshoot.
1238 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1239 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1240 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1241 : -backStep;
1242 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1243 : backStep;
1244
1245 totalPinchGestureAmount_ += event.data.pinchUpdate.scale;
1246 if (totalPinchGestureAmount_ > zoomInThreshold) {
1247 currentPinchZoomStepDelta_++;
1248 delegate_->ContentsZoomChange(true);
1249 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1250 currentPinchZoomStepDelta_--;
1251 delegate_->ContentsZoomChange(false);
1252 }
1253 return true;
1254 }
1255
1256 return false;
1257}
1258
[email protected]2ceee8f2014-01-14 18:02:081259#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411260gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1261 return accessible_parent_;
1262}
1263#endif
1264
[email protected]b172aee2012-04-10 17:05:261265void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431266 if (delegate_)
1267 delegate_->HandleMouseDown();
1268}
1269
[email protected]b172aee2012-04-10 17:05:261270void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481271 if (delegate_)
1272 delegate_->HandleMouseUp();
1273}
1274
[email protected]590a634e2012-07-19 16:38:231275void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481276 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231277 delegate_->HandlePointerActivate();
1278}
1279
1280void WebContentsImpl::HandleGestureBegin() {
1281 if (delegate_)
1282 delegate_->HandleGestureBegin();
1283}
1284
1285void WebContentsImpl::HandleGestureEnd() {
1286 if (delegate_)
1287 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481288}
1289
[email protected]b172aee2012-04-10 17:05:261290void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491291 // This method is being called to enter or leave renderer-initiated fullscreen
1292 // mode. Either way, make sure any existing fullscreen widget is shut down
1293 // first.
1294 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1295 if (widget_view)
1296 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1297
[email protected]8a5e0ca2011-08-25 06:30:471298 if (delegate_)
1299 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371300
1301 FOR_EACH_OBSERVER(WebContentsObserver,
1302 observers_,
1303 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471304}
1305
[email protected]b172aee2012-04-10 17:05:261306bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381307 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121308}
1309
[email protected]a9c81f02012-06-01 00:15:441310void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1311 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371312 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441313 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371314 } else {
1315 GotResponseToLockMouseRequest(false);
1316 }
1317}
1318
[email protected]b172aee2012-04-10 17:05:261319void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371320 if (delegate_)
1321 delegate_->LostMouseLock();
1322}
1323
[email protected]bafe6cd2012-05-23 23:09:501324void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201325 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501326 int route_id,
[email protected]227692c52013-05-31 22:43:041327 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131328 const ViewHostMsg_CreateWindow_Params& params,
1329 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501330 // We usually create the new window in the same BrowsingInstance (group of
1331 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551332 // if the opener is being suppressed (in a non-guest), we create a new
1333 // SiteInstance in its own BrowsingInstance.
1334 bool is_guest = GetRenderProcessHost()->IsGuest();
1335
[email protected]04cbd3d2013-12-04 04:58:201336 // If the opener is to be suppressed, the new window can be in any process.
1337 // Since routing ids are process specific, we must not have one passed in
1338 // as argument here.
1339 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1340
[email protected]bafe6cd2012-05-23 23:09:501341 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551342 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571343 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501344 GetSiteInstance();
1345
[email protected]04cbd3d2013-12-04 04:58:201346 // A message to create a new window can only come from the active process for
1347 // this WebContentsImpl instance. If any other process sends the request,
1348 // it is invalid and the process must be terminated.
1349 if (GetRenderProcessHost()->GetID() != render_process_id) {
1350 base::ProcessHandle process_handle =
1351 RenderProcessHost::FromID(render_process_id)->GetHandle();
1352 if (process_handle != base::kNullProcessHandle) {
1353 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391354 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201355 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1356 }
1357 return;
1358 }
1359
[email protected]d1198fd2012-08-13 22:50:191360 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341361 //
1362 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301363 const std::string& partition_id =
1364 GetContentClient()->browser()->
1365 GetStoragePartitionIdForSite(GetBrowserContext(),
1366 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461367 StoragePartition* partition = BrowserContext::GetStoragePartition(
1368 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411369 DOMStorageContextWrapper* dom_storage_context =
1370 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191371 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1372 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1373 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371374
1375 if (delegate_ &&
1376 !delegate_->ShouldCreateWebContents(this,
1377 route_id,
1378 params.window_container_type,
1379 params.frame_name,
1380 params.target_url,
1381 partition_id,
1382 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011383 if (route_id != MSG_ROUTING_NONE &&
1384 !RenderViewHost::FromID(render_process_id, route_id)) {
1385 // If the embedder didn't create a WebContents for this route, we need to
1386 // delete the RenderView that had already been created.
1387 Send(new ViewMsg_Close(route_id));
1388 }
[email protected]dd6730412013-08-14 15:03:371389 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1390 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1391 main_frame_route_id);
1392 return;
1393 }
1394
1395 // Create the new web contents. This will automatically create the new
1396 // WebContentsView. In the future, we may want to create the view separately.
1397 WebContentsImpl* new_contents =
1398 new WebContentsImpl(GetBrowserContext(),
1399 params.opener_suppressed ? NULL : this);
1400
[email protected]d1198fd2012-08-13 22:50:191401 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301402 partition_id,
[email protected]d1198fd2012-08-13 22:50:191403 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461404 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591405 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041406 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551407 if (!is_guest) {
1408 create_params.context = view_->GetNativeView();
1409 create_params.initial_size = view_->GetContainerSize();
1410 } else {
1411 // This makes |new_contents| act as a guest.
1412 // For more info, see comment above class BrowserPluginGuest.
1413 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1414 WebContentsImpl* new_contents_impl =
1415 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461416 BrowserPluginGuest::CreateWithOpener(instance_id,
1417 new_contents_impl->opener() != NULL,
1418 new_contents_impl,
1419 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551420 }
[email protected]1ac10dca2013-08-20 20:47:041421 if (params.disposition == NEW_BACKGROUND_TAB)
1422 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591423 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191424
[email protected]c4538072013-03-18 02:17:551425 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341426 // will be shown immediately).
1427 if (!params.opener_suppressed) {
1428 if (!is_guest) {
1429 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501430
[email protected]d70bea92013-04-05 04:23:341431 // TODO(brettw): It seems bogus that we have to call this function on the
1432 // newly created object and give it one of its own member variables.
1433 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1434 }
[email protected]bafe6cd2012-05-23 23:09:501435 // Save the created window associated with the route so we can show it
1436 // later.
1437 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1438 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101439 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501440 }
1441
1442 if (delegate_) {
1443 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071444 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131445 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501446 }
1447
1448 if (params.opener_suppressed) {
1449 // When the opener is suppressed, the original renderer cannot access the
1450 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001451 bool was_blocked = false;
1452 if (delegate_) {
1453 gfx::Rect initial_pos;
1454 delegate_->AddNewContents(
1455 this, new_contents, params.disposition, initial_pos,
1456 params.user_gesture, &was_blocked);
1457 }
1458 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211459 OpenURLParams open_params(params.target_url,
1460 Referrer(),
1461 CURRENT_TAB,
1462 PAGE_TRANSITION_LINK,
1463 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301464 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001465 new_contents->OpenURL(open_params);
1466 }
[email protected]bafe6cd2012-05-23 23:09:501467 }
1468}
1469
[email protected]a8504022013-12-04 20:23:511470void WebContentsImpl::CreateNewWidget(int render_process_id,
1471 int route_id,
[email protected]180ef242013-11-07 06:50:461472 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511473 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501474}
1475
[email protected]a8504022013-12-04 20:23:511476void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1477 int route_id) {
1478 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501479}
1480
[email protected]a8504022013-12-04 20:23:511481void WebContentsImpl::CreateNewWidget(int render_process_id,
1482 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501483 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461484 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211485 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511486 // A message to create a new widget can only come from the active process for
1487 // this WebContentsImpl instance. If any other process sends the request,
1488 // it is invalid and the process must be terminated.
1489 if (process->GetID() != render_process_id) {
1490 base::ProcessHandle process_handle =
1491 RenderProcessHost::FromID(render_process_id)->GetHandle();
1492 if (process_handle != base::kNullProcessHandle) {
1493 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391494 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511495 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1496 }
1497 return;
1498 }
1499
[email protected]bafe6cd2012-05-23 23:09:501500 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041501 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261502 created_widgets_.insert(widget_host);
1503
[email protected]83918ec2013-01-10 15:37:191504 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1505 view_->CreateViewForPopupWidget(widget_host));
1506 if (!widget_view)
1507 return;
[email protected]bafe6cd2012-05-23 23:09:501508 if (!is_fullscreen) {
1509 // Popups should not get activated.
1510 widget_view->SetPopupType(popup_type);
1511 }
1512 // Save the created widget associated with the route so we can show it later.
1513 pending_widget_views_[route_id] = widget_view;
1514
1515#if defined(OS_MACOSX)
1516 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1517 // to allow it to survive the trip without being hosted.
1518 base::mac::NSObjectRetain(widget_view->GetNativeView());
1519#endif
1520}
1521
1522void WebContentsImpl::ShowCreatedWindow(int route_id,
1523 WindowOpenDisposition disposition,
1524 const gfx::Rect& initial_pos,
1525 bool user_gesture) {
1526 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001527 if (contents) {
1528 WebContentsDelegate* delegate = GetDelegate();
1529 if (delegate) {
1530 delegate->AddNewContents(
1531 this, contents, disposition, initial_pos, user_gesture, NULL);
1532 }
1533 }
[email protected]bafe6cd2012-05-23 23:09:501534}
1535
1536void WebContentsImpl::ShowCreatedWidget(int route_id,
1537 const gfx::Rect& initial_pos) {
1538 ShowCreatedWidget(route_id, false, initial_pos);
1539}
1540
1541void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1542 ShowCreatedWidget(route_id, true, gfx::Rect());
1543}
1544
1545void WebContentsImpl::ShowCreatedWidget(int route_id,
1546 bool is_fullscreen,
1547 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501548 RenderWidgetHostViewPort* widget_host_view =
1549 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1550 if (!widget_host_view)
1551 return;
[email protected]4aebbca2013-09-17 22:26:491552 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311553 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1554 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491555 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1556 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1557 delegate_->ToggleFullscreenModeForTab(this, true);
1558 } else {
1559 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491560 }
[email protected]4aebbca2013-09-17 22:26:491561 FOR_EACH_OBSERVER(WebContentsObserver,
1562 observers_,
1563 DidShowFullscreenWidget(route_id));
1564 if (!widget_host_view->HasFocus())
1565 widget_host_view->Focus();
1566 } else {
[email protected]f8497342013-02-05 22:15:021567 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491568 }
[email protected]89054502012-06-03 10:29:241569
1570 RenderWidgetHostImpl* render_widget_host_impl =
1571 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1572 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311573 // Only allow privileged mouse lock for fullscreen render widget, which is
1574 // used to implement Pepper Flash fullscreen.
1575 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501576
1577#if defined(OS_MACOSX)
1578 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1579 // properly embedded (or purposefully ignored) we can release the retain we
1580 // took in CreateNewWidget().
1581 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1582#endif
1583}
1584
1585WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1586 PendingContents::iterator iter = pending_contents_.find(route_id);
1587
1588 // Certain systems can block the creation of new windows. If we didn't succeed
1589 // in creating one, just return NULL.
1590 if (iter == pending_contents_.end()) {
1591 return NULL;
1592 }
1593
1594 WebContentsImpl* new_contents = iter->second;
1595 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101596 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501597
[email protected]d70bea92013-04-05 04:23:341598 // Don't initialize the guest WebContents immediately.
1599 if (new_contents->GetRenderProcessHost()->IsGuest())
1600 return new_contents;
1601
[email protected]bafe6cd2012-05-23 23:09:501602 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1603 !new_contents->GetRenderViewHost()->GetView())
1604 return NULL;
1605
1606 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1607 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1608 return new_contents;
1609}
1610
1611RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1612 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1613 if (iter == pending_widget_views_.end()) {
1614 DCHECK(false);
1615 return NULL;
1616 }
1617
1618 RenderWidgetHostView* widget_host_view = iter->second;
1619 pending_widget_views_.erase(route_id);
1620
1621 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1622 if (!widget_host->GetProcess()->HasConnection()) {
1623 // The view has gone away or the renderer crashed. Nothing to do.
1624 return NULL;
1625 }
1626
1627 return widget_host_view;
1628}
1629
[email protected]f13b4202012-06-12 23:53:231630void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091631 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211632 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371633 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231634 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371635 } else {
1636 callback.Run(MediaStreamDevices(),
1637 MEDIA_DEVICE_INVALID_STATE,
1638 scoped_ptr<MediaStreamUI>());
1639 }
[email protected]f13b4202012-06-12 23:53:231640}
1641
[email protected]cc9200432013-07-23 23:02:401642SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1643 SiteInstance* instance) {
1644 return controller_.GetSessionStorageNamespace(instance);
1645}
1646
[email protected]9b159a52013-10-03 17:24:551647FrameTree* WebContentsImpl::GetFrameTree() {
1648 return &frame_tree_;
1649}
1650
[email protected]31a71eaf2014-03-13 01:47:361651void WebContentsImpl::AccessibilityEventReceived(
1652 const std::vector<AXEventNotificationDetails>& details) {
1653 FOR_EACH_OBSERVER(
1654 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1655}
1656
[email protected]edc3af82013-12-12 21:24:071657void WebContentsImpl::OnShowValidationMessage(
1658 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291659 const base::string16& main_text,
1660 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071661 if (delegate_)
1662 delegate_->ShowValidationMessage(
1663 this, anchor_in_root_view, main_text, sub_text);
1664}
1665
1666void WebContentsImpl::OnHideValidationMessage() {
1667 if (delegate_)
1668 delegate_->HideValidationMessage(this);
1669}
1670
1671void WebContentsImpl::OnMoveValidationMessage(
1672 const gfx::Rect& anchor_in_root_view) {
1673 if (delegate_)
1674 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1675}
1676
[email protected]32deec62013-05-15 23:55:041677void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1678 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441679 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041680}
1681
[email protected]b172aee2012-04-10 17:05:261682void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491683 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231684 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491685 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331686}
1687
[email protected]b172aee2012-04-10 17:05:261688void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341689 if (delegate_)
1690 delegate_->ResizeDueToAutoResize(this, new_size);
1691}
1692
[email protected]b172aee2012-04-10 17:05:261693WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201694 if (!delegate_)
1695 return NULL;
[email protected]00c37fc2011-08-02 00:22:501696
[email protected]e5d549d2011-12-28 01:29:201697 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201698 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341699}
1700
[email protected]6b618e62012-08-16 12:59:181701bool WebContentsImpl::Send(IPC::Message* message) {
1702 if (!GetRenderViewHost()) {
1703 delete message;
1704 return false;
1705 }
1706
1707 return GetRenderViewHost()->Send(message);
1708}
1709
[email protected]b172aee2012-04-10 17:05:261710bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501711 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261712 FrameTreeNode* node = frame_tree_.root();
1713
1714 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1715 // specified in the pending entry.
1716 NavigationEntryImpl* pending_entry =
1717 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1718 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1719 pending_entry->frame_tree_node_id() != -1) {
1720 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1721 }
1722
1723 return node->navigator()->NavigateToPendingEntry(
1724 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541725}
[email protected]96d185d2009-04-24 03:28:541726
[email protected]a86c0e962013-12-17 17:10:391727void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1728 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441729 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391730 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441731}
1732
[email protected]20ca0382013-02-28 19:50:071733void WebContentsImpl::AttachInterstitialPage(
1734 InterstitialPageImpl* interstitial_page) {
1735 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211736 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291737
1738 // Cancel any visible dialogs so that they don't interfere with the
1739 // interstitial.
1740 if (dialog_manager_)
1741 dialog_manager_->CancelActiveAndPendingDialogs(this);
1742
[email protected]20ca0382013-02-28 19:50:071743 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1744 DidAttachInterstitialPage());
1745}
1746
1747void WebContentsImpl::DetachInterstitialPage() {
1748 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211749 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071750 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1751 DidDetachInterstitialPage());
1752}
1753
[email protected]b172aee2012-04-10 17:05:261754void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331755 const SiteInstance* site_instance,
1756 int history_length,
1757 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411758 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1759 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211760 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191761 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141762 return;
[email protected]9e1ad4b2011-08-14 16:49:191763 }
[email protected]9f76c1e2012-03-05 15:15:581764 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191765 if (!rvh) {
1766 NOTREACHED();
1767 return;
1768 }
[email protected]9f76c1e2012-03-05 15:15:581769 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191770 NOTREACHED();
1771 return;
1772 }
[email protected]6b618e62012-08-16 12:59:181773 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1774 history_length,
1775 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141776}
1777
[email protected]4fed3702014-04-01 09:08:001778void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171779 RenderFrameHost* focused_frame = GetFocusedFrame();
1780 if (!focused_frame)
1781 return;
1782
[email protected]959be4c2014-04-08 15:01:331783 focused_frame->Send(new FrameMsg_Reload(
1784 focused_frame->GetRoutingID(), ignore_cache));
1785}
1786
1787void WebContentsImpl::Undo() {
1788 RenderFrameHost* focused_frame = GetFocusedFrame();
1789 if (!focused_frame)
1790 return;
1791
1792 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1793 RecordAction(base::UserMetricsAction("Undo"));
1794}
1795
1796void WebContentsImpl::Redo() {
1797 RenderFrameHost* focused_frame = GetFocusedFrame();
1798 if (!focused_frame)
1799 return;
1800 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1801 RecordAction(base::UserMetricsAction("Redo"));
1802}
1803
1804void WebContentsImpl::Cut() {
1805 RenderFrameHost* focused_frame = GetFocusedFrame();
1806 if (!focused_frame)
1807 return;
1808
1809 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1810 RecordAction(base::UserMetricsAction("Cut"));
1811}
1812
1813void WebContentsImpl::Copy() {
1814 RenderFrameHost* focused_frame = GetFocusedFrame();
1815 if (!focused_frame)
1816 return;
1817
1818 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1819 RecordAction(base::UserMetricsAction("Copy"));
1820}
1821
1822void WebContentsImpl::CopyToFindPboard() {
1823#if defined(OS_MACOSX)
1824 RenderFrameHost* focused_frame = GetFocusedFrame();
1825 if (!focused_frame)
1826 return;
1827
1828 // Windows/Linux don't have the concept of a find pasteboard.
1829 focused_frame->Send(
1830 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1831 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1832#endif
1833}
1834
1835void WebContentsImpl::Paste() {
1836 RenderFrameHost* focused_frame = GetFocusedFrame();
1837 if (!focused_frame)
1838 return;
1839
1840 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1841 RecordAction(base::UserMetricsAction("Paste"));
1842}
1843
1844void WebContentsImpl::PasteAndMatchStyle() {
1845 RenderFrameHost* focused_frame = GetFocusedFrame();
1846 if (!focused_frame)
1847 return;
1848
1849 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1850 focused_frame->GetRoutingID()));
1851 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1852}
1853
1854void WebContentsImpl::Delete() {
1855 RenderFrameHost* focused_frame = GetFocusedFrame();
1856 if (!focused_frame)
1857 return;
1858
1859 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1860 RecordAction(base::UserMetricsAction("DeleteSelection"));
1861}
1862
1863void WebContentsImpl::SelectAll() {
1864 RenderFrameHost* focused_frame = GetFocusedFrame();
1865 if (!focused_frame)
1866 return;
1867
1868 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1869 RecordAction(base::UserMetricsAction("SelectAll"));
1870}
1871
1872void WebContentsImpl::Unselect() {
1873 RenderFrameHost* focused_frame = GetFocusedFrame();
1874 if (!focused_frame)
1875 return;
1876
1877 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1878 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171879}
1880
1881void WebContentsImpl::Replace(const base::string16& word) {
1882 RenderFrameHost* focused_frame = GetFocusedFrame();
1883 if (!focused_frame)
1884 return;
1885
[email protected]959be4c2014-04-08 15:01:331886 focused_frame->Send(new InputMsg_Replace(
1887 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171888}
1889
1890void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1891 RenderFrameHost* focused_frame = GetFocusedFrame();
1892 if (!focused_frame)
1893 return;
1894
[email protected]959be4c2014-04-08 15:01:331895 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1896 focused_frame->GetRoutingID(), word));
1897}
1898
1899void WebContentsImpl::NotifyContextMenuClosed(
1900 const CustomContextMenuContext& context) {
1901 RenderFrameHost* focused_frame = GetFocusedFrame();
1902 if (!focused_frame)
1903 return;
1904
1905 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1906 focused_frame->GetRoutingID(), context));
1907}
1908
1909void WebContentsImpl::ExecuteCustomContextMenuCommand(
1910 int action, const CustomContextMenuContext& context) {
1911 RenderFrameHost* focused_frame = GetFocusedFrame();
1912 if (!focused_frame)
1913 return;
1914
1915 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1916 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001917}
1918
[email protected]b172aee2012-04-10 17:05:261919void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271920 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211921 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541922 return;
1923 }
[email protected]9f76c1e2012-03-05 15:15:581924 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541925}
1926
[email protected]b172aee2012-04-10 17:05:261927bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211928 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541929}
1930
[email protected]b172aee2012-04-10 17:05:261931InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211932 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221933}
1934
[email protected]b172aee2012-04-10 17:05:261935bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161936 // WebKit creates Document object when MIME type is application/xhtml+xml,
1937 // so we also support this MIME type.
1938 return contents_mime_type_ == "text/html" ||
1939 contents_mime_type_ == "text/xml" ||
1940 contents_mime_type_ == "application/xhtml+xml" ||
1941 contents_mime_type_ == "text/plain" ||
1942 contents_mime_type_ == "text/css" ||
1943 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1944}
1945
[email protected]b172aee2012-04-10 17:05:261946void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591947 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161948 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551949 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011950 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141951 return;
[email protected]c7dd2f62011-07-18 15:57:591952 }
1953
1954 Stop();
1955
1956 // Create the save package and possibly prompt the user for the name to save
1957 // the page as. The user prompt is an asynchronous operation that runs on
1958 // another thread.
1959 save_package_ = new SavePackage(this);
1960 save_package_->GetSaveInfo();
1961}
1962
1963// Used in automated testing to bypass prompting the user for file names.
1964// Instead, the names and paths are hard coded rather than running them through
1965// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341966bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1967 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211968 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591969 // Stop the page from navigating.
1970 Stop();
1971
1972 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211973 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591974}
1975
[email protected]3c71576ce2013-07-23 02:00:011976void WebContentsImpl::SaveFrame(const GURL& url,
1977 const Referrer& referrer) {
1978 if (!GetURL().is_valid())
1979 return;
1980 bool is_main_frame = (url == GetURL());
1981
1982 DownloadManager* dlm =
1983 BrowserContext::GetDownloadManager(GetBrowserContext());
1984 if (!dlm)
1985 return;
1986 int64 post_id = -1;
1987 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271988 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011989 if (entry)
1990 post_id = entry->GetPostID();
1991 }
1992 scoped_ptr<DownloadUrlParameters> params(
1993 DownloadUrlParameters::FromWebContents(this, url));
1994 params->set_referrer(referrer);
1995 params->set_post_id(post_id);
1996 params->set_prefer_cache(true);
1997 if (post_id >= 0)
1998 params->set_method("POST");
1999 params->set_prompt(true);
2000 dlm->DownloadUrl(params.Pass());
2001}
2002
[email protected]b172aee2012-04-10 17:05:262003void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342004 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482005 const base::Callback<void(int64)>& callback) {
2006 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122007}
2008
[email protected]6286a372013-10-09 04:03:272009// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262010bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272011 NavigationEntryImpl* visible_entry =
2012 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2013 return (visible_entry != NULL &&
2014 visible_entry->site_instance() == GetSiteInstance() &&
2015 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322016}
2017
[email protected]b172aee2012-04-10 17:05:262018const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272019 return contents_mime_type_;
2020}
2021
[email protected]b172aee2012-04-10 17:05:262022bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272023 return notify_disconnection_;
2024}
2025
[email protected]b172aee2012-04-10 17:05:262026void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312027 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182028 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162029}
2030
[email protected]b172aee2012-04-10 17:05:262031void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:312032 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182033 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162034}
2035
[email protected]8ff00d72012-10-23 19:12:212036RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272037 return &renderer_preferences_;
2038}
2039
[email protected]e35ccd52012-05-23 16:22:472040void WebContentsImpl::Close() {
2041 Close(GetRenderViewHost());
2042}
2043
[email protected]cf200a562013-05-03 16:24:292044void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462045 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292046 if (browser_plugin_embedder_.get())
2047 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2048 screen_x, screen_y, operation);
2049 if (GetRenderViewHost())
2050 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2051 screen_x, screen_y, operation);
2052}
2053
[email protected]d60f3702013-12-26 16:30:242054void WebContentsImpl::DidGetResourceResponseStart(
2055 const ResourceRequestDetails& details) {
2056 controller_.ssl_manager()->DidStartResourceResponse(details);
2057
2058 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2059 DidGetResourceResponseStart(details));
2060
2061 // TODO(avi): Remove. http://crbug.com/170921
2062 NotificationService::current()->Notify(
2063 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2064 Source<WebContents>(this),
2065 Details<const ResourceRequestDetails>(&details));
2066}
2067
2068void WebContentsImpl::DidGetRedirectForResourceRequest(
2069 RenderViewHost* render_view_host,
2070 const ResourceRedirectDetails& details) {
2071 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2072
2073 FOR_EACH_OBSERVER(
2074 WebContentsObserver,
2075 observers_,
2076 DidGetRedirectForResourceRequest(render_view_host, details));
2077
2078 // TODO(avi): Remove. http://crbug.com/170921
2079 NotificationService::current()->Notify(
2080 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2081 Source<WebContents>(this),
2082 Details<const ResourceRedirectDetails>(&details));
2083}
2084
[email protected]b172aee2012-04-10 17:05:262085void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522086 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582087 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512088 if (delegate_)
2089 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292090 if (browser_plugin_embedder_.get())
2091 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342092}
2093
[email protected]e35ccd52012-05-23 16:22:472094void WebContentsImpl::UserGestureDone() {
2095 OnUserGesture();
2096}
2097
[email protected]b172aee2012-04-10 17:05:262098void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272099 closed_by_user_gesture_ = value;
2100}
2101
[email protected]b172aee2012-04-10 17:05:262102bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272103 return closed_by_user_gesture_;
2104}
2105
[email protected]b172aee2012-04-10 17:05:262106double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052107 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562108 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252109 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172110 return 0;
[email protected]b75b8292010-10-01 07:28:252111
2112 double zoom_level;
2113 if (temporary_zoom_settings_) {
2114 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582115 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252116 } else {
[email protected]2ae88d12011-10-14 09:11:192117 GURL url;
[email protected]6286a372013-10-09 04:03:272118 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192119 // Since zoom map is updated using rewritten URL, use rewritten URL
2120 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272121 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022122 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2123 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252124 }
[email protected]d0b8d092010-10-25 04:05:172125 return zoom_level;
2126}
[email protected]b75b8292010-10-01 07:28:252127
[email protected]b172aee2012-04-10 17:05:262128int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592129 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172130 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012131 // Calculate the zoom percent from the factor. Round up to the nearest whole
2132 // number.
[email protected]b75b8292010-10-01 07:28:252133 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492134 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252135 *enable_decrement = percent > minimum_zoom_percent_;
2136 *enable_increment = percent < maximum_zoom_percent_;
2137 return percent;
2138}
2139
[email protected]b172aee2012-04-10 17:05:262140void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502141 if (!delegate_)
2142 return;
2143
[email protected]6286a372013-10-09 04:03:272144 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2145 if (!entry)
[email protected]1788e772010-12-15 16:40:502146 return;
2147
[email protected]6286a372013-10-09 04:03:272148 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122149}
2150
[email protected]b172aee2012-04-10 17:05:262151void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042152 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272153 if (!delegate_)
2154 return;
2155
[email protected]691aa2f2013-05-28 22:52:042156 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272157}
2158
[email protected]b172aee2012-04-10 17:05:262159int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272160 return minimum_zoom_percent_;
2161}
2162
[email protected]b172aee2012-04-10 17:05:262163int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272164 return maximum_zoom_percent_;
2165}
2166
[email protected]b172aee2012-04-10 17:05:262167gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492168 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232169}
2170
[email protected]b172aee2012-04-10 17:05:262171bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272172 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582173 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272174}
2175
[email protected]b172aee2012-04-10 17:05:262176bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442177 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502178}
2179
[email protected]cb805452013-05-22 15:16:212180void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182181 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212182 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202183}
2184
[email protected]cb805452013-05-22 15:16:212185void WebContentsImpl::DidEndColorChooser() {
2186 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2187 color_chooser_identifier_));
2188 color_chooser_.reset();
2189 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202190}
2191
[email protected]41225fe2013-03-29 05:32:022192int WebContentsImpl::DownloadImage(const GURL& url,
2193 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302194 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022195 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582196 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022197 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392198 return id;
2199}
2200
[email protected]5dcaf8e2013-12-28 01:31:422201bool WebContentsImpl::IsSubframe() const {
2202 return is_subframe_;
2203}
2204
[email protected]9649d492014-01-10 07:15:522205void WebContentsImpl::SetZoomLevel(double level) {
2206 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2207 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2208 if (embedder)
2209 embedder->SetZoomLevel(level);
2210}
2211
[email protected]36ec24f2014-01-09 00:32:082212void WebContentsImpl::Find(int request_id,
2213 const base::string16& search_text,
2214 const blink::WebFindOptions& options) {
2215 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2216}
2217
2218void WebContentsImpl::StopFinding(StopFindAction action) {
2219 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2220}
2221
[email protected]b172aee2012-04-10 17:05:262222bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272223 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202224 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332225 return true;
2226 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272227}
2228
[email protected]b172aee2012-04-10 17:05:262229void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272230 if (delegate_)
2231 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212232}
2233
[email protected]52913802013-12-10 05:52:182234void WebContentsImpl::DidStartProvisionalLoad(
2235 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072236 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182237 const GURL& validated_url,
2238 bool is_error_page,
2239 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262240 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182241 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572242 DidChangeLoadProgress(0);
2243
[email protected]0d60f0192011-04-14 12:40:102244 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272245 int render_frame_id = render_frame_host->GetRoutingID();
2246 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252247 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072248 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272249 render_frame_id, parent_routing_id, is_main_frame,
2250 validated_url, is_error_page, is_iframe_srcdoc,
2251 render_view_host));
[email protected]400992b2012-06-14 00:03:542252
2253 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182254 FOR_EACH_OBSERVER(
2255 WebContentsObserver,
2256 observers_,
2257 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582258 render_frame_host));
[email protected]400992b2012-06-14 00:03:542259 }
2260}
2261
[email protected]3109fbb72014-01-06 23:57:152262void WebContentsImpl::DidFailProvisionalLoadWithError(
2263 RenderFrameHostImpl* render_frame_host,
2264 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2265 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272266 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262267 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272268 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152269 FOR_EACH_OBSERVER(
2270 WebContentsObserver,
2271 observers_,
[email protected]161eabd2014-03-19 19:47:272272 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152273 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262274 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152275 validated_url,
2276 params.error_code,
2277 params.error_description,
[email protected]161eabd2014-03-19 19:47:272278 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152279}
2280
[email protected]b80624c2014-02-09 02:46:552281void WebContentsImpl::DidFailLoadWithError(
2282 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552283 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552284 int error_code,
2285 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272286 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262287 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272288 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552289 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272290 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262291 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552292}
2293
[email protected]52913802013-12-10 05:52:182294void WebContentsImpl::NotifyChangedNavigationState(
2295 InvalidateTypes changed_flags) {
2296 NotifyNavigationStateChanged(changed_flags);
2297}
2298
[email protected]3691e5cf2014-01-22 10:16:202299void WebContentsImpl::AboutToNavigateRenderFrame(
2300 RenderFrameHostImpl* render_frame_host) {
2301 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272302 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202303 FOR_EACH_OBSERVER(
2304 WebContentsObserver,
2305 observers_,
[email protected]161eabd2014-03-19 19:47:272306 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202307}
2308
2309void WebContentsImpl::DidStartNavigationToPendingEntry(
2310 RenderFrameHostImpl* render_frame_host,
2311 const GURL& url,
2312 NavigationController::ReloadType reload_type) {
2313 // Notify observers about navigation.
2314 FOR_EACH_OBSERVER(
2315 WebContentsObserver,
2316 observers_,
2317 DidStartNavigationToPendingEntry(url, reload_type));
2318}
2319
[email protected]8cb834e2014-03-06 14:23:232320void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2321 const OpenURLParams& params) {
2322 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182323 WebContents* new_contents = OpenURL(params);
2324
2325 if (new_contents) {
2326 // Notify observers.
2327 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2328 DidOpenRequestedURL(new_contents,
2329 params.url,
2330 params.referrer,
2331 params.disposition,
2332 params.transition,
[email protected]8cb834e2014-03-06 14:23:232333 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182334 }
2335}
2336
[email protected]400992b2012-06-14 00:03:542337void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582338 RenderFrameHostImpl* render_frame_host,
2339 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542340 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582341 FOR_EACH_OBSERVER(
2342 WebContentsObserver,
2343 observers_,
2344 ProvisionalChangeToMainFrameUrl(validated_target_url,
2345 render_frame_host));
[email protected]724159a2010-12-30 01:11:182346}
2347
[email protected]37567b432014-02-12 01:12:222348void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432349 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222350 const base::string16& frame_unique_name,
2351 bool is_main_frame,
2352 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432353 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432354 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272355 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222356 // Notify observers about the commit of the provisional load.
2357 FOR_EACH_OBSERVER(
2358 WebContentsObserver,
2359 observers_,
[email protected]27dd82fd2014-03-03 22:11:432360 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222361 frame_unique_name,
2362 is_main_frame,
2363 url,
2364 transition_type,
2365 render_view_host));
2366}
2367
[email protected]0d0f4c492014-04-02 06:42:572368void WebContentsImpl::DidNavigateMainFramePreCommit(
2369 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2370 // Ensure fullscreen mode is exited before committing the navigation to a
2371 // different page. The next page will not start out assuming it is in
2372 // fullscreen mode.
2373 if (params.was_within_same_page) {
2374 // No document change? Then, the renderer shall decide whether to exit
2375 // fullscreen.
2376 return;
2377 }
2378 if (IsFullscreenForCurrentTab())
2379 GetRenderViewHost()->ExitFullscreen();
2380 DCHECK(!IsFullscreenForCurrentTab());
2381}
2382
[email protected]37567b432014-02-12 01:12:222383void WebContentsImpl::DidNavigateMainFramePostCommit(
2384 const LoadCommittedDetails& details,
2385 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2386 if (details.is_navigation_to_different_page()) {
2387 // Clear the status bubble. This is a workaround for a bug where WebKit
2388 // doesn't let us know that the cursor left an element during a
2389 // transition (this is also why the mouse cursor remains as a hand after
2390 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2391 // clear the bubble when a user navigates to a named anchor in the same
2392 // page.
2393 UpdateTargetURL(details.entry->GetPageID(), GURL());
2394 }
2395
2396 if (!details.is_in_page) {
2397 // Once the main frame is navigated, we're no longer considered to have
2398 // displayed insecure content.
2399 displayed_insecure_content_ = false;
2400 SSLManager::NotifySSLInternalStateChanged(
2401 GetController().GetBrowserContext());
2402 }
2403
2404 // Notify observers about navigation.
2405 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2406 DidNavigateMainFrame(details, params));
2407
2408 if (delegate_) {
2409 delegate_->DidNavigateMainFramePostCommit(this);
2410 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2411 }
2412}
2413
2414void WebContentsImpl::DidNavigateAnyFramePostCommit(
2415 RenderFrameHostImpl* render_frame_host,
2416 const LoadCommittedDetails& details,
2417 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2418 // If we navigate off the page, close all JavaScript dialogs.
2419 if (dialog_manager_ && !details.is_in_page)
2420 dialog_manager_->CancelActiveAndPendingDialogs(this);
2421
2422 // Notify observers about navigation.
2423 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2424 DidNavigateAnyFrame(details, params));
2425}
2426
2427void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2428 contents_mime_type_ = mime_type;
2429}
2430
2431bool WebContentsImpl::CanOverscrollContent() {
2432 if (delegate_)
2433 return delegate_->CanOverscrollContent();
2434
2435 return false;
2436}
2437
[email protected]b172aee2012-04-10 17:05:262438void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182439 const GURL& url,
[email protected]70435962011-08-02 20:13:282440 const std::string& security_info,
2441 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182442 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282443 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192444 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182445 cache.Increment();
2446
2447 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082448 int cert_id = 0;
2449 net::CertStatus cert_status = 0;
2450 int security_bits = -1;
2451 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122452 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212453 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122454 &security_bits, &connection_status,
2455 &signed_certificate_timestamp_ids);
2456 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212457 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002458 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2459 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182460
[email protected]b0f724c2013-09-05 04:21:132461 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2462
2463 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2464 DidLoadResourceFromMemoryCache(details));
2465
[email protected]8bfc8272013-09-09 20:10:532466 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2467 scoped_refptr<net::URLRequestContextGetter> request_context(
2468 resource_type == ResourceType::MEDIA ?
2469 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2470 GetRenderProcessHost()->GetID()) :
2471 GetBrowserContext()->GetRequestContextForRenderProcess(
2472 GetRenderProcessHost()->GetID()));
2473 BrowserThread::PostTask(
2474 BrowserThread::IO,
2475 FROM_HERE,
2476 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2477 }
[email protected]724159a2010-12-30 01:11:182478}
2479
[email protected]b172aee2012-04-10 17:05:262480void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392481 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182482 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192483 SSLManager::NotifySSLInternalStateChanged(
2484 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182485}
2486
[email protected]b172aee2012-04-10 17:05:262487void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022488 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582489 LOG(WARNING) << security_origin << " ran insecure content from "
2490 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392491 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412492 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392493 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182494 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412495 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192496 SSLManager::NotifySSLInternalStateChanged(
2497 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182498}
2499
[email protected]501052ff2014-02-21 22:19:072500void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572501 CHECK(render_frame_message_source_);
2502 CHECK(!render_view_message_source_);
2503 RenderFrameHostImpl* rfh =
2504 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2505
[email protected]161eabd2014-03-19 19:47:272506 int render_frame_id = rfh->GetRoutingID();
2507 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572508 FOR_EACH_OBSERVER(WebContentsObserver,
2509 observers_,
[email protected]161eabd2014-03-19 19:47:272510 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182511}
2512
[email protected]b172aee2012-04-10 17:05:262513void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262514 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372515 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122516 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2517 GetRenderProcessHost()->ReceivedBadMessage();
2518 return;
2519 }
[email protected]a1b99262013-12-27 21:56:222520
[email protected]8b3af1e2014-01-24 13:29:122521 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442522 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372523 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422524 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372525
[email protected]61ac9e242014-03-21 20:55:262526 RenderFrameHostImpl* rfh =
2527 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272528 int render_frame_id = rfh->GetRoutingID();
2529 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262530 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252531 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272532 DidFinishLoad(render_frame_id, validated_url,
2533 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312534}
2535
[email protected]b172aee2012-04-10 17:05:262536void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222537 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2538 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262539}
2540
[email protected]b172aee2012-04-10 17:05:262541void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2542 int maximum_percent,
2543 bool remember) {
[email protected]216813952011-05-19 22:21:262544 minimum_zoom_percent_ = minimum_percent;
2545 maximum_zoom_percent_ = maximum_percent;
2546 temporary_zoom_settings_ = !remember;
2547}
2548
[email protected]b172aee2012-04-10 17:05:262549void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342550 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432551 if (!delegate_)
2552 return;
2553
[email protected]b9535422012-02-09 01:47:592554 ChildProcessSecurityPolicyImpl* policy =
2555 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222556 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592557 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212558}
2559
[email protected]b172aee2012-04-10 17:05:262560void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2561 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262562 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362563 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432564 if (!delegate_)
2565 return;
2566
[email protected]b9535422012-02-09 01:47:592567 ChildProcessSecurityPolicyImpl* policy =
2568 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322569 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592570 return;
[email protected]8f810632013-06-06 22:33:322571
[email protected]3a3b75a2012-06-01 08:38:362572 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202573}
2574
[email protected]b172aee2012-04-10 17:05:262575void WebContentsImpl::OnFindReply(int request_id,
2576 int number_of_matches,
2577 const gfx::Rect& selection_rect,
2578 int active_match_ordinal,
2579 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432580 if (delegate_) {
2581 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2582 active_match_ordinal, final_update);
2583 }
[email protected]b888919c2011-09-02 00:32:162584}
2585
[email protected]59363fc92012-09-05 03:46:312586#if defined(OS_ANDROID)
2587void WebContentsImpl::OnFindMatchRectsReply(
2588 int version,
2589 const std::vector<gfx::RectF>& rects,
2590 const gfx::RectF& active_rect) {
2591 if (delegate_)
2592 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2593}
[email protected]583418cc2013-01-17 14:01:102594
[email protected]1ff427972013-02-07 21:14:072595void WebContentsImpl::OnOpenDateTimeDialog(
2596 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092597 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2598 GetRenderViewHost(),
2599 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132600 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092601 value.minimum,
2602 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172603 value.step,
2604 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102605}
2606
[email protected]a794f3a2013-10-30 17:00:322607void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2608 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]c06c58c2014-03-12 20:31:592609 render_frame_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322610}
2611
[email protected]59363fc92012-09-05 03:46:312612#endif
2613
[email protected]f114fa42013-12-06 17:06:442614void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2615 const base::FilePath& path,
2616 bool is_hung) {
2617 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2618
2619 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2620 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2621}
2622
2623void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422624 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442625 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422626 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452627}
2628
[email protected]cfa856d62014-02-22 07:58:402629void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2630 int automation_id) {
2631 DomOperationNotificationDetails details(json_string, automation_id);
2632 NotificationService::current()->Notify(
2633 NOTIFICATION_DOM_OPERATION_RESPONSE,
2634 Source<WebContents>(this),
2635 Details<DomOperationNotificationDetails>(&details));
2636}
2637
[email protected]b172aee2012-04-10 17:05:262638void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2639 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102640 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252641 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102642 AppCacheAccessed(manifest_url, blocked_by_policy));
2643}
2644
[email protected]8bc5ff02013-11-29 06:34:032645void WebContentsImpl::OnOpenColorChooser(
2646 int color_chooser_id,
2647 SkColor color,
2648 const std::vector<ColorSuggestion>& suggestions) {
2649 ColorChooser* new_color_chooser =
2650 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302651 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212652 return;
[email protected]820957a2014-01-14 14:56:302653 if (color_chooser_)
2654 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212655 color_chooser_.reset(new_color_chooser);
2656 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202657}
2658
[email protected]b172aee2012-04-10 17:05:262659void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202660 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212661 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202662 color_chooser_->End();
2663}
2664
[email protected]b172aee2012-04-10 17:05:262665void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322666 SkColor color) {
[email protected]da8543762012-03-20 08:52:202667 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212668 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202669 color_chooser_->SetSelectedColor(color);
2670}
2671
[email protected]d0759f492012-04-19 22:50:502672// This exists for render views that don't have a WebUI, but do have WebUI
2673// bindings enabled.
2674void WebContentsImpl::OnWebUISend(const GURL& source_url,
2675 const std::string& name,
2676 const base::ListValue& args) {
2677 if (delegate_)
2678 delegate_->WebUISend(this, source_url, name, args);
2679}
2680
[email protected]d8415ad92012-08-23 14:40:502681void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442682 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502683 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342684 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162685 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442686 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162687 return;
[email protected]d8415ad92012-08-23 14:40:502688 }
2689
[email protected]8c8fc292012-11-23 18:57:162690 if (!delegate_->RequestPpapiBrokerPermission(
2691 this, url, plugin_path,
2692 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442693 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162694 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442695 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162696 }
[email protected]d8415ad92012-08-23 14:40:502697}
2698
[email protected]ea0309c2013-08-06 19:35:442699void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502700 bool result) {
[email protected]ea0309c2013-08-06 19:35:442701 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502702}
2703
[email protected]c4538072013-03-18 02:17:552704void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372705 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082706 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552707 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392708 // For more info, see comment above classes BrowserPluginEmbedder and
2709 // BrowserPluginGuest.
2710 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142711 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082712 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372713}
2714
[email protected]41225fe2013-03-29 05:32:022715void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392716 int id,
[email protected]749fadd2013-05-15 08:37:482717 int http_status_code,
[email protected]795c28972012-12-06 06:13:392718 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302719 const std::vector<SkBitmap>& bitmaps,
2720 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132721 if (bitmaps.size() != original_bitmap_sizes.size())
2722 return;
2723
[email protected]41225fe2013-03-29 05:32:022724 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2725 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392726 // Currently WebContents notifies us of ANY downloads so that it is
2727 // possible to get here.
2728 return;
2729 }
2730 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302731 iter->second.Run(
2732 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392733 }
[email protected]41225fe2013-03-29 05:32:022734 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392735}
2736
2737void WebContentsImpl::OnUpdateFaviconURL(
2738 int32 page_id,
2739 const std::vector<FaviconURL>& candidates) {
2740 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2741 DidUpdateFaviconURL(page_id, candidates));
2742}
2743
[email protected]1dd0bb752014-02-01 01:16:262744void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2745 bool has_video,
2746 bool has_audio) {
2747// Chrome OS does its own detection of audio and video.
2748#if !defined(OS_CHROMEOS)
2749 scoped_ptr<PowerSaveBlocker> blocker;
2750 if (has_video) {
2751 blocker = PowerSaveBlocker::Create(
2752 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2753#if defined(OS_ANDROID)
2754 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2755 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2756#endif
2757 } else if (has_audio) {
2758 blocker = PowerSaveBlocker::Create(
2759 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2760 }
2761
2762 if (blocker) {
2763 power_save_blockers_[render_view_message_source_][player_cookie] =
2764 blocker.release();
2765 }
2766#endif // !defined(OS_CHROMEOS)
2767}
2768
2769void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062770 // Chrome OS does its own detection of audio and video.
2771#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262772 delete power_save_blockers_[render_view_message_source_][player_cookie];
2773 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062774#endif // !defined(OS_CHROMEOS)
2775}
2776
[email protected]9f268072013-11-07 00:02:152777void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2778 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2779 DidFirstVisuallyNonEmptyPaint(page_id));
2780}
[email protected]d9030b82013-07-19 08:26:062781
[email protected]e67ebf32013-02-13 11:07:192782void WebContentsImpl::DidChangeVisibleSSLState() {
2783 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2784 DidChangeVisibleSSLState());
2785}
2786
[email protected]17e286e2013-03-01 23:29:392787void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2788 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2789 BeforeFormRepostWarningShow());
2790}
2791
[email protected]ec6c05f2013-10-23 18:41:572792
2793void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2794 Activate();
2795 if (delegate_)
2796 delegate_->ShowRepostFormWarningDialog(this);
2797}
2798
[email protected]96d185d2009-04-24 03:28:542799// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592800// loading, or done loading.
2801void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2802 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092803 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262804 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542805 if (is_loading == is_loading_)
2806 return;
2807
2808 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262809 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2810 base::string16());
[email protected]96d185d2009-04-24 03:28:542811 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562812 upload_size_ = 0;
2813 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542814 }
2815
[email protected]fa944cb82013-11-15 17:51:212816 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542817
2818 is_loading_ = is_loading;
2819 waiting_for_response_ = is_loading;
2820
[email protected]6ebdc9b2010-09-27 16:55:572821 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092822 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212823 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542824
[email protected]eab61442013-11-14 18:35:482825 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592826 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482827 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2828 "URL", url);
[email protected]91621872013-10-08 04:04:592829 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2830 DidStartLoading(render_view_host));
2831 } else {
[email protected]eab61442013-11-14 18:35:482832 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2833 "URL", url);
[email protected]91621872013-10-08 04:04:592834 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2835 DidStopLoading(render_view_host));
2836 }
[email protected]66798902013-10-01 18:40:162837
2838 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212839 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2840 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542841 if (details)
[email protected]8ff00d72012-10-23 19:12:212842 det = Details<LoadNotificationDetails>(details);
2843 NotificationService::current()->Notify(
2844 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542845}
2846
[email protected]959be4c2014-04-08 15:01:332847void WebContentsImpl::SelectRange(const gfx::Point& start,
2848 const gfx::Point& end) {
2849 RenderFrameHost* focused_frame = GetFocusedFrame();
2850 if (!focused_frame)
2851 return;
2852
2853 focused_frame->Send(
2854 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
2855}
2856
[email protected]b172aee2012-04-10 17:05:262857void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462858 // If we are creating a RVH for a restored controller, then we need to make
2859 // sure the RenderView starts with a next_page_id_ larger than the number
2860 // of restored entries. This must be called before the RenderView starts
2861 // navigating (to avoid a race between the browser updating max_page_id and
2862 // the renderer updating next_page_id_). Because of this, we only call this
2863 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562864 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582865 if (max_restored_page_id >
2866 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2867 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2868 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322869}
2870
[email protected]b172aee2012-04-10 17:05:262871bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262872 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322873 // For file URLs without a title, use the pathname instead. In the case of a
2874 // synthesized title, we don't want the update to count toward the "one set
2875 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262876 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322877 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512878 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242879 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322880 explicit_set = false; // Don't count synthetic titles toward the set limit.
2881 } else {
[email protected]8af69c6c2014-03-03 19:05:312882 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322883 explicit_set = true;
2884 }
2885
[email protected]987fc3a2011-05-26 14:18:092886 // If a page is created via window.open and never navigated,
2887 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552888 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092889 if (entry) {
[email protected]36fc0392011-12-25 03:59:512890 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092891 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322892
[email protected]36fc0392011-12-25 03:59:512893 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092894 } else {
2895 if (page_title_when_no_navigation_entry_ == final_title)
2896 return false; // Nothing changed, don't bother.
2897
2898 page_title_when_no_navigation_entry_ = final_title;
2899 }
[email protected]420ae012009-04-24 05:16:322900
[email protected]420ae012009-04-24 05:16:322901 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232902 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322903
[email protected]66798902013-10-01 18:40:162904 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532905 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162906
2907 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212908 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462909 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212910 NotificationService::current()->Notify(
2911 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2912 Source<WebContents>(this),
2913 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042914
[email protected]420ae012009-04-24 05:16:322915 return true;
2916}
2917
[email protected]7b712ee22013-10-03 00:57:282918void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2919 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322920 // After sending out a swap notification, we need to send a disconnect
2921 // notification so that clients that pick up a pointer to |this| can NULL the
2922 // pointer. See Bug 1230284.
2923 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112924 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282925 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112926
2927 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282928 std::pair<RenderViewHost*, RenderViewHost*> details =
2929 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212930 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282931 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212932 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282933 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392934
2935 // Ensure that the associated embedder gets cleared after a RenderViewHost
2936 // gets swapped, so we don't reuse the same embedder next time a
2937 // RenderViewHost is attached to this WebContents.
2938 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322939}
2940
[email protected]da7a7182013-09-06 08:11:112941// TODO(avi): Remove this entire function because this notification is already
2942// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262943void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322944 if (!notify_disconnection_)
2945 return;
2946
2947 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212948 NotificationService::current()->Notify(
2949 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2950 Source<WebContents>(this),
2951 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322952}
2953
[email protected]cbb1ef592013-06-05 19:49:462954void WebContentsImpl::NotifyNavigationEntryCommitted(
2955 const LoadCommittedDetails& load_details) {
2956 FOR_EACH_OBSERVER(
2957 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2958}
2959
[email protected]f114fa42013-12-06 17:06:442960bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2961 const IPC::Message& message) {
2962 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312963}
2964
[email protected]c31a84802014-04-03 15:55:492965const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
2966 return GetLastCommittedURL();
2967}
2968
[email protected]b849847b2013-12-10 21:57:582969void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2970 // Note this is only for subframes, the notification for the main frame
2971 // happens in RenderViewCreated.
2972 FOR_EACH_OBSERVER(WebContentsObserver,
2973 observers_,
2974 RenderFrameCreated(render_frame_host));
2975}
2976
2977void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2978 FOR_EACH_OBSERVER(WebContentsObserver,
2979 observers_,
2980 RenderFrameDeleted(render_frame_host));
2981}
2982
[email protected]a09d53ce2014-01-31 00:46:422983void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302984 if (delegate_)
2985 delegate_->WorkerCrashed(this);
2986}
2987
[email protected]a09d53ce2014-01-31 00:46:422988void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2989 const ContextMenuParams& params) {
2990 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:402991 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:422992 return;
2993
2994 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2995}
2996
[email protected]a86c0e962013-12-17 17:10:392997WebContents* WebContentsImpl::GetAsWebContents() {
2998 return this;
2999}
3000
[email protected]5a3bdf52012-05-24 15:12:573001RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3002 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323003}
3004
[email protected]8ff00d72012-10-23 19:12:213005RendererPreferences WebContentsImpl::GetRendererPrefs(
3006 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463007 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513008}
3009
[email protected]b172aee2012-04-10 17:05:263010gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173011 if (delegate_)
3012 return delegate_->GetRootWindowResizerRect();
3013 return gfx::Rect();
3014}
3015
[email protected]7a846df2012-09-20 19:17:393016void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273017 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393018 browser_plugin_embedder_.reset();
3019}
3020
[email protected]b172aee2012-04-10 17:05:263021void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443022 // Don't send notifications if we are just creating a swapped-out RVH for
3023 // the opener chain. These won't be used for view-source or WebUI, so it's
3024 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243025 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443026 return;
3027
[email protected]86f98a22013-03-20 14:35:003028 if (delegate_)
3029 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083030
[email protected]8ff00d72012-10-23 19:12:213031 NotificationService::current()->Notify(
3032 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3033 Source<WebContents>(this),
3034 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323035
3036 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353037 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213038 if (GetRenderManager()->pending_web_ui())
3039 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323040
[email protected]6286a372013-10-09 04:03:273041 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333042 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323043 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183044 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583045 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323046 }
[email protected]0666aef2009-05-13 19:48:083047
[email protected]60780f412013-02-25 16:34:103048 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263049
3050 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253051 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583052
3053 // We tell the observers now instead of when the main RenderFrameHostImpl is
3054 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3055 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363056 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583057 FOR_EACH_OBSERVER(
3058 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323059}
3060
[email protected]b172aee2012-04-10 17:05:263061void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523062 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323063 // Don't notify the world, since this came from a renderer in the
3064 // background.
3065 return;
3066 }
3067
[email protected]da7a7182013-09-06 08:11:113068 notify_disconnection_ = true;
3069 // TODO(avi): Remove. http://crbug.com/170921
3070 NotificationService::current()->Notify(
3071 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3072 Source<WebContents>(this),
3073 NotificationService::NoDetails());
3074
[email protected]be1f56ab2011-12-22 06:55:313075 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233076 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303077
3078 // Restore the focus to the tab (otherwise the focus will be on the top
3079 // window).
[email protected]484ae5912010-09-29 19:16:143080 if (was_crashed && !FocusLocationBarByDefault() &&
3081 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063082 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143083 }
[email protected]32ded2212011-11-10 18:51:433084
[email protected]d8c660432011-12-22 20:51:253085 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323086}
3087
[email protected]ec6a7eb2013-04-22 17:34:223088void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3089 base::TerminationStatus status,
3090 int error_code) {
[email protected]151a63d2011-12-20 22:32:523091 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323092 // The pending page's RenderViewHost is gone.
3093 return;
3094 }
3095
[email protected]2fcdcc32014-03-05 02:14:073096 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3097 // renderer may not have made a clean exit.
3098 if (IsFullscreenForCurrentTab())
3099 ToggleFullscreenMode(false);
3100
[email protected]698191dc2014-02-25 01:06:133101 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3102 if (dialog_manager_)
3103 dialog_manager_->CancelActiveAndPendingDialogs(this);
3104
[email protected]d9030b82013-07-19 08:26:063105 ClearPowerSaveBlockers(rvh);
[email protected]e3b10d12014-03-28 16:06:093106 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323107 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233108 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:313109 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:323110
[email protected]d8c660432011-12-22 20:51:253111 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273112 observers_,
[email protected]58d5cfe2013-07-10 02:40:523113 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323114}
3115
[email protected]b172aee2012-04-10 17:05:263116void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:063117 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:213118 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:253119 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063120}
3121
[email protected]b172aee2012-04-10 17:05:263122void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3123 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043124 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153125 // Ensure that this state update comes from either the active RVH or one of
3126 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413127 // TODO(nasko): This should go through RenderFrameHost.
3128 // TODO(creis): We can't update state for cross-process subframes until we
3129 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3130 if (rvh != GetRenderViewHost() &&
3131 !GetRenderManager()->IsRVHOnSwappedOutList(
3132 static_cast<RenderViewHostImpl*>(rvh)))
3133 return;
[email protected]420ae012009-04-24 05:16:323134
3135 // We must be prepared to handle state updates for any page, these occur
3136 // when the user is scrolling and entering form data, as well as when we're
3137 // leaving a page, in which case our state may have already been moved to
3138 // the next page. The navigation controller will look up the appropriate
3139 // NavigationEntry and update it when it is notified via the delegate.
3140
3141 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583142 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323143 if (entry_index < 0)
3144 return;
[email protected]10f417c52011-12-28 21:04:233145 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323146
[email protected]691aa2f2013-05-28 22:52:043147 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323148 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043149 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323150 controller_.NotifyEntryChanged(entry, entry_index);
3151}
3152
[email protected]b172aee2012-04-10 17:05:263153void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3154 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263155 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263156 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323157 // If we have a title, that's a pretty good indication that we've started
3158 // getting useful data.
3159 SetNotWaitingForResponse();
3160
[email protected]73eb2602012-02-09 19:50:553161 // Try to find the navigation entry, which might not be the current one.
3162 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233163 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583164 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093165
[email protected]73eb2602012-02-09 19:50:553166 // We can handle title updates when we don't have an entry in
3167 // UpdateTitleForEntry, but only if the update is from the current RVH.
3168 if (!entry && rvh != GetRenderViewHost())
3169 return;
3170
[email protected]a49e10b2011-08-01 23:57:463171 // TODO(evan): make use of title_direction.
3172 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093173 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323174 return;
3175
3176 // Broadcast notifications when the UI should be updated.
3177 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213178 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323179}
3180
[email protected]b172aee2012-04-10 17:05:263181void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3182 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313183 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323184}
3185
[email protected]b172aee2012-04-10 17:05:263186void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513187 if (delegate_)
3188 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323189}
3190
[email protected]b172aee2012-04-10 17:05:263191void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103192#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293193 // The UI may be in an event-tracking loop, such as between the
3194 // mouse-down and mouse-up in text selection or a button click.
3195 // Defer the close until after tracking is complete, so that we
3196 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293197 // TODO(shess): This could get more fine-grained. For instance,
3198 // closing a tab in another window while selecting text in the
3199 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103200 if (view_->IsEventTracking()) {
3201 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293202 return;
3203 }
[email protected]60780f412013-02-25 16:34:103204#endif
[email protected]07707302009-11-06 00:50:293205
[email protected]420ae012009-04-24 05:16:323206 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523207 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513208 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323209}
3210
[email protected]66bbadaf2014-03-28 16:25:543211void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573212 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3213 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573214}
3215
[email protected]b172aee2012-04-10 17:05:263216void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513217 if (delegate_ && delegate_->IsPopupOrPanel(this))
3218 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323219}
3220
[email protected]e3b10d12014-03-28 16:06:093221void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3222 bool to_different_document) {
3223 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3224 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323225}
3226
[email protected]723971b2014-02-12 11:08:253227void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323228 scoped_ptr<LoadNotificationDetails> details;
3229
[email protected]9595fd82013-04-19 21:28:493230 // Use the last committed entry rather than the active one, in case a
3231 // pending entry has been created.
3232 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203233 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493234
[email protected]420ae012009-04-24 05:16:323235 // An entry may not exist for a stop when loading an initial blank page or
3236 // if an iframe injected by script into a blank page finishes loading.
3237 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203238 base::TimeDelta elapsed =
3239 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323240
3241 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513242 entry->GetVirtualURL(),
3243 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323244 elapsed,
3245 &controller_,
3246 controller_.GetCurrentEntryIndex()));
3247 }
3248
[email protected]e3b10d12014-03-28 16:06:093249 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3250 details.get());
[email protected]420ae012009-04-24 05:16:323251}
3252
[email protected]b172aee2012-04-10 17:05:263253void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163254 controller_.DiscardNonCommittedEntries();
3255
3256 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213257 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163258}
3259
[email protected]b172aee2012-04-10 17:05:263260void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513261 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133262 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403263}
3264
[email protected]7cc78902012-12-06 02:32:263265void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393266 if (opener_) {
3267 // Clear our opener so that future cross-process navigations don't have an
3268 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103269 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393270 opener_ = NULL;
3271 }
[email protected]7cc78902012-12-06 02:32:263272
3273 // Notify all swapped out RenderViewHosts for this tab. This is important
3274 // in case we go back to them, or if another window in those processes tries
3275 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213276 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263277}
3278
[email protected]59167c22013-06-03 18:07:323279void WebContentsImpl::DidAccessInitialDocument() {
3280 // Update the URL display.
3281 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3282}
3283
[email protected]87717d0e2012-04-26 02:58:433284void WebContentsImpl::DocumentAvailableInMainFrame(
3285 RenderViewHost* render_view_host) {
3286 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3287 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103288}
3289
[email protected]b172aee2012-04-10 17:05:263290void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083291 RenderViewHost* render_view_host,
3292 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093293 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3294 DocumentOnLoadCompletedInMainFrame(page_id));
3295
3296 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213297 NotificationService::current()->Notify(
3298 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3299 Source<WebContents>(this),
3300 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083301}
3302
[email protected]e1c3a552012-05-04 20:51:323303void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3304 // Tell the active RenderViewHost to run unload handlers and close, as long
3305 // as the request came from a RenderViewHost in the same BrowsingInstance.
3306 // In most cases, we receive this from a swapped out RenderViewHost.
3307 // It is possible to receive it from one that has just been swapped in,
3308 // in which case we might as well deliver the message anyway.
3309 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3310 GetRenderViewHost()->ClosePage();
3311}
3312
[email protected]f546640b2012-05-15 00:03:493313void WebContentsImpl::RouteMessageEvent(
3314 RenderViewHost* rvh,
3315 const ViewMsg_PostMessage_Params& params) {
3316 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363317 // came from a RenderViewHost in the same BrowsingInstance or if this
3318 // WebContents is dedicated to a browser plugin guest.
3319 // Note: This check means that an embedder could theoretically receive a
3320 // postMessage from anyone (not just its own guests). However, this is
3321 // probably not a risk for apps since other pages won't have references
3322 // to App windows.
3323 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3324 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493325 return;
3326
3327 ViewMsg_PostMessage_Params new_params(params);
3328
[email protected]0bc7f3542013-10-21 15:05:533329 if (!params.message_port_ids.empty()) {
3330 MessagePortMessageFilter* message_port_message_filter =
3331 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3332 ->message_port_message_filter();
3333 std::vector<int> new_routing_ids(params.message_port_ids.size());
3334 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3335 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3336 MessagePortService::GetInstance()->UpdateMessagePort(
3337 params.message_port_ids[i],
3338 message_port_message_filter,
3339 new_routing_ids[i]);
3340 }
3341 new_params.new_routing_ids = new_routing_ids;
3342 }
3343
[email protected]f546640b2012-05-15 00:03:493344 // If there is a source_routing_id, translate it to the routing ID for
3345 // the equivalent swapped out RVH in the target process. If we need
3346 // to create a swapped out RVH for the source tab, we create its opener
3347 // chain as well, since those will also be accessible to the target page.
3348 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3349 // Try to look up the WebContents for the source page.
3350 WebContentsImpl* source_contents = NULL;
3351 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3352 rvh->GetProcess()->GetID(), params.source_routing_id);
3353 if (source_rvh) {
3354 source_contents = static_cast<WebContentsImpl*>(
3355 source_rvh->GetDelegate()->GetAsWebContents());
3356 }
3357
3358 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363359 if (GetBrowserPluginGuest()) {
3360 // We create a swapped out RenderView for the embedder in the guest's
3361 // render process but we intentionally do not expose the embedder's
3362 // opener chain to it.
3363 new_params.source_routing_id =
3364 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3365 } else {
3366 new_params.source_routing_id =
3367 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3368 }
[email protected]f546640b2012-05-15 00:03:493369 } else {
3370 // We couldn't find it, so don't pass a source frame.
3371 new_params.source_routing_id = MSG_ROUTING_NONE;
3372 }
3373 }
3374
3375 // In most cases, we receive this from a swapped out RenderViewHost.
3376 // It is possible to receive it from one that has just been swapped in,
3377 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183378 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493379}
3380
[email protected]b172aee2012-04-10 17:05:263381void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343382 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263383 const base::string16& message,
3384 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323385 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213386 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323387 IPC::Message* reply_msg,
3388 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073389 // Suppress JavaScript dialogs when requested. Also suppress messages when
3390 // showing an interstitial as it's shown over the previous page and we don't
3391 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503392 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243393 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() ||
[email protected]0bfbf882011-12-22 18:19:273394 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073395 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523396 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153397 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323398
3399 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213400 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433401 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153402 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3403 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433404 this,
3405 frame_url.GetOrigin(),
3406 accept_lang,
3407 javascript_message_type,
3408 message,
[email protected]51da7e32012-01-30 19:24:523409 default_prompt,
[email protected]b172aee2012-04-10 17:05:263410 base::Bind(&WebContentsImpl::OnDialogClosed,
3411 base::Unretained(this),
3412 rvh,
3413 reply_msg),
[email protected]51da7e32012-01-30 19:24:523414 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323415 }
[email protected]3ab9cb82011-06-03 18:02:073416
[email protected]6dd2f1e2013-09-11 15:06:013417 *did_suppress_message = suppress_this_message;
3418
[email protected]3ab9cb82011-06-03 18:02:073419 if (suppress_this_message) {
3420 // If we are suppressing messages, just reply as if the user immediately
3421 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263422 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073423 }
3424
[email protected]6dd2f1e2013-09-11 15:06:013425 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3426 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323427}
3428
[email protected]b172aee2012-04-10 17:05:263429void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263430 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263431 bool is_reload,
3432 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583433 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513434 if (delegate_)
3435 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073436
3437 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243438 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
[email protected]3ab9cb82011-06-03 18:02:073439 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523440 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153441 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153442 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343443 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263444 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503445 return;
3446 }
[email protected]3ab9cb82011-06-03 18:02:073447
[email protected]7ab1e7d62009-10-14 23:32:013448 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153449 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3450 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323451 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263452 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523453 reply_msg));
[email protected]420ae012009-04-24 05:16:323454}
3455
[email protected]a796f202012-05-30 14:14:253456bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263457 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253458 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263459 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253460 if (!delegate_)
3461 return false;
3462 return delegate_->AddMessageToConsole(this, level, message, line_no,
3463 source_id);
3464}
3465
[email protected]b172aee2012-04-10 17:05:263466WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273467 // We want to base the page config off of the actual URL, rather than the
3468 // virtual URL.
3469 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3470 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003471 GURL url = controller_.GetActiveEntry()
3472 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153473
[email protected]fa944cb82013-11-15 17:51:213474 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323475}
3476
[email protected]0eba810b2012-10-18 03:19:363477int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213478 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413479 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3480 true, true);
[email protected]0eba810b2012-10-18 03:19:363481}
3482
[email protected]b172aee2012-04-10 17:05:263483void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273484 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253485 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223486
[email protected]ea114722012-03-12 01:11:253487 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173488 if (rdh) // NULL in unittests.
3489 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253490}
3491
[email protected]b172aee2012-04-10 17:05:263492void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443493 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253494 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443495}
3496
[email protected]b172aee2012-04-10 17:05:263497void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563498 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263499 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153500 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523501 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153502 return;
3503
[email protected]9f76c1e2012-03-05 15:15:583504 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3505
[email protected]e5fc1632011-08-08 07:51:533506 // Ignore renderer unresponsive event if debugger is attached to the tab
3507 // since the event may be a result of the renderer sitting on a breakpoint.
3508 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363509 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533510 return;
3511
[email protected]2e9d79f2013-08-16 05:45:563512 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323513 // Hang occurred while firing the beforeunload/unload handler.
3514 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583515 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323516
[email protected]fa944cb82013-11-15 17:51:213517 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323518 return;
3519
3520 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563521 // nothing we can do to recover. If the hang is in the beforeunload handler,
3522 // pretend the beforeunload listeners have all fired and allow the delegate
3523 // to continue closing; the user will not have the option of cancelling the
3524 // close. Otherwise, pretend the unload listeners have all fired and close
3525 // the tab.
3526 bool close = true;
3527 if (is_during_beforeunload) {
3528 delegate_->BeforeUnloadFired(this, true, &close);
3529 }
3530 if (close)
3531 Close(rvh);
[email protected]420ae012009-04-24 05:16:323532 return;
3533 }
3534
[email protected]9f76c1e2012-03-05 15:15:583535 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473536 return;
3537
[email protected]6934a702011-12-20 00:04:513538 if (delegate_)
3539 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323540}
3541
[email protected]b172aee2012-04-10 17:05:263542void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513543 if (delegate_)
3544 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323545}
3546
[email protected]b172aee2012-04-10 17:05:263547void WebContentsImpl::LoadStateChanged(
3548 const GURL& url,
3549 const net::LoadStateWithParam& load_state,
3550 uint64 upload_position,
3551 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323552 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563553 upload_position_ = upload_position;
3554 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503555 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213556 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303557 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213558 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323559 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463560 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213561 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463562 }
[email protected]420ae012009-04-24 05:16:323563}
3564
[email protected]b172aee2012-04-10 17:05:263565void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553566 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323567 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123568 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3569 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513570 if (delegate_)
3571 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093572 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323573}
3574
[email protected]58d5cfe2013-07-10 02:40:523575void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543576 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233577 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223578 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543579}
3580
[email protected]b172aee2012-04-10 17:05:263581void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103582 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213583 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263584 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3585 // here during container initialization and normal window size will be set
3586 // later. In case of tab duplication this resizing to 0x0 prevents setting
3587 // normal size later so just ignore it.
3588 if (!size.IsEmpty())
3589 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323590}
3591
[email protected]af905902013-10-01 21:38:513592void WebContentsImpl::CancelModalDialogsForRenderManager() {
3593 // We need to cancel modal dialogs when doing a process swap, since the load
3594 // deferrer would prevent us from swapping out.
3595 if (dialog_manager_)
3596 dialog_manager_->CancelActiveAndPendingDialogs(this);
3597}
3598
[email protected]7b712ee22013-10-03 00:57:283599void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3600 RenderViewHost* new_host) {
3601 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083602
3603 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003604 if (delegate_)
3605 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393606
[email protected]7b712ee22013-10-03 00:57:283607 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543608}
3609
[email protected]14392a52012-05-02 20:28:443610int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3611 SiteInstance* instance) {
3612 if (!opener_)
3613 return MSG_ROUTING_NONE;
3614
3615 // Recursively create RenderViews for anything else in the opener chain.
3616 return opener_->CreateOpenerRenderViews(instance);
3617}
3618
3619int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3620 int opener_route_id = MSG_ROUTING_NONE;
3621
3622 // If this tab has an opener, ensure it has a RenderView in the given
3623 // SiteInstance as well.
3624 if (opener_)
3625 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3626
[email protected]45a22ad2013-02-21 03:25:003627 // If any of the renderers (current, pending, or swapped out) for this
3628 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213629 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3630 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373631
[email protected]fa944cb82013-11-15 17:51:213632 if (GetRenderManager()->pending_render_view_host() &&
3633 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3634 instance)
3635 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003636
[email protected]fa944cb82013-11-15 17:51:213637 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373638 instance);
3639 if (rvh)
3640 return rvh->GetRoutingID();
3641
[email protected]14392a52012-05-02 20:28:443642 // Create a swapped out RenderView in the given SiteInstance if none exists,
3643 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413644 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3645 true, true);
[email protected]14392a52012-05-02 20:28:443646}
3647
[email protected]b172aee2012-04-10 17:05:263648NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193649 return GetController();
[email protected]3a3d47472010-07-15 21:03:543650}
3651
[email protected]b172aee2012-04-10 17:05:263652WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563653 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323654}
3655
[email protected]10f417c52011-12-28 21:04:233656NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263657 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323658 return controller_.GetLastCommittedEntry();
3659}
3660
[email protected]b172aee2012-04-10 17:05:263661bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163662 RenderViewHost* render_view_host,
3663 int opener_route_id,
3664 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033665 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443666 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163667 RenderWidgetHostView* rwh_view;
3668 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3669 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3670 // case this because RWH is still a base class of RenderViewHost, and child
3671 // frame RWHVs are unique in that they do not have their own WebContents.
3672 if (frame_connector) {
3673 RenderWidgetHostViewChildFrame* rwh_view_child =
3674 new RenderWidgetHostViewChildFrame(render_view_host);
3675 frame_connector->set_view(rwh_view_child);
3676 rwh_view = rwh_view_child;
3677 } else {
3678 rwh_view = view_->CreateViewForWidget(render_view_host);
3679 }
[email protected]1a98a932009-11-17 00:12:523680
[email protected]420ae012009-04-24 05:16:323681 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443682 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213683 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323684
[email protected]74ce1ad2011-12-16 21:51:463685 // Make sure we use the correct starting page_id in the new RenderView.
3686 UpdateMaxPageIDIfNecessary(render_view_host);
3687 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583688 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463689
[email protected]9f76c1e2012-03-05 15:15:583690 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263691 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493692 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133693 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523694 return false;
[email protected]14392a52012-05-02 20:28:443695 }
[email protected]a4127722011-04-27 23:13:523696
[email protected]a220b5932013-09-21 03:47:443697#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503698 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3699 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443700 if (rwh_view) {
3701 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3702 render_widget_host->WasResized();
3703 }
[email protected]f8233cc2011-05-31 20:24:503704#endif
3705
[email protected]420ae012009-04-24 05:16:323706 return true;
3707}
3708
[email protected]7d244f12013-08-22 21:41:513709#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183710base::android::ScopedJavaLocalRef<jobject>
3711WebContentsImpl::GetJavaWebContents() {
3712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3713
3714 WebContentsAndroid* web_contents_android =
3715 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3716 if (!web_contents_android) {
3717 web_contents_android = new WebContentsAndroid(this);
3718 SetUserData(kWebContentsAndroidKey, web_contents_android);
3719 }
3720 return web_contents_android->GetJavaObject();
3721}
3722
[email protected]7d244f12013-08-22 21:41:513723bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3724 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163725 MSG_ROUTING_NONE,
3726 NULL);
[email protected]7d244f12013-08-22 21:41:513727}
3728#endif
3729
[email protected]b172aee2012-04-10 17:05:263730void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3731 IPC::Message* reply_msg,
3732 bool success,
[email protected]fcf75d42013-12-03 20:11:263733 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543734 if (is_showing_before_unload_dialog_ && !success) {
3735 // If a beforeunload dialog is canceled, we need to stop the throbber from
3736 // spinning, since we forced it to start spinning in Navigate.
[email protected]723971b2014-02-12 11:08:253737 DidStopLoading(rvh->GetMainFrame());
[email protected]15d160c02012-07-04 10:52:353738 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103739
[email protected]6d65a462013-06-21 21:29:123740 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3741 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543742 }
3743 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583744 static_cast<RenderViewHostImpl*>(
3745 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543746}
3747
[email protected]b172aee2012-04-10 17:05:263748void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213749 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123750 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103751}
[email protected]f45d2a72010-03-08 23:28:353752
[email protected]b172aee2012-04-10 17:05:263753void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103754 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443755 // Can be NULL during tests.
3756 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213757 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363758}
[email protected]9f76c1e2012-03-05 15:15:583759
[email protected]1ac10dca2013-08-20 20:47:043760bool WebContentsImpl::IsHidden() {
3761 return capturer_count_ == 0 && !should_normally_be_visible_;
3762}
3763
[email protected]b0936d22013-11-28 06:47:363764RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213765 return frame_tree_.root()->render_manager();
3766}
3767
[email protected]b172aee2012-04-10 17:05:263768RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583769 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3770}
[email protected]7900bfdb2012-05-24 19:31:243771
[email protected]f8497342013-02-05 22:15:023772BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393773 return browser_plugin_guest_.get();
3774}
3775
[email protected]738f57a2013-06-29 21:06:543776void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3777 CHECK(!browser_plugin_guest_);
3778 browser_plugin_guest_.reset(guest);
3779}
3780
[email protected]f8497342013-02-05 22:15:023781BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393782 return browser_plugin_embedder_.get();
3783}
[email protected]8ff00d72012-10-23 19:12:213784
[email protected]8eb04562013-03-06 03:41:143785BrowserPluginGuestManager*
3786 WebContentsImpl::GetBrowserPluginGuestManager() const {
3787 return static_cast<BrowserPluginGuestManager*>(
3788 GetBrowserContext()->GetUserData(
3789 browser_plugin::kBrowserPluginGuestManagerKeyName));
3790}
3791
[email protected]d9030b82013-07-19 08:26:063792void WebContentsImpl::ClearPowerSaveBlockers(
3793 RenderViewHost* render_view_host) {
3794 STLDeleteValues(&power_save_blockers_[render_view_host]);
3795 power_save_blockers_.erase(render_view_host);
3796}
3797
3798void WebContentsImpl::ClearAllPowerSaveBlockers() {
3799 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3800 i != power_save_blockers_.end(); ++i)
3801 STLDeleteValues(&power_save_blockers_[i->first]);
3802 power_save_blockers_.clear();
3803}
3804
[email protected]dc0fd432013-08-27 15:29:213805gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3806 gfx::Size size;
3807 if (delegate_)
3808 size = delegate_->GetSizeForNewRenderView(this);
3809 if (size.IsEmpty())
3810 size = view_->GetContainerSize();
3811 return size;
3812}
3813
[email protected]9b159a52013-10-03 17:24:553814void WebContentsImpl::OnFrameRemoved(
3815 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583816 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553817 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583818 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553819}
3820
[email protected]222f5822014-02-05 23:40:493821void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3822 if (!delegate_)
3823 return;
3824 const gfx::Size new_size = GetPreferredSize();
3825 if (new_size != old_size)
3826 delegate_->UpdatePreferredSize(this, new_size);
3827}
3828
[email protected]8ff00d72012-10-23 19:12:213829} // namespace content