blob: e363c3287f8bd282a44df1e557da96591b66989e [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/browser_plugin/browser_plugin_embedder.h"
22#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]8eb04562013-03-06 03:41:1423#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
[email protected]b9535422012-02-09 01:47:5924#include "content/browser/child_process_security_policy_impl.h"
[email protected]70019152012-12-19 11:44:1925#include "content/browser/devtools/devtools_manager_impl.h"
[email protected]5f2aa722013-08-07 16:59:4126#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0427#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4628#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1229#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1630#include "content/browser/download/save_package.h"
[email protected]d4a8ca482013-10-30 21:06:4031#include "content/browser/frame_host/interstitial_page_impl.h"
32#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]190b8c52013-11-09 01:35:4433#include "content/browser/frame_host/navigator.h"
[email protected]5c9250872012-01-30 17:24:0534#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4435#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5336#include "content/browser/message_port_message_filter.h"
37#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0638#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3039#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3240#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5041#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3342#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1143#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5844#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0345#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5646#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1447#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4248#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]41225fe2013-03-29 05:32:0249#include "content/common/image_messages.h"
[email protected]35be7ec2012-02-12 20:42:5150#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0251#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5752#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5853#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1154#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2055#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4456#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3657#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1758#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1459#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4660#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1561#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0062#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2763#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0064#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3765#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1466#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3267#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3468#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3869#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4270#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2571#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1072#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2173#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4874#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5475#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4976#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2077#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0378#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1679#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2980#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5381#include "net/http/http_cache.h"
82#include "net/http/http_transaction_factory.h"
83#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3484#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5685#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0186#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4187#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5288#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1889#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3190
[email protected]583418cc2013-01-17 14:01:1091#if defined(OS_ANDROID)
92#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3293#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
94#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:0095#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:1096#endif
97
[email protected]f66df822012-05-18 16:52:1798#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5099#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27100#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57101#endif
[email protected]3e45ba92009-02-20 21:09:00102
[email protected]420ae012009-04-24 05:16:32103// Cross-Site Navigations
104//
[email protected]b172aee2012-04-10 17:05:26105// If a WebContentsImpl is told to navigate to a different web site (as
106// determined by SiteInstance), it will replace its current RenderViewHost with
107// a new RenderViewHost dedicated to the new SiteInstance. This works as
108// follows:
[email protected]420ae012009-04-24 05:16:32109//
[email protected]fc6c1872013-10-03 01:22:35110// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46111// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32112// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35113// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32114// run in the current RVH.
115// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35116// that it has a pending cross-site request. We will check this on the IO
117// thread when deciding how to handle the response.
118// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46119// cancel all the pending logic. Otherwise we allow the pending RVH to send
120// the navigation request to its renderer.
121// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35122// main resource load on the pending RVH. It creates a
123// CrossSiteResourceHandler to check whether a process swap is needed when
124// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46125// - When RDH receives a response, the BufferedResourceHandler determines
126// whether it is a download. If so, it sends a message to the new renderer
127// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26128// pending RVH remains until the next DidNavigate event for this
129// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32130// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35131// download, the CrossSiteResourceHandler checks whether a process swap is
132// needed (either because CrossSiteRequestManager has state for it or because
133// a transfer was needed for a redirect).
134// - If so, CrossSiteResourceHandler pauses the response to first run the old
135// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36136// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
137// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35138// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
139// to a new process is needed, based on the stored pending_nav_params_. (This
140// is independent of whether we started out with a cross-process navigation.)
141// - If not, it just tells the ResourceDispatcherHost to resume the response
142// to its current RenderViewHost.
143// - If so, it cancels the current pending RenderViewHost and sets up a new
144// navigation using RequestTransferURL. When the transferred request
145// arrives in the ResourceDispatcherHost, we transfer the response and
146// resume it.
[email protected]420ae012009-04-24 05:16:32147// - The pending renderer sends a FrameNavigate message that invokes the
148// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46149// pending RVH.
[email protected]b0936d22013-11-28 06:47:36150// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15151// the user goes back. The process only stays live if another tab is using
152// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32153
[email protected]8ff00d72012-10-23 19:12:21154namespace content {
[email protected]420ae012009-04-24 05:16:32155namespace {
156
[email protected]82114f52012-03-20 22:53:41157const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05158
[email protected]e4abd3b42013-11-12 18:28:47159base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46160g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
161
[email protected]795c28972012-12-06 06:13:39162static int StartDownload(content::RenderViewHost* rvh,
163 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29164 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30165 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02166 static int g_next_image_download_id = 0;
167 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
168 ++g_next_image_download_id,
169 url,
170 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30171 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02172 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39173}
174
[email protected]2c5569662011-03-22 20:45:02175ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]8ff00d72012-10-23 19:12:21176 BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50177 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16178 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47179 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02180 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47181 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02182 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]7c16976c2012-08-04 02:38:23183 case NavigationControllerImpl::RELOAD_ORIGINAL_REQUEST_URL:
184 return ViewMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL;
[email protected]d202a7c2012-01-04 07:53:47185 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16186 break; // Fall through to rest of function.
187 }
[email protected]5e369672009-11-03 23:48:30188
[email protected]59246c572012-02-10 13:32:13189 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
190 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]2ca1ea662012-10-04 02:26:36191 if (entry.restore_type() ==
192 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) {
[email protected]59246c572012-02-10 13:32:13193 if (entry.GetHasPostData())
194 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02195 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13196 }
[email protected]5e369672009-11-03 23:48:30197
[email protected]2c5569662011-03-22 20:45:02198 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30199}
200
[email protected]10f417c52011-12-28 21:04:23201void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47202 const NavigationControllerImpl& controller,
[email protected]8ff00d72012-10-23 19:12:21203 WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50204 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16205 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51206 params->page_id = entry.GetPageID();
[email protected]60d6cca2013-04-30 08:47:13207 params->should_clear_history_list = entry.should_clear_history_list();
[email protected]4972fc82013-11-19 04:33:42208 params->should_replace_current_entry = entry.should_replace_entry();
[email protected]60d6cca2013-04-30 08:47:13209 if (entry.should_clear_history_list()) {
210 // Set the history list related parameters to the same values a
211 // NavigationController would return before its first navigation. This will
212 // fully clear the RenderView's view of the session history.
213 params->pending_history_list_offset = -1;
214 params->current_history_list_offset = -1;
215 params->current_history_list_length = 0;
216 } else {
217 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
218 params->current_history_list_offset =
219 controller.GetLastCommittedEntryIndex();
220 params->current_history_list_length = controller.GetEntryCount();
221 }
[email protected]eaaba7dd2013-10-14 02:38:07222 params->url = entry.GetURL();
[email protected]d1ef81d2012-07-24 11:39:36223 if (!entry.GetBaseURLForDataURL().is_empty()) {
224 params->base_url_for_data_url = entry.GetBaseURLForDataURL();
225 params->history_url_for_data_url = entry.GetVirtualURL();
226 }
[email protected]36fc0392011-12-25 03:59:51227 params->referrer = entry.GetReferrer();
228 params->transition = entry.GetTransitionType();
[email protected]691aa2f2013-05-28 22:52:04229 params->page_state = entry.GetPageState();
[email protected]3cc72b12010-03-18 23:03:00230 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55231 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34232 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47233 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48234 params->transferred_request_child_id =
235 entry.transferred_global_request_id().child_id;
236 params->transferred_request_request_id =
237 entry.transferred_global_request_id().request_id;
[email protected]bf70edce2012-06-20 22:32:22238 params->is_overriding_user_agent = entry.GetIsOverridingUserAgent();
[email protected]80744782012-05-04 01:47:00239 // Avoid downloading when in view-source mode.
240 params->allow_download = !entry.IsViewSourceMode();
[email protected]132e281a2012-07-31 18:32:44241 params->is_post = entry.GetHasPostData();
[email protected]eaaba7dd2013-10-14 02:38:07242 if (entry.GetBrowserInitiatedPostData()) {
243 params->browser_initiated_post_data.assign(
244 entry.GetBrowserInitiatedPostData()->front(),
245 entry.GetBrowserInitiatedPostData()->front() +
246 entry.GetBrowserInitiatedPostData()->size());
[email protected]7c16976c2012-08-04 02:38:23247 }
248
[email protected]f8872902013-10-30 03:18:57249 params->redirects = entry.redirect_chain();
250
[email protected]951a64832012-10-11 16:26:37251 params->can_load_local_resources = entry.GetCanLoadLocalResources();
[email protected]3027cf02013-01-24 08:16:58252 params->frame_to_navigate = entry.GetFrameToNavigate();
[email protected]951a64832012-10-11 16:26:37253
[email protected]6c6b02d2011-09-02 03:36:47254 if (delegate)
255 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34256}
257
[email protected]8bfc8272013-09-09 20:10:53258void NotifyCacheOnIO(
259 scoped_refptr<net::URLRequestContextGetter> request_context,
260 const GURL& url,
261 const std::string& http_method) {
262 request_context->GetURLRequestContext()->http_transaction_factory()->
263 GetCache()->OnExternalCacheHit(url, http_method);
264}
265
[email protected]9b159a52013-10-03 17:24:55266// Helper function for retrieving all the sites in a frame tree.
267bool CollectSites(BrowserContext* context,
268 std::set<GURL>* sites,
269 FrameTreeNode* node) {
270 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
271 return true;
272}
273
[email protected]420ae012009-04-24 05:16:32274} // namespace
275
[email protected]54944cde2012-12-09 09:24:59276WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15277 return WebContentsImpl::CreateWithOpener(
278 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19279}
280
281WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59282 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30283 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59284 WebContentsImpl* new_contents = new WebContentsImpl(
285 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30286
287 for (SessionStorageNamespaceMap::const_iterator it =
288 session_storage_namespace_map.begin();
289 it != session_storage_namespace_map.end();
290 ++it) {
291 new_contents->GetController()
292 .SetSessionStorageNamespace(it->first, it->second.get());
293 }
294
[email protected]54944cde2012-12-09 09:24:59295 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19296 return new_contents;
[email protected]a81343d232011-12-27 07:39:20297}
[email protected]746d3052012-05-22 15:15:47298
[email protected]e4abd3b42013-11-12 18:28:47299void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46300 g_created_callbacks.Get().push_back(callback);
301}
302
[email protected]e4abd3b42013-11-12 18:28:47303void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46304 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
305 if (g_created_callbacks.Get().at(i).Equals(callback)) {
306 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
307 return;
308 }
309 }
310}
311
[email protected]299d7f12012-05-23 05:31:15312WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47313 return rvh->GetDelegate()->GetAsWebContents();
314}
315
[email protected]7fff43e2013-05-21 20:21:10316// WebContentsImpl::DestructionObserver ----------------------------------------
317
318class WebContentsImpl::DestructionObserver : public WebContentsObserver {
319 public:
320 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
321 : WebContentsObserver(watched_contents),
322 owner_(owner) {
323 }
324
325 // WebContentsObserver:
326 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
327 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
328 }
329
330 private:
331 WebContentsImpl* owner_;
332
333 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
334};
335
[email protected]b172aee2012-04-10 17:05:26336// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32337
[email protected]b172aee2012-04-10 17:05:26338WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21339 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19340 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42341 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22342 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57343 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44344 opener_(opener),
[email protected]c73a2282013-04-29 21:10:41345#if defined(OS_WIN) && defined(USE_AURA)
346 accessible_parent_(NULL),
347#endif
[email protected]fa944cb82013-11-15 17:51:21348 frame_tree_(new Navigator(&controller_, this), this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34349 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23350 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
351 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34352 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26353 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56354 upload_size_(0),
355 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47356 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55357 capturer_count_(0),
358 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57359 is_being_destroyed_(false),
360 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15361 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01362 is_showing_before_unload_dialog_(false),
[email protected]ebf40a72010-07-22 01:46:38363 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21364 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
365 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00366 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21367 color_chooser_identifier_(0),
[email protected]f8bebfb2013-03-06 04:22:58368 message_source_(NULL),
[email protected]44470a22013-01-24 01:21:54369 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
[email protected]cbb1ef592013-06-05 19:49:46370 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
371 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55372 frame_tree_.SetFrameRemoveListener(
373 base::Bind(&WebContentsImpl::OnFrameRemoved,
374 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35375}
initial.commit09911bf2008-07-26 23:55:29376
[email protected]b172aee2012-04-10 17:05:26377WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32378 is_being_destroyed_ = true;
379
[email protected]d9030b82013-07-19 08:26:06380 ClearAllPowerSaveBlockers();
381
[email protected]b24b68a2012-09-24 21:57:26382 for (std::set<RenderWidgetHostImpl*>::iterator iter =
383 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
384 (*iter)->DetachDelegate();
385 }
386 created_widgets_.clear();
387
[email protected]3ab9cb82011-06-03 18:02:07388 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15389 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11390 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07391
[email protected]da8543762012-03-20 08:52:20392 if (color_chooser_)
393 color_chooser_->End();
394
[email protected]420ae012009-04-24 05:16:32395 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32396
[email protected]ca13a442012-04-17 14:00:12397 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21398 NotificationService::current()->Notify(
399 NOTIFICATION_WEB_CONTENTS_DESTROYED,
400 Source<WebContents>(this),
401 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32402
403 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07404#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32405 // If we still have a window handle, destroy it. GetNativeView can return
406 // NULL if this contents was part of a window that closed.
[email protected]f3615f02013-02-26 06:09:06407 if (view_->GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52408 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58409 if (host && host->GetView())
410 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42411 }
[email protected]420ae012009-04-24 05:16:32412#endif
[email protected]7ab1e7d62009-10-14 23:32:01413
[email protected]fa944cb82013-11-15 17:51:21414 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27415 if (pending_rvh) {
416 FOR_EACH_OBSERVER(WebContentsObserver,
417 observers_,
418 RenderViewDeleted(pending_rvh));
419 }
420
421 FOR_EACH_OBSERVER(WebContentsObserver,
422 observers_,
[email protected]fa944cb82013-11-15 17:51:21423 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27424
[email protected]2db9bd72012-04-13 20:20:56425 FOR_EACH_OBSERVER(WebContentsObserver,
426 observers_,
427 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08428
[email protected]6934a702011-12-20 00:04:51429 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10430
431 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
432 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42433}
434
[email protected]d1198fd2012-08-13 22:50:19435WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59436 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19437 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03438 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59439 WebContentsImpl* new_contents = new WebContentsImpl(
440 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19441
[email protected]54944cde2012-12-09 09:24:59442 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19443 return new_contents;
444}
445
[email protected]b371a5652013-02-20 11:25:51446// static
[email protected]8eb04562013-03-06 03:41:14447BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36448 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53449 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54450 int guest_instance_id,
451 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39452 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39453
454 // This makes |new_contents| act as a guest.
455 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54456 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19457 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11458
[email protected]3de10bb32013-01-08 21:57:33459 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33460 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11461
[email protected]216be772013-01-25 00:22:27462 // We are instantiating a WebContents for browser plugin. Set its subframe bit
463 // to true.
464 static_cast<RenderViewHostImpl*>(
465 new_contents->GetRenderViewHost())->set_is_subframe(true);
466
[email protected]8eb04562013-03-06 03:41:14467 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39468}
469
[email protected]b0936d22013-11-28 06:47:36470RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21471 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28472}
473
[email protected]7bb761892012-07-20 09:32:47474bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
475 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56476 if (GetWebUI() &&
477 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17478 return true;
[email protected]d2353452012-01-19 19:53:56479 }
[email protected]f82d57b52011-04-27 19:13:17480
[email protected]d8c660432011-12-22 20:51:25481 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
482 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10483 while ((observer = it.GetNext()) != NULL)
484 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53485 return true;
[email protected]403415a2011-01-10 18:57:53486
[email protected]7bb761892012-07-20 09:32:47487 // Message handlers should be aware of which RenderViewHost sent the
488 // message, which is temporarily stored in message_source_.
489 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18490 bool handled = true;
491 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26492 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]724159a2010-12-30 01:11:18493 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
494 OnDidLoadResourceFromMemoryCache)
495 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
496 OnDidDisplayInsecureContent)
497 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
498 OnDidRunInsecureContent)
499 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
500 OnDocumentLoadedInFrame)
501 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26502 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
503 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25504 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26505 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21506 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20507 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
508 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
509 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16510 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45511 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10512 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20513 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
514 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
515 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
516 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29517 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50518 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50519 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
520 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55521 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
522 OnBrowserPluginMessage(message))
523 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
524 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02525 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
526 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10527#if defined(OS_ANDROID)
528 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
529 OnFindMatchRectsReply)
530 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
531 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32532 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
533 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10534#endif
[email protected]d9030b82013-07-19 08:26:06535 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaNotification, OnMediaNotification)
[email protected]9f268072013-11-07 00:02:15536 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
537 OnFirstVisuallyNonEmptyPaint)
[email protected]724159a2010-12-30 01:11:18538 IPC_MESSAGE_UNHANDLED(handled = false)
539 IPC_END_MESSAGE_MAP_EX()
[email protected]7bb761892012-07-20 09:32:47540 message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18541
542 if (!message_is_ok) {
[email protected]8ff00d72012-10-23 19:12:21543 RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18544 GetRenderProcessHost()->ReceivedBadMessage();
545 }
546
547 return handled;
548}
549
[email protected]b172aee2012-04-10 17:05:26550void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18551 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21552 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43553 if (delegate_)
554 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18555}
556
[email protected]d1198fd2012-08-13 22:50:19557NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56558 return controller_;
559}
560
[email protected]d1198fd2012-08-13 22:50:19561const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56562 return controller_;
563}
564
[email protected]8ff00d72012-10-23 19:12:21565BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55566 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30567}
568
[email protected]b172aee2012-04-10 17:05:26569const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24570 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32571 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51572 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31573}
574
[email protected]a093ce02013-07-22 20:53:14575const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24576 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32577 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24578 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
579}
580
581const GURL& WebContentsImpl::GetLastCommittedURL() const {
582 // We may not have a navigation entry yet.
583 NavigationEntry* entry = controller_.GetLastCommittedEntry();
584 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
585}
586
[email protected]8ff00d72012-10-23 19:12:21587WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31588 return delegate_;
589}
590
[email protected]8ff00d72012-10-23 19:12:21591void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31592 // TODO(cbentzel): remove this debugging code?
593 if (delegate == delegate_)
594 return;
595 if (delegate_)
596 delegate_->Detach(this);
597 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08598 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31599 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08600 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00601 if (view_)
602 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08603 }
[email protected]be1f56ab2011-12-22 06:55:31604}
605
[email protected]8ff00d72012-10-23 19:12:21606RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21607 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41608 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16609}
610
[email protected]b172aee2012-04-10 17:05:26611RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21612 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31613}
614
[email protected]a04c9d02012-11-14 21:04:34615void WebContentsImpl::GetRenderViewHostAtPosition(
616 int x,
617 int y,
618 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
619 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
620 if (embedder)
621 embedder->GetRenderViewHostAtPosition(x, y, callback);
622 else
623 callback.Run(GetRenderViewHost(), x, y);
624}
625
[email protected]bfcfa692013-02-07 06:17:02626WebContents* WebContentsImpl::GetEmbedderWebContents() const {
627 BrowserPluginGuest* guest = GetBrowserPluginGuest();
628 if (guest)
629 return guest->embedder_web_contents();
630 return NULL;
631}
632
633int WebContentsImpl::GetEmbeddedInstanceID() const {
634 BrowserPluginGuest* guest = GetBrowserPluginGuest();
635 if (guest)
636 return guest->instance_id();
637 return 0;
638}
639
[email protected]6b618e62012-08-16 12:59:18640int WebContentsImpl::GetRoutingID() const {
641 if (!GetRenderViewHost())
642 return MSG_ROUTING_NONE;
643
644 return GetRenderViewHost()->GetRoutingID();
645}
646
[email protected]44470a22013-01-24 01:21:54647int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
648 return fullscreen_widget_routing_id_;
649}
650
[email protected]b172aee2012-04-10 17:05:26651RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21652 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31653}
654
[email protected]f8497342013-02-05 22:15:02655RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
656 BrowserPluginGuest* guest = GetBrowserPluginGuest();
657 if (guest && guest->embedder_web_contents()) {
658 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
659 }
660 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
661}
662
[email protected]4aebbca2013-09-17 22:26:49663RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
664 const {
665 RenderWidgetHost* const widget_host =
666 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
667 GetFullscreenWidgetRoutingID());
668 return widget_host ? widget_host->GetView() : NULL;
669}
670
[email protected]8ff00d72012-10-23 19:12:21671WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31672 return view_.get();
673}
674
[email protected]8ff00d72012-10-23 19:12:21675WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56676 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03677 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
678 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22679 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58680 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22681 web_ui->SetController(controller);
682 return web_ui;
683 }
684
685 delete web_ui;
686 return NULL;
687}
688
[email protected]8ff00d72012-10-23 19:12:21689WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21690 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
691 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31692}
693
[email protected]8ff00d72012-10-23 19:12:21694WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21695 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34696}
697
[email protected]86ef6a392012-05-11 22:03:11698void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22699 if (GetUserAgentOverride() == override)
700 return;
701
702 renderer_preferences_.user_agent_override = override;
703
704 // Send the new override string to the renderer.
705 RenderViewHost* host = GetRenderViewHost();
706 if (host)
707 host->SyncRendererPrefs();
708
709 // Reload the page if a load is currently in progress to avoid having
710 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27711 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22712 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
713 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53714
715 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
716 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11717}
718
719const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22720 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11721}
722
[email protected]c73a2282013-04-29 21:10:41723#if defined(OS_WIN) && defined(USE_AURA)
724void WebContentsImpl::SetParentNativeViewAccessible(
725gfx::NativeViewAccessible accessible_parent) {
726 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45727 if (GetRenderViewHost())
728 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41729}
730#endif
731
[email protected]fcf75d42013-12-03 20:11:26732const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55733 // Transient entries take precedence. They are used for interstitial pages
734 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23735 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08736 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21737 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30738 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23739 if (entry) {
[email protected]b5cca982011-05-26 04:42:08740 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23741 }
[email protected]fa944cb82013-11-15 17:51:21742 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
743 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58744 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54745 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32746 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54747 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35748 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26749 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54750 if (!title.empty())
751 return title;
752 }
753 }
754
755 // We use the title for the last committed entry rather than a pending
756 // navigation entry. For example, when the user types in a URL, we want to
757 // keep the old page's title until the new load has committed and we get a new
758 // title.
[email protected]96d185d2009-04-24 03:28:54759 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32760
[email protected]9eeafc012013-11-25 23:49:47761 // We make an exception for initial navigations.
762 if (controller_.IsInitialNavigation()) {
763 // We only want to use the title from the visible entry in one of two cases:
764 // 1. There's already a committed entry for an initial navigation, in which
765 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
766 // 2. The pending entry has been explicitly assigned a title to display.
767 //
768 // If there's no last committed entry and no assigned title, we should fall
769 // back to |page_title_when_no_navigation_entry_| rather than showing the
770 // URL.
771 if (entry ||
772 (controller_.GetVisibleEntry() &&
773 !controller_.GetVisibleEntry()->GetTitle().empty())) {
774 entry = controller_.GetVisibleEntry();
775 }
776 }
[email protected]59167c22013-06-03 18:07:32777
[email protected]45d0ef7f2011-01-05 13:46:23778 if (entry) {
[email protected]b5cca982011-05-26 04:42:08779 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23780 }
[email protected]987fc3a2011-05-26 14:18:09781
782 // |page_title_when_no_navigation_entry_| is finally used
783 // if no title cannot be retrieved.
784 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54785}
786
[email protected]b172aee2012-04-10 17:05:26787int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46788 return GetMaxPageIDForSiteInstance(GetSiteInstance());
789}
790
[email protected]b172aee2012-04-10 17:05:26791int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
792 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33793 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
794 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46795
[email protected]b6583592012-01-25 19:52:33796 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34797}
798
[email protected]b172aee2012-04-10 17:05:26799void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46800 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
801}
802
[email protected]b172aee2012-04-10 17:05:26803void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33804 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46805 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33806 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34807}
808
[email protected]ec6c05f2013-10-23 18:41:57809void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
810 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
811 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57812}
813
[email protected]b172aee2012-04-10 17:05:26814SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21815 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54816}
817
[email protected]b172aee2012-04-10 17:05:26818SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21819 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
820 GetRenderManager()->pending_render_view_host() :
821 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58822 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38823}
824
[email protected]b172aee2012-04-10 17:05:26825bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31826 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49827}
828
[email protected]b172aee2012-04-10 17:05:26829bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31830 return waiting_for_response_;
831}
832
[email protected]b172aee2012-04-10 17:05:26833const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31834 return load_state_;
835}
836
[email protected]fcf75d42013-12-03 20:11:26837const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31838 return load_state_host_;
839}
840
[email protected]b172aee2012-04-10 17:05:26841uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31842 return upload_size_;
843}
844
[email protected]b172aee2012-04-10 17:05:26845uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31846 return upload_position_;
847}
848
[email protected]1ae93fb2013-06-14 03:38:56849std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56850 std::set<GURL> sites;
[email protected]9b159a52013-10-03 17:24:55851 frame_tree_.ForEach(Bind(&CollectSites,
852 base::Unretained(GetBrowserContext()),
853 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56854 return sites;
855}
856
[email protected]b172aee2012-04-10 17:05:26857const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31858 return encoding_;
859}
860
[email protected]b172aee2012-04-10 17:05:26861bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31862 return displayed_insecure_content_;
863}
864
[email protected]54597982013-02-06 01:59:55865void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25866 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55867 ++capturer_count_;
868 DVLOG(1) << "There are now " << capturer_count_
869 << " capturing(s) of WebContentsImpl@" << this;
870}
871
872void WebContentsImpl::DecrementCapturerCount() {
873 --capturer_count_;
874 DVLOG(1) << "There are now " << capturer_count_
875 << " capturing(s) of WebContentsImpl@" << this;
876 DCHECK_LE(0, capturer_count_);
877
[email protected]5a652232013-02-12 06:15:25878 if (is_being_destroyed_)
879 return;
880
[email protected]1ac10dca2013-08-20 20:47:04881 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55882 DVLOG(1) << "Executing delayed WasHidden().";
883 WasHidden();
884 }
[email protected]be1f56ab2011-12-22 06:55:31885}
886
[email protected]f2bd40812013-07-20 04:30:44887int WebContentsImpl::GetCapturerCount() const {
888 return capturer_count_;
889}
890
[email protected]b172aee2012-04-10 17:05:26891bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31892 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
893 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
894 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49895}
896
[email protected]b172aee2012-04-10 17:05:26897void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
898 int error_code) {
[email protected]443b80e2010-12-14 00:42:23899 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34900 return;
901
[email protected]443b80e2010-12-14 00:42:23902 crashed_status_ = status;
903 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21904 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34905}
906
[email protected]b172aee2012-04-10 17:05:26907base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31908 return crashed_status_;
909}
910
[email protected]b172aee2012-04-10 17:05:26911bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31912 return is_being_destroyed_;
913}
914
[email protected]b172aee2012-04-10 17:05:26915void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34916 if (delegate_)
917 delegate_->NavigationStateChanged(this, changed_flags);
918}
919
[email protected]3e324142012-06-25 18:26:33920base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
921 return last_selected_time_;
922}
923
[email protected]9e2e4632012-07-27 16:38:41924void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54925 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04926 RenderWidgetHostViewPort* rwhv =
927 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16928 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29929 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43930#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16931 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43932#endif
933 }
[email protected]96d185d2009-04-24 03:28:54934
[email protected]5ac20162010-11-24 23:33:11935 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38936
[email protected]b9769d82012-02-10 00:23:59937 // The resize rect might have changed while this was inactive -- send the new
938 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58939 RenderViewHostImpl* rvh =
940 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59941 if (rvh) {
942 rvh->ResizeRectChanged(GetRootWindowResizerRect());
943 }
[email protected]96d185d2009-04-24 03:28:54944
[email protected]c0d9d5672013-10-09 07:38:03945 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
946
[email protected]54597982013-02-06 01:59:55947 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31948}
949
[email protected]b172aee2012-04-10 17:05:26950void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55951 // If there are entities capturing screenshots or video (e.g., mirroring),
952 // don't activate the "disable rendering" optimization.
953 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52954 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55955 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26956 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52957 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33958 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52959 // calls us).
[email protected]c30585c2012-02-16 15:02:04960 RenderWidgetHostViewPort* rwhv =
961 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16962 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29963 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54964 }
965
[email protected]c0d9d5672013-10-09 07:38:03966 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
967
[email protected]54597982013-02-06 01:59:55968 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37969}
970
[email protected]b172aee2012-04-10 17:05:26971bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31972 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27973 return WillNotifyDisconnection() &&
974 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58975 !static_cast<RenderViewHostImpl*>(
976 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31977}
978
[email protected]b172aee2012-04-10 17:05:26979void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:21980 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:40981 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:27982}
983
[email protected]b172aee2012-04-10 17:05:26984WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44985 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:45986 // We pass our own opener so that the cloned page can access it if it was
987 // before.
[email protected]54944cde2012-12-09 09:24:59988 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:45989 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:59990 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:19991 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:22992 FOR_EACH_OBSERVER(WebContentsObserver,
993 observers_,
994 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:27995 return tc;
996}
997
[email protected]14392a52012-05-02 20:28:44998void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:21999 const NotificationSource& source,
1000 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441001 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211002 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1003 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501004 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1005 i != pending_widget_views_.end(); ++i) {
1006 if (host->GetView() == i->second) {
1007 pending_widget_views_.erase(i);
1008 break;
1009 }
1010 }
1011 break;
1012 }
[email protected]14392a52012-05-02 20:28:441013 default:
1014 NOTREACHED();
1015 }
1016}
1017
[email protected]ec6c05f2013-10-23 18:41:571018WebContents* WebContentsImpl::GetWebContents() {
1019 return this;
1020}
1021
[email protected]54944cde2012-12-09 09:24:591022void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211023 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361024 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211025 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431026 should_normally_be_visible_ = !params.initially_hidden;
1027
[email protected]fa944cb82013-11-15 17:51:211028 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041029 params.browser_context, params.site_instance, params.routing_id,
1030 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191031
[email protected]8ff00d72012-10-23 19:12:211032 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191033 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271034 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191035 CHECK(render_view_host_delegate_view_);
1036 } else {
[email protected]f8497342013-02-05 22:15:021037 WebContentsViewDelegate* delegate =
1038 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1039
[email protected]59383c782013-04-17 16:43:271040 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381041 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1042 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021043
[email protected]b5a40842012-11-28 15:26:111044 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381045 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431046 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111047 render_view_host_delegate_view_ = rv;
1048 view_.reset(rv);
1049 } else {
[email protected]f8497342013-02-05 22:15:021050 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111051 view_.reset(CreateWebContentsView(
1052 this, delegate, &render_view_host_delegate_view_));
1053 }
[email protected]d1198fd2012-08-13 22:50:191054 CHECK(render_view_host_delegate_view_);
1055 }
1056 CHECK(view_.get());
1057
[email protected]ed245db2012-12-18 08:00:451058 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591059 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191060
1061 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101062 if (opener_)
1063 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191064
1065 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211066 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1067 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441068#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191069 java_bridge_dispatcher_host_manager_.reset(
1070 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101071 date_time_chooser_.reset(new DateTimeChooserAndroid());
1072#endif
[email protected]d1198fd2012-08-13 22:50:191073}
1074
[email protected]7fff43e2013-05-21 20:21:101075void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1076 RemoveDestructionObserver(web_contents);
1077
[email protected]14392a52012-05-02 20:28:441078 // Clear the opener if it has been closed.
1079 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441080 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511081 return;
[email protected]14392a52012-05-02 20:28:441082 }
[email protected]ceee8cd2013-03-08 04:59:511083 // Clear a pending contents that has been closed before being shown.
1084 for (PendingContents::iterator iter = pending_contents_.begin();
1085 iter != pending_contents_.end();
1086 ++iter) {
1087 if (iter->second != web_contents)
1088 continue;
1089 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511090 return;
1091 }
1092 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441093}
1094
[email protected]7fff43e2013-05-21 20:21:101095void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1096 if (!ContainsKey(destruction_observers_, web_contents)) {
1097 destruction_observers_[web_contents] =
1098 new DestructionObserver(this, web_contents);
1099 }
1100}
1101
1102void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1103 DestructionObservers::iterator iter =
1104 destruction_observers_.find(web_contents);
1105 if (iter != destruction_observers_.end()) {
1106 delete destruction_observers_[web_contents];
1107 destruction_observers_.erase(iter);
1108 }
1109}
1110
[email protected]b172aee2012-04-10 17:05:261111void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311112 observers_.AddObserver(observer);
1113}
1114
[email protected]b172aee2012-04-10 17:05:261115void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311116 observers_.RemoveObserver(observer);
1117}
1118
[email protected]b172aee2012-04-10 17:05:261119void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341120 if (delegate_)
1121 delegate_->ActivateContents(this);
1122}
1123
[email protected]b172aee2012-04-10 17:05:261124void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121125 if (delegate_)
1126 delegate_->DeactivateContents(this);
1127}
1128
[email protected]b172aee2012-04-10 17:05:261129void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481130 if (delegate_)
1131 delegate_->LostCapture();
1132}
1133
[email protected]b24b68a2012-09-24 21:57:261134void WebContentsImpl::RenderWidgetDeleted(
1135 RenderWidgetHostImpl* render_widget_host) {
1136 if (is_being_destroyed_) {
1137 // |created_widgets_| might have been destroyed.
1138 return;
1139 }
1140
1141 std::set<RenderWidgetHostImpl*>::iterator iter =
1142 created_widgets_.find(render_widget_host);
1143 if (iter != created_widgets_.end())
1144 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541145
1146 if (render_widget_host &&
1147 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491148 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1149 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541150 FOR_EACH_OBSERVER(WebContentsObserver,
1151 observers_,
1152 DidDestroyFullscreenWidget(
1153 fullscreen_widget_routing_id_));
1154 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1155 }
[email protected]b24b68a2012-09-24 21:57:261156}
1157
[email protected]b172aee2012-04-10 17:05:261158bool WebContentsImpl::PreHandleKeyboardEvent(
1159 const NativeWebKeyboardEvent& event,
1160 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481161 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131162 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481163}
1164
[email protected]b172aee2012-04-10 17:05:261165void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061166 if (browser_plugin_embedder_ &&
1167 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1168 return;
1169 }
1170
[email protected]63954792011-07-11 04:17:481171 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131172 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481173}
1174
[email protected]fb3f066e2013-02-12 19:12:521175bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461176 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191177#if !defined(OS_MACOSX)
1178 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1179 // isn't done for two reasons:
1180 // -the OS already has a gesture to do this through pinch-zoom
1181 // -if a user starts an inertial scroll, let's go, and presses control
1182 // (i.e. control+tab) then the OS's buffered scroll events will come in
1183 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521184 if (delegate_ &&
1185 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461186 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521187 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1188 return true;
1189 }
[email protected]bccc4472013-04-18 16:37:191190#endif
[email protected]fb3f066e2013-02-12 19:12:521191
1192 return false;
1193}
1194
[email protected]c73a2282013-04-29 21:10:411195#if defined(OS_WIN) && defined(USE_AURA)
1196gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1197 return accessible_parent_;
1198}
1199#endif
1200
[email protected]b172aee2012-04-10 17:05:261201void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431202 if (delegate_)
1203 delegate_->HandleMouseDown();
1204}
1205
[email protected]b172aee2012-04-10 17:05:261206void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481207 if (delegate_)
1208 delegate_->HandleMouseUp();
1209}
1210
[email protected]590a634e2012-07-19 16:38:231211void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481212 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231213 delegate_->HandlePointerActivate();
1214}
1215
1216void WebContentsImpl::HandleGestureBegin() {
1217 if (delegate_)
1218 delegate_->HandleGestureBegin();
1219}
1220
1221void WebContentsImpl::HandleGestureEnd() {
1222 if (delegate_)
1223 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481224}
1225
[email protected]b172aee2012-04-10 17:05:261226void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491227 // This method is being called to enter or leave renderer-initiated fullscreen
1228 // mode. Either way, make sure any existing fullscreen widget is shut down
1229 // first.
1230 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1231 if (widget_view)
1232 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1233
[email protected]8a5e0ca2011-08-25 06:30:471234 if (delegate_)
1235 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1236}
1237
[email protected]b172aee2012-04-10 17:05:261238bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381239 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121240}
1241
[email protected]a9c81f02012-06-01 00:15:441242void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1243 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371244 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441245 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371246 } else {
1247 GotResponseToLockMouseRequest(false);
1248 }
1249}
1250
[email protected]b172aee2012-04-10 17:05:261251void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371252 if (delegate_)
1253 delegate_->LostMouseLock();
1254}
1255
[email protected]bafe6cd2012-05-23 23:09:501256void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201257 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501258 int route_id,
[email protected]227692c52013-05-31 22:43:041259 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131260 const ViewHostMsg_CreateWindow_Params& params,
1261 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501262 // We usually create the new window in the same BrowsingInstance (group of
1263 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551264 // if the opener is being suppressed (in a non-guest), we create a new
1265 // SiteInstance in its own BrowsingInstance.
1266 bool is_guest = GetRenderProcessHost()->IsGuest();
1267
[email protected]04cbd3d2013-12-04 04:58:201268 // If the opener is to be suppressed, the new window can be in any process.
1269 // Since routing ids are process specific, we must not have one passed in
1270 // as argument here.
1271 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1272
[email protected]bafe6cd2012-05-23 23:09:501273 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551274 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571275 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501276 GetSiteInstance();
1277
[email protected]04cbd3d2013-12-04 04:58:201278 // A message to create a new window can only come from the active process for
1279 // this WebContentsImpl instance. If any other process sends the request,
1280 // it is invalid and the process must be terminated.
1281 if (GetRenderProcessHost()->GetID() != render_process_id) {
1282 base::ProcessHandle process_handle =
1283 RenderProcessHost::FromID(render_process_id)->GetHandle();
1284 if (process_handle != base::kNullProcessHandle) {
1285 RecordAction(
1286 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
1287 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1288 }
1289 return;
1290 }
1291
[email protected]d1198fd2012-08-13 22:50:191292 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341293 //
1294 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301295 const std::string& partition_id =
1296 GetContentClient()->browser()->
1297 GetStoragePartitionIdForSite(GetBrowserContext(),
1298 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461299 StoragePartition* partition = BrowserContext::GetStoragePartition(
1300 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411301 DOMStorageContextWrapper* dom_storage_context =
1302 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191303 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1304 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1305 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371306
1307 if (delegate_ &&
1308 !delegate_->ShouldCreateWebContents(this,
1309 route_id,
1310 params.window_container_type,
1311 params.frame_name,
1312 params.target_url,
1313 partition_id,
1314 session_storage_namespace)) {
1315 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1316 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1317 main_frame_route_id);
1318 return;
1319 }
1320
1321 // Create the new web contents. This will automatically create the new
1322 // WebContentsView. In the future, we may want to create the view separately.
1323 WebContentsImpl* new_contents =
1324 new WebContentsImpl(GetBrowserContext(),
1325 params.opener_suppressed ? NULL : this);
1326
[email protected]d1198fd2012-08-13 22:50:191327 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301328 partition_id,
[email protected]d1198fd2012-08-13 22:50:191329 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461330 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591331 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041332 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551333 if (!is_guest) {
1334 create_params.context = view_->GetNativeView();
1335 create_params.initial_size = view_->GetContainerSize();
1336 } else {
1337 // This makes |new_contents| act as a guest.
1338 // For more info, see comment above class BrowserPluginGuest.
1339 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1340 WebContentsImpl* new_contents_impl =
1341 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461342 BrowserPluginGuest::CreateWithOpener(instance_id,
1343 new_contents_impl->opener() != NULL,
1344 new_contents_impl,
1345 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551346 }
[email protected]1ac10dca2013-08-20 20:47:041347 if (params.disposition == NEW_BACKGROUND_TAB)
1348 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591349 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191350
[email protected]c4538072013-03-18 02:17:551351 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341352 // will be shown immediately).
1353 if (!params.opener_suppressed) {
1354 if (!is_guest) {
1355 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501356
[email protected]d70bea92013-04-05 04:23:341357 // TODO(brettw): It seems bogus that we have to call this function on the
1358 // newly created object and give it one of its own member variables.
1359 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1360 }
[email protected]bafe6cd2012-05-23 23:09:501361 // Save the created window associated with the route so we can show it
1362 // later.
1363 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1364 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101365 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501366 }
1367
1368 if (delegate_) {
1369 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131370 this, params.opener_frame_id, params.frame_name,
1371 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501372 }
1373
1374 if (params.opener_suppressed) {
1375 // When the opener is suppressed, the original renderer cannot access the
1376 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001377 bool was_blocked = false;
1378 if (delegate_) {
1379 gfx::Rect initial_pos;
1380 delegate_->AddNewContents(
1381 this, new_contents, params.disposition, initial_pos,
1382 params.user_gesture, &was_blocked);
1383 }
1384 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211385 OpenURLParams open_params(params.target_url,
1386 Referrer(),
1387 CURRENT_TAB,
1388 PAGE_TRANSITION_LINK,
1389 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301390 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001391 new_contents->OpenURL(open_params);
1392 }
[email protected]bafe6cd2012-05-23 23:09:501393 }
1394}
1395
1396void WebContentsImpl::CreateNewWidget(int route_id,
[email protected]180ef242013-11-07 06:50:461397 blink::WebPopupType popup_type) {
[email protected]bafe6cd2012-05-23 23:09:501398 CreateNewWidget(route_id, false, popup_type);
1399}
1400
1401void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
[email protected]180ef242013-11-07 06:50:461402 CreateNewWidget(route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501403}
1404
1405void WebContentsImpl::CreateNewWidget(int route_id,
1406 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461407 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211408 RenderProcessHost* process = GetRenderProcessHost();
[email protected]bafe6cd2012-05-23 23:09:501409 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041410 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261411 created_widgets_.insert(widget_host);
1412
[email protected]83918ec2013-01-10 15:37:191413 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1414 view_->CreateViewForPopupWidget(widget_host));
1415 if (!widget_view)
1416 return;
[email protected]bafe6cd2012-05-23 23:09:501417 if (!is_fullscreen) {
1418 // Popups should not get activated.
1419 widget_view->SetPopupType(popup_type);
1420 }
1421 // Save the created widget associated with the route so we can show it later.
1422 pending_widget_views_[route_id] = widget_view;
1423
1424#if defined(OS_MACOSX)
1425 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1426 // to allow it to survive the trip without being hosted.
1427 base::mac::NSObjectRetain(widget_view->GetNativeView());
1428#endif
1429}
1430
1431void WebContentsImpl::ShowCreatedWindow(int route_id,
1432 WindowOpenDisposition disposition,
1433 const gfx::Rect& initial_pos,
1434 bool user_gesture) {
1435 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001436 if (contents) {
1437 WebContentsDelegate* delegate = GetDelegate();
1438 if (delegate) {
1439 delegate->AddNewContents(
1440 this, contents, disposition, initial_pos, user_gesture, NULL);
1441 }
1442 }
[email protected]bafe6cd2012-05-23 23:09:501443}
1444
1445void WebContentsImpl::ShowCreatedWidget(int route_id,
1446 const gfx::Rect& initial_pos) {
1447 ShowCreatedWidget(route_id, false, initial_pos);
1448}
1449
1450void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1451 ShowCreatedWidget(route_id, true, gfx::Rect());
1452}
1453
1454void WebContentsImpl::ShowCreatedWidget(int route_id,
1455 bool is_fullscreen,
1456 const gfx::Rect& initial_pos) {
1457 if (delegate_)
1458 delegate_->RenderWidgetShowing();
1459
1460 RenderWidgetHostViewPort* widget_host_view =
1461 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1462 if (!widget_host_view)
1463 return;
[email protected]4aebbca2013-09-17 22:26:491464 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311465 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1466 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491467 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1468 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1469 delegate_->ToggleFullscreenModeForTab(this, true);
1470 } else {
1471 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491472 }
[email protected]4aebbca2013-09-17 22:26:491473 FOR_EACH_OBSERVER(WebContentsObserver,
1474 observers_,
1475 DidShowFullscreenWidget(route_id));
1476 if (!widget_host_view->HasFocus())
1477 widget_host_view->Focus();
1478 } else {
[email protected]f8497342013-02-05 22:15:021479 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491480 }
[email protected]89054502012-06-03 10:29:241481
1482 RenderWidgetHostImpl* render_widget_host_impl =
1483 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1484 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311485 // Only allow privileged mouse lock for fullscreen render widget, which is
1486 // used to implement Pepper Flash fullscreen.
1487 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501488
1489#if defined(OS_MACOSX)
1490 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1491 // properly embedded (or purposefully ignored) we can release the retain we
1492 // took in CreateNewWidget().
1493 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1494#endif
1495}
1496
1497WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1498 PendingContents::iterator iter = pending_contents_.find(route_id);
1499
1500 // Certain systems can block the creation of new windows. If we didn't succeed
1501 // in creating one, just return NULL.
1502 if (iter == pending_contents_.end()) {
1503 return NULL;
1504 }
1505
1506 WebContentsImpl* new_contents = iter->second;
1507 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101508 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501509
[email protected]d70bea92013-04-05 04:23:341510 // Don't initialize the guest WebContents immediately.
1511 if (new_contents->GetRenderProcessHost()->IsGuest())
1512 return new_contents;
1513
[email protected]bafe6cd2012-05-23 23:09:501514 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1515 !new_contents->GetRenderViewHost()->GetView())
1516 return NULL;
1517
1518 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1519 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1520 return new_contents;
1521}
1522
1523RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1524 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1525 if (iter == pending_widget_views_.end()) {
1526 DCHECK(false);
1527 return NULL;
1528 }
1529
1530 RenderWidgetHostView* widget_host_view = iter->second;
1531 pending_widget_views_.erase(route_id);
1532
1533 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1534 if (!widget_host->GetProcess()->HasConnection()) {
1535 // The view has gone away or the renderer crashed. Nothing to do.
1536 return NULL;
1537 }
1538
1539 return widget_host_view;
1540}
1541
[email protected]f56c7872013-06-18 12:31:571542void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501543 // Allow WebContentsDelegates to handle the context menu operation first.
1544 if (delegate_ && delegate_->HandleContextMenu(params))
1545 return;
1546
[email protected]f56c7872013-06-18 12:31:571547 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501548}
1549
[email protected]f13b4202012-06-12 23:53:231550void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091551 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211552 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231553 if (delegate_)
1554 delegate_->RequestMediaAccessPermission(this, request, callback);
1555 else
[email protected]b5f76742013-04-29 15:05:591556 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231557}
1558
[email protected]cc9200432013-07-23 23:02:401559SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1560 SiteInstance* instance) {
1561 return controller_.GetSessionStorageNamespace(instance);
1562}
1563
[email protected]9b159a52013-10-03 17:24:551564FrameTree* WebContentsImpl::GetFrameTree() {
1565 return &frame_tree_;
1566}
1567
[email protected]32deec62013-05-15 23:55:041568void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1569 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441570 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041571}
1572
[email protected]b172aee2012-04-10 17:05:261573void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231574 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331575 if (delegate_)
1576 delegate_->UpdatePreferredSize(this, pref_size);
1577}
1578
[email protected]b172aee2012-04-10 17:05:261579void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341580 if (delegate_)
1581 delegate_->ResizeDueToAutoResize(this, new_size);
1582}
1583
[email protected]b172aee2012-04-10 17:05:261584WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201585 if (!delegate_)
1586 return NULL;
[email protected]00c37fc2011-08-02 00:22:501587
[email protected]e5d549d2011-12-28 01:29:201588 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201589 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341590}
1591
[email protected]6b618e62012-08-16 12:59:181592bool WebContentsImpl::Send(IPC::Message* message) {
1593 if (!GetRenderViewHost()) {
1594 delete message;
1595 return false;
1596 }
1597
1598 return GetRenderViewHost()->Send(message);
1599}
1600
[email protected]b172aee2012-04-10 17:05:261601bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501602 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251603 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231604 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251605 reload_type);
[email protected]876bc832010-09-07 16:29:541606}
[email protected]96d185d2009-04-24 03:28:541607
[email protected]ba45bfd2012-05-22 21:51:441608void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211609 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441610 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1611 RenderViewForInterstitialPageCreated(render_view_host));
1612}
1613
[email protected]20ca0382013-02-28 19:50:071614void WebContentsImpl::AttachInterstitialPage(
1615 InterstitialPageImpl* interstitial_page) {
1616 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211617 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291618
1619 // Cancel any visible dialogs so that they don't interfere with the
1620 // interstitial.
1621 if (dialog_manager_)
1622 dialog_manager_->CancelActiveAndPendingDialogs(this);
1623
[email protected]20ca0382013-02-28 19:50:071624 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1625 DidAttachInterstitialPage());
1626}
1627
1628void WebContentsImpl::DetachInterstitialPage() {
1629 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211630 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071631 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1632 DidDetachInterstitialPage());
1633}
1634
[email protected]b172aee2012-04-10 17:05:261635bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231636 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501637 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031638 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1639
[email protected]19e81142011-10-03 16:19:401640 // The renderer will reject IPC messages with URLs longer than
1641 // this limit, so don't attempt to navigate with a longer URL.
[email protected]3adab1c2013-09-09 21:23:431642 if (entry.GetURL().spec().size() > kMaxURLChars) {
1643 LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars
1644 << " characters.";
[email protected]19e81142011-10-03 16:19:401645 return false;
[email protected]3adab1c2013-09-09 21:23:431646 }
[email protected]19e81142011-10-03 16:19:401647
[email protected]c80297782013-11-21 07:10:161648 // TODO(creis): Use entry->frame_tree_node_id() to pick which
[email protected]b0936d22013-11-28 06:47:361649 // RenderFrameHostManager to use.
[email protected]9f76c1e2012-03-05 15:15:581650 RenderViewHostImpl* dest_render_view_host =
[email protected]fa944cb82013-11-15 17:51:211651 static_cast<RenderViewHostImpl*>(GetRenderManager()->Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401652 if (!dest_render_view_host)
1653 return false; // Unable to create the desired render view host.
1654
[email protected]80a8fad2011-01-29 04:02:381655 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071656 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581657 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271658 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501659 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031660 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1661 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211662 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231663 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271664 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211665 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231666 CHECK(0);
1667 }
[email protected]54ec6472010-04-09 19:39:581668
[email protected]7bb761892012-07-20 09:32:471669 // Notify observers that we will navigate in this RV.
1670 FOR_EACH_OBSERVER(WebContentsObserver,
1671 observers_,
1672 AboutToNavigateRenderView(dest_render_view_host));
1673
[email protected]96d185d2009-04-24 03:28:541674 // Used for page load time metrics.
1675 current_load_start_ = base::TimeTicks::Now();
1676
1677 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341678 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271679 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471680 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341681 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541682
[email protected]36fc0392011-12-25 03:59:511683 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541684 // HACK!! This code suppresses javascript: URLs from being added to
1685 // session history, which is what we want to do for javascript: URLs that
1686 // do not generate content. What we really need is a message from the
1687 // renderer telling us that a new page was not created. The same message
1688 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351689 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541690 return false;
1691 }
1692
[email protected]3c9e1872010-11-18 16:17:491693 // Notify observers about navigation.
[email protected]0661cee2013-11-23 21:22:391694 FOR_EACH_OBSERVER(
1695 WebContentsObserver,
1696 observers_,
1697 DidStartNavigationToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541698
[email protected]09b29342011-06-24 19:18:481699 if (delegate_)
1700 delegate_->DidNavigateToPendingEntry(this);
1701
[email protected]d5f942ba2008-09-26 19:30:341702 return true;
1703}
1704
[email protected]b172aee2012-04-10 17:05:261705void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331706 const SiteInstance* site_instance,
1707 int history_length,
1708 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411709 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1710 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211711 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191712 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141713 return;
[email protected]9e1ad4b2011-08-14 16:49:191714 }
[email protected]9f76c1e2012-03-05 15:15:581715 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191716 if (!rvh) {
1717 NOTREACHED();
1718 return;
1719 }
[email protected]9f76c1e2012-03-05 15:15:581720 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191721 NOTREACHED();
1722 return;
1723 }
[email protected]6b618e62012-08-16 12:59:181724 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1725 history_length,
1726 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141727}
1728
[email protected]b172aee2012-04-10 17:05:261729void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271730 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211731 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541732 return;
1733 }
[email protected]9f76c1e2012-03-05 15:15:581734 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541735}
1736
[email protected]b172aee2012-04-10 17:05:261737bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211738 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541739}
1740
[email protected]b172aee2012-04-10 17:05:261741InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211742 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221743}
1744
[email protected]b172aee2012-04-10 17:05:261745bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161746 // WebKit creates Document object when MIME type is application/xhtml+xml,
1747 // so we also support this MIME type.
1748 return contents_mime_type_ == "text/html" ||
1749 contents_mime_type_ == "text/xml" ||
1750 contents_mime_type_ == "application/xhtml+xml" ||
1751 contents_mime_type_ == "text/plain" ||
1752 contents_mime_type_ == "text/css" ||
1753 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1754}
1755
[email protected]b172aee2012-04-10 17:05:261756void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591757 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161758 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551759 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011760 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141761 return;
[email protected]c7dd2f62011-07-18 15:57:591762 }
1763
1764 Stop();
1765
1766 // Create the save package and possibly prompt the user for the name to save
1767 // the page as. The user prompt is an asynchronous operation that runs on
1768 // another thread.
1769 save_package_ = new SavePackage(this);
1770 save_package_->GetSaveInfo();
1771}
1772
1773// Used in automated testing to bypass prompting the user for file names.
1774// Instead, the names and paths are hard coded rather than running them through
1775// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341776bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1777 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211778 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591779 // Stop the page from navigating.
1780 Stop();
1781
1782 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211783 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591784}
1785
[email protected]3c71576ce2013-07-23 02:00:011786void WebContentsImpl::SaveFrame(const GURL& url,
1787 const Referrer& referrer) {
1788 if (!GetURL().is_valid())
1789 return;
1790 bool is_main_frame = (url == GetURL());
1791
1792 DownloadManager* dlm =
1793 BrowserContext::GetDownloadManager(GetBrowserContext());
1794 if (!dlm)
1795 return;
1796 int64 post_id = -1;
1797 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271798 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011799 if (entry)
1800 post_id = entry->GetPostID();
1801 }
1802 scoped_ptr<DownloadUrlParameters> params(
1803 DownloadUrlParameters::FromWebContents(this, url));
1804 params->set_referrer(referrer);
1805 params->set_post_id(post_id);
1806 params->set_prefer_cache(true);
1807 if (post_id >= 0)
1808 params->set_method("POST");
1809 params->set_prompt(true);
1810 dlm->DownloadUrl(params.Pass());
1811}
1812
[email protected]b172aee2012-04-10 17:05:261813void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341814 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481815 const base::Callback<void(int64)>& callback) {
1816 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121817}
1818
[email protected]6286a372013-10-09 04:03:271819// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261820bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271821 NavigationEntryImpl* visible_entry =
1822 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1823 return (visible_entry != NULL &&
1824 visible_entry->site_instance() == GetSiteInstance() &&
1825 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321826}
1827
[email protected]b172aee2012-04-10 17:05:261828const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271829 return contents_mime_type_;
1830}
1831
[email protected]b172aee2012-04-10 17:05:261832bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271833 return notify_disconnection_;
1834}
1835
[email protected]b172aee2012-04-10 17:05:261836void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311837 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181838 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161839}
1840
[email protected]b172aee2012-04-10 17:05:261841void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311842 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181843 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161844}
1845
[email protected]8ff00d72012-10-23 19:12:211846RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271847 return &renderer_preferences_;
1848}
1849
[email protected]e35ccd52012-05-23 16:22:471850void WebContentsImpl::Close() {
1851 Close(GetRenderViewHost());
1852}
1853
[email protected]cf200a562013-05-03 16:24:291854void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461855 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291856 if (browser_plugin_embedder_.get())
1857 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1858 screen_x, screen_y, operation);
1859 if (GetRenderViewHost())
1860 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1861 screen_x, screen_y, operation);
1862}
1863
1864void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1865 int screen_x, int screen_y) {
1866 if (browser_plugin_embedder_.get())
1867 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1868 screen_x, screen_y);
1869 if (GetRenderViewHost())
1870 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1871 screen_x, screen_y);
1872}
1873
[email protected]b172aee2012-04-10 17:05:261874void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521875 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581876 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511877 if (delegate_)
1878 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291879 if (browser_plugin_embedder_.get())
1880 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341881}
1882
[email protected]e35ccd52012-05-23 16:22:471883void WebContentsImpl::UserGestureDone() {
1884 OnUserGesture();
1885}
1886
[email protected]b172aee2012-04-10 17:05:261887void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271888 closed_by_user_gesture_ = value;
1889}
1890
[email protected]b172aee2012-04-10 17:05:261891bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271892 return closed_by_user_gesture_;
1893}
1894
[email protected]b172aee2012-04-10 17:05:261895double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051896 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561897 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251898 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171899 return 0;
[email protected]b75b8292010-10-01 07:28:251900
1901 double zoom_level;
1902 if (temporary_zoom_settings_) {
1903 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581904 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251905 } else {
[email protected]2ae88d12011-10-14 09:11:191906 GURL url;
[email protected]6286a372013-10-09 04:03:271907 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191908 // Since zoom map is updated using rewritten URL, use rewritten URL
1909 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271910 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021911 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1912 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251913 }
[email protected]d0b8d092010-10-25 04:05:171914 return zoom_level;
1915}
[email protected]b75b8292010-10-01 07:28:251916
[email protected]b172aee2012-04-10 17:05:261917int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591918 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171919 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011920 // Calculate the zoom percent from the factor. Round up to the nearest whole
1921 // number.
[email protected]b75b8292010-10-01 07:28:251922 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491923 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251924 *enable_decrement = percent > minimum_zoom_percent_;
1925 *enable_increment = percent < maximum_zoom_percent_;
1926 return percent;
1927}
1928
[email protected]b172aee2012-04-10 17:05:261929void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501930 if (!delegate_)
1931 return;
1932
[email protected]6286a372013-10-09 04:03:271933 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1934 if (!entry)
[email protected]1788e772010-12-15 16:40:501935 return;
1936
[email protected]6286a372013-10-09 04:03:271937 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121938}
1939
[email protected]b172aee2012-04-10 17:05:261940void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041941 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271942 if (!delegate_)
1943 return;
1944
[email protected]691aa2f2013-05-28 22:52:041945 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271946}
1947
[email protected]b172aee2012-04-10 17:05:261948int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271949 return minimum_zoom_percent_;
1950}
1951
[email protected]b172aee2012-04-10 17:05:261952int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271953 return maximum_zoom_percent_;
1954}
1955
[email protected]b172aee2012-04-10 17:05:261956gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231957 return preferred_size_;
1958}
1959
[email protected]b172aee2012-04-10 17:05:261960bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271961 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581962 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271963}
1964
[email protected]b172aee2012-04-10 17:05:261965bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441966 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501967}
1968
[email protected]cb805452013-05-22 15:16:211969void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181970 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211971 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201972}
1973
[email protected]cb805452013-05-22 15:16:211974void WebContentsImpl::DidEndColorChooser() {
1975 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1976 color_chooser_identifier_));
1977 color_chooser_.reset();
1978 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201979}
1980
[email protected]41225fe2013-03-29 05:32:021981int WebContentsImpl::DownloadImage(const GURL& url,
1982 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301983 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021984 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:391985 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:301986 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:021987 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:391988 return id;
1989}
1990
[email protected]b172aee2012-04-10 17:05:261991bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:271992 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:201993 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:331994 return true;
1995 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:271996}
1997
[email protected]b172aee2012-04-10 17:05:261998void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271999 if (delegate_)
2000 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212001}
2002
[email protected]54047eb52012-05-08 21:45:572003void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:212004 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:572005 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132006 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572007 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:572008 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:212009 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]081dc522013-05-15 04:59:202010 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:182011 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:212012 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572013 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082014 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182015
[email protected]442385d2013-08-09 02:38:412016 if (is_main_frame) {
[email protected]d974a0a2013-01-10 01:43:572017 DidChangeLoadProgress(0);
2018
[email protected]442385d2013-08-09 02:38:412019 // If there is no browser-initiated pending entry for this navigation and it
2020 // is not for the error URL, create a pending entry using the current
2021 // SiteInstance, and ensure the address bar updates accordingly. We don't
2022 // know the referrer or extra headers at this point, but the referrer will
2023 // be set properly upon commit.
[email protected]97d8f0d2013-10-29 16:49:212024 NavigationEntryImpl* pending_entry =
2025 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
[email protected]442385d2013-08-09 02:38:412026 bool has_browser_initiated_pending_entry = pending_entry &&
[email protected]97d8f0d2013-10-29 16:49:212027 !pending_entry->is_renderer_initiated();
[email protected]442385d2013-08-09 02:38:412028 if (!has_browser_initiated_pending_entry && !is_error_page) {
2029 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
2030 controller_.CreateNavigationEntry(validated_url,
2031 content::Referrer(),
2032 content::PAGE_TRANSITION_LINK,
2033 true /* is_renderer_initiated */,
2034 std::string(),
2035 GetBrowserContext()));
2036 entry->set_site_instance(
2037 static_cast<SiteInstanceImpl*>(GetSiteInstance()));
[email protected]3ed682bf2013-10-17 20:56:562038 // TODO(creis): If there's a pending entry already, find a safe way to
2039 // update it instead of replacing it and copying over things like this.
[email protected]97d8f0d2013-10-29 16:49:212040 if (pending_entry) {
2041 entry->set_transferred_global_request_id(
2042 pending_entry->transferred_global_request_id());
2043 entry->set_should_replace_entry(pending_entry->should_replace_entry());
[email protected]f8872902013-10-30 03:18:572044 entry->set_redirect_chain(pending_entry->redirect_chain());
[email protected]3ed682bf2013-10-17 20:56:562045 }
[email protected]442385d2013-08-09 02:38:412046 controller_.SetPendingEntry(entry);
2047 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
2048 }
[email protected]59167c22013-06-03 18:07:322049 }
2050
[email protected]0d60f0192011-04-14 12:40:102051 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252052 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132053 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2054 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322055 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542056
2057 if (is_main_frame) {
2058 // Notify observers about the provisional change in the main frame URL.
2059 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2060 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542061 render_view_host));
2062 }
2063}
2064
2065void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212066 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542067 int32 page_id,
[email protected]400992b2012-06-14 00:03:542068 const GURL& source_url,
2069 const GURL& target_url) {
2070 // TODO(creis): Remove this method and have the pre-rendering code listen to
[email protected]b0f724c2013-09-05 04:21:132071 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
2072 // See http://crbug.com/78512.
[email protected]400992b2012-06-14 00:03:542073 GURL validated_source_url(source_url);
2074 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212075 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542076 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082077 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2078 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542079 NavigationEntry* entry;
2080 if (page_id == -1) {
2081 entry = controller_.GetPendingEntry();
2082 } else {
2083 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2084 page_id);
2085 }
2086 if (!entry || entry->GetURL() != validated_source_url)
2087 return;
2088
2089 // Notify observers about the provisional change in the main frame URL.
2090 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2091 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542092 render_view_host));
[email protected]724159a2010-12-30 01:11:182093}
2094
[email protected]54047eb52012-05-08 21:45:572095void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212096 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582097 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2098 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2099 << ", error_code: " << params.error_code
2100 << ", error_description: " << params.error_description
2101 << ", is_main_frame: " << params.is_main_frame
2102 << ", showing_repost_interstitial: " <<
2103 params.showing_repost_interstitial
2104 << ", frame_id: " << params.frame_id;
2105 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212106 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572107 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082108 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182109
[email protected]d7b175e2011-10-11 15:31:582110 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182111 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2112 // This means that the interstitial won't be torn down properly, which is
2113 // bad. But if we have an interstitial, go back to another tab type, and
2114 // then load the same interstitial again, we could end up getting the first
2115 // interstitial's "failed" message (as a result of the cancel) when we're on
2116 // the second one.
2117 //
2118 // We can't tell this apart, so we think we're tearing down the current page
2119 // which will cause a crash later one. There is also some code in
[email protected]b0936d22013-11-28 06:47:362120 // RenderFrameHostManager::RendererAbortedProvisionalLoad that is commented
[email protected]724159a2010-12-30 01:11:182121 // out because of this problem.
2122 //
2123 // http://code.google.com/p/chromium/issues/detail?id=2855
2124 // Because this will not tear down the interstitial properly, if "back" is
2125 // back to another tab type, the interstitial will still be somewhat alive
2126 // in the previous tab type. If you navigate somewhere that activates the
2127 // tab with the interstitial again, you'll see a flash before the new load
2128 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272129 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182130 LOG(WARNING) << "Discarding message during interstitial.";
2131 return;
2132 }
2133
[email protected]fa944cb82013-11-15 17:51:212134 GetRenderManager()->RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182135 }
2136
[email protected]b12eb222013-09-10 00:11:482137 // Do not usually clear the pending entry if one exists, so that the user's
2138 // typed URL is not lost when a navigation fails or is aborted. However, in
2139 // cases that we don't show the pending entry (e.g., renderer-initiated
2140 // navigations in an existing tab), we don't keep it around. That prevents
2141 // spoofs on in-page navigations that don't go through
2142 // DidStartProvisionalLoadForFrame.
2143 // In general, we allow the view to clear the pending entry and typed URL if
2144 // the user requests (e.g., hitting Escape with focus in the address bar).
2145 // Note: don't touch the transient entry, since an interstitial may exist.
2146 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry())
2147 controller_.DiscardPendingEntry();
2148
[email protected]d8c660432011-12-22 20:51:252149 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582150 observers_,
2151 DidFailProvisionalLoad(params.frame_id,
[email protected]2f673064c2013-10-22 04:01:442152 params.frame_unique_name,
[email protected]d7b175e2011-10-11 15:31:582153 params.is_main_frame,
2154 validated_url,
2155 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462156 params.error_description,
2157 render_view_host));
[email protected]724159a2010-12-30 01:11:182158}
2159
[email protected]b172aee2012-04-10 17:05:262160void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182161 const GURL& url,
[email protected]70435962011-08-02 20:13:282162 const std::string& security_info,
2163 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182164 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282165 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192166 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182167 cache.Increment();
2168
2169 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082170 int cert_id = 0;
2171 net::CertStatus cert_status = 0;
2172 int security_bits = -1;
2173 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122174 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212175 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122176 &security_bits, &connection_status,
2177 &signed_certificate_timestamp_ids);
2178 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212179 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002180 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2181 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182182
[email protected]b0f724c2013-09-05 04:21:132183 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2184
2185 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2186 DidLoadResourceFromMemoryCache(details));
2187
[email protected]8bfc8272013-09-09 20:10:532188 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2189 scoped_refptr<net::URLRequestContextGetter> request_context(
2190 resource_type == ResourceType::MEDIA ?
2191 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2192 GetRenderProcessHost()->GetID()) :
2193 GetBrowserContext()->GetRequestContextForRenderProcess(
2194 GetRenderProcessHost()->GetID()));
2195 BrowserThread::PostTask(
2196 BrowserThread::IO,
2197 FROM_HERE,
2198 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2199 }
[email protected]724159a2010-12-30 01:11:182200}
2201
[email protected]b172aee2012-04-10 17:05:262202void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212203 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182204 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192205 SSLManager::NotifySSLInternalStateChanged(
2206 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182207}
2208
[email protected]b172aee2012-04-10 17:05:262209void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022210 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582211 LOG(WARNING) << security_origin << " ran insecure content from "
2212 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212213 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412214 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212215 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182216 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412217 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192218 SSLManager::NotifySSLInternalStateChanged(
2219 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182220}
2221
[email protected]b172aee2012-04-10 17:05:262222void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]d8c660432011-12-22 20:51:252223 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472224 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182225}
2226
[email protected]b172aee2012-04-10 17:05:262227void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312228 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062229 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312230 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062231 GURL validated_url(url);
2232 RenderProcessHost* render_process_host = message_source_->GetProcess();
2233 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252234 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472235 DidFinishLoad(frame_id, validated_url, is_main_frame,
2236 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312237}
2238
[email protected]b172aee2012-04-10 17:05:262239void WebContentsImpl::OnDidFailLoadWithError(
2240 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062241 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262242 bool is_main_frame,
2243 int error_code,
[email protected]fcf75d42013-12-03 20:11:262244 const base::string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062245 GURL validated_url(url);
2246 RenderProcessHost* render_process_host = message_source_->GetProcess();
2247 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252248 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312249 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472250 error_code, error_description,
2251 message_source_));
[email protected]724159a2010-12-30 01:11:182252}
2253
[email protected]b172aee2012-04-10 17:05:262254void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262255 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232256 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252257 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262258 if (!entry)
2259 return;
2260 // Note that we don't call NavigationController::GotToOffset() as we don't
2261 // want to create a pending navigation entry (it might end up lingering
2262 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252263 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212264 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512265 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212266 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472267 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572268
2269 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2270 // it in now that we know. This allows us to find the entry when it commits.
2271 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232272 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332273 entry->set_site_instance(
2274 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572275 }
[email protected]216813952011-05-19 22:21:262276 }
2277}
2278
[email protected]b172aee2012-04-10 17:05:262279void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2280 int maximum_percent,
2281 bool remember) {
[email protected]216813952011-05-19 22:21:262282 minimum_zoom_percent_ = minimum_percent;
2283 maximum_zoom_percent_ = maximum_percent;
2284 temporary_zoom_settings_ = !remember;
2285}
2286
[email protected]b172aee2012-04-10 17:05:262287void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342288 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432289 if (!delegate_)
2290 return;
2291
[email protected]b9535422012-02-09 01:47:592292 ChildProcessSecurityPolicyImpl* policy =
2293 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222294 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592295 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212296}
2297
[email protected]b172aee2012-04-10 17:05:262298void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432299 if (delegate_)
2300 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202301}
2302
[email protected]b172aee2012-04-10 17:05:262303void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2304 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262305 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362306 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432307 if (!delegate_)
2308 return;
2309
[email protected]b9535422012-02-09 01:47:592310 ChildProcessSecurityPolicyImpl* policy =
2311 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322312 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592313 return;
[email protected]8f810632013-06-06 22:33:322314
[email protected]3a3b75a2012-06-01 08:38:362315 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202316}
2317
[email protected]b172aee2012-04-10 17:05:262318void WebContentsImpl::OnFindReply(int request_id,
2319 int number_of_matches,
2320 const gfx::Rect& selection_rect,
2321 int active_match_ordinal,
2322 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432323 if (delegate_) {
2324 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2325 active_match_ordinal, final_update);
2326 }
[email protected]b888919c2011-09-02 00:32:162327}
2328
[email protected]59363fc92012-09-05 03:46:312329#if defined(OS_ANDROID)
2330void WebContentsImpl::OnFindMatchRectsReply(
2331 int version,
2332 const std::vector<gfx::RectF>& rects,
2333 const gfx::RectF& active_rect) {
2334 if (delegate_)
2335 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2336}
[email protected]583418cc2013-01-17 14:01:102337
[email protected]1ff427972013-02-07 21:14:072338void WebContentsImpl::OnOpenDateTimeDialog(
2339 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092340 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2341 GetRenderViewHost(),
2342 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132343 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092344 value.minimum,
2345 value.maximum,
2346 value.step);
[email protected]583418cc2013-01-17 14:01:102347}
2348
[email protected]a794f3a2013-10-30 17:00:322349void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2350 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
2351 message_source_, reply_msg);
2352}
2353
[email protected]59363fc92012-09-05 03:46:312354#endif
2355
[email protected]2dec8ec2013-02-07 19:20:342356void WebContentsImpl::OnCrashedPlugin(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422357 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442358 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422359 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452360}
2361
[email protected]b172aee2012-04-10 17:05:262362void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2363 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102364 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252365 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102366 AppCacheAccessed(manifest_url, blocked_by_policy));
2367}
2368
[email protected]8bc5ff02013-11-29 06:34:032369void WebContentsImpl::OnOpenColorChooser(
2370 int color_chooser_id,
2371 SkColor color,
2372 const std::vector<ColorSuggestion>& suggestions) {
2373 ColorChooser* new_color_chooser =
2374 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]cb805452013-05-22 15:16:212375 if (color_chooser_ == new_color_chooser)
2376 return;
2377 color_chooser_.reset(new_color_chooser);
2378 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202379}
2380
[email protected]b172aee2012-04-10 17:05:262381void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202382 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212383 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202384 color_chooser_->End();
2385}
2386
[email protected]b172aee2012-04-10 17:05:262387void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322388 SkColor color) {
[email protected]da8543762012-03-20 08:52:202389 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212390 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202391 color_chooser_->SetSelectedColor(color);
2392}
2393
[email protected]9f2a9d72012-04-16 16:02:222394void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
[email protected]2dec8ec2013-02-07 19:20:342395 const base::FilePath& path,
[email protected]9f2a9d72012-04-16 16:02:222396 bool is_hung) {
[email protected]f5eabc372012-10-12 00:33:552397 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2398
[email protected]3fc07c52012-04-20 00:27:442399 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2400 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292401}
2402
[email protected]d0759f492012-04-19 22:50:502403// This exists for render views that don't have a WebUI, but do have WebUI
2404// bindings enabled.
2405void WebContentsImpl::OnWebUISend(const GURL& source_url,
2406 const std::string& name,
2407 const base::ListValue& args) {
2408 if (delegate_)
2409 delegate_->WebUISend(this, source_url, name, args);
2410}
2411
[email protected]d8415ad92012-08-23 14:40:502412void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442413 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502414 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342415 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162416 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442417 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162418 return;
[email protected]d8415ad92012-08-23 14:40:502419 }
2420
[email protected]8c8fc292012-11-23 18:57:162421 if (!delegate_->RequestPpapiBrokerPermission(
2422 this, url, plugin_path,
2423 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442424 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162425 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442426 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162427 }
[email protected]d8415ad92012-08-23 14:40:502428}
2429
[email protected]ea0309c2013-08-06 19:35:442430void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502431 bool result) {
[email protected]ea0309c2013-08-06 19:35:442432 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502433}
2434
[email protected]c4538072013-03-18 02:17:552435void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372436 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082437 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552438 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392439 // For more info, see comment above classes BrowserPluginEmbedder and
2440 // BrowserPluginGuest.
2441 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142442 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082443 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372444}
2445
[email protected]41225fe2013-03-29 05:32:022446void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392447 int id,
[email protected]749fadd2013-05-15 08:37:482448 int http_status_code,
[email protected]795c28972012-12-06 06:13:392449 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302450 const std::vector<SkBitmap>& bitmaps,
2451 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022452 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2453 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392454 // Currently WebContents notifies us of ANY downloads so that it is
2455 // possible to get here.
2456 return;
2457 }
2458 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302459 iter->second.Run(
2460 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392461 }
[email protected]41225fe2013-03-29 05:32:022462 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392463}
2464
2465void WebContentsImpl::OnUpdateFaviconURL(
2466 int32 page_id,
2467 const std::vector<FaviconURL>& candidates) {
2468 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2469 DidUpdateFaviconURL(page_id, candidates));
2470}
2471
[email protected]d9030b82013-07-19 08:26:062472void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2473 bool has_video,
2474 bool has_audio,
2475 bool is_playing) {
2476 // Chrome OS does its own detection of audio and video.
2477#if !defined(OS_CHROMEOS)
2478 if (is_playing) {
2479 scoped_ptr<PowerSaveBlocker> blocker;
2480 if (has_video) {
2481 blocker = PowerSaveBlocker::Create(
2482 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2483 "Playing video");
2484#if defined(OS_ANDROID)
2485 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382486 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062487#endif
2488 } else if (has_audio) {
2489 blocker = PowerSaveBlocker::Create(
2490 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2491 "Playing audio");
2492 }
2493
2494 if (blocker)
2495 power_save_blockers_[message_source_][player_cookie] = blocker.release();
2496 } else {
2497 delete power_save_blockers_[message_source_][player_cookie];
2498 power_save_blockers_[message_source_].erase(player_cookie);
2499 }
2500#endif // !defined(OS_CHROMEOS)
2501}
2502
[email protected]9f268072013-11-07 00:02:152503void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2504 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2505 DidFirstVisuallyNonEmptyPaint(page_id));
2506}
[email protected]d9030b82013-07-19 08:26:062507
[email protected]e67ebf32013-02-13 11:07:192508void WebContentsImpl::DidChangeVisibleSSLState() {
2509 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2510 DidChangeVisibleSSLState());
2511}
2512
[email protected]17e286e2013-03-01 23:29:392513void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2514 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2515 BeforeFormRepostWarningShow());
2516}
2517
[email protected]ec6c05f2013-10-23 18:41:572518
2519void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2520 Activate();
2521 if (delegate_)
2522 delegate_->ShowRepostFormWarningDialog(this);
2523}
2524
[email protected]96d185d2009-04-24 03:28:542525// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592526// loading, or done loading.
2527void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2528 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262529 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542530 if (is_loading == is_loading_)
2531 return;
2532
2533 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262534 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2535 base::string16());
[email protected]96d185d2009-04-24 03:28:542536 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562537 upload_size_ = 0;
2538 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542539 }
2540
[email protected]fa944cb82013-11-15 17:51:212541 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542542
2543 is_loading_ = is_loading;
2544 waiting_for_response_ = is_loading;
2545
[email protected]6ebdc9b2010-09-27 16:55:572546 if (delegate_)
2547 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212548 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542549
[email protected]eab61442013-11-14 18:35:482550 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592551 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482552 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2553 "URL", url);
[email protected]91621872013-10-08 04:04:592554 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2555 DidStartLoading(render_view_host));
2556 } else {
[email protected]eab61442013-11-14 18:35:482557 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2558 "URL", url);
[email protected]91621872013-10-08 04:04:592559 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2560 DidStopLoading(render_view_host));
2561 }
[email protected]66798902013-10-01 18:40:162562
2563 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212564 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2565 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542566 if (details)
[email protected]8ff00d72012-10-23 19:12:212567 det = Details<LoadNotificationDetails>(details);
2568 NotificationService::current()->Notify(
2569 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542570}
2571
[email protected]b172aee2012-04-10 17:05:262572void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212573 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322574 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562575 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322576 // Clear the status bubble. This is a workaround for a bug where WebKit
2577 // doesn't let us know that the cursor left an element during a
2578 // transition (this is also why the mouse cursor remains as a hand after
2579 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2580 // clear the bubble when a user navigates to a named anchor in the same
2581 // page.
[email protected]36fc0392011-12-25 03:59:512582 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322583 }
2584
[email protected]a6e82fc2010-02-24 22:28:142585 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472586 // Once the main frame is navigated, we're no longer considered to have
2587 // displayed insecure content.
2588 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352589 SSLManager::NotifySSLInternalStateChanged(
2590 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172591 }
[email protected]ce5c4502009-05-06 16:46:112592
[email protected]3c9e1872010-11-18 16:17:492593 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252594 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042595 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322596}
2597
[email protected]b172aee2012-04-10 17:05:262598void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322599 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212600 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322601 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112602 // If we navigate off the page, close all JavaScript dialogs.
2603 if (dialog_manager_ && !details.is_in_page)
2604 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322605
[email protected]3c9e1872010-11-18 16:17:492606 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252607 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042608 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322609}
2610
[email protected]2f7b3c5a2013-06-21 04:59:252611bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292612 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2613 // still be used for a normal web site.
2614 if (url == GURL(kAboutBlankURL))
2615 return false;
2616
2617 // The embedder will then have the opportunity to determine if the URL
2618 // should "use up" the SiteInstance.
2619 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252620}
2621
[email protected]b172aee2012-04-10 17:05:262622void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462623 // If we are creating a RVH for a restored controller, then we need to make
2624 // sure the RenderView starts with a next_page_id_ larger than the number
2625 // of restored entries. This must be called before the RenderView starts
2626 // navigating (to avoid a race between the browser updating max_page_id and
2627 // the renderer updating next_page_id_). Because of this, we only call this
2628 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562629 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582630 if (max_restored_page_id >
2631 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2632 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2633 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322634}
2635
[email protected]b172aee2012-04-10 17:05:262636bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262637 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322638 // For file URLs without a title, use the pathname instead. In the case of a
2639 // synthesized title, we don't want the update to count toward the "one set
2640 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262641 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322642 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512643 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2644 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322645 explicit_set = false; // Don't count synthetic titles toward the set limit.
2646 } else {
[email protected]acafd272011-07-26 17:35:572647 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322648 explicit_set = true;
2649 }
2650
[email protected]987fc3a2011-05-26 14:18:092651 // If a page is created via window.open and never navigated,
2652 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552653 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092654 if (entry) {
[email protected]36fc0392011-12-25 03:59:512655 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092656 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322657
[email protected]36fc0392011-12-25 03:59:512658 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092659 } else {
2660 if (page_title_when_no_navigation_entry_ == final_title)
2661 return false; // Nothing changed, don't bother.
2662
2663 page_title_when_no_navigation_entry_ = final_title;
2664 }
[email protected]420ae012009-04-24 05:16:322665
[email protected]420ae012009-04-24 05:16:322666 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232667 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322668
[email protected]66798902013-10-01 18:40:162669 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532670 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162671
2672 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212673 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462674 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212675 NotificationService::current()->Notify(
2676 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2677 Source<WebContents>(this),
2678 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042679
[email protected]420ae012009-04-24 05:16:322680 return true;
2681}
2682
[email protected]7b712ee22013-10-03 00:57:282683void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2684 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322685 // After sending out a swap notification, we need to send a disconnect
2686 // notification so that clients that pick up a pointer to |this| can NULL the
2687 // pointer. See Bug 1230284.
2688 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112689 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282690 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112691
2692 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282693 std::pair<RenderViewHost*, RenderViewHost*> details =
2694 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212695 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282696 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212697 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282698 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392699
2700 // Ensure that the associated embedder gets cleared after a RenderViewHost
2701 // gets swapped, so we don't reuse the same embedder next time a
2702 // RenderViewHost is attached to this WebContents.
2703 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322704}
2705
[email protected]da7a7182013-09-06 08:11:112706// TODO(avi): Remove this entire function because this notification is already
2707// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262708void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322709 if (!notify_disconnection_)
2710 return;
2711
2712 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212713 NotificationService::current()->Notify(
2714 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2715 Source<WebContents>(this),
2716 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322717}
2718
[email protected]cbb1ef592013-06-05 19:49:462719void WebContentsImpl::NotifyNavigationEntryCommitted(
2720 const LoadCommittedDetails& load_details) {
2721 FOR_EACH_OBSERVER(
2722 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2723}
2724
[email protected]5a3bdf52012-05-24 15:12:572725RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2726 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322727}
2728
[email protected]8d3347f2009-07-09 22:00:212729RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262730WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212731 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212732}
2733
[email protected]8ff00d72012-10-23 19:12:212734RendererPreferences WebContentsImpl::GetRendererPrefs(
2735 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462736 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512737}
2738
[email protected]b172aee2012-04-10 17:05:262739WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172740 return this;
2741}
2742
[email protected]b172aee2012-04-10 17:05:262743gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172744 if (delegate_)
2745 return delegate_->GetRootWindowResizerRect();
2746 return gfx::Rect();
2747}
2748
[email protected]7a846df2012-09-20 19:17:392749void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272750 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392751 browser_plugin_embedder_.reset();
2752}
2753
[email protected]b172aee2012-04-10 17:05:262754void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442755 // Don't send notifications if we are just creating a swapped-out RVH for
2756 // the opener chain. These won't be used for view-source or WebUI, so it's
2757 // ok to return early.
2758 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2759 return;
2760
[email protected]86f98a22013-03-20 14:35:002761 if (delegate_)
2762 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082763
[email protected]8ff00d72012-10-23 19:12:212764 NotificationService::current()->Notify(
2765 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2766 Source<WebContents>(this),
2767 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322768
2769 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352770 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212771 if (GetRenderManager()->pending_web_ui())
2772 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322773
[email protected]6286a372013-10-09 04:03:272774 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332775 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322776 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182777 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582778 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322779 }
[email protected]0666aef2009-05-13 19:48:082780
[email protected]60780f412013-02-25 16:34:102781 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262782
2783 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252784 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322785}
2786
[email protected]b172aee2012-04-10 17:05:262787void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522788 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322789 // Don't notify the world, since this came from a renderer in the
2790 // background.
2791 return;
2792 }
2793
[email protected]da7a7182013-09-06 08:11:112794 notify_disconnection_ = true;
2795 // TODO(avi): Remove. http://crbug.com/170921
2796 NotificationService::current()->Notify(
2797 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2798 Source<WebContents>(this),
2799 NotificationService::NoDetails());
2800
[email protected]be1f56ab2011-12-22 06:55:312801 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232802 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302803
2804 // Restore the focus to the tab (otherwise the focus will be on the top
2805 // window).
[email protected]484ae5912010-09-29 19:16:142806 if (was_crashed && !FocusLocationBarByDefault() &&
2807 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062808 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142809 }
[email protected]32ded2212011-11-10 18:51:432810
[email protected]d8c660432011-12-22 20:51:252811 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322812}
2813
[email protected]ec6a7eb2013-04-22 17:34:222814void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2815 base::TerminationStatus status,
2816 int error_code) {
[email protected]151a63d2011-12-20 22:32:522817 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322818 // The pending page's RenderViewHost is gone.
2819 return;
2820 }
2821
[email protected]d9030b82013-07-19 08:26:062822 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592823 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322824 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232825 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312826 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322827
[email protected]d8c660432011-12-22 20:51:252828 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272829 observers_,
[email protected]58d5cfe2013-07-10 02:40:522830 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322831}
2832
[email protected]b172aee2012-04-10 17:05:262833void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062834 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212835 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252836 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062837}
2838
[email protected]b0f724c2013-09-05 04:21:132839void WebContentsImpl::DidGetResourceResponseStart(
2840 const ResourceRequestDetails& details) {
2841 controller_.ssl_manager()->DidStartResourceResponse(details);
2842
2843 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2844 DidGetResourceResponseStart(details));
2845
2846 // TODO(avi): Remove. http://crbug.com/170921
2847 NotificationService::current()->Notify(
2848 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2849 Source<WebContents>(this),
2850 Details<const ResourceRequestDetails>(&details));
2851}
2852
2853void WebContentsImpl::DidGetRedirectForResourceRequest(
2854 const ResourceRedirectDetails& details) {
2855 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2856
2857 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2858 DidGetRedirectForResourceRequest(details));
2859
2860 // TODO(avi): Remove. http://crbug.com/170921
2861 NotificationService::current()->Notify(
2862 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2863 Source<WebContents>(this),
2864 Details<const ResourceRedirectDetails>(&details));
2865}
2866
[email protected]b172aee2012-04-10 17:05:262867void WebContentsImpl::DidNavigate(
2868 RenderViewHost* rvh,
2869 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]9b159a52013-10-03 17:24:552870 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2871 // First navigation should be a main frame navigation.
[email protected]50904452013-05-09 02:05:122872 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552873 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122874 }
2875
[email protected]e3d92a7f2013-01-10 02:35:052876 if (PageTransitionIsMainFrame(params.transition)) {
2877 // When overscroll navigation gesture is enabled, a screenshot of the page
2878 // in its current state is taken so that it can be used during the
2879 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362880 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052881 // WebContents::GetRenderViewHost to return the new host, instead of the one
2882 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482883 if (delegate_ && delegate_->CanOverscrollContent())
2884 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052885
[email protected]fa944cb82013-11-15 17:51:212886 GetRenderManager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052887 }
[email protected]8030f012009-09-25 18:09:372888
[email protected]434f69f2012-02-06 21:56:522889 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252890 // assigning a site is not necessary for this URL. In that case, the
2891 // SiteInstance can still be considered unused until a navigation to a real
2892 // page.
[email protected]434f69f2012-02-06 21:56:522893 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252894 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332895 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522896 }
[email protected]420ae012009-04-24 05:16:322897
2898 // Need to update MIME type here because it's referred to in
2899 // UpdateNavigationCommands() called by RendererDidNavigate() to
2900 // determine whether or not to enable the encoding menu.
2901 // It's updated only for the main frame. For a subframe,
2902 // RenderView::UpdateURL does not set params.contents_mime_type.
2903 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2904 // TODO(jungshik): Add a test for the encoding menu to avoid
2905 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212906 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322907 contents_mime_type_ = params.contents_mime_type;
2908
[email protected]8ff00d72012-10-23 19:12:212909 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002910 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392911
[email protected]1ae93fb2013-06-14 03:38:562912 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2913 // us estimate our process count for implementing OOP iframes.
2914 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552915 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562916
[email protected]a9c0bfe2010-09-17 08:35:222917 // Send notification about committed provisional loads. This notification is
2918 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2919 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212920 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072921 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2922 // that is not recorded in the navigation history. For the purpose of
2923 // tracking navigation events, we treat this event as a sub frame navigation
2924 // event.
2925 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212926 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222927 // Whether or not a page transition was triggered by going backward or
2928 // forward in the history is only stored in the navigation controller's
2929 // entry list.
2930 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272931 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212932 PAGE_TRANSITION_FORWARD_BACK)) {
2933 transition_type = PageTransitionFromInt(
2934 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222935 }
[email protected]0d60f0192011-04-14 12:40:102936 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252937 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442938 DidCommitProvisionalLoadForFrame(
2939 params.frame_id,
2940 params.frame_unique_name,
2941 is_main_frame,
2942 params.url,
2943 transition_type,
2944 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222945 }
2946
[email protected]76543b92009-08-31 17:27:452947 if (!did_navigate)
2948 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322949
2950 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2951 // for the appropriate notification (best) or you can add it to
2952 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2953 // necessary, please).
2954
2955 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002956 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322957 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002958 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512959 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002960 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2961 }
[email protected]93f230e02011-06-01 14:40:002962 }
[email protected]420ae012009-04-24 05:16:322963 DidNavigateAnyFramePostCommit(rvh, details, params);
2964}
2965
[email protected]b172aee2012-04-10 17:05:262966void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2967 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042968 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152969 // Ensure that this state update comes from either the active RVH or one of
2970 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]fa944cb82013-11-15 17:51:212971 DCHECK(rvh == GetRenderViewHost() ||
2972 GetRenderManager()->IsOnSwappedOutList(rvh));
[email protected]420ae012009-04-24 05:16:322973
2974 // We must be prepared to handle state updates for any page, these occur
2975 // when the user is scrolling and entering form data, as well as when we're
2976 // leaving a page, in which case our state may have already been moved to
2977 // the next page. The navigation controller will look up the appropriate
2978 // NavigationEntry and update it when it is notified via the delegate.
2979
2980 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582981 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322982 if (entry_index < 0)
2983 return;
[email protected]10f417c52011-12-28 21:04:232984 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322985
[email protected]691aa2f2013-05-28 22:52:042986 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322987 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042988 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322989 controller_.NotifyEntryChanged(entry, entry_index);
2990}
2991
[email protected]b172aee2012-04-10 17:05:262992void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2993 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262994 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262995 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322996 // If we have a title, that's a pretty good indication that we've started
2997 // getting useful data.
2998 SetNotWaitingForResponse();
2999
[email protected]73eb2602012-02-09 19:50:553000 // Try to find the navigation entry, which might not be the current one.
3001 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233002 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583003 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093004
[email protected]73eb2602012-02-09 19:50:553005 // We can handle title updates when we don't have an entry in
3006 // UpdateTitleForEntry, but only if the update is from the current RVH.
3007 if (!entry && rvh != GetRenderViewHost())
3008 return;
3009
[email protected]a49e10b2011-08-01 23:57:463010 // TODO(evan): make use of title_direction.
3011 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093012 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323013 return;
3014
3015 // Broadcast notifications when the UI should be updated.
3016 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213017 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323018}
3019
[email protected]b172aee2012-04-10 17:05:263020void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3021 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313022 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323023}
3024
[email protected]b172aee2012-04-10 17:05:263025void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513026 if (delegate_)
3027 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323028}
3029
[email protected]b172aee2012-04-10 17:05:263030void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103031#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293032 // The UI may be in an event-tracking loop, such as between the
3033 // mouse-down and mouse-up in text selection or a button click.
3034 // Defer the close until after tracking is complete, so that we
3035 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293036 // TODO(shess): This could get more fine-grained. For instance,
3037 // closing a tab in another window while selecting text in the
3038 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103039 if (view_->IsEventTracking()) {
3040 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293041 return;
3042 }
[email protected]60780f412013-02-25 16:34:103043#endif
[email protected]07707302009-11-06 00:50:293044
[email protected]420ae012009-04-24 05:16:323045 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523046 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513047 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323048}
3049
[email protected]b172aee2012-04-10 17:05:263050void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523051 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513052 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283053
3054 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213055 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573056}
3057
[email protected]b172aee2012-04-10 17:05:263058void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513059 if (delegate_ && delegate_->IsPopupOrPanel(this))
3060 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323061}
3062
[email protected]8ff00d72012-10-23 19:12:213063void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593064 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323065}
3066
[email protected]8ff00d72012-10-23 19:12:213067void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323068 scoped_ptr<LoadNotificationDetails> details;
3069
[email protected]9595fd82013-04-19 21:28:493070 // Use the last committed entry rather than the active one, in case a
3071 // pending entry has been created.
3072 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3073
[email protected]420ae012009-04-24 05:16:323074 // An entry may not exist for a stop when loading an initial blank page or
3075 // if an iframe injected by script into a blank page finishes loading.
3076 if (entry) {
[email protected]420ae012009-04-24 05:16:323077 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3078
3079 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513080 entry->GetVirtualURL(),
3081 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323082 elapsed,
3083 &controller_,
3084 controller_.GetCurrentEntryIndex()));
3085 }
3086
[email protected]91621872013-10-08 04:04:593087 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323088}
3089
[email protected]b172aee2012-04-10 17:05:263090void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163091 controller_.DiscardNonCommittedEntries();
3092
3093 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213094 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163095}
3096
[email protected]b172aee2012-04-10 17:05:263097void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513098 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133099 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403100}
3101
[email protected]7cc78902012-12-06 02:32:263102void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393103 if (opener_) {
3104 // Clear our opener so that future cross-process navigations don't have an
3105 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103106 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393107 opener_ = NULL;
3108 }
[email protected]7cc78902012-12-06 02:32:263109
3110 // Notify all swapped out RenderViewHosts for this tab. This is important
3111 // in case we go back to them, or if another window in those processes tries
3112 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213113 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263114}
3115
[email protected]59167c22013-06-03 18:07:323116void WebContentsImpl::DidAccessInitialDocument() {
3117 // Update the URL display.
3118 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3119}
3120
[email protected]87717d0e2012-04-26 02:58:433121void WebContentsImpl::DocumentAvailableInMainFrame(
3122 RenderViewHost* render_view_host) {
3123 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3124 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103125}
3126
[email protected]b172aee2012-04-10 17:05:263127void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083128 RenderViewHost* render_view_host,
3129 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093130 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3131 DocumentOnLoadCompletedInMainFrame(page_id));
3132
3133 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213134 NotificationService::current()->Notify(
3135 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3136 Source<WebContents>(this),
3137 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083138}
3139
[email protected]196159d2012-05-04 17:26:543140void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3141 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213142 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263143 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183144 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523145 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303146 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543147 // If this came from a swapped out RenderViewHost, we only allow the request
3148 // if we are still in the same BrowsingInstance.
3149 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3150 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3151 return;
3152 }
3153
[email protected]4ad5d77d2011-12-03 02:00:483154 // Delegate to RequestTransferURL because this is just the generic
3155 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573156 // TODO(creis): Pass the redirect_chain into this method to support client
3157 // redirects. http://crbug.com/311721.
3158 std::vector<GURL> redirect_chain;
3159 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3160 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523161 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483162}
3163
[email protected]b172aee2012-04-10 17:05:263164void WebContentsImpl::RequestTransferURL(
3165 const GURL& url,
[email protected]f8872902013-10-30 03:18:573166 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213167 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573168 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263169 WindowOpenDisposition disposition,
3170 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183171 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523172 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303173 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203174 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123175 GURL dest_url(url);
3176 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553177 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123178 dest_url = GURL(kAboutBlankURL);
3179
[email protected]c80297782013-11-21 07:10:163180 // TODO(creis): Look up the FrameTreeNode ID corresponding to source_frame_id.
3181 int frame_tree_node_id = -1;
3182 OpenURLParams params(dest_url, referrer, source_frame_id,
3183 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573184 page_transition, true /* is_renderer_initiated */);
3185 if (redirect_chain.size() > 0)
3186 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553187 params.transferred_global_request_id = old_request_id;
3188 params.should_replace_current_entry = should_replace_current_entry;
3189 params.user_gesture = user_gesture;
3190
[email protected]fa944cb82013-11-15 17:51:213191 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573192 // Web UI pages sometimes want to override the page transition type for
3193 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3194 // automatically generated suggestions). We don't override other types
3195 // like TYPED because they have different implications (e.g., autocomplete).
3196 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213197 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553198
[email protected]e0112912011-02-02 22:54:353199 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163200 // want web sites to see a referrer of "chrome://blah" (and some
3201 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323202 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553203 params.referrer = Referrer();
3204
3205 // Navigations in Web UI pages count as browser-initiated navigations.
3206 params.is_renderer_initiated = false;
[email protected]16a13fa2013-11-07 01:03:533207
3208 // TODO(creis): Remove this line. In the short term, it fixes a regression
3209 // (http://crbug.com/313572) by partially reverting r231370.
3210 // The underlying problem is that WebDataSource::replacesCurrentHistoryItem
3211 // should be returning false when the CWS goes to the sign-in page.
3212 // See http://crbug.com/311721.
3213 params.should_replace_current_entry = false;
[email protected]ae5184d62011-10-06 19:25:583214 }
[email protected]44d0930a2013-10-28 18:53:553215
3216 new_contents = OpenURL(params);
3217
[email protected]ae5184d62011-10-06 19:25:583218 if (new_contents) {
3219 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253220 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583221 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123222 dest_url,
[email protected]ae5184d62011-10-06 19:25:583223 referrer,
3224 disposition,
[email protected]44d0930a2013-10-28 18:53:553225 params.transition,
[email protected]ae5184d62011-10-06 19:25:583226 source_frame_id));
[email protected]420ae012009-04-24 05:16:323227 }
3228}
3229
[email protected]e1c3a552012-05-04 20:51:323230void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3231 // Tell the active RenderViewHost to run unload handlers and close, as long
3232 // as the request came from a RenderViewHost in the same BrowsingInstance.
3233 // In most cases, we receive this from a swapped out RenderViewHost.
3234 // It is possible to receive it from one that has just been swapped in,
3235 // in which case we might as well deliver the message anyway.
3236 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3237 GetRenderViewHost()->ClosePage();
3238}
3239
[email protected]f546640b2012-05-15 00:03:493240void WebContentsImpl::RouteMessageEvent(
3241 RenderViewHost* rvh,
3242 const ViewMsg_PostMessage_Params& params) {
3243 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363244 // came from a RenderViewHost in the same BrowsingInstance or if this
3245 // WebContents is dedicated to a browser plugin guest.
3246 // Note: This check means that an embedder could theoretically receive a
3247 // postMessage from anyone (not just its own guests). However, this is
3248 // probably not a risk for apps since other pages won't have references
3249 // to App windows.
3250 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3251 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493252 return;
3253
3254 ViewMsg_PostMessage_Params new_params(params);
3255
[email protected]0bc7f3542013-10-21 15:05:533256 if (!params.message_port_ids.empty()) {
3257 MessagePortMessageFilter* message_port_message_filter =
3258 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3259 ->message_port_message_filter();
3260 std::vector<int> new_routing_ids(params.message_port_ids.size());
3261 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3262 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3263 MessagePortService::GetInstance()->UpdateMessagePort(
3264 params.message_port_ids[i],
3265 message_port_message_filter,
3266 new_routing_ids[i]);
3267 }
3268 new_params.new_routing_ids = new_routing_ids;
3269 }
3270
[email protected]f546640b2012-05-15 00:03:493271 // If there is a source_routing_id, translate it to the routing ID for
3272 // the equivalent swapped out RVH in the target process. If we need
3273 // to create a swapped out RVH for the source tab, we create its opener
3274 // chain as well, since those will also be accessible to the target page.
3275 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3276 // Try to look up the WebContents for the source page.
3277 WebContentsImpl* source_contents = NULL;
3278 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3279 rvh->GetProcess()->GetID(), params.source_routing_id);
3280 if (source_rvh) {
3281 source_contents = static_cast<WebContentsImpl*>(
3282 source_rvh->GetDelegate()->GetAsWebContents());
3283 }
3284
3285 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363286 if (GetBrowserPluginGuest()) {
3287 // We create a swapped out RenderView for the embedder in the guest's
3288 // render process but we intentionally do not expose the embedder's
3289 // opener chain to it.
3290 new_params.source_routing_id =
3291 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3292 } else {
3293 new_params.source_routing_id =
3294 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3295 }
[email protected]f546640b2012-05-15 00:03:493296 } else {
3297 // We couldn't find it, so don't pass a source frame.
3298 new_params.source_routing_id = MSG_ROUTING_NONE;
3299 }
3300 }
3301
3302 // In most cases, we receive this from a swapped out RenderViewHost.
3303 // It is possible to receive it from one that has just been swapped in,
3304 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183305 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493306}
3307
[email protected]b172aee2012-04-10 17:05:263308void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343309 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263310 const base::string16& message,
3311 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323312 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213313 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323314 IPC::Message* reply_msg,
3315 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073316 // Suppress JavaScript dialogs when requested. Also suppress messages when
3317 // showing an interstitial as it's shown over the previous page and we don't
3318 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503319 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583320 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273321 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073322 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523323 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153324 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323325
3326 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213327 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433328 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153329 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3330 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433331 this,
3332 frame_url.GetOrigin(),
3333 accept_lang,
3334 javascript_message_type,
3335 message,
[email protected]51da7e32012-01-30 19:24:523336 default_prompt,
[email protected]b172aee2012-04-10 17:05:263337 base::Bind(&WebContentsImpl::OnDialogClosed,
3338 base::Unretained(this),
3339 rvh,
3340 reply_msg),
[email protected]51da7e32012-01-30 19:24:523341 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323342 }
[email protected]3ab9cb82011-06-03 18:02:073343
[email protected]6dd2f1e2013-09-11 15:06:013344 *did_suppress_message = suppress_this_message;
3345
[email protected]3ab9cb82011-06-03 18:02:073346 if (suppress_this_message) {
3347 // If we are suppressing messages, just reply as if the user immediately
3348 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263349 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073350 }
3351
[email protected]6dd2f1e2013-09-11 15:06:013352 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3353 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323354}
3355
[email protected]b172aee2012-04-10 17:05:263356void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263357 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263358 bool is_reload,
3359 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583360 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513361 if (delegate_)
3362 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073363
3364 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583365 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073366 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523367 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153368 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153369 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343370 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263371 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503372 return;
3373 }
[email protected]3ab9cb82011-06-03 18:02:073374
[email protected]7ab1e7d62009-10-14 23:32:013375 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153376 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3377 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323378 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263379 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523380 reply_msg));
[email protected]420ae012009-04-24 05:16:323381}
3382
[email protected]a796f202012-05-30 14:14:253383bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263384 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253385 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263386 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253387 if (!delegate_)
3388 return false;
3389 return delegate_->AddMessageToConsole(this, level, message, line_no,
3390 source_id);
3391}
3392
[email protected]b172aee2012-04-10 17:05:263393WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273394 // We want to base the page config off of the actual URL, rather than the
3395 // virtual URL.
3396 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3397 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003398 GURL url = controller_.GetActiveEntry()
3399 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153400
[email protected]fa944cb82013-11-15 17:51:213401 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323402}
3403
[email protected]0eba810b2012-10-18 03:19:363404int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213405 SiteInstance* instance) {
[email protected]fa944cb82013-11-15 17:51:213406 return GetRenderManager()->CreateRenderView(instance, MSG_ROUTING_NONE,
3407 true, true);
[email protected]0eba810b2012-10-18 03:19:363408}
3409
[email protected]b172aee2012-04-10 17:05:263410void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273411 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253412 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223413
[email protected]ea114722012-03-12 01:11:253414 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173415 if (rdh) // NULL in unittests.
3416 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253417}
3418
[email protected]b172aee2012-04-10 17:05:263419void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443420 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253421 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443422}
3423
[email protected]b172aee2012-04-10 17:05:263424void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563425 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263426 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153427 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523428 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153429 return;
3430
[email protected]9f76c1e2012-03-05 15:15:583431 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3432
[email protected]e5fc1632011-08-08 07:51:533433 // Ignore renderer unresponsive event if debugger is attached to the tab
3434 // since the event may be a result of the renderer sitting on a breakpoint.
3435 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363436 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533437 return;
3438
[email protected]2e9d79f2013-08-16 05:45:563439 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323440 // Hang occurred while firing the beforeunload/unload handler.
3441 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583442 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323443
[email protected]fa944cb82013-11-15 17:51:213444 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323445 return;
3446
3447 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563448 // nothing we can do to recover. If the hang is in the beforeunload handler,
3449 // pretend the beforeunload listeners have all fired and allow the delegate
3450 // to continue closing; the user will not have the option of cancelling the
3451 // close. Otherwise, pretend the unload listeners have all fired and close
3452 // the tab.
3453 bool close = true;
3454 if (is_during_beforeunload) {
3455 delegate_->BeforeUnloadFired(this, true, &close);
3456 }
3457 if (close)
3458 Close(rvh);
[email protected]420ae012009-04-24 05:16:323459 return;
3460 }
3461
[email protected]9f76c1e2012-03-05 15:15:583462 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473463 return;
3464
[email protected]6934a702011-12-20 00:04:513465 if (delegate_)
3466 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323467}
3468
[email protected]b172aee2012-04-10 17:05:263469void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513470 if (delegate_)
3471 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323472}
3473
[email protected]b172aee2012-04-10 17:05:263474void WebContentsImpl::LoadStateChanged(
3475 const GURL& url,
3476 const net::LoadStateWithParam& load_state,
3477 uint64 upload_position,
3478 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323479 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563480 upload_position_ = upload_position;
3481 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503482 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213483 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303484 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213485 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323486 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463487 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213488 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463489 }
[email protected]420ae012009-04-24 05:16:323490}
3491
[email protected]b172aee2012-04-10 17:05:263492void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513493 if (delegate_)
3494 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253495}
3496
[email protected]b172aee2012-04-10 17:05:263497void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553498 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323499 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123500 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3501 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513502 if (delegate_)
3503 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093504 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323505}
3506
[email protected]58d5cfe2013-07-10 02:40:523507void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543508 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233509 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223510 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543511}
3512
[email protected]b172aee2012-04-10 17:05:263513void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103514 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213515 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263516 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3517 // here during container initialization and normal window size will be set
3518 // later. In case of tab duplication this resizing to 0x0 prevents setting
3519 // normal size later so just ignore it.
3520 if (!size.IsEmpty())
3521 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323522}
3523
[email protected]af905902013-10-01 21:38:513524void WebContentsImpl::CancelModalDialogsForRenderManager() {
3525 // We need to cancel modal dialogs when doing a process swap, since the load
3526 // deferrer would prevent us from swapping out.
3527 if (dialog_manager_)
3528 dialog_manager_->CancelActiveAndPendingDialogs(this);
3529}
3530
[email protected]7b712ee22013-10-03 00:57:283531void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3532 RenderViewHost* new_host) {
3533 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083534
3535 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003536 if (delegate_)
3537 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393538
[email protected]7b712ee22013-10-03 00:57:283539 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543540}
3541
[email protected]14392a52012-05-02 20:28:443542int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3543 SiteInstance* instance) {
3544 if (!opener_)
3545 return MSG_ROUTING_NONE;
3546
3547 // Recursively create RenderViews for anything else in the opener chain.
3548 return opener_->CreateOpenerRenderViews(instance);
3549}
3550
3551int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3552 int opener_route_id = MSG_ROUTING_NONE;
3553
3554 // If this tab has an opener, ensure it has a RenderView in the given
3555 // SiteInstance as well.
3556 if (opener_)
3557 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3558
[email protected]45a22ad2013-02-21 03:25:003559 // If any of the renderers (current, pending, or swapped out) for this
3560 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213561 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3562 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373563
[email protected]fa944cb82013-11-15 17:51:213564 if (GetRenderManager()->pending_render_view_host() &&
3565 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3566 instance)
3567 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003568
[email protected]fa944cb82013-11-15 17:51:213569 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373570 instance);
3571 if (rvh)
3572 return rvh->GetRoutingID();
3573
[email protected]14392a52012-05-02 20:28:443574 // Create a swapped out RenderView in the given SiteInstance if none exists,
3575 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]fa944cb82013-11-15 17:51:213576 return GetRenderManager()->CreateRenderView(instance, opener_route_id,
3577 true, true);
[email protected]14392a52012-05-02 20:28:443578}
3579
[email protected]b172aee2012-04-10 17:05:263580NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193581 return GetController();
[email protected]3a3d47472010-07-15 21:03:543582}
3583
[email protected]b172aee2012-04-10 17:05:263584WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563585 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323586}
3587
[email protected]10f417c52011-12-28 21:04:233588NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263589 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323590 return controller_.GetLastCommittedEntry();
3591}
3592
[email protected]b172aee2012-04-10 17:05:263593bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443594 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033595 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443596 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323597 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523598
[email protected]420ae012009-04-24 05:16:323599 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443600 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213601 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323602
[email protected]74ce1ad2011-12-16 21:51:463603 // Make sure we use the correct starting page_id in the new RenderView.
3604 UpdateMaxPageIDIfNecessary(render_view_host);
3605 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583606 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463607
[email protected]9f76c1e2012-03-05 15:15:583608 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263609 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493610 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133611 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523612 return false;
[email protected]14392a52012-05-02 20:28:443613 }
[email protected]a4127722011-04-27 23:13:523614
[email protected]a220b5932013-09-21 03:47:443615#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503616 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3617 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443618 if (rwh_view) {
3619 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3620 render_widget_host->WasResized();
3621 }
[email protected]f8233cc2011-05-31 20:24:503622#endif
3623
[email protected]420ae012009-04-24 05:16:323624 return true;
3625}
3626
[email protected]7d244f12013-08-22 21:41:513627#if defined(OS_ANDROID)
3628bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3629 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3630 MSG_ROUTING_NONE);
3631}
3632#endif
3633
[email protected]b172aee2012-04-10 17:05:263634void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3635 IPC::Message* reply_msg,
3636 bool success,
[email protected]fcf75d42013-12-03 20:11:263637 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543638 if (is_showing_before_unload_dialog_ && !success) {
3639 // If a beforeunload dialog is canceled, we need to stop the throbber from
3640 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293641 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353642 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103643
[email protected]6d65a462013-06-21 21:29:123644 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3645 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543646 }
3647 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583648 static_cast<RenderViewHostImpl*>(
3649 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543650}
3651
[email protected]b172aee2012-04-10 17:05:263652void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213653 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123654 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103655}
[email protected]f45d2a72010-03-08 23:28:353656
[email protected]b172aee2012-04-10 17:05:263657void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103658 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443659 // Can be NULL during tests.
3660 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213661 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363662}
[email protected]9f76c1e2012-03-05 15:15:583663
[email protected]1ac10dca2013-08-20 20:47:043664bool WebContentsImpl::IsHidden() {
3665 return capturer_count_ == 0 && !should_normally_be_visible_;
3666}
3667
[email protected]b0936d22013-11-28 06:47:363668RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213669 return frame_tree_.root()->render_manager();
3670}
3671
[email protected]b172aee2012-04-10 17:05:263672RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583673 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3674}
[email protected]7900bfdb2012-05-24 19:31:243675
[email protected]f8497342013-02-05 22:15:023676BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393677 return browser_plugin_guest_.get();
3678}
3679
[email protected]738f57a2013-06-29 21:06:543680void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3681 CHECK(!browser_plugin_guest_);
3682 browser_plugin_guest_.reset(guest);
3683}
3684
[email protected]f8497342013-02-05 22:15:023685BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393686 return browser_plugin_embedder_.get();
3687}
[email protected]8ff00d72012-10-23 19:12:213688
[email protected]8eb04562013-03-06 03:41:143689BrowserPluginGuestManager*
3690 WebContentsImpl::GetBrowserPluginGuestManager() const {
3691 return static_cast<BrowserPluginGuestManager*>(
3692 GetBrowserContext()->GetUserData(
3693 browser_plugin::kBrowserPluginGuestManagerKeyName));
3694}
3695
[email protected]d9030b82013-07-19 08:26:063696void WebContentsImpl::ClearPowerSaveBlockers(
3697 RenderViewHost* render_view_host) {
3698 STLDeleteValues(&power_save_blockers_[render_view_host]);
3699 power_save_blockers_.erase(render_view_host);
3700}
3701
3702void WebContentsImpl::ClearAllPowerSaveBlockers() {
3703 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3704 i != power_save_blockers_.end(); ++i)
3705 STLDeleteValues(&power_save_blockers_[i->first]);
3706 power_save_blockers_.clear();
3707}
3708
[email protected]dc0fd432013-08-27 15:29:213709gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3710 gfx::Size size;
3711 if (delegate_)
3712 size = delegate_->GetSizeForNewRenderView(this);
3713 if (size.IsEmpty())
3714 size = view_->GetContainerSize();
3715 return size;
3716}
3717
[email protected]9b159a52013-10-03 17:24:553718void WebContentsImpl::OnFrameRemoved(
3719 RenderViewHostImpl* render_view_host,
3720 int64 frame_id) {
3721 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3722 FrameDetached(render_view_host, frame_id));
3723}
3724
[email protected]8ff00d72012-10-23 19:12:213725} // namespace content