blob: 39d9d8f17c700a6b95afbd6fef3672750bded7e4 [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),
[email protected]87de04b02014-04-08 22:14:49341 is_subframe_(false),
342 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46343 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
344 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55345 frame_tree_.SetFrameRemoveListener(
346 base::Bind(&WebContentsImpl::OnFrameRemoved,
347 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35348}
initial.commit09911bf2008-07-26 23:55:29349
[email protected]b172aee2012-04-10 17:05:26350WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32351 is_being_destroyed_ = true;
352
[email protected]21b41c7e892014-02-28 01:52:24353 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
354 // shutdown and be deleted as well.
355 frame_tree_.ForEach(
356 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
357
[email protected]d9030b82013-07-19 08:26:06358 ClearAllPowerSaveBlockers();
359
[email protected]b24b68a2012-09-24 21:57:26360 for (std::set<RenderWidgetHostImpl*>::iterator iter =
361 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
362 (*iter)->DetachDelegate();
363 }
364 created_widgets_.clear();
365
[email protected]3ab9cb82011-06-03 18:02:07366 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15367 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11368 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07369
[email protected]da8543762012-03-20 08:52:20370 if (color_chooser_)
371 color_chooser_->End();
372
[email protected]420ae012009-04-24 05:16:32373 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32374
[email protected]ca13a442012-04-17 14:00:12375 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21376 NotificationService::current()->Notify(
377 NOTIFICATION_WEB_CONTENTS_DESTROYED,
378 Source<WebContents>(this),
379 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32380
[email protected]c06c58c2014-03-12 20:31:59381 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
382 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
383 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
384 run_render_frame_deleted_callback));
385
[email protected]fa944cb82013-11-15 17:51:21386 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27387 if (pending_rvh) {
388 FOR_EACH_OBSERVER(WebContentsObserver,
389 observers_,
390 RenderViewDeleted(pending_rvh));
391 }
392
[email protected]c06c58c2014-03-12 20:31:59393 ForEachFrame(run_render_frame_deleted_callback);
394
[email protected]f273ee52013-10-18 16:05:27395 FOR_EACH_OBSERVER(WebContentsObserver,
396 observers_,
[email protected]fa944cb82013-11-15 17:51:21397 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27398
[email protected]2db9bd72012-04-13 20:20:56399 FOR_EACH_OBSERVER(WebContentsObserver,
400 observers_,
401 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08402
[email protected]6934a702011-12-20 00:04:51403 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10404
405 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
406 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42407}
408
[email protected]d1198fd2012-08-13 22:50:19409WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59410 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19411 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03412 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59413 WebContentsImpl* new_contents = new WebContentsImpl(
414 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19415
[email protected]54944cde2012-12-09 09:24:59416 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19417 return new_contents;
418}
419
[email protected]b371a5652013-02-20 11:25:51420// static
[email protected]8eb04562013-03-06 03:41:14421BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36422 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53423 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54424 int guest_instance_id,
425 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39426 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39427
428 // This makes |new_contents| act as a guest.
429 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54430 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19431 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11432
[email protected]3de10bb32013-01-08 21:57:33433 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33434 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11435
[email protected]216be772013-01-25 00:22:27436 // We are instantiating a WebContents for browser plugin. Set its subframe bit
437 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42438 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27439
[email protected]8eb04562013-03-06 03:41:14440 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39441}
442
[email protected]b0936d22013-11-28 06:47:36443RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21444 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28445}
446
[email protected]7bb761892012-07-20 09:32:47447bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
448 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44449 return OnMessageReceived(render_view_host, NULL, message);
450}
451
452bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
453 RenderFrameHost* render_frame_host,
454 const IPC::Message& message) {
455 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56456 if (GetWebUI() &&
457 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17458 return true;
[email protected]d2353452012-01-19 19:53:56459 }
[email protected]f82d57b52011-04-27 19:13:17460
[email protected]d8c660432011-12-22 20:51:25461 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
462 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10463 while ((observer = it.GetNext()) != NULL)
464 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53465 return true;
[email protected]403415a2011-01-10 18:57:53466
[email protected]1d62cf72014-02-07 21:31:57467 // Message handlers should be aware of which
468 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
469 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43470 if (render_frame_host) {
471 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
472 render_frame_host->GetRenderViewHost(), message))
473 return true;
[email protected]1d62cf72014-02-07 21:31:57474 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43475 } else {
476 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
477 render_view_host, message))
478 return true;
[email protected]1d62cf72014-02-07 21:31:57479 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43480 }
[email protected]1d62cf72014-02-07 21:31:57481
[email protected]724159a2010-12-30 01:11:18482 bool handled = true;
483 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26484 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44485 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
486 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40487 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
488 OnDomOperationResponse)
[email protected]724159a2010-12-30 01:11:18489 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
490 OnDidLoadResourceFromMemoryCache)
491 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
492 OnDidDisplayInsecureContent)
493 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
494 OnDidRunInsecureContent)
[email protected]1d62cf72014-02-07 21:31:57495 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
[email protected]724159a2010-12-30 01:11:18496 OnDocumentLoadedInFrame)
[email protected]028053d42014-03-05 22:20:37497 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]7d472472011-01-22 01:30:25498 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26499 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21500 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20501 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
502 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16503 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10504 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20505 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
506 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
507 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
508 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50509 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50510 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
511 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55512 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
513 OnBrowserPluginMessage(message))
514 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
515 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02516 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
517 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10518#if defined(OS_ANDROID)
519 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
520 OnFindMatchRectsReply)
521 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
522 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32523 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
524 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10525#endif
[email protected]1dd0bb752014-02-01 01:16:26526 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
527 OnMediaPlayingNotification)
528 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
529 OnMediaPausedNotification)
[email protected]9f268072013-11-07 00:02:15530 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
531 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07532 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
533 OnShowValidationMessage)
534 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
535 OnHideValidationMessage)
536 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
537 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18538 IPC_MESSAGE_UNHANDLED(handled = false)
539 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44540 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57541 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18542
543 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39544 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18545 GetRenderProcessHost()->ReceivedBadMessage();
546 }
547
548 return handled;
549}
550
[email protected]b172aee2012-04-10 17:05:26551void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18552 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21553 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43554 if (delegate_)
555 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18556}
557
[email protected]d1198fd2012-08-13 22:50:19558NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56559 return controller_;
560}
561
[email protected]d1198fd2012-08-13 22:50:19562const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56563 return controller_;
564}
565
[email protected]8ff00d72012-10-23 19:12:21566BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55567 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30568}
569
[email protected]b172aee2012-04-10 17:05:26570const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24571 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32572 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51573 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31574}
575
[email protected]a093ce02013-07-22 20:53:14576const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24577 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32578 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24579 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
580}
581
582const GURL& WebContentsImpl::GetLastCommittedURL() const {
583 // We may not have a navigation entry yet.
584 NavigationEntry* entry = controller_.GetLastCommittedEntry();
585 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
586}
587
[email protected]8ff00d72012-10-23 19:12:21588WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31589 return delegate_;
590}
591
[email protected]8ff00d72012-10-23 19:12:21592void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31593 // TODO(cbentzel): remove this debugging code?
594 if (delegate == delegate_)
595 return;
596 if (delegate_)
597 delegate_->Detach(this);
598 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08599 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31600 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08601 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00602 if (view_)
603 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08604 }
[email protected]be1f56ab2011-12-22 06:55:31605}
606
[email protected]8ff00d72012-10-23 19:12:21607RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21608 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41609 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16610}
611
[email protected]60eca4eb2013-12-06 00:02:16612RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41613 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16614}
615
[email protected]9c9343b2014-03-08 02:56:07616RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
617 if (!frame_tree_.GetFocusedFrame())
618 return NULL;
619 return frame_tree_.GetFocusedFrame()->current_frame_host();
620}
621
[email protected]a86c0e962013-12-17 17:10:39622void WebContentsImpl::ForEachFrame(
623 const base::Callback<void(RenderFrameHost*)>& on_frame) {
624 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
625}
626
627void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
628 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
629 delete message;
630}
631
[email protected]b172aee2012-04-10 17:05:26632RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21633 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31634}
635
[email protected]bfcfa692013-02-07 06:17:02636WebContents* WebContentsImpl::GetEmbedderWebContents() const {
637 BrowserPluginGuest* guest = GetBrowserPluginGuest();
638 if (guest)
639 return guest->embedder_web_contents();
640 return NULL;
641}
642
643int WebContentsImpl::GetEmbeddedInstanceID() const {
644 BrowserPluginGuest* guest = GetBrowserPluginGuest();
645 if (guest)
646 return guest->instance_id();
647 return 0;
648}
649
[email protected]6b618e62012-08-16 12:59:18650int WebContentsImpl::GetRoutingID() const {
651 if (!GetRenderViewHost())
652 return MSG_ROUTING_NONE;
653
654 return GetRenderViewHost()->GetRoutingID();
655}
656
[email protected]44470a22013-01-24 01:21:54657int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
658 return fullscreen_widget_routing_id_;
659}
660
[email protected]b172aee2012-04-10 17:05:26661RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21662 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31663}
664
[email protected]f8497342013-02-05 22:15:02665RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
666 BrowserPluginGuest* guest = GetBrowserPluginGuest();
667 if (guest && guest->embedder_web_contents()) {
668 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
669 }
670 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
671}
672
[email protected]4aebbca2013-09-17 22:26:49673RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
674 const {
675 RenderWidgetHost* const widget_host =
676 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
677 GetFullscreenWidgetRoutingID());
678 return widget_host ? widget_host->GetView() : NULL;
679}
680
[email protected]8ff00d72012-10-23 19:12:21681WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31682 return view_.get();
683}
684
[email protected]8ff00d72012-10-23 19:12:21685WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56686 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03687 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
688 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22689 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58690 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22691 web_ui->SetController(controller);
692 return web_ui;
693 }
694
695 delete web_ui;
696 return NULL;
697}
698
[email protected]8ff00d72012-10-23 19:12:21699WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21700 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
701 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31702}
703
[email protected]8ff00d72012-10-23 19:12:21704WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21705 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34706}
707
[email protected]86ef6a392012-05-11 22:03:11708void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22709 if (GetUserAgentOverride() == override)
710 return;
711
712 renderer_preferences_.user_agent_override = override;
713
714 // Send the new override string to the renderer.
715 RenderViewHost* host = GetRenderViewHost();
716 if (host)
717 host->SyncRendererPrefs();
718
719 // Reload the page if a load is currently in progress to avoid having
720 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27721 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22722 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
723 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53724
725 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
726 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11727}
728
729const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22730 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11731}
732
[email protected]2ceee8f2014-01-14 18:02:08733#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41734void WebContentsImpl::SetParentNativeViewAccessible(
735gfx::NativeViewAccessible accessible_parent) {
736 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45737 if (GetRenderViewHost())
738 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41739}
740#endif
741
[email protected]fcf75d42013-12-03 20:11:26742const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55743 // Transient entries take precedence. They are used for interstitial pages
744 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23745 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08746 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21747 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30748 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23749 if (entry) {
[email protected]b5cca982011-05-26 04:42:08750 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23751 }
[email protected]fa944cb82013-11-15 17:51:21752 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
753 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58754 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54755 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32756 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54757 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35758 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26759 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54760 if (!title.empty())
761 return title;
762 }
763 }
764
765 // We use the title for the last committed entry rather than a pending
766 // navigation entry. For example, when the user types in a URL, we want to
767 // keep the old page's title until the new load has committed and we get a new
768 // title.
[email protected]96d185d2009-04-24 03:28:54769 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32770
[email protected]9eeafc012013-11-25 23:49:47771 // We make an exception for initial navigations.
772 if (controller_.IsInitialNavigation()) {
773 // We only want to use the title from the visible entry in one of two cases:
774 // 1. There's already a committed entry for an initial navigation, in which
775 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
776 // 2. The pending entry has been explicitly assigned a title to display.
777 //
778 // If there's no last committed entry and no assigned title, we should fall
779 // back to |page_title_when_no_navigation_entry_| rather than showing the
780 // URL.
781 if (entry ||
782 (controller_.GetVisibleEntry() &&
783 !controller_.GetVisibleEntry()->GetTitle().empty())) {
784 entry = controller_.GetVisibleEntry();
785 }
786 }
[email protected]59167c22013-06-03 18:07:32787
[email protected]45d0ef7f2011-01-05 13:46:23788 if (entry) {
[email protected]b5cca982011-05-26 04:42:08789 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23790 }
[email protected]987fc3a2011-05-26 14:18:09791
792 // |page_title_when_no_navigation_entry_| is finally used
793 // if no title cannot be retrieved.
794 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54795}
796
[email protected]b172aee2012-04-10 17:05:26797int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46798 return GetMaxPageIDForSiteInstance(GetSiteInstance());
799}
800
[email protected]b172aee2012-04-10 17:05:26801int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
802 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33803 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
804 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46805
[email protected]b6583592012-01-25 19:52:33806 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34807}
808
[email protected]b172aee2012-04-10 17:05:26809void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46810 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
811}
812
[email protected]b172aee2012-04-10 17:05:26813void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33814 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46815 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33816 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34817}
818
[email protected]ec6c05f2013-10-23 18:41:57819void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
820 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
821 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57822}
823
[email protected]b172aee2012-04-10 17:05:26824SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21825 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54826}
827
[email protected]b172aee2012-04-10 17:05:26828SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21829 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
830 GetRenderManager()->pending_render_view_host() :
831 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58832 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38833}
834
[email protected]b172aee2012-04-10 17:05:26835bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31836 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49837}
838
[email protected]b172aee2012-04-10 17:05:26839bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31840 return waiting_for_response_;
841}
842
[email protected]b172aee2012-04-10 17:05:26843const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31844 return load_state_;
845}
846
[email protected]fcf75d42013-12-03 20:11:26847const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31848 return load_state_host_;
849}
850
[email protected]b172aee2012-04-10 17:05:26851uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31852 return upload_size_;
853}
854
[email protected]b172aee2012-04-10 17:05:26855uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31856 return upload_position_;
857}
858
[email protected]1ae93fb2013-06-14 03:38:56859std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56860 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39861 frame_tree_.ForEach(base::Bind(&CollectSites,
862 base::Unretained(GetBrowserContext()),
863 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56864 return sites;
865}
866
[email protected]b172aee2012-04-10 17:05:26867const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31868 return encoding_;
869}
870
[email protected]b172aee2012-04-10 17:05:26871bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31872 return displayed_insecure_content_;
873}
874
[email protected]222f5822014-02-05 23:40:49875void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25876 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55877 ++capturer_count_;
878 DVLOG(1) << "There are now " << capturer_count_
879 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49880
881 // Note: This provides a hint to upstream code to size the views optimally
882 // for quality (e.g., to avoid scaling).
883 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
884 preferred_size_for_capture_ = capture_size;
885 OnPreferredSizeChanged(preferred_size_);
886 }
[email protected]54597982013-02-06 01:59:55887}
888
889void WebContentsImpl::DecrementCapturerCount() {
890 --capturer_count_;
891 DVLOG(1) << "There are now " << capturer_count_
892 << " capturing(s) of WebContentsImpl@" << this;
893 DCHECK_LE(0, capturer_count_);
894
[email protected]5a652232013-02-12 06:15:25895 if (is_being_destroyed_)
896 return;
897
[email protected]222f5822014-02-05 23:40:49898 if (capturer_count_ == 0) {
899 const gfx::Size old_size = preferred_size_for_capture_;
900 preferred_size_for_capture_ = gfx::Size();
901 OnPreferredSizeChanged(old_size);
902 }
903
[email protected]1ac10dca2013-08-20 20:47:04904 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55905 DVLOG(1) << "Executing delayed WasHidden().";
906 WasHidden();
907 }
[email protected]be1f56ab2011-12-22 06:55:31908}
909
[email protected]f2bd40812013-07-20 04:30:44910int WebContentsImpl::GetCapturerCount() const {
911 return capturer_count_;
912}
913
[email protected]b172aee2012-04-10 17:05:26914bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31915 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
916 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
917 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49918}
919
[email protected]b172aee2012-04-10 17:05:26920void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
921 int error_code) {
[email protected]443b80e2010-12-14 00:42:23922 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34923 return;
924
[email protected]443b80e2010-12-14 00:42:23925 crashed_status_ = status;
926 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21927 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34928}
929
[email protected]b172aee2012-04-10 17:05:26930base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31931 return crashed_status_;
932}
933
[email protected]b172aee2012-04-10 17:05:26934bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31935 return is_being_destroyed_;
936}
937
[email protected]b172aee2012-04-10 17:05:26938void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34939 if (delegate_)
940 delegate_->NavigationStateChanged(this, changed_flags);
941}
942
[email protected]9a890452014-02-13 22:21:02943base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
944 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33945}
946
[email protected]9e2e4632012-07-27 16:38:41947void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54948 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04949 RenderWidgetHostViewPort* rwhv =
950 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16951 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29952 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43953#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16954 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43955#endif
956 }
[email protected]96d185d2009-04-24 03:28:54957
[email protected]9a890452014-02-13 22:21:02958 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38959
[email protected]b9769d82012-02-10 00:23:59960 // The resize rect might have changed while this was inactive -- send the new
961 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58962 RenderViewHostImpl* rvh =
963 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59964 if (rvh) {
965 rvh->ResizeRectChanged(GetRootWindowResizerRect());
966 }
[email protected]96d185d2009-04-24 03:28:54967
[email protected]c0d9d5672013-10-09 07:38:03968 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
969
[email protected]54597982013-02-06 01:59:55970 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31971}
972
[email protected]b172aee2012-04-10 17:05:26973void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55974 // If there are entities capturing screenshots or video (e.g., mirroring),
975 // don't activate the "disable rendering" optimization.
976 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52977 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55978 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26979 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52980 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33981 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52982 // calls us).
[email protected]c30585c2012-02-16 15:02:04983 RenderWidgetHostViewPort* rwhv =
984 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16985 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29986 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54987 }
988
[email protected]c0d9d5672013-10-09 07:38:03989 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
990
[email protected]54597982013-02-06 01:59:55991 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37992}
993
[email protected]b172aee2012-04-10 17:05:26994bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31995 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27996 return WillNotifyDisconnection() &&
997 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58998 !static_cast<RenderViewHostImpl*>(
999 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311000}
1001
[email protected]1c3f80bd2014-04-08 23:02:061002void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1003 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1004 for_cross_site_transition);
1005}
1006
[email protected]b172aee2012-04-10 17:05:261007void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211008 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401009 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271010}
1011
[email protected]b172aee2012-04-10 17:05:261012WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441013 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451014 // We pass our own opener so that the cloned page can access it if it was
1015 // before.
[email protected]54944cde2012-12-09 09:24:591016 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451017 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591018 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191019 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221020 FOR_EACH_OBSERVER(WebContentsObserver,
1021 observers_,
1022 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271023 return tc;
1024}
1025
[email protected]14392a52012-05-02 20:28:441026void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211027 const NotificationSource& source,
1028 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441029 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211030 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1031 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501032 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1033 i != pending_widget_views_.end(); ++i) {
1034 if (host->GetView() == i->second) {
1035 pending_widget_views_.erase(i);
1036 break;
1037 }
1038 }
1039 break;
1040 }
[email protected]14392a52012-05-02 20:28:441041 default:
1042 NOTREACHED();
1043 }
1044}
1045
[email protected]ec6c05f2013-10-23 18:41:571046WebContents* WebContentsImpl::GetWebContents() {
1047 return this;
1048}
1049
[email protected]54944cde2012-12-09 09:24:591050void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211051 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361052 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211053 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431054 should_normally_be_visible_ = !params.initially_hidden;
1055
[email protected]fa944cb82013-11-15 17:51:211056 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041057 params.browser_context, params.site_instance, params.routing_id,
1058 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191059
[email protected]8ff00d72012-10-23 19:12:211060 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191061 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271062 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191063 CHECK(render_view_host_delegate_view_);
1064 } else {
[email protected]f8497342013-02-05 22:15:021065 WebContentsViewDelegate* delegate =
1066 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1067
[email protected]59383c782013-04-17 16:43:271068 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381069 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1070 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021071
[email protected]b5a40842012-11-28 15:26:111072 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381073 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431074 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111075 render_view_host_delegate_view_ = rv;
1076 view_.reset(rv);
1077 } else {
[email protected]f8497342013-02-05 22:15:021078 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111079 view_.reset(CreateWebContentsView(
1080 this, delegate, &render_view_host_delegate_view_));
1081 }
[email protected]d1198fd2012-08-13 22:50:191082 CHECK(render_view_host_delegate_view_);
1083 }
1084 CHECK(view_.get());
1085
[email protected]ed245db2012-12-18 08:00:451086 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591087 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191088
1089 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101090 if (opener_)
1091 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191092
1093 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211094 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1095 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441096#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191097 java_bridge_dispatcher_host_manager_.reset(
1098 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101099 date_time_chooser_.reset(new DateTimeChooserAndroid());
1100#endif
[email protected]d1198fd2012-08-13 22:50:191101}
1102
[email protected]7fff43e2013-05-21 20:21:101103void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1104 RemoveDestructionObserver(web_contents);
1105
[email protected]14392a52012-05-02 20:28:441106 // Clear the opener if it has been closed.
1107 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441108 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511109 return;
[email protected]14392a52012-05-02 20:28:441110 }
[email protected]ceee8cd2013-03-08 04:59:511111 // Clear a pending contents that has been closed before being shown.
1112 for (PendingContents::iterator iter = pending_contents_.begin();
1113 iter != pending_contents_.end();
1114 ++iter) {
1115 if (iter->second != web_contents)
1116 continue;
1117 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511118 return;
1119 }
1120 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441121}
1122
[email protected]7fff43e2013-05-21 20:21:101123void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1124 if (!ContainsKey(destruction_observers_, web_contents)) {
1125 destruction_observers_[web_contents] =
1126 new DestructionObserver(this, web_contents);
1127 }
1128}
1129
1130void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1131 DestructionObservers::iterator iter =
1132 destruction_observers_.find(web_contents);
1133 if (iter != destruction_observers_.end()) {
1134 delete destruction_observers_[web_contents];
1135 destruction_observers_.erase(iter);
1136 }
1137}
1138
[email protected]b172aee2012-04-10 17:05:261139void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311140 observers_.AddObserver(observer);
1141}
1142
[email protected]b172aee2012-04-10 17:05:261143void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311144 observers_.RemoveObserver(observer);
1145}
1146
[email protected]b172aee2012-04-10 17:05:261147void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341148 if (delegate_)
1149 delegate_->ActivateContents(this);
1150}
1151
[email protected]b172aee2012-04-10 17:05:261152void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121153 if (delegate_)
1154 delegate_->DeactivateContents(this);
1155}
1156
[email protected]b172aee2012-04-10 17:05:261157void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481158 if (delegate_)
1159 delegate_->LostCapture();
1160}
1161
[email protected]b24b68a2012-09-24 21:57:261162void WebContentsImpl::RenderWidgetDeleted(
1163 RenderWidgetHostImpl* render_widget_host) {
1164 if (is_being_destroyed_) {
1165 // |created_widgets_| might have been destroyed.
1166 return;
1167 }
1168
1169 std::set<RenderWidgetHostImpl*>::iterator iter =
1170 created_widgets_.find(render_widget_host);
1171 if (iter != created_widgets_.end())
1172 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541173
1174 if (render_widget_host &&
1175 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491176 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1177 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541178 FOR_EACH_OBSERVER(WebContentsObserver,
1179 observers_,
1180 DidDestroyFullscreenWidget(
1181 fullscreen_widget_routing_id_));
1182 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1183 }
[email protected]b24b68a2012-09-24 21:57:261184}
1185
[email protected]b172aee2012-04-10 17:05:261186bool WebContentsImpl::PreHandleKeyboardEvent(
1187 const NativeWebKeyboardEvent& event,
1188 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481189 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131190 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481191}
1192
[email protected]b172aee2012-04-10 17:05:261193void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061194 if (browser_plugin_embedder_ &&
1195 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1196 return;
1197 }
1198
[email protected]63954792011-07-11 04:17:481199 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131200 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481201}
1202
[email protected]d92026ef2014-03-03 21:04:131203bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461204 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191205#if !defined(OS_MACOSX)
1206 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1207 // isn't done for two reasons:
1208 // -the OS already has a gesture to do this through pinch-zoom
1209 // -if a user starts an inertial scroll, let's go, and presses control
1210 // (i.e. control+tab) then the OS's buffered scroll events will come in
1211 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521212 if (delegate_ &&
1213 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461214 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521215 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1216 return true;
1217 }
[email protected]bccc4472013-04-18 16:37:191218#endif
[email protected]fb3f066e2013-02-12 19:12:521219 return false;
1220}
1221
[email protected]04bce562014-01-30 05:34:541222bool WebContentsImpl::PreHandleGestureEvent(
1223 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031224 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541225}
1226
[email protected]bab38af2014-03-30 17:37:291227bool WebContentsImpl::HandleGestureEvent(
1228 const blink::WebGestureEvent& event) {
1229 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1230 // Use them to implement browser zoom, as for HandleWheelEvent above.
1231 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1232 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1233 // The scale difference necessary to trigger a zoom action. Derived from
1234 // experimentation to find a value that feels reasonable.
1235 const float kZoomStepValue = 0.6f;
1236
1237 // Find the (absolute) thresholds on either side of the current zoom factor,
1238 // then convert those to actual numbers to trigger a zoom in or out.
1239 // This logic deliberately makes the range around the starting zoom value
1240 // for the gesture twice as large as the other ranges (i.e., the notches are
1241 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1242 // so that it's easier to get back to your starting point than it is to
1243 // overshoot.
1244 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1245 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1246 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1247 : -backStep;
1248 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1249 : backStep;
1250
1251 totalPinchGestureAmount_ += event.data.pinchUpdate.scale;
1252 if (totalPinchGestureAmount_ > zoomInThreshold) {
1253 currentPinchZoomStepDelta_++;
1254 delegate_->ContentsZoomChange(true);
1255 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1256 currentPinchZoomStepDelta_--;
1257 delegate_->ContentsZoomChange(false);
1258 }
1259 return true;
1260 }
1261
1262 return false;
1263}
1264
[email protected]2ceee8f2014-01-14 18:02:081265#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411266gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1267 return accessible_parent_;
1268}
1269#endif
1270
[email protected]b172aee2012-04-10 17:05:261271void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431272 if (delegate_)
1273 delegate_->HandleMouseDown();
1274}
1275
[email protected]b172aee2012-04-10 17:05:261276void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481277 if (delegate_)
1278 delegate_->HandleMouseUp();
1279}
1280
[email protected]590a634e2012-07-19 16:38:231281void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481282 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231283 delegate_->HandlePointerActivate();
1284}
1285
1286void WebContentsImpl::HandleGestureBegin() {
1287 if (delegate_)
1288 delegate_->HandleGestureBegin();
1289}
1290
1291void WebContentsImpl::HandleGestureEnd() {
1292 if (delegate_)
1293 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481294}
1295
[email protected]b172aee2012-04-10 17:05:261296void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491297 // This method is being called to enter or leave renderer-initiated fullscreen
1298 // mode. Either way, make sure any existing fullscreen widget is shut down
1299 // first.
1300 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1301 if (widget_view)
1302 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1303
[email protected]8a5e0ca2011-08-25 06:30:471304 if (delegate_)
1305 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371306
1307 FOR_EACH_OBSERVER(WebContentsObserver,
1308 observers_,
1309 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471310}
1311
[email protected]b172aee2012-04-10 17:05:261312bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381313 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121314}
1315
[email protected]a9c81f02012-06-01 00:15:441316void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1317 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371318 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441319 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371320 } else {
1321 GotResponseToLockMouseRequest(false);
1322 }
1323}
1324
[email protected]b172aee2012-04-10 17:05:261325void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371326 if (delegate_)
1327 delegate_->LostMouseLock();
1328}
1329
[email protected]bafe6cd2012-05-23 23:09:501330void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201331 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501332 int route_id,
[email protected]227692c52013-05-31 22:43:041333 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131334 const ViewHostMsg_CreateWindow_Params& params,
1335 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501336 // We usually create the new window in the same BrowsingInstance (group of
1337 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551338 // if the opener is being suppressed (in a non-guest), we create a new
1339 // SiteInstance in its own BrowsingInstance.
1340 bool is_guest = GetRenderProcessHost()->IsGuest();
1341
[email protected]04cbd3d2013-12-04 04:58:201342 // If the opener is to be suppressed, the new window can be in any process.
1343 // Since routing ids are process specific, we must not have one passed in
1344 // as argument here.
1345 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1346
[email protected]bafe6cd2012-05-23 23:09:501347 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551348 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571349 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501350 GetSiteInstance();
1351
[email protected]04cbd3d2013-12-04 04:58:201352 // A message to create a new window can only come from the active process for
1353 // this WebContentsImpl instance. If any other process sends the request,
1354 // it is invalid and the process must be terminated.
1355 if (GetRenderProcessHost()->GetID() != render_process_id) {
1356 base::ProcessHandle process_handle =
1357 RenderProcessHost::FromID(render_process_id)->GetHandle();
1358 if (process_handle != base::kNullProcessHandle) {
1359 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391360 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201361 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1362 }
1363 return;
1364 }
1365
[email protected]d1198fd2012-08-13 22:50:191366 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341367 //
1368 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301369 const std::string& partition_id =
1370 GetContentClient()->browser()->
1371 GetStoragePartitionIdForSite(GetBrowserContext(),
1372 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461373 StoragePartition* partition = BrowserContext::GetStoragePartition(
1374 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411375 DOMStorageContextWrapper* dom_storage_context =
1376 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191377 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1378 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1379 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371380
1381 if (delegate_ &&
1382 !delegate_->ShouldCreateWebContents(this,
1383 route_id,
1384 params.window_container_type,
1385 params.frame_name,
1386 params.target_url,
1387 partition_id,
1388 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011389 if (route_id != MSG_ROUTING_NONE &&
1390 !RenderViewHost::FromID(render_process_id, route_id)) {
1391 // If the embedder didn't create a WebContents for this route, we need to
1392 // delete the RenderView that had already been created.
1393 Send(new ViewMsg_Close(route_id));
1394 }
[email protected]dd6730412013-08-14 15:03:371395 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1396 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1397 main_frame_route_id);
1398 return;
1399 }
1400
1401 // Create the new web contents. This will automatically create the new
1402 // WebContentsView. In the future, we may want to create the view separately.
1403 WebContentsImpl* new_contents =
1404 new WebContentsImpl(GetBrowserContext(),
1405 params.opener_suppressed ? NULL : this);
1406
[email protected]d1198fd2012-08-13 22:50:191407 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301408 partition_id,
[email protected]d1198fd2012-08-13 22:50:191409 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461410 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591411 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041412 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551413 if (!is_guest) {
1414 create_params.context = view_->GetNativeView();
1415 create_params.initial_size = view_->GetContainerSize();
1416 } else {
1417 // This makes |new_contents| act as a guest.
1418 // For more info, see comment above class BrowserPluginGuest.
1419 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1420 WebContentsImpl* new_contents_impl =
1421 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461422 BrowserPluginGuest::CreateWithOpener(instance_id,
1423 new_contents_impl->opener() != NULL,
1424 new_contents_impl,
1425 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551426 }
[email protected]1ac10dca2013-08-20 20:47:041427 if (params.disposition == NEW_BACKGROUND_TAB)
1428 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591429 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191430
[email protected]c4538072013-03-18 02:17:551431 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341432 // will be shown immediately).
1433 if (!params.opener_suppressed) {
1434 if (!is_guest) {
1435 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501436
[email protected]d70bea92013-04-05 04:23:341437 // TODO(brettw): It seems bogus that we have to call this function on the
1438 // newly created object and give it one of its own member variables.
1439 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1440 }
[email protected]bafe6cd2012-05-23 23:09:501441 // Save the created window associated with the route so we can show it
1442 // later.
1443 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1444 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101445 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501446 }
1447
1448 if (delegate_) {
1449 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071450 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131451 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501452 }
1453
1454 if (params.opener_suppressed) {
1455 // When the opener is suppressed, the original renderer cannot access the
1456 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001457 bool was_blocked = false;
1458 if (delegate_) {
1459 gfx::Rect initial_pos;
1460 delegate_->AddNewContents(
1461 this, new_contents, params.disposition, initial_pos,
1462 params.user_gesture, &was_blocked);
1463 }
1464 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211465 OpenURLParams open_params(params.target_url,
1466 Referrer(),
1467 CURRENT_TAB,
1468 PAGE_TRANSITION_LINK,
1469 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301470 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001471 new_contents->OpenURL(open_params);
1472 }
[email protected]bafe6cd2012-05-23 23:09:501473 }
1474}
1475
[email protected]a8504022013-12-04 20:23:511476void WebContentsImpl::CreateNewWidget(int render_process_id,
1477 int route_id,
[email protected]180ef242013-11-07 06:50:461478 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511479 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501480}
1481
[email protected]a8504022013-12-04 20:23:511482void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1483 int route_id) {
1484 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501485}
1486
[email protected]a8504022013-12-04 20:23:511487void WebContentsImpl::CreateNewWidget(int render_process_id,
1488 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501489 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461490 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211491 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511492 // A message to create a new widget can only come from the active process for
1493 // this WebContentsImpl instance. If any other process sends the request,
1494 // it is invalid and the process must be terminated.
1495 if (process->GetID() != render_process_id) {
1496 base::ProcessHandle process_handle =
1497 RenderProcessHost::FromID(render_process_id)->GetHandle();
1498 if (process_handle != base::kNullProcessHandle) {
1499 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391500 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511501 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1502 }
1503 return;
1504 }
1505
[email protected]bafe6cd2012-05-23 23:09:501506 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041507 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261508 created_widgets_.insert(widget_host);
1509
[email protected]83918ec2013-01-10 15:37:191510 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1511 view_->CreateViewForPopupWidget(widget_host));
1512 if (!widget_view)
1513 return;
[email protected]bafe6cd2012-05-23 23:09:501514 if (!is_fullscreen) {
1515 // Popups should not get activated.
1516 widget_view->SetPopupType(popup_type);
1517 }
1518 // Save the created widget associated with the route so we can show it later.
1519 pending_widget_views_[route_id] = widget_view;
1520
1521#if defined(OS_MACOSX)
1522 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1523 // to allow it to survive the trip without being hosted.
1524 base::mac::NSObjectRetain(widget_view->GetNativeView());
1525#endif
1526}
1527
1528void WebContentsImpl::ShowCreatedWindow(int route_id,
1529 WindowOpenDisposition disposition,
1530 const gfx::Rect& initial_pos,
1531 bool user_gesture) {
1532 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001533 if (contents) {
1534 WebContentsDelegate* delegate = GetDelegate();
1535 if (delegate) {
1536 delegate->AddNewContents(
1537 this, contents, disposition, initial_pos, user_gesture, NULL);
1538 }
1539 }
[email protected]bafe6cd2012-05-23 23:09:501540}
1541
1542void WebContentsImpl::ShowCreatedWidget(int route_id,
1543 const gfx::Rect& initial_pos) {
1544 ShowCreatedWidget(route_id, false, initial_pos);
1545}
1546
1547void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1548 ShowCreatedWidget(route_id, true, gfx::Rect());
1549}
1550
1551void WebContentsImpl::ShowCreatedWidget(int route_id,
1552 bool is_fullscreen,
1553 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501554 RenderWidgetHostViewPort* widget_host_view =
1555 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1556 if (!widget_host_view)
1557 return;
[email protected]4aebbca2013-09-17 22:26:491558 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311559 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1560 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491561 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1562 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1563 delegate_->ToggleFullscreenModeForTab(this, true);
1564 } else {
1565 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491566 }
[email protected]4aebbca2013-09-17 22:26:491567 FOR_EACH_OBSERVER(WebContentsObserver,
1568 observers_,
1569 DidShowFullscreenWidget(route_id));
1570 if (!widget_host_view->HasFocus())
1571 widget_host_view->Focus();
1572 } else {
[email protected]f8497342013-02-05 22:15:021573 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491574 }
[email protected]89054502012-06-03 10:29:241575
1576 RenderWidgetHostImpl* render_widget_host_impl =
1577 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1578 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311579 // Only allow privileged mouse lock for fullscreen render widget, which is
1580 // used to implement Pepper Flash fullscreen.
1581 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501582
1583#if defined(OS_MACOSX)
1584 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1585 // properly embedded (or purposefully ignored) we can release the retain we
1586 // took in CreateNewWidget().
1587 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1588#endif
1589}
1590
1591WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1592 PendingContents::iterator iter = pending_contents_.find(route_id);
1593
1594 // Certain systems can block the creation of new windows. If we didn't succeed
1595 // in creating one, just return NULL.
1596 if (iter == pending_contents_.end()) {
1597 return NULL;
1598 }
1599
1600 WebContentsImpl* new_contents = iter->second;
1601 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101602 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501603
[email protected]d70bea92013-04-05 04:23:341604 // Don't initialize the guest WebContents immediately.
1605 if (new_contents->GetRenderProcessHost()->IsGuest())
1606 return new_contents;
1607
[email protected]bafe6cd2012-05-23 23:09:501608 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1609 !new_contents->GetRenderViewHost()->GetView())
1610 return NULL;
1611
1612 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1613 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1614 return new_contents;
1615}
1616
1617RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1618 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1619 if (iter == pending_widget_views_.end()) {
1620 DCHECK(false);
1621 return NULL;
1622 }
1623
1624 RenderWidgetHostView* widget_host_view = iter->second;
1625 pending_widget_views_.erase(route_id);
1626
1627 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1628 if (!widget_host->GetProcess()->HasConnection()) {
1629 // The view has gone away or the renderer crashed. Nothing to do.
1630 return NULL;
1631 }
1632
1633 return widget_host_view;
1634}
1635
[email protected]f13b4202012-06-12 23:53:231636void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091637 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211638 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371639 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231640 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371641 } else {
1642 callback.Run(MediaStreamDevices(),
1643 MEDIA_DEVICE_INVALID_STATE,
1644 scoped_ptr<MediaStreamUI>());
1645 }
[email protected]f13b4202012-06-12 23:53:231646}
1647
[email protected]cc9200432013-07-23 23:02:401648SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1649 SiteInstance* instance) {
1650 return controller_.GetSessionStorageNamespace(instance);
1651}
1652
[email protected]9b159a52013-10-03 17:24:551653FrameTree* WebContentsImpl::GetFrameTree() {
1654 return &frame_tree_;
1655}
1656
[email protected]31a71eaf2014-03-13 01:47:361657void WebContentsImpl::AccessibilityEventReceived(
1658 const std::vector<AXEventNotificationDetails>& details) {
1659 FOR_EACH_OBSERVER(
1660 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1661}
1662
[email protected]edc3af82013-12-12 21:24:071663void WebContentsImpl::OnShowValidationMessage(
1664 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291665 const base::string16& main_text,
1666 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071667 if (delegate_)
1668 delegate_->ShowValidationMessage(
1669 this, anchor_in_root_view, main_text, sub_text);
1670}
1671
1672void WebContentsImpl::OnHideValidationMessage() {
1673 if (delegate_)
1674 delegate_->HideValidationMessage(this);
1675}
1676
1677void WebContentsImpl::OnMoveValidationMessage(
1678 const gfx::Rect& anchor_in_root_view) {
1679 if (delegate_)
1680 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1681}
1682
[email protected]32deec62013-05-15 23:55:041683void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1684 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441685 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041686}
1687
[email protected]b172aee2012-04-10 17:05:261688void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491689 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231690 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491691 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331692}
1693
[email protected]b172aee2012-04-10 17:05:261694void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341695 if (delegate_)
1696 delegate_->ResizeDueToAutoResize(this, new_size);
1697}
1698
[email protected]b172aee2012-04-10 17:05:261699WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201700 if (!delegate_)
1701 return NULL;
[email protected]00c37fc2011-08-02 00:22:501702
[email protected]e5d549d2011-12-28 01:29:201703 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201704 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341705}
1706
[email protected]6b618e62012-08-16 12:59:181707bool WebContentsImpl::Send(IPC::Message* message) {
1708 if (!GetRenderViewHost()) {
1709 delete message;
1710 return false;
1711 }
1712
1713 return GetRenderViewHost()->Send(message);
1714}
1715
[email protected]b172aee2012-04-10 17:05:261716bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501717 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261718 FrameTreeNode* node = frame_tree_.root();
1719
1720 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1721 // specified in the pending entry.
1722 NavigationEntryImpl* pending_entry =
1723 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1724 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1725 pending_entry->frame_tree_node_id() != -1) {
1726 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1727 }
1728
1729 return node->navigator()->NavigateToPendingEntry(
1730 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541731}
[email protected]96d185d2009-04-24 03:28:541732
[email protected]a86c0e962013-12-17 17:10:391733void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1734 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441735 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391736 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441737}
1738
[email protected]20ca0382013-02-28 19:50:071739void WebContentsImpl::AttachInterstitialPage(
1740 InterstitialPageImpl* interstitial_page) {
1741 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211742 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291743
1744 // Cancel any visible dialogs so that they don't interfere with the
1745 // interstitial.
1746 if (dialog_manager_)
1747 dialog_manager_->CancelActiveAndPendingDialogs(this);
1748
[email protected]20ca0382013-02-28 19:50:071749 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1750 DidAttachInterstitialPage());
1751}
1752
1753void WebContentsImpl::DetachInterstitialPage() {
1754 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211755 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071756 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1757 DidDetachInterstitialPage());
1758}
1759
[email protected]b172aee2012-04-10 17:05:261760void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331761 const SiteInstance* site_instance,
1762 int history_length,
1763 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411764 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1765 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211766 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191767 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141768 return;
[email protected]9e1ad4b2011-08-14 16:49:191769 }
[email protected]9f76c1e2012-03-05 15:15:581770 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191771 if (!rvh) {
1772 NOTREACHED();
1773 return;
1774 }
[email protected]9f76c1e2012-03-05 15:15:581775 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191776 NOTREACHED();
1777 return;
1778 }
[email protected]6b618e62012-08-16 12:59:181779 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1780 history_length,
1781 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141782}
1783
[email protected]4fed3702014-04-01 09:08:001784void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171785 RenderFrameHost* focused_frame = GetFocusedFrame();
1786 if (!focused_frame)
1787 return;
1788
[email protected]959be4c2014-04-08 15:01:331789 focused_frame->Send(new FrameMsg_Reload(
1790 focused_frame->GetRoutingID(), ignore_cache));
1791}
1792
1793void WebContentsImpl::Undo() {
1794 RenderFrameHost* focused_frame = GetFocusedFrame();
1795 if (!focused_frame)
1796 return;
1797
1798 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1799 RecordAction(base::UserMetricsAction("Undo"));
1800}
1801
1802void WebContentsImpl::Redo() {
1803 RenderFrameHost* focused_frame = GetFocusedFrame();
1804 if (!focused_frame)
1805 return;
1806 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1807 RecordAction(base::UserMetricsAction("Redo"));
1808}
1809
1810void WebContentsImpl::Cut() {
1811 RenderFrameHost* focused_frame = GetFocusedFrame();
1812 if (!focused_frame)
1813 return;
1814
1815 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1816 RecordAction(base::UserMetricsAction("Cut"));
1817}
1818
1819void WebContentsImpl::Copy() {
1820 RenderFrameHost* focused_frame = GetFocusedFrame();
1821 if (!focused_frame)
1822 return;
1823
1824 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1825 RecordAction(base::UserMetricsAction("Copy"));
1826}
1827
1828void WebContentsImpl::CopyToFindPboard() {
1829#if defined(OS_MACOSX)
1830 RenderFrameHost* focused_frame = GetFocusedFrame();
1831 if (!focused_frame)
1832 return;
1833
1834 // Windows/Linux don't have the concept of a find pasteboard.
1835 focused_frame->Send(
1836 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1837 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1838#endif
1839}
1840
1841void WebContentsImpl::Paste() {
1842 RenderFrameHost* focused_frame = GetFocusedFrame();
1843 if (!focused_frame)
1844 return;
1845
1846 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1847 RecordAction(base::UserMetricsAction("Paste"));
1848}
1849
1850void WebContentsImpl::PasteAndMatchStyle() {
1851 RenderFrameHost* focused_frame = GetFocusedFrame();
1852 if (!focused_frame)
1853 return;
1854
1855 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1856 focused_frame->GetRoutingID()));
1857 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1858}
1859
1860void WebContentsImpl::Delete() {
1861 RenderFrameHost* focused_frame = GetFocusedFrame();
1862 if (!focused_frame)
1863 return;
1864
1865 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1866 RecordAction(base::UserMetricsAction("DeleteSelection"));
1867}
1868
1869void WebContentsImpl::SelectAll() {
1870 RenderFrameHost* focused_frame = GetFocusedFrame();
1871 if (!focused_frame)
1872 return;
1873
1874 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1875 RecordAction(base::UserMetricsAction("SelectAll"));
1876}
1877
1878void WebContentsImpl::Unselect() {
1879 RenderFrameHost* focused_frame = GetFocusedFrame();
1880 if (!focused_frame)
1881 return;
1882
1883 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1884 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171885}
1886
1887void WebContentsImpl::Replace(const base::string16& word) {
1888 RenderFrameHost* focused_frame = GetFocusedFrame();
1889 if (!focused_frame)
1890 return;
1891
[email protected]959be4c2014-04-08 15:01:331892 focused_frame->Send(new InputMsg_Replace(
1893 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171894}
1895
1896void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1897 RenderFrameHost* focused_frame = GetFocusedFrame();
1898 if (!focused_frame)
1899 return;
1900
[email protected]959be4c2014-04-08 15:01:331901 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1902 focused_frame->GetRoutingID(), word));
1903}
1904
1905void WebContentsImpl::NotifyContextMenuClosed(
1906 const CustomContextMenuContext& context) {
1907 RenderFrameHost* focused_frame = GetFocusedFrame();
1908 if (!focused_frame)
1909 return;
1910
1911 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1912 focused_frame->GetRoutingID(), context));
1913}
1914
1915void WebContentsImpl::ExecuteCustomContextMenuCommand(
1916 int action, const CustomContextMenuContext& context) {
1917 RenderFrameHost* focused_frame = GetFocusedFrame();
1918 if (!focused_frame)
1919 return;
1920
1921 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1922 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001923}
1924
[email protected]b172aee2012-04-10 17:05:261925void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271926 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211927 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541928 return;
1929 }
[email protected]9f76c1e2012-03-05 15:15:581930 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541931}
1932
[email protected]b172aee2012-04-10 17:05:261933bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211934 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541935}
1936
[email protected]b172aee2012-04-10 17:05:261937InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211938 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221939}
1940
[email protected]b172aee2012-04-10 17:05:261941bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161942 // WebKit creates Document object when MIME type is application/xhtml+xml,
1943 // so we also support this MIME type.
1944 return contents_mime_type_ == "text/html" ||
1945 contents_mime_type_ == "text/xml" ||
1946 contents_mime_type_ == "application/xhtml+xml" ||
1947 contents_mime_type_ == "text/plain" ||
1948 contents_mime_type_ == "text/css" ||
1949 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1950}
1951
[email protected]b172aee2012-04-10 17:05:261952void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591953 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161954 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551955 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011956 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141957 return;
[email protected]c7dd2f62011-07-18 15:57:591958 }
1959
1960 Stop();
1961
1962 // Create the save package and possibly prompt the user for the name to save
1963 // the page as. The user prompt is an asynchronous operation that runs on
1964 // another thread.
1965 save_package_ = new SavePackage(this);
1966 save_package_->GetSaveInfo();
1967}
1968
1969// Used in automated testing to bypass prompting the user for file names.
1970// Instead, the names and paths are hard coded rather than running them through
1971// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341972bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1973 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211974 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591975 // Stop the page from navigating.
1976 Stop();
1977
1978 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211979 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591980}
1981
[email protected]3c71576ce2013-07-23 02:00:011982void WebContentsImpl::SaveFrame(const GURL& url,
1983 const Referrer& referrer) {
1984 if (!GetURL().is_valid())
1985 return;
1986 bool is_main_frame = (url == GetURL());
1987
1988 DownloadManager* dlm =
1989 BrowserContext::GetDownloadManager(GetBrowserContext());
1990 if (!dlm)
1991 return;
1992 int64 post_id = -1;
1993 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271994 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011995 if (entry)
1996 post_id = entry->GetPostID();
1997 }
1998 scoped_ptr<DownloadUrlParameters> params(
1999 DownloadUrlParameters::FromWebContents(this, url));
2000 params->set_referrer(referrer);
2001 params->set_post_id(post_id);
2002 params->set_prefer_cache(true);
2003 if (post_id >= 0)
2004 params->set_method("POST");
2005 params->set_prompt(true);
2006 dlm->DownloadUrl(params.Pass());
2007}
2008
[email protected]b172aee2012-04-10 17:05:262009void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342010 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482011 const base::Callback<void(int64)>& callback) {
2012 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122013}
2014
[email protected]6286a372013-10-09 04:03:272015// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262016bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272017 NavigationEntryImpl* visible_entry =
2018 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2019 return (visible_entry != NULL &&
2020 visible_entry->site_instance() == GetSiteInstance() &&
2021 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322022}
2023
[email protected]b172aee2012-04-10 17:05:262024const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272025 return contents_mime_type_;
2026}
2027
[email protected]b172aee2012-04-10 17:05:262028bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272029 return notify_disconnection_;
2030}
2031
[email protected]b172aee2012-04-10 17:05:262032void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312033 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182034 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162035}
2036
[email protected]b172aee2012-04-10 17:05:262037void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:312038 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182039 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162040}
2041
[email protected]8ff00d72012-10-23 19:12:212042RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272043 return &renderer_preferences_;
2044}
2045
[email protected]e35ccd52012-05-23 16:22:472046void WebContentsImpl::Close() {
2047 Close(GetRenderViewHost());
2048}
2049
[email protected]cf200a562013-05-03 16:24:292050void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462051 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292052 if (browser_plugin_embedder_.get())
2053 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2054 screen_x, screen_y, operation);
2055 if (GetRenderViewHost())
2056 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2057 screen_x, screen_y, operation);
2058}
2059
[email protected]d60f3702013-12-26 16:30:242060void WebContentsImpl::DidGetResourceResponseStart(
2061 const ResourceRequestDetails& details) {
2062 controller_.ssl_manager()->DidStartResourceResponse(details);
2063
2064 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2065 DidGetResourceResponseStart(details));
2066
2067 // TODO(avi): Remove. http://crbug.com/170921
2068 NotificationService::current()->Notify(
2069 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2070 Source<WebContents>(this),
2071 Details<const ResourceRequestDetails>(&details));
2072}
2073
2074void WebContentsImpl::DidGetRedirectForResourceRequest(
2075 RenderViewHost* render_view_host,
2076 const ResourceRedirectDetails& details) {
2077 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2078
2079 FOR_EACH_OBSERVER(
2080 WebContentsObserver,
2081 observers_,
2082 DidGetRedirectForResourceRequest(render_view_host, details));
2083
2084 // TODO(avi): Remove. http://crbug.com/170921
2085 NotificationService::current()->Notify(
2086 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2087 Source<WebContents>(this),
2088 Details<const ResourceRedirectDetails>(&details));
2089}
2090
[email protected]b172aee2012-04-10 17:05:262091void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522092 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582093 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512094 if (delegate_)
2095 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292096 if (browser_plugin_embedder_.get())
2097 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342098}
2099
[email protected]e35ccd52012-05-23 16:22:472100void WebContentsImpl::UserGestureDone() {
2101 OnUserGesture();
2102}
2103
[email protected]b172aee2012-04-10 17:05:262104void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272105 closed_by_user_gesture_ = value;
2106}
2107
[email protected]b172aee2012-04-10 17:05:262108bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272109 return closed_by_user_gesture_;
2110}
2111
[email protected]b172aee2012-04-10 17:05:262112double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052113 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562114 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252115 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172116 return 0;
[email protected]b75b8292010-10-01 07:28:252117
2118 double zoom_level;
2119 if (temporary_zoom_settings_) {
2120 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582121 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252122 } else {
[email protected]2ae88d12011-10-14 09:11:192123 GURL url;
[email protected]6286a372013-10-09 04:03:272124 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192125 // Since zoom map is updated using rewritten URL, use rewritten URL
2126 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272127 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022128 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2129 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252130 }
[email protected]d0b8d092010-10-25 04:05:172131 return zoom_level;
2132}
[email protected]b75b8292010-10-01 07:28:252133
[email protected]b172aee2012-04-10 17:05:262134int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592135 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172136 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012137 // Calculate the zoom percent from the factor. Round up to the nearest whole
2138 // number.
[email protected]b75b8292010-10-01 07:28:252139 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492140 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252141 *enable_decrement = percent > minimum_zoom_percent_;
2142 *enable_increment = percent < maximum_zoom_percent_;
2143 return percent;
2144}
2145
[email protected]b172aee2012-04-10 17:05:262146void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502147 if (!delegate_)
2148 return;
2149
[email protected]6286a372013-10-09 04:03:272150 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2151 if (!entry)
[email protected]1788e772010-12-15 16:40:502152 return;
2153
[email protected]6286a372013-10-09 04:03:272154 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122155}
2156
[email protected]b172aee2012-04-10 17:05:262157void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042158 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272159 if (!delegate_)
2160 return;
2161
[email protected]691aa2f2013-05-28 22:52:042162 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272163}
2164
[email protected]b172aee2012-04-10 17:05:262165int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272166 return minimum_zoom_percent_;
2167}
2168
[email protected]b172aee2012-04-10 17:05:262169int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272170 return maximum_zoom_percent_;
2171}
2172
[email protected]b172aee2012-04-10 17:05:262173gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492174 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232175}
2176
[email protected]b172aee2012-04-10 17:05:262177bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272178 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582179 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272180}
2181
[email protected]b172aee2012-04-10 17:05:262182bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442183 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502184}
2185
[email protected]cb805452013-05-22 15:16:212186void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182187 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212188 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202189}
2190
[email protected]cb805452013-05-22 15:16:212191void WebContentsImpl::DidEndColorChooser() {
2192 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2193 color_chooser_identifier_));
2194 color_chooser_.reset();
2195 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202196}
2197
[email protected]41225fe2013-03-29 05:32:022198int WebContentsImpl::DownloadImage(const GURL& url,
2199 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302200 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022201 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582202 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022203 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392204 return id;
2205}
2206
[email protected]5dcaf8e2013-12-28 01:31:422207bool WebContentsImpl::IsSubframe() const {
2208 return is_subframe_;
2209}
2210
[email protected]9649d492014-01-10 07:15:522211void WebContentsImpl::SetZoomLevel(double level) {
2212 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2213 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2214 if (embedder)
2215 embedder->SetZoomLevel(level);
2216}
2217
[email protected]36ec24f2014-01-09 00:32:082218void WebContentsImpl::Find(int request_id,
2219 const base::string16& search_text,
2220 const blink::WebFindOptions& options) {
2221 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2222}
2223
2224void WebContentsImpl::StopFinding(StopFindAction action) {
2225 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2226}
2227
[email protected]4fe53add2014-04-08 19:53:362228void WebContentsImpl::InsertCSS(const std::string& css) {
2229 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2230 GetMainFrame()->GetRoutingID(), css));
2231}
2232
[email protected]b172aee2012-04-10 17:05:262233bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272234 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202235 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332236 return true;
2237 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272238}
2239
[email protected]b172aee2012-04-10 17:05:262240void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272241 if (delegate_)
2242 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212243}
2244
[email protected]52913802013-12-10 05:52:182245void WebContentsImpl::DidStartProvisionalLoad(
2246 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072247 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182248 const GURL& validated_url,
2249 bool is_error_page,
2250 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262251 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182252 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572253 DidChangeLoadProgress(0);
2254
[email protected]0d60f0192011-04-14 12:40:102255 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272256 int render_frame_id = render_frame_host->GetRoutingID();
2257 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252258 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072259 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272260 render_frame_id, parent_routing_id, is_main_frame,
2261 validated_url, is_error_page, is_iframe_srcdoc,
2262 render_view_host));
[email protected]400992b2012-06-14 00:03:542263
2264 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182265 FOR_EACH_OBSERVER(
2266 WebContentsObserver,
2267 observers_,
2268 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582269 render_frame_host));
[email protected]400992b2012-06-14 00:03:542270 }
2271}
2272
[email protected]3109fbb72014-01-06 23:57:152273void WebContentsImpl::DidFailProvisionalLoadWithError(
2274 RenderFrameHostImpl* render_frame_host,
2275 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2276 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272277 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262278 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272279 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152280 FOR_EACH_OBSERVER(
2281 WebContentsObserver,
2282 observers_,
[email protected]161eabd2014-03-19 19:47:272283 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152284 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262285 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152286 validated_url,
2287 params.error_code,
2288 params.error_description,
[email protected]161eabd2014-03-19 19:47:272289 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152290}
2291
[email protected]b80624c2014-02-09 02:46:552292void WebContentsImpl::DidFailLoadWithError(
2293 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552294 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552295 int error_code,
2296 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272297 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262298 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272299 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552300 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272301 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262302 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552303}
2304
[email protected]52913802013-12-10 05:52:182305void WebContentsImpl::NotifyChangedNavigationState(
2306 InvalidateTypes changed_flags) {
2307 NotifyNavigationStateChanged(changed_flags);
2308}
2309
[email protected]3691e5cf2014-01-22 10:16:202310void WebContentsImpl::AboutToNavigateRenderFrame(
2311 RenderFrameHostImpl* render_frame_host) {
2312 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272313 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202314 FOR_EACH_OBSERVER(
2315 WebContentsObserver,
2316 observers_,
[email protected]161eabd2014-03-19 19:47:272317 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202318}
2319
2320void WebContentsImpl::DidStartNavigationToPendingEntry(
2321 RenderFrameHostImpl* render_frame_host,
2322 const GURL& url,
2323 NavigationController::ReloadType reload_type) {
2324 // Notify observers about navigation.
2325 FOR_EACH_OBSERVER(
2326 WebContentsObserver,
2327 observers_,
2328 DidStartNavigationToPendingEntry(url, reload_type));
2329}
2330
[email protected]8cb834e2014-03-06 14:23:232331void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2332 const OpenURLParams& params) {
2333 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182334 WebContents* new_contents = OpenURL(params);
2335
2336 if (new_contents) {
2337 // Notify observers.
2338 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2339 DidOpenRequestedURL(new_contents,
2340 params.url,
2341 params.referrer,
2342 params.disposition,
2343 params.transition,
[email protected]8cb834e2014-03-06 14:23:232344 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182345 }
2346}
2347
[email protected]400992b2012-06-14 00:03:542348void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582349 RenderFrameHostImpl* render_frame_host,
2350 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542351 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582352 FOR_EACH_OBSERVER(
2353 WebContentsObserver,
2354 observers_,
2355 ProvisionalChangeToMainFrameUrl(validated_target_url,
2356 render_frame_host));
[email protected]724159a2010-12-30 01:11:182357}
2358
[email protected]37567b432014-02-12 01:12:222359void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432360 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222361 const base::string16& frame_unique_name,
2362 bool is_main_frame,
2363 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432364 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432365 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272366 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222367 // Notify observers about the commit of the provisional load.
2368 FOR_EACH_OBSERVER(
2369 WebContentsObserver,
2370 observers_,
[email protected]27dd82fd2014-03-03 22:11:432371 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222372 frame_unique_name,
2373 is_main_frame,
2374 url,
2375 transition_type,
2376 render_view_host));
2377}
2378
[email protected]0d0f4c492014-04-02 06:42:572379void WebContentsImpl::DidNavigateMainFramePreCommit(
2380 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2381 // Ensure fullscreen mode is exited before committing the navigation to a
2382 // different page. The next page will not start out assuming it is in
2383 // fullscreen mode.
2384 if (params.was_within_same_page) {
2385 // No document change? Then, the renderer shall decide whether to exit
2386 // fullscreen.
2387 return;
2388 }
2389 if (IsFullscreenForCurrentTab())
2390 GetRenderViewHost()->ExitFullscreen();
2391 DCHECK(!IsFullscreenForCurrentTab());
2392}
2393
[email protected]37567b432014-02-12 01:12:222394void WebContentsImpl::DidNavigateMainFramePostCommit(
2395 const LoadCommittedDetails& details,
2396 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2397 if (details.is_navigation_to_different_page()) {
2398 // Clear the status bubble. This is a workaround for a bug where WebKit
2399 // doesn't let us know that the cursor left an element during a
2400 // transition (this is also why the mouse cursor remains as a hand after
2401 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2402 // clear the bubble when a user navigates to a named anchor in the same
2403 // page.
2404 UpdateTargetURL(details.entry->GetPageID(), GURL());
2405 }
2406
2407 if (!details.is_in_page) {
2408 // Once the main frame is navigated, we're no longer considered to have
2409 // displayed insecure content.
2410 displayed_insecure_content_ = false;
2411 SSLManager::NotifySSLInternalStateChanged(
2412 GetController().GetBrowserContext());
2413 }
2414
2415 // Notify observers about navigation.
2416 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2417 DidNavigateMainFrame(details, params));
2418
2419 if (delegate_) {
2420 delegate_->DidNavigateMainFramePostCommit(this);
2421 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2422 }
2423}
2424
2425void WebContentsImpl::DidNavigateAnyFramePostCommit(
2426 RenderFrameHostImpl* render_frame_host,
2427 const LoadCommittedDetails& details,
2428 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2429 // If we navigate off the page, close all JavaScript dialogs.
2430 if (dialog_manager_ && !details.is_in_page)
2431 dialog_manager_->CancelActiveAndPendingDialogs(this);
2432
2433 // Notify observers about navigation.
2434 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2435 DidNavigateAnyFrame(details, params));
2436}
2437
2438void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2439 contents_mime_type_ = mime_type;
2440}
2441
2442bool WebContentsImpl::CanOverscrollContent() {
2443 if (delegate_)
2444 return delegate_->CanOverscrollContent();
2445
2446 return false;
2447}
2448
[email protected]b172aee2012-04-10 17:05:262449void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182450 const GURL& url,
[email protected]70435962011-08-02 20:13:282451 const std::string& security_info,
2452 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182453 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282454 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192455 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182456 cache.Increment();
2457
2458 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082459 int cert_id = 0;
2460 net::CertStatus cert_status = 0;
2461 int security_bits = -1;
2462 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122463 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212464 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122465 &security_bits, &connection_status,
2466 &signed_certificate_timestamp_ids);
2467 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212468 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002469 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2470 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182471
[email protected]b0f724c2013-09-05 04:21:132472 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2473
2474 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2475 DidLoadResourceFromMemoryCache(details));
2476
[email protected]8bfc8272013-09-09 20:10:532477 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2478 scoped_refptr<net::URLRequestContextGetter> request_context(
2479 resource_type == ResourceType::MEDIA ?
2480 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2481 GetRenderProcessHost()->GetID()) :
2482 GetBrowserContext()->GetRequestContextForRenderProcess(
2483 GetRenderProcessHost()->GetID()));
2484 BrowserThread::PostTask(
2485 BrowserThread::IO,
2486 FROM_HERE,
2487 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2488 }
[email protected]724159a2010-12-30 01:11:182489}
2490
[email protected]b172aee2012-04-10 17:05:262491void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392492 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182493 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192494 SSLManager::NotifySSLInternalStateChanged(
2495 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182496}
2497
[email protected]b172aee2012-04-10 17:05:262498void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022499 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582500 LOG(WARNING) << security_origin << " ran insecure content from "
2501 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392502 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412503 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392504 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182505 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412506 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192507 SSLManager::NotifySSLInternalStateChanged(
2508 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182509}
2510
[email protected]501052ff2014-02-21 22:19:072511void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572512 CHECK(render_frame_message_source_);
2513 CHECK(!render_view_message_source_);
2514 RenderFrameHostImpl* rfh =
2515 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2516
[email protected]161eabd2014-03-19 19:47:272517 int render_frame_id = rfh->GetRoutingID();
2518 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572519 FOR_EACH_OBSERVER(WebContentsObserver,
2520 observers_,
[email protected]161eabd2014-03-19 19:47:272521 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182522}
2523
[email protected]b172aee2012-04-10 17:05:262524void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262525 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372526 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122527 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2528 GetRenderProcessHost()->ReceivedBadMessage();
2529 return;
2530 }
[email protected]a1b99262013-12-27 21:56:222531
[email protected]8b3af1e2014-01-24 13:29:122532 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442533 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372534 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422535 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372536
[email protected]61ac9e242014-03-21 20:55:262537 RenderFrameHostImpl* rfh =
2538 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272539 int render_frame_id = rfh->GetRoutingID();
2540 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262541 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252542 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272543 DidFinishLoad(render_frame_id, validated_url,
2544 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312545}
2546
[email protected]b172aee2012-04-10 17:05:262547void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222548 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2549 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262550}
2551
[email protected]b172aee2012-04-10 17:05:262552void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2553 int maximum_percent,
2554 bool remember) {
[email protected]216813952011-05-19 22:21:262555 minimum_zoom_percent_ = minimum_percent;
2556 maximum_zoom_percent_ = maximum_percent;
2557 temporary_zoom_settings_ = !remember;
2558}
2559
[email protected]b172aee2012-04-10 17:05:262560void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342561 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432562 if (!delegate_)
2563 return;
2564
[email protected]b9535422012-02-09 01:47:592565 ChildProcessSecurityPolicyImpl* policy =
2566 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222567 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592568 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212569}
2570
[email protected]b172aee2012-04-10 17:05:262571void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2572 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262573 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362574 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432575 if (!delegate_)
2576 return;
2577
[email protected]b9535422012-02-09 01:47:592578 ChildProcessSecurityPolicyImpl* policy =
2579 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322580 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592581 return;
[email protected]8f810632013-06-06 22:33:322582
[email protected]3a3b75a2012-06-01 08:38:362583 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202584}
2585
[email protected]b172aee2012-04-10 17:05:262586void WebContentsImpl::OnFindReply(int request_id,
2587 int number_of_matches,
2588 const gfx::Rect& selection_rect,
2589 int active_match_ordinal,
2590 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432591 if (delegate_) {
2592 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2593 active_match_ordinal, final_update);
2594 }
[email protected]b888919c2011-09-02 00:32:162595}
2596
[email protected]59363fc92012-09-05 03:46:312597#if defined(OS_ANDROID)
2598void WebContentsImpl::OnFindMatchRectsReply(
2599 int version,
2600 const std::vector<gfx::RectF>& rects,
2601 const gfx::RectF& active_rect) {
2602 if (delegate_)
2603 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2604}
[email protected]583418cc2013-01-17 14:01:102605
[email protected]1ff427972013-02-07 21:14:072606void WebContentsImpl::OnOpenDateTimeDialog(
2607 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092608 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2609 GetRenderViewHost(),
2610 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132611 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092612 value.minimum,
2613 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172614 value.step,
2615 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102616}
2617
[email protected]a794f3a2013-10-30 17:00:322618void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2619 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]c06c58c2014-03-12 20:31:592620 render_frame_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322621}
2622
[email protected]59363fc92012-09-05 03:46:312623#endif
2624
[email protected]f114fa42013-12-06 17:06:442625void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2626 const base::FilePath& path,
2627 bool is_hung) {
2628 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2629
2630 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2631 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2632}
2633
2634void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422635 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442636 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422637 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452638}
2639
[email protected]cfa856d62014-02-22 07:58:402640void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2641 int automation_id) {
2642 DomOperationNotificationDetails details(json_string, automation_id);
2643 NotificationService::current()->Notify(
2644 NOTIFICATION_DOM_OPERATION_RESPONSE,
2645 Source<WebContents>(this),
2646 Details<DomOperationNotificationDetails>(&details));
2647}
2648
[email protected]b172aee2012-04-10 17:05:262649void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2650 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102651 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252652 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102653 AppCacheAccessed(manifest_url, blocked_by_policy));
2654}
2655
[email protected]8bc5ff02013-11-29 06:34:032656void WebContentsImpl::OnOpenColorChooser(
2657 int color_chooser_id,
2658 SkColor color,
2659 const std::vector<ColorSuggestion>& suggestions) {
2660 ColorChooser* new_color_chooser =
2661 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302662 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212663 return;
[email protected]820957a2014-01-14 14:56:302664 if (color_chooser_)
2665 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212666 color_chooser_.reset(new_color_chooser);
2667 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202668}
2669
[email protected]b172aee2012-04-10 17:05:262670void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202671 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212672 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202673 color_chooser_->End();
2674}
2675
[email protected]b172aee2012-04-10 17:05:262676void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322677 SkColor color) {
[email protected]da8543762012-03-20 08:52:202678 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212679 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202680 color_chooser_->SetSelectedColor(color);
2681}
2682
[email protected]d0759f492012-04-19 22:50:502683// This exists for render views that don't have a WebUI, but do have WebUI
2684// bindings enabled.
2685void WebContentsImpl::OnWebUISend(const GURL& source_url,
2686 const std::string& name,
2687 const base::ListValue& args) {
2688 if (delegate_)
2689 delegate_->WebUISend(this, source_url, name, args);
2690}
2691
[email protected]d8415ad92012-08-23 14:40:502692void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442693 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502694 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342695 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162696 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442697 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162698 return;
[email protected]d8415ad92012-08-23 14:40:502699 }
2700
[email protected]8c8fc292012-11-23 18:57:162701 if (!delegate_->RequestPpapiBrokerPermission(
2702 this, url, plugin_path,
2703 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442704 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162705 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442706 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162707 }
[email protected]d8415ad92012-08-23 14:40:502708}
2709
[email protected]ea0309c2013-08-06 19:35:442710void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502711 bool result) {
[email protected]ea0309c2013-08-06 19:35:442712 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502713}
2714
[email protected]c4538072013-03-18 02:17:552715void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372716 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082717 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552718 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392719 // For more info, see comment above classes BrowserPluginEmbedder and
2720 // BrowserPluginGuest.
2721 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142722 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082723 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372724}
2725
[email protected]41225fe2013-03-29 05:32:022726void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392727 int id,
[email protected]749fadd2013-05-15 08:37:482728 int http_status_code,
[email protected]795c28972012-12-06 06:13:392729 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302730 const std::vector<SkBitmap>& bitmaps,
2731 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132732 if (bitmaps.size() != original_bitmap_sizes.size())
2733 return;
2734
[email protected]41225fe2013-03-29 05:32:022735 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2736 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392737 // Currently WebContents notifies us of ANY downloads so that it is
2738 // possible to get here.
2739 return;
2740 }
2741 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302742 iter->second.Run(
2743 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392744 }
[email protected]41225fe2013-03-29 05:32:022745 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392746}
2747
2748void WebContentsImpl::OnUpdateFaviconURL(
2749 int32 page_id,
2750 const std::vector<FaviconURL>& candidates) {
2751 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2752 DidUpdateFaviconURL(page_id, candidates));
2753}
2754
[email protected]1dd0bb752014-02-01 01:16:262755void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2756 bool has_video,
2757 bool has_audio) {
2758// Chrome OS does its own detection of audio and video.
2759#if !defined(OS_CHROMEOS)
2760 scoped_ptr<PowerSaveBlocker> blocker;
2761 if (has_video) {
2762 blocker = PowerSaveBlocker::Create(
2763 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2764#if defined(OS_ANDROID)
2765 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2766 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2767#endif
2768 } else if (has_audio) {
2769 blocker = PowerSaveBlocker::Create(
2770 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2771 }
2772
2773 if (blocker) {
2774 power_save_blockers_[render_view_message_source_][player_cookie] =
2775 blocker.release();
2776 }
2777#endif // !defined(OS_CHROMEOS)
2778}
2779
2780void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062781 // Chrome OS does its own detection of audio and video.
2782#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262783 delete power_save_blockers_[render_view_message_source_][player_cookie];
2784 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062785#endif // !defined(OS_CHROMEOS)
2786}
2787
[email protected]9f268072013-11-07 00:02:152788void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2789 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2790 DidFirstVisuallyNonEmptyPaint(page_id));
2791}
[email protected]d9030b82013-07-19 08:26:062792
[email protected]e67ebf32013-02-13 11:07:192793void WebContentsImpl::DidChangeVisibleSSLState() {
2794 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2795 DidChangeVisibleSSLState());
2796}
2797
[email protected]17e286e2013-03-01 23:29:392798void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2799 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2800 BeforeFormRepostWarningShow());
2801}
2802
[email protected]ec6c05f2013-10-23 18:41:572803
2804void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2805 Activate();
2806 if (delegate_)
2807 delegate_->ShowRepostFormWarningDialog(this);
2808}
2809
[email protected]96d185d2009-04-24 03:28:542810// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592811// loading, or done loading.
2812void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2813 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092814 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262815 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542816 if (is_loading == is_loading_)
2817 return;
2818
2819 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262820 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2821 base::string16());
[email protected]96d185d2009-04-24 03:28:542822 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562823 upload_size_ = 0;
2824 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542825 }
2826
[email protected]fa944cb82013-11-15 17:51:212827 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542828
2829 is_loading_ = is_loading;
2830 waiting_for_response_ = is_loading;
2831
[email protected]6ebdc9b2010-09-27 16:55:572832 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092833 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212834 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542835
[email protected]eab61442013-11-14 18:35:482836 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592837 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482838 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2839 "URL", url);
[email protected]91621872013-10-08 04:04:592840 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2841 DidStartLoading(render_view_host));
2842 } else {
[email protected]eab61442013-11-14 18:35:482843 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2844 "URL", url);
[email protected]91621872013-10-08 04:04:592845 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2846 DidStopLoading(render_view_host));
2847 }
[email protected]66798902013-10-01 18:40:162848
2849 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212850 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2851 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542852 if (details)
[email protected]8ff00d72012-10-23 19:12:212853 det = Details<LoadNotificationDetails>(details);
2854 NotificationService::current()->Notify(
2855 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542856}
2857
[email protected]959be4c2014-04-08 15:01:332858void WebContentsImpl::SelectRange(const gfx::Point& start,
2859 const gfx::Point& end) {
2860 RenderFrameHost* focused_frame = GetFocusedFrame();
2861 if (!focused_frame)
2862 return;
2863
2864 focused_frame->Send(
2865 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
2866}
2867
[email protected]b172aee2012-04-10 17:05:262868void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462869 // If we are creating a RVH for a restored controller, then we need to make
2870 // sure the RenderView starts with a next_page_id_ larger than the number
2871 // of restored entries. This must be called before the RenderView starts
2872 // navigating (to avoid a race between the browser updating max_page_id and
2873 // the renderer updating next_page_id_). Because of this, we only call this
2874 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562875 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582876 if (max_restored_page_id >
2877 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2878 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2879 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322880}
2881
[email protected]b172aee2012-04-10 17:05:262882bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262883 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322884 // For file URLs without a title, use the pathname instead. In the case of a
2885 // synthesized title, we don't want the update to count toward the "one set
2886 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262887 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322888 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512889 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242890 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322891 explicit_set = false; // Don't count synthetic titles toward the set limit.
2892 } else {
[email protected]8af69c6c2014-03-03 19:05:312893 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322894 explicit_set = true;
2895 }
2896
[email protected]987fc3a2011-05-26 14:18:092897 // If a page is created via window.open and never navigated,
2898 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552899 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092900 if (entry) {
[email protected]36fc0392011-12-25 03:59:512901 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092902 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322903
[email protected]36fc0392011-12-25 03:59:512904 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092905 } else {
2906 if (page_title_when_no_navigation_entry_ == final_title)
2907 return false; // Nothing changed, don't bother.
2908
2909 page_title_when_no_navigation_entry_ = final_title;
2910 }
[email protected]420ae012009-04-24 05:16:322911
[email protected]420ae012009-04-24 05:16:322912 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232913 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322914
[email protected]66798902013-10-01 18:40:162915 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532916 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162917
2918 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212919 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462920 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212921 NotificationService::current()->Notify(
2922 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2923 Source<WebContents>(this),
2924 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042925
[email protected]420ae012009-04-24 05:16:322926 return true;
2927}
2928
[email protected]7b712ee22013-10-03 00:57:282929void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2930 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322931 // After sending out a swap notification, we need to send a disconnect
2932 // notification so that clients that pick up a pointer to |this| can NULL the
2933 // pointer. See Bug 1230284.
2934 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112935 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282936 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112937
2938 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282939 std::pair<RenderViewHost*, RenderViewHost*> details =
2940 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212941 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282942 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212943 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282944 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392945
2946 // Ensure that the associated embedder gets cleared after a RenderViewHost
2947 // gets swapped, so we don't reuse the same embedder next time a
2948 // RenderViewHost is attached to this WebContents.
2949 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322950}
2951
[email protected]da7a7182013-09-06 08:11:112952// TODO(avi): Remove this entire function because this notification is already
2953// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262954void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322955 if (!notify_disconnection_)
2956 return;
2957
2958 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212959 NotificationService::current()->Notify(
2960 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2961 Source<WebContents>(this),
2962 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322963}
2964
[email protected]cbb1ef592013-06-05 19:49:462965void WebContentsImpl::NotifyNavigationEntryCommitted(
2966 const LoadCommittedDetails& load_details) {
2967 FOR_EACH_OBSERVER(
2968 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2969}
2970
[email protected]f114fa42013-12-06 17:06:442971bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2972 const IPC::Message& message) {
2973 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312974}
2975
[email protected]c31a84802014-04-03 15:55:492976const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
2977 return GetLastCommittedURL();
2978}
2979
[email protected]b849847b2013-12-10 21:57:582980void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2981 // Note this is only for subframes, the notification for the main frame
2982 // happens in RenderViewCreated.
2983 FOR_EACH_OBSERVER(WebContentsObserver,
2984 observers_,
2985 RenderFrameCreated(render_frame_host));
2986}
2987
2988void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2989 FOR_EACH_OBSERVER(WebContentsObserver,
2990 observers_,
2991 RenderFrameDeleted(render_frame_host));
2992}
2993
[email protected]a09d53ce2014-01-31 00:46:422994void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302995 if (delegate_)
2996 delegate_->WorkerCrashed(this);
2997}
2998
[email protected]a09d53ce2014-01-31 00:46:422999void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3000 const ContextMenuParams& params) {
3001 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:403002 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:423003 return;
3004
3005 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
3006}
3007
[email protected]87de04b02014-04-08 22:14:493008void WebContentsImpl::RunJavaScriptMessage(
3009 RenderFrameHost* rfh,
3010 const base::string16& message,
3011 const base::string16& default_prompt,
3012 const GURL& frame_url,
3013 JavaScriptMessageType javascript_message_type,
3014 IPC::Message* reply_msg) {
3015 // Suppress JavaScript dialogs when requested. Also suppress messages when
3016 // showing an interstitial as it's shown over the previous page and we don't
3017 // want the hidden page's dialogs to interfere with the interstitial.
3018 bool suppress_this_message =
3019 static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost())->
3020 IsSwappedOut() ||
3021 ShowingInterstitialPage() ||
3022 !delegate_ ||
3023 delegate_->ShouldSuppressDialogs() ||
3024 !delegate_->GetJavaScriptDialogManager();
3025
3026 if (!suppress_this_message) {
3027 std::string accept_lang = GetContentClient()->browser()->
3028 GetAcceptLangs(GetBrowserContext());
3029 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3030 dialog_manager_->RunJavaScriptDialog(
3031 this,
3032 frame_url.GetOrigin(),
3033 accept_lang,
3034 javascript_message_type,
3035 message,
3036 default_prompt,
3037 base::Bind(&WebContentsImpl::OnDialogClosed,
3038 base::Unretained(this),
3039 rfh,
3040 reply_msg,
3041 false),
3042 &suppress_this_message);
3043 }
3044
3045 if (suppress_this_message) {
3046 // If we are suppressing messages, just reply as if the user immediately
3047 // pressed "Cancel", passing true to |dialog_was_suppressed|.
3048 OnDialogClosed(rfh, reply_msg, true, false, base::string16());
3049 }
3050
3051 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3052 // http://crbug.com/288961 ). The only safe thing to do here is return.
3053}
3054
3055void WebContentsImpl::RunBeforeUnloadConfirm(
3056 RenderFrameHost* rfh,
3057 const base::string16& message,
3058 bool is_reload,
3059 IPC::Message* reply_msg) {
3060 RenderFrameHostImpl* rfhi = static_cast<RenderFrameHostImpl*>(rfh);
3061 RenderViewHostImpl* rvhi =
3062 static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost());
3063 if (delegate_)
3064 delegate_->WillRunBeforeUnloadConfirm();
3065
3066 bool suppress_this_message =
3067 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3068 !delegate_ ||
3069 delegate_->ShouldSuppressDialogs() ||
3070 !delegate_->GetJavaScriptDialogManager();
3071 if (suppress_this_message) {
3072 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3073 return;
3074 }
3075
3076 is_showing_before_unload_dialog_ = true;
3077 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3078 dialog_manager_->RunBeforeUnloadDialog(
3079 this, message, is_reload,
3080 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
3081 rfh, reply_msg, false));
3082}
3083
[email protected]a86c0e962013-12-17 17:10:393084WebContents* WebContentsImpl::GetAsWebContents() {
3085 return this;
3086}
3087
[email protected]5a3bdf52012-05-24 15:12:573088RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3089 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323090}
3091
[email protected]8ff00d72012-10-23 19:12:213092RendererPreferences WebContentsImpl::GetRendererPrefs(
3093 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463094 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513095}
3096
[email protected]b172aee2012-04-10 17:05:263097gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173098 if (delegate_)
3099 return delegate_->GetRootWindowResizerRect();
3100 return gfx::Rect();
3101}
3102
[email protected]7a846df2012-09-20 19:17:393103void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273104 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393105 browser_plugin_embedder_.reset();
3106}
3107
[email protected]b172aee2012-04-10 17:05:263108void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443109 // Don't send notifications if we are just creating a swapped-out RVH for
3110 // the opener chain. These won't be used for view-source or WebUI, so it's
3111 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243112 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443113 return;
3114
[email protected]86f98a22013-03-20 14:35:003115 if (delegate_)
3116 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083117
[email protected]8ff00d72012-10-23 19:12:213118 NotificationService::current()->Notify(
3119 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3120 Source<WebContents>(this),
3121 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323122
3123 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353124 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213125 if (GetRenderManager()->pending_web_ui())
3126 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323127
[email protected]6286a372013-10-09 04:03:273128 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333129 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323130 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183131 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583132 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323133 }
[email protected]0666aef2009-05-13 19:48:083134
[email protected]60780f412013-02-25 16:34:103135 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263136
3137 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253138 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583139
3140 // We tell the observers now instead of when the main RenderFrameHostImpl is
3141 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3142 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363143 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583144 FOR_EACH_OBSERVER(
3145 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323146}
3147
[email protected]b172aee2012-04-10 17:05:263148void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523149 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323150 // Don't notify the world, since this came from a renderer in the
3151 // background.
3152 return;
3153 }
3154
[email protected]da7a7182013-09-06 08:11:113155 notify_disconnection_ = true;
3156 // TODO(avi): Remove. http://crbug.com/170921
3157 NotificationService::current()->Notify(
3158 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3159 Source<WebContents>(this),
3160 NotificationService::NoDetails());
3161
[email protected]be1f56ab2011-12-22 06:55:313162 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233163 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303164
3165 // Restore the focus to the tab (otherwise the focus will be on the top
3166 // window).
[email protected]484ae5912010-09-29 19:16:143167 if (was_crashed && !FocusLocationBarByDefault() &&
3168 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063169 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143170 }
[email protected]32ded2212011-11-10 18:51:433171
[email protected]d8c660432011-12-22 20:51:253172 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323173}
3174
[email protected]ec6a7eb2013-04-22 17:34:223175void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3176 base::TerminationStatus status,
3177 int error_code) {
[email protected]151a63d2011-12-20 22:32:523178 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323179 // The pending page's RenderViewHost is gone.
3180 return;
3181 }
3182
[email protected]2fcdcc32014-03-05 02:14:073183 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3184 // renderer may not have made a clean exit.
3185 if (IsFullscreenForCurrentTab())
3186 ToggleFullscreenMode(false);
3187
[email protected]698191dc2014-02-25 01:06:133188 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3189 if (dialog_manager_)
3190 dialog_manager_->CancelActiveAndPendingDialogs(this);
3191
[email protected]d9030b82013-07-19 08:26:063192 ClearPowerSaveBlockers(rvh);
[email protected]e3b10d12014-03-28 16:06:093193 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323194 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233195 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:313196 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:323197
[email protected]d8c660432011-12-22 20:51:253198 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273199 observers_,
[email protected]58d5cfe2013-07-10 02:40:523200 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323201}
3202
[email protected]b172aee2012-04-10 17:05:263203void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:063204 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:213205 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:253206 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063207}
3208
[email protected]b172aee2012-04-10 17:05:263209void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3210 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043211 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153212 // Ensure that this state update comes from either the active RVH or one of
3213 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413214 // TODO(nasko): This should go through RenderFrameHost.
3215 // TODO(creis): We can't update state for cross-process subframes until we
3216 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3217 if (rvh != GetRenderViewHost() &&
3218 !GetRenderManager()->IsRVHOnSwappedOutList(
3219 static_cast<RenderViewHostImpl*>(rvh)))
3220 return;
[email protected]420ae012009-04-24 05:16:323221
3222 // We must be prepared to handle state updates for any page, these occur
3223 // when the user is scrolling and entering form data, as well as when we're
3224 // leaving a page, in which case our state may have already been moved to
3225 // the next page. The navigation controller will look up the appropriate
3226 // NavigationEntry and update it when it is notified via the delegate.
3227
3228 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583229 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323230 if (entry_index < 0)
3231 return;
[email protected]10f417c52011-12-28 21:04:233232 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323233
[email protected]691aa2f2013-05-28 22:52:043234 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323235 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043236 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323237 controller_.NotifyEntryChanged(entry, entry_index);
3238}
3239
[email protected]b172aee2012-04-10 17:05:263240void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3241 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263242 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263243 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323244 // If we have a title, that's a pretty good indication that we've started
3245 // getting useful data.
3246 SetNotWaitingForResponse();
3247
[email protected]73eb2602012-02-09 19:50:553248 // Try to find the navigation entry, which might not be the current one.
3249 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233250 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583251 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093252
[email protected]73eb2602012-02-09 19:50:553253 // We can handle title updates when we don't have an entry in
3254 // UpdateTitleForEntry, but only if the update is from the current RVH.
3255 if (!entry && rvh != GetRenderViewHost())
3256 return;
3257
[email protected]a49e10b2011-08-01 23:57:463258 // TODO(evan): make use of title_direction.
3259 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093260 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323261 return;
3262
3263 // Broadcast notifications when the UI should be updated.
3264 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213265 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323266}
3267
[email protected]b172aee2012-04-10 17:05:263268void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3269 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313270 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323271}
3272
[email protected]b172aee2012-04-10 17:05:263273void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513274 if (delegate_)
3275 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323276}
3277
[email protected]b172aee2012-04-10 17:05:263278void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103279#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293280 // The UI may be in an event-tracking loop, such as between the
3281 // mouse-down and mouse-up in text selection or a button click.
3282 // Defer the close until after tracking is complete, so that we
3283 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293284 // TODO(shess): This could get more fine-grained. For instance,
3285 // closing a tab in another window while selecting text in the
3286 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103287 if (view_->IsEventTracking()) {
3288 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293289 return;
3290 }
[email protected]60780f412013-02-25 16:34:103291#endif
[email protected]07707302009-11-06 00:50:293292
[email protected]420ae012009-04-24 05:16:323293 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523294 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513295 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323296}
3297
[email protected]66bbadaf2014-03-28 16:25:543298void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573299 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3300 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573301}
3302
[email protected]b172aee2012-04-10 17:05:263303void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513304 if (delegate_ && delegate_->IsPopupOrPanel(this))
3305 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323306}
3307
[email protected]e3b10d12014-03-28 16:06:093308void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3309 bool to_different_document) {
3310 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3311 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323312}
3313
[email protected]723971b2014-02-12 11:08:253314void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323315 scoped_ptr<LoadNotificationDetails> details;
3316
[email protected]9595fd82013-04-19 21:28:493317 // Use the last committed entry rather than the active one, in case a
3318 // pending entry has been created.
3319 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203320 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493321
[email protected]420ae012009-04-24 05:16:323322 // An entry may not exist for a stop when loading an initial blank page or
3323 // if an iframe injected by script into a blank page finishes loading.
3324 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203325 base::TimeDelta elapsed =
3326 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323327
3328 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513329 entry->GetVirtualURL(),
3330 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323331 elapsed,
3332 &controller_,
3333 controller_.GetCurrentEntryIndex()));
3334 }
3335
[email protected]e3b10d12014-03-28 16:06:093336 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3337 details.get());
[email protected]420ae012009-04-24 05:16:323338}
3339
[email protected]b172aee2012-04-10 17:05:263340void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163341 controller_.DiscardNonCommittedEntries();
3342
3343 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213344 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163345}
3346
[email protected]b172aee2012-04-10 17:05:263347void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513348 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133349 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403350}
3351
[email protected]7cc78902012-12-06 02:32:263352void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393353 if (opener_) {
3354 // Clear our opener so that future cross-process navigations don't have an
3355 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103356 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393357 opener_ = NULL;
3358 }
[email protected]7cc78902012-12-06 02:32:263359
3360 // Notify all swapped out RenderViewHosts for this tab. This is important
3361 // in case we go back to them, or if another window in those processes tries
3362 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213363 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263364}
3365
[email protected]59167c22013-06-03 18:07:323366void WebContentsImpl::DidAccessInitialDocument() {
3367 // Update the URL display.
3368 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3369}
3370
[email protected]87717d0e2012-04-26 02:58:433371void WebContentsImpl::DocumentAvailableInMainFrame(
3372 RenderViewHost* render_view_host) {
3373 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3374 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103375}
3376
[email protected]b172aee2012-04-10 17:05:263377void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083378 RenderViewHost* render_view_host,
3379 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093380 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3381 DocumentOnLoadCompletedInMainFrame(page_id));
3382
3383 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213384 NotificationService::current()->Notify(
3385 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3386 Source<WebContents>(this),
3387 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083388}
3389
[email protected]e1c3a552012-05-04 20:51:323390void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3391 // Tell the active RenderViewHost to run unload handlers and close, as long
3392 // as the request came from a RenderViewHost in the same BrowsingInstance.
3393 // In most cases, we receive this from a swapped out RenderViewHost.
3394 // It is possible to receive it from one that has just been swapped in,
3395 // in which case we might as well deliver the message anyway.
3396 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3397 GetRenderViewHost()->ClosePage();
3398}
3399
[email protected]f546640b2012-05-15 00:03:493400void WebContentsImpl::RouteMessageEvent(
3401 RenderViewHost* rvh,
3402 const ViewMsg_PostMessage_Params& params) {
3403 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363404 // came from a RenderViewHost in the same BrowsingInstance or if this
3405 // WebContents is dedicated to a browser plugin guest.
3406 // Note: This check means that an embedder could theoretically receive a
3407 // postMessage from anyone (not just its own guests). However, this is
3408 // probably not a risk for apps since other pages won't have references
3409 // to App windows.
3410 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3411 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493412 return;
3413
3414 ViewMsg_PostMessage_Params new_params(params);
3415
[email protected]0bc7f3542013-10-21 15:05:533416 if (!params.message_port_ids.empty()) {
3417 MessagePortMessageFilter* message_port_message_filter =
3418 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3419 ->message_port_message_filter();
3420 std::vector<int> new_routing_ids(params.message_port_ids.size());
3421 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3422 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3423 MessagePortService::GetInstance()->UpdateMessagePort(
3424 params.message_port_ids[i],
3425 message_port_message_filter,
3426 new_routing_ids[i]);
3427 }
3428 new_params.new_routing_ids = new_routing_ids;
3429 }
3430
[email protected]f546640b2012-05-15 00:03:493431 // If there is a source_routing_id, translate it to the routing ID for
3432 // the equivalent swapped out RVH in the target process. If we need
3433 // to create a swapped out RVH for the source tab, we create its opener
3434 // chain as well, since those will also be accessible to the target page.
3435 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3436 // Try to look up the WebContents for the source page.
3437 WebContentsImpl* source_contents = NULL;
3438 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3439 rvh->GetProcess()->GetID(), params.source_routing_id);
3440 if (source_rvh) {
3441 source_contents = static_cast<WebContentsImpl*>(
3442 source_rvh->GetDelegate()->GetAsWebContents());
3443 }
3444
3445 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363446 if (GetBrowserPluginGuest()) {
3447 // We create a swapped out RenderView for the embedder in the guest's
3448 // render process but we intentionally do not expose the embedder's
3449 // opener chain to it.
3450 new_params.source_routing_id =
3451 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3452 } else {
3453 new_params.source_routing_id =
3454 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3455 }
[email protected]f546640b2012-05-15 00:03:493456 } else {
3457 // We couldn't find it, so don't pass a source frame.
3458 new_params.source_routing_id = MSG_ROUTING_NONE;
3459 }
3460 }
3461
3462 // In most cases, we receive this from a swapped out RenderViewHost.
3463 // It is possible to receive it from one that has just been swapped in,
3464 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183465 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493466}
3467
[email protected]a796f202012-05-30 14:14:253468bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263469 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253470 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263471 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253472 if (!delegate_)
3473 return false;
3474 return delegate_->AddMessageToConsole(this, level, message, line_no,
3475 source_id);
3476}
3477
[email protected]b172aee2012-04-10 17:05:263478WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273479 // We want to base the page config off of the actual URL, rather than the
3480 // virtual URL.
3481 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3482 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003483 GURL url = controller_.GetActiveEntry()
3484 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153485
[email protected]fa944cb82013-11-15 17:51:213486 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323487}
3488
[email protected]0eba810b2012-10-18 03:19:363489int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213490 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413491 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3492 true, true);
[email protected]0eba810b2012-10-18 03:19:363493}
3494
[email protected]b172aee2012-04-10 17:05:263495void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273496 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253497 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223498
[email protected]ea114722012-03-12 01:11:253499 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173500 if (rdh) // NULL in unittests.
3501 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253502}
3503
[email protected]b172aee2012-04-10 17:05:263504void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443505 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253506 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443507}
3508
[email protected]b172aee2012-04-10 17:05:263509void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563510 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263511 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153512 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523513 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153514 return;
3515
[email protected]9f76c1e2012-03-05 15:15:583516 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3517
[email protected]e5fc1632011-08-08 07:51:533518 // Ignore renderer unresponsive event if debugger is attached to the tab
3519 // since the event may be a result of the renderer sitting on a breakpoint.
3520 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363521 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533522 return;
3523
[email protected]2e9d79f2013-08-16 05:45:563524 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323525 // Hang occurred while firing the beforeunload/unload handler.
3526 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583527 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323528
[email protected]fa944cb82013-11-15 17:51:213529 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323530 return;
3531
3532 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563533 // nothing we can do to recover. If the hang is in the beforeunload handler,
3534 // pretend the beforeunload listeners have all fired and allow the delegate
3535 // to continue closing; the user will not have the option of cancelling the
3536 // close. Otherwise, pretend the unload listeners have all fired and close
3537 // the tab.
3538 bool close = true;
3539 if (is_during_beforeunload) {
3540 delegate_->BeforeUnloadFired(this, true, &close);
3541 }
3542 if (close)
3543 Close(rvh);
[email protected]420ae012009-04-24 05:16:323544 return;
3545 }
3546
[email protected]9f76c1e2012-03-05 15:15:583547 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473548 return;
3549
[email protected]6934a702011-12-20 00:04:513550 if (delegate_)
3551 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323552}
3553
[email protected]b172aee2012-04-10 17:05:263554void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513555 if (delegate_)
3556 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323557}
3558
[email protected]b172aee2012-04-10 17:05:263559void WebContentsImpl::LoadStateChanged(
3560 const GURL& url,
3561 const net::LoadStateWithParam& load_state,
3562 uint64 upload_position,
3563 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323564 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563565 upload_position_ = upload_position;
3566 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503567 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213568 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303569 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213570 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323571 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463572 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213573 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463574 }
[email protected]420ae012009-04-24 05:16:323575}
3576
[email protected]b172aee2012-04-10 17:05:263577void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553578 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323579 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123580 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3581 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513582 if (delegate_)
3583 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093584 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323585}
3586
[email protected]58d5cfe2013-07-10 02:40:523587void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543588 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233589 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223590 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543591}
3592
[email protected]b172aee2012-04-10 17:05:263593void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103594 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213595 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263596 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3597 // here during container initialization and normal window size will be set
3598 // later. In case of tab duplication this resizing to 0x0 prevents setting
3599 // normal size later so just ignore it.
3600 if (!size.IsEmpty())
3601 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323602}
3603
[email protected]af905902013-10-01 21:38:513604void WebContentsImpl::CancelModalDialogsForRenderManager() {
3605 // We need to cancel modal dialogs when doing a process swap, since the load
3606 // deferrer would prevent us from swapping out.
3607 if (dialog_manager_)
3608 dialog_manager_->CancelActiveAndPendingDialogs(this);
3609}
3610
[email protected]7b712ee22013-10-03 00:57:283611void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3612 RenderViewHost* new_host) {
3613 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083614
3615 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003616 if (delegate_)
3617 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393618
[email protected]7b712ee22013-10-03 00:57:283619 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543620}
3621
[email protected]14392a52012-05-02 20:28:443622int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3623 SiteInstance* instance) {
3624 if (!opener_)
3625 return MSG_ROUTING_NONE;
3626
3627 // Recursively create RenderViews for anything else in the opener chain.
3628 return opener_->CreateOpenerRenderViews(instance);
3629}
3630
3631int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3632 int opener_route_id = MSG_ROUTING_NONE;
3633
3634 // If this tab has an opener, ensure it has a RenderView in the given
3635 // SiteInstance as well.
3636 if (opener_)
3637 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3638
[email protected]45a22ad2013-02-21 03:25:003639 // If any of the renderers (current, pending, or swapped out) for this
3640 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213641 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3642 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373643
[email protected]fa944cb82013-11-15 17:51:213644 if (GetRenderManager()->pending_render_view_host() &&
3645 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3646 instance)
3647 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003648
[email protected]fa944cb82013-11-15 17:51:213649 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373650 instance);
3651 if (rvh)
3652 return rvh->GetRoutingID();
3653
[email protected]14392a52012-05-02 20:28:443654 // Create a swapped out RenderView in the given SiteInstance if none exists,
3655 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413656 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3657 true, true);
[email protected]14392a52012-05-02 20:28:443658}
3659
[email protected]b172aee2012-04-10 17:05:263660NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193661 return GetController();
[email protected]3a3d47472010-07-15 21:03:543662}
3663
[email protected]b172aee2012-04-10 17:05:263664WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563665 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323666}
3667
[email protected]10f417c52011-12-28 21:04:233668NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263669 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323670 return controller_.GetLastCommittedEntry();
3671}
3672
[email protected]b172aee2012-04-10 17:05:263673bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163674 RenderViewHost* render_view_host,
3675 int opener_route_id,
3676 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033677 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443678 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163679 RenderWidgetHostView* rwh_view;
3680 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3681 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3682 // case this because RWH is still a base class of RenderViewHost, and child
3683 // frame RWHVs are unique in that they do not have their own WebContents.
3684 if (frame_connector) {
3685 RenderWidgetHostViewChildFrame* rwh_view_child =
3686 new RenderWidgetHostViewChildFrame(render_view_host);
3687 frame_connector->set_view(rwh_view_child);
3688 rwh_view = rwh_view_child;
3689 } else {
3690 rwh_view = view_->CreateViewForWidget(render_view_host);
3691 }
[email protected]1a98a932009-11-17 00:12:523692
[email protected]420ae012009-04-24 05:16:323693 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443694 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213695 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323696
[email protected]74ce1ad2011-12-16 21:51:463697 // Make sure we use the correct starting page_id in the new RenderView.
3698 UpdateMaxPageIDIfNecessary(render_view_host);
3699 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583700 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463701
[email protected]9f76c1e2012-03-05 15:15:583702 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263703 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493704 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133705 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523706 return false;
[email protected]14392a52012-05-02 20:28:443707 }
[email protected]a4127722011-04-27 23:13:523708
[email protected]a220b5932013-09-21 03:47:443709#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503710 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3711 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443712 if (rwh_view) {
3713 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3714 render_widget_host->WasResized();
3715 }
[email protected]f8233cc2011-05-31 20:24:503716#endif
3717
[email protected]420ae012009-04-24 05:16:323718 return true;
3719}
3720
[email protected]7d244f12013-08-22 21:41:513721#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183722base::android::ScopedJavaLocalRef<jobject>
3723WebContentsImpl::GetJavaWebContents() {
3724 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3725
3726 WebContentsAndroid* web_contents_android =
3727 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3728 if (!web_contents_android) {
3729 web_contents_android = new WebContentsAndroid(this);
3730 SetUserData(kWebContentsAndroidKey, web_contents_android);
3731 }
3732 return web_contents_android->GetJavaObject();
3733}
3734
[email protected]7d244f12013-08-22 21:41:513735bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3736 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163737 MSG_ROUTING_NONE,
3738 NULL);
[email protected]7d244f12013-08-22 21:41:513739}
3740#endif
3741
[email protected]87de04b02014-04-08 22:14:493742void WebContentsImpl::OnDialogClosed(RenderFrameHost* rfh,
[email protected]b172aee2012-04-10 17:05:263743 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493744 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263745 bool success,
[email protected]fcf75d42013-12-03 20:11:263746 const base::string16& user_input) {
[email protected]87de04b02014-04-08 22:14:493747 last_dialog_suppressed_ = dialog_was_suppressed;
3748
[email protected]beb440c2009-11-06 04:08:543749 if (is_showing_before_unload_dialog_ && !success) {
3750 // If a beforeunload dialog is canceled, we need to stop the throbber from
3751 // spinning, since we forced it to start spinning in Navigate.
[email protected]87de04b02014-04-08 22:14:493752 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353753 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103754
[email protected]6d65a462013-06-21 21:29:123755 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3756 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543757 }
[email protected]87de04b02014-04-08 22:14:493758
[email protected]beb440c2009-11-06 04:08:543759 is_showing_before_unload_dialog_ = false;
[email protected]87de04b02014-04-08 22:14:493760 static_cast<RenderFrameHostImpl*>(rfh)->JavaScriptDialogClosed(
3761 reply_msg, success, user_input, dialog_was_suppressed);
[email protected]beb440c2009-11-06 04:08:543762}
3763
[email protected]b172aee2012-04-10 17:05:263764void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213765 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123766 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103767}
[email protected]f45d2a72010-03-08 23:28:353768
[email protected]b172aee2012-04-10 17:05:263769void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103770 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443771 // Can be NULL during tests.
3772 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213773 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363774}
[email protected]9f76c1e2012-03-05 15:15:583775
[email protected]1ac10dca2013-08-20 20:47:043776bool WebContentsImpl::IsHidden() {
3777 return capturer_count_ == 0 && !should_normally_be_visible_;
3778}
3779
[email protected]b0936d22013-11-28 06:47:363780RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213781 return frame_tree_.root()->render_manager();
3782}
3783
[email protected]b172aee2012-04-10 17:05:263784RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583785 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3786}
[email protected]7900bfdb2012-05-24 19:31:243787
[email protected]f8497342013-02-05 22:15:023788BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393789 return browser_plugin_guest_.get();
3790}
3791
[email protected]738f57a2013-06-29 21:06:543792void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3793 CHECK(!browser_plugin_guest_);
3794 browser_plugin_guest_.reset(guest);
3795}
3796
[email protected]f8497342013-02-05 22:15:023797BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393798 return browser_plugin_embedder_.get();
3799}
[email protected]8ff00d72012-10-23 19:12:213800
[email protected]8eb04562013-03-06 03:41:143801BrowserPluginGuestManager*
3802 WebContentsImpl::GetBrowserPluginGuestManager() const {
3803 return static_cast<BrowserPluginGuestManager*>(
3804 GetBrowserContext()->GetUserData(
3805 browser_plugin::kBrowserPluginGuestManagerKeyName));
3806}
3807
[email protected]d9030b82013-07-19 08:26:063808void WebContentsImpl::ClearPowerSaveBlockers(
3809 RenderViewHost* render_view_host) {
3810 STLDeleteValues(&power_save_blockers_[render_view_host]);
3811 power_save_blockers_.erase(render_view_host);
3812}
3813
3814void WebContentsImpl::ClearAllPowerSaveBlockers() {
3815 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3816 i != power_save_blockers_.end(); ++i)
3817 STLDeleteValues(&power_save_blockers_[i->first]);
3818 power_save_blockers_.clear();
3819}
3820
[email protected]dc0fd432013-08-27 15:29:213821gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3822 gfx::Size size;
3823 if (delegate_)
3824 size = delegate_->GetSizeForNewRenderView(this);
3825 if (size.IsEmpty())
3826 size = view_->GetContainerSize();
3827 return size;
3828}
3829
[email protected]9b159a52013-10-03 17:24:553830void WebContentsImpl::OnFrameRemoved(
3831 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583832 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553833 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583834 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553835}
3836
[email protected]222f5822014-02-05 23:40:493837void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3838 if (!delegate_)
3839 return;
3840 const gfx::Size new_size = GetPreferredSize();
3841 if (new_size != old_size)
3842 delegate_->UpdatePreferredSize(this, new_size);
3843}
3844
[email protected]8ff00d72012-10-23 19:12:213845} // namespace content