blob: ab4cde80bee1bd670791f1daab6ac51d35f11843 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/browser_plugin/browser_plugin_embedder.h"
22#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]8eb04562013-03-06 03:41:1423#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
[email protected]b9535422012-02-09 01:47:5924#include "content/browser/child_process_security_policy_impl.h"
[email protected]49413ca52014-03-05 14:13:4325#include "content/browser/devtools/render_view_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4126#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0427#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4628#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1229#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1630#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1631#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4032#include "content/browser/frame_host/interstitial_page_impl.h"
33#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0134#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1835#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1636#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]5c9250872012-01-30 17:24:0537#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4438#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5339#include "content/browser/message_port_message_filter.h"
40#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0641#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3042#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3243#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5044#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3345#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1146#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5847#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0348#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5649#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1450#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4251#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4452#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0253#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1754#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5155#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0256#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5757#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5858#include "content/port/browser/render_widget_host_view_port.h"
[email protected]31a71eaf2014-03-13 01:47:3659#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1160#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2061#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4462#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3663#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1764#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1465#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4666#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1567#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0068#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2769#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0070#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3771#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1472#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3273#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3474#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3875#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4276#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2577#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1078#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2179#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4880#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5481#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4982#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2083#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0384#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5785#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1686#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2987#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5388#include "net/http/http_cache.h"
89#include "net/http/http_transaction_factory.h"
90#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3491#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5692#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0193#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4194#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5295#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1896#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3197
[email protected]583418cc2013-01-17 14:01:1098#if defined(OS_ANDROID)
99#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:32100#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]155c7f22013-12-09 17:07:18101#include "content/browser/web_contents/web_contents_android.h"
[email protected]a794f3a2013-10-30 17:00:32102#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:00103#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10104#endif
105
[email protected]f66df822012-05-18 16:52:17106#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50107#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27108#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57109#endif
[email protected]3e45ba92009-02-20 21:09:00110
[email protected]420ae012009-04-24 05:16:32111// Cross-Site Navigations
112//
[email protected]b172aee2012-04-10 17:05:26113// If a WebContentsImpl is told to navigate to a different web site (as
114// determined by SiteInstance), it will replace its current RenderViewHost with
115// a new RenderViewHost dedicated to the new SiteInstance. This works as
116// follows:
[email protected]420ae012009-04-24 05:16:32117//
[email protected]fc6c1872013-10-03 01:22:35118// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46119// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32120// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35121// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32122// run in the current RVH.
123// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35124// that it has a pending cross-site request. We will check this on the IO
125// thread when deciding how to handle the response.
126// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46127// cancel all the pending logic. Otherwise we allow the pending RVH to send
128// the navigation request to its renderer.
129// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35130// main resource load on the pending RVH. It creates a
131// CrossSiteResourceHandler to check whether a process swap is needed when
132// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46133// - When RDH receives a response, the BufferedResourceHandler determines
134// whether it is a download. If so, it sends a message to the new renderer
135// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26136// pending RVH remains until the next DidNavigate event for this
137// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32138// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35139// download, the CrossSiteResourceHandler checks whether a process swap is
140// needed (either because CrossSiteRequestManager has state for it or because
141// a transfer was needed for a redirect).
142// - If so, CrossSiteResourceHandler pauses the response to first run the old
143// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36144// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
145// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35146// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
147// to a new process is needed, based on the stored pending_nav_params_. (This
148// is independent of whether we started out with a cross-process navigation.)
149// - If not, it just tells the ResourceDispatcherHost to resume the response
150// to its current RenderViewHost.
151// - If so, it cancels the current pending RenderViewHost and sets up a new
152// navigation using RequestTransferURL. When the transferred request
153// arrives in the ResourceDispatcherHost, we transfer the response and
154// resume it.
[email protected]420ae012009-04-24 05:16:32155// - The pending renderer sends a FrameNavigate message that invokes the
156// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46157// pending RVH.
[email protected]b0936d22013-11-28 06:47:36158// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15159// the user goes back. The process only stays live if another tab is using
160// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32161
[email protected]8ff00d72012-10-23 19:12:21162namespace content {
[email protected]420ae012009-04-24 05:16:32163namespace {
164
[email protected]82114f52012-03-20 22:53:41165const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05166
[email protected]155c7f22013-12-09 17:07:18167#if defined(OS_ANDROID)
168const char kWebContentsAndroidKey[] = "web_contents_android";
169#endif // OS_ANDROID
170
[email protected]e4abd3b42013-11-12 18:28:47171base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46172g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
173
[email protected]988ed7132014-03-31 16:25:58174static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39175 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29176 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30177 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02178 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58179 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02180 ++g_next_image_download_id,
181 url,
182 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30183 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02184 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39185}
186
[email protected]8bfc8272013-09-09 20:10:53187void NotifyCacheOnIO(
188 scoped_refptr<net::URLRequestContextGetter> request_context,
189 const GURL& url,
190 const std::string& http_method) {
191 request_context->GetURLRequestContext()->http_transaction_factory()->
192 GetCache()->OnExternalCacheHit(url, http_method);
193}
194
[email protected]9b159a52013-10-03 17:24:55195// Helper function for retrieving all the sites in a frame tree.
196bool CollectSites(BrowserContext* context,
197 std::set<GURL>* sites,
198 FrameTreeNode* node) {
199 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
200 return true;
201}
202
[email protected]a86c0e962013-12-17 17:10:39203bool ForEachFrameInternal(
204 const base::Callback<void(RenderFrameHost*)>& on_frame,
205 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41206 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39207 return true;
208}
209
[email protected]c06c58c2014-03-12 20:31:59210bool ForEachPendingFrameInternal(
211 const base::Callback<void(RenderFrameHost*)>& on_frame,
212 FrameTreeNode* node) {
213 RenderFrameHost* pending_frame_host =
214 node->render_manager()->pending_frame_host();
215 if (pending_frame_host)
216 on_frame.Run(pending_frame_host);
217 return true;
218}
219
[email protected]a86c0e962013-12-17 17:10:39220void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
221 IPC::Message* message_copy = new IPC::Message(*message);
222 message_copy->set_routing_id(rfh->GetRoutingID());
223 rfh->Send(message_copy);
224}
225
[email protected]c06c58c2014-03-12 20:31:59226void RunRenderFrameDeleted(
227 ObserverList<WebContentsObserver>* observer_list,
228 RenderFrameHost* render_frame_host) {
229 FOR_EACH_OBSERVER(WebContentsObserver,
230 *observer_list,
231 RenderFrameDeleted(render_frame_host));
232}
233
[email protected]420ae012009-04-24 05:16:32234} // namespace
235
[email protected]54944cde2012-12-09 09:24:59236WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15237 return WebContentsImpl::CreateWithOpener(
238 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19239}
240
241WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59242 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30243 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59244 WebContentsImpl* new_contents = new WebContentsImpl(
245 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30246
247 for (SessionStorageNamespaceMap::const_iterator it =
248 session_storage_namespace_map.begin();
249 it != session_storage_namespace_map.end();
250 ++it) {
251 new_contents->GetController()
252 .SetSessionStorageNamespace(it->first, it->second.get());
253 }
254
[email protected]54944cde2012-12-09 09:24:59255 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19256 return new_contents;
[email protected]a81343d232011-12-27 07:39:20257}
[email protected]746d3052012-05-22 15:15:47258
[email protected]e4abd3b42013-11-12 18:28:47259void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46260 g_created_callbacks.Get().push_back(callback);
261}
262
[email protected]e4abd3b42013-11-12 18:28:47263void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46264 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
265 if (g_created_callbacks.Get().at(i).Equals(callback)) {
266 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
267 return;
268 }
269 }
270}
271
[email protected]299d7f12012-05-23 05:31:15272WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47273 return rvh->GetDelegate()->GetAsWebContents();
274}
275
[email protected]a86c0e962013-12-17 17:10:39276WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
277 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
278 if (!rfh_impl)
279 return NULL;
280 return rfh_impl->delegate()->GetAsWebContents();
281}
282
[email protected]7fff43e2013-05-21 20:21:10283// WebContentsImpl::DestructionObserver ----------------------------------------
284
285class WebContentsImpl::DestructionObserver : public WebContentsObserver {
286 public:
287 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
288 : WebContentsObserver(watched_contents),
289 owner_(owner) {
290 }
291
292 // WebContentsObserver:
293 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
294 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
295 }
296
297 private:
298 WebContentsImpl* owner_;
299
300 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
301};
302
[email protected]b172aee2012-04-10 17:05:26303// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32304
[email protected]b172aee2012-04-10 17:05:26305WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21306 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19307 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42308 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22309 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57310 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44311 opener_(opener),
[email protected]2ceee8f2014-01-14 18:02:08312#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41313 accessible_parent_(NULL),
314#endif
[email protected]6ea6bdf2013-12-06 13:35:01315 frame_tree_(new NavigatorImpl(&controller_, this),
316 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34317 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23318 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
319 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34320 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26321 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56322 upload_size_(0),
323 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47324 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55325 capturer_count_(0),
326 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57327 is_being_destroyed_(false),
328 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15329 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01330 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02331 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38332 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21333 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
334 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00335 temporary_zoom_settings_(false),
[email protected]bab38af2014-03-30 17:37:29336 totalPinchGestureAmount_(0),
337 currentPinchZoomStepDelta_(0),
[email protected]cb805452013-05-22 15:16:21338 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44339 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42340 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
341 is_subframe_(false) {
[email protected]cbb1ef592013-06-05 19:49:46342 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
343 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55344 frame_tree_.SetFrameRemoveListener(
345 base::Bind(&WebContentsImpl::OnFrameRemoved,
346 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35347}
initial.commit09911bf2008-07-26 23:55:29348
[email protected]b172aee2012-04-10 17:05:26349WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32350 is_being_destroyed_ = true;
351
[email protected]21b41c7e892014-02-28 01:52:24352 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
353 // shutdown and be deleted as well.
354 frame_tree_.ForEach(
355 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
356
[email protected]d9030b82013-07-19 08:26:06357 ClearAllPowerSaveBlockers();
358
[email protected]b24b68a2012-09-24 21:57:26359 for (std::set<RenderWidgetHostImpl*>::iterator iter =
360 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
361 (*iter)->DetachDelegate();
362 }
363 created_widgets_.clear();
364
[email protected]3ab9cb82011-06-03 18:02:07365 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15366 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11367 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07368
[email protected]da8543762012-03-20 08:52:20369 if (color_chooser_)
370 color_chooser_->End();
371
[email protected]420ae012009-04-24 05:16:32372 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32373
[email protected]ca13a442012-04-17 14:00:12374 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21375 NotificationService::current()->Notify(
376 NOTIFICATION_WEB_CONTENTS_DESTROYED,
377 Source<WebContents>(this),
378 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32379
[email protected]c06c58c2014-03-12 20:31:59380 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
381 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
382 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
383 run_render_frame_deleted_callback));
384
[email protected]fa944cb82013-11-15 17:51:21385 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27386 if (pending_rvh) {
387 FOR_EACH_OBSERVER(WebContentsObserver,
388 observers_,
389 RenderViewDeleted(pending_rvh));
390 }
391
[email protected]c06c58c2014-03-12 20:31:59392 ForEachFrame(run_render_frame_deleted_callback);
393
[email protected]f273ee52013-10-18 16:05:27394 FOR_EACH_OBSERVER(WebContentsObserver,
395 observers_,
[email protected]fa944cb82013-11-15 17:51:21396 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27397
[email protected]2db9bd72012-04-13 20:20:56398 FOR_EACH_OBSERVER(WebContentsObserver,
399 observers_,
400 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08401
[email protected]6934a702011-12-20 00:04:51402 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10403
404 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
405 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42406}
407
[email protected]d1198fd2012-08-13 22:50:19408WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59409 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19410 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03411 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59412 WebContentsImpl* new_contents = new WebContentsImpl(
413 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19414
[email protected]54944cde2012-12-09 09:24:59415 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19416 return new_contents;
417}
418
[email protected]b371a5652013-02-20 11:25:51419// static
[email protected]8eb04562013-03-06 03:41:14420BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36421 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53422 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54423 int guest_instance_id,
424 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39425 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39426
427 // This makes |new_contents| act as a guest.
428 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54429 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19430 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11431
[email protected]3de10bb32013-01-08 21:57:33432 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33433 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11434
[email protected]216be772013-01-25 00:22:27435 // We are instantiating a WebContents for browser plugin. Set its subframe bit
436 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42437 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27438
[email protected]8eb04562013-03-06 03:41:14439 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39440}
441
[email protected]b0936d22013-11-28 06:47:36442RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21443 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28444}
445
[email protected]7bb761892012-07-20 09:32:47446bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
447 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44448 return OnMessageReceived(render_view_host, NULL, message);
449}
450
451bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
452 RenderFrameHost* render_frame_host,
453 const IPC::Message& message) {
454 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56455 if (GetWebUI() &&
456 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17457 return true;
[email protected]d2353452012-01-19 19:53:56458 }
[email protected]f82d57b52011-04-27 19:13:17459
[email protected]d8c660432011-12-22 20:51:25460 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
461 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10462 while ((observer = it.GetNext()) != NULL)
463 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53464 return true;
[email protected]403415a2011-01-10 18:57:53465
[email protected]1d62cf72014-02-07 21:31:57466 // Message handlers should be aware of which
467 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
468 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43469 if (render_frame_host) {
470 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
471 render_frame_host->GetRenderViewHost(), message))
472 return true;
[email protected]1d62cf72014-02-07 21:31:57473 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43474 } else {
475 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
476 render_view_host, message))
477 return true;
[email protected]1d62cf72014-02-07 21:31:57478 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43479 }
[email protected]1d62cf72014-02-07 21:31:57480
[email protected]724159a2010-12-30 01:11:18481 bool handled = true;
482 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26483 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44484 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
485 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40486 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
487 OnDomOperationResponse)
[email protected]724159a2010-12-30 01:11:18488 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
489 OnDidLoadResourceFromMemoryCache)
490 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
491 OnDidDisplayInsecureContent)
492 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
493 OnDidRunInsecureContent)
[email protected]1d62cf72014-02-07 21:31:57494 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
[email protected]724159a2010-12-30 01:11:18495 OnDocumentLoadedInFrame)
[email protected]028053d42014-03-05 22:20:37496 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]7d472472011-01-22 01:30:25497 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26498 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21499 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20500 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
501 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16502 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10503 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20504 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
505 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
506 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
507 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50508 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50509 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
510 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55511 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
512 OnBrowserPluginMessage(message))
513 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
514 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02515 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
516 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10517#if defined(OS_ANDROID)
518 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
519 OnFindMatchRectsReply)
520 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
521 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32522 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
523 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10524#endif
[email protected]1dd0bb752014-02-01 01:16:26525 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
526 OnMediaPlayingNotification)
527 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
528 OnMediaPausedNotification)
[email protected]9f268072013-11-07 00:02:15529 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
530 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07531 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
532 OnShowValidationMessage)
533 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
534 OnHideValidationMessage)
535 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
536 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18537 IPC_MESSAGE_UNHANDLED(handled = false)
538 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44539 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57540 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18541
542 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39543 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18544 GetRenderProcessHost()->ReceivedBadMessage();
545 }
546
547 return handled;
548}
549
[email protected]b172aee2012-04-10 17:05:26550void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18551 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21552 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43553 if (delegate_)
554 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18555}
556
[email protected]d1198fd2012-08-13 22:50:19557NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56558 return controller_;
559}
560
[email protected]d1198fd2012-08-13 22:50:19561const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56562 return controller_;
563}
564
[email protected]8ff00d72012-10-23 19:12:21565BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55566 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30567}
568
[email protected]b172aee2012-04-10 17:05:26569const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24570 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32571 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51572 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31573}
574
[email protected]a093ce02013-07-22 20:53:14575const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24576 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32577 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24578 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
579}
580
581const GURL& WebContentsImpl::GetLastCommittedURL() const {
582 // We may not have a navigation entry yet.
583 NavigationEntry* entry = controller_.GetLastCommittedEntry();
584 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
585}
586
[email protected]8ff00d72012-10-23 19:12:21587WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31588 return delegate_;
589}
590
[email protected]8ff00d72012-10-23 19:12:21591void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31592 // TODO(cbentzel): remove this debugging code?
593 if (delegate == delegate_)
594 return;
595 if (delegate_)
596 delegate_->Detach(this);
597 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08598 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31599 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08600 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00601 if (view_)
602 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08603 }
[email protected]be1f56ab2011-12-22 06:55:31604}
605
[email protected]8ff00d72012-10-23 19:12:21606RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21607 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41608 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16609}
610
[email protected]60eca4eb2013-12-06 00:02:16611RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41612 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16613}
614
[email protected]9c9343b2014-03-08 02:56:07615RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
616 if (!frame_tree_.GetFocusedFrame())
617 return NULL;
618 return frame_tree_.GetFocusedFrame()->current_frame_host();
619}
620
[email protected]a86c0e962013-12-17 17:10:39621void WebContentsImpl::ForEachFrame(
622 const base::Callback<void(RenderFrameHost*)>& on_frame) {
623 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
624}
625
626void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
627 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
628 delete message;
629}
630
[email protected]b172aee2012-04-10 17:05:26631RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21632 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31633}
634
[email protected]bfcfa692013-02-07 06:17:02635WebContents* WebContentsImpl::GetEmbedderWebContents() const {
636 BrowserPluginGuest* guest = GetBrowserPluginGuest();
637 if (guest)
638 return guest->embedder_web_contents();
639 return NULL;
640}
641
642int WebContentsImpl::GetEmbeddedInstanceID() const {
643 BrowserPluginGuest* guest = GetBrowserPluginGuest();
644 if (guest)
645 return guest->instance_id();
646 return 0;
647}
648
[email protected]6b618e62012-08-16 12:59:18649int WebContentsImpl::GetRoutingID() const {
650 if (!GetRenderViewHost())
651 return MSG_ROUTING_NONE;
652
653 return GetRenderViewHost()->GetRoutingID();
654}
655
[email protected]44470a22013-01-24 01:21:54656int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
657 return fullscreen_widget_routing_id_;
658}
659
[email protected]b172aee2012-04-10 17:05:26660RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21661 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31662}
663
[email protected]f8497342013-02-05 22:15:02664RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
665 BrowserPluginGuest* guest = GetBrowserPluginGuest();
666 if (guest && guest->embedder_web_contents()) {
667 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
668 }
669 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
670}
671
[email protected]4aebbca2013-09-17 22:26:49672RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
673 const {
674 RenderWidgetHost* const widget_host =
675 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
676 GetFullscreenWidgetRoutingID());
677 return widget_host ? widget_host->GetView() : NULL;
678}
679
[email protected]8ff00d72012-10-23 19:12:21680WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31681 return view_.get();
682}
683
[email protected]8ff00d72012-10-23 19:12:21684WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56685 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03686 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
687 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22688 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58689 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22690 web_ui->SetController(controller);
691 return web_ui;
692 }
693
694 delete web_ui;
695 return NULL;
696}
697
[email protected]8ff00d72012-10-23 19:12:21698WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21699 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
700 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31701}
702
[email protected]8ff00d72012-10-23 19:12:21703WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21704 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34705}
706
[email protected]86ef6a392012-05-11 22:03:11707void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22708 if (GetUserAgentOverride() == override)
709 return;
710
711 renderer_preferences_.user_agent_override = override;
712
713 // Send the new override string to the renderer.
714 RenderViewHost* host = GetRenderViewHost();
715 if (host)
716 host->SyncRendererPrefs();
717
718 // Reload the page if a load is currently in progress to avoid having
719 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27720 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22721 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
722 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53723
724 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
725 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11726}
727
728const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22729 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11730}
731
[email protected]2ceee8f2014-01-14 18:02:08732#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41733void WebContentsImpl::SetParentNativeViewAccessible(
734gfx::NativeViewAccessible accessible_parent) {
735 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45736 if (GetRenderViewHost())
737 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41738}
739#endif
740
[email protected]fcf75d42013-12-03 20:11:26741const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55742 // Transient entries take precedence. They are used for interstitial pages
743 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23744 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08745 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21746 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30747 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23748 if (entry) {
[email protected]b5cca982011-05-26 04:42:08749 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23750 }
[email protected]fa944cb82013-11-15 17:51:21751 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
752 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58753 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54754 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32755 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54756 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35757 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26758 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54759 if (!title.empty())
760 return title;
761 }
762 }
763
764 // We use the title for the last committed entry rather than a pending
765 // navigation entry. For example, when the user types in a URL, we want to
766 // keep the old page's title until the new load has committed and we get a new
767 // title.
[email protected]96d185d2009-04-24 03:28:54768 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32769
[email protected]9eeafc012013-11-25 23:49:47770 // We make an exception for initial navigations.
771 if (controller_.IsInitialNavigation()) {
772 // We only want to use the title from the visible entry in one of two cases:
773 // 1. There's already a committed entry for an initial navigation, in which
774 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
775 // 2. The pending entry has been explicitly assigned a title to display.
776 //
777 // If there's no last committed entry and no assigned title, we should fall
778 // back to |page_title_when_no_navigation_entry_| rather than showing the
779 // URL.
780 if (entry ||
781 (controller_.GetVisibleEntry() &&
782 !controller_.GetVisibleEntry()->GetTitle().empty())) {
783 entry = controller_.GetVisibleEntry();
784 }
785 }
[email protected]59167c22013-06-03 18:07:32786
[email protected]45d0ef7f2011-01-05 13:46:23787 if (entry) {
[email protected]b5cca982011-05-26 04:42:08788 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23789 }
[email protected]987fc3a2011-05-26 14:18:09790
791 // |page_title_when_no_navigation_entry_| is finally used
792 // if no title cannot be retrieved.
793 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54794}
795
[email protected]b172aee2012-04-10 17:05:26796int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46797 return GetMaxPageIDForSiteInstance(GetSiteInstance());
798}
799
[email protected]b172aee2012-04-10 17:05:26800int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
801 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33802 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
803 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46804
[email protected]b6583592012-01-25 19:52:33805 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34806}
807
[email protected]b172aee2012-04-10 17:05:26808void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46809 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
810}
811
[email protected]b172aee2012-04-10 17:05:26812void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33813 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46814 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33815 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34816}
817
[email protected]ec6c05f2013-10-23 18:41:57818void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
819 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
820 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57821}
822
[email protected]b172aee2012-04-10 17:05:26823SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21824 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54825}
826
[email protected]b172aee2012-04-10 17:05:26827SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21828 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
829 GetRenderManager()->pending_render_view_host() :
830 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58831 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38832}
833
[email protected]b172aee2012-04-10 17:05:26834bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31835 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49836}
837
[email protected]b172aee2012-04-10 17:05:26838bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31839 return waiting_for_response_;
840}
841
[email protected]b172aee2012-04-10 17:05:26842const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31843 return load_state_;
844}
845
[email protected]fcf75d42013-12-03 20:11:26846const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31847 return load_state_host_;
848}
849
[email protected]b172aee2012-04-10 17:05:26850uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31851 return upload_size_;
852}
853
[email protected]b172aee2012-04-10 17:05:26854uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31855 return upload_position_;
856}
857
[email protected]1ae93fb2013-06-14 03:38:56858std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56859 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39860 frame_tree_.ForEach(base::Bind(&CollectSites,
861 base::Unretained(GetBrowserContext()),
862 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56863 return sites;
864}
865
[email protected]b172aee2012-04-10 17:05:26866const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31867 return encoding_;
868}
869
[email protected]b172aee2012-04-10 17:05:26870bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31871 return displayed_insecure_content_;
872}
873
[email protected]222f5822014-02-05 23:40:49874void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25875 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55876 ++capturer_count_;
877 DVLOG(1) << "There are now " << capturer_count_
878 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49879
880 // Note: This provides a hint to upstream code to size the views optimally
881 // for quality (e.g., to avoid scaling).
882 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
883 preferred_size_for_capture_ = capture_size;
884 OnPreferredSizeChanged(preferred_size_);
885 }
[email protected]54597982013-02-06 01:59:55886}
887
888void WebContentsImpl::DecrementCapturerCount() {
889 --capturer_count_;
890 DVLOG(1) << "There are now " << capturer_count_
891 << " capturing(s) of WebContentsImpl@" << this;
892 DCHECK_LE(0, capturer_count_);
893
[email protected]5a652232013-02-12 06:15:25894 if (is_being_destroyed_)
895 return;
896
[email protected]222f5822014-02-05 23:40:49897 if (capturer_count_ == 0) {
898 const gfx::Size old_size = preferred_size_for_capture_;
899 preferred_size_for_capture_ = gfx::Size();
900 OnPreferredSizeChanged(old_size);
901 }
902
[email protected]1ac10dca2013-08-20 20:47:04903 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55904 DVLOG(1) << "Executing delayed WasHidden().";
905 WasHidden();
906 }
[email protected]be1f56ab2011-12-22 06:55:31907}
908
[email protected]f2bd40812013-07-20 04:30:44909int WebContentsImpl::GetCapturerCount() const {
910 return capturer_count_;
911}
912
[email protected]b172aee2012-04-10 17:05:26913bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31914 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
915 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
916 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49917}
918
[email protected]b172aee2012-04-10 17:05:26919void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
920 int error_code) {
[email protected]443b80e2010-12-14 00:42:23921 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34922 return;
923
[email protected]443b80e2010-12-14 00:42:23924 crashed_status_ = status;
925 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21926 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34927}
928
[email protected]b172aee2012-04-10 17:05:26929base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31930 return crashed_status_;
931}
932
[email protected]b172aee2012-04-10 17:05:26933bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31934 return is_being_destroyed_;
935}
936
[email protected]b172aee2012-04-10 17:05:26937void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34938 if (delegate_)
939 delegate_->NavigationStateChanged(this, changed_flags);
940}
941
[email protected]9a890452014-02-13 22:21:02942base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
943 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33944}
945
[email protected]9e2e4632012-07-27 16:38:41946void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54947 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04948 RenderWidgetHostViewPort* rwhv =
949 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16950 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29951 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43952#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16953 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43954#endif
955 }
[email protected]96d185d2009-04-24 03:28:54956
[email protected]9a890452014-02-13 22:21:02957 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38958
[email protected]b9769d82012-02-10 00:23:59959 // The resize rect might have changed while this was inactive -- send the new
960 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58961 RenderViewHostImpl* rvh =
962 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59963 if (rvh) {
964 rvh->ResizeRectChanged(GetRootWindowResizerRect());
965 }
[email protected]96d185d2009-04-24 03:28:54966
[email protected]c0d9d5672013-10-09 07:38:03967 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
968
[email protected]54597982013-02-06 01:59:55969 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31970}
971
[email protected]b172aee2012-04-10 17:05:26972void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55973 // If there are entities capturing screenshots or video (e.g., mirroring),
974 // don't activate the "disable rendering" optimization.
975 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52976 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55977 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26978 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52979 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33980 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52981 // calls us).
[email protected]c30585c2012-02-16 15:02:04982 RenderWidgetHostViewPort* rwhv =
983 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16984 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29985 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54986 }
987
[email protected]c0d9d5672013-10-09 07:38:03988 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
989
[email protected]54597982013-02-06 01:59:55990 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37991}
992
[email protected]b172aee2012-04-10 17:05:26993bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31994 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27995 return WillNotifyDisconnection() &&
996 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58997 !static_cast<RenderViewHostImpl*>(
998 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31999}
1000
[email protected]b172aee2012-04-10 17:05:261001void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211002 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401003 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271004}
1005
[email protected]b172aee2012-04-10 17:05:261006WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441007 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451008 // We pass our own opener so that the cloned page can access it if it was
1009 // before.
[email protected]54944cde2012-12-09 09:24:591010 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451011 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591012 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191013 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221014 FOR_EACH_OBSERVER(WebContentsObserver,
1015 observers_,
1016 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271017 return tc;
1018}
1019
[email protected]14392a52012-05-02 20:28:441020void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211021 const NotificationSource& source,
1022 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441023 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211024 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1025 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501026 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1027 i != pending_widget_views_.end(); ++i) {
1028 if (host->GetView() == i->second) {
1029 pending_widget_views_.erase(i);
1030 break;
1031 }
1032 }
1033 break;
1034 }
[email protected]14392a52012-05-02 20:28:441035 default:
1036 NOTREACHED();
1037 }
1038}
1039
[email protected]ec6c05f2013-10-23 18:41:571040WebContents* WebContentsImpl::GetWebContents() {
1041 return this;
1042}
1043
[email protected]54944cde2012-12-09 09:24:591044void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211045 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361046 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211047 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431048 should_normally_be_visible_ = !params.initially_hidden;
1049
[email protected]fa944cb82013-11-15 17:51:211050 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041051 params.browser_context, params.site_instance, params.routing_id,
1052 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191053
[email protected]8ff00d72012-10-23 19:12:211054 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191055 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271056 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191057 CHECK(render_view_host_delegate_view_);
1058 } else {
[email protected]f8497342013-02-05 22:15:021059 WebContentsViewDelegate* delegate =
1060 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1061
[email protected]59383c782013-04-17 16:43:271062 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381063 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1064 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021065
[email protected]b5a40842012-11-28 15:26:111066 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381067 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431068 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111069 render_view_host_delegate_view_ = rv;
1070 view_.reset(rv);
1071 } else {
[email protected]f8497342013-02-05 22:15:021072 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111073 view_.reset(CreateWebContentsView(
1074 this, delegate, &render_view_host_delegate_view_));
1075 }
[email protected]d1198fd2012-08-13 22:50:191076 CHECK(render_view_host_delegate_view_);
1077 }
1078 CHECK(view_.get());
1079
[email protected]ed245db2012-12-18 08:00:451080 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591081 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191082
1083 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101084 if (opener_)
1085 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191086
1087 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211088 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1089 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441090#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191091 java_bridge_dispatcher_host_manager_.reset(
1092 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101093 date_time_chooser_.reset(new DateTimeChooserAndroid());
1094#endif
[email protected]d1198fd2012-08-13 22:50:191095}
1096
[email protected]7fff43e2013-05-21 20:21:101097void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1098 RemoveDestructionObserver(web_contents);
1099
[email protected]14392a52012-05-02 20:28:441100 // Clear the opener if it has been closed.
1101 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441102 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511103 return;
[email protected]14392a52012-05-02 20:28:441104 }
[email protected]ceee8cd2013-03-08 04:59:511105 // Clear a pending contents that has been closed before being shown.
1106 for (PendingContents::iterator iter = pending_contents_.begin();
1107 iter != pending_contents_.end();
1108 ++iter) {
1109 if (iter->second != web_contents)
1110 continue;
1111 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511112 return;
1113 }
1114 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441115}
1116
[email protected]7fff43e2013-05-21 20:21:101117void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1118 if (!ContainsKey(destruction_observers_, web_contents)) {
1119 destruction_observers_[web_contents] =
1120 new DestructionObserver(this, web_contents);
1121 }
1122}
1123
1124void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1125 DestructionObservers::iterator iter =
1126 destruction_observers_.find(web_contents);
1127 if (iter != destruction_observers_.end()) {
1128 delete destruction_observers_[web_contents];
1129 destruction_observers_.erase(iter);
1130 }
1131}
1132
[email protected]b172aee2012-04-10 17:05:261133void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311134 observers_.AddObserver(observer);
1135}
1136
[email protected]b172aee2012-04-10 17:05:261137void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311138 observers_.RemoveObserver(observer);
1139}
1140
[email protected]b172aee2012-04-10 17:05:261141void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341142 if (delegate_)
1143 delegate_->ActivateContents(this);
1144}
1145
[email protected]b172aee2012-04-10 17:05:261146void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121147 if (delegate_)
1148 delegate_->DeactivateContents(this);
1149}
1150
[email protected]b172aee2012-04-10 17:05:261151void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481152 if (delegate_)
1153 delegate_->LostCapture();
1154}
1155
[email protected]b24b68a2012-09-24 21:57:261156void WebContentsImpl::RenderWidgetDeleted(
1157 RenderWidgetHostImpl* render_widget_host) {
1158 if (is_being_destroyed_) {
1159 // |created_widgets_| might have been destroyed.
1160 return;
1161 }
1162
1163 std::set<RenderWidgetHostImpl*>::iterator iter =
1164 created_widgets_.find(render_widget_host);
1165 if (iter != created_widgets_.end())
1166 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541167
1168 if (render_widget_host &&
1169 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491170 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1171 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541172 FOR_EACH_OBSERVER(WebContentsObserver,
1173 observers_,
1174 DidDestroyFullscreenWidget(
1175 fullscreen_widget_routing_id_));
1176 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1177 }
[email protected]b24b68a2012-09-24 21:57:261178}
1179
[email protected]b172aee2012-04-10 17:05:261180bool WebContentsImpl::PreHandleKeyboardEvent(
1181 const NativeWebKeyboardEvent& event,
1182 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481183 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131184 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481185}
1186
[email protected]b172aee2012-04-10 17:05:261187void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061188 if (browser_plugin_embedder_ &&
1189 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1190 return;
1191 }
1192
[email protected]63954792011-07-11 04:17:481193 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131194 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481195}
1196
[email protected]d92026ef2014-03-03 21:04:131197bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461198 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191199#if !defined(OS_MACOSX)
1200 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1201 // isn't done for two reasons:
1202 // -the OS already has a gesture to do this through pinch-zoom
1203 // -if a user starts an inertial scroll, let's go, and presses control
1204 // (i.e. control+tab) then the OS's buffered scroll events will come in
1205 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521206 if (delegate_ &&
1207 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461208 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521209 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1210 return true;
1211 }
[email protected]bccc4472013-04-18 16:37:191212#endif
[email protected]fb3f066e2013-02-12 19:12:521213 return false;
1214}
1215
[email protected]04bce562014-01-30 05:34:541216bool WebContentsImpl::PreHandleGestureEvent(
1217 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031218 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541219}
1220
[email protected]bab38af2014-03-30 17:37:291221bool WebContentsImpl::HandleGestureEvent(
1222 const blink::WebGestureEvent& event) {
1223 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1224 // Use them to implement browser zoom, as for HandleWheelEvent above.
1225 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1226 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1227 // The scale difference necessary to trigger a zoom action. Derived from
1228 // experimentation to find a value that feels reasonable.
1229 const float kZoomStepValue = 0.6f;
1230
1231 // Find the (absolute) thresholds on either side of the current zoom factor,
1232 // then convert those to actual numbers to trigger a zoom in or out.
1233 // This logic deliberately makes the range around the starting zoom value
1234 // for the gesture twice as large as the other ranges (i.e., the notches are
1235 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1236 // so that it's easier to get back to your starting point than it is to
1237 // overshoot.
1238 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1239 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1240 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1241 : -backStep;
1242 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1243 : backStep;
1244
1245 totalPinchGestureAmount_ += event.data.pinchUpdate.scale;
1246 if (totalPinchGestureAmount_ > zoomInThreshold) {
1247 currentPinchZoomStepDelta_++;
1248 delegate_->ContentsZoomChange(true);
1249 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1250 currentPinchZoomStepDelta_--;
1251 delegate_->ContentsZoomChange(false);
1252 }
1253 return true;
1254 }
1255
1256 return false;
1257}
1258
[email protected]2ceee8f2014-01-14 18:02:081259#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411260gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1261 return accessible_parent_;
1262}
1263#endif
1264
[email protected]b172aee2012-04-10 17:05:261265void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431266 if (delegate_)
1267 delegate_->HandleMouseDown();
1268}
1269
[email protected]b172aee2012-04-10 17:05:261270void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481271 if (delegate_)
1272 delegate_->HandleMouseUp();
1273}
1274
[email protected]590a634e2012-07-19 16:38:231275void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481276 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231277 delegate_->HandlePointerActivate();
1278}
1279
1280void WebContentsImpl::HandleGestureBegin() {
1281 if (delegate_)
1282 delegate_->HandleGestureBegin();
1283}
1284
1285void WebContentsImpl::HandleGestureEnd() {
1286 if (delegate_)
1287 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481288}
1289
[email protected]b172aee2012-04-10 17:05:261290void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491291 // This method is being called to enter or leave renderer-initiated fullscreen
1292 // mode. Either way, make sure any existing fullscreen widget is shut down
1293 // first.
1294 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1295 if (widget_view)
1296 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1297
[email protected]8a5e0ca2011-08-25 06:30:471298 if (delegate_)
1299 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371300
1301 FOR_EACH_OBSERVER(WebContentsObserver,
1302 observers_,
1303 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471304}
1305
[email protected]b172aee2012-04-10 17:05:261306bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381307 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121308}
1309
[email protected]a9c81f02012-06-01 00:15:441310void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1311 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371312 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441313 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371314 } else {
1315 GotResponseToLockMouseRequest(false);
1316 }
1317}
1318
[email protected]b172aee2012-04-10 17:05:261319void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371320 if (delegate_)
1321 delegate_->LostMouseLock();
1322}
1323
[email protected]bafe6cd2012-05-23 23:09:501324void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201325 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501326 int route_id,
[email protected]227692c52013-05-31 22:43:041327 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131328 const ViewHostMsg_CreateWindow_Params& params,
1329 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501330 // We usually create the new window in the same BrowsingInstance (group of
1331 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551332 // if the opener is being suppressed (in a non-guest), we create a new
1333 // SiteInstance in its own BrowsingInstance.
1334 bool is_guest = GetRenderProcessHost()->IsGuest();
1335
[email protected]04cbd3d2013-12-04 04:58:201336 // If the opener is to be suppressed, the new window can be in any process.
1337 // Since routing ids are process specific, we must not have one passed in
1338 // as argument here.
1339 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1340
[email protected]bafe6cd2012-05-23 23:09:501341 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551342 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571343 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501344 GetSiteInstance();
1345
[email protected]04cbd3d2013-12-04 04:58:201346 // A message to create a new window can only come from the active process for
1347 // this WebContentsImpl instance. If any other process sends the request,
1348 // it is invalid and the process must be terminated.
1349 if (GetRenderProcessHost()->GetID() != render_process_id) {
1350 base::ProcessHandle process_handle =
1351 RenderProcessHost::FromID(render_process_id)->GetHandle();
1352 if (process_handle != base::kNullProcessHandle) {
1353 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391354 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201355 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1356 }
1357 return;
1358 }
1359
[email protected]d1198fd2012-08-13 22:50:191360 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341361 //
1362 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301363 const std::string& partition_id =
1364 GetContentClient()->browser()->
1365 GetStoragePartitionIdForSite(GetBrowserContext(),
1366 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461367 StoragePartition* partition = BrowserContext::GetStoragePartition(
1368 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411369 DOMStorageContextWrapper* dom_storage_context =
1370 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191371 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1372 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1373 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371374
1375 if (delegate_ &&
1376 !delegate_->ShouldCreateWebContents(this,
1377 route_id,
1378 params.window_container_type,
1379 params.frame_name,
1380 params.target_url,
1381 partition_id,
1382 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011383 if (route_id != MSG_ROUTING_NONE &&
1384 !RenderViewHost::FromID(render_process_id, route_id)) {
1385 // If the embedder didn't create a WebContents for this route, we need to
1386 // delete the RenderView that had already been created.
1387 Send(new ViewMsg_Close(route_id));
1388 }
[email protected]dd6730412013-08-14 15:03:371389 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1390 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1391 main_frame_route_id);
1392 return;
1393 }
1394
1395 // Create the new web contents. This will automatically create the new
1396 // WebContentsView. In the future, we may want to create the view separately.
1397 WebContentsImpl* new_contents =
1398 new WebContentsImpl(GetBrowserContext(),
1399 params.opener_suppressed ? NULL : this);
1400
[email protected]d1198fd2012-08-13 22:50:191401 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301402 partition_id,
[email protected]d1198fd2012-08-13 22:50:191403 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461404 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591405 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041406 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551407 if (!is_guest) {
1408 create_params.context = view_->GetNativeView();
1409 create_params.initial_size = view_->GetContainerSize();
1410 } else {
1411 // This makes |new_contents| act as a guest.
1412 // For more info, see comment above class BrowserPluginGuest.
1413 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1414 WebContentsImpl* new_contents_impl =
1415 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461416 BrowserPluginGuest::CreateWithOpener(instance_id,
1417 new_contents_impl->opener() != NULL,
1418 new_contents_impl,
1419 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551420 }
[email protected]1ac10dca2013-08-20 20:47:041421 if (params.disposition == NEW_BACKGROUND_TAB)
1422 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591423 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191424
[email protected]c4538072013-03-18 02:17:551425 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341426 // will be shown immediately).
1427 if (!params.opener_suppressed) {
1428 if (!is_guest) {
1429 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501430
[email protected]d70bea92013-04-05 04:23:341431 // TODO(brettw): It seems bogus that we have to call this function on the
1432 // newly created object and give it one of its own member variables.
1433 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1434 }
[email protected]bafe6cd2012-05-23 23:09:501435 // Save the created window associated with the route so we can show it
1436 // later.
1437 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1438 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101439 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501440 }
1441
1442 if (delegate_) {
1443 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071444 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131445 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501446 }
1447
1448 if (params.opener_suppressed) {
1449 // When the opener is suppressed, the original renderer cannot access the
1450 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001451 bool was_blocked = false;
1452 if (delegate_) {
1453 gfx::Rect initial_pos;
1454 delegate_->AddNewContents(
1455 this, new_contents, params.disposition, initial_pos,
1456 params.user_gesture, &was_blocked);
1457 }
1458 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211459 OpenURLParams open_params(params.target_url,
1460 Referrer(),
1461 CURRENT_TAB,
1462 PAGE_TRANSITION_LINK,
1463 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301464 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001465 new_contents->OpenURL(open_params);
1466 }
[email protected]bafe6cd2012-05-23 23:09:501467 }
1468}
1469
[email protected]a8504022013-12-04 20:23:511470void WebContentsImpl::CreateNewWidget(int render_process_id,
1471 int route_id,
[email protected]180ef242013-11-07 06:50:461472 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511473 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501474}
1475
[email protected]a8504022013-12-04 20:23:511476void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1477 int route_id) {
1478 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501479}
1480
[email protected]a8504022013-12-04 20:23:511481void WebContentsImpl::CreateNewWidget(int render_process_id,
1482 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501483 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461484 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211485 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511486 // A message to create a new widget can only come from the active process for
1487 // this WebContentsImpl instance. If any other process sends the request,
1488 // it is invalid and the process must be terminated.
1489 if (process->GetID() != render_process_id) {
1490 base::ProcessHandle process_handle =
1491 RenderProcessHost::FromID(render_process_id)->GetHandle();
1492 if (process_handle != base::kNullProcessHandle) {
1493 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391494 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511495 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1496 }
1497 return;
1498 }
1499
[email protected]bafe6cd2012-05-23 23:09:501500 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041501 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261502 created_widgets_.insert(widget_host);
1503
[email protected]83918ec2013-01-10 15:37:191504 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1505 view_->CreateViewForPopupWidget(widget_host));
1506 if (!widget_view)
1507 return;
[email protected]bafe6cd2012-05-23 23:09:501508 if (!is_fullscreen) {
1509 // Popups should not get activated.
1510 widget_view->SetPopupType(popup_type);
1511 }
1512 // Save the created widget associated with the route so we can show it later.
1513 pending_widget_views_[route_id] = widget_view;
1514
1515#if defined(OS_MACOSX)
1516 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1517 // to allow it to survive the trip without being hosted.
1518 base::mac::NSObjectRetain(widget_view->GetNativeView());
1519#endif
1520}
1521
1522void WebContentsImpl::ShowCreatedWindow(int route_id,
1523 WindowOpenDisposition disposition,
1524 const gfx::Rect& initial_pos,
1525 bool user_gesture) {
1526 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001527 if (contents) {
1528 WebContentsDelegate* delegate = GetDelegate();
1529 if (delegate) {
1530 delegate->AddNewContents(
1531 this, contents, disposition, initial_pos, user_gesture, NULL);
1532 }
1533 }
[email protected]bafe6cd2012-05-23 23:09:501534}
1535
1536void WebContentsImpl::ShowCreatedWidget(int route_id,
1537 const gfx::Rect& initial_pos) {
1538 ShowCreatedWidget(route_id, false, initial_pos);
1539}
1540
1541void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1542 ShowCreatedWidget(route_id, true, gfx::Rect());
1543}
1544
1545void WebContentsImpl::ShowCreatedWidget(int route_id,
1546 bool is_fullscreen,
1547 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501548 RenderWidgetHostViewPort* widget_host_view =
1549 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1550 if (!widget_host_view)
1551 return;
[email protected]4aebbca2013-09-17 22:26:491552 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311553 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1554 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491555 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1556 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1557 delegate_->ToggleFullscreenModeForTab(this, true);
1558 } else {
1559 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491560 }
[email protected]4aebbca2013-09-17 22:26:491561 FOR_EACH_OBSERVER(WebContentsObserver,
1562 observers_,
1563 DidShowFullscreenWidget(route_id));
1564 if (!widget_host_view->HasFocus())
1565 widget_host_view->Focus();
1566 } else {
[email protected]f8497342013-02-05 22:15:021567 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491568 }
[email protected]89054502012-06-03 10:29:241569
1570 RenderWidgetHostImpl* render_widget_host_impl =
1571 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1572 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311573 // Only allow privileged mouse lock for fullscreen render widget, which is
1574 // used to implement Pepper Flash fullscreen.
1575 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501576
1577#if defined(OS_MACOSX)
1578 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1579 // properly embedded (or purposefully ignored) we can release the retain we
1580 // took in CreateNewWidget().
1581 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1582#endif
1583}
1584
1585WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1586 PendingContents::iterator iter = pending_contents_.find(route_id);
1587
1588 // Certain systems can block the creation of new windows. If we didn't succeed
1589 // in creating one, just return NULL.
1590 if (iter == pending_contents_.end()) {
1591 return NULL;
1592 }
1593
1594 WebContentsImpl* new_contents = iter->second;
1595 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101596 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501597
[email protected]d70bea92013-04-05 04:23:341598 // Don't initialize the guest WebContents immediately.
1599 if (new_contents->GetRenderProcessHost()->IsGuest())
1600 return new_contents;
1601
[email protected]bafe6cd2012-05-23 23:09:501602 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1603 !new_contents->GetRenderViewHost()->GetView())
1604 return NULL;
1605
1606 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1607 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1608 return new_contents;
1609}
1610
1611RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1612 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1613 if (iter == pending_widget_views_.end()) {
1614 DCHECK(false);
1615 return NULL;
1616 }
1617
1618 RenderWidgetHostView* widget_host_view = iter->second;
1619 pending_widget_views_.erase(route_id);
1620
1621 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1622 if (!widget_host->GetProcess()->HasConnection()) {
1623 // The view has gone away or the renderer crashed. Nothing to do.
1624 return NULL;
1625 }
1626
1627 return widget_host_view;
1628}
1629
[email protected]f13b4202012-06-12 23:53:231630void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091631 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211632 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371633 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231634 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371635 } else {
1636 callback.Run(MediaStreamDevices(),
1637 MEDIA_DEVICE_INVALID_STATE,
1638 scoped_ptr<MediaStreamUI>());
1639 }
[email protected]f13b4202012-06-12 23:53:231640}
1641
[email protected]cc9200432013-07-23 23:02:401642SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1643 SiteInstance* instance) {
1644 return controller_.GetSessionStorageNamespace(instance);
1645}
1646
[email protected]9b159a52013-10-03 17:24:551647FrameTree* WebContentsImpl::GetFrameTree() {
1648 return &frame_tree_;
1649}
1650
[email protected]31a71eaf2014-03-13 01:47:361651void WebContentsImpl::AccessibilityEventReceived(
1652 const std::vector<AXEventNotificationDetails>& details) {
1653 FOR_EACH_OBSERVER(
1654 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1655}
1656
[email protected]edc3af82013-12-12 21:24:071657void WebContentsImpl::OnShowValidationMessage(
1658 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291659 const base::string16& main_text,
1660 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071661 if (delegate_)
1662 delegate_->ShowValidationMessage(
1663 this, anchor_in_root_view, main_text, sub_text);
1664}
1665
1666void WebContentsImpl::OnHideValidationMessage() {
1667 if (delegate_)
1668 delegate_->HideValidationMessage(this);
1669}
1670
1671void WebContentsImpl::OnMoveValidationMessage(
1672 const gfx::Rect& anchor_in_root_view) {
1673 if (delegate_)
1674 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1675}
1676
[email protected]32deec62013-05-15 23:55:041677void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1678 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441679 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041680}
1681
[email protected]b172aee2012-04-10 17:05:261682void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491683 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231684 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491685 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331686}
1687
[email protected]b172aee2012-04-10 17:05:261688void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341689 if (delegate_)
1690 delegate_->ResizeDueToAutoResize(this, new_size);
1691}
1692
[email protected]b172aee2012-04-10 17:05:261693WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201694 if (!delegate_)
1695 return NULL;
[email protected]00c37fc2011-08-02 00:22:501696
[email protected]e5d549d2011-12-28 01:29:201697 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201698 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341699}
1700
[email protected]6b618e62012-08-16 12:59:181701bool WebContentsImpl::Send(IPC::Message* message) {
1702 if (!GetRenderViewHost()) {
1703 delete message;
1704 return false;
1705 }
1706
1707 return GetRenderViewHost()->Send(message);
1708}
1709
[email protected]b172aee2012-04-10 17:05:261710bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501711 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261712 FrameTreeNode* node = frame_tree_.root();
1713
1714 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1715 // specified in the pending entry.
1716 NavigationEntryImpl* pending_entry =
1717 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1718 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1719 pending_entry->frame_tree_node_id() != -1) {
1720 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1721 }
1722
1723 return node->navigator()->NavigateToPendingEntry(
1724 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541725}
[email protected]96d185d2009-04-24 03:28:541726
[email protected]a86c0e962013-12-17 17:10:391727void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1728 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441729 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391730 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441731}
1732
[email protected]20ca0382013-02-28 19:50:071733void WebContentsImpl::AttachInterstitialPage(
1734 InterstitialPageImpl* interstitial_page) {
1735 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211736 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291737
1738 // Cancel any visible dialogs so that they don't interfere with the
1739 // interstitial.
1740 if (dialog_manager_)
1741 dialog_manager_->CancelActiveAndPendingDialogs(this);
1742
[email protected]20ca0382013-02-28 19:50:071743 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1744 DidAttachInterstitialPage());
1745}
1746
1747void WebContentsImpl::DetachInterstitialPage() {
1748 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211749 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071750 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1751 DidDetachInterstitialPage());
1752}
1753
[email protected]b172aee2012-04-10 17:05:261754void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331755 const SiteInstance* site_instance,
1756 int history_length,
1757 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411758 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1759 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211760 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191761 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141762 return;
[email protected]9e1ad4b2011-08-14 16:49:191763 }
[email protected]9f76c1e2012-03-05 15:15:581764 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191765 if (!rvh) {
1766 NOTREACHED();
1767 return;
1768 }
[email protected]9f76c1e2012-03-05 15:15:581769 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191770 NOTREACHED();
1771 return;
1772 }
[email protected]6b618e62012-08-16 12:59:181773 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1774 history_length,
1775 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141776}
1777
[email protected]4fed3702014-04-01 09:08:001778void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171779 RenderFrameHost* focused_frame = GetFocusedFrame();
1780 if (!focused_frame)
1781 return;
1782
1783 Send(new FrameMsg_Reload(focused_frame->GetRoutingID(), ignore_cache));
1784}
1785
1786void WebContentsImpl::Replace(const base::string16& word) {
1787 RenderFrameHost* focused_frame = GetFocusedFrame();
1788 if (!focused_frame)
1789 return;
1790
1791 Send(new InputMsg_Replace(focused_frame->GetRoutingID(), word));
1792}
1793
1794void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1795 RenderFrameHost* focused_frame = GetFocusedFrame();
1796 if (!focused_frame)
1797 return;
1798
1799 Send(new InputMsg_ReplaceMisspelling(focused_frame->GetRoutingID(), word));
[email protected]4fed3702014-04-01 09:08:001800}
1801
[email protected]b172aee2012-04-10 17:05:261802void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271803 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211804 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541805 return;
1806 }
[email protected]9f76c1e2012-03-05 15:15:581807 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541808}
1809
[email protected]b172aee2012-04-10 17:05:261810bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211811 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541812}
1813
[email protected]b172aee2012-04-10 17:05:261814InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211815 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221816}
1817
[email protected]b172aee2012-04-10 17:05:261818bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161819 // WebKit creates Document object when MIME type is application/xhtml+xml,
1820 // so we also support this MIME type.
1821 return contents_mime_type_ == "text/html" ||
1822 contents_mime_type_ == "text/xml" ||
1823 contents_mime_type_ == "application/xhtml+xml" ||
1824 contents_mime_type_ == "text/plain" ||
1825 contents_mime_type_ == "text/css" ||
1826 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1827}
1828
[email protected]b172aee2012-04-10 17:05:261829void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591830 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161831 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551832 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011833 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141834 return;
[email protected]c7dd2f62011-07-18 15:57:591835 }
1836
1837 Stop();
1838
1839 // Create the save package and possibly prompt the user for the name to save
1840 // the page as. The user prompt is an asynchronous operation that runs on
1841 // another thread.
1842 save_package_ = new SavePackage(this);
1843 save_package_->GetSaveInfo();
1844}
1845
1846// Used in automated testing to bypass prompting the user for file names.
1847// Instead, the names and paths are hard coded rather than running them through
1848// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341849bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1850 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211851 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591852 // Stop the page from navigating.
1853 Stop();
1854
1855 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211856 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591857}
1858
[email protected]3c71576ce2013-07-23 02:00:011859void WebContentsImpl::SaveFrame(const GURL& url,
1860 const Referrer& referrer) {
1861 if (!GetURL().is_valid())
1862 return;
1863 bool is_main_frame = (url == GetURL());
1864
1865 DownloadManager* dlm =
1866 BrowserContext::GetDownloadManager(GetBrowserContext());
1867 if (!dlm)
1868 return;
1869 int64 post_id = -1;
1870 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271871 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011872 if (entry)
1873 post_id = entry->GetPostID();
1874 }
1875 scoped_ptr<DownloadUrlParameters> params(
1876 DownloadUrlParameters::FromWebContents(this, url));
1877 params->set_referrer(referrer);
1878 params->set_post_id(post_id);
1879 params->set_prefer_cache(true);
1880 if (post_id >= 0)
1881 params->set_method("POST");
1882 params->set_prompt(true);
1883 dlm->DownloadUrl(params.Pass());
1884}
1885
[email protected]b172aee2012-04-10 17:05:261886void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341887 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481888 const base::Callback<void(int64)>& callback) {
1889 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121890}
1891
[email protected]6286a372013-10-09 04:03:271892// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261893bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271894 NavigationEntryImpl* visible_entry =
1895 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1896 return (visible_entry != NULL &&
1897 visible_entry->site_instance() == GetSiteInstance() &&
1898 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321899}
1900
[email protected]b172aee2012-04-10 17:05:261901const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271902 return contents_mime_type_;
1903}
1904
[email protected]b172aee2012-04-10 17:05:261905bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271906 return notify_disconnection_;
1907}
1908
[email protected]b172aee2012-04-10 17:05:261909void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311910 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181911 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161912}
1913
[email protected]b172aee2012-04-10 17:05:261914void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311915 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181916 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161917}
1918
[email protected]8ff00d72012-10-23 19:12:211919RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271920 return &renderer_preferences_;
1921}
1922
[email protected]e35ccd52012-05-23 16:22:471923void WebContentsImpl::Close() {
1924 Close(GetRenderViewHost());
1925}
1926
[email protected]cf200a562013-05-03 16:24:291927void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461928 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291929 if (browser_plugin_embedder_.get())
1930 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1931 screen_x, screen_y, operation);
1932 if (GetRenderViewHost())
1933 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1934 screen_x, screen_y, operation);
1935}
1936
1937void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1938 int screen_x, int screen_y) {
1939 if (browser_plugin_embedder_.get())
1940 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1941 screen_x, screen_y);
1942 if (GetRenderViewHost())
1943 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1944 screen_x, screen_y);
1945}
1946
[email protected]d60f3702013-12-26 16:30:241947void WebContentsImpl::DidGetResourceResponseStart(
1948 const ResourceRequestDetails& details) {
1949 controller_.ssl_manager()->DidStartResourceResponse(details);
1950
1951 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1952 DidGetResourceResponseStart(details));
1953
1954 // TODO(avi): Remove. http://crbug.com/170921
1955 NotificationService::current()->Notify(
1956 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1957 Source<WebContents>(this),
1958 Details<const ResourceRequestDetails>(&details));
1959}
1960
1961void WebContentsImpl::DidGetRedirectForResourceRequest(
1962 RenderViewHost* render_view_host,
1963 const ResourceRedirectDetails& details) {
1964 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1965
1966 FOR_EACH_OBSERVER(
1967 WebContentsObserver,
1968 observers_,
1969 DidGetRedirectForResourceRequest(render_view_host, details));
1970
1971 // TODO(avi): Remove. http://crbug.com/170921
1972 NotificationService::current()->Notify(
1973 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1974 Source<WebContents>(this),
1975 Details<const ResourceRedirectDetails>(&details));
1976}
1977
[email protected]b172aee2012-04-10 17:05:261978void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521979 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581980 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511981 if (delegate_)
1982 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291983 if (browser_plugin_embedder_.get())
1984 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341985}
1986
[email protected]e35ccd52012-05-23 16:22:471987void WebContentsImpl::UserGestureDone() {
1988 OnUserGesture();
1989}
1990
[email protected]b172aee2012-04-10 17:05:261991void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271992 closed_by_user_gesture_ = value;
1993}
1994
[email protected]b172aee2012-04-10 17:05:261995bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271996 return closed_by_user_gesture_;
1997}
1998
[email protected]b172aee2012-04-10 17:05:261999double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052000 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562001 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252002 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172003 return 0;
[email protected]b75b8292010-10-01 07:28:252004
2005 double zoom_level;
2006 if (temporary_zoom_settings_) {
2007 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582008 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252009 } else {
[email protected]2ae88d12011-10-14 09:11:192010 GURL url;
[email protected]6286a372013-10-09 04:03:272011 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192012 // Since zoom map is updated using rewritten URL, use rewritten URL
2013 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272014 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022015 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2016 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252017 }
[email protected]d0b8d092010-10-25 04:05:172018 return zoom_level;
2019}
[email protected]b75b8292010-10-01 07:28:252020
[email protected]b172aee2012-04-10 17:05:262021int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592022 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172023 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012024 // Calculate the zoom percent from the factor. Round up to the nearest whole
2025 // number.
[email protected]b75b8292010-10-01 07:28:252026 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492027 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252028 *enable_decrement = percent > minimum_zoom_percent_;
2029 *enable_increment = percent < maximum_zoom_percent_;
2030 return percent;
2031}
2032
[email protected]b172aee2012-04-10 17:05:262033void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502034 if (!delegate_)
2035 return;
2036
[email protected]6286a372013-10-09 04:03:272037 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2038 if (!entry)
[email protected]1788e772010-12-15 16:40:502039 return;
2040
[email protected]6286a372013-10-09 04:03:272041 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122042}
2043
[email protected]b172aee2012-04-10 17:05:262044void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042045 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272046 if (!delegate_)
2047 return;
2048
[email protected]691aa2f2013-05-28 22:52:042049 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272050}
2051
[email protected]b172aee2012-04-10 17:05:262052int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272053 return minimum_zoom_percent_;
2054}
2055
[email protected]b172aee2012-04-10 17:05:262056int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272057 return maximum_zoom_percent_;
2058}
2059
[email protected]b172aee2012-04-10 17:05:262060gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492061 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232062}
2063
[email protected]b172aee2012-04-10 17:05:262064bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272065 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582066 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272067}
2068
[email protected]b172aee2012-04-10 17:05:262069bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442070 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502071}
2072
[email protected]cb805452013-05-22 15:16:212073void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182074 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212075 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202076}
2077
[email protected]cb805452013-05-22 15:16:212078void WebContentsImpl::DidEndColorChooser() {
2079 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2080 color_chooser_identifier_));
2081 color_chooser_.reset();
2082 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202083}
2084
[email protected]41225fe2013-03-29 05:32:022085int WebContentsImpl::DownloadImage(const GURL& url,
2086 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302087 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022088 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582089 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022090 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392091 return id;
2092}
2093
[email protected]5dcaf8e2013-12-28 01:31:422094bool WebContentsImpl::IsSubframe() const {
2095 return is_subframe_;
2096}
2097
[email protected]9649d492014-01-10 07:15:522098void WebContentsImpl::SetZoomLevel(double level) {
2099 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2100 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2101 if (embedder)
2102 embedder->SetZoomLevel(level);
2103}
2104
[email protected]36ec24f2014-01-09 00:32:082105void WebContentsImpl::Find(int request_id,
2106 const base::string16& search_text,
2107 const blink::WebFindOptions& options) {
2108 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2109}
2110
2111void WebContentsImpl::StopFinding(StopFindAction action) {
2112 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2113}
2114
[email protected]b172aee2012-04-10 17:05:262115bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272116 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202117 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332118 return true;
2119 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272120}
2121
[email protected]b172aee2012-04-10 17:05:262122void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272123 if (delegate_)
2124 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212125}
2126
[email protected]52913802013-12-10 05:52:182127void WebContentsImpl::DidStartProvisionalLoad(
2128 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072129 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182130 const GURL& validated_url,
2131 bool is_error_page,
2132 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262133 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182134 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572135 DidChangeLoadProgress(0);
2136
[email protected]0d60f0192011-04-14 12:40:102137 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272138 int render_frame_id = render_frame_host->GetRoutingID();
2139 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252140 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072141 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272142 render_frame_id, parent_routing_id, is_main_frame,
2143 validated_url, is_error_page, is_iframe_srcdoc,
2144 render_view_host));
[email protected]400992b2012-06-14 00:03:542145
2146 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182147 FOR_EACH_OBSERVER(
2148 WebContentsObserver,
2149 observers_,
2150 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582151 render_frame_host));
[email protected]400992b2012-06-14 00:03:542152 }
2153}
2154
[email protected]3109fbb72014-01-06 23:57:152155void WebContentsImpl::DidFailProvisionalLoadWithError(
2156 RenderFrameHostImpl* render_frame_host,
2157 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2158 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272159 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262160 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272161 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152162 FOR_EACH_OBSERVER(
2163 WebContentsObserver,
2164 observers_,
[email protected]161eabd2014-03-19 19:47:272165 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152166 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262167 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152168 validated_url,
2169 params.error_code,
2170 params.error_description,
[email protected]161eabd2014-03-19 19:47:272171 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152172}
2173
[email protected]b80624c2014-02-09 02:46:552174void WebContentsImpl::DidFailLoadWithError(
2175 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552176 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552177 int error_code,
2178 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272179 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262180 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272181 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552182 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272183 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262184 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552185}
2186
[email protected]52913802013-12-10 05:52:182187void WebContentsImpl::NotifyChangedNavigationState(
2188 InvalidateTypes changed_flags) {
2189 NotifyNavigationStateChanged(changed_flags);
2190}
2191
[email protected]3691e5cf2014-01-22 10:16:202192void WebContentsImpl::AboutToNavigateRenderFrame(
2193 RenderFrameHostImpl* render_frame_host) {
2194 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272195 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202196 FOR_EACH_OBSERVER(
2197 WebContentsObserver,
2198 observers_,
[email protected]161eabd2014-03-19 19:47:272199 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202200}
2201
2202void WebContentsImpl::DidStartNavigationToPendingEntry(
2203 RenderFrameHostImpl* render_frame_host,
2204 const GURL& url,
2205 NavigationController::ReloadType reload_type) {
2206 // Notify observers about navigation.
2207 FOR_EACH_OBSERVER(
2208 WebContentsObserver,
2209 observers_,
2210 DidStartNavigationToPendingEntry(url, reload_type));
2211}
2212
[email protected]8cb834e2014-03-06 14:23:232213void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2214 const OpenURLParams& params) {
2215 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182216 WebContents* new_contents = OpenURL(params);
2217
2218 if (new_contents) {
2219 // Notify observers.
2220 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2221 DidOpenRequestedURL(new_contents,
2222 params.url,
2223 params.referrer,
2224 params.disposition,
2225 params.transition,
[email protected]8cb834e2014-03-06 14:23:232226 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182227 }
2228}
2229
[email protected]400992b2012-06-14 00:03:542230void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582231 RenderFrameHostImpl* render_frame_host,
2232 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542233 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582234 FOR_EACH_OBSERVER(
2235 WebContentsObserver,
2236 observers_,
2237 ProvisionalChangeToMainFrameUrl(validated_target_url,
2238 render_frame_host));
[email protected]724159a2010-12-30 01:11:182239}
2240
[email protected]37567b432014-02-12 01:12:222241void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432242 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222243 const base::string16& frame_unique_name,
2244 bool is_main_frame,
2245 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432246 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432247 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272248 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222249 // Notify observers about the commit of the provisional load.
2250 FOR_EACH_OBSERVER(
2251 WebContentsObserver,
2252 observers_,
[email protected]27dd82fd2014-03-03 22:11:432253 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222254 frame_unique_name,
2255 is_main_frame,
2256 url,
2257 transition_type,
2258 render_view_host));
2259}
2260
[email protected]0d0f4c492014-04-02 06:42:572261void WebContentsImpl::DidNavigateMainFramePreCommit(
2262 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2263 // Ensure fullscreen mode is exited before committing the navigation to a
2264 // different page. The next page will not start out assuming it is in
2265 // fullscreen mode.
2266 if (params.was_within_same_page) {
2267 // No document change? Then, the renderer shall decide whether to exit
2268 // fullscreen.
2269 return;
2270 }
2271 if (IsFullscreenForCurrentTab())
2272 GetRenderViewHost()->ExitFullscreen();
2273 DCHECK(!IsFullscreenForCurrentTab());
2274}
2275
[email protected]37567b432014-02-12 01:12:222276void WebContentsImpl::DidNavigateMainFramePostCommit(
2277 const LoadCommittedDetails& details,
2278 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2279 if (details.is_navigation_to_different_page()) {
2280 // Clear the status bubble. This is a workaround for a bug where WebKit
2281 // doesn't let us know that the cursor left an element during a
2282 // transition (this is also why the mouse cursor remains as a hand after
2283 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2284 // clear the bubble when a user navigates to a named anchor in the same
2285 // page.
2286 UpdateTargetURL(details.entry->GetPageID(), GURL());
2287 }
2288
2289 if (!details.is_in_page) {
2290 // Once the main frame is navigated, we're no longer considered to have
2291 // displayed insecure content.
2292 displayed_insecure_content_ = false;
2293 SSLManager::NotifySSLInternalStateChanged(
2294 GetController().GetBrowserContext());
2295 }
2296
2297 // Notify observers about navigation.
2298 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2299 DidNavigateMainFrame(details, params));
2300
2301 if (delegate_) {
2302 delegate_->DidNavigateMainFramePostCommit(this);
2303 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2304 }
2305}
2306
2307void WebContentsImpl::DidNavigateAnyFramePostCommit(
2308 RenderFrameHostImpl* render_frame_host,
2309 const LoadCommittedDetails& details,
2310 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2311 // If we navigate off the page, close all JavaScript dialogs.
2312 if (dialog_manager_ && !details.is_in_page)
2313 dialog_manager_->CancelActiveAndPendingDialogs(this);
2314
2315 // Notify observers about navigation.
2316 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2317 DidNavigateAnyFrame(details, params));
2318}
2319
2320void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2321 contents_mime_type_ = mime_type;
2322}
2323
2324bool WebContentsImpl::CanOverscrollContent() {
2325 if (delegate_)
2326 return delegate_->CanOverscrollContent();
2327
2328 return false;
2329}
2330
[email protected]b172aee2012-04-10 17:05:262331void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182332 const GURL& url,
[email protected]70435962011-08-02 20:13:282333 const std::string& security_info,
2334 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182335 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282336 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192337 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182338 cache.Increment();
2339
2340 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082341 int cert_id = 0;
2342 net::CertStatus cert_status = 0;
2343 int security_bits = -1;
2344 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122345 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212346 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122347 &security_bits, &connection_status,
2348 &signed_certificate_timestamp_ids);
2349 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212350 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002351 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2352 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182353
[email protected]b0f724c2013-09-05 04:21:132354 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2355
2356 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2357 DidLoadResourceFromMemoryCache(details));
2358
[email protected]8bfc8272013-09-09 20:10:532359 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2360 scoped_refptr<net::URLRequestContextGetter> request_context(
2361 resource_type == ResourceType::MEDIA ?
2362 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2363 GetRenderProcessHost()->GetID()) :
2364 GetBrowserContext()->GetRequestContextForRenderProcess(
2365 GetRenderProcessHost()->GetID()));
2366 BrowserThread::PostTask(
2367 BrowserThread::IO,
2368 FROM_HERE,
2369 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2370 }
[email protected]724159a2010-12-30 01:11:182371}
2372
[email protected]b172aee2012-04-10 17:05:262373void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392374 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182375 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192376 SSLManager::NotifySSLInternalStateChanged(
2377 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182378}
2379
[email protected]b172aee2012-04-10 17:05:262380void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022381 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582382 LOG(WARNING) << security_origin << " ran insecure content from "
2383 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392384 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412385 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392386 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182387 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412388 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192389 SSLManager::NotifySSLInternalStateChanged(
2390 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182391}
2392
[email protected]501052ff2014-02-21 22:19:072393void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572394 CHECK(render_frame_message_source_);
2395 CHECK(!render_view_message_source_);
2396 RenderFrameHostImpl* rfh =
2397 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2398
[email protected]161eabd2014-03-19 19:47:272399 int render_frame_id = rfh->GetRoutingID();
2400 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572401 FOR_EACH_OBSERVER(WebContentsObserver,
2402 observers_,
[email protected]161eabd2014-03-19 19:47:272403 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182404}
2405
[email protected]b172aee2012-04-10 17:05:262406void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262407 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372408 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122409 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2410 GetRenderProcessHost()->ReceivedBadMessage();
2411 return;
2412 }
[email protected]a1b99262013-12-27 21:56:222413
[email protected]8b3af1e2014-01-24 13:29:122414 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442415 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372416 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422417 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372418
[email protected]61ac9e242014-03-21 20:55:262419 RenderFrameHostImpl* rfh =
2420 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272421 int render_frame_id = rfh->GetRoutingID();
2422 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262423 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252424 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272425 DidFinishLoad(render_frame_id, validated_url,
2426 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312427}
2428
[email protected]b172aee2012-04-10 17:05:262429void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222430 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2431 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262432}
2433
[email protected]b172aee2012-04-10 17:05:262434void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2435 int maximum_percent,
2436 bool remember) {
[email protected]216813952011-05-19 22:21:262437 minimum_zoom_percent_ = minimum_percent;
2438 maximum_zoom_percent_ = maximum_percent;
2439 temporary_zoom_settings_ = !remember;
2440}
2441
[email protected]b172aee2012-04-10 17:05:262442void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342443 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432444 if (!delegate_)
2445 return;
2446
[email protected]b9535422012-02-09 01:47:592447 ChildProcessSecurityPolicyImpl* policy =
2448 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222449 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592450 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212451}
2452
[email protected]b172aee2012-04-10 17:05:262453void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2454 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262455 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362456 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432457 if (!delegate_)
2458 return;
2459
[email protected]b9535422012-02-09 01:47:592460 ChildProcessSecurityPolicyImpl* policy =
2461 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322462 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592463 return;
[email protected]8f810632013-06-06 22:33:322464
[email protected]3a3b75a2012-06-01 08:38:362465 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202466}
2467
[email protected]b172aee2012-04-10 17:05:262468void WebContentsImpl::OnFindReply(int request_id,
2469 int number_of_matches,
2470 const gfx::Rect& selection_rect,
2471 int active_match_ordinal,
2472 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432473 if (delegate_) {
2474 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2475 active_match_ordinal, final_update);
2476 }
[email protected]b888919c2011-09-02 00:32:162477}
2478
[email protected]59363fc92012-09-05 03:46:312479#if defined(OS_ANDROID)
2480void WebContentsImpl::OnFindMatchRectsReply(
2481 int version,
2482 const std::vector<gfx::RectF>& rects,
2483 const gfx::RectF& active_rect) {
2484 if (delegate_)
2485 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2486}
[email protected]583418cc2013-01-17 14:01:102487
[email protected]1ff427972013-02-07 21:14:072488void WebContentsImpl::OnOpenDateTimeDialog(
2489 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092490 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2491 GetRenderViewHost(),
2492 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132493 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092494 value.minimum,
2495 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172496 value.step,
2497 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102498}
2499
[email protected]a794f3a2013-10-30 17:00:322500void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2501 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]c06c58c2014-03-12 20:31:592502 render_frame_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322503}
2504
[email protected]59363fc92012-09-05 03:46:312505#endif
2506
[email protected]f114fa42013-12-06 17:06:442507void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2508 const base::FilePath& path,
2509 bool is_hung) {
2510 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2511
2512 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2513 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2514}
2515
2516void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422517 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442518 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422519 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452520}
2521
[email protected]cfa856d62014-02-22 07:58:402522void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2523 int automation_id) {
2524 DomOperationNotificationDetails details(json_string, automation_id);
2525 NotificationService::current()->Notify(
2526 NOTIFICATION_DOM_OPERATION_RESPONSE,
2527 Source<WebContents>(this),
2528 Details<DomOperationNotificationDetails>(&details));
2529}
2530
[email protected]b172aee2012-04-10 17:05:262531void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2532 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102533 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252534 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102535 AppCacheAccessed(manifest_url, blocked_by_policy));
2536}
2537
[email protected]8bc5ff02013-11-29 06:34:032538void WebContentsImpl::OnOpenColorChooser(
2539 int color_chooser_id,
2540 SkColor color,
2541 const std::vector<ColorSuggestion>& suggestions) {
2542 ColorChooser* new_color_chooser =
2543 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302544 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212545 return;
[email protected]820957a2014-01-14 14:56:302546 if (color_chooser_)
2547 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212548 color_chooser_.reset(new_color_chooser);
2549 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202550}
2551
[email protected]b172aee2012-04-10 17:05:262552void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202553 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212554 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202555 color_chooser_->End();
2556}
2557
[email protected]b172aee2012-04-10 17:05:262558void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322559 SkColor color) {
[email protected]da8543762012-03-20 08:52:202560 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212561 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202562 color_chooser_->SetSelectedColor(color);
2563}
2564
[email protected]d0759f492012-04-19 22:50:502565// This exists for render views that don't have a WebUI, but do have WebUI
2566// bindings enabled.
2567void WebContentsImpl::OnWebUISend(const GURL& source_url,
2568 const std::string& name,
2569 const base::ListValue& args) {
2570 if (delegate_)
2571 delegate_->WebUISend(this, source_url, name, args);
2572}
2573
[email protected]d8415ad92012-08-23 14:40:502574void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442575 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502576 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342577 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162578 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442579 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162580 return;
[email protected]d8415ad92012-08-23 14:40:502581 }
2582
[email protected]8c8fc292012-11-23 18:57:162583 if (!delegate_->RequestPpapiBrokerPermission(
2584 this, url, plugin_path,
2585 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442586 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162587 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442588 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162589 }
[email protected]d8415ad92012-08-23 14:40:502590}
2591
[email protected]ea0309c2013-08-06 19:35:442592void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502593 bool result) {
[email protected]ea0309c2013-08-06 19:35:442594 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502595}
2596
[email protected]c4538072013-03-18 02:17:552597void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372598 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082599 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552600 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392601 // For more info, see comment above classes BrowserPluginEmbedder and
2602 // BrowserPluginGuest.
2603 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142604 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082605 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372606}
2607
[email protected]41225fe2013-03-29 05:32:022608void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392609 int id,
[email protected]749fadd2013-05-15 08:37:482610 int http_status_code,
[email protected]795c28972012-12-06 06:13:392611 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302612 const std::vector<SkBitmap>& bitmaps,
2613 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132614 if (bitmaps.size() != original_bitmap_sizes.size())
2615 return;
2616
[email protected]41225fe2013-03-29 05:32:022617 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2618 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392619 // Currently WebContents notifies us of ANY downloads so that it is
2620 // possible to get here.
2621 return;
2622 }
2623 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302624 iter->second.Run(
2625 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392626 }
[email protected]41225fe2013-03-29 05:32:022627 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392628}
2629
2630void WebContentsImpl::OnUpdateFaviconURL(
2631 int32 page_id,
2632 const std::vector<FaviconURL>& candidates) {
2633 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2634 DidUpdateFaviconURL(page_id, candidates));
2635}
2636
[email protected]1dd0bb752014-02-01 01:16:262637void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2638 bool has_video,
2639 bool has_audio) {
2640// Chrome OS does its own detection of audio and video.
2641#if !defined(OS_CHROMEOS)
2642 scoped_ptr<PowerSaveBlocker> blocker;
2643 if (has_video) {
2644 blocker = PowerSaveBlocker::Create(
2645 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2646#if defined(OS_ANDROID)
2647 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2648 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2649#endif
2650 } else if (has_audio) {
2651 blocker = PowerSaveBlocker::Create(
2652 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2653 }
2654
2655 if (blocker) {
2656 power_save_blockers_[render_view_message_source_][player_cookie] =
2657 blocker.release();
2658 }
2659#endif // !defined(OS_CHROMEOS)
2660}
2661
2662void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062663 // Chrome OS does its own detection of audio and video.
2664#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262665 delete power_save_blockers_[render_view_message_source_][player_cookie];
2666 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062667#endif // !defined(OS_CHROMEOS)
2668}
2669
[email protected]9f268072013-11-07 00:02:152670void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2671 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2672 DidFirstVisuallyNonEmptyPaint(page_id));
2673}
[email protected]d9030b82013-07-19 08:26:062674
[email protected]e67ebf32013-02-13 11:07:192675void WebContentsImpl::DidChangeVisibleSSLState() {
2676 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2677 DidChangeVisibleSSLState());
2678}
2679
[email protected]17e286e2013-03-01 23:29:392680void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2681 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2682 BeforeFormRepostWarningShow());
2683}
2684
[email protected]ec6c05f2013-10-23 18:41:572685
2686void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2687 Activate();
2688 if (delegate_)
2689 delegate_->ShowRepostFormWarningDialog(this);
2690}
2691
[email protected]96d185d2009-04-24 03:28:542692// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592693// loading, or done loading.
2694void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2695 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092696 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262697 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542698 if (is_loading == is_loading_)
2699 return;
2700
2701 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262702 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2703 base::string16());
[email protected]96d185d2009-04-24 03:28:542704 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562705 upload_size_ = 0;
2706 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542707 }
2708
[email protected]fa944cb82013-11-15 17:51:212709 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542710
2711 is_loading_ = is_loading;
2712 waiting_for_response_ = is_loading;
2713
[email protected]6ebdc9b2010-09-27 16:55:572714 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092715 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212716 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542717
[email protected]eab61442013-11-14 18:35:482718 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592719 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482720 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2721 "URL", url);
[email protected]91621872013-10-08 04:04:592722 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2723 DidStartLoading(render_view_host));
2724 } else {
[email protected]eab61442013-11-14 18:35:482725 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2726 "URL", url);
[email protected]91621872013-10-08 04:04:592727 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2728 DidStopLoading(render_view_host));
2729 }
[email protected]66798902013-10-01 18:40:162730
2731 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212732 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2733 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542734 if (details)
[email protected]8ff00d72012-10-23 19:12:212735 det = Details<LoadNotificationDetails>(details);
2736 NotificationService::current()->Notify(
2737 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542738}
2739
[email protected]b172aee2012-04-10 17:05:262740void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462741 // If we are creating a RVH for a restored controller, then we need to make
2742 // sure the RenderView starts with a next_page_id_ larger than the number
2743 // of restored entries. This must be called before the RenderView starts
2744 // navigating (to avoid a race between the browser updating max_page_id and
2745 // the renderer updating next_page_id_). Because of this, we only call this
2746 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562747 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582748 if (max_restored_page_id >
2749 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2750 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2751 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322752}
2753
[email protected]b172aee2012-04-10 17:05:262754bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262755 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322756 // For file URLs without a title, use the pathname instead. In the case of a
2757 // synthesized title, we don't want the update to count toward the "one set
2758 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262759 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322760 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512761 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242762 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322763 explicit_set = false; // Don't count synthetic titles toward the set limit.
2764 } else {
[email protected]8af69c6c2014-03-03 19:05:312765 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322766 explicit_set = true;
2767 }
2768
[email protected]987fc3a2011-05-26 14:18:092769 // If a page is created via window.open and never navigated,
2770 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552771 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092772 if (entry) {
[email protected]36fc0392011-12-25 03:59:512773 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092774 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322775
[email protected]36fc0392011-12-25 03:59:512776 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092777 } else {
2778 if (page_title_when_no_navigation_entry_ == final_title)
2779 return false; // Nothing changed, don't bother.
2780
2781 page_title_when_no_navigation_entry_ = final_title;
2782 }
[email protected]420ae012009-04-24 05:16:322783
[email protected]420ae012009-04-24 05:16:322784 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232785 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322786
[email protected]66798902013-10-01 18:40:162787 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532788 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162789
2790 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212791 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462792 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212793 NotificationService::current()->Notify(
2794 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2795 Source<WebContents>(this),
2796 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042797
[email protected]420ae012009-04-24 05:16:322798 return true;
2799}
2800
[email protected]7b712ee22013-10-03 00:57:282801void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2802 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322803 // After sending out a swap notification, we need to send a disconnect
2804 // notification so that clients that pick up a pointer to |this| can NULL the
2805 // pointer. See Bug 1230284.
2806 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112807 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282808 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112809
2810 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282811 std::pair<RenderViewHost*, RenderViewHost*> details =
2812 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212813 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282814 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212815 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282816 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392817
2818 // Ensure that the associated embedder gets cleared after a RenderViewHost
2819 // gets swapped, so we don't reuse the same embedder next time a
2820 // RenderViewHost is attached to this WebContents.
2821 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322822}
2823
[email protected]da7a7182013-09-06 08:11:112824// TODO(avi): Remove this entire function because this notification is already
2825// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262826void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322827 if (!notify_disconnection_)
2828 return;
2829
2830 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212831 NotificationService::current()->Notify(
2832 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2833 Source<WebContents>(this),
2834 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322835}
2836
[email protected]cbb1ef592013-06-05 19:49:462837void WebContentsImpl::NotifyNavigationEntryCommitted(
2838 const LoadCommittedDetails& load_details) {
2839 FOR_EACH_OBSERVER(
2840 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2841}
2842
[email protected]f114fa42013-12-06 17:06:442843bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2844 const IPC::Message& message) {
2845 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312846}
2847
[email protected]b849847b2013-12-10 21:57:582848void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2849 // Note this is only for subframes, the notification for the main frame
2850 // happens in RenderViewCreated.
2851 FOR_EACH_OBSERVER(WebContentsObserver,
2852 observers_,
2853 RenderFrameCreated(render_frame_host));
2854}
2855
2856void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2857 FOR_EACH_OBSERVER(WebContentsObserver,
2858 observers_,
2859 RenderFrameDeleted(render_frame_host));
2860}
2861
[email protected]a09d53ce2014-01-31 00:46:422862void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302863 if (delegate_)
2864 delegate_->WorkerCrashed(this);
2865}
2866
[email protected]a09d53ce2014-01-31 00:46:422867void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2868 const ContextMenuParams& params) {
2869 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:402870 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:422871 return;
2872
2873 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2874}
2875
[email protected]a86c0e962013-12-17 17:10:392876WebContents* WebContentsImpl::GetAsWebContents() {
2877 return this;
2878}
2879
[email protected]5a3bdf52012-05-24 15:12:572880RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2881 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322882}
2883
[email protected]8ff00d72012-10-23 19:12:212884RendererPreferences WebContentsImpl::GetRendererPrefs(
2885 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462886 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512887}
2888
[email protected]b172aee2012-04-10 17:05:262889gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172890 if (delegate_)
2891 return delegate_->GetRootWindowResizerRect();
2892 return gfx::Rect();
2893}
2894
[email protected]7a846df2012-09-20 19:17:392895void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272896 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392897 browser_plugin_embedder_.reset();
2898}
2899
[email protected]b172aee2012-04-10 17:05:262900void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442901 // Don't send notifications if we are just creating a swapped-out RVH for
2902 // the opener chain. These won't be used for view-source or WebUI, so it's
2903 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:242904 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:442905 return;
2906
[email protected]86f98a22013-03-20 14:35:002907 if (delegate_)
2908 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082909
[email protected]8ff00d72012-10-23 19:12:212910 NotificationService::current()->Notify(
2911 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2912 Source<WebContents>(this),
2913 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322914
2915 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352916 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212917 if (GetRenderManager()->pending_web_ui())
2918 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322919
[email protected]6286a372013-10-09 04:03:272920 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332921 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322922 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182923 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582924 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322925 }
[email protected]0666aef2009-05-13 19:48:082926
[email protected]60780f412013-02-25 16:34:102927 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262928
2929 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252930 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582931
2932 // We tell the observers now instead of when the main RenderFrameHostImpl is
2933 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2934 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:362935 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:582936 FOR_EACH_OBSERVER(
2937 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322938}
2939
[email protected]b172aee2012-04-10 17:05:262940void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522941 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322942 // Don't notify the world, since this came from a renderer in the
2943 // background.
2944 return;
2945 }
2946
[email protected]da7a7182013-09-06 08:11:112947 notify_disconnection_ = true;
2948 // TODO(avi): Remove. http://crbug.com/170921
2949 NotificationService::current()->Notify(
2950 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2951 Source<WebContents>(this),
2952 NotificationService::NoDetails());
2953
[email protected]be1f56ab2011-12-22 06:55:312954 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232955 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302956
2957 // Restore the focus to the tab (otherwise the focus will be on the top
2958 // window).
[email protected]484ae5912010-09-29 19:16:142959 if (was_crashed && !FocusLocationBarByDefault() &&
2960 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062961 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142962 }
[email protected]32ded2212011-11-10 18:51:432963
[email protected]d8c660432011-12-22 20:51:252964 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322965}
2966
[email protected]ec6a7eb2013-04-22 17:34:222967void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2968 base::TerminationStatus status,
2969 int error_code) {
[email protected]151a63d2011-12-20 22:32:522970 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322971 // The pending page's RenderViewHost is gone.
2972 return;
2973 }
2974
[email protected]2fcdcc32014-03-05 02:14:072975 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
2976 // renderer may not have made a clean exit.
2977 if (IsFullscreenForCurrentTab())
2978 ToggleFullscreenMode(false);
2979
[email protected]698191dc2014-02-25 01:06:132980 // Cancel any visible dialogs so they are not left dangling over the sad tab.
2981 if (dialog_manager_)
2982 dialog_manager_->CancelActiveAndPendingDialogs(this);
2983
[email protected]d9030b82013-07-19 08:26:062984 ClearPowerSaveBlockers(rvh);
[email protected]e3b10d12014-03-28 16:06:092985 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:322986 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232987 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312988 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322989
[email protected]d8c660432011-12-22 20:51:252990 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272991 observers_,
[email protected]58d5cfe2013-07-10 02:40:522992 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322993}
2994
[email protected]b172aee2012-04-10 17:05:262995void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062996 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212997 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252998 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062999}
3000
[email protected]b172aee2012-04-10 17:05:263001void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3002 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043003 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153004 // Ensure that this state update comes from either the active RVH or one of
3005 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413006 // TODO(nasko): This should go through RenderFrameHost.
3007 // TODO(creis): We can't update state for cross-process subframes until we
3008 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3009 if (rvh != GetRenderViewHost() &&
3010 !GetRenderManager()->IsRVHOnSwappedOutList(
3011 static_cast<RenderViewHostImpl*>(rvh)))
3012 return;
[email protected]420ae012009-04-24 05:16:323013
3014 // We must be prepared to handle state updates for any page, these occur
3015 // when the user is scrolling and entering form data, as well as when we're
3016 // leaving a page, in which case our state may have already been moved to
3017 // the next page. The navigation controller will look up the appropriate
3018 // NavigationEntry and update it when it is notified via the delegate.
3019
3020 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583021 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323022 if (entry_index < 0)
3023 return;
[email protected]10f417c52011-12-28 21:04:233024 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323025
[email protected]691aa2f2013-05-28 22:52:043026 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323027 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043028 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323029 controller_.NotifyEntryChanged(entry, entry_index);
3030}
3031
[email protected]b172aee2012-04-10 17:05:263032void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3033 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263034 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263035 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323036 // If we have a title, that's a pretty good indication that we've started
3037 // getting useful data.
3038 SetNotWaitingForResponse();
3039
[email protected]73eb2602012-02-09 19:50:553040 // Try to find the navigation entry, which might not be the current one.
3041 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233042 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583043 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093044
[email protected]73eb2602012-02-09 19:50:553045 // We can handle title updates when we don't have an entry in
3046 // UpdateTitleForEntry, but only if the update is from the current RVH.
3047 if (!entry && rvh != GetRenderViewHost())
3048 return;
3049
[email protected]a49e10b2011-08-01 23:57:463050 // TODO(evan): make use of title_direction.
3051 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093052 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323053 return;
3054
3055 // Broadcast notifications when the UI should be updated.
3056 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213057 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323058}
3059
[email protected]b172aee2012-04-10 17:05:263060void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3061 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313062 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323063}
3064
[email protected]b172aee2012-04-10 17:05:263065void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513066 if (delegate_)
3067 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323068}
3069
[email protected]b172aee2012-04-10 17:05:263070void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103071#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293072 // The UI may be in an event-tracking loop, such as between the
3073 // mouse-down and mouse-up in text selection or a button click.
3074 // Defer the close until after tracking is complete, so that we
3075 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293076 // TODO(shess): This could get more fine-grained. For instance,
3077 // closing a tab in another window while selecting text in the
3078 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103079 if (view_->IsEventTracking()) {
3080 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293081 return;
3082 }
[email protected]60780f412013-02-25 16:34:103083#endif
[email protected]07707302009-11-06 00:50:293084
[email protected]420ae012009-04-24 05:16:323085 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523086 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513087 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323088}
3089
[email protected]66bbadaf2014-03-28 16:25:543090void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573091 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3092 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573093}
3094
[email protected]b172aee2012-04-10 17:05:263095void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513096 if (delegate_ && delegate_->IsPopupOrPanel(this))
3097 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323098}
3099
[email protected]e3b10d12014-03-28 16:06:093100void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3101 bool to_different_document) {
3102 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3103 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323104}
3105
[email protected]723971b2014-02-12 11:08:253106void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323107 scoped_ptr<LoadNotificationDetails> details;
3108
[email protected]9595fd82013-04-19 21:28:493109 // Use the last committed entry rather than the active one, in case a
3110 // pending entry has been created.
3111 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203112 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493113
[email protected]420ae012009-04-24 05:16:323114 // An entry may not exist for a stop when loading an initial blank page or
3115 // if an iframe injected by script into a blank page finishes loading.
3116 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203117 base::TimeDelta elapsed =
3118 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323119
3120 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513121 entry->GetVirtualURL(),
3122 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323123 elapsed,
3124 &controller_,
3125 controller_.GetCurrentEntryIndex()));
3126 }
3127
[email protected]e3b10d12014-03-28 16:06:093128 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3129 details.get());
[email protected]420ae012009-04-24 05:16:323130}
3131
[email protected]b172aee2012-04-10 17:05:263132void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163133 controller_.DiscardNonCommittedEntries();
3134
3135 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213136 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163137}
3138
[email protected]b172aee2012-04-10 17:05:263139void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513140 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133141 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403142}
3143
[email protected]7cc78902012-12-06 02:32:263144void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393145 if (opener_) {
3146 // Clear our opener so that future cross-process navigations don't have an
3147 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103148 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393149 opener_ = NULL;
3150 }
[email protected]7cc78902012-12-06 02:32:263151
3152 // Notify all swapped out RenderViewHosts for this tab. This is important
3153 // in case we go back to them, or if another window in those processes tries
3154 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213155 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263156}
3157
[email protected]59167c22013-06-03 18:07:323158void WebContentsImpl::DidAccessInitialDocument() {
3159 // Update the URL display.
3160 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3161}
3162
[email protected]87717d0e2012-04-26 02:58:433163void WebContentsImpl::DocumentAvailableInMainFrame(
3164 RenderViewHost* render_view_host) {
3165 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3166 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103167}
3168
[email protected]b172aee2012-04-10 17:05:263169void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083170 RenderViewHost* render_view_host,
3171 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093172 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3173 DocumentOnLoadCompletedInMainFrame(page_id));
3174
3175 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213176 NotificationService::current()->Notify(
3177 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3178 Source<WebContents>(this),
3179 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083180}
3181
[email protected]e1c3a552012-05-04 20:51:323182void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3183 // Tell the active RenderViewHost to run unload handlers and close, as long
3184 // as the request came from a RenderViewHost in the same BrowsingInstance.
3185 // In most cases, we receive this from a swapped out RenderViewHost.
3186 // It is possible to receive it from one that has just been swapped in,
3187 // in which case we might as well deliver the message anyway.
3188 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3189 GetRenderViewHost()->ClosePage();
3190}
3191
[email protected]f546640b2012-05-15 00:03:493192void WebContentsImpl::RouteMessageEvent(
3193 RenderViewHost* rvh,
3194 const ViewMsg_PostMessage_Params& params) {
3195 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363196 // came from a RenderViewHost in the same BrowsingInstance or if this
3197 // WebContents is dedicated to a browser plugin guest.
3198 // Note: This check means that an embedder could theoretically receive a
3199 // postMessage from anyone (not just its own guests). However, this is
3200 // probably not a risk for apps since other pages won't have references
3201 // to App windows.
3202 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3203 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493204 return;
3205
3206 ViewMsg_PostMessage_Params new_params(params);
3207
[email protected]0bc7f3542013-10-21 15:05:533208 if (!params.message_port_ids.empty()) {
3209 MessagePortMessageFilter* message_port_message_filter =
3210 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3211 ->message_port_message_filter();
3212 std::vector<int> new_routing_ids(params.message_port_ids.size());
3213 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3214 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3215 MessagePortService::GetInstance()->UpdateMessagePort(
3216 params.message_port_ids[i],
3217 message_port_message_filter,
3218 new_routing_ids[i]);
3219 }
3220 new_params.new_routing_ids = new_routing_ids;
3221 }
3222
[email protected]f546640b2012-05-15 00:03:493223 // If there is a source_routing_id, translate it to the routing ID for
3224 // the equivalent swapped out RVH in the target process. If we need
3225 // to create a swapped out RVH for the source tab, we create its opener
3226 // chain as well, since those will also be accessible to the target page.
3227 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3228 // Try to look up the WebContents for the source page.
3229 WebContentsImpl* source_contents = NULL;
3230 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3231 rvh->GetProcess()->GetID(), params.source_routing_id);
3232 if (source_rvh) {
3233 source_contents = static_cast<WebContentsImpl*>(
3234 source_rvh->GetDelegate()->GetAsWebContents());
3235 }
3236
3237 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363238 if (GetBrowserPluginGuest()) {
3239 // We create a swapped out RenderView for the embedder in the guest's
3240 // render process but we intentionally do not expose the embedder's
3241 // opener chain to it.
3242 new_params.source_routing_id =
3243 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3244 } else {
3245 new_params.source_routing_id =
3246 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3247 }
[email protected]f546640b2012-05-15 00:03:493248 } else {
3249 // We couldn't find it, so don't pass a source frame.
3250 new_params.source_routing_id = MSG_ROUTING_NONE;
3251 }
3252 }
3253
3254 // In most cases, we receive this from a swapped out RenderViewHost.
3255 // It is possible to receive it from one that has just been swapped in,
3256 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183257 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493258}
3259
[email protected]b172aee2012-04-10 17:05:263260void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343261 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263262 const base::string16& message,
3263 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323264 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213265 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323266 IPC::Message* reply_msg,
3267 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073268 // Suppress JavaScript dialogs when requested. Also suppress messages when
3269 // showing an interstitial as it's shown over the previous page and we don't
3270 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503271 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243272 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() ||
[email protected]0bfbf882011-12-22 18:19:273273 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073274 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523275 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153276 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323277
3278 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213279 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433280 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153281 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3282 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433283 this,
3284 frame_url.GetOrigin(),
3285 accept_lang,
3286 javascript_message_type,
3287 message,
[email protected]51da7e32012-01-30 19:24:523288 default_prompt,
[email protected]b172aee2012-04-10 17:05:263289 base::Bind(&WebContentsImpl::OnDialogClosed,
3290 base::Unretained(this),
3291 rvh,
3292 reply_msg),
[email protected]51da7e32012-01-30 19:24:523293 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323294 }
[email protected]3ab9cb82011-06-03 18:02:073295
[email protected]6dd2f1e2013-09-11 15:06:013296 *did_suppress_message = suppress_this_message;
3297
[email protected]3ab9cb82011-06-03 18:02:073298 if (suppress_this_message) {
3299 // If we are suppressing messages, just reply as if the user immediately
3300 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263301 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073302 }
3303
[email protected]6dd2f1e2013-09-11 15:06:013304 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3305 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323306}
3307
[email protected]b172aee2012-04-10 17:05:263308void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263309 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263310 bool is_reload,
3311 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583312 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513313 if (delegate_)
3314 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073315
3316 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243317 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
[email protected]3ab9cb82011-06-03 18:02:073318 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523319 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153320 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153321 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343322 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263323 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503324 return;
3325 }
[email protected]3ab9cb82011-06-03 18:02:073326
[email protected]7ab1e7d62009-10-14 23:32:013327 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153328 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3329 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323330 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263331 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523332 reply_msg));
[email protected]420ae012009-04-24 05:16:323333}
3334
[email protected]a796f202012-05-30 14:14:253335bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263336 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253337 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263338 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253339 if (!delegate_)
3340 return false;
3341 return delegate_->AddMessageToConsole(this, level, message, line_no,
3342 source_id);
3343}
3344
[email protected]b172aee2012-04-10 17:05:263345WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273346 // We want to base the page config off of the actual URL, rather than the
3347 // virtual URL.
3348 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3349 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003350 GURL url = controller_.GetActiveEntry()
3351 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153352
[email protected]fa944cb82013-11-15 17:51:213353 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323354}
3355
[email protected]0eba810b2012-10-18 03:19:363356int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213357 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413358 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3359 true, true);
[email protected]0eba810b2012-10-18 03:19:363360}
3361
[email protected]b172aee2012-04-10 17:05:263362void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273363 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253364 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223365
[email protected]ea114722012-03-12 01:11:253366 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173367 if (rdh) // NULL in unittests.
3368 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253369}
3370
[email protected]b172aee2012-04-10 17:05:263371void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443372 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253373 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443374}
3375
[email protected]b172aee2012-04-10 17:05:263376void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563377 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263378 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153379 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523380 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153381 return;
3382
[email protected]9f76c1e2012-03-05 15:15:583383 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3384
[email protected]e5fc1632011-08-08 07:51:533385 // Ignore renderer unresponsive event if debugger is attached to the tab
3386 // since the event may be a result of the renderer sitting on a breakpoint.
3387 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363388 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533389 return;
3390
[email protected]2e9d79f2013-08-16 05:45:563391 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323392 // Hang occurred while firing the beforeunload/unload handler.
3393 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583394 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323395
[email protected]fa944cb82013-11-15 17:51:213396 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323397 return;
3398
3399 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563400 // nothing we can do to recover. If the hang is in the beforeunload handler,
3401 // pretend the beforeunload listeners have all fired and allow the delegate
3402 // to continue closing; the user will not have the option of cancelling the
3403 // close. Otherwise, pretend the unload listeners have all fired and close
3404 // the tab.
3405 bool close = true;
3406 if (is_during_beforeunload) {
3407 delegate_->BeforeUnloadFired(this, true, &close);
3408 }
3409 if (close)
3410 Close(rvh);
[email protected]420ae012009-04-24 05:16:323411 return;
3412 }
3413
[email protected]9f76c1e2012-03-05 15:15:583414 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473415 return;
3416
[email protected]6934a702011-12-20 00:04:513417 if (delegate_)
3418 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323419}
3420
[email protected]b172aee2012-04-10 17:05:263421void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513422 if (delegate_)
3423 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323424}
3425
[email protected]b172aee2012-04-10 17:05:263426void WebContentsImpl::LoadStateChanged(
3427 const GURL& url,
3428 const net::LoadStateWithParam& load_state,
3429 uint64 upload_position,
3430 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323431 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563432 upload_position_ = upload_position;
3433 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503434 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213435 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303436 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213437 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323438 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463439 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213440 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463441 }
[email protected]420ae012009-04-24 05:16:323442}
3443
[email protected]b172aee2012-04-10 17:05:263444void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553445 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323446 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123447 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3448 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513449 if (delegate_)
3450 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093451 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323452}
3453
[email protected]58d5cfe2013-07-10 02:40:523454void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543455 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233456 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223457 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543458}
3459
[email protected]b172aee2012-04-10 17:05:263460void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103461 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213462 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263463 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3464 // here during container initialization and normal window size will be set
3465 // later. In case of tab duplication this resizing to 0x0 prevents setting
3466 // normal size later so just ignore it.
3467 if (!size.IsEmpty())
3468 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323469}
3470
[email protected]af905902013-10-01 21:38:513471void WebContentsImpl::CancelModalDialogsForRenderManager() {
3472 // We need to cancel modal dialogs when doing a process swap, since the load
3473 // deferrer would prevent us from swapping out.
3474 if (dialog_manager_)
3475 dialog_manager_->CancelActiveAndPendingDialogs(this);
3476}
3477
[email protected]7b712ee22013-10-03 00:57:283478void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3479 RenderViewHost* new_host) {
3480 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083481
3482 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003483 if (delegate_)
3484 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393485
[email protected]7b712ee22013-10-03 00:57:283486 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543487}
3488
[email protected]14392a52012-05-02 20:28:443489int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3490 SiteInstance* instance) {
3491 if (!opener_)
3492 return MSG_ROUTING_NONE;
3493
3494 // Recursively create RenderViews for anything else in the opener chain.
3495 return opener_->CreateOpenerRenderViews(instance);
3496}
3497
3498int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3499 int opener_route_id = MSG_ROUTING_NONE;
3500
3501 // If this tab has an opener, ensure it has a RenderView in the given
3502 // SiteInstance as well.
3503 if (opener_)
3504 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3505
[email protected]45a22ad2013-02-21 03:25:003506 // If any of the renderers (current, pending, or swapped out) for this
3507 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213508 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3509 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373510
[email protected]fa944cb82013-11-15 17:51:213511 if (GetRenderManager()->pending_render_view_host() &&
3512 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3513 instance)
3514 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003515
[email protected]fa944cb82013-11-15 17:51:213516 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373517 instance);
3518 if (rvh)
3519 return rvh->GetRoutingID();
3520
[email protected]14392a52012-05-02 20:28:443521 // Create a swapped out RenderView in the given SiteInstance if none exists,
3522 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413523 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3524 true, true);
[email protected]14392a52012-05-02 20:28:443525}
3526
[email protected]b172aee2012-04-10 17:05:263527NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193528 return GetController();
[email protected]3a3d47472010-07-15 21:03:543529}
3530
[email protected]b172aee2012-04-10 17:05:263531WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563532 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323533}
3534
[email protected]10f417c52011-12-28 21:04:233535NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263536 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323537 return controller_.GetLastCommittedEntry();
3538}
3539
[email protected]b172aee2012-04-10 17:05:263540bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163541 RenderViewHost* render_view_host,
3542 int opener_route_id,
3543 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033544 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443545 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163546 RenderWidgetHostView* rwh_view;
3547 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3548 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3549 // case this because RWH is still a base class of RenderViewHost, and child
3550 // frame RWHVs are unique in that they do not have their own WebContents.
3551 if (frame_connector) {
3552 RenderWidgetHostViewChildFrame* rwh_view_child =
3553 new RenderWidgetHostViewChildFrame(render_view_host);
3554 frame_connector->set_view(rwh_view_child);
3555 rwh_view = rwh_view_child;
3556 } else {
3557 rwh_view = view_->CreateViewForWidget(render_view_host);
3558 }
[email protected]1a98a932009-11-17 00:12:523559
[email protected]420ae012009-04-24 05:16:323560 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443561 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213562 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323563
[email protected]74ce1ad2011-12-16 21:51:463564 // Make sure we use the correct starting page_id in the new RenderView.
3565 UpdateMaxPageIDIfNecessary(render_view_host);
3566 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583567 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463568
[email protected]9f76c1e2012-03-05 15:15:583569 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263570 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493571 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133572 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523573 return false;
[email protected]14392a52012-05-02 20:28:443574 }
[email protected]a4127722011-04-27 23:13:523575
[email protected]a220b5932013-09-21 03:47:443576#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503577 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3578 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443579 if (rwh_view) {
3580 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3581 render_widget_host->WasResized();
3582 }
[email protected]f8233cc2011-05-31 20:24:503583#endif
3584
[email protected]420ae012009-04-24 05:16:323585 return true;
3586}
3587
[email protected]7d244f12013-08-22 21:41:513588#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183589base::android::ScopedJavaLocalRef<jobject>
3590WebContentsImpl::GetJavaWebContents() {
3591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3592
3593 WebContentsAndroid* web_contents_android =
3594 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3595 if (!web_contents_android) {
3596 web_contents_android = new WebContentsAndroid(this);
3597 SetUserData(kWebContentsAndroidKey, web_contents_android);
3598 }
3599 return web_contents_android->GetJavaObject();
3600}
3601
[email protected]7d244f12013-08-22 21:41:513602bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3603 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163604 MSG_ROUTING_NONE,
3605 NULL);
[email protected]7d244f12013-08-22 21:41:513606}
3607#endif
3608
[email protected]b172aee2012-04-10 17:05:263609void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3610 IPC::Message* reply_msg,
3611 bool success,
[email protected]fcf75d42013-12-03 20:11:263612 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543613 if (is_showing_before_unload_dialog_ && !success) {
3614 // If a beforeunload dialog is canceled, we need to stop the throbber from
3615 // spinning, since we forced it to start spinning in Navigate.
[email protected]723971b2014-02-12 11:08:253616 DidStopLoading(rvh->GetMainFrame());
[email protected]15d160c02012-07-04 10:52:353617 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103618
[email protected]6d65a462013-06-21 21:29:123619 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3620 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543621 }
3622 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583623 static_cast<RenderViewHostImpl*>(
3624 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543625}
3626
[email protected]b172aee2012-04-10 17:05:263627void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213628 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123629 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103630}
[email protected]f45d2a72010-03-08 23:28:353631
[email protected]b172aee2012-04-10 17:05:263632void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103633 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443634 // Can be NULL during tests.
3635 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213636 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363637}
[email protected]9f76c1e2012-03-05 15:15:583638
[email protected]1ac10dca2013-08-20 20:47:043639bool WebContentsImpl::IsHidden() {
3640 return capturer_count_ == 0 && !should_normally_be_visible_;
3641}
3642
[email protected]b0936d22013-11-28 06:47:363643RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213644 return frame_tree_.root()->render_manager();
3645}
3646
[email protected]b172aee2012-04-10 17:05:263647RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583648 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3649}
[email protected]7900bfdb2012-05-24 19:31:243650
[email protected]f8497342013-02-05 22:15:023651BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393652 return browser_plugin_guest_.get();
3653}
3654
[email protected]738f57a2013-06-29 21:06:543655void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3656 CHECK(!browser_plugin_guest_);
3657 browser_plugin_guest_.reset(guest);
3658}
3659
[email protected]f8497342013-02-05 22:15:023660BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393661 return browser_plugin_embedder_.get();
3662}
[email protected]8ff00d72012-10-23 19:12:213663
[email protected]8eb04562013-03-06 03:41:143664BrowserPluginGuestManager*
3665 WebContentsImpl::GetBrowserPluginGuestManager() const {
3666 return static_cast<BrowserPluginGuestManager*>(
3667 GetBrowserContext()->GetUserData(
3668 browser_plugin::kBrowserPluginGuestManagerKeyName));
3669}
3670
[email protected]d9030b82013-07-19 08:26:063671void WebContentsImpl::ClearPowerSaveBlockers(
3672 RenderViewHost* render_view_host) {
3673 STLDeleteValues(&power_save_blockers_[render_view_host]);
3674 power_save_blockers_.erase(render_view_host);
3675}
3676
3677void WebContentsImpl::ClearAllPowerSaveBlockers() {
3678 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3679 i != power_save_blockers_.end(); ++i)
3680 STLDeleteValues(&power_save_blockers_[i->first]);
3681 power_save_blockers_.clear();
3682}
3683
[email protected]dc0fd432013-08-27 15:29:213684gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3685 gfx::Size size;
3686 if (delegate_)
3687 size = delegate_->GetSizeForNewRenderView(this);
3688 if (size.IsEmpty())
3689 size = view_->GetContainerSize();
3690 return size;
3691}
3692
[email protected]9b159a52013-10-03 17:24:553693void WebContentsImpl::OnFrameRemoved(
3694 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583695 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553696 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583697 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553698}
3699
[email protected]222f5822014-02-05 23:40:493700void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3701 if (!delegate_)
3702 return;
3703 const gfx::Size new_size = GetPreferredSize();
3704 if (new_size != old_size)
3705 delegate_->UpdatePreferredSize(this, new_size);
3706}
3707
[email protected]8ff00d72012-10-23 19:12:213708} // namespace content