blob: f089c4a5ecf548134d453e3f6d814b28969423e5 [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]5c9250872012-01-30 17:24:0530#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4431#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5332#include "content/browser/message_port_message_filter.h"
33#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0634#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3035#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3236#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5037#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3338#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3739#include "content/browser/web_contents/interstitial_page_impl.h"
40#include "content/browser/web_contents/navigation_entry_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]74ebfb12013-06-07 20:48:0090#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:1091#endif
92
[email protected]f66df822012-05-18 16:52:1793#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5094#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:2795#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5796#endif
[email protected]3e45ba92009-02-20 21:09:0097
[email protected]c7654a232013-06-12 21:04:4498#if defined(OS_ANDROID)
[email protected]4cc1ab52013-01-21 19:24:3499#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
100#endif
101
[email protected]420ae012009-04-24 05:16:32102// Cross-Site Navigations
103//
[email protected]b172aee2012-04-10 17:05:26104// If a WebContentsImpl is told to navigate to a different web site (as
105// determined by SiteInstance), it will replace its current RenderViewHost with
106// a new RenderViewHost dedicated to the new SiteInstance. This works as
107// follows:
[email protected]420ae012009-04-24 05:16:32108//
[email protected]fc6c1872013-10-03 01:22:35109// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46110// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32111// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35112// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32113// run in the current RVH.
114// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35115// that it has a pending cross-site request. We will check this on the IO
116// thread when deciding how to handle the response.
117// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46118// cancel all the pending logic. Otherwise we allow the pending RVH to send
119// the navigation request to its renderer.
120// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35121// main resource load on the pending RVH. It creates a
122// CrossSiteResourceHandler to check whether a process swap is needed when
123// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46124// - When RDH receives a response, the BufferedResourceHandler determines
125// whether it is a download. If so, it sends a message to the new renderer
126// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26127// pending RVH remains until the next DidNavigate event for this
128// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32129// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35130// download, the CrossSiteResourceHandler checks whether a process swap is
131// needed (either because CrossSiteRequestManager has state for it or because
132// a transfer was needed for a redirect).
133// - If so, CrossSiteResourceHandler pauses the response to first run the old
134// page's unload handler. It does this by asynchronously calling the
135// OnCrossSiteResponse method of RenderViewHostManager on the UI thread, which
136// sends a SwapOut message to the current RVH.
137// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
138// to a new process is needed, based on the stored pending_nav_params_. (This
139// is independent of whether we started out with a cross-process navigation.)
140// - If not, it just tells the ResourceDispatcherHost to resume the response
141// to its current RenderViewHost.
142// - If so, it cancels the current pending RenderViewHost and sets up a new
143// navigation using RequestTransferURL. When the transferred request
144// arrives in the ResourceDispatcherHost, we transfer the response and
145// resume it.
[email protected]420ae012009-04-24 05:16:32146// - The pending renderer sends a FrameNavigate message that invokes the
147// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46148// pending RVH.
[email protected]992db4c2011-05-12 15:37:15149// - The previous renderer is kept swapped out in RenderViewHostManager in case
150// the user goes back. The process only stays live if another tab is using
151// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32152
[email protected]8ff00d72012-10-23 19:12:21153namespace content {
[email protected]420ae012009-04-24 05:16:32154namespace {
155
[email protected]82114f52012-03-20 22:53:41156const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05157
[email protected]cbb1ef592013-06-05 19:49:46158base::LazyInstance<std::vector<WebContents::CreatedCallback> >
159g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
160
[email protected]795c28972012-12-06 06:13:39161static int StartDownload(content::RenderViewHost* rvh,
162 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29163 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30164 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02165 static int g_next_image_download_id = 0;
166 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
167 ++g_next_image_download_id,
168 url,
169 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30170 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02171 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39172}
173
[email protected]2c5569662011-03-22 20:45:02174ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21175 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50176 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16177 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47178 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02179 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47180 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02181 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23182 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
183 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47184 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16185 break; // Fall through to rest of function.
186 }
[email protected]5e369672009-11-03 23:48:30187
[email protected]59246c572012-02-10 13:32:13188 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
189 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36190 if (entry.restore_type() ==
191 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13192 if (entry.GetHasPostData())
193 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02194 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13195 }
[email protected]5e369672009-11-03 23:48:30196
[email protected]2c5569662011-03-22 20:45:02197 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30198}
199
[email protected]10f417c52011-12-28 21:04:23200void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47201 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21202 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50203 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16204 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51205 params->page_id = entry.GetPageID();
[email protected]60d6cca2013-04-30 08:47:13206 params->should_clear_history_list = entry.should_clear_history_list();
207 if (entry.should_clear_history_list()) {
208 // Set the history list related parameters to the same values a
209 // NavigationController would return before its first navigation. This will
210 // fully clear the RenderView's view of the session history.
211 params->pending_history_list_offset = -1;
212 params->current_history_list_offset = -1;
213 params->current_history_list_length = 0;
214 } else {
215 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
216 params->current_history_list_offset =
217 controller.GetLastCommittedEntryIndex();
218 params->current_history_list_length = controller.GetEntryCount();
219 }
[email protected]eaaba7dd2013-10-14 02:38:07220 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36221 if (!entry.GetBaseURLForDataURL().is_empty()) {
222 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
223 params->history_url_for_data_url = entry.GetVirtualURL();
224 }
[email protected]36fc0392011-12-25 03:59:51225 params->referrer = entry.GetReferrer();
226 params->transition = entry.GetTransitionType();
[email protected]691aa2f2013-05-28 22:52:04227 params->page_state = entry.GetPageState();
[email protected]3cc72b12010-03-18 23:03:00228 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55229 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34230 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47231 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48232 params->transferred_request_child_id =
233 entry.transferred_global_request_id().child_id;
234 params->transferred_request_request_id =
235 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22236 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00237 // Avoid downloading when in view-source mode.
238 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44239 params->is_post = entry.GetHasPostData();
[email protected]eaaba7dd2013-10-14 02:38:07240 if (entry.GetBrowserInitiatedPostData()) {
241 params->browser_initiated_post_data.assign(
242 entry.GetBrowserInitiatedPostData()->front(),
243 entry.GetBrowserInitiatedPostData()->front() +
244 entry.GetBrowserInitiatedPostData()->size());
[email protected]7c16976c2012-08-04 02:38:23245 }
246
[email protected]f8872902013-10-30 03:18:57247 params->redirects = entry.redirect_chain();
248
[email protected]951a64832012-10-11 16:26:37249 params->can_load_local_resources = entry.GetCanLoadLocalResources();
[email protected]3027cf02013-01-24 08:16:58250 params->frame_to_navigate = entry.GetFrameToNavigate();
[email protected]951a64832012-10-11 16:26:37251
[email protected]6c6b02d2011-09-02 03:36:47252 if (delegate)
253 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34254}
255
[email protected]8bfc8272013-09-09 20:10:53256void NotifyCacheOnIO(
257 scoped_refptr<net::URLRequestContextGetter> request_context,
258 const GURL& url,
259 const std::string& http_method) {
260 request_context->GetURLRequestContext()->http_transaction_factory()->
261 GetCache()->OnExternalCacheHit(url, http_method);
262}
263
[email protected]9b159a52013-10-03 17:24:55264// Helper function for retrieving all the sites in a frame tree.
265bool CollectSites(BrowserContext* context,
266 std::set<GURL>* sites,
267 FrameTreeNode* node) {
268 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
269 return true;
270}
271
[email protected]420ae012009-04-24 05:16:32272} // namespace
273
[email protected]54944cde2012-12-09 09:24:59274WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15275 return WebContentsImpl::CreateWithOpener(
276 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19277}
278
279WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59280 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30281 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59282 WebContentsImpl* new_contents = new WebContentsImpl(
283 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30284
285 for (SessionStorageNamespaceMap::const_iterator it =
286 session_storage_namespace_map.begin();
287 it != session_storage_namespace_map.end();
288 ++it) {
289 new_contents->GetController()
290 .SetSessionStorageNamespace(it->first, it->second.get());
291 }
292
[email protected]54944cde2012-12-09 09:24:59293 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19294 return new_contents;
[email protected]a81343d232011-12-27 07:39:20295}
[email protected]746d3052012-05-22 15:15:47296
[email protected]cbb1ef592013-06-05 19:49:46297void WebContents::AddCreatedCallback(const CreatedCallback& callback) {
298 g_created_callbacks.Get().push_back(callback);
299}
300
301void WebContents::RemoveCreatedCallback(const CreatedCallback& callback) {
302 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
303 if (g_created_callbacks.Get().at(i).Equals(callback)) {
304 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
305 return;
306 }
307 }
308}
309
[email protected]299d7f12012-05-23 05:31:15310WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47311 return rvh->GetDelegate()->GetAsWebContents();
312}
313
[email protected]7fff43e2013-05-21 20:21:10314// WebContentsImpl::DestructionObserver ----------------------------------------
315
316class WebContentsImpl::DestructionObserver : public WebContentsObserver {
317 public:
318 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
319 : WebContentsObserver(watched_contents),
320 owner_(owner) {
321 }
322
323 // WebContentsObserver:
324 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
325 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
326 }
327
328 private:
329 WebContentsImpl* owner_;
330
331 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
332};
333
[email protected]b172aee2012-04-10 17:05:26334// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32335
[email protected]b172aee2012-04-10 17:05:26336WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21337 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19338 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42339 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22340 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57341 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44342 opener_(opener),
[email protected]c73a2282013-04-29 21:10:41343#if defined(OS_WIN) && defined(USE_AURA)
344 accessible_parent_(NULL),
345#endif
[email protected]69e797f2013-04-30 01:10:22346 render_manager_(this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34347 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23348 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
349 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34350 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21351 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56352 upload_size_(0),
353 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47354 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55355 capturer_count_(0),
356 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57357 is_being_destroyed_(false),
358 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15359 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01360 is_showing_before_unload_dialog_(false),
[email protected]ebf40a72010-07-22 01:46:38361 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21362 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
363 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00364 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21365 color_chooser_identifier_(0),
[email protected]f8bebfb2013-03-06 04:22:58366 message_source_(NULL),
[email protected]44470a22013-01-24 01:21:54367 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
[email protected]cbb1ef592013-06-05 19:49:46368 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
369 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55370 frame_tree_.SetFrameRemoveListener(
371 base::Bind(&WebContentsImpl::OnFrameRemoved,
372 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35373}
initial.commit09911bf2008-07-26 23:55:29374
[email protected]b172aee2012-04-10 17:05:26375WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32376 is_being_destroyed_ = true;
377
[email protected]d9030b82013-07-19 08:26:06378 ClearAllPowerSaveBlockers();
379
[email protected]b24b68a2012-09-24 21:57:26380 for (std::set<RenderWidgetHostImpl*>::iterator iter =
381 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
382 (*iter)->DetachDelegate();
383 }
384 created_widgets_.clear();
385
[email protected]3ab9cb82011-06-03 18:02:07386 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15387 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11388 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07389
[email protected]da8543762012-03-20 08:52:20390 if (color_chooser_)
391 color_chooser_->End();
392
[email protected]420ae012009-04-24 05:16:32393 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32394
[email protected]ca13a442012-04-17 14:00:12395 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21396 NotificationService::current()->Notify(
397 NOTIFICATION_WEB_CONTENTS_DESTROYED,
398 Source<WebContents>(this),
399 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32400
401 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07402#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32403 // If we still have a window handle, destroy it. GetNativeView can return
404 // NULL if this contents was part of a window that closed.
[email protected]f3615f02013-02-26 06:09:06405 if (view_->GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52406 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58407 if (host && host->GetView())
408 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42409 }
[email protected]420ae012009-04-24 05:16:32410#endif
[email protected]7ab1e7d62009-10-14 23:32:01411
[email protected]f273ee52013-10-18 16:05:27412 RenderViewHost* pending_rvh = render_manager_.pending_render_view_host();
413 if (pending_rvh) {
414 FOR_EACH_OBSERVER(WebContentsObserver,
415 observers_,
416 RenderViewDeleted(pending_rvh));
417 }
418
419 FOR_EACH_OBSERVER(WebContentsObserver,
420 observers_,
421 RenderViewDeleted(render_manager_.current_host()));
422
[email protected]2db9bd72012-04-13 20:20:56423 FOR_EACH_OBSERVER(WebContentsObserver,
424 observers_,
425 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08426
[email protected]6934a702011-12-20 00:04:51427 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10428
429 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
430 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42431}
432
[email protected]d1198fd2012-08-13 22:50:19433WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59434 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19435 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03436 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59437 WebContentsImpl* new_contents = new WebContentsImpl(
438 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19439
[email protected]54944cde2012-12-09 09:24:59440 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19441 return new_contents;
442}
443
[email protected]b371a5652013-02-20 11:25:51444// static
[email protected]8eb04562013-03-06 03:41:14445BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36446 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53447 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54448 int guest_instance_id,
449 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39450 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39451
452 // This makes |new_contents| act as a guest.
453 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54454 BrowserPluginGuest::Create(
455 guest_instance_id, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11456
[email protected]3de10bb32013-01-08 21:57:33457 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33458 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11459
[email protected]216be772013-01-25 00:22:27460 // We are instantiating a WebContents for browser plugin. Set its subframe bit
461 // to true.
462 static_cast<RenderViewHostImpl*>(
463 new_contents->GetRenderViewHost())->set_is_subframe(true);
464
[email protected]8eb04562013-03-06 03:41:14465 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39466}
467
[email protected]b172aee2012-04-10 17:05:26468RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28469 return &render_manager_;
470}
471
[email protected]7bb761892012-07-20 09:32:47472bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
473 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56474 if (GetWebUI() &&
475 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17476 return true;
[email protected]d2353452012-01-19 19:53:56477 }
[email protected]f82d57b52011-04-27 19:13:17478
[email protected]d8c660432011-12-22 20:51:25479 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
480 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10481 while ((observer = it.GetNext()) != NULL)
482 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53483 return true;
[email protected]403415a2011-01-10 18:57:53484
[email protected]7bb761892012-07-20 09:32:47485 // Message handlers should be aware of which RenderViewHost sent the
486 // message, which is temporarily stored in message_source_.
487 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18488 bool handled = true;
489 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26490 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]724159a2010-12-30 01:11:18491 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
492 OnDidLoadResourceFromMemoryCache)
493 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
494 OnDidDisplayInsecureContent)
495 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
496 OnDidRunInsecureContent)
497 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
498 OnDocumentLoadedInFrame)
499 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26500 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
501 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25502 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26503 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21504 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20505 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
506 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
507 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16508 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45509 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10510 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20511 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
512 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
513 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
514 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29515 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50516 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50517 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
518 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55519 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
520 OnBrowserPluginMessage(message))
521 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
522 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02523 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
524 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10525#if defined(OS_ANDROID)
526 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
527 OnFindMatchRectsReply)
528 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
529 OnOpenDateTimeDialog)
530#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));
1053#endif
[email protected]583418cc2013-01-17 14:01:101054
1055#if defined(OS_ANDROID)
1056 date_time_chooser_.reset(new DateTimeChooserAndroid());
1057#endif
[email protected]d1198fd2012-08-13 22:50:191058}
1059
[email protected]7fff43e2013-05-21 20:21:101060void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1061 RemoveDestructionObserver(web_contents);
1062
[email protected]14392a52012-05-02 20:28:441063 // Clear the opener if it has been closed.
1064 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441065 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511066 return;
[email protected]14392a52012-05-02 20:28:441067 }
[email protected]ceee8cd2013-03-08 04:59:511068 // Clear a pending contents that has been closed before being shown.
1069 for (PendingContents::iterator iter = pending_contents_.begin();
1070 iter != pending_contents_.end();
1071 ++iter) {
1072 if (iter->second != web_contents)
1073 continue;
1074 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511075 return;
1076 }
1077 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441078}
1079
[email protected]7fff43e2013-05-21 20:21:101080void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1081 if (!ContainsKey(destruction_observers_, web_contents)) {
1082 destruction_observers_[web_contents] =
1083 new DestructionObserver(this, web_contents);
1084 }
1085}
1086
1087void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1088 DestructionObservers::iterator iter =
1089 destruction_observers_.find(web_contents);
1090 if (iter != destruction_observers_.end()) {
1091 delete destruction_observers_[web_contents];
1092 destruction_observers_.erase(iter);
1093 }
1094}
1095
[email protected]b172aee2012-04-10 17:05:261096void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311097 observers_.AddObserver(observer);
1098}
1099
[email protected]b172aee2012-04-10 17:05:261100void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311101 observers_.RemoveObserver(observer);
1102}
1103
[email protected]b172aee2012-04-10 17:05:261104void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341105 if (delegate_)
1106 delegate_->ActivateContents(this);
1107}
1108
[email protected]b172aee2012-04-10 17:05:261109void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121110 if (delegate_)
1111 delegate_->DeactivateContents(this);
1112}
1113
[email protected]b172aee2012-04-10 17:05:261114void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481115 if (delegate_)
1116 delegate_->LostCapture();
1117}
1118
[email protected]b24b68a2012-09-24 21:57:261119void WebContentsImpl::RenderWidgetDeleted(
1120 RenderWidgetHostImpl* render_widget_host) {
1121 if (is_being_destroyed_) {
1122 // |created_widgets_| might have been destroyed.
1123 return;
1124 }
1125
1126 std::set<RenderWidgetHostImpl*>::iterator iter =
1127 created_widgets_.find(render_widget_host);
1128 if (iter != created_widgets_.end())
1129 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541130
1131 if (render_widget_host &&
1132 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491133 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1134 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541135 FOR_EACH_OBSERVER(WebContentsObserver,
1136 observers_,
1137 DidDestroyFullscreenWidget(
1138 fullscreen_widget_routing_id_));
1139 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1140 }
[email protected]b24b68a2012-09-24 21:57:261141}
1142
[email protected]b172aee2012-04-10 17:05:261143bool WebContentsImpl::PreHandleKeyboardEvent(
1144 const NativeWebKeyboardEvent& event,
1145 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481146 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131147 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481148}
1149
[email protected]b172aee2012-04-10 17:05:261150void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061151 if (browser_plugin_embedder_ &&
1152 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1153 return;
1154 }
1155
[email protected]63954792011-07-11 04:17:481156 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131157 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481158}
1159
[email protected]fb3f066e2013-02-12 19:12:521160bool WebContentsImpl::PreHandleWheelEvent(
1161 const WebKit::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191162#if !defined(OS_MACOSX)
1163 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1164 // isn't done for two reasons:
1165 // -the OS already has a gesture to do this through pinch-zoom
1166 // -if a user starts an inertial scroll, let's go, and presses control
1167 // (i.e. control+tab) then the OS's buffered scroll events will come in
1168 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521169 if (delegate_ &&
1170 event.wheelTicksY &&
1171 (event.modifiers & WebKit::WebInputEvent::ControlKey)) {
1172 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1173 return true;
1174 }
[email protected]bccc4472013-04-18 16:37:191175#endif
[email protected]fb3f066e2013-02-12 19:12:521176
1177 return false;
1178}
1179
[email protected]c73a2282013-04-29 21:10:411180#if defined(OS_WIN) && defined(USE_AURA)
1181gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1182 return accessible_parent_;
1183}
1184#endif
1185
[email protected]b172aee2012-04-10 17:05:261186void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431187 if (delegate_)
1188 delegate_->HandleMouseDown();
1189}
1190
[email protected]b172aee2012-04-10 17:05:261191void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481192 if (delegate_)
1193 delegate_->HandleMouseUp();
1194}
1195
[email protected]590a634e2012-07-19 16:38:231196void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481197 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231198 delegate_->HandlePointerActivate();
1199}
1200
1201void WebContentsImpl::HandleGestureBegin() {
1202 if (delegate_)
1203 delegate_->HandleGestureBegin();
1204}
1205
1206void WebContentsImpl::HandleGestureEnd() {
1207 if (delegate_)
1208 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481209}
1210
[email protected]b172aee2012-04-10 17:05:261211void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491212 // This method is being called to enter or leave renderer-initiated fullscreen
1213 // mode. Either way, make sure any existing fullscreen widget is shut down
1214 // first.
1215 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1216 if (widget_view)
1217 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1218
[email protected]8a5e0ca2011-08-25 06:30:471219 if (delegate_)
1220 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1221}
1222
[email protected]b172aee2012-04-10 17:05:261223bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381224 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121225}
1226
[email protected]a9c81f02012-06-01 00:15:441227void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1228 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371229 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441230 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371231 } else {
1232 GotResponseToLockMouseRequest(false);
1233 }
1234}
1235
[email protected]b172aee2012-04-10 17:05:261236void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371237 if (delegate_)
1238 delegate_->LostMouseLock();
1239}
1240
[email protected]bafe6cd2012-05-23 23:09:501241void WebContentsImpl::CreateNewWindow(
1242 int route_id,
[email protected]227692c52013-05-31 22:43:041243 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131244 const ViewHostMsg_CreateWindow_Params& params,
1245 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501246 // We usually create the new window in the same BrowsingInstance (group of
1247 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551248 // if the opener is being suppressed (in a non-guest), we create a new
1249 // SiteInstance in its own BrowsingInstance.
1250 bool is_guest = GetRenderProcessHost()->IsGuest();
1251
[email protected]bafe6cd2012-05-23 23:09:501252 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551253 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571254 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501255 GetSiteInstance();
1256
[email protected]d1198fd2012-08-13 22:50:191257 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341258 //
1259 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301260 const std::string& partition_id =
1261 GetContentClient()->browser()->
1262 GetStoragePartitionIdForSite(GetBrowserContext(),
1263 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461264 StoragePartition* partition = BrowserContext::GetStoragePartition(
1265 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411266 DOMStorageContextWrapper* dom_storage_context =
1267 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191268 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1269 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1270 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371271
1272 if (delegate_ &&
1273 !delegate_->ShouldCreateWebContents(this,
1274 route_id,
1275 params.window_container_type,
1276 params.frame_name,
1277 params.target_url,
1278 partition_id,
1279 session_storage_namespace)) {
1280 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1281 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1282 main_frame_route_id);
1283 return;
1284 }
1285
1286 // Create the new web contents. This will automatically create the new
1287 // WebContentsView. In the future, we may want to create the view separately.
1288 WebContentsImpl* new_contents =
1289 new WebContentsImpl(GetBrowserContext(),
1290 params.opener_suppressed ? NULL : this);
1291
[email protected]d1198fd2012-08-13 22:50:191292 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301293 partition_id,
[email protected]d1198fd2012-08-13 22:50:191294 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461295 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591296 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041297 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551298 if (!is_guest) {
1299 create_params.context = view_->GetNativeView();
1300 create_params.initial_size = view_->GetContainerSize();
1301 } else {
1302 // This makes |new_contents| act as a guest.
1303 // For more info, see comment above class BrowserPluginGuest.
1304 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1305 WebContentsImpl* new_contents_impl =
1306 static_cast<WebContentsImpl*>(new_contents);
[email protected]738f57a2013-06-29 21:06:541307 BrowserPluginGuest::CreateWithOpener(instance_id, new_contents_impl,
1308 GetBrowserPluginGuest(), !!new_contents_impl->opener());
[email protected]c4538072013-03-18 02:17:551309 }
[email protected]1ac10dca2013-08-20 20:47:041310 if (params.disposition == NEW_BACKGROUND_TAB)
1311 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591312 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191313
[email protected]c4538072013-03-18 02:17:551314 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341315 // will be shown immediately).
1316 if (!params.opener_suppressed) {
1317 if (!is_guest) {
1318 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501319
[email protected]d70bea92013-04-05 04:23:341320 // TODO(brettw): It seems bogus that we have to call this function on the
1321 // newly created object and give it one of its own member variables.
1322 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1323 }
[email protected]bafe6cd2012-05-23 23:09:501324 // Save the created window associated with the route so we can show it
1325 // later.
1326 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1327 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101328 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501329 }
1330
1331 if (delegate_) {
1332 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131333 this, params.opener_frame_id, params.frame_name,
1334 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501335 }
1336
1337 if (params.opener_suppressed) {
1338 // When the opener is suppressed, the original renderer cannot access the
1339 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001340 bool was_blocked = false;
1341 if (delegate_) {
1342 gfx::Rect initial_pos;
1343 delegate_->AddNewContents(
1344 this, new_contents, params.disposition, initial_pos,
1345 params.user_gesture, &was_blocked);
1346 }
1347 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211348 OpenURLParams open_params(params.target_url,
1349 Referrer(),
1350 CURRENT_TAB,
1351 PAGE_TRANSITION_LINK,
1352 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301353 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001354 new_contents->OpenURL(open_params);
1355 }
[email protected]bafe6cd2012-05-23 23:09:501356 }
1357}
1358
1359void WebContentsImpl::CreateNewWidget(int route_id,
1360 WebKit::WebPopupType popup_type) {
1361 CreateNewWidget(route_id, false, popup_type);
1362}
1363
1364void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1365 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1366}
1367
1368void WebContentsImpl::CreateNewWidget(int route_id,
1369 bool is_fullscreen,
1370 WebKit::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211371 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501372 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041373 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261374 created_widgets_.insert(widget_host);
1375
[email protected]83918ec2013-01-10 15:37:191376 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1377 view_->CreateViewForPopupWidget(widget_host));
1378 if (!widget_view)
1379 return;
[email protected]bafe6cd2012-05-23 23:09:501380 if (!is_fullscreen) {
1381 // Popups should not get activated.
1382 widget_view->SetPopupType(popup_type);
1383 }
1384 // Save the created widget associated with the route so we can show it later.
1385 pending_widget_views_[route_id] = widget_view;
1386
1387#if defined(OS_MACOSX)
1388 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1389 // to allow it to survive the trip without being hosted.
1390 base::mac::NSObjectRetain(widget_view->GetNativeView());
1391#endif
1392}
1393
1394void WebContentsImpl::ShowCreatedWindow(int route_id,
1395 WindowOpenDisposition disposition,
1396 const gfx::Rect& initial_pos,
1397 bool user_gesture) {
1398 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001399 if (contents) {
1400 WebContentsDelegate* delegate = GetDelegate();
1401 if (delegate) {
1402 delegate->AddNewContents(
1403 this, contents, disposition, initial_pos, user_gesture, NULL);
1404 }
1405 }
[email protected]bafe6cd2012-05-23 23:09:501406}
1407
1408void WebContentsImpl::ShowCreatedWidget(int route_id,
1409 const gfx::Rect& initial_pos) {
1410 ShowCreatedWidget(route_id, false, initial_pos);
1411}
1412
1413void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1414 ShowCreatedWidget(route_id, true, gfx::Rect());
1415}
1416
1417void WebContentsImpl::ShowCreatedWidget(int route_id,
1418 bool is_fullscreen,
1419 const gfx::Rect& initial_pos) {
1420 if (delegate_)
1421 delegate_->RenderWidgetShowing();
1422
1423 RenderWidgetHostViewPort* widget_host_view =
1424 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1425 if (!widget_host_view)
1426 return;
[email protected]4aebbca2013-09-17 22:26:491427 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311428 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1429 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491430 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1431 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1432 delegate_->ToggleFullscreenModeForTab(this, true);
1433 } else {
1434 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491435 }
[email protected]4aebbca2013-09-17 22:26:491436 FOR_EACH_OBSERVER(WebContentsObserver,
1437 observers_,
1438 DidShowFullscreenWidget(route_id));
1439 if (!widget_host_view->HasFocus())
1440 widget_host_view->Focus();
1441 } else {
[email protected]f8497342013-02-05 22:15:021442 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491443 }
[email protected]89054502012-06-03 10:29:241444
1445 RenderWidgetHostImpl* render_widget_host_impl =
1446 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1447 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311448 // Only allow privileged mouse lock for fullscreen render widget, which is
1449 // used to implement Pepper Flash fullscreen.
1450 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501451
1452#if defined(OS_MACOSX)
1453 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1454 // properly embedded (or purposefully ignored) we can release the retain we
1455 // took in CreateNewWidget().
1456 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1457#endif
1458}
1459
1460WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1461 PendingContents::iterator iter = pending_contents_.find(route_id);
1462
1463 // Certain systems can block the creation of new windows. If we didn't succeed
1464 // in creating one, just return NULL.
1465 if (iter == pending_contents_.end()) {
1466 return NULL;
1467 }
1468
1469 WebContentsImpl* new_contents = iter->second;
1470 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101471 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501472
[email protected]d70bea92013-04-05 04:23:341473 // Don't initialize the guest WebContents immediately.
1474 if (new_contents->GetRenderProcessHost()->IsGuest())
1475 return new_contents;
1476
[email protected]bafe6cd2012-05-23 23:09:501477 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1478 !new_contents->GetRenderViewHost()->GetView())
1479 return NULL;
1480
1481 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1482 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1483 return new_contents;
1484}
1485
1486RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1487 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1488 if (iter == pending_widget_views_.end()) {
1489 DCHECK(false);
1490 return NULL;
1491 }
1492
1493 RenderWidgetHostView* widget_host_view = iter->second;
1494 pending_widget_views_.erase(route_id);
1495
1496 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1497 if (!widget_host->GetProcess()->HasConnection()) {
1498 // The view has gone away or the renderer crashed. Nothing to do.
1499 return NULL;
1500 }
1501
1502 return widget_host_view;
1503}
1504
[email protected]f56c7872013-06-18 12:31:571505void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501506 // Allow WebContentsDelegates to handle the context menu operation first.
1507 if (delegate_ && delegate_->HandleContextMenu(params))
1508 return;
1509
[email protected]f56c7872013-06-18 12:31:571510 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501511}
1512
[email protected]f13b4202012-06-12 23:53:231513void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091514 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211515 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231516 if (delegate_)
1517 delegate_->RequestMediaAccessPermission(this, request, callback);
1518 else
[email protected]b5f76742013-04-29 15:05:591519 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231520}
1521
[email protected]cc9200432013-07-23 23:02:401522SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1523 SiteInstance* instance) {
1524 return controller_.GetSessionStorageNamespace(instance);
1525}
1526
[email protected]9b159a52013-10-03 17:24:551527FrameTree* WebContentsImpl::GetFrameTree() {
1528 return &frame_tree_;
1529}
1530
[email protected]32deec62013-05-15 23:55:041531void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1532 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441533 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041534}
1535
[email protected]b172aee2012-04-10 17:05:261536void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231537 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331538 if (delegate_)
1539 delegate_->UpdatePreferredSize(this, pref_size);
1540}
1541
[email protected]b172aee2012-04-10 17:05:261542void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341543 if (delegate_)
1544 delegate_->ResizeDueToAutoResize(this, new_size);
1545}
1546
[email protected]b172aee2012-04-10 17:05:261547WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201548 if (!delegate_)
1549 return NULL;
[email protected]00c37fc2011-08-02 00:22:501550
[email protected]e5d549d2011-12-28 01:29:201551 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201552 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341553}
1554
[email protected]6b618e62012-08-16 12:59:181555bool WebContentsImpl::Send(IPC::Message* message) {
1556 if (!GetRenderViewHost()) {
1557 delete message;
1558 return false;
1559 }
1560
1561 return GetRenderViewHost()->Send(message);
1562}
1563
[email protected]b172aee2012-04-10 17:05:261564bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501565 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251566 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231567 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251568 reload_type);
[email protected]876bc832010-09-07 16:29:541569}
[email protected]96d185d2009-04-24 03:28:541570
[email protected]ba45bfd2012-05-22 21:51:441571void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211572 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441573 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1574 RenderViewForInterstitialPageCreated(render_view_host));
1575}
1576
[email protected]20ca0382013-02-28 19:50:071577void WebContentsImpl::AttachInterstitialPage(
1578 InterstitialPageImpl* interstitial_page) {
1579 DCHECK(interstitial_page);
1580 render_manager_.set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291581
1582 // Cancel any visible dialogs so that they don't interfere with the
1583 // interstitial.
1584 if (dialog_manager_)
1585 dialog_manager_->CancelActiveAndPendingDialogs(this);
1586
[email protected]20ca0382013-02-28 19:50:071587 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1588 DidAttachInterstitialPage());
1589}
1590
1591void WebContentsImpl::DetachInterstitialPage() {
1592 if (GetInterstitialPage())
1593 render_manager_.remove_interstitial_page();
1594 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1595 DidDetachInterstitialPage());
1596}
1597
[email protected]b172aee2012-04-10 17:05:261598bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231599 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501600 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031601 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1602
[email protected]19e81142011-10-03 16:19:401603 // The renderer will reject IPC messages with URLs longer than
1604 // this limit, so don't attempt to navigate with a longer URL.
[email protected]3adab1c2013-09-09 21:23:431605 if (entry.GetURL().spec().size() > kMaxURLChars) {
1606 LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars
1607 << " characters.";
[email protected]19e81142011-10-03 16:19:401608 return false;
[email protected]3adab1c2013-09-09 21:23:431609 }
[email protected]19e81142011-10-03 16:19:401610
[email protected]9f76c1e2012-03-05 15:15:581611 RenderViewHostImpl* dest_render_view_host =
1612 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401613 if (!dest_render_view_host)
1614 return false; // Unable to create the desired render view host.
1615
[email protected]80a8fad2011-01-29 04:02:381616 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071617 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581618 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271619 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501620 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031621 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1622 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211623 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231624 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271625 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211626 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231627 CHECK(0);
1628 }
[email protected]54ec6472010-04-09 19:39:581629
[email protected]7bb761892012-07-20 09:32:471630 // Notify observers that we will navigate in this RV.
1631 FOR_EACH_OBSERVER(WebContentsObserver,
1632 observers_,
1633 AboutToNavigateRenderView(dest_render_view_host));
1634
[email protected]96d185d2009-04-24 03:28:541635 // Used for page load time metrics.
1636 current_load_start_ = base::TimeTicks::Now();
1637
1638 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341639 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271640 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471641 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341642 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541643
[email protected]36fc0392011-12-25 03:59:511644 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541645 // HACK!! This code suppresses javascript: URLs from being added to
1646 // session history, which is what we want to do for javascript: URLs that
1647 // do not generate content. What we really need is a message from the
1648 // renderer telling us that a new page was not created. The same message
1649 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351650 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541651 return false;
1652 }
1653
[email protected]3c9e1872010-11-18 16:17:491654 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251655 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041656 observers_,
[email protected]36fc0392011-12-25 03:59:511657 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541658
[email protected]09b29342011-06-24 19:18:481659 if (delegate_)
1660 delegate_->DidNavigateToPendingEntry(this);
1661
[email protected]d5f942ba2008-09-26 19:30:341662 return true;
1663}
1664
[email protected]b172aee2012-04-10 17:05:261665void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331666 const SiteInstance* site_instance,
1667 int history_length,
1668 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411669 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1670 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191671 if (render_manager_.pending_render_view_host()) {
1672 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141673 return;
[email protected]9e1ad4b2011-08-14 16:49:191674 }
[email protected]9f76c1e2012-03-05 15:15:581675 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191676 if (!rvh) {
1677 NOTREACHED();
1678 return;
1679 }
[email protected]9f76c1e2012-03-05 15:15:581680 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191681 NOTREACHED();
1682 return;
1683 }
[email protected]6b618e62012-08-16 12:59:181684 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1685 history_length,
1686 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271690 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541691 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1692 return;
1693 }
[email protected]9f76c1e2012-03-05 15:15:581694 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541695}
1696
[email protected]b172aee2012-04-10 17:05:261697bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271698 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541699}
1700
[email protected]b172aee2012-04-10 17:05:261701InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271702 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221703}
1704
[email protected]b172aee2012-04-10 17:05:261705bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161706 // WebKit creates Document object when MIME type is application/xhtml+xml,
1707 // so we also support this MIME type.
1708 return contents_mime_type_ == "text/html" ||
1709 contents_mime_type_ == "text/xml" ||
1710 contents_mime_type_ == "application/xhtml+xml" ||
1711 contents_mime_type_ == "text/plain" ||
1712 contents_mime_type_ == "text/css" ||
1713 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1714}
1715
[email protected]b172aee2012-04-10 17:05:261716void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591717 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161718 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551719 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011720 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141721 return;
[email protected]c7dd2f62011-07-18 15:57:591722 }
1723
1724 Stop();
1725
1726 // Create the save package and possibly prompt the user for the name to save
1727 // the page as. The user prompt is an asynchronous operation that runs on
1728 // another thread.
1729 save_package_ = new SavePackage(this);
1730 save_package_->GetSaveInfo();
1731}
1732
1733// Used in automated testing to bypass prompting the user for file names.
1734// Instead, the names and paths are hard coded rather than running them through
1735// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341736bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1737 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211738 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591739 // Stop the page from navigating.
1740 Stop();
1741
1742 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211743 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591744}
1745
[email protected]3c71576ce2013-07-23 02:00:011746void WebContentsImpl::SaveFrame(const GURL& url,
1747 const Referrer& referrer) {
1748 if (!GetURL().is_valid())
1749 return;
1750 bool is_main_frame = (url == GetURL());
1751
1752 DownloadManager* dlm =
1753 BrowserContext::GetDownloadManager(GetBrowserContext());
1754 if (!dlm)
1755 return;
1756 int64 post_id = -1;
1757 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271758 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011759 if (entry)
1760 post_id = entry->GetPostID();
1761 }
1762 scoped_ptr<DownloadUrlParameters> params(
1763 DownloadUrlParameters::FromWebContents(this, url));
1764 params->set_referrer(referrer);
1765 params->set_post_id(post_id);
1766 params->set_prefer_cache(true);
1767 if (post_id >= 0)
1768 params->set_method("POST");
1769 params->set_prompt(true);
1770 dlm->DownloadUrl(params.Pass());
1771}
1772
[email protected]b172aee2012-04-10 17:05:261773void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341774 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481775 const base::Callback<void(int64)>& callback) {
1776 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121777}
1778
[email protected]6286a372013-10-09 04:03:271779// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261780bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271781 NavigationEntryImpl* visible_entry =
1782 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1783 return (visible_entry != NULL &&
1784 visible_entry->site_instance() == GetSiteInstance() &&
1785 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321786}
1787
[email protected]b172aee2012-04-10 17:05:261788const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271789 return contents_mime_type_;
1790}
1791
[email protected]b172aee2012-04-10 17:05:261792bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271793 return notify_disconnection_;
1794}
1795
[email protected]b172aee2012-04-10 17:05:261796void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311797 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181798 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161799}
1800
[email protected]b172aee2012-04-10 17:05:261801void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311802 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181803 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161804}
1805
[email protected]8ff00d72012-10-23 19:12:211806RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271807 return &renderer_preferences_;
1808}
1809
[email protected]e35ccd52012-05-23 16:22:471810void WebContentsImpl::Close() {
1811 Close(GetRenderViewHost());
1812}
1813
[email protected]cf200a562013-05-03 16:24:291814void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
1815 int screen_x, int screen_y, WebKit::WebDragOperation operation) {
1816 if (browser_plugin_embedder_.get())
1817 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1818 screen_x, screen_y, operation);
1819 if (GetRenderViewHost())
1820 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1821 screen_x, screen_y, operation);
1822}
1823
1824void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1825 int screen_x, int screen_y) {
1826 if (browser_plugin_embedder_.get())
1827 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1828 screen_x, screen_y);
1829 if (GetRenderViewHost())
1830 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1831 screen_x, screen_y);
1832}
1833
[email protected]b172aee2012-04-10 17:05:261834void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521835 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581836 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511837 if (delegate_)
1838 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291839 if (browser_plugin_embedder_.get())
1840 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341841}
1842
[email protected]e35ccd52012-05-23 16:22:471843void WebContentsImpl::UserGestureDone() {
1844 OnUserGesture();
1845}
1846
[email protected]b172aee2012-04-10 17:05:261847void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271848 closed_by_user_gesture_ = value;
1849}
1850
[email protected]b172aee2012-04-10 17:05:261851bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271852 return closed_by_user_gesture_;
1853}
1854
[email protected]b172aee2012-04-10 17:05:261855double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051856 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561857 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251858 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171859 return 0;
[email protected]b75b8292010-10-01 07:28:251860
1861 double zoom_level;
1862 if (temporary_zoom_settings_) {
1863 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581864 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251865 } else {
[email protected]2ae88d12011-10-14 09:11:191866 GURL url;
[email protected]6286a372013-10-09 04:03:271867 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191868 // Since zoom map is updated using rewritten URL, use rewritten URL
1869 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271870 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021871 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1872 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251873 }
[email protected]d0b8d092010-10-25 04:05:171874 return zoom_level;
1875}
[email protected]b75b8292010-10-01 07:28:251876
[email protected]b172aee2012-04-10 17:05:261877int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591878 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171879 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011880 // Calculate the zoom percent from the factor. Round up to the nearest whole
1881 // number.
[email protected]b75b8292010-10-01 07:28:251882 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491883 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251884 *enable_decrement = percent > minimum_zoom_percent_;
1885 *enable_increment = percent < maximum_zoom_percent_;
1886 return percent;
1887}
1888
[email protected]b172aee2012-04-10 17:05:261889void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501890 if (!delegate_)
1891 return;
1892
[email protected]6286a372013-10-09 04:03:271893 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1894 if (!entry)
[email protected]1788e772010-12-15 16:40:501895 return;
1896
[email protected]6286a372013-10-09 04:03:271897 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121898}
1899
[email protected]b172aee2012-04-10 17:05:261900void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041901 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271902 if (!delegate_)
1903 return;
1904
[email protected]691aa2f2013-05-28 22:52:041905 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271906}
1907
[email protected]b172aee2012-04-10 17:05:261908int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271909 return minimum_zoom_percent_;
1910}
1911
[email protected]b172aee2012-04-10 17:05:261912int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271913 return maximum_zoom_percent_;
1914}
1915
[email protected]b172aee2012-04-10 17:05:261916gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231917 return preferred_size_;
1918}
1919
[email protected]b172aee2012-04-10 17:05:261920bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271921 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581922 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271923}
1924
[email protected]b172aee2012-04-10 17:05:261925bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441926 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501927}
1928
[email protected]cb805452013-05-22 15:16:211929void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181930 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211931 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201932}
1933
[email protected]cb805452013-05-22 15:16:211934void WebContentsImpl::DidEndColorChooser() {
1935 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1936 color_chooser_identifier_));
1937 color_chooser_.reset();
1938 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201939}
1940
[email protected]41225fe2013-03-29 05:32:021941int WebContentsImpl::DownloadImage(const GURL& url,
1942 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301943 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021944 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391945 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301946 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021947 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391948 return id;
1949}
1950
[email protected]b172aee2012-04-10 17:05:261951bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:271952 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:201953 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:331954 return true;
1955 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:271956}
1957
[email protected]b172aee2012-04-10 17:05:261958void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271959 if (delegate_)
1960 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211961}
1962
[email protected]54047eb52012-05-08 21:45:571963void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:211964 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:571965 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:131966 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:571967 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:571968 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:211969 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]081dc522013-05-15 04:59:201970 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:181971 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:211972 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:571973 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:081974 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:181975
[email protected]442385d2013-08-09 02:38:411976 if (is_main_frame) {
[email protected]d974a0a2013-01-10 01:43:571977 DidChangeLoadProgress(0);
1978
[email protected]442385d2013-08-09 02:38:411979 // If there is no browser-initiated pending entry for this navigation and it
1980 // is not for the error URL, create a pending entry using the current
1981 // SiteInstance, and ensure the address bar updates accordingly. We don't
1982 // know the referrer or extra headers at this point, but the referrer will
1983 // be set properly upon commit.
[email protected]97d8f0d2013-10-29 16:49:211984 NavigationEntryImpl* pending_entry =
1985 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
[email protected]442385d2013-08-09 02:38:411986 bool has_browser_initiated_pending_entry = pending_entry &&
[email protected]97d8f0d2013-10-29 16:49:211987 !pending_entry->is_renderer_initiated();
[email protected]442385d2013-08-09 02:38:411988 if (!has_browser_initiated_pending_entry && !is_error_page) {
1989 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
1990 controller_.CreateNavigationEntry(validated_url,
1991 content::Referrer(),
1992 content::PAGE_TRANSITION_LINK,
1993 true /* is_renderer_initiated */,
1994 std::string(),
1995 GetBrowserContext()));
1996 entry->set_site_instance(
1997 static_cast<SiteInstanceImpl*>(GetSiteInstance()));
[email protected]3ed682bf2013-10-17 20:56:561998 // TODO(creis): If there's a pending entry already, find a safe way to
1999 // update it instead of replacing it and copying over things like this.
[email protected]97d8f0d2013-10-29 16:49:212000 if (pending_entry) {
2001 entry->set_transferred_global_request_id(
2002 pending_entry->transferred_global_request_id());
2003 entry->set_should_replace_entry(pending_entry->should_replace_entry());
[email protected]f8872902013-10-30 03:18:572004 entry->set_redirect_chain(pending_entry->redirect_chain());
[email protected]3ed682bf2013-10-17 20:56:562005 }
[email protected]442385d2013-08-09 02:38:412006 controller_.SetPendingEntry(entry);
2007 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
2008 }
[email protected]59167c22013-06-03 18:07:322009 }
2010
[email protected]0d60f0192011-04-14 12:40:102011 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252012 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132013 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2014 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322015 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542016
2017 if (is_main_frame) {
2018 // Notify observers about the provisional change in the main frame URL.
2019 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2020 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542021 render_view_host));
2022 }
2023}
2024
2025void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212026 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542027 int32 page_id,
[email protected]400992b2012-06-14 00:03:542028 const GURL& source_url,
2029 const GURL& target_url) {
2030 // TODO(creis): Remove this method and have the pre-rendering code listen to
[email protected]b0f724c2013-09-05 04:21:132031 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
2032 // See http://crbug.com/78512.
[email protected]400992b2012-06-14 00:03:542033 GURL validated_source_url(source_url);
2034 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212035 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542036 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082037 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2038 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542039 NavigationEntry* entry;
2040 if (page_id == -1) {
2041 entry = controller_.GetPendingEntry();
2042 } else {
2043 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2044 page_id);
2045 }
2046 if (!entry || entry->GetURL() != validated_source_url)
2047 return;
2048
2049 // Notify observers about the provisional change in the main frame URL.
2050 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2051 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542052 render_view_host));
[email protected]724159a2010-12-30 01:11:182053}
2054
[email protected]54047eb52012-05-08 21:45:572055void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212056 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582057 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2058 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2059 << ", error_code: " << params.error_code
2060 << ", error_description: " << params.error_description
2061 << ", is_main_frame: " << params.is_main_frame
2062 << ", showing_repost_interstitial: " <<
2063 params.showing_repost_interstitial
2064 << ", frame_id: " << params.frame_id;
2065 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212066 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572067 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082068 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182069
[email protected]d7b175e2011-10-11 15:31:582070 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182071 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2072 // This means that the interstitial won't be torn down properly, which is
2073 // bad. But if we have an interstitial, go back to another tab type, and
2074 // then load the same interstitial again, we could end up getting the first
2075 // interstitial's "failed" message (as a result of the cancel) when we're on
2076 // the second one.
2077 //
2078 // We can't tell this apart, so we think we're tearing down the current page
2079 // which will cause a crash later one. There is also some code in
2080 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2081 // out because of this problem.
2082 //
2083 // http://code.google.com/p/chromium/issues/detail?id=2855
2084 // Because this will not tear down the interstitial properly, if "back" is
2085 // back to another tab type, the interstitial will still be somewhat alive
2086 // in the previous tab type. If you navigate somewhere that activates the
2087 // tab with the interstitial again, you'll see a flash before the new load
2088 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272089 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182090 LOG(WARNING) << "Discarding message during interstitial.";
2091 return;
2092 }
2093
[email protected]54047eb52012-05-08 21:45:572094 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182095 }
2096
[email protected]b12eb222013-09-10 00:11:482097 // Do not usually clear the pending entry if one exists, so that the user's
2098 // typed URL is not lost when a navigation fails or is aborted. However, in
2099 // cases that we don't show the pending entry (e.g., renderer-initiated
2100 // navigations in an existing tab), we don't keep it around. That prevents
2101 // spoofs on in-page navigations that don't go through
2102 // DidStartProvisionalLoadForFrame.
2103 // In general, we allow the view to clear the pending entry and typed URL if
2104 // the user requests (e.g., hitting Escape with focus in the address bar).
2105 // Note: don't touch the transient entry, since an interstitial may exist.
2106 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry())
2107 controller_.DiscardPendingEntry();
2108
[email protected]d8c660432011-12-22 20:51:252109 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582110 observers_,
2111 DidFailProvisionalLoad(params.frame_id,
[email protected]2f673064c2013-10-22 04:01:442112 params.frame_unique_name,
[email protected]d7b175e2011-10-11 15:31:582113 params.is_main_frame,
2114 validated_url,
2115 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462116 params.error_description,
2117 render_view_host));
[email protected]724159a2010-12-30 01:11:182118}
2119
[email protected]b172aee2012-04-10 17:05:262120void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182121 const GURL& url,
[email protected]70435962011-08-02 20:13:282122 const std::string& security_info,
2123 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182124 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282125 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192126 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182127 cache.Increment();
2128
2129 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082130 int cert_id = 0;
2131 net::CertStatus cert_status = 0;
2132 int security_bits = -1;
2133 int connection_status = 0;
[email protected]8ff00d72012-10-23 19:12:212134 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
2135 &security_bits, &connection_status);
2136 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002137 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2138 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182139
[email protected]b0f724c2013-09-05 04:21:132140 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2141
2142 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2143 DidLoadResourceFromMemoryCache(details));
2144
[email protected]8bfc8272013-09-09 20:10:532145 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2146 scoped_refptr<net::URLRequestContextGetter> request_context(
2147 resource_type == ResourceType::MEDIA ?
2148 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2149 GetRenderProcessHost()->GetID()) :
2150 GetBrowserContext()->GetRequestContextForRenderProcess(
2151 GetRenderProcessHost()->GetID()));
2152 BrowserThread::PostTask(
2153 BrowserThread::IO,
2154 FROM_HERE,
2155 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2156 }
[email protected]724159a2010-12-30 01:11:182157}
2158
[email protected]b172aee2012-04-10 17:05:262159void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212160 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182161 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192162 SSLManager::NotifySSLInternalStateChanged(
2163 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182164}
2165
[email protected]b172aee2012-04-10 17:05:262166void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022167 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:232168 LOG(INFO) << security_origin << " ran insecure content from "
2169 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212170 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412171 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212172 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182173 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412174 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192175 SSLManager::NotifySSLInternalStateChanged(
2176 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182177}
2178
[email protected]b172aee2012-04-10 17:05:262179void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]d8c660432011-12-22 20:51:252180 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472181 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182182}
2183
[email protected]b172aee2012-04-10 17:05:262184void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312185 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062186 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312187 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062188 GURL validated_url(url);
2189 RenderProcessHost* render_process_host = message_source_->GetProcess();
2190 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252191 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472192 DidFinishLoad(frame_id, validated_url, is_main_frame,
2193 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312194}
2195
[email protected]b172aee2012-04-10 17:05:262196void WebContentsImpl::OnDidFailLoadWithError(
2197 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062198 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262199 bool is_main_frame,
2200 int error_code,
2201 const string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062202 GURL validated_url(url);
2203 RenderProcessHost* render_process_host = message_source_->GetProcess();
2204 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252205 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312206 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472207 error_code, error_description,
2208 message_source_));
[email protected]724159a2010-12-30 01:11:182209}
2210
[email protected]b172aee2012-04-10 17:05:262211void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262212 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232213 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252214 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262215 if (!entry)
2216 return;
2217 // Note that we don't call NavigationController::GotToOffset() as we don't
2218 // want to create a pending navigation entry (it might end up lingering
2219 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252220 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212221 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512222 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212223 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472224 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572225
2226 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2227 // it in now that we know. This allows us to find the entry when it commits.
2228 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232229 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332230 entry->set_site_instance(
2231 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572232 }
[email protected]216813952011-05-19 22:21:262233 }
2234}
2235
[email protected]b172aee2012-04-10 17:05:262236void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2237 int maximum_percent,
2238 bool remember) {
[email protected]216813952011-05-19 22:21:262239 minimum_zoom_percent_ = minimum_percent;
2240 maximum_zoom_percent_ = maximum_percent;
2241 temporary_zoom_settings_ = !remember;
2242}
2243
[email protected]b172aee2012-04-10 17:05:262244void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342245 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432246 if (!delegate_)
2247 return;
2248
[email protected]b9535422012-02-09 01:47:592249 ChildProcessSecurityPolicyImpl* policy =
2250 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222251 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592252 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212253}
2254
[email protected]b172aee2012-04-10 17:05:262255void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432256 if (delegate_)
2257 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202258}
2259
[email protected]b172aee2012-04-10 17:05:262260void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2261 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362262 const string16& title,
2263 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432264 if (!delegate_)
2265 return;
2266
[email protected]b9535422012-02-09 01:47:592267 ChildProcessSecurityPolicyImpl* policy =
2268 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322269 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592270 return;
[email protected]8f810632013-06-06 22:33:322271
[email protected]3a3b75a2012-06-01 08:38:362272 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202273}
2274
[email protected]b172aee2012-04-10 17:05:262275void WebContentsImpl::OnFindReply(int request_id,
2276 int number_of_matches,
2277 const gfx::Rect& selection_rect,
2278 int active_match_ordinal,
2279 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432280 if (delegate_) {
2281 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2282 active_match_ordinal, final_update);
2283 }
[email protected]b888919c2011-09-02 00:32:162284}
2285
[email protected]59363fc92012-09-05 03:46:312286#if defined(OS_ANDROID)
2287void WebContentsImpl::OnFindMatchRectsReply(
2288 int version,
2289 const std::vector<gfx::RectF>& rects,
2290 const gfx::RectF& active_rect) {
2291 if (delegate_)
2292 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2293}
[email protected]583418cc2013-01-17 14:01:102294
[email protected]1ff427972013-02-07 21:14:072295void WebContentsImpl::OnOpenDateTimeDialog(
2296 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092297 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2298 GetRenderViewHost(),
2299 value.dialog_type,
2300 value.year,
2301 value.month,
2302 value.day,
2303 value.hour,
2304 value.minute,
2305 value.second,
2306 value.milli,
2307 value.week,
2308 value.minimum,
2309 value.maximum,
2310 value.step);
[email protected]583418cc2013-01-17 14:01:102311}
2312
[email protected]59363fc92012-09-05 03:46:312313#endif
2314
[email protected]2dec8ec2013-02-07 19:20:342315void WebContentsImpl::OnCrashedPlugin(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422316 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442317 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422318 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452319}
2320
[email protected]b172aee2012-04-10 17:05:262321void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2322 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102323 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252324 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102325 AppCacheAccessed(manifest_url, blocked_by_policy));
2326}
2327
[email protected]b172aee2012-04-10 17:05:262328void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322329 SkColor color) {
[email protected]cb805452013-05-22 15:16:212330 ColorChooser* new_color_chooser = delegate_->OpenColorChooser(this, color);
2331 if (color_chooser_ == new_color_chooser)
2332 return;
2333 color_chooser_.reset(new_color_chooser);
2334 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202335}
2336
[email protected]b172aee2012-04-10 17:05:262337void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202338 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212339 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202340 color_chooser_->End();
2341}
2342
[email protected]b172aee2012-04-10 17:05:262343void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322344 SkColor color) {
[email protected]da8543762012-03-20 08:52:202345 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212346 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202347 color_chooser_->SetSelectedColor(color);
2348}
2349
[email protected]9f2a9d72012-04-16 16:02:222350void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
[email protected]2dec8ec2013-02-07 19:20:342351 const base::FilePath& path,
[email protected]9f2a9d72012-04-16 16:02:222352 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552353 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2354
[email protected]3fc07c52012-04-20 00:27:442355 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2356 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292357}
2358
[email protected]d0759f492012-04-19 22:50:502359// This exists for render views that don't have a WebUI, but do have WebUI
2360// bindings enabled.
2361void WebContentsImpl::OnWebUISend(const GURL& source_url,
2362 const std::string& name,
2363 const base::ListValue& args) {
2364 if (delegate_)
2365 delegate_->WebUISend(this, source_url, name, args);
2366}
2367
[email protected]d8415ad92012-08-23 14:40:502368void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442369 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502370 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342371 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162372 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442373 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162374 return;
[email protected]d8415ad92012-08-23 14:40:502375 }
2376
[email protected]8c8fc292012-11-23 18:57:162377 if (!delegate_->RequestPpapiBrokerPermission(
2378 this, url, plugin_path,
2379 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442380 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162381 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442382 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162383 }
[email protected]d8415ad92012-08-23 14:40:502384}
2385
[email protected]ea0309c2013-08-06 19:35:442386void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502387 bool result) {
[email protected]ea0309c2013-08-06 19:35:442388 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502389}
2390
[email protected]c4538072013-03-18 02:17:552391void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372392 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082393 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552394 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392395 // For more info, see comment above classes BrowserPluginEmbedder and
2396 // BrowserPluginGuest.
2397 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142398 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082399 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372400}
2401
[email protected]41225fe2013-03-29 05:32:022402void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392403 int id,
[email protected]749fadd2013-05-15 08:37:482404 int http_status_code,
[email protected]795c28972012-12-06 06:13:392405 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302406 const std::vector<SkBitmap>& bitmaps,
2407 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022408 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2409 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392410 // Currently WebContents notifies us of ANY downloads so that it is
2411 // possible to get here.
2412 return;
2413 }
2414 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302415 iter->second.Run(
2416 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392417 }
[email protected]41225fe2013-03-29 05:32:022418 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392419}
2420
2421void WebContentsImpl::OnUpdateFaviconURL(
2422 int32 page_id,
2423 const std::vector<FaviconURL>& candidates) {
2424 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2425 DidUpdateFaviconURL(page_id, candidates));
2426}
2427
[email protected]d9030b82013-07-19 08:26:062428void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2429 bool has_video,
2430 bool has_audio,
2431 bool is_playing) {
2432 // Chrome OS does its own detection of audio and video.
2433#if !defined(OS_CHROMEOS)
2434 if (is_playing) {
2435 scoped_ptr<PowerSaveBlocker> blocker;
2436 if (has_video) {
2437 blocker = PowerSaveBlocker::Create(
2438 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2439 "Playing video");
2440#if defined(OS_ANDROID)
2441 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382442 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062443#endif
2444 } else if (has_audio) {
2445 blocker = PowerSaveBlocker::Create(
2446 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2447 "Playing audio");
2448 }
2449
2450 if (blocker)
2451 power_save_blockers_[message_source_][player_cookie] = blocker.release();
2452 } else {
2453 delete power_save_blockers_[message_source_][player_cookie];
2454 power_save_blockers_[message_source_].erase(player_cookie);
2455 }
2456#endif // !defined(OS_CHROMEOS)
2457}
2458
2459
[email protected]e67ebf32013-02-13 11:07:192460void WebContentsImpl::DidChangeVisibleSSLState() {
2461 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2462 DidChangeVisibleSSLState());
2463}
2464
[email protected]17e286e2013-03-01 23:29:392465void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2466 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2467 BeforeFormRepostWarningShow());
2468}
2469
[email protected]ec6c05f2013-10-23 18:41:572470
2471void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2472 Activate();
2473 if (delegate_)
2474 delegate_->ShowRepostFormWarningDialog(this);
2475}
2476
[email protected]96d185d2009-04-24 03:28:542477// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592478// loading, or done loading.
2479void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2480 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262481 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542482 if (is_loading == is_loading_)
2483 return;
2484
2485 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212486 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542487 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562488 upload_size_ = 0;
2489 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542490 }
2491
2492 render_manager_.SetIsLoading(is_loading);
2493
2494 is_loading_ = is_loading;
2495 waiting_for_response_ = is_loading;
2496
[email protected]6ebdc9b2010-09-27 16:55:572497 if (delegate_)
2498 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212499 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542500
[email protected]91621872013-10-08 04:04:592501 if (is_loading) {
[email protected]fae7b5682013-03-15 11:49:432502 TRACE_EVENT_ASYNC_BEGIN0("browser", "WebContentsImpl Loading", this);
[email protected]91621872013-10-08 04:04:592503 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2504 DidStartLoading(render_view_host));
2505 } else {
[email protected]fae7b5682013-03-15 11:49:432506 TRACE_EVENT_ASYNC_END0("browser", "WebContentsImpl Loading", this);
[email protected]91621872013-10-08 04:04:592507 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2508 DidStopLoading(render_view_host));
2509 }
[email protected]66798902013-10-01 18:40:162510
2511 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212512 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2513 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542514 if (details)
[email protected]8ff00d72012-10-23 19:12:212515 det = Details<LoadNotificationDetails>(details);
2516 NotificationService::current()->Notify(
2517 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542518}
2519
[email protected]b172aee2012-04-10 17:05:262520void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212521 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322522 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562523 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322524 // Clear the status bubble. This is a workaround for a bug where WebKit
2525 // doesn't let us know that the cursor left an element during a
2526 // transition (this is also why the mouse cursor remains as a hand after
2527 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2528 // clear the bubble when a user navigates to a named anchor in the same
2529 // page.
[email protected]36fc0392011-12-25 03:59:512530 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322531 }
2532
[email protected]a6e82fc2010-02-24 22:28:142533 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472534 // Once the main frame is navigated, we're no longer considered to have
2535 // displayed insecure content.
2536 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352537 SSLManager::NotifySSLInternalStateChanged(
2538 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172539 }
[email protected]ce5c4502009-05-06 16:46:112540
[email protected]3c9e1872010-11-18 16:17:492541 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252542 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042543 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322544}
2545
[email protected]b172aee2012-04-10 17:05:262546void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322547 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212548 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322549 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112550 // If we navigate off the page, close all JavaScript dialogs.
2551 if (dialog_manager_ && !details.is_in_page)
2552 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322553
[email protected]3c9e1872010-11-18 16:17:492554 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252555 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042556 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322557}
2558
[email protected]2f7b3c5a2013-06-21 04:59:252559bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292560 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2561 // still be used for a normal web site.
2562 if (url == GURL(kAboutBlankURL))
2563 return false;
2564
2565 // The embedder will then have the opportunity to determine if the URL
2566 // should "use up" the SiteInstance.
2567 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252568}
2569
[email protected]b172aee2012-04-10 17:05:262570void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462571 // If we are creating a RVH for a restored controller, then we need to make
2572 // sure the RenderView starts with a next_page_id_ larger than the number
2573 // of restored entries. This must be called before the RenderView starts
2574 // navigating (to avoid a race between the browser updating max_page_id and
2575 // the renderer updating next_page_id_). Because of this, we only call this
2576 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562577 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582578 if (max_restored_page_id >
2579 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2580 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2581 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322582}
2583
[email protected]b172aee2012-04-10 17:05:262584bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2585 const string16& title) {
[email protected]420ae012009-04-24 05:16:322586 // For file URLs without a title, use the pathname instead. In the case of a
2587 // synthesized title, we don't want the update to count toward the "one set
2588 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512589 string16 final_title;
[email protected]420ae012009-04-24 05:16:322590 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512591 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2592 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322593 explicit_set = false; // Don't count synthetic titles toward the set limit.
2594 } else {
[email protected]acafd272011-07-26 17:35:572595 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322596 explicit_set = true;
2597 }
2598
[email protected]987fc3a2011-05-26 14:18:092599 // If a page is created via window.open and never navigated,
2600 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552601 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092602 if (entry) {
[email protected]36fc0392011-12-25 03:59:512603 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092604 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322605
[email protected]36fc0392011-12-25 03:59:512606 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092607 } else {
2608 if (page_title_when_no_navigation_entry_ == final_title)
2609 return false; // Nothing changed, don't bother.
2610
2611 page_title_when_no_navigation_entry_ = final_title;
2612 }
[email protected]420ae012009-04-24 05:16:322613
[email protected]420ae012009-04-24 05:16:322614 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232615 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322616
[email protected]66798902013-10-01 18:40:162617 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532618 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162619
2620 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212621 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462622 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212623 NotificationService::current()->Notify(
2624 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2625 Source<WebContents>(this),
2626 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042627
[email protected]420ae012009-04-24 05:16:322628 return true;
2629}
2630
[email protected]7b712ee22013-10-03 00:57:282631void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2632 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322633 // After sending out a swap notification, we need to send a disconnect
2634 // notification so that clients that pick up a pointer to |this| can NULL the
2635 // pointer. See Bug 1230284.
2636 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112637 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282638 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112639
2640 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282641 std::pair<RenderViewHost*, RenderViewHost*> details =
2642 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212643 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282644 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212645 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282646 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392647
2648 // Ensure that the associated embedder gets cleared after a RenderViewHost
2649 // gets swapped, so we don't reuse the same embedder next time a
2650 // RenderViewHost is attached to this WebContents.
2651 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322652}
2653
[email protected]da7a7182013-09-06 08:11:112654// TODO(avi): Remove this entire function because this notification is already
2655// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262656void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322657 if (!notify_disconnection_)
2658 return;
2659
2660 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212661 NotificationService::current()->Notify(
2662 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2663 Source<WebContents>(this),
2664 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322665}
2666
[email protected]cbb1ef592013-06-05 19:49:462667void WebContentsImpl::NotifyNavigationEntryCommitted(
2668 const LoadCommittedDetails& load_details) {
2669 FOR_EACH_OBSERVER(
2670 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2671}
2672
[email protected]5a3bdf52012-05-24 15:12:572673RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2674 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322675}
2676
[email protected]8d3347f2009-07-09 22:00:212677RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262678WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212679 return &render_manager_;
2680}
2681
[email protected]8ff00d72012-10-23 19:12:212682RendererPreferences WebContentsImpl::GetRendererPrefs(
2683 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462684 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512685}
2686
[email protected]b172aee2012-04-10 17:05:262687WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172688 return this;
2689}
2690
[email protected]b172aee2012-04-10 17:05:262691gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172692 if (delegate_)
2693 return delegate_->GetRootWindowResizerRect();
2694 return gfx::Rect();
2695}
2696
[email protected]7a846df2012-09-20 19:17:392697void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272698 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392699 browser_plugin_embedder_.reset();
2700}
2701
[email protected]b172aee2012-04-10 17:05:262702void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442703 // Don't send notifications if we are just creating a swapped-out RVH for
2704 // the opener chain. These won't be used for view-source or WebUI, so it's
2705 // ok to return early.
2706 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2707 return;
2708
[email protected]86f98a22013-03-20 14:35:002709 if (delegate_)
2710 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082711
[email protected]8ff00d72012-10-23 19:12:212712 NotificationService::current()->Notify(
2713 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2714 Source<WebContents>(this),
2715 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322716
2717 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352718 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562719 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582720 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322721
[email protected]6286a372013-10-09 04:03:272722 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332723 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322724 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182725 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582726 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322727 }
[email protected]0666aef2009-05-13 19:48:082728
[email protected]60780f412013-02-25 16:34:102729 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262730
2731 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252732 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322733}
2734
[email protected]b172aee2012-04-10 17:05:262735void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522736 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322737 // Don't notify the world, since this came from a renderer in the
2738 // background.
2739 return;
2740 }
2741
[email protected]da7a7182013-09-06 08:11:112742 notify_disconnection_ = true;
2743 // TODO(avi): Remove. http://crbug.com/170921
2744 NotificationService::current()->Notify(
2745 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2746 Source<WebContents>(this),
2747 NotificationService::NoDetails());
2748
[email protected]be1f56ab2011-12-22 06:55:312749 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232750 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302751
2752 // Restore the focus to the tab (otherwise the focus will be on the top
2753 // window).
[email protected]484ae5912010-09-29 19:16:142754 if (was_crashed && !FocusLocationBarByDefault() &&
2755 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062756 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142757 }
[email protected]32ded2212011-11-10 18:51:432758
[email protected]d8c660432011-12-22 20:51:252759 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322760}
2761
[email protected]ec6a7eb2013-04-22 17:34:222762void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2763 base::TerminationStatus status,
2764 int error_code) {
[email protected]151a63d2011-12-20 22:32:522765 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322766 // The pending page's RenderViewHost is gone.
2767 return;
2768 }
2769
[email protected]d9030b82013-07-19 08:26:062770 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592771 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322772 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232773 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312774 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322775
[email protected]d8c660432011-12-22 20:51:252776 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272777 observers_,
[email protected]58d5cfe2013-07-10 02:40:522778 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322779}
2780
[email protected]b172aee2012-04-10 17:05:262781void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062782 ClearPowerSaveBlockers(rvh);
[email protected]fb7b79f72009-11-06 18:00:482783 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252784 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062785}
2786
[email protected]b0f724c2013-09-05 04:21:132787void WebContentsImpl::DidGetResourceResponseStart(
2788 const ResourceRequestDetails& details) {
2789 controller_.ssl_manager()->DidStartResourceResponse(details);
2790
2791 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2792 DidGetResourceResponseStart(details));
2793
2794 // TODO(avi): Remove. http://crbug.com/170921
2795 NotificationService::current()->Notify(
2796 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2797 Source<WebContents>(this),
2798 Details<const ResourceRequestDetails>(&details));
2799}
2800
2801void WebContentsImpl::DidGetRedirectForResourceRequest(
2802 const ResourceRedirectDetails& details) {
2803 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2804
2805 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2806 DidGetRedirectForResourceRequest(details));
2807
2808 // TODO(avi): Remove. http://crbug.com/170921
2809 NotificationService::current()->Notify(
2810 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2811 Source<WebContents>(this),
2812 Details<const ResourceRedirectDetails>(&details));
2813}
2814
[email protected]b172aee2012-04-10 17:05:262815void WebContentsImpl::DidNavigate(
2816 RenderViewHost* rvh,
2817 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]9b159a52013-10-03 17:24:552818 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2819 // First navigation should be a main frame navigation.
[email protected]50904452013-05-09 02:05:122820 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552821 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122822 }
2823
[email protected]e3d92a7f2013-01-10 02:35:052824 if (PageTransitionIsMainFrame(params.transition)) {
2825 // When overscroll navigation gesture is enabled, a screenshot of the page
2826 // in its current state is taken so that it can be used during the
2827 // nav-gesture. It is necessary to take the screenshot here, before calling
2828 // RenderViewHostManager::DidNavigateMainFrame, because that can change
2829 // WebContents::GetRenderViewHost to return the new host, instead of the one
2830 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482831 if (delegate_ && delegate_->CanOverscrollContent())
2832 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052833
[email protected]420ae012009-04-24 05:16:322834 render_manager_.DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052835 }
[email protected]8030f012009-09-25 18:09:372836
[email protected]434f69f2012-02-06 21:56:522837 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252838 // assigning a site is not necessary for this URL. In that case, the
2839 // SiteInstance can still be considered unused until a navigation to a real
2840 // page.
[email protected]434f69f2012-02-06 21:56:522841 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252842 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332843 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522844 }
[email protected]420ae012009-04-24 05:16:322845
2846 // Need to update MIME type here because it's referred to in
2847 // UpdateNavigationCommands() called by RendererDidNavigate() to
2848 // determine whether or not to enable the encoding menu.
2849 // It's updated only for the main frame. For a subframe,
2850 // RenderView::UpdateURL does not set params.contents_mime_type.
2851 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2852 // TODO(jungshik): Add a test for the encoding menu to avoid
2853 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212854 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322855 contents_mime_type_ = params.contents_mime_type;
2856
[email protected]8ff00d72012-10-23 19:12:212857 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002858 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392859
[email protected]1ae93fb2013-06-14 03:38:562860 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2861 // us estimate our process count for implementing OOP iframes.
2862 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552863 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562864
[email protected]a9c0bfe2010-09-17 08:35:222865 // Send notification about committed provisional loads. This notification is
2866 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2867 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212868 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072869 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2870 // that is not recorded in the navigation history. For the purpose of
2871 // tracking navigation events, we treat this event as a sub frame navigation
2872 // event.
2873 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212874 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222875 // Whether or not a page transition was triggered by going backward or
2876 // forward in the history is only stored in the navigation controller's
2877 // entry list.
2878 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272879 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212880 PAGE_TRANSITION_FORWARD_BACK)) {
2881 transition_type = PageTransitionFromInt(
2882 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222883 }
[email protected]0d60f0192011-04-14 12:40:102884 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252885 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442886 DidCommitProvisionalLoadForFrame(
2887 params.frame_id,
2888 params.frame_unique_name,
2889 is_main_frame,
2890 params.url,
2891 transition_type,
2892 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222893 }
2894
[email protected]76543b92009-08-31 17:27:452895 if (!did_navigate)
2896 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322897
2898 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2899 // for the appropriate notification (best) or you can add it to
2900 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2901 // necessary, please).
2902
2903 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002904 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322905 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002906 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512907 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002908 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2909 }
[email protected]93f230e02011-06-01 14:40:002910 }
[email protected]420ae012009-04-24 05:16:322911 DidNavigateAnyFramePostCommit(rvh, details, params);
2912}
2913
[email protected]b172aee2012-04-10 17:05:262914void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2915 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042916 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152917 // Ensure that this state update comes from either the active RVH or one of
2918 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]7a49f7e2013-04-19 15:07:222919 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsOnSwappedOutList(rvh));
[email protected]420ae012009-04-24 05:16:322920
2921 // We must be prepared to handle state updates for any page, these occur
2922 // when the user is scrolling and entering form data, as well as when we're
2923 // leaving a page, in which case our state may have already been moved to
2924 // the next page. The navigation controller will look up the appropriate
2925 // NavigationEntry and update it when it is notified via the delegate.
2926
2927 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582928 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322929 if (entry_index < 0)
2930 return;
[email protected]10f417c52011-12-28 21:04:232931 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322932
[email protected]691aa2f2013-05-28 22:52:042933 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322934 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042935 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322936 controller_.NotifyEntryChanged(entry, entry_index);
2937}
2938
[email protected]b172aee2012-04-10 17:05:262939void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2940 int32 page_id,
2941 const string16& title,
2942 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322943 // If we have a title, that's a pretty good indication that we've started
2944 // getting useful data.
2945 SetNotWaitingForResponse();
2946
[email protected]73eb2602012-02-09 19:50:552947 // Try to find the navigation entry, which might not be the current one.
2948 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232949 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582950 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092951
[email protected]73eb2602012-02-09 19:50:552952 // We can handle title updates when we don't have an entry in
2953 // UpdateTitleForEntry, but only if the update is from the current RVH.
2954 if (!entry && rvh != GetRenderViewHost())
2955 return;
2956
[email protected]a49e10b2011-08-01 23:57:462957 // TODO(evan): make use of title_direction.
2958 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092959 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322960 return;
2961
2962 // Broadcast notifications when the UI should be updated.
2963 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212964 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322965}
2966
[email protected]b172aee2012-04-10 17:05:262967void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2968 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312969 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322970}
2971
[email protected]b172aee2012-04-10 17:05:262972void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512973 if (delegate_)
2974 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322975}
2976
[email protected]b172aee2012-04-10 17:05:262977void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:102978#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:292979 // The UI may be in an event-tracking loop, such as between the
2980 // mouse-down and mouse-up in text selection or a button click.
2981 // Defer the close until after tracking is complete, so that we
2982 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292983 // TODO(shess): This could get more fine-grained. For instance,
2984 // closing a tab in another window while selecting text in the
2985 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:102986 if (view_->IsEventTracking()) {
2987 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292988 return;
2989 }
[email protected]60780f412013-02-25 16:34:102990#endif
[email protected]07707302009-11-06 00:50:292991
[email protected]420ae012009-04-24 05:16:322992 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522993 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512994 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322995}
2996
[email protected]b172aee2012-04-10 17:05:262997void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522998 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512999 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283000
3001 // Allow the navigation to proceed.
3002 render_manager_.SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573003}
3004
[email protected]b172aee2012-04-10 17:05:263005void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513006 if (delegate_ && delegate_->IsPopupOrPanel(this))
3007 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323008}
3009
[email protected]8ff00d72012-10-23 19:12:213010void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593011 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323012}
3013
[email protected]8ff00d72012-10-23 19:12:213014void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323015 scoped_ptr<LoadNotificationDetails> details;
3016
[email protected]9595fd82013-04-19 21:28:493017 // Use the last committed entry rather than the active one, in case a
3018 // pending entry has been created.
3019 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3020
[email protected]420ae012009-04-24 05:16:323021 // An entry may not exist for a stop when loading an initial blank page or
3022 // if an iframe injected by script into a blank page finishes loading.
3023 if (entry) {
[email protected]420ae012009-04-24 05:16:323024 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3025
3026 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513027 entry->GetVirtualURL(),
3028 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323029 elapsed,
3030 &controller_,
3031 controller_.GetCurrentEntryIndex()));
3032 }
3033
[email protected]91621872013-10-08 04:04:593034 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323035}
3036
[email protected]b172aee2012-04-10 17:05:263037void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163038 controller_.DiscardNonCommittedEntries();
3039
3040 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213041 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163042}
3043
[email protected]b172aee2012-04-10 17:05:263044void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513045 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133046 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403047}
3048
[email protected]7cc78902012-12-06 02:32:263049void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393050 if (opener_) {
3051 // Clear our opener so that future cross-process navigations don't have an
3052 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103053 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393054 opener_ = NULL;
3055 }
[email protected]7cc78902012-12-06 02:32:263056
3057 // Notify all swapped out RenderViewHosts for this tab. This is important
3058 // in case we go back to them, or if another window in those processes tries
3059 // to access window.opener.
3060 render_manager_.DidDisownOpener(rvh);
3061}
3062
[email protected]59167c22013-06-03 18:07:323063void WebContentsImpl::DidAccessInitialDocument() {
3064 // Update the URL display.
3065 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3066}
3067
[email protected]87717d0e2012-04-26 02:58:433068void WebContentsImpl::DocumentAvailableInMainFrame(
3069 RenderViewHost* render_view_host) {
3070 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3071 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103072}
3073
[email protected]b172aee2012-04-10 17:05:263074void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083075 RenderViewHost* render_view_host,
3076 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093077 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3078 DocumentOnLoadCompletedInMainFrame(page_id));
3079
3080 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213081 NotificationService::current()->Notify(
3082 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3083 Source<WebContents>(this),
3084 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083085}
3086
[email protected]196159d2012-05-04 17:26:543087void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3088 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213089 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263090 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183091 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523092 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303093 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543094 // If this came from a swapped out RenderViewHost, we only allow the request
3095 // if we are still in the same BrowsingInstance.
3096 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3097 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3098 return;
3099 }
3100
[email protected]4ad5d77d2011-12-03 02:00:483101 // Delegate to RequestTransferURL because this is just the generic
3102 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573103 // TODO(creis): Pass the redirect_chain into this method to support client
3104 // redirects. http://crbug.com/311721.
3105 std::vector<GURL> redirect_chain;
3106 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3107 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523108 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483109}
3110
[email protected]b172aee2012-04-10 17:05:263111void WebContentsImpl::RequestTransferURL(
3112 const GURL& url,
[email protected]f8872902013-10-30 03:18:573113 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213114 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573115 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263116 WindowOpenDisposition disposition,
3117 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183118 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523119 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303120 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203121 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123122 GURL dest_url(url);
3123 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553124 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123125 dest_url = GURL(kAboutBlankURL);
3126
[email protected]44d0930a2013-10-28 18:53:553127 OpenURLParams params(dest_url, referrer, source_frame_id, disposition,
[email protected]f8872902013-10-30 03:18:573128 page_transition, true /* is_renderer_initiated */);
3129 if (redirect_chain.size() > 0)
3130 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553131 params.transferred_global_request_id = old_request_id;
3132 params.should_replace_current_entry = should_replace_current_entry;
3133 params.user_gesture = user_gesture;
3134
[email protected]7ade2732011-02-10 00:13:583135 if (render_manager_.web_ui()) {
[email protected]f8872902013-10-30 03:18:573136 // Web UI pages sometimes want to override the page transition type for
3137 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3138 // automatically generated suggestions). We don't override other types
3139 // like TYPED because they have different implications (e.g., autocomplete).
3140 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
3141 params.transition = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553142
[email protected]e0112912011-02-02 22:54:353143 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163144 // want web sites to see a referrer of "chrome://blah" (and some
3145 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323146 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553147 params.referrer = Referrer();
3148
3149 // Navigations in Web UI pages count as browser-initiated navigations.
3150 params.is_renderer_initiated = false;
[email protected]ae5184d62011-10-06 19:25:583151 }
[email protected]44d0930a2013-10-28 18:53:553152
3153 new_contents = OpenURL(params);
3154
[email protected]ae5184d62011-10-06 19:25:583155 if (new_contents) {
3156 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253157 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583158 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123159 dest_url,
[email protected]ae5184d62011-10-06 19:25:583160 referrer,
3161 disposition,
[email protected]44d0930a2013-10-28 18:53:553162 params.transition,
[email protected]ae5184d62011-10-06 19:25:583163 source_frame_id));
[email protected]420ae012009-04-24 05:16:323164 }
3165}
3166
[email protected]e1c3a552012-05-04 20:51:323167void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3168 // Tell the active RenderViewHost to run unload handlers and close, as long
3169 // as the request came from a RenderViewHost in the same BrowsingInstance.
3170 // In most cases, we receive this from a swapped out RenderViewHost.
3171 // It is possible to receive it from one that has just been swapped in,
3172 // in which case we might as well deliver the message anyway.
3173 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3174 GetRenderViewHost()->ClosePage();
3175}
3176
[email protected]f546640b2012-05-15 00:03:493177void WebContentsImpl::RouteMessageEvent(
3178 RenderViewHost* rvh,
3179 const ViewMsg_PostMessage_Params& params) {
3180 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363181 // came from a RenderViewHost in the same BrowsingInstance or if this
3182 // WebContents is dedicated to a browser plugin guest.
3183 // Note: This check means that an embedder could theoretically receive a
3184 // postMessage from anyone (not just its own guests). However, this is
3185 // probably not a risk for apps since other pages won't have references
3186 // to App windows.
3187 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3188 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493189 return;
3190
3191 ViewMsg_PostMessage_Params new_params(params);
3192
[email protected]0bc7f3542013-10-21 15:05:533193 if (!params.message_port_ids.empty()) {
3194 MessagePortMessageFilter* message_port_message_filter =
3195 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3196 ->message_port_message_filter();
3197 std::vector<int> new_routing_ids(params.message_port_ids.size());
3198 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3199 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3200 MessagePortService::GetInstance()->UpdateMessagePort(
3201 params.message_port_ids[i],
3202 message_port_message_filter,
3203 new_routing_ids[i]);
3204 }
3205 new_params.new_routing_ids = new_routing_ids;
3206 }
3207
[email protected]f546640b2012-05-15 00:03:493208 // If there is a source_routing_id, translate it to the routing ID for
3209 // the equivalent swapped out RVH in the target process. If we need
3210 // to create a swapped out RVH for the source tab, we create its opener
3211 // chain as well, since those will also be accessible to the target page.
3212 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3213 // Try to look up the WebContents for the source page.
3214 WebContentsImpl* source_contents = NULL;
3215 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3216 rvh->GetProcess()->GetID(), params.source_routing_id);
3217 if (source_rvh) {
3218 source_contents = static_cast<WebContentsImpl*>(
3219 source_rvh->GetDelegate()->GetAsWebContents());
3220 }
3221
3222 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363223 if (GetBrowserPluginGuest()) {
3224 // We create a swapped out RenderView for the embedder in the guest's
3225 // render process but we intentionally do not expose the embedder's
3226 // opener chain to it.
3227 new_params.source_routing_id =
3228 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3229 } else {
3230 new_params.source_routing_id =
3231 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3232 }
[email protected]f546640b2012-05-15 00:03:493233 } else {
3234 // We couldn't find it, so don't pass a source frame.
3235 new_params.source_routing_id = MSG_ROUTING_NONE;
3236 }
3237 }
3238
3239 // In most cases, we receive this from a swapped out RenderViewHost.
3240 // It is possible to receive it from one that has just been swapped in,
3241 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183242 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493243}
3244
[email protected]b172aee2012-04-10 17:05:263245void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343246 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:413247 const string16& message,
3248 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323249 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213250 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323251 IPC::Message* reply_msg,
3252 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073253 // Suppress JavaScript dialogs when requested. Also suppress messages when
3254 // showing an interstitial as it's shown over the previous page and we don't
3255 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503256 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583257 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273258 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073259 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523260 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153261 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323262
3263 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213264 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433265 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153266 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3267 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433268 this,
3269 frame_url.GetOrigin(),
3270 accept_lang,
3271 javascript_message_type,
3272 message,
[email protected]51da7e32012-01-30 19:24:523273 default_prompt,
[email protected]b172aee2012-04-10 17:05:263274 base::Bind(&WebContentsImpl::OnDialogClosed,
3275 base::Unretained(this),
3276 rvh,
3277 reply_msg),
[email protected]51da7e32012-01-30 19:24:523278 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323279 }
[email protected]3ab9cb82011-06-03 18:02:073280
[email protected]6dd2f1e2013-09-11 15:06:013281 *did_suppress_message = suppress_this_message;
3282
[email protected]3ab9cb82011-06-03 18:02:073283 if (suppress_this_message) {
3284 // If we are suppressing messages, just reply as if the user immediately
3285 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:343286 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:073287 }
3288
[email protected]6dd2f1e2013-09-11 15:06:013289 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3290 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323291}
3292
[email protected]b172aee2012-04-10 17:05:263293void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
3294 const string16& message,
3295 bool is_reload,
3296 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583297 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513298 if (delegate_)
3299 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073300
3301 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583302 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073303 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523304 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153305 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153306 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343307 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:583308 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:503309 return;
3310 }
[email protected]3ab9cb82011-06-03 18:02:073311
[email protected]7ab1e7d62009-10-14 23:32:013312 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153313 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3314 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323315 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263316 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523317 reply_msg));
[email protected]420ae012009-04-24 05:16:323318}
3319
[email protected]a796f202012-05-30 14:14:253320bool WebContentsImpl::AddMessageToConsole(int32 level,
3321 const string16& message,
3322 int32 line_no,
[email protected]88b50b62013-09-01 23:05:063323 const string16& source_id) {
[email protected]a796f202012-05-30 14:14:253324 if (!delegate_)
3325 return false;
3326 return delegate_->AddMessageToConsole(this, level, message, line_no,
3327 source_id);
3328}
3329
[email protected]b172aee2012-04-10 17:05:263330WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273331 // We want to base the page config off of the actual URL, rather than the
3332 // virtual URL.
3333 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3334 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003335 GURL url = controller_.GetActiveEntry()
3336 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153337
3338 return render_manager_.current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323339}
3340
[email protected]0eba810b2012-10-18 03:19:363341int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213342 SiteInstance* instance) {
[email protected]1ac10dca2013-08-20 20:47:043343 return render_manager_.CreateRenderView(instance, MSG_ROUTING_NONE,
3344 true, true);
[email protected]0eba810b2012-10-18 03:19:363345}
3346
[email protected]b172aee2012-04-10 17:05:263347void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273348 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253349 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223350
[email protected]ea114722012-03-12 01:11:253351 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173352 if (rdh) // NULL in unittests.
3353 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253354}
3355
[email protected]b172aee2012-04-10 17:05:263356void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443357 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253358 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443359}
3360
[email protected]b172aee2012-04-10 17:05:263361void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563362 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263363 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153364 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523365 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153366 return;
3367
[email protected]9f76c1e2012-03-05 15:15:583368 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3369
[email protected]e5fc1632011-08-08 07:51:533370 // Ignore renderer unresponsive event if debugger is attached to the tab
3371 // since the event may be a result of the renderer sitting on a breakpoint.
3372 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363373 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533374 return;
3375
[email protected]2e9d79f2013-08-16 05:45:563376 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323377 // Hang occurred while firing the beforeunload/unload handler.
3378 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583379 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323380
3381 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3382 return;
3383
3384 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563385 // nothing we can do to recover. If the hang is in the beforeunload handler,
3386 // pretend the beforeunload listeners have all fired and allow the delegate
3387 // to continue closing; the user will not have the option of cancelling the
3388 // close. Otherwise, pretend the unload listeners have all fired and close
3389 // the tab.
3390 bool close = true;
3391 if (is_during_beforeunload) {
3392 delegate_->BeforeUnloadFired(this, true, &close);
3393 }
3394 if (close)
3395 Close(rvh);
[email protected]420ae012009-04-24 05:16:323396 return;
3397 }
3398
[email protected]9f76c1e2012-03-05 15:15:583399 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473400 return;
3401
[email protected]6934a702011-12-20 00:04:513402 if (delegate_)
3403 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323404}
3405
[email protected]b172aee2012-04-10 17:05:263406void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513407 if (delegate_)
3408 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323409}
3410
[email protected]b172aee2012-04-10 17:05:263411void WebContentsImpl::LoadStateChanged(
3412 const GURL& url,
3413 const net::LoadStateWithParam& load_state,
3414 uint64 upload_position,
3415 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323416 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563417 upload_position_ = upload_position;
3418 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503419 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213420 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303421 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213422 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323423 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463424 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213425 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463426 }
[email protected]420ae012009-04-24 05:16:323427}
3428
[email protected]b172aee2012-04-10 17:05:263429void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513430 if (delegate_)
3431 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253432}
3433
[email protected]b172aee2012-04-10 17:05:263434void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553435 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323436 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123437 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3438 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513439 if (delegate_)
3440 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093441 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323442}
3443
[email protected]58d5cfe2013-07-10 02:40:523444void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543445 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233446 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223447 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543448}
3449
[email protected]b172aee2012-04-10 17:05:263450void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103451 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213452 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263453 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3454 // here during container initialization and normal window size will be set
3455 // later. In case of tab duplication this resizing to 0x0 prevents setting
3456 // normal size later so just ignore it.
3457 if (!size.IsEmpty())
3458 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323459}
3460
[email protected]af905902013-10-01 21:38:513461void WebContentsImpl::CancelModalDialogsForRenderManager() {
3462 // We need to cancel modal dialogs when doing a process swap, since the load
3463 // deferrer would prevent us from swapping out.
3464 if (dialog_manager_)
3465 dialog_manager_->CancelActiveAndPendingDialogs(this);
3466}
3467
[email protected]7b712ee22013-10-03 00:57:283468void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3469 RenderViewHost* new_host) {
3470 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083471
3472 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003473 if (delegate_)
3474 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393475
[email protected]7b712ee22013-10-03 00:57:283476 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543477}
3478
[email protected]14392a52012-05-02 20:28:443479int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3480 SiteInstance* instance) {
3481 if (!opener_)
3482 return MSG_ROUTING_NONE;
3483
3484 // Recursively create RenderViews for anything else in the opener chain.
3485 return opener_->CreateOpenerRenderViews(instance);
3486}
3487
3488int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3489 int opener_route_id = MSG_ROUTING_NONE;
3490
3491 // If this tab has an opener, ensure it has a RenderView in the given
3492 // SiteInstance as well.
3493 if (opener_)
3494 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3495
[email protected]45a22ad2013-02-21 03:25:003496 // If any of the renderers (current, pending, or swapped out) for this
3497 // WebContents has the same SiteInstance, use it.
[email protected]0720b532012-08-28 19:23:373498 if (render_manager_.current_host()->GetSiteInstance() == instance)
3499 return render_manager_.current_host()->GetRoutingID();
3500
[email protected]45a22ad2013-02-21 03:25:003501 if (render_manager_.pending_render_view_host() &&
3502 render_manager_.pending_render_view_host()->GetSiteInstance() == instance)
3503 return render_manager_.pending_render_view_host()->GetRoutingID();
3504
[email protected]0720b532012-08-28 19:23:373505 RenderViewHostImpl* rvh = render_manager_.GetSwappedOutRenderViewHost(
3506 instance);
3507 if (rvh)
3508 return rvh->GetRoutingID();
3509
[email protected]14392a52012-05-02 20:28:443510 // Create a swapped out RenderView in the given SiteInstance if none exists,
3511 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]1ac10dca2013-08-20 20:47:043512 return render_manager_.CreateRenderView(instance, opener_route_id,
3513 true, true);
[email protected]14392a52012-05-02 20:28:443514}
3515
[email protected]b172aee2012-04-10 17:05:263516NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193517 return GetController();
[email protected]3a3d47472010-07-15 21:03:543518}
3519
[email protected]b172aee2012-04-10 17:05:263520WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563521 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323522}
3523
[email protected]10f417c52011-12-28 21:04:233524NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263525 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323526 return controller_.GetLastCommittedEntry();
3527}
3528
[email protected]b172aee2012-04-10 17:05:263529bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443530 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033531 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443532 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323533 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523534
[email protected]420ae012009-04-24 05:16:323535 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443536 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213537 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323538
[email protected]74ce1ad2011-12-16 21:51:463539 // Make sure we use the correct starting page_id in the new RenderView.
3540 UpdateMaxPageIDIfNecessary(render_view_host);
3541 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583542 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463543
[email protected]9f76c1e2012-03-05 15:15:583544 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493545 render_view_host)->CreateRenderView(string16(),
3546 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133547 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523548 return false;
[email protected]14392a52012-05-02 20:28:443549 }
[email protected]a4127722011-04-27 23:13:523550
[email protected]a220b5932013-09-21 03:47:443551#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503552 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3553 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443554 if (rwh_view) {
3555 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3556 render_widget_host->WasResized();
3557 }
[email protected]f8233cc2011-05-31 20:24:503558#endif
3559
[email protected]420ae012009-04-24 05:16:323560 return true;
3561}
3562
[email protected]7d244f12013-08-22 21:41:513563#if defined(OS_ANDROID)
3564bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3565 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3566 MSG_ROUTING_NONE);
3567}
3568#endif
3569
[email protected]b172aee2012-04-10 17:05:263570void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3571 IPC::Message* reply_msg,
3572 bool success,
3573 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543574 if (is_showing_before_unload_dialog_ && !success) {
3575 // If a beforeunload dialog is canceled, we need to stop the throbber from
3576 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293577 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353578 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103579
[email protected]6d65a462013-06-21 21:29:123580 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3581 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543582 }
3583 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583584 static_cast<RenderViewHostImpl*>(
3585 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543586}
3587
[email protected]b172aee2012-04-10 17:05:263588void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213589 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123590 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103591}
[email protected]f45d2a72010-03-08 23:28:353592
[email protected]b172aee2012-04-10 17:05:263593void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103594 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443595 // Can be NULL during tests.
3596 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213597 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363598}
[email protected]9f76c1e2012-03-05 15:15:583599
[email protected]1ac10dca2013-08-20 20:47:043600bool WebContentsImpl::IsHidden() {
3601 return capturer_count_ == 0 && !should_normally_be_visible_;
3602}
3603
[email protected]b172aee2012-04-10 17:05:263604RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583605 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3606}
[email protected]7900bfdb2012-05-24 19:31:243607
[email protected]f8497342013-02-05 22:15:023608BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393609 return browser_plugin_guest_.get();
3610}
3611
[email protected]738f57a2013-06-29 21:06:543612void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3613 CHECK(!browser_plugin_guest_);
3614 browser_plugin_guest_.reset(guest);
3615}
3616
[email protected]f8497342013-02-05 22:15:023617BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393618 return browser_plugin_embedder_.get();
3619}
[email protected]8ff00d72012-10-23 19:12:213620
[email protected]8eb04562013-03-06 03:41:143621BrowserPluginGuestManager*
3622 WebContentsImpl::GetBrowserPluginGuestManager() const {
3623 return static_cast<BrowserPluginGuestManager*>(
3624 GetBrowserContext()->GetUserData(
3625 browser_plugin::kBrowserPluginGuestManagerKeyName));
3626}
3627
[email protected]d9030b82013-07-19 08:26:063628void WebContentsImpl::ClearPowerSaveBlockers(
3629 RenderViewHost* render_view_host) {
3630 STLDeleteValues(&power_save_blockers_[render_view_host]);
3631 power_save_blockers_.erase(render_view_host);
3632}
3633
3634void WebContentsImpl::ClearAllPowerSaveBlockers() {
3635 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3636 i != power_save_blockers_.end(); ++i)
3637 STLDeleteValues(&power_save_blockers_[i->first]);
3638 power_save_blockers_.clear();
3639}
3640
[email protected]dc0fd432013-08-27 15:29:213641gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3642 gfx::Size size;
3643 if (delegate_)
3644 size = delegate_->GetSizeForNewRenderView(this);
3645 if (size.IsEmpty())
3646 size = view_->GetContainerSize();
3647 return size;
3648}
3649
[email protected]9b159a52013-10-03 17:24:553650void WebContentsImpl::OnFrameRemoved(
3651 RenderViewHostImpl* render_view_host,
3652 int64 frame_id) {
3653 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3654 FrameDetached(render_view_host, frame_id));
3655}
3656
[email protected]8ff00d72012-10-23 19:12:213657} // namespace content