blob: 340f8a4bd6a1155acf9eccec38c6667b701d909e [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]348fbaac2013-06-11 06:31:5115#include "base/strings/string16.h"
16#include "base/strings/string_number_conversions.h"
17#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0018#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3719#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3920#include "content/browser/browser_plugin/browser_plugin_embedder.h"
21#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]8eb04562013-03-06 03:41:1422#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
[email protected]b9535422012-02-09 01:47:5923#include "content/browser/child_process_security_policy_impl.h"
[email protected]70019152012-12-19 11:44:1924#include "content/browser/devtools/devtools_manager_impl.h"
[email protected]5f2aa722013-08-07 16:59:4125#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0426#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4627#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1228#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1629#include "content/browser/download/save_package.h"
[email protected]d4a8ca482013-10-30 21:06:4030#include "content/browser/frame_host/interstitial_page_impl.h"
31#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]5c9250872012-01-30 17:24:0532#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4433#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5334#include "content/browser/message_port_message_filter.h"
35#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0636#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3037#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3238#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5039#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3340#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1141#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5842#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0343#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5644#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1445#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4246#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]41225fe2013-03-29 05:32:0247#include "content/common/image_messages.h"
[email protected]35be7ec2012-02-12 20:42:5148#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0249#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5750#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5851#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1152#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2053#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4454#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3655#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1756#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1457#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4658#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1559#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0060#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2761#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0062#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3763#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1464#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3265#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3466#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3867#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4268#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2569#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1070#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2171#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4872#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5473#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4974#include "content/public/common/page_zoom.h"
[email protected]a1d29162011-10-14 17:14:0375#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1676#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2977#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5378#include "net/http/http_cache.h"
79#include "net/http/http_transaction_factory.h"
80#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3481#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5682#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0183#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4184#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5285#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1886#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3187
[email protected]583418cc2013-01-17 14:01:1088#if defined(OS_ANDROID)
89#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3290#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
91#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:0092#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:1093#endif
94
[email protected]f66df822012-05-18 16:52:1795#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5096#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:2797#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5798#endif
[email protected]3e45ba92009-02-20 21:09:0099
[email protected]420ae012009-04-24 05:16:32100// Cross-Site Navigations
101//
[email protected]b172aee2012-04-10 17:05:26102// If a WebContentsImpl is told to navigate to a different web site (as
103// determined by SiteInstance), it will replace its current RenderViewHost with
104// a new RenderViewHost dedicated to the new SiteInstance. This works as
105// follows:
[email protected]420ae012009-04-24 05:16:32106//
[email protected]fc6c1872013-10-03 01:22:35107// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46108// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32109// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35110// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32111// run in the current RVH.
112// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35113// that it has a pending cross-site request. We will check this on the IO
114// thread when deciding how to handle the response.
115// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46116// cancel all the pending logic. Otherwise we allow the pending RVH to send
117// the navigation request to its renderer.
118// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35119// main resource load on the pending RVH. It creates a
120// CrossSiteResourceHandler to check whether a process swap is needed when
121// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46122// - When RDH receives a response, the BufferedResourceHandler determines
123// whether it is a download. If so, it sends a message to the new renderer
124// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26125// pending RVH remains until the next DidNavigate event for this
126// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32127// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35128// download, the CrossSiteResourceHandler checks whether a process swap is
129// needed (either because CrossSiteRequestManager has state for it or because
130// a transfer was needed for a redirect).
131// - If so, CrossSiteResourceHandler pauses the response to first run the old
132// page's unload handler. It does this by asynchronously calling the
133// OnCrossSiteResponse method of RenderViewHostManager on the UI thread, which
134// sends a SwapOut message to the current RVH.
135// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
136// to a new process is needed, based on the stored pending_nav_params_. (This
137// is independent of whether we started out with a cross-process navigation.)
138// - If not, it just tells the ResourceDispatcherHost to resume the response
139// to its current RenderViewHost.
140// - If so, it cancels the current pending RenderViewHost and sets up a new
141// navigation using RequestTransferURL. When the transferred request
142// arrives in the ResourceDispatcherHost, we transfer the response and
143// resume it.
[email protected]420ae012009-04-24 05:16:32144// - The pending renderer sends a FrameNavigate message that invokes the
145// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46146// pending RVH.
[email protected]992db4c2011-05-12 15:37:15147// - The previous renderer is kept swapped out in RenderViewHostManager in case
148// the user goes back. The process only stays live if another tab is using
149// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32150
[email protected]8ff00d72012-10-23 19:12:21151namespace content {
[email protected]420ae012009-04-24 05:16:32152namespace {
153
[email protected]82114f52012-03-20 22:53:41154const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05155
[email protected]cbb1ef592013-06-05 19:49:46156base::LazyInstance<std::vector<WebContents::CreatedCallback> >
157g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
158
[email protected]795c28972012-12-06 06:13:39159static int StartDownload(content::RenderViewHost* rvh,
160 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29161 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30162 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02163 static int g_next_image_download_id = 0;
164 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
165 ++g_next_image_download_id,
166 url,
167 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30168 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02169 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39170}
171
[email protected]2c5569662011-03-22 20:45:02172ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21173 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50174 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16175 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47176 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02177 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47178 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02179 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23180 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
181 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47182 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16183 break; // Fall through to rest of function.
184 }
[email protected]5e369672009-11-03 23:48:30185
[email protected]59246c572012-02-10 13:32:13186 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
187 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36188 if (entry.restore_type() ==
189 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13190 if (entry.GetHasPostData())
191 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02192 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13193 }
[email protected]5e369672009-11-03 23:48:30194
[email protected]2c5569662011-03-22 20:45:02195 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30196}
197
[email protected]10f417c52011-12-28 21:04:23198void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47199 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21200 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50201 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16202 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51203 params->page_id = entry.GetPageID();
[email protected]60d6cca2013-04-30 08:47:13204 params->should_clear_history_list = entry.should_clear_history_list();
205 if (entry.should_clear_history_list()) {
206 // Set the history list related parameters to the same values a
207 // NavigationController would return before its first navigation. This will
208 // fully clear the RenderView's view of the session history.
209 params->pending_history_list_offset = -1;
210 params->current_history_list_offset = -1;
211 params->current_history_list_length = 0;
212 } else {
213 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
214 params->current_history_list_offset =
215 controller.GetLastCommittedEntryIndex();
216 params->current_history_list_length = controller.GetEntryCount();
217 }
[email protected]eaaba7dd2013-10-14 02:38:07218 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36219 if (!entry.GetBaseURLForDataURL().is_empty()) {
220 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
221 params->history_url_for_data_url = entry.GetVirtualURL();
222 }
[email protected]36fc0392011-12-25 03:59:51223 params->referrer = entry.GetReferrer();
224 params->transition = entry.GetTransitionType();
[email protected]691aa2f2013-05-28 22:52:04225 params->page_state = entry.GetPageState();
[email protected]3cc72b12010-03-18 23:03:00226 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55227 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34228 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47229 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48230 params->transferred_request_child_id =
231 entry.transferred_global_request_id().child_id;
232 params->transferred_request_request_id =
233 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22234 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00235 // Avoid downloading when in view-source mode.
236 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44237 params->is_post = entry.GetHasPostData();
[email protected]eaaba7dd2013-10-14 02:38:07238 if (entry.GetBrowserInitiatedPostData()) {
239 params->browser_initiated_post_data.assign(
240 entry.GetBrowserInitiatedPostData()->front(),
241 entry.GetBrowserInitiatedPostData()->front() +
242 entry.GetBrowserInitiatedPostData()->size());
[email protected]7c16976c2012-08-04 02:38:23243 }
244
[email protected]f8872902013-10-30 03:18:57245 params->redirects = entry.redirect_chain();
246
[email protected]951a64832012-10-11 16:26:37247 params->can_load_local_resources = entry.GetCanLoadLocalResources();
[email protected]3027cf02013-01-24 08:16:58248 params->frame_to_navigate = entry.GetFrameToNavigate();
[email protected]951a64832012-10-11 16:26:37249
[email protected]6c6b02d2011-09-02 03:36:47250 if (delegate)
251 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34252}
253
[email protected]8bfc8272013-09-09 20:10:53254void NotifyCacheOnIO(
255 scoped_refptr<net::URLRequestContextGetter> request_context,
256 const GURL& url,
257 const std::string& http_method) {
258 request_context->GetURLRequestContext()->http_transaction_factory()->
259 GetCache()->OnExternalCacheHit(url, http_method);
260}
261
[email protected]9b159a52013-10-03 17:24:55262// Helper function for retrieving all the sites in a frame tree.
263bool CollectSites(BrowserContext* context,
264 std::set<GURL>* sites,
265 FrameTreeNode* node) {
266 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
267 return true;
268}
269
[email protected]420ae012009-04-24 05:16:32270} // namespace
271
[email protected]54944cde2012-12-09 09:24:59272WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15273 return WebContentsImpl::CreateWithOpener(
274 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19275}
276
277WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59278 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30279 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59280 WebContentsImpl* new_contents = new WebContentsImpl(
281 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30282
283 for (SessionStorageNamespaceMap::const_iterator it =
284 session_storage_namespace_map.begin();
285 it != session_storage_namespace_map.end();
286 ++it) {
287 new_contents->GetController()
288 .SetSessionStorageNamespace(it->first, it->second.get());
289 }
290
[email protected]54944cde2012-12-09 09:24:59291 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19292 return new_contents;
[email protected]a81343d232011-12-27 07:39:20293}
[email protected]746d3052012-05-22 15:15:47294
[email protected]cbb1ef592013-06-05 19:49:46295void WebContents::AddCreatedCallback(const CreatedCallback& callback) {
296 g_created_callbacks.Get().push_back(callback);
297}
298
299void WebContents::RemoveCreatedCallback(const CreatedCallback& callback) {
300 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
301 if (g_created_callbacks.Get().at(i).Equals(callback)) {
302 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
303 return;
304 }
305 }
306}
307
[email protected]299d7f12012-05-23 05:31:15308WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47309 return rvh->GetDelegate()->GetAsWebContents();
310}
311
[email protected]7fff43e2013-05-21 20:21:10312// WebContentsImpl::DestructionObserver ----------------------------------------
313
314class WebContentsImpl::DestructionObserver : public WebContentsObserver {
315 public:
316 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
317 : WebContentsObserver(watched_contents),
318 owner_(owner) {
319 }
320
321 // WebContentsObserver:
322 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
323 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
324 }
325
326 private:
327 WebContentsImpl* owner_;
328
329 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
330};
331
[email protected]b172aee2012-04-10 17:05:26332// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32333
[email protected]b172aee2012-04-10 17:05:26334WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21335 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19336 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42337 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22338 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57339 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44340 opener_(opener),
[email protected]c73a2282013-04-29 21:10:41341#if defined(OS_WIN) && defined(USE_AURA)
342 accessible_parent_(NULL),
343#endif
[email protected]69e797f2013-04-30 01:10:22344 render_manager_(this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34345 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23346 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
347 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34348 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21349 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56350 upload_size_(0),
351 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47352 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55353 capturer_count_(0),
354 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57355 is_being_destroyed_(false),
356 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15357 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01358 is_showing_before_unload_dialog_(false),
[email protected]ebf40a72010-07-22 01:46:38359 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21360 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
361 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00362 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21363 color_chooser_identifier_(0),
[email protected]f8bebfb2013-03-06 04:22:58364 message_source_(NULL),
[email protected]44470a22013-01-24 01:21:54365 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
[email protected]cbb1ef592013-06-05 19:49:46366 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
367 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55368 frame_tree_.SetFrameRemoveListener(
369 base::Bind(&WebContentsImpl::OnFrameRemoved,
370 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35371}
initial.commit09911bf2008-07-26 23:55:29372
[email protected]b172aee2012-04-10 17:05:26373WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32374 is_being_destroyed_ = true;
375
[email protected]d9030b82013-07-19 08:26:06376 ClearAllPowerSaveBlockers();
377
[email protected]b24b68a2012-09-24 21:57:26378 for (std::set<RenderWidgetHostImpl*>::iterator iter =
379 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
380 (*iter)->DetachDelegate();
381 }
382 created_widgets_.clear();
383
[email protected]3ab9cb82011-06-03 18:02:07384 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15385 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11386 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07387
[email protected]da8543762012-03-20 08:52:20388 if (color_chooser_)
389 color_chooser_->End();
390
[email protected]420ae012009-04-24 05:16:32391 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32392
[email protected]ca13a442012-04-17 14:00:12393 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21394 NotificationService::current()->Notify(
395 NOTIFICATION_WEB_CONTENTS_DESTROYED,
396 Source<WebContents>(this),
397 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32398
399 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07400#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32401 // If we still have a window handle, destroy it. GetNativeView can return
402 // NULL if this contents was part of a window that closed.
[email protected]f3615f02013-02-26 06:09:06403 if (view_->GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52404 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58405 if (host && host->GetView())
406 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42407 }
[email protected]420ae012009-04-24 05:16:32408#endif
[email protected]7ab1e7d62009-10-14 23:32:01409
[email protected]f273ee52013-10-18 16:05:27410 RenderViewHost* pending_rvh = render_manager_.pending_render_view_host();
411 if (pending_rvh) {
412 FOR_EACH_OBSERVER(WebContentsObserver,
413 observers_,
414 RenderViewDeleted(pending_rvh));
415 }
416
417 FOR_EACH_OBSERVER(WebContentsObserver,
418 observers_,
419 RenderViewDeleted(render_manager_.current_host()));
420
[email protected]2db9bd72012-04-13 20:20:56421 FOR_EACH_OBSERVER(WebContentsObserver,
422 observers_,
423 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08424
[email protected]6934a702011-12-20 00:04:51425 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10426
427 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
428 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42429}
430
[email protected]d1198fd2012-08-13 22:50:19431WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59432 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19433 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03434 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59435 WebContentsImpl* new_contents = new WebContentsImpl(
436 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19437
[email protected]54944cde2012-12-09 09:24:59438 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19439 return new_contents;
440}
441
[email protected]b371a5652013-02-20 11:25:51442// static
[email protected]8eb04562013-03-06 03:41:14443BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36444 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53445 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54446 int guest_instance_id,
447 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39448 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39449
450 // This makes |new_contents| act as a guest.
451 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54452 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19453 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11454
[email protected]3de10bb32013-01-08 21:57:33455 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33456 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11457
[email protected]216be772013-01-25 00:22:27458 // We are instantiating a WebContents for browser plugin. Set its subframe bit
459 // to true.
460 static_cast<RenderViewHostImpl*>(
461 new_contents->GetRenderViewHost())->set_is_subframe(true);
462
[email protected]8eb04562013-03-06 03:41:14463 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39464}
465
[email protected]b172aee2012-04-10 17:05:26466RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28467 return &render_manager_;
468}
469
[email protected]7bb761892012-07-20 09:32:47470bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
471 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56472 if (GetWebUI() &&
473 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17474 return true;
[email protected]d2353452012-01-19 19:53:56475 }
[email protected]f82d57b52011-04-27 19:13:17476
[email protected]d8c660432011-12-22 20:51:25477 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
478 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10479 while ((observer = it.GetNext()) != NULL)
480 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53481 return true;
[email protected]403415a2011-01-10 18:57:53482
[email protected]7bb761892012-07-20 09:32:47483 // Message handlers should be aware of which RenderViewHost sent the
484 // message, which is temporarily stored in message_source_.
485 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18486 bool handled = true;
487 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26488 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]724159a2010-12-30 01:11:18489 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
490 OnDidLoadResourceFromMemoryCache)
491 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
492 OnDidDisplayInsecureContent)
493 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
494 OnDidRunInsecureContent)
495 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
496 OnDocumentLoadedInFrame)
497 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26498 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
499 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25500 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26501 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21502 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20503 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
504 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
505 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16506 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45507 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10508 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20509 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
510 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
511 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
512 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29513 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50514 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50515 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
516 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55517 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
518 OnBrowserPluginMessage(message))
519 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
520 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02521 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
522 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10523#if defined(OS_ANDROID)
524 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
525 OnFindMatchRectsReply)
526 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
527 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32528 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
529 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10530#endif
[email protected]d9030b82013-07-19 08:26:06531 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
[email protected]724159a2010-12-30 01:11:18532 IPC_MESSAGE_UNHANDLED(handled = false)
533 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47534 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18535
536 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21537 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18538 GetRenderProcessHost()->ReceivedBadMessage();
539 }
540
541 return handled;
542}
543
[email protected]b172aee2012-04-10 17:05:26544void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18545 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21546 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43547 if (delegate_)
548 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18549}
550
[email protected]d1198fd2012-08-13 22:50:19551NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56552 return controller_;
553}
554
[email protected]d1198fd2012-08-13 22:50:19555const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56556 return controller_;
557}
558
[email protected]8ff00d72012-10-23 19:12:21559BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55560 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30561}
562
[email protected]b172aee2012-04-10 17:05:26563const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24564 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32565 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51566 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31567}
568
[email protected]a093ce02013-07-22 20:53:14569const GURL& WebContentsImpl::GetVisibleURL() 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]c854a7e2013-05-21 16:42:24572 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
573}
574
575const GURL& WebContentsImpl::GetLastCommittedURL() const {
576 // We may not have a navigation entry yet.
577 NavigationEntry* entry = controller_.GetLastCommittedEntry();
578 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
579}
580
[email protected]8ff00d72012-10-23 19:12:21581WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31582 return delegate_;
583}
584
[email protected]8ff00d72012-10-23 19:12:21585void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31586 // TODO(cbentzel): remove this debugging code?
587 if (delegate == delegate_)
588 return;
589 if (delegate_)
590 delegate_->Detach(this);
591 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08592 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31593 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08594 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00595 if (view_)
596 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08597 }
[email protected]be1f56ab2011-12-22 06:55:31598}
599
[email protected]8ff00d72012-10-23 19:12:21600RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41601 RenderViewHostImpl* host = render_manager_.current_host();
602 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16603}
604
[email protected]b172aee2012-04-10 17:05:26605RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31606 return render_manager_.current_host();
607}
608
[email protected]a04c9d02012-11-14 21:04:34609void WebContentsImpl::GetRenderViewHostAtPosition(
610 int x,
611 int y,
612 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
613 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
614 if (embedder)
615 embedder->GetRenderViewHostAtPosition(x, y, callback);
616 else
617 callback.Run(GetRenderViewHost(), x, y);
618}
619
[email protected]bfcfa692013-02-07 06:17:02620WebContents* WebContentsImpl::GetEmbedderWebContents() const {
621 BrowserPluginGuest* guest = GetBrowserPluginGuest();
622 if (guest)
623 return guest->embedder_web_contents();
624 return NULL;
625}
626
627int WebContentsImpl::GetEmbeddedInstanceID() const {
628 BrowserPluginGuest* guest = GetBrowserPluginGuest();
629 if (guest)
630 return guest->instance_id();
631 return 0;
632}
633
[email protected]6b618e62012-08-16 12:59:18634int WebContentsImpl::GetRoutingID() const {
635 if (!GetRenderViewHost())
636 return MSG_ROUTING_NONE;
637
638 return GetRenderViewHost()->GetRoutingID();
639}
640
[email protected]44470a22013-01-24 01:21:54641int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
642 return fullscreen_widget_routing_id_;
643}
644
[email protected]b172aee2012-04-10 17:05:26645RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31646 return render_manager_.GetRenderWidgetHostView();
647}
648
[email protected]f8497342013-02-05 22:15:02649RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
650 BrowserPluginGuest* guest = GetBrowserPluginGuest();
651 if (guest && guest->embedder_web_contents()) {
652 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
653 }
654 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
655}
656
[email protected]4aebbca2013-09-17 22:26:49657RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
658 const {
659 RenderWidgetHost* const widget_host =
660 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
661 GetFullscreenWidgetRoutingID());
662 return widget_host ? widget_host->GetView() : NULL;
663}
664
[email protected]8ff00d72012-10-23 19:12:21665WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31666 return view_.get();
667}
668
[email protected]8ff00d72012-10-23 19:12:21669WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56670 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03671 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
672 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22673 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58674 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22675 web_ui->SetController(controller);
676 return web_ui;
677 }
678
679 delete web_ui;
680 return NULL;
681}
682
[email protected]8ff00d72012-10-23 19:12:21683WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31684 return render_manager_.web_ui() ? render_manager_.web_ui()
685 : render_manager_.pending_web_ui();
686}
687
[email protected]8ff00d72012-10-23 19:12:21688WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31689 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34690}
691
[email protected]86ef6a392012-05-11 22:03:11692void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22693 if (GetUserAgentOverride() == override)
694 return;
695
696 renderer_preferences_.user_agent_override = override;
697
698 // Send the new override string to the renderer.
699 RenderViewHost* host = GetRenderViewHost();
700 if (host)
701 host->SyncRendererPrefs();
702
703 // Reload the page if a load is currently in progress to avoid having
704 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27705 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22706 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
707 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53708
709 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
710 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11711}
712
713const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22714 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11715}
716
[email protected]c73a2282013-04-29 21:10:41717#if defined(OS_WIN) && defined(USE_AURA)
718void WebContentsImpl::SetParentNativeViewAccessible(
719gfx::NativeViewAccessible accessible_parent) {
720 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45721 if (GetRenderViewHost())
722 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41723}
724#endif
725
[email protected]b172aee2012-04-10 17:05:26726const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55727 // Transient entries take precedence. They are used for interstitial pages
728 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23729 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08730 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21731 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30732 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23733 if (entry) {
[email protected]b5cca982011-05-26 04:42:08734 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23735 }
[email protected]7ade2732011-02-10 00:13:58736 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
737 render_manager_.pending_web_ui() : render_manager_.web_ui();
738 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54739 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32740 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54741 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35742 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22743 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54744 if (!title.empty())
745 return title;
746 }
747 }
748
749 // We use the title for the last committed entry rather than a pending
750 // navigation entry. For example, when the user types in a URL, we want to
751 // keep the old page's title until the new load has committed and we get a new
752 // title.
[email protected]96d185d2009-04-24 03:28:54753 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32754
755 // We make an exception for initial navigations, because we can have a
756 // committed entry for an initial navigation when doing a history navigation
757 // in a new tab, such as Ctrl+Back.
758 if (entry && controller_.IsInitialNavigation())
759 entry = controller_.GetVisibleEntry();
760
[email protected]45d0ef7f2011-01-05 13:46:23761 if (entry) {
[email protected]b5cca982011-05-26 04:42:08762 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23763 }
[email protected]987fc3a2011-05-26 14:18:09764
765 // |page_title_when_no_navigation_entry_| is finally used
766 // if no title cannot be retrieved.
767 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54768}
769
[email protected]b172aee2012-04-10 17:05:26770int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46771 return GetMaxPageIDForSiteInstance(GetSiteInstance());
772}
773
[email protected]b172aee2012-04-10 17:05:26774int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
775 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33776 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
777 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46778
[email protected]b6583592012-01-25 19:52:33779 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34780}
781
[email protected]b172aee2012-04-10 17:05:26782void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46783 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
784}
785
[email protected]b172aee2012-04-10 17:05:26786void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33787 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46788 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33789 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34790}
791
[email protected]ec6c05f2013-10-23 18:41:57792void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
793 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
794 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57795}
796
[email protected]b172aee2012-04-10 17:05:26797SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58798 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54799}
800
[email protected]b172aee2012-04-10 17:05:26801SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38802 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
803 render_manager_.pending_render_view_host() :
804 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58805 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38806}
807
[email protected]b172aee2012-04-10 17:05:26808bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31809 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49810}
811
[email protected]b172aee2012-04-10 17:05:26812bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31813 return waiting_for_response_;
814}
815
[email protected]b172aee2012-04-10 17:05:26816const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31817 return load_state_;
818}
819
[email protected]b172aee2012-04-10 17:05:26820const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31821 return load_state_host_;
822}
823
[email protected]b172aee2012-04-10 17:05:26824uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31825 return upload_size_;
826}
827
[email protected]b172aee2012-04-10 17:05:26828uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31829 return upload_position_;
830}
831
[email protected]1ae93fb2013-06-14 03:38:56832std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56833 std::set<GURL> sites;
[email protected]9b159a52013-10-03 17:24:55834 frame_tree_.ForEach(Bind(&CollectSites,
835 base::Unretained(GetBrowserContext()),
836 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56837 return sites;
838}
839
[email protected]b172aee2012-04-10 17:05:26840const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31841 return encoding_;
842}
843
[email protected]b172aee2012-04-10 17:05:26844bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31845 return displayed_insecure_content_;
846}
847
[email protected]54597982013-02-06 01:59:55848void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25849 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55850 ++capturer_count_;
851 DVLOG(1) << "There are now " << capturer_count_
852 << " capturing(s) of WebContentsImpl@" << this;
853}
854
855void WebContentsImpl::DecrementCapturerCount() {
856 --capturer_count_;
857 DVLOG(1) << "There are now " << capturer_count_
858 << " capturing(s) of WebContentsImpl@" << this;
859 DCHECK_LE(0, capturer_count_);
860
[email protected]5a652232013-02-12 06:15:25861 if (is_being_destroyed_)
862 return;
863
[email protected]1ac10dca2013-08-20 20:47:04864 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55865 DVLOG(1) << "Executing delayed WasHidden().";
866 WasHidden();
867 }
[email protected]be1f56ab2011-12-22 06:55:31868}
869
[email protected]f2bd40812013-07-20 04:30:44870int WebContentsImpl::GetCapturerCount() const {
871 return capturer_count_;
872}
873
[email protected]b172aee2012-04-10 17:05:26874bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31875 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
876 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
877 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49878}
879
[email protected]b172aee2012-04-10 17:05:26880void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
881 int error_code) {
[email protected]443b80e2010-12-14 00:42:23882 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34883 return;
884
[email protected]443b80e2010-12-14 00:42:23885 crashed_status_ = status;
886 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21887 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34888}
889
[email protected]b172aee2012-04-10 17:05:26890base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31891 return crashed_status_;
892}
893
[email protected]b172aee2012-04-10 17:05:26894bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31895 return is_being_destroyed_;
896}
897
[email protected]b172aee2012-04-10 17:05:26898void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34899 if (delegate_)
900 delegate_->NavigationStateChanged(this, changed_flags);
901}
902
[email protected]3e324142012-06-25 18:26:33903base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
904 return last_selected_time_;
905}
906
[email protected]9e2e4632012-07-27 16:38:41907void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54908 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04909 RenderWidgetHostViewPort* rwhv =
910 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16911 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29912 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43913#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16914 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43915#endif
916 }
[email protected]96d185d2009-04-24 03:28:54917
[email protected]5ac20162010-11-24 23:33:11918 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38919
[email protected]b9769d82012-02-10 00:23:59920 // The resize rect might have changed while this was inactive -- send the new
921 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58922 RenderViewHostImpl* rvh =
923 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59924 if (rvh) {
925 rvh->ResizeRectChanged(GetRootWindowResizerRect());
926 }
[email protected]96d185d2009-04-24 03:28:54927
[email protected]c0d9d5672013-10-09 07:38:03928 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
929
[email protected]54597982013-02-06 01:59:55930 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31931}
932
[email protected]b172aee2012-04-10 17:05:26933void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55934 // If there are entities capturing screenshots or video (e.g., mirroring),
935 // don't activate the "disable rendering" optimization.
936 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52937 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55938 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26939 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52940 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33941 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52942 // calls us).
[email protected]c30585c2012-02-16 15:02:04943 RenderWidgetHostViewPort* rwhv =
944 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16945 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29946 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54947 }
948
[email protected]c0d9d5672013-10-09 07:38:03949 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
950
[email protected]54597982013-02-06 01:59:55951 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37952}
953
[email protected]b172aee2012-04-10 17:05:26954bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31955 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27956 return WillNotifyDisconnection() &&
957 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58958 !static_cast<RenderViewHostImpl*>(
959 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31960}
961
[email protected]b172aee2012-04-10 17:05:26962void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27963 render_manager_.Stop();
[email protected]d16609c2013-08-23 06:01:40964 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:27965}
966
[email protected]b172aee2012-04-10 17:05:26967WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44968 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:45969 // We pass our own opener so that the cloned page can access it if it was
970 // before.
[email protected]54944cde2012-12-09 09:24:59971 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:45972 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:59973 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:19974 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:22975 FOR_EACH_OBSERVER(WebContentsObserver,
976 observers_,
977 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:27978 return tc;
979}
980
[email protected]14392a52012-05-02 20:28:44981void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:21982 const NotificationSource& source,
983 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:44984 switch (type) {
[email protected]8ff00d72012-10-23 19:12:21985 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
986 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:50987 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
988 i != pending_widget_views_.end(); ++i) {
989 if (host->GetView() == i->second) {
990 pending_widget_views_.erase(i);
991 break;
992 }
993 }
994 break;
995 }
[email protected]14392a52012-05-02 20:28:44996 default:
997 NOTREACHED();
998 }
999}
1000
[email protected]ec6c05f2013-10-23 18:41:571001WebContents* WebContentsImpl::GetWebContents() {
1002 return this;
1003}
1004
[email protected]54944cde2012-12-09 09:24:591005void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]d6fa88f2013-10-18 16:00:431006 // This is set before initializing the render_manager_ since render_manager_
1007 // init calls back into us via its delegate to ask if it should be hidden.
1008 should_normally_be_visible_ = !params.initially_hidden;
1009
[email protected]54944cde2012-12-09 09:24:591010 render_manager_.Init(
[email protected]227692c52013-05-31 22:43:041011 params.browser_context, params.site_instance, params.routing_id,
1012 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191013
[email protected]8ff00d72012-10-23 19:12:211014 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191015 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271016 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191017 CHECK(render_view_host_delegate_view_);
1018 } else {
[email protected]f8497342013-02-05 22:15:021019 WebContentsViewDelegate* delegate =
1020 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1021
[email protected]59383c782013-04-17 16:43:271022 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381023 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1024 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021025
[email protected]b5a40842012-11-28 15:26:111026 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381027 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431028 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111029 render_view_host_delegate_view_ = rv;
1030 view_.reset(rv);
1031 } else {
[email protected]f8497342013-02-05 22:15:021032 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111033 view_.reset(CreateWebContentsView(
1034 this, delegate, &render_view_host_delegate_view_));
1035 }
[email protected]d1198fd2012-08-13 22:50:191036 CHECK(render_view_host_delegate_view_);
1037 }
1038 CHECK(view_.get());
1039
[email protected]ed245db2012-12-18 08:00:451040 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591041 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191042
1043 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101044 if (opener_)
1045 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191046
1047 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211048 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1049 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441050#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191051 java_bridge_dispatcher_host_manager_.reset(
1052 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101053 date_time_chooser_.reset(new DateTimeChooserAndroid());
1054#endif
[email protected]d1198fd2012-08-13 22:50:191055}
1056
[email protected]7fff43e2013-05-21 20:21:101057void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1058 RemoveDestructionObserver(web_contents);
1059
[email protected]14392a52012-05-02 20:28:441060 // Clear the opener if it has been closed.
1061 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441062 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511063 return;
[email protected]14392a52012-05-02 20:28:441064 }
[email protected]ceee8cd2013-03-08 04:59:511065 // Clear a pending contents that has been closed before being shown.
1066 for (PendingContents::iterator iter = pending_contents_.begin();
1067 iter != pending_contents_.end();
1068 ++iter) {
1069 if (iter->second != web_contents)
1070 continue;
1071 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511072 return;
1073 }
1074 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441075}
1076
[email protected]7fff43e2013-05-21 20:21:101077void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1078 if (!ContainsKey(destruction_observers_, web_contents)) {
1079 destruction_observers_[web_contents] =
1080 new DestructionObserver(this, web_contents);
1081 }
1082}
1083
1084void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1085 DestructionObservers::iterator iter =
1086 destruction_observers_.find(web_contents);
1087 if (iter != destruction_observers_.end()) {
1088 delete destruction_observers_[web_contents];
1089 destruction_observers_.erase(iter);
1090 }
1091}
1092
[email protected]b172aee2012-04-10 17:05:261093void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311094 observers_.AddObserver(observer);
1095}
1096
[email protected]b172aee2012-04-10 17:05:261097void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311098 observers_.RemoveObserver(observer);
1099}
1100
[email protected]b172aee2012-04-10 17:05:261101void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341102 if (delegate_)
1103 delegate_->ActivateContents(this);
1104}
1105
[email protected]b172aee2012-04-10 17:05:261106void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121107 if (delegate_)
1108 delegate_->DeactivateContents(this);
1109}
1110
[email protected]b172aee2012-04-10 17:05:261111void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481112 if (delegate_)
1113 delegate_->LostCapture();
1114}
1115
[email protected]b24b68a2012-09-24 21:57:261116void WebContentsImpl::RenderWidgetDeleted(
1117 RenderWidgetHostImpl* render_widget_host) {
1118 if (is_being_destroyed_) {
1119 // |created_widgets_| might have been destroyed.
1120 return;
1121 }
1122
1123 std::set<RenderWidgetHostImpl*>::iterator iter =
1124 created_widgets_.find(render_widget_host);
1125 if (iter != created_widgets_.end())
1126 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541127
1128 if (render_widget_host &&
1129 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491130 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1131 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541132 FOR_EACH_OBSERVER(WebContentsObserver,
1133 observers_,
1134 DidDestroyFullscreenWidget(
1135 fullscreen_widget_routing_id_));
1136 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1137 }
[email protected]b24b68a2012-09-24 21:57:261138}
1139
[email protected]b172aee2012-04-10 17:05:261140bool WebContentsImpl::PreHandleKeyboardEvent(
1141 const NativeWebKeyboardEvent& event,
1142 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481143 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131144 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481145}
1146
[email protected]b172aee2012-04-10 17:05:261147void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061148 if (browser_plugin_embedder_ &&
1149 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1150 return;
1151 }
1152
[email protected]63954792011-07-11 04:17:481153 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131154 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481155}
1156
[email protected]fb3f066e2013-02-12 19:12:521157bool WebContentsImpl::PreHandleWheelEvent(
1158 const WebKit::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191159#if !defined(OS_MACOSX)
1160 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1161 // isn't done for two reasons:
1162 // -the OS already has a gesture to do this through pinch-zoom
1163 // -if a user starts an inertial scroll, let's go, and presses control
1164 // (i.e. control+tab) then the OS's buffered scroll events will come in
1165 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521166 if (delegate_ &&
1167 event.wheelTicksY &&
1168 (event.modifiers & WebKit::WebInputEvent::ControlKey)) {
1169 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1170 return true;
1171 }
[email protected]bccc4472013-04-18 16:37:191172#endif
[email protected]fb3f066e2013-02-12 19:12:521173
1174 return false;
1175}
1176
[email protected]c73a2282013-04-29 21:10:411177#if defined(OS_WIN) && defined(USE_AURA)
1178gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1179 return accessible_parent_;
1180}
1181#endif
1182
[email protected]b172aee2012-04-10 17:05:261183void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431184 if (delegate_)
1185 delegate_->HandleMouseDown();
1186}
1187
[email protected]b172aee2012-04-10 17:05:261188void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481189 if (delegate_)
1190 delegate_->HandleMouseUp();
1191}
1192
[email protected]590a634e2012-07-19 16:38:231193void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481194 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231195 delegate_->HandlePointerActivate();
1196}
1197
1198void WebContentsImpl::HandleGestureBegin() {
1199 if (delegate_)
1200 delegate_->HandleGestureBegin();
1201}
1202
1203void WebContentsImpl::HandleGestureEnd() {
1204 if (delegate_)
1205 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481206}
1207
[email protected]b172aee2012-04-10 17:05:261208void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491209 // This method is being called to enter or leave renderer-initiated fullscreen
1210 // mode. Either way, make sure any existing fullscreen widget is shut down
1211 // first.
1212 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1213 if (widget_view)
1214 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1215
[email protected]8a5e0ca2011-08-25 06:30:471216 if (delegate_)
1217 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1218}
1219
[email protected]b172aee2012-04-10 17:05:261220bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381221 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121222}
1223
[email protected]a9c81f02012-06-01 00:15:441224void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1225 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371226 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441227 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371228 } else {
1229 GotResponseToLockMouseRequest(false);
1230 }
1231}
1232
[email protected]b172aee2012-04-10 17:05:261233void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371234 if (delegate_)
1235 delegate_->LostMouseLock();
1236}
1237
[email protected]bafe6cd2012-05-23 23:09:501238void WebContentsImpl::CreateNewWindow(
1239 int route_id,
[email protected]227692c52013-05-31 22:43:041240 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131241 const ViewHostMsg_CreateWindow_Params& params,
1242 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501243 // We usually create the new window in the same BrowsingInstance (group of
1244 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551245 // if the opener is being suppressed (in a non-guest), we create a new
1246 // SiteInstance in its own BrowsingInstance.
1247 bool is_guest = GetRenderProcessHost()->IsGuest();
1248
[email protected]bafe6cd2012-05-23 23:09:501249 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551250 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571251 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501252 GetSiteInstance();
1253
[email protected]d1198fd2012-08-13 22:50:191254 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341255 //
1256 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301257 const std::string& partition_id =
1258 GetContentClient()->browser()->
1259 GetStoragePartitionIdForSite(GetBrowserContext(),
1260 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461261 StoragePartition* partition = BrowserContext::GetStoragePartition(
1262 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411263 DOMStorageContextWrapper* dom_storage_context =
1264 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191265 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1266 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1267 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371268
1269 if (delegate_ &&
1270 !delegate_->ShouldCreateWebContents(this,
1271 route_id,
1272 params.window_container_type,
1273 params.frame_name,
1274 params.target_url,
1275 partition_id,
1276 session_storage_namespace)) {
1277 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1278 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1279 main_frame_route_id);
1280 return;
1281 }
1282
1283 // Create the new web contents. This will automatically create the new
1284 // WebContentsView. In the future, we may want to create the view separately.
1285 WebContentsImpl* new_contents =
1286 new WebContentsImpl(GetBrowserContext(),
1287 params.opener_suppressed ? NULL : this);
1288
[email protected]d1198fd2012-08-13 22:50:191289 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301290 partition_id,
[email protected]d1198fd2012-08-13 22:50:191291 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461292 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591293 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041294 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551295 if (!is_guest) {
1296 create_params.context = view_->GetNativeView();
1297 create_params.initial_size = view_->GetContainerSize();
1298 } else {
1299 // This makes |new_contents| act as a guest.
1300 // For more info, see comment above class BrowserPluginGuest.
1301 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1302 WebContentsImpl* new_contents_impl =
1303 static_cast<WebContentsImpl*>(new_contents);
[email protected]738f57a2013-06-29 21:06:541304 BrowserPluginGuest::CreateWithOpener(instance_id, new_contents_impl,
1305 GetBrowserPluginGuest(), !!new_contents_impl->opener());
[email protected]c4538072013-03-18 02:17:551306 }
[email protected]1ac10dca2013-08-20 20:47:041307 if (params.disposition == NEW_BACKGROUND_TAB)
1308 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591309 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191310
[email protected]c4538072013-03-18 02:17:551311 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341312 // will be shown immediately).
1313 if (!params.opener_suppressed) {
1314 if (!is_guest) {
1315 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501316
[email protected]d70bea92013-04-05 04:23:341317 // TODO(brettw): It seems bogus that we have to call this function on the
1318 // newly created object and give it one of its own member variables.
1319 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1320 }
[email protected]bafe6cd2012-05-23 23:09:501321 // Save the created window associated with the route so we can show it
1322 // later.
1323 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1324 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101325 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501326 }
1327
1328 if (delegate_) {
1329 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131330 this, params.opener_frame_id, params.frame_name,
1331 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501332 }
1333
1334 if (params.opener_suppressed) {
1335 // When the opener is suppressed, the original renderer cannot access the
1336 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001337 bool was_blocked = false;
1338 if (delegate_) {
1339 gfx::Rect initial_pos;
1340 delegate_->AddNewContents(
1341 this, new_contents, params.disposition, initial_pos,
1342 params.user_gesture, &was_blocked);
1343 }
1344 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211345 OpenURLParams open_params(params.target_url,
1346 Referrer(),
1347 CURRENT_TAB,
1348 PAGE_TRANSITION_LINK,
1349 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301350 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001351 new_contents->OpenURL(open_params);
1352 }
[email protected]bafe6cd2012-05-23 23:09:501353 }
1354}
1355
1356void WebContentsImpl::CreateNewWidget(int route_id,
1357 WebKit::WebPopupType popup_type) {
1358 CreateNewWidget(route_id, false, popup_type);
1359}
1360
1361void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1362 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1363}
1364
1365void WebContentsImpl::CreateNewWidget(int route_id,
1366 bool is_fullscreen,
1367 WebKit::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211368 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501369 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041370 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261371 created_widgets_.insert(widget_host);
1372
[email protected]83918ec2013-01-10 15:37:191373 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1374 view_->CreateViewForPopupWidget(widget_host));
1375 if (!widget_view)
1376 return;
[email protected]bafe6cd2012-05-23 23:09:501377 if (!is_fullscreen) {
1378 // Popups should not get activated.
1379 widget_view->SetPopupType(popup_type);
1380 }
1381 // Save the created widget associated with the route so we can show it later.
1382 pending_widget_views_[route_id] = widget_view;
1383
1384#if defined(OS_MACOSX)
1385 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1386 // to allow it to survive the trip without being hosted.
1387 base::mac::NSObjectRetain(widget_view->GetNativeView());
1388#endif
1389}
1390
1391void WebContentsImpl::ShowCreatedWindow(int route_id,
1392 WindowOpenDisposition disposition,
1393 const gfx::Rect& initial_pos,
1394 bool user_gesture) {
1395 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001396 if (contents) {
1397 WebContentsDelegate* delegate = GetDelegate();
1398 if (delegate) {
1399 delegate->AddNewContents(
1400 this, contents, disposition, initial_pos, user_gesture, NULL);
1401 }
1402 }
[email protected]bafe6cd2012-05-23 23:09:501403}
1404
1405void WebContentsImpl::ShowCreatedWidget(int route_id,
1406 const gfx::Rect& initial_pos) {
1407 ShowCreatedWidget(route_id, false, initial_pos);
1408}
1409
1410void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1411 ShowCreatedWidget(route_id, true, gfx::Rect());
1412}
1413
1414void WebContentsImpl::ShowCreatedWidget(int route_id,
1415 bool is_fullscreen,
1416 const gfx::Rect& initial_pos) {
1417 if (delegate_)
1418 delegate_->RenderWidgetShowing();
1419
1420 RenderWidgetHostViewPort* widget_host_view =
1421 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1422 if (!widget_host_view)
1423 return;
[email protected]4aebbca2013-09-17 22:26:491424 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311425 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1426 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491427 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1428 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1429 delegate_->ToggleFullscreenModeForTab(this, true);
1430 } else {
1431 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491432 }
[email protected]4aebbca2013-09-17 22:26:491433 FOR_EACH_OBSERVER(WebContentsObserver,
1434 observers_,
1435 DidShowFullscreenWidget(route_id));
1436 if (!widget_host_view->HasFocus())
1437 widget_host_view->Focus();
1438 } else {
[email protected]f8497342013-02-05 22:15:021439 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491440 }
[email protected]89054502012-06-03 10:29:241441
1442 RenderWidgetHostImpl* render_widget_host_impl =
1443 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1444 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311445 // Only allow privileged mouse lock for fullscreen render widget, which is
1446 // used to implement Pepper Flash fullscreen.
1447 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501448
1449#if defined(OS_MACOSX)
1450 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1451 // properly embedded (or purposefully ignored) we can release the retain we
1452 // took in CreateNewWidget().
1453 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1454#endif
1455}
1456
1457WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1458 PendingContents::iterator iter = pending_contents_.find(route_id);
1459
1460 // Certain systems can block the creation of new windows. If we didn't succeed
1461 // in creating one, just return NULL.
1462 if (iter == pending_contents_.end()) {
1463 return NULL;
1464 }
1465
1466 WebContentsImpl* new_contents = iter->second;
1467 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101468 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501469
[email protected]d70bea92013-04-05 04:23:341470 // Don't initialize the guest WebContents immediately.
1471 if (new_contents->GetRenderProcessHost()->IsGuest())
1472 return new_contents;
1473
[email protected]bafe6cd2012-05-23 23:09:501474 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1475 !new_contents->GetRenderViewHost()->GetView())
1476 return NULL;
1477
1478 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1479 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1480 return new_contents;
1481}
1482
1483RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1484 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1485 if (iter == pending_widget_views_.end()) {
1486 DCHECK(false);
1487 return NULL;
1488 }
1489
1490 RenderWidgetHostView* widget_host_view = iter->second;
1491 pending_widget_views_.erase(route_id);
1492
1493 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1494 if (!widget_host->GetProcess()->HasConnection()) {
1495 // The view has gone away or the renderer crashed. Nothing to do.
1496 return NULL;
1497 }
1498
1499 return widget_host_view;
1500}
1501
[email protected]f56c7872013-06-18 12:31:571502void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501503 // Allow WebContentsDelegates to handle the context menu operation first.
1504 if (delegate_ && delegate_->HandleContextMenu(params))
1505 return;
1506
[email protected]f56c7872013-06-18 12:31:571507 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501508}
1509
[email protected]f13b4202012-06-12 23:53:231510void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091511 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211512 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231513 if (delegate_)
1514 delegate_->RequestMediaAccessPermission(this, request, callback);
1515 else
[email protected]b5f76742013-04-29 15:05:591516 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231517}
1518
[email protected]cc9200432013-07-23 23:02:401519SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1520 SiteInstance* instance) {
1521 return controller_.GetSessionStorageNamespace(instance);
1522}
1523
[email protected]9b159a52013-10-03 17:24:551524FrameTree* WebContentsImpl::GetFrameTree() {
1525 return &frame_tree_;
1526}
1527
[email protected]32deec62013-05-15 23:55:041528void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1529 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441530 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041531}
1532
[email protected]b172aee2012-04-10 17:05:261533void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231534 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331535 if (delegate_)
1536 delegate_->UpdatePreferredSize(this, pref_size);
1537}
1538
[email protected]b172aee2012-04-10 17:05:261539void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341540 if (delegate_)
1541 delegate_->ResizeDueToAutoResize(this, new_size);
1542}
1543
[email protected]b172aee2012-04-10 17:05:261544WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201545 if (!delegate_)
1546 return NULL;
[email protected]00c37fc2011-08-02 00:22:501547
[email protected]e5d549d2011-12-28 01:29:201548 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201549 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341550}
1551
[email protected]6b618e62012-08-16 12:59:181552bool WebContentsImpl::Send(IPC::Message* message) {
1553 if (!GetRenderViewHost()) {
1554 delete message;
1555 return false;
1556 }
1557
1558 return GetRenderViewHost()->Send(message);
1559}
1560
[email protected]b172aee2012-04-10 17:05:261561bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501562 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251563 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231564 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251565 reload_type);
[email protected]876bc832010-09-07 16:29:541566}
[email protected]96d185d2009-04-24 03:28:541567
[email protected]ba45bfd2012-05-22 21:51:441568void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211569 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441570 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1571 RenderViewForInterstitialPageCreated(render_view_host));
1572}
1573
[email protected]20ca0382013-02-28 19:50:071574void WebContentsImpl::AttachInterstitialPage(
1575 InterstitialPageImpl* interstitial_page) {
1576 DCHECK(interstitial_page);
1577 render_manager_.set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291578
1579 // Cancel any visible dialogs so that they don't interfere with the
1580 // interstitial.
1581 if (dialog_manager_)
1582 dialog_manager_->CancelActiveAndPendingDialogs(this);
1583
[email protected]20ca0382013-02-28 19:50:071584 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1585 DidAttachInterstitialPage());
1586}
1587
1588void WebContentsImpl::DetachInterstitialPage() {
1589 if (GetInterstitialPage())
1590 render_manager_.remove_interstitial_page();
1591 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1592 DidDetachInterstitialPage());
1593}
1594
[email protected]b172aee2012-04-10 17:05:261595bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231596 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501597 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031598 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1599
[email protected]19e81142011-10-03 16:19:401600 // The renderer will reject IPC messages with URLs longer than
1601 // this limit, so don't attempt to navigate with a longer URL.
[email protected]3adab1c2013-09-09 21:23:431602 if (entry.GetURL().spec().size() > kMaxURLChars) {
1603 LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars
1604 << " characters.";
[email protected]19e81142011-10-03 16:19:401605 return false;
[email protected]3adab1c2013-09-09 21:23:431606 }
[email protected]19e81142011-10-03 16:19:401607
[email protected]9f76c1e2012-03-05 15:15:581608 RenderViewHostImpl* dest_render_view_host =
1609 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401610 if (!dest_render_view_host)
1611 return false; // Unable to create the desired render view host.
1612
[email protected]80a8fad2011-01-29 04:02:381613 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071614 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581615 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271616 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501617 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031618 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1619 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211620 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231621 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271622 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211623 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231624 CHECK(0);
1625 }
[email protected]54ec6472010-04-09 19:39:581626
[email protected]7bb761892012-07-20 09:32:471627 // Notify observers that we will navigate in this RV.
1628 FOR_EACH_OBSERVER(WebContentsObserver,
1629 observers_,
1630 AboutToNavigateRenderView(dest_render_view_host));
1631
[email protected]96d185d2009-04-24 03:28:541632 // Used for page load time metrics.
1633 current_load_start_ = base::TimeTicks::Now();
1634
1635 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341636 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271637 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471638 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341639 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541640
[email protected]36fc0392011-12-25 03:59:511641 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541642 // HACK!! This code suppresses javascript: URLs from being added to
1643 // session history, which is what we want to do for javascript: URLs that
1644 // do not generate content. What we really need is a message from the
1645 // renderer telling us that a new page was not created. The same message
1646 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351647 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541648 return false;
1649 }
1650
[email protected]3c9e1872010-11-18 16:17:491651 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251652 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041653 observers_,
[email protected]36fc0392011-12-25 03:59:511654 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541655
[email protected]09b29342011-06-24 19:18:481656 if (delegate_)
1657 delegate_->DidNavigateToPendingEntry(this);
1658
[email protected]d5f942ba2008-09-26 19:30:341659 return true;
1660}
1661
[email protected]b172aee2012-04-10 17:05:261662void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331663 const SiteInstance* site_instance,
1664 int history_length,
1665 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411666 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1667 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191668 if (render_manager_.pending_render_view_host()) {
1669 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141670 return;
[email protected]9e1ad4b2011-08-14 16:49:191671 }
[email protected]9f76c1e2012-03-05 15:15:581672 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191673 if (!rvh) {
1674 NOTREACHED();
1675 return;
1676 }
[email protected]9f76c1e2012-03-05 15:15:581677 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191678 NOTREACHED();
1679 return;
1680 }
[email protected]6b618e62012-08-16 12:59:181681 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1682 history_length,
1683 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141684}
1685
[email protected]b172aee2012-04-10 17:05:261686void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271687 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541688 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1689 return;
1690 }
[email protected]9f76c1e2012-03-05 15:15:581691 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541692}
1693
[email protected]b172aee2012-04-10 17:05:261694bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271695 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541696}
1697
[email protected]b172aee2012-04-10 17:05:261698InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271699 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221700}
1701
[email protected]b172aee2012-04-10 17:05:261702bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161703 // WebKit creates Document object when MIME type is application/xhtml+xml,
1704 // so we also support this MIME type.
1705 return contents_mime_type_ == "text/html" ||
1706 contents_mime_type_ == "text/xml" ||
1707 contents_mime_type_ == "application/xhtml+xml" ||
1708 contents_mime_type_ == "text/plain" ||
1709 contents_mime_type_ == "text/css" ||
1710 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1711}
1712
[email protected]b172aee2012-04-10 17:05:261713void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591714 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161715 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551716 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011717 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141718 return;
[email protected]c7dd2f62011-07-18 15:57:591719 }
1720
1721 Stop();
1722
1723 // Create the save package and possibly prompt the user for the name to save
1724 // the page as. The user prompt is an asynchronous operation that runs on
1725 // another thread.
1726 save_package_ = new SavePackage(this);
1727 save_package_->GetSaveInfo();
1728}
1729
1730// Used in automated testing to bypass prompting the user for file names.
1731// Instead, the names and paths are hard coded rather than running them through
1732// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341733bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1734 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211735 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591736 // Stop the page from navigating.
1737 Stop();
1738
1739 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211740 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591741}
1742
[email protected]3c71576ce2013-07-23 02:00:011743void WebContentsImpl::SaveFrame(const GURL& url,
1744 const Referrer& referrer) {
1745 if (!GetURL().is_valid())
1746 return;
1747 bool is_main_frame = (url == GetURL());
1748
1749 DownloadManager* dlm =
1750 BrowserContext::GetDownloadManager(GetBrowserContext());
1751 if (!dlm)
1752 return;
1753 int64 post_id = -1;
1754 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271755 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011756 if (entry)
1757 post_id = entry->GetPostID();
1758 }
1759 scoped_ptr<DownloadUrlParameters> params(
1760 DownloadUrlParameters::FromWebContents(this, url));
1761 params->set_referrer(referrer);
1762 params->set_post_id(post_id);
1763 params->set_prefer_cache(true);
1764 if (post_id >= 0)
1765 params->set_method("POST");
1766 params->set_prompt(true);
1767 dlm->DownloadUrl(params.Pass());
1768}
1769
[email protected]b172aee2012-04-10 17:05:261770void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341771 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481772 const base::Callback<void(int64)>& callback) {
1773 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121774}
1775
[email protected]6286a372013-10-09 04:03:271776// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261777bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271778 NavigationEntryImpl* visible_entry =
1779 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1780 return (visible_entry != NULL &&
1781 visible_entry->site_instance() == GetSiteInstance() &&
1782 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321783}
1784
[email protected]b172aee2012-04-10 17:05:261785const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271786 return contents_mime_type_;
1787}
1788
[email protected]b172aee2012-04-10 17:05:261789bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271790 return notify_disconnection_;
1791}
1792
[email protected]b172aee2012-04-10 17:05:261793void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311794 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181795 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161796}
1797
[email protected]b172aee2012-04-10 17:05:261798void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311799 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181800 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161801}
1802
[email protected]8ff00d72012-10-23 19:12:211803RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271804 return &renderer_preferences_;
1805}
1806
[email protected]e35ccd52012-05-23 16:22:471807void WebContentsImpl::Close() {
1808 Close(GetRenderViewHost());
1809}
1810
[email protected]cf200a562013-05-03 16:24:291811void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
1812 int screen_x, int screen_y, WebKit::WebDragOperation operation) {
1813 if (browser_plugin_embedder_.get())
1814 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1815 screen_x, screen_y, operation);
1816 if (GetRenderViewHost())
1817 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1818 screen_x, screen_y, operation);
1819}
1820
1821void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1822 int screen_x, int screen_y) {
1823 if (browser_plugin_embedder_.get())
1824 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1825 screen_x, screen_y);
1826 if (GetRenderViewHost())
1827 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1828 screen_x, screen_y);
1829}
1830
[email protected]b172aee2012-04-10 17:05:261831void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521832 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581833 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511834 if (delegate_)
1835 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291836 if (browser_plugin_embedder_.get())
1837 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341838}
1839
[email protected]e35ccd52012-05-23 16:22:471840void WebContentsImpl::UserGestureDone() {
1841 OnUserGesture();
1842}
1843
[email protected]b172aee2012-04-10 17:05:261844void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271845 closed_by_user_gesture_ = value;
1846}
1847
[email protected]b172aee2012-04-10 17:05:261848bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271849 return closed_by_user_gesture_;
1850}
1851
[email protected]b172aee2012-04-10 17:05:261852double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051853 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561854 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251855 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171856 return 0;
[email protected]b75b8292010-10-01 07:28:251857
1858 double zoom_level;
1859 if (temporary_zoom_settings_) {
1860 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581861 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251862 } else {
[email protected]2ae88d12011-10-14 09:11:191863 GURL url;
[email protected]6286a372013-10-09 04:03:271864 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191865 // Since zoom map is updated using rewritten URL, use rewritten URL
1866 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271867 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021868 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1869 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251870 }
[email protected]d0b8d092010-10-25 04:05:171871 return zoom_level;
1872}
[email protected]b75b8292010-10-01 07:28:251873
[email protected]b172aee2012-04-10 17:05:261874int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591875 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171876 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011877 // Calculate the zoom percent from the factor. Round up to the nearest whole
1878 // number.
[email protected]b75b8292010-10-01 07:28:251879 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491880 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251881 *enable_decrement = percent > minimum_zoom_percent_;
1882 *enable_increment = percent < maximum_zoom_percent_;
1883 return percent;
1884}
1885
[email protected]b172aee2012-04-10 17:05:261886void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501887 if (!delegate_)
1888 return;
1889
[email protected]6286a372013-10-09 04:03:271890 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1891 if (!entry)
[email protected]1788e772010-12-15 16:40:501892 return;
1893
[email protected]6286a372013-10-09 04:03:271894 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121895}
1896
[email protected]b172aee2012-04-10 17:05:261897void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041898 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271899 if (!delegate_)
1900 return;
1901
[email protected]691aa2f2013-05-28 22:52:041902 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271903}
1904
[email protected]b172aee2012-04-10 17:05:261905int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271906 return minimum_zoom_percent_;
1907}
1908
[email protected]b172aee2012-04-10 17:05:261909int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271910 return maximum_zoom_percent_;
1911}
1912
[email protected]b172aee2012-04-10 17:05:261913gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231914 return preferred_size_;
1915}
1916
[email protected]b172aee2012-04-10 17:05:261917bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271918 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581919 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271920}
1921
[email protected]b172aee2012-04-10 17:05:261922bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441923 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501924}
1925
[email protected]cb805452013-05-22 15:16:211926void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181927 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211928 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201929}
1930
[email protected]cb805452013-05-22 15:16:211931void WebContentsImpl::DidEndColorChooser() {
1932 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1933 color_chooser_identifier_));
1934 color_chooser_.reset();
1935 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201936}
1937
[email protected]41225fe2013-03-29 05:32:021938int WebContentsImpl::DownloadImage(const GURL& url,
1939 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301940 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021941 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391942 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301943 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021944 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391945 return id;
1946}
1947
[email protected]b172aee2012-04-10 17:05:261948bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:271949 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:201950 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:331951 return true;
1952 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:271953}
1954
[email protected]b172aee2012-04-10 17:05:261955void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271956 if (delegate_)
1957 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211958}
1959
[email protected]54047eb52012-05-08 21:45:571960void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:211961 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:571962 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131963 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571964 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:571965 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:211966 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]081dc522013-05-15 04:59:201967 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:181968 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:211969 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:571970 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:081971 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:181972
[email protected]442385d2013-08-09 02:38:411973 if (is_main_frame) {
[email protected]d974a0a2013-01-10 01:43:571974 DidChangeLoadProgress(0);
1975
[email protected]442385d2013-08-09 02:38:411976 // If there is no browser-initiated pending entry for this navigation and it
1977 // is not for the error URL, create a pending entry using the current
1978 // SiteInstance, and ensure the address bar updates accordingly. We don't
1979 // know the referrer or extra headers at this point, but the referrer will
1980 // be set properly upon commit.
[email protected]97d8f0d2013-10-29 16:49:211981 NavigationEntryImpl* pending_entry =
1982 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
[email protected]442385d2013-08-09 02:38:411983 bool has_browser_initiated_pending_entry = pending_entry &&
[email protected]97d8f0d2013-10-29 16:49:211984 !pending_entry->is_renderer_initiated();
[email protected]442385d2013-08-09 02:38:411985 if (!has_browser_initiated_pending_entry && !is_error_page) {
1986 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
1987 controller_.CreateNavigationEntry(validated_url,
1988 content::Referrer(),
1989 content::PAGE_TRANSITION_LINK,
1990 true /* is_renderer_initiated */,
1991 std::string(),
1992 GetBrowserContext()));
1993 entry->set_site_instance(
1994 static_cast<SiteInstanceImpl*>(GetSiteInstance()));
[email protected]3ed682bf2013-10-17 20:56:561995 // TODO(creis): If there's a pending entry already, find a safe way to
1996 // update it instead of replacing it and copying over things like this.
[email protected]97d8f0d2013-10-29 16:49:211997 if (pending_entry) {
1998 entry->set_transferred_global_request_id(
1999 pending_entry->transferred_global_request_id());
2000 entry->set_should_replace_entry(pending_entry->should_replace_entry());
[email protected]f8872902013-10-30 03:18:572001 entry->set_redirect_chain(pending_entry->redirect_chain());
[email protected]3ed682bf2013-10-17 20:56:562002 }
[email protected]442385d2013-08-09 02:38:412003 controller_.SetPendingEntry(entry);
2004 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
2005 }
[email protected]59167c22013-06-03 18:07:322006 }
2007
[email protected]0d60f0192011-04-14 12:40:102008 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252009 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132010 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2011 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322012 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542013
2014 if (is_main_frame) {
2015 // Notify observers about the provisional change in the main frame URL.
2016 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2017 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542018 render_view_host));
2019 }
2020}
2021
2022void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212023 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542024 int32 page_id,
[email protected]400992b2012-06-14 00:03:542025 const GURL& source_url,
2026 const GURL& target_url) {
2027 // TODO(creis): Remove this method and have the pre-rendering code listen to
[email protected]b0f724c2013-09-05 04:21:132028 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
2029 // See http://crbug.com/78512.
[email protected]400992b2012-06-14 00:03:542030 GURL validated_source_url(source_url);
2031 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212032 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542033 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082034 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2035 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542036 NavigationEntry* entry;
2037 if (page_id == -1) {
2038 entry = controller_.GetPendingEntry();
2039 } else {
2040 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2041 page_id);
2042 }
2043 if (!entry || entry->GetURL() != validated_source_url)
2044 return;
2045
2046 // Notify observers about the provisional change in the main frame URL.
2047 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2048 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542049 render_view_host));
[email protected]724159a2010-12-30 01:11:182050}
2051
[email protected]54047eb52012-05-08 21:45:572052void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212053 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582054 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2055 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2056 << ", error_code: " << params.error_code
2057 << ", error_description: " << params.error_description
2058 << ", is_main_frame: " << params.is_main_frame
2059 << ", showing_repost_interstitial: " <<
2060 params.showing_repost_interstitial
2061 << ", frame_id: " << params.frame_id;
2062 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212063 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572064 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082065 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182066
[email protected]d7b175e2011-10-11 15:31:582067 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182068 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2069 // This means that the interstitial won't be torn down properly, which is
2070 // bad. But if we have an interstitial, go back to another tab type, and
2071 // then load the same interstitial again, we could end up getting the first
2072 // interstitial's "failed" message (as a result of the cancel) when we're on
2073 // the second one.
2074 //
2075 // We can't tell this apart, so we think we're tearing down the current page
2076 // which will cause a crash later one. There is also some code in
2077 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2078 // out because of this problem.
2079 //
2080 // http://code.google.com/p/chromium/issues/detail?id=2855
2081 // Because this will not tear down the interstitial properly, if "back" is
2082 // back to another tab type, the interstitial will still be somewhat alive
2083 // in the previous tab type. If you navigate somewhere that activates the
2084 // tab with the interstitial again, you'll see a flash before the new load
2085 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272086 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182087 LOG(WARNING) << "Discarding message during interstitial.";
2088 return;
2089 }
2090
[email protected]54047eb52012-05-08 21:45:572091 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182092 }
2093
[email protected]b12eb222013-09-10 00:11:482094 // Do not usually clear the pending entry if one exists, so that the user's
2095 // typed URL is not lost when a navigation fails or is aborted. However, in
2096 // cases that we don't show the pending entry (e.g., renderer-initiated
2097 // navigations in an existing tab), we don't keep it around. That prevents
2098 // spoofs on in-page navigations that don't go through
2099 // DidStartProvisionalLoadForFrame.
2100 // In general, we allow the view to clear the pending entry and typed URL if
2101 // the user requests (e.g., hitting Escape with focus in the address bar).
2102 // Note: don't touch the transient entry, since an interstitial may exist.
2103 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry())
2104 controller_.DiscardPendingEntry();
2105
[email protected]d8c660432011-12-22 20:51:252106 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582107 observers_,
2108 DidFailProvisionalLoad(params.frame_id,
[email protected]2f673064c2013-10-22 04:01:442109 params.frame_unique_name,
[email protected]d7b175e2011-10-11 15:31:582110 params.is_main_frame,
2111 validated_url,
2112 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462113 params.error_description,
2114 render_view_host));
[email protected]724159a2010-12-30 01:11:182115}
2116
[email protected]b172aee2012-04-10 17:05:262117void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182118 const GURL& url,
[email protected]70435962011-08-02 20:13:282119 const std::string& security_info,
2120 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182121 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282122 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192123 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182124 cache.Increment();
2125
2126 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082127 int cert_id = 0;
2128 net::CertStatus cert_status = 0;
2129 int security_bits = -1;
2130 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212131 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2132 &security_bits, &connection_status);
2133 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002134 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2135 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182136
[email protected]b0f724c2013-09-05 04:21:132137 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2138
2139 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2140 DidLoadResourceFromMemoryCache(details));
2141
[email protected]8bfc8272013-09-09 20:10:532142 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2143 scoped_refptr<net::URLRequestContextGetter> request_context(
2144 resource_type == ResourceType::MEDIA ?
2145 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2146 GetRenderProcessHost()->GetID()) :
2147 GetBrowserContext()->GetRequestContextForRenderProcess(
2148 GetRenderProcessHost()->GetID()));
2149 BrowserThread::PostTask(
2150 BrowserThread::IO,
2151 FROM_HERE,
2152 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2153 }
[email protected]724159a2010-12-30 01:11:182154}
2155
[email protected]b172aee2012-04-10 17:05:262156void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212157 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182158 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192159 SSLManager::NotifySSLInternalStateChanged(
2160 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182161}
2162
[email protected]b172aee2012-04-10 17:05:262163void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022164 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232165 LOG(INFO) << security_origin << " ran insecure content from "
2166 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212167 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412168 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212169 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182170 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412171 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192172 SSLManager::NotifySSLInternalStateChanged(
2173 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182174}
2175
[email protected]b172aee2012-04-10 17:05:262176void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]d8c660432011-12-22 20:51:252177 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472178 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182179}
2180
[email protected]b172aee2012-04-10 17:05:262181void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312182 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062183 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312184 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062185 GURL validated_url(url);
2186 RenderProcessHost* render_process_host = message_source_->GetProcess();
2187 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252188 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472189 DidFinishLoad(frame_id, validated_url, is_main_frame,
2190 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312191}
2192
[email protected]b172aee2012-04-10 17:05:262193void WebContentsImpl::OnDidFailLoadWithError(
2194 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062195 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262196 bool is_main_frame,
2197 int error_code,
2198 const string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062199 GURL validated_url(url);
2200 RenderProcessHost* render_process_host = message_source_->GetProcess();
2201 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252202 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312203 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472204 error_code, error_description,
2205 message_source_));
[email protected]724159a2010-12-30 01:11:182206}
2207
[email protected]b172aee2012-04-10 17:05:262208void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262209 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232210 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252211 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262212 if (!entry)
2213 return;
2214 // Note that we don't call NavigationController::GotToOffset() as we don't
2215 // want to create a pending navigation entry (it might end up lingering
2216 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252217 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212218 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512219 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212220 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472221 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572222
2223 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2224 // it in now that we know. This allows us to find the entry when it commits.
2225 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232226 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332227 entry->set_site_instance(
2228 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572229 }
[email protected]216813952011-05-19 22:21:262230 }
2231}
2232
[email protected]b172aee2012-04-10 17:05:262233void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2234 int maximum_percent,
2235 bool remember) {
[email protected]216813952011-05-19 22:21:262236 minimum_zoom_percent_ = minimum_percent;
2237 maximum_zoom_percent_ = maximum_percent;
2238 temporary_zoom_settings_ = !remember;
2239}
2240
[email protected]b172aee2012-04-10 17:05:262241void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342242 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432243 if (!delegate_)
2244 return;
2245
[email protected]b9535422012-02-09 01:47:592246 ChildProcessSecurityPolicyImpl* policy =
2247 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222248 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592249 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212250}
2251
[email protected]b172aee2012-04-10 17:05:262252void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432253 if (delegate_)
2254 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202255}
2256
[email protected]b172aee2012-04-10 17:05:262257void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2258 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362259 const string16& title,
2260 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432261 if (!delegate_)
2262 return;
2263
[email protected]b9535422012-02-09 01:47:592264 ChildProcessSecurityPolicyImpl* policy =
2265 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322266 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592267 return;
[email protected]8f810632013-06-06 22:33:322268
[email protected]3a3b75a2012-06-01 08:38:362269 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202270}
2271
[email protected]b172aee2012-04-10 17:05:262272void WebContentsImpl::OnFindReply(int request_id,
2273 int number_of_matches,
2274 const gfx::Rect& selection_rect,
2275 int active_match_ordinal,
2276 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432277 if (delegate_) {
2278 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2279 active_match_ordinal, final_update);
2280 }
[email protected]b888919c2011-09-02 00:32:162281}
2282
[email protected]59363fc92012-09-05 03:46:312283#if defined(OS_ANDROID)
2284void WebContentsImpl::OnFindMatchRectsReply(
2285 int version,
2286 const std::vector<gfx::RectF>& rects,
2287 const gfx::RectF& active_rect) {
2288 if (delegate_)
2289 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2290}
[email protected]583418cc2013-01-17 14:01:102291
[email protected]1ff427972013-02-07 21:14:072292void WebContentsImpl::OnOpenDateTimeDialog(
2293 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092294 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2295 GetRenderViewHost(),
2296 value.dialog_type,
2297 value.year,
2298 value.month,
2299 value.day,
2300 value.hour,
2301 value.minute,
2302 value.second,
2303 value.milli,
2304 value.week,
2305 value.minimum,
2306 value.maximum,
2307 value.step);
[email protected]583418cc2013-01-17 14:01:102308}
2309
[email protected]a794f3a2013-10-30 17:00:322310void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2311 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
2312 message_source_, reply_msg);
2313}
2314
[email protected]59363fc92012-09-05 03:46:312315#endif
2316
[email protected]2dec8ec2013-02-07 19:20:342317void WebContentsImpl::OnCrashedPlugin(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422318 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442319 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422320 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452321}
2322
[email protected]b172aee2012-04-10 17:05:262323void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2324 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102325 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252326 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102327 AppCacheAccessed(manifest_url, blocked_by_policy));
2328}
2329
[email protected]b172aee2012-04-10 17:05:262330void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322331 SkColor color) {
[email protected]cb805452013-05-22 15:16:212332 ColorChooser* new_color_chooser = delegate_->OpenColorChooser(this, color);
2333 if (color_chooser_ == new_color_chooser)
2334 return;
2335 color_chooser_.reset(new_color_chooser);
2336 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202337}
2338
[email protected]b172aee2012-04-10 17:05:262339void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202340 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212341 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202342 color_chooser_->End();
2343}
2344
[email protected]b172aee2012-04-10 17:05:262345void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322346 SkColor color) {
[email protected]da8543762012-03-20 08:52:202347 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212348 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202349 color_chooser_->SetSelectedColor(color);
2350}
2351
[email protected]9f2a9d72012-04-16 16:02:222352void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
[email protected]2dec8ec2013-02-07 19:20:342353 const base::FilePath& path,
[email protected]9f2a9d72012-04-16 16:02:222354 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552355 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2356
[email protected]3fc07c52012-04-20 00:27:442357 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2358 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292359}
2360
[email protected]d0759f492012-04-19 22:50:502361// This exists for render views that don't have a WebUI, but do have WebUI
2362// bindings enabled.
2363void WebContentsImpl::OnWebUISend(const GURL& source_url,
2364 const std::string& name,
2365 const base::ListValue& args) {
2366 if (delegate_)
2367 delegate_->WebUISend(this, source_url, name, args);
2368}
2369
[email protected]d8415ad92012-08-23 14:40:502370void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442371 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502372 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342373 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162374 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442375 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162376 return;
[email protected]d8415ad92012-08-23 14:40:502377 }
2378
[email protected]8c8fc292012-11-23 18:57:162379 if (!delegate_->RequestPpapiBrokerPermission(
2380 this, url, plugin_path,
2381 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442382 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162383 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442384 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162385 }
[email protected]d8415ad92012-08-23 14:40:502386}
2387
[email protected]ea0309c2013-08-06 19:35:442388void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502389 bool result) {
[email protected]ea0309c2013-08-06 19:35:442390 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502391}
2392
[email protected]c4538072013-03-18 02:17:552393void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372394 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082395 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552396 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392397 // For more info, see comment above classes BrowserPluginEmbedder and
2398 // BrowserPluginGuest.
2399 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142400 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082401 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372402}
2403
[email protected]41225fe2013-03-29 05:32:022404void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392405 int id,
[email protected]749fadd2013-05-15 08:37:482406 int http_status_code,
[email protected]795c28972012-12-06 06:13:392407 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302408 const std::vector<SkBitmap>& bitmaps,
2409 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022410 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2411 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392412 // Currently WebContents notifies us of ANY downloads so that it is
2413 // possible to get here.
2414 return;
2415 }
2416 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302417 iter->second.Run(
2418 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392419 }
[email protected]41225fe2013-03-29 05:32:022420 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392421}
2422
2423void WebContentsImpl::OnUpdateFaviconURL(
2424 int32 page_id,
2425 const std::vector<FaviconURL>& candidates) {
2426 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2427 DidUpdateFaviconURL(page_id, candidates));
2428}
2429
[email protected]d9030b82013-07-19 08:26:062430void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2431 bool has_video,
2432 bool has_audio,
2433 bool is_playing) {
2434 // Chrome OS does its own detection of audio and video.
2435#if !defined(OS_CHROMEOS)
2436 if (is_playing) {
2437 scoped_ptr<PowerSaveBlocker> blocker;
2438 if (has_video) {
2439 blocker = PowerSaveBlocker::Create(
2440 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2441 "Playing video");
2442#if defined(OS_ANDROID)
2443 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382444 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062445#endif
2446 } else if (has_audio) {
2447 blocker = PowerSaveBlocker::Create(
2448 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2449 "Playing audio");
2450 }
2451
2452 if (blocker)
2453 power_save_blockers_[message_source_][player_cookie] = blocker.release();
2454 } else {
2455 delete power_save_blockers_[message_source_][player_cookie];
2456 power_save_blockers_[message_source_].erase(player_cookie);
2457 }
2458#endif // !defined(OS_CHROMEOS)
2459}
2460
2461
[email protected]e67ebf32013-02-13 11:07:192462void WebContentsImpl::DidChangeVisibleSSLState() {
2463 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2464 DidChangeVisibleSSLState());
2465}
2466
[email protected]17e286e2013-03-01 23:29:392467void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2468 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2469 BeforeFormRepostWarningShow());
2470}
2471
[email protected]ec6c05f2013-10-23 18:41:572472
2473void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2474 Activate();
2475 if (delegate_)
2476 delegate_->ShowRepostFormWarningDialog(this);
2477}
2478
[email protected]96d185d2009-04-24 03:28:542479// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592480// loading, or done loading.
2481void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2482 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262483 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542484 if (is_loading == is_loading_)
2485 return;
2486
2487 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212488 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542489 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562490 upload_size_ = 0;
2491 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542492 }
2493
2494 render_manager_.SetIsLoading(is_loading);
2495
2496 is_loading_ = is_loading;
2497 waiting_for_response_ = is_loading;
2498
[email protected]6ebdc9b2010-09-27 16:55:572499 if (delegate_)
2500 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212501 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542502
[email protected]91621872013-10-08 04:04:592503 if (is_loading) {
[email protected]fae7b5682013-03-15 11:49:432504 TRACE_EVENT_ASYNC_BEGIN0("browser", "WebContentsImpl Loading", this);
[email protected]91621872013-10-08 04:04:592505 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2506 DidStartLoading(render_view_host));
2507 } else {
[email protected]fae7b5682013-03-15 11:49:432508 TRACE_EVENT_ASYNC_END0("browser", "WebContentsImpl Loading", this);
[email protected]91621872013-10-08 04:04:592509 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2510 DidStopLoading(render_view_host));
2511 }
[email protected]66798902013-10-01 18:40:162512
2513 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212514 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2515 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542516 if (details)
[email protected]8ff00d72012-10-23 19:12:212517 det = Details<LoadNotificationDetails>(details);
2518 NotificationService::current()->Notify(
2519 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542520}
2521
[email protected]b172aee2012-04-10 17:05:262522void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212523 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322524 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562525 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322526 // Clear the status bubble. This is a workaround for a bug where WebKit
2527 // doesn't let us know that the cursor left an element during a
2528 // transition (this is also why the mouse cursor remains as a hand after
2529 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2530 // clear the bubble when a user navigates to a named anchor in the same
2531 // page.
[email protected]36fc0392011-12-25 03:59:512532 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322533 }
2534
[email protected]a6e82fc2010-02-24 22:28:142535 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472536 // Once the main frame is navigated, we're no longer considered to have
2537 // displayed insecure content.
2538 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352539 SSLManager::NotifySSLInternalStateChanged(
2540 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172541 }
[email protected]ce5c4502009-05-06 16:46:112542
[email protected]3c9e1872010-11-18 16:17:492543 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252544 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042545 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322546}
2547
[email protected]b172aee2012-04-10 17:05:262548void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322549 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212550 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322551 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112552 // If we navigate off the page, close all JavaScript dialogs.
2553 if (dialog_manager_ && !details.is_in_page)
2554 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322555
[email protected]3c9e1872010-11-18 16:17:492556 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252557 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042558 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322559}
2560
[email protected]2f7b3c5a2013-06-21 04:59:252561bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292562 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2563 // still be used for a normal web site.
2564 if (url == GURL(kAboutBlankURL))
2565 return false;
2566
2567 // The embedder will then have the opportunity to determine if the URL
2568 // should "use up" the SiteInstance.
2569 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252570}
2571
[email protected]b172aee2012-04-10 17:05:262572void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462573 // If we are creating a RVH for a restored controller, then we need to make
2574 // sure the RenderView starts with a next_page_id_ larger than the number
2575 // of restored entries. This must be called before the RenderView starts
2576 // navigating (to avoid a race between the browser updating max_page_id and
2577 // the renderer updating next_page_id_). Because of this, we only call this
2578 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562579 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582580 if (max_restored_page_id >
2581 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2582 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2583 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322584}
2585
[email protected]b172aee2012-04-10 17:05:262586bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2587 const string16& title) {
[email protected]420ae012009-04-24 05:16:322588 // For file URLs without a title, use the pathname instead. In the case of a
2589 // synthesized title, we don't want the update to count toward the "one set
2590 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512591 string16 final_title;
[email protected]420ae012009-04-24 05:16:322592 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512593 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2594 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322595 explicit_set = false; // Don't count synthetic titles toward the set limit.
2596 } else {
[email protected]acafd272011-07-26 17:35:572597 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322598 explicit_set = true;
2599 }
2600
[email protected]987fc3a2011-05-26 14:18:092601 // If a page is created via window.open and never navigated,
2602 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552603 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092604 if (entry) {
[email protected]36fc0392011-12-25 03:59:512605 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092606 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322607
[email protected]36fc0392011-12-25 03:59:512608 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092609 } else {
2610 if (page_title_when_no_navigation_entry_ == final_title)
2611 return false; // Nothing changed, don't bother.
2612
2613 page_title_when_no_navigation_entry_ = final_title;
2614 }
[email protected]420ae012009-04-24 05:16:322615
[email protected]420ae012009-04-24 05:16:322616 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232617 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322618
[email protected]66798902013-10-01 18:40:162619 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532620 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162621
2622 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212623 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462624 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212625 NotificationService::current()->Notify(
2626 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2627 Source<WebContents>(this),
2628 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042629
[email protected]420ae012009-04-24 05:16:322630 return true;
2631}
2632
[email protected]7b712ee22013-10-03 00:57:282633void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2634 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322635 // After sending out a swap notification, we need to send a disconnect
2636 // notification so that clients that pick up a pointer to |this| can NULL the
2637 // pointer. See Bug 1230284.
2638 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112639 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282640 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112641
2642 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282643 std::pair<RenderViewHost*, RenderViewHost*> details =
2644 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212645 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282646 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212647 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282648 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392649
2650 // Ensure that the associated embedder gets cleared after a RenderViewHost
2651 // gets swapped, so we don't reuse the same embedder next time a
2652 // RenderViewHost is attached to this WebContents.
2653 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322654}
2655
[email protected]da7a7182013-09-06 08:11:112656// TODO(avi): Remove this entire function because this notification is already
2657// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262658void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322659 if (!notify_disconnection_)
2660 return;
2661
2662 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212663 NotificationService::current()->Notify(
2664 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2665 Source<WebContents>(this),
2666 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322667}
2668
[email protected]cbb1ef592013-06-05 19:49:462669void WebContentsImpl::NotifyNavigationEntryCommitted(
2670 const LoadCommittedDetails& load_details) {
2671 FOR_EACH_OBSERVER(
2672 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2673}
2674
[email protected]5a3bdf52012-05-24 15:12:572675RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2676 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322677}
2678
[email protected]8d3347f2009-07-09 22:00:212679RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262680WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212681 return &render_manager_;
2682}
2683
[email protected]8ff00d72012-10-23 19:12:212684RendererPreferences WebContentsImpl::GetRendererPrefs(
2685 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462686 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512687}
2688
[email protected]b172aee2012-04-10 17:05:262689WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172690 return this;
2691}
2692
[email protected]b172aee2012-04-10 17:05:262693gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172694 if (delegate_)
2695 return delegate_->GetRootWindowResizerRect();
2696 return gfx::Rect();
2697}
2698
[email protected]7a846df2012-09-20 19:17:392699void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272700 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392701 browser_plugin_embedder_.reset();
2702}
2703
[email protected]b172aee2012-04-10 17:05:262704void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442705 // Don't send notifications if we are just creating a swapped-out RVH for
2706 // the opener chain. These won't be used for view-source or WebUI, so it's
2707 // ok to return early.
2708 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2709 return;
2710
[email protected]86f98a22013-03-20 14:35:002711 if (delegate_)
2712 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082713
[email protected]8ff00d72012-10-23 19:12:212714 NotificationService::current()->Notify(
2715 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2716 Source<WebContents>(this),
2717 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322718
2719 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352720 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562721 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582722 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322723
[email protected]6286a372013-10-09 04:03:272724 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332725 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322726 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182727 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582728 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322729 }
[email protected]0666aef2009-05-13 19:48:082730
[email protected]60780f412013-02-25 16:34:102731 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262732
2733 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252734 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322735}
2736
[email protected]b172aee2012-04-10 17:05:262737void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522738 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322739 // Don't notify the world, since this came from a renderer in the
2740 // background.
2741 return;
2742 }
2743
[email protected]da7a7182013-09-06 08:11:112744 notify_disconnection_ = true;
2745 // TODO(avi): Remove. http://crbug.com/170921
2746 NotificationService::current()->Notify(
2747 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2748 Source<WebContents>(this),
2749 NotificationService::NoDetails());
2750
[email protected]be1f56ab2011-12-22 06:55:312751 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232752 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302753
2754 // Restore the focus to the tab (otherwise the focus will be on the top
2755 // window).
[email protected]484ae5912010-09-29 19:16:142756 if (was_crashed && !FocusLocationBarByDefault() &&
2757 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062758 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142759 }
[email protected]32ded2212011-11-10 18:51:432760
[email protected]d8c660432011-12-22 20:51:252761 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322762}
2763
[email protected]ec6a7eb2013-04-22 17:34:222764void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2765 base::TerminationStatus status,
2766 int error_code) {
[email protected]151a63d2011-12-20 22:32:522767 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322768 // The pending page's RenderViewHost is gone.
2769 return;
2770 }
2771
[email protected]d9030b82013-07-19 08:26:062772 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592773 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322774 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232775 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312776 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322777
[email protected]d8c660432011-12-22 20:51:252778 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272779 observers_,
[email protected]58d5cfe2013-07-10 02:40:522780 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322781}
2782
[email protected]b172aee2012-04-10 17:05:262783void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062784 ClearPowerSaveBlockers(rvh);
[email protected]fb7b79f72009-11-06 18:00:482785 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252786 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062787}
2788
[email protected]b0f724c2013-09-05 04:21:132789void WebContentsImpl::DidGetResourceResponseStart(
2790 const ResourceRequestDetails& details) {
2791 controller_.ssl_manager()->DidStartResourceResponse(details);
2792
2793 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2794 DidGetResourceResponseStart(details));
2795
2796 // TODO(avi): Remove. http://crbug.com/170921
2797 NotificationService::current()->Notify(
2798 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2799 Source<WebContents>(this),
2800 Details<const ResourceRequestDetails>(&details));
2801}
2802
2803void WebContentsImpl::DidGetRedirectForResourceRequest(
2804 const ResourceRedirectDetails& details) {
2805 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2806
2807 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2808 DidGetRedirectForResourceRequest(details));
2809
2810 // TODO(avi): Remove. http://crbug.com/170921
2811 NotificationService::current()->Notify(
2812 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2813 Source<WebContents>(this),
2814 Details<const ResourceRedirectDetails>(&details));
2815}
2816
[email protected]b172aee2012-04-10 17:05:262817void WebContentsImpl::DidNavigate(
2818 RenderViewHost* rvh,
2819 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]9b159a52013-10-03 17:24:552820 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2821 // First navigation should be a main frame navigation.
[email protected]50904452013-05-09 02:05:122822 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552823 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122824 }
2825
[email protected]e3d92a7f2013-01-10 02:35:052826 if (PageTransitionIsMainFrame(params.transition)) {
2827 // When overscroll navigation gesture is enabled, a screenshot of the page
2828 // in its current state is taken so that it can be used during the
2829 // nav-gesture. It is necessary to take the screenshot here, before calling
2830 // RenderViewHostManager::DidNavigateMainFrame, because that can change
2831 // WebContents::GetRenderViewHost to return the new host, instead of the one
2832 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482833 if (delegate_ && delegate_->CanOverscrollContent())
2834 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052835
[email protected]420ae012009-04-24 05:16:322836 render_manager_.DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052837 }
[email protected]8030f012009-09-25 18:09:372838
[email protected]434f69f2012-02-06 21:56:522839 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252840 // assigning a site is not necessary for this URL. In that case, the
2841 // SiteInstance can still be considered unused until a navigation to a real
2842 // page.
[email protected]434f69f2012-02-06 21:56:522843 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252844 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332845 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522846 }
[email protected]420ae012009-04-24 05:16:322847
2848 // Need to update MIME type here because it's referred to in
2849 // UpdateNavigationCommands() called by RendererDidNavigate() to
2850 // determine whether or not to enable the encoding menu.
2851 // It's updated only for the main frame. For a subframe,
2852 // RenderView::UpdateURL does not set params.contents_mime_type.
2853 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2854 // TODO(jungshik): Add a test for the encoding menu to avoid
2855 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212856 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322857 contents_mime_type_ = params.contents_mime_type;
2858
[email protected]8ff00d72012-10-23 19:12:212859 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002860 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392861
[email protected]1ae93fb2013-06-14 03:38:562862 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2863 // us estimate our process count for implementing OOP iframes.
2864 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552865 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562866
[email protected]a9c0bfe2010-09-17 08:35:222867 // Send notification about committed provisional loads. This notification is
2868 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2869 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212870 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072871 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2872 // that is not recorded in the navigation history. For the purpose of
2873 // tracking navigation events, we treat this event as a sub frame navigation
2874 // event.
2875 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212876 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222877 // Whether or not a page transition was triggered by going backward or
2878 // forward in the history is only stored in the navigation controller's
2879 // entry list.
2880 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272881 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212882 PAGE_TRANSITION_FORWARD_BACK)) {
2883 transition_type = PageTransitionFromInt(
2884 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222885 }
[email protected]0d60f0192011-04-14 12:40:102886 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252887 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442888 DidCommitProvisionalLoadForFrame(
2889 params.frame_id,
2890 params.frame_unique_name,
2891 is_main_frame,
2892 params.url,
2893 transition_type,
2894 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222895 }
2896
[email protected]76543b92009-08-31 17:27:452897 if (!did_navigate)
2898 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322899
2900 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2901 // for the appropriate notification (best) or you can add it to
2902 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2903 // necessary, please).
2904
2905 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002906 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322907 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002908 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512909 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002910 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2911 }
[email protected]93f230e02011-06-01 14:40:002912 }
[email protected]420ae012009-04-24 05:16:322913 DidNavigateAnyFramePostCommit(rvh, details, params);
2914}
2915
[email protected]b172aee2012-04-10 17:05:262916void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2917 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042918 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152919 // Ensure that this state update comes from either the active RVH or one of
2920 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]7a49f7e2013-04-19 15:07:222921 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsOnSwappedOutList(rvh));
[email protected]420ae012009-04-24 05:16:322922
2923 // We must be prepared to handle state updates for any page, these occur
2924 // when the user is scrolling and entering form data, as well as when we're
2925 // leaving a page, in which case our state may have already been moved to
2926 // the next page. The navigation controller will look up the appropriate
2927 // NavigationEntry and update it when it is notified via the delegate.
2928
2929 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582930 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322931 if (entry_index < 0)
2932 return;
[email protected]10f417c52011-12-28 21:04:232933 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322934
[email protected]691aa2f2013-05-28 22:52:042935 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322936 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042937 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322938 controller_.NotifyEntryChanged(entry, entry_index);
2939}
2940
[email protected]b172aee2012-04-10 17:05:262941void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2942 int32 page_id,
2943 const string16& title,
2944 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322945 // If we have a title, that's a pretty good indication that we've started
2946 // getting useful data.
2947 SetNotWaitingForResponse();
2948
[email protected]73eb2602012-02-09 19:50:552949 // Try to find the navigation entry, which might not be the current one.
2950 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232951 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582952 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092953
[email protected]73eb2602012-02-09 19:50:552954 // We can handle title updates when we don't have an entry in
2955 // UpdateTitleForEntry, but only if the update is from the current RVH.
2956 if (!entry && rvh != GetRenderViewHost())
2957 return;
2958
[email protected]a49e10b2011-08-01 23:57:462959 // TODO(evan): make use of title_direction.
2960 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092961 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322962 return;
2963
2964 // Broadcast notifications when the UI should be updated.
2965 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212966 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322967}
2968
[email protected]b172aee2012-04-10 17:05:262969void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2970 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312971 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322972}
2973
[email protected]b172aee2012-04-10 17:05:262974void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512975 if (delegate_)
2976 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322977}
2978
[email protected]b172aee2012-04-10 17:05:262979void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:102980#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:292981 // The UI may be in an event-tracking loop, such as between the
2982 // mouse-down and mouse-up in text selection or a button click.
2983 // Defer the close until after tracking is complete, so that we
2984 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292985 // TODO(shess): This could get more fine-grained. For instance,
2986 // closing a tab in another window while selecting text in the
2987 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:102988 if (view_->IsEventTracking()) {
2989 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292990 return;
2991 }
[email protected]60780f412013-02-25 16:34:102992#endif
[email protected]07707302009-11-06 00:50:292993
[email protected]420ae012009-04-24 05:16:322994 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522995 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512996 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322997}
2998
[email protected]b172aee2012-04-10 17:05:262999void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523000 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513001 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283002
3003 // Allow the navigation to proceed.
3004 render_manager_.SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573005}
3006
[email protected]b172aee2012-04-10 17:05:263007void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513008 if (delegate_ && delegate_->IsPopupOrPanel(this))
3009 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323010}
3011
[email protected]8ff00d72012-10-23 19:12:213012void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593013 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323014}
3015
[email protected]8ff00d72012-10-23 19:12:213016void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323017 scoped_ptr<LoadNotificationDetails> details;
3018
[email protected]9595fd82013-04-19 21:28:493019 // Use the last committed entry rather than the active one, in case a
3020 // pending entry has been created.
3021 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3022
[email protected]420ae012009-04-24 05:16:323023 // An entry may not exist for a stop when loading an initial blank page or
3024 // if an iframe injected by script into a blank page finishes loading.
3025 if (entry) {
[email protected]420ae012009-04-24 05:16:323026 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3027
3028 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513029 entry->GetVirtualURL(),
3030 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323031 elapsed,
3032 &controller_,
3033 controller_.GetCurrentEntryIndex()));
3034 }
3035
[email protected]91621872013-10-08 04:04:593036 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323037}
3038
[email protected]b172aee2012-04-10 17:05:263039void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163040 controller_.DiscardNonCommittedEntries();
3041
3042 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213043 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163044}
3045
[email protected]b172aee2012-04-10 17:05:263046void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513047 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133048 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403049}
3050
[email protected]7cc78902012-12-06 02:32:263051void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393052 if (opener_) {
3053 // Clear our opener so that future cross-process navigations don't have an
3054 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103055 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393056 opener_ = NULL;
3057 }
[email protected]7cc78902012-12-06 02:32:263058
3059 // Notify all swapped out RenderViewHosts for this tab. This is important
3060 // in case we go back to them, or if another window in those processes tries
3061 // to access window.opener.
3062 render_manager_.DidDisownOpener(rvh);
3063}
3064
[email protected]59167c22013-06-03 18:07:323065void WebContentsImpl::DidAccessInitialDocument() {
3066 // Update the URL display.
3067 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3068}
3069
[email protected]87717d0e2012-04-26 02:58:433070void WebContentsImpl::DocumentAvailableInMainFrame(
3071 RenderViewHost* render_view_host) {
3072 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3073 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103074}
3075
[email protected]b172aee2012-04-10 17:05:263076void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083077 RenderViewHost* render_view_host,
3078 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093079 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3080 DocumentOnLoadCompletedInMainFrame(page_id));
3081
3082 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213083 NotificationService::current()->Notify(
3084 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3085 Source<WebContents>(this),
3086 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083087}
3088
[email protected]196159d2012-05-04 17:26:543089void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3090 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213091 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263092 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183093 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523094 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303095 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543096 // If this came from a swapped out RenderViewHost, we only allow the request
3097 // if we are still in the same BrowsingInstance.
3098 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3099 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3100 return;
3101 }
3102
[email protected]4ad5d77d2011-12-03 02:00:483103 // Delegate to RequestTransferURL because this is just the generic
3104 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573105 // TODO(creis): Pass the redirect_chain into this method to support client
3106 // redirects. http://crbug.com/311721.
3107 std::vector<GURL> redirect_chain;
3108 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3109 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523110 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483111}
3112
[email protected]b172aee2012-04-10 17:05:263113void WebContentsImpl::RequestTransferURL(
3114 const GURL& url,
[email protected]f8872902013-10-30 03:18:573115 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213116 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573117 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263118 WindowOpenDisposition disposition,
3119 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183120 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523121 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303122 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203123 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123124 GURL dest_url(url);
3125 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553126 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123127 dest_url = GURL(kAboutBlankURL);
3128
[email protected]44d0930a2013-10-28 18:53:553129 OpenURLParams params(dest_url, referrer, source_frame_id, disposition,
[email protected]f8872902013-10-30 03:18:573130 page_transition, true /* is_renderer_initiated */);
3131 if (redirect_chain.size() > 0)
3132 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553133 params.transferred_global_request_id = old_request_id;
3134 params.should_replace_current_entry = should_replace_current_entry;
3135 params.user_gesture = user_gesture;
3136
[email protected]7ade2732011-02-10 00:13:583137 if (render_manager_.web_ui()) {
[email protected]f8872902013-10-30 03:18:573138 // Web UI pages sometimes want to override the page transition type for
3139 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3140 // automatically generated suggestions). We don't override other types
3141 // like TYPED because they have different implications (e.g., autocomplete).
3142 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
3143 params.transition = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553144
[email protected]e0112912011-02-02 22:54:353145 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163146 // want web sites to see a referrer of "chrome://blah" (and some
3147 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323148 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553149 params.referrer = Referrer();
3150
3151 // Navigations in Web UI pages count as browser-initiated navigations.
3152 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583153 }
[email protected]44d0930a2013-10-28 18:53:553154
3155 new_contents = OpenURL(params);
3156
[email protected]ae5184d62011-10-06 19:25:583157 if (new_contents) {
3158 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253159 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583160 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123161 dest_url,
[email protected]ae5184d62011-10-06 19:25:583162 referrer,
3163 disposition,
[email protected]44d0930a2013-10-28 18:53:553164 params.transition,
[email protected]ae5184d62011-10-06 19:25:583165 source_frame_id));
[email protected]420ae012009-04-24 05:16:323166 }
3167}
3168
[email protected]e1c3a552012-05-04 20:51:323169void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3170 // Tell the active RenderViewHost to run unload handlers and close, as long
3171 // as the request came from a RenderViewHost in the same BrowsingInstance.
3172 // In most cases, we receive this from a swapped out RenderViewHost.
3173 // It is possible to receive it from one that has just been swapped in,
3174 // in which case we might as well deliver the message anyway.
3175 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3176 GetRenderViewHost()->ClosePage();
3177}
3178
[email protected]f546640b2012-05-15 00:03:493179void WebContentsImpl::RouteMessageEvent(
3180 RenderViewHost* rvh,
3181 const ViewMsg_PostMessage_Params& params) {
3182 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363183 // came from a RenderViewHost in the same BrowsingInstance or if this
3184 // WebContents is dedicated to a browser plugin guest.
3185 // Note: This check means that an embedder could theoretically receive a
3186 // postMessage from anyone (not just its own guests). However, this is
3187 // probably not a risk for apps since other pages won't have references
3188 // to App windows.
3189 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3190 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493191 return;
3192
3193 ViewMsg_PostMessage_Params new_params(params);
3194
[email protected]0bc7f3542013-10-21 15:05:533195 if (!params.message_port_ids.empty()) {
3196 MessagePortMessageFilter* message_port_message_filter =
3197 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3198 ->message_port_message_filter();
3199 std::vector<int> new_routing_ids(params.message_port_ids.size());
3200 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3201 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3202 MessagePortService::GetInstance()->UpdateMessagePort(
3203 params.message_port_ids[i],
3204 message_port_message_filter,
3205 new_routing_ids[i]);
3206 }
3207 new_params.new_routing_ids = new_routing_ids;
3208 }
3209
[email protected]f546640b2012-05-15 00:03:493210 // If there is a source_routing_id, translate it to the routing ID for
3211 // the equivalent swapped out RVH in the target process. If we need
3212 // to create a swapped out RVH for the source tab, we create its opener
3213 // chain as well, since those will also be accessible to the target page.
3214 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3215 // Try to look up the WebContents for the source page.
3216 WebContentsImpl* source_contents = NULL;
3217 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3218 rvh->GetProcess()->GetID(), params.source_routing_id);
3219 if (source_rvh) {
3220 source_contents = static_cast<WebContentsImpl*>(
3221 source_rvh->GetDelegate()->GetAsWebContents());
3222 }
3223
3224 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363225 if (GetBrowserPluginGuest()) {
3226 // We create a swapped out RenderView for the embedder in the guest's
3227 // render process but we intentionally do not expose the embedder's
3228 // opener chain to it.
3229 new_params.source_routing_id =
3230 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3231 } else {
3232 new_params.source_routing_id =
3233 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3234 }
[email protected]f546640b2012-05-15 00:03:493235 } else {
3236 // We couldn't find it, so don't pass a source frame.
3237 new_params.source_routing_id = MSG_ROUTING_NONE;
3238 }
3239 }
3240
3241 // In most cases, we receive this from a swapped out RenderViewHost.
3242 // It is possible to receive it from one that has just been swapped in,
3243 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183244 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493245}
3246
[email protected]b172aee2012-04-10 17:05:263247void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343248 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413249 const string16& message,
3250 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323251 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213252 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323253 IPC::Message* reply_msg,
3254 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073255 // Suppress JavaScript dialogs when requested. Also suppress messages when
3256 // showing an interstitial as it's shown over the previous page and we don't
3257 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503258 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583259 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273260 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073261 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523262 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153263 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323264
3265 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213266 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433267 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153268 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3269 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433270 this,
3271 frame_url.GetOrigin(),
3272 accept_lang,
3273 javascript_message_type,
3274 message,
[email protected]51da7e32012-01-30 19:24:523275 default_prompt,
[email protected]b172aee2012-04-10 17:05:263276 base::Bind(&WebContentsImpl::OnDialogClosed,
3277 base::Unretained(this),
3278 rvh,
3279 reply_msg),
[email protected]51da7e32012-01-30 19:24:523280 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323281 }
[email protected]3ab9cb82011-06-03 18:02:073282
[email protected]6dd2f1e2013-09-11 15:06:013283 *did_suppress_message = suppress_this_message;
3284
[email protected]3ab9cb82011-06-03 18:02:073285 if (suppress_this_message) {
3286 // If we are suppressing messages, just reply as if the user immediately
3287 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343288 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073289 }
3290
[email protected]6dd2f1e2013-09-11 15:06:013291 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3292 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323293}
3294
[email protected]b172aee2012-04-10 17:05:263295void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3296 const string16& message,
3297 bool is_reload,
3298 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583299 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513300 if (delegate_)
3301 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073302
3303 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583304 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073305 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523306 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153307 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153308 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343309 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583310 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503311 return;
3312 }
[email protected]3ab9cb82011-06-03 18:02:073313
[email protected]7ab1e7d62009-10-14 23:32:013314 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153315 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3316 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323317 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263318 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523319 reply_msg));
[email protected]420ae012009-04-24 05:16:323320}
3321
[email protected]a796f202012-05-30 14:14:253322bool WebContentsImpl::AddMessageToConsole(int32 level,
3323 const string16& message,
3324 int32 line_no,
[email protected]88b50b62013-09-01 23:05:063325 const string16& source_id) {
[email protected]a796f202012-05-30 14:14:253326 if (!delegate_)
3327 return false;
3328 return delegate_->AddMessageToConsole(this, level, message, line_no,
3329 source_id);
3330}
3331
[email protected]b172aee2012-04-10 17:05:263332WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273333 // We want to base the page config off of the actual URL, rather than the
3334 // virtual URL.
3335 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3336 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003337 GURL url = controller_.GetActiveEntry()
3338 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153339
3340 return render_manager_.current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323341}
3342
[email protected]0eba810b2012-10-18 03:19:363343int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213344 SiteInstance* instance) {
[email protected]1ac10dca2013-08-20 20:47:043345 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE,
3346 true, true);
[email protected]0eba810b2012-10-18 03:19:363347}
3348
[email protected]b172aee2012-04-10 17:05:263349void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273350 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253351 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223352
[email protected]ea114722012-03-12 01:11:253353 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173354 if (rdh) // NULL in unittests.
3355 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253356}
3357
[email protected]b172aee2012-04-10 17:05:263358void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443359 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253360 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443361}
3362
[email protected]b172aee2012-04-10 17:05:263363void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563364 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263365 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153366 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523367 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153368 return;
3369
[email protected]9f76c1e2012-03-05 15:15:583370 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3371
[email protected]e5fc1632011-08-08 07:51:533372 // Ignore renderer unresponsive event if debugger is attached to the tab
3373 // since the event may be a result of the renderer sitting on a breakpoint.
3374 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363375 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533376 return;
3377
[email protected]2e9d79f2013-08-16 05:45:563378 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323379 // Hang occurred while firing the beforeunload/unload handler.
3380 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583381 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323382
3383 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3384 return;
3385
3386 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563387 // nothing we can do to recover. If the hang is in the beforeunload handler,
3388 // pretend the beforeunload listeners have all fired and allow the delegate
3389 // to continue closing; the user will not have the option of cancelling the
3390 // close. Otherwise, pretend the unload listeners have all fired and close
3391 // the tab.
3392 bool close = true;
3393 if (is_during_beforeunload) {
3394 delegate_->BeforeUnloadFired(this, true, &close);
3395 }
3396 if (close)
3397 Close(rvh);
[email protected]420ae012009-04-24 05:16:323398 return;
3399 }
3400
[email protected]9f76c1e2012-03-05 15:15:583401 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473402 return;
3403
[email protected]6934a702011-12-20 00:04:513404 if (delegate_)
3405 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323406}
3407
[email protected]b172aee2012-04-10 17:05:263408void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513409 if (delegate_)
3410 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323411}
3412
[email protected]b172aee2012-04-10 17:05:263413void WebContentsImpl::LoadStateChanged(
3414 const GURL& url,
3415 const net::LoadStateWithParam& load_state,
3416 uint64 upload_position,
3417 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323418 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563419 upload_position_ = upload_position;
3420 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503421 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213422 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303423 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213424 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323425 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463426 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213427 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463428 }
[email protected]420ae012009-04-24 05:16:323429}
3430
[email protected]b172aee2012-04-10 17:05:263431void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513432 if (delegate_)
3433 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253434}
3435
[email protected]b172aee2012-04-10 17:05:263436void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553437 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323438 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123439 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3440 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513441 if (delegate_)
3442 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093443 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323444}
3445
[email protected]58d5cfe2013-07-10 02:40:523446void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543447 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233448 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223449 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543450}
3451
[email protected]b172aee2012-04-10 17:05:263452void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103453 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213454 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263455 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3456 // here during container initialization and normal window size will be set
3457 // later. In case of tab duplication this resizing to 0x0 prevents setting
3458 // normal size later so just ignore it.
3459 if (!size.IsEmpty())
3460 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323461}
3462
[email protected]af905902013-10-01 21:38:513463void WebContentsImpl::CancelModalDialogsForRenderManager() {
3464 // We need to cancel modal dialogs when doing a process swap, since the load
3465 // deferrer would prevent us from swapping out.
3466 if (dialog_manager_)
3467 dialog_manager_->CancelActiveAndPendingDialogs(this);
3468}
3469
[email protected]7b712ee22013-10-03 00:57:283470void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3471 RenderViewHost* new_host) {
3472 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083473
3474 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003475 if (delegate_)
3476 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393477
[email protected]7b712ee22013-10-03 00:57:283478 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543479}
3480
[email protected]14392a52012-05-02 20:28:443481int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3482 SiteInstance* instance) {
3483 if (!opener_)
3484 return MSG_ROUTING_NONE;
3485
3486 // Recursively create RenderViews for anything else in the opener chain.
3487 return opener_->CreateOpenerRenderViews(instance);
3488}
3489
3490int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3491 int opener_route_id = MSG_ROUTING_NONE;
3492
3493 // If this tab has an opener, ensure it has a RenderView in the given
3494 // SiteInstance as well.
3495 if (opener_)
3496 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3497
[email protected]45a22ad2013-02-21 03:25:003498 // If any of the renderers (current, pending, or swapped out) for this
3499 // WebContents has the same SiteInstance, use it.
[email protected]0720b532012-08-28 19:23:373500 if (render_manager_.current_host()->GetSiteInstance() == instance)
3501 return render_manager_.current_host()->GetRoutingID();
3502
[email protected]45a22ad2013-02-21 03:25:003503 if (render_manager_.pending_render_view_host() &&
3504 render_manager_.pending_render_view_host()->GetSiteInstance() == instance)
3505 return render_manager_.pending_render_view_host()->GetRoutingID();
3506
[email protected]0720b532012-08-28 19:23:373507 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3508 instance);
3509 if (rvh)
3510 return rvh->GetRoutingID();
3511
[email protected]14392a52012-05-02 20:28:443512 // Create a swapped out RenderView in the given SiteInstance if none exists,
3513 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]1ac10dca2013-08-20 20:47:043514 return render_manager_.CreateRenderView(instance, opener_route_id,
3515 true, true);
[email protected]14392a52012-05-02 20:28:443516}
3517
[email protected]b172aee2012-04-10 17:05:263518NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193519 return GetController();
[email protected]3a3d47472010-07-15 21:03:543520}
3521
[email protected]b172aee2012-04-10 17:05:263522WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563523 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323524}
3525
[email protected]10f417c52011-12-28 21:04:233526NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263527 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323528 return controller_.GetLastCommittedEntry();
3529}
3530
[email protected]b172aee2012-04-10 17:05:263531bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443532 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033533 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443534 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323535 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523536
[email protected]420ae012009-04-24 05:16:323537 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443538 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213539 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323540
[email protected]74ce1ad2011-12-16 21:51:463541 // Make sure we use the correct starting page_id in the new RenderView.
3542 UpdateMaxPageIDIfNecessary(render_view_host);
3543 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583544 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463545
[email protected]9f76c1e2012-03-05 15:15:583546 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493547 render_view_host)->CreateRenderView(string16(),
3548 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133549 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523550 return false;
[email protected]14392a52012-05-02 20:28:443551 }
[email protected]a4127722011-04-27 23:13:523552
[email protected]a220b5932013-09-21 03:47:443553#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503554 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3555 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443556 if (rwh_view) {
3557 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3558 render_widget_host->WasResized();
3559 }
[email protected]f8233cc2011-05-31 20:24:503560#endif
3561
[email protected]420ae012009-04-24 05:16:323562 return true;
3563}
3564
[email protected]7d244f12013-08-22 21:41:513565#if defined(OS_ANDROID)
3566bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3567 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3568 MSG_ROUTING_NONE);
3569}
3570#endif
3571
[email protected]b172aee2012-04-10 17:05:263572void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3573 IPC::Message* reply_msg,
3574 bool success,
3575 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543576 if (is_showing_before_unload_dialog_ && !success) {
3577 // If a beforeunload dialog is canceled, we need to stop the throbber from
3578 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293579 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353580 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103581
[email protected]6d65a462013-06-21 21:29:123582 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3583 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543584 }
3585 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583586 static_cast<RenderViewHostImpl*>(
3587 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543588}
3589
[email protected]b172aee2012-04-10 17:05:263590void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213591 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123592 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103593}
[email protected]f45d2a72010-03-08 23:28:353594
[email protected]b172aee2012-04-10 17:05:263595void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103596 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443597 // Can be NULL during tests.
3598 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213599 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363600}
[email protected]9f76c1e2012-03-05 15:15:583601
[email protected]1ac10dca2013-08-20 20:47:043602bool WebContentsImpl::IsHidden() {
3603 return capturer_count_ == 0 && !should_normally_be_visible_;
3604}
3605
[email protected]b172aee2012-04-10 17:05:263606RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583607 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3608}
[email protected]7900bfdb2012-05-24 19:31:243609
[email protected]f8497342013-02-05 22:15:023610BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393611 return browser_plugin_guest_.get();
3612}
3613
[email protected]738f57a2013-06-29 21:06:543614void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3615 CHECK(!browser_plugin_guest_);
3616 browser_plugin_guest_.reset(guest);
3617}
3618
[email protected]f8497342013-02-05 22:15:023619BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393620 return browser_plugin_embedder_.get();
3621}
[email protected]8ff00d72012-10-23 19:12:213622
[email protected]8eb04562013-03-06 03:41:143623BrowserPluginGuestManager*
3624 WebContentsImpl::GetBrowserPluginGuestManager() const {
3625 return static_cast<BrowserPluginGuestManager*>(
3626 GetBrowserContext()->GetUserData(
3627 browser_plugin::kBrowserPluginGuestManagerKeyName));
3628}
3629
[email protected]d9030b82013-07-19 08:26:063630void WebContentsImpl::ClearPowerSaveBlockers(
3631 RenderViewHost* render_view_host) {
3632 STLDeleteValues(&power_save_blockers_[render_view_host]);
3633 power_save_blockers_.erase(render_view_host);
3634}
3635
3636void WebContentsImpl::ClearAllPowerSaveBlockers() {
3637 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3638 i != power_save_blockers_.end(); ++i)
3639 STLDeleteValues(&power_save_blockers_[i->first]);
3640 power_save_blockers_.clear();
3641}
3642
[email protected]dc0fd432013-08-27 15:29:213643gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3644 gfx::Size size;
3645 if (delegate_)
3646 size = delegate_->GetSizeForNewRenderView(this);
3647 if (size.IsEmpty())
3648 size = view_->GetContainerSize();
3649 return size;
3650}
3651
[email protected]9b159a52013-10-03 17:24:553652void WebContentsImpl::OnFrameRemoved(
3653 RenderViewHostImpl* render_view_host,
3654 int64 frame_id) {
3655 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3656 FrameDetached(render_view_host, frame_id));
3657}
3658
[email protected]8ff00d72012-10-23 19:12:213659} // namespace content