blob: 51757de56bd34a22051e972b56f2fd9f24a3e4d6 [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]6ea6bdf2013-12-06 13:35:0133#include "content/browser/frame_host/navigator_impl.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]6ea6bdf2013-12-06 13:35:01348 frame_tree_(new NavigatorImpl(&controller_, this),
349 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34350 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23351 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
352 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34353 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26354 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56355 upload_size_(0),
356 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47357 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55358 capturer_count_(0),
359 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57360 is_being_destroyed_(false),
361 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15362 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01363 is_showing_before_unload_dialog_(false),
[email protected]ebf40a72010-07-22 01:46:38364 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21365 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
366 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00367 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21368 color_chooser_identifier_(0),
[email protected]c80725d52013-12-06 06:22:26369 message_source_(NULL),
[email protected]44470a22013-01-24 01:21:54370 fullscreen_widget_routing_id_(MSG_ROUTING_NONE) {
[email protected]cbb1ef592013-06-05 19:49:46371 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
372 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55373 frame_tree_.SetFrameRemoveListener(
374 base::Bind(&WebContentsImpl::OnFrameRemoved,
375 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35376}
initial.commit09911bf2008-07-26 23:55:29377
[email protected]b172aee2012-04-10 17:05:26378WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32379 is_being_destroyed_ = true;
380
[email protected]d9030b82013-07-19 08:26:06381 ClearAllPowerSaveBlockers();
382
[email protected]b24b68a2012-09-24 21:57:26383 for (std::set<RenderWidgetHostImpl*>::iterator iter =
384 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
385 (*iter)->DetachDelegate();
386 }
387 created_widgets_.clear();
388
[email protected]3ab9cb82011-06-03 18:02:07389 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15390 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11391 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07392
[email protected]da8543762012-03-20 08:52:20393 if (color_chooser_)
394 color_chooser_->End();
395
[email protected]420ae012009-04-24 05:16:32396 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32397
[email protected]ca13a442012-04-17 14:00:12398 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21399 NotificationService::current()->Notify(
400 NOTIFICATION_WEB_CONTENTS_DESTROYED,
401 Source<WebContents>(this),
402 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32403
404 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07405#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32406 // If we still have a window handle, destroy it. GetNativeView can return
407 // NULL if this contents was part of a window that closed.
[email protected]f3615f02013-02-26 06:09:06408 if (view_->GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52409 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58410 if (host && host->GetView())
411 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42412 }
[email protected]420ae012009-04-24 05:16:32413#endif
[email protected]7ab1e7d62009-10-14 23:32:01414
[email protected]fa944cb82013-11-15 17:51:21415 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27416 if (pending_rvh) {
417 FOR_EACH_OBSERVER(WebContentsObserver,
418 observers_,
419 RenderViewDeleted(pending_rvh));
420 }
421
422 FOR_EACH_OBSERVER(WebContentsObserver,
423 observers_,
[email protected]fa944cb82013-11-15 17:51:21424 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27425
[email protected]2db9bd72012-04-13 20:20:56426 FOR_EACH_OBSERVER(WebContentsObserver,
427 observers_,
428 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08429
[email protected]6934a702011-12-20 00:04:51430 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10431
432 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
433 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42434}
435
[email protected]d1198fd2012-08-13 22:50:19436WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59437 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19438 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03439 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59440 WebContentsImpl* new_contents = new WebContentsImpl(
441 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19442
[email protected]54944cde2012-12-09 09:24:59443 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19444 return new_contents;
445}
446
[email protected]b371a5652013-02-20 11:25:51447// static
[email protected]8eb04562013-03-06 03:41:14448BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36449 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53450 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54451 int guest_instance_id,
452 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39453 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39454
455 // This makes |new_contents| act as a guest.
456 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54457 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19458 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11459
[email protected]3de10bb32013-01-08 21:57:33460 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33461 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11462
[email protected]216be772013-01-25 00:22:27463 // We are instantiating a WebContents for browser plugin. Set its subframe bit
464 // to true.
465 static_cast<RenderViewHostImpl*>(
466 new_contents->GetRenderViewHost())->set_is_subframe(true);
467
[email protected]8eb04562013-03-06 03:41:14468 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39469}
470
[email protected]b0936d22013-11-28 06:47:36471RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21472 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28473}
474
[email protected]7bb761892012-07-20 09:32:47475bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
476 const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56477 if (GetWebUI() &&
478 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17479 return true;
[email protected]d2353452012-01-19 19:53:56480 }
[email protected]f82d57b52011-04-27 19:13:17481
[email protected]d8c660432011-12-22 20:51:25482 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
483 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10484 while ((observer = it.GetNext()) != NULL)
485 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53486 return true;
[email protected]403415a2011-01-10 18:57:53487
[email protected]c80725d52013-12-06 06:22:26488 // Message handlers should be aware of which RenderViewHost sent the
489 // message, which is temporarily stored in message_source_.
490 message_source_ = render_view_host;
[email protected]724159a2010-12-30 01:11:18491 bool handled = true;
492 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26493 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]724159a2010-12-30 01:11:18494 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
495 OnDidLoadResourceFromMemoryCache)
496 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
497 OnDidDisplayInsecureContent)
498 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
499 OnDidRunInsecureContent)
500 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
501 OnDocumentLoadedInFrame)
502 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26503 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
504 OnDidFailLoadWithError)
[email protected]7d472472011-01-22 01:30:25505 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26506 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21507 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20508 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
509 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
510 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16511 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]c80725d52013-12-06 06:22:26512 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10513 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20514 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
515 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
516 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
517 OnSetSelectedColorInColorChooser)
[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]c80725d52013-12-06 06:22:26540 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]60eca4eb2013-12-06 00:02:16611RenderFrameHost* WebContentsImpl::GetMainFrame() {
612 return frame_tree_.root()->render_frame_host();
613}
614
[email protected]b172aee2012-04-10 17:05:26615RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21616 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31617}
618
[email protected]a04c9d02012-11-14 21:04:34619void WebContentsImpl::GetRenderViewHostAtPosition(
620 int x,
621 int y,
622 const base::Callback<void(RenderViewHost*, int, int)>& callback) {
623 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
624 if (embedder)
625 embedder->GetRenderViewHostAtPosition(x, y, callback);
626 else
627 callback.Run(GetRenderViewHost(), x, y);
628}
629
[email protected]bfcfa692013-02-07 06:17:02630WebContents* WebContentsImpl::GetEmbedderWebContents() const {
631 BrowserPluginGuest* guest = GetBrowserPluginGuest();
632 if (guest)
633 return guest->embedder_web_contents();
634 return NULL;
635}
636
637int WebContentsImpl::GetEmbeddedInstanceID() const {
638 BrowserPluginGuest* guest = GetBrowserPluginGuest();
639 if (guest)
640 return guest->instance_id();
641 return 0;
642}
643
[email protected]6b618e62012-08-16 12:59:18644int WebContentsImpl::GetRoutingID() const {
645 if (!GetRenderViewHost())
646 return MSG_ROUTING_NONE;
647
648 return GetRenderViewHost()->GetRoutingID();
649}
650
[email protected]44470a22013-01-24 01:21:54651int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
652 return fullscreen_widget_routing_id_;
653}
654
[email protected]b172aee2012-04-10 17:05:26655RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21656 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31657}
658
[email protected]f8497342013-02-05 22:15:02659RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
660 BrowserPluginGuest* guest = GetBrowserPluginGuest();
661 if (guest && guest->embedder_web_contents()) {
662 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
663 }
664 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
665}
666
[email protected]4aebbca2013-09-17 22:26:49667RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
668 const {
669 RenderWidgetHost* const widget_host =
670 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
671 GetFullscreenWidgetRoutingID());
672 return widget_host ? widget_host->GetView() : NULL;
673}
674
[email protected]8ff00d72012-10-23 19:12:21675WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31676 return view_.get();
677}
678
[email protected]8ff00d72012-10-23 19:12:21679WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56680 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03681 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
682 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22683 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58684 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22685 web_ui->SetController(controller);
686 return web_ui;
687 }
688
689 delete web_ui;
690 return NULL;
691}
692
[email protected]8ff00d72012-10-23 19:12:21693WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21694 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
695 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31696}
697
[email protected]8ff00d72012-10-23 19:12:21698WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21699 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34700}
701
[email protected]86ef6a392012-05-11 22:03:11702void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22703 if (GetUserAgentOverride() == override)
704 return;
705
706 renderer_preferences_.user_agent_override = override;
707
708 // Send the new override string to the renderer.
709 RenderViewHost* host = GetRenderViewHost();
710 if (host)
711 host->SyncRendererPrefs();
712
713 // Reload the page if a load is currently in progress to avoid having
714 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27715 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22716 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
717 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53718
719 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
720 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11721}
722
723const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22724 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11725}
726
[email protected]c73a2282013-04-29 21:10:41727#if defined(OS_WIN) && defined(USE_AURA)
728void WebContentsImpl::SetParentNativeViewAccessible(
729gfx::NativeViewAccessible accessible_parent) {
730 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45731 if (GetRenderViewHost())
732 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41733}
734#endif
735
[email protected]fcf75d42013-12-03 20:11:26736const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55737 // Transient entries take precedence. They are used for interstitial pages
738 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23739 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08740 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21741 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30742 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23743 if (entry) {
[email protected]b5cca982011-05-26 04:42:08744 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23745 }
[email protected]fa944cb82013-11-15 17:51:21746 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
747 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58748 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54749 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32750 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54751 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35752 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26753 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54754 if (!title.empty())
755 return title;
756 }
757 }
758
759 // We use the title for the last committed entry rather than a pending
760 // navigation entry. For example, when the user types in a URL, we want to
761 // keep the old page's title until the new load has committed and we get a new
762 // title.
[email protected]96d185d2009-04-24 03:28:54763 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32764
[email protected]9eeafc012013-11-25 23:49:47765 // We make an exception for initial navigations.
766 if (controller_.IsInitialNavigation()) {
767 // We only want to use the title from the visible entry in one of two cases:
768 // 1. There's already a committed entry for an initial navigation, in which
769 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
770 // 2. The pending entry has been explicitly assigned a title to display.
771 //
772 // If there's no last committed entry and no assigned title, we should fall
773 // back to |page_title_when_no_navigation_entry_| rather than showing the
774 // URL.
775 if (entry ||
776 (controller_.GetVisibleEntry() &&
777 !controller_.GetVisibleEntry()->GetTitle().empty())) {
778 entry = controller_.GetVisibleEntry();
779 }
780 }
[email protected]59167c22013-06-03 18:07:32781
[email protected]45d0ef7f2011-01-05 13:46:23782 if (entry) {
[email protected]b5cca982011-05-26 04:42:08783 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23784 }
[email protected]987fc3a2011-05-26 14:18:09785
786 // |page_title_when_no_navigation_entry_| is finally used
787 // if no title cannot be retrieved.
788 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54789}
790
[email protected]b172aee2012-04-10 17:05:26791int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46792 return GetMaxPageIDForSiteInstance(GetSiteInstance());
793}
794
[email protected]b172aee2012-04-10 17:05:26795int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
796 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33797 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
798 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46799
[email protected]b6583592012-01-25 19:52:33800 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34801}
802
[email protected]b172aee2012-04-10 17:05:26803void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46804 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
805}
806
[email protected]b172aee2012-04-10 17:05:26807void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33808 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46809 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33810 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34811}
812
[email protected]ec6c05f2013-10-23 18:41:57813void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
814 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
815 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57816}
817
[email protected]b172aee2012-04-10 17:05:26818SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21819 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54820}
821
[email protected]b172aee2012-04-10 17:05:26822SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21823 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
824 GetRenderManager()->pending_render_view_host() :
825 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58826 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38827}
828
[email protected]b172aee2012-04-10 17:05:26829bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31830 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49831}
832
[email protected]b172aee2012-04-10 17:05:26833bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31834 return waiting_for_response_;
835}
836
[email protected]b172aee2012-04-10 17:05:26837const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31838 return load_state_;
839}
840
[email protected]fcf75d42013-12-03 20:11:26841const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31842 return load_state_host_;
843}
844
[email protected]b172aee2012-04-10 17:05:26845uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31846 return upload_size_;
847}
848
[email protected]b172aee2012-04-10 17:05:26849uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31850 return upload_position_;
851}
852
[email protected]1ae93fb2013-06-14 03:38:56853std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56854 std::set<GURL> sites;
[email protected]9b159a52013-10-03 17:24:55855 frame_tree_.ForEach(Bind(&CollectSites,
856 base::Unretained(GetBrowserContext()),
857 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56858 return sites;
859}
860
[email protected]b172aee2012-04-10 17:05:26861const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31862 return encoding_;
863}
864
[email protected]b172aee2012-04-10 17:05:26865bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31866 return displayed_insecure_content_;
867}
868
[email protected]54597982013-02-06 01:59:55869void WebContentsImpl::IncrementCapturerCount() {
[email protected]5a652232013-02-12 06:15:25870 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55871 ++capturer_count_;
872 DVLOG(1) << "There are now " << capturer_count_
873 << " capturing(s) of WebContentsImpl@" << this;
874}
875
876void WebContentsImpl::DecrementCapturerCount() {
877 --capturer_count_;
878 DVLOG(1) << "There are now " << capturer_count_
879 << " capturing(s) of WebContentsImpl@" << this;
880 DCHECK_LE(0, capturer_count_);
881
[email protected]5a652232013-02-12 06:15:25882 if (is_being_destroyed_)
883 return;
884
[email protected]1ac10dca2013-08-20 20:47:04885 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55886 DVLOG(1) << "Executing delayed WasHidden().";
887 WasHidden();
888 }
[email protected]be1f56ab2011-12-22 06:55:31889}
890
[email protected]f2bd40812013-07-20 04:30:44891int WebContentsImpl::GetCapturerCount() const {
892 return capturer_count_;
893}
894
[email protected]b172aee2012-04-10 17:05:26895bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31896 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
897 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
898 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49899}
900
[email protected]b172aee2012-04-10 17:05:26901void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
902 int error_code) {
[email protected]443b80e2010-12-14 00:42:23903 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34904 return;
905
[email protected]443b80e2010-12-14 00:42:23906 crashed_status_ = status;
907 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21908 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34909}
910
[email protected]b172aee2012-04-10 17:05:26911base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31912 return crashed_status_;
913}
914
[email protected]b172aee2012-04-10 17:05:26915bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31916 return is_being_destroyed_;
917}
918
[email protected]b172aee2012-04-10 17:05:26919void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34920 if (delegate_)
921 delegate_->NavigationStateChanged(this, changed_flags);
922}
923
[email protected]3e324142012-06-25 18:26:33924base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
925 return last_selected_time_;
926}
927
[email protected]9e2e4632012-07-27 16:38:41928void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54929 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04930 RenderWidgetHostViewPort* rwhv =
931 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16932 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29933 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43934#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16935 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43936#endif
937 }
[email protected]96d185d2009-04-24 03:28:54938
[email protected]5ac20162010-11-24 23:33:11939 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38940
[email protected]b9769d82012-02-10 00:23:59941 // The resize rect might have changed while this was inactive -- send the new
942 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58943 RenderViewHostImpl* rvh =
944 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59945 if (rvh) {
946 rvh->ResizeRectChanged(GetRootWindowResizerRect());
947 }
[email protected]96d185d2009-04-24 03:28:54948
[email protected]c0d9d5672013-10-09 07:38:03949 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
950
[email protected]54597982013-02-06 01:59:55951 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31952}
953
[email protected]b172aee2012-04-10 17:05:26954void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55955 // If there are entities capturing screenshots or video (e.g., mirroring),
956 // don't activate the "disable rendering" optimization.
957 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52958 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55959 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26960 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52961 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33962 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52963 // calls us).
[email protected]c30585c2012-02-16 15:02:04964 RenderWidgetHostViewPort* rwhv =
965 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16966 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29967 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54968 }
969
[email protected]c0d9d5672013-10-09 07:38:03970 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
971
[email protected]54597982013-02-06 01:59:55972 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37973}
974
[email protected]b172aee2012-04-10 17:05:26975bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31976 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27977 return WillNotifyDisconnection() &&
978 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58979 !static_cast<RenderViewHostImpl*>(
980 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31981}
982
[email protected]b172aee2012-04-10 17:05:26983void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:21984 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:40985 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:27986}
987
[email protected]b172aee2012-04-10 17:05:26988WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44989 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:45990 // We pass our own opener so that the cloned page can access it if it was
991 // before.
[email protected]54944cde2012-12-09 09:24:59992 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:45993 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:59994 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:19995 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:22996 FOR_EACH_OBSERVER(WebContentsObserver,
997 observers_,
998 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:27999 return tc;
1000}
1001
[email protected]14392a52012-05-02 20:28:441002void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211003 const NotificationSource& source,
1004 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441005 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211006 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1007 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501008 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1009 i != pending_widget_views_.end(); ++i) {
1010 if (host->GetView() == i->second) {
1011 pending_widget_views_.erase(i);
1012 break;
1013 }
1014 }
1015 break;
1016 }
[email protected]14392a52012-05-02 20:28:441017 default:
1018 NOTREACHED();
1019 }
1020}
1021
[email protected]ec6c05f2013-10-23 18:41:571022WebContents* WebContentsImpl::GetWebContents() {
1023 return this;
1024}
1025
[email protected]54944cde2012-12-09 09:24:591026void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211027 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361028 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211029 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431030 should_normally_be_visible_ = !params.initially_hidden;
1031
[email protected]fa944cb82013-11-15 17:51:211032 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041033 params.browser_context, params.site_instance, params.routing_id,
1034 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191035
[email protected]8ff00d72012-10-23 19:12:211036 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191037 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271038 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191039 CHECK(render_view_host_delegate_view_);
1040 } else {
[email protected]f8497342013-02-05 22:15:021041 WebContentsViewDelegate* delegate =
1042 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1043
[email protected]59383c782013-04-17 16:43:271044 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381045 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1046 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021047
[email protected]b5a40842012-11-28 15:26:111048 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381049 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431050 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111051 render_view_host_delegate_view_ = rv;
1052 view_.reset(rv);
1053 } else {
[email protected]f8497342013-02-05 22:15:021054 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111055 view_.reset(CreateWebContentsView(
1056 this, delegate, &render_view_host_delegate_view_));
1057 }
[email protected]d1198fd2012-08-13 22:50:191058 CHECK(render_view_host_delegate_view_);
1059 }
1060 CHECK(view_.get());
1061
[email protected]ed245db2012-12-18 08:00:451062 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591063 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191064
1065 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101066 if (opener_)
1067 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191068
1069 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211070 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1071 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441072#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191073 java_bridge_dispatcher_host_manager_.reset(
1074 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101075 date_time_chooser_.reset(new DateTimeChooserAndroid());
1076#endif
[email protected]d1198fd2012-08-13 22:50:191077}
1078
[email protected]7fff43e2013-05-21 20:21:101079void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1080 RemoveDestructionObserver(web_contents);
1081
[email protected]14392a52012-05-02 20:28:441082 // Clear the opener if it has been closed.
1083 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441084 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511085 return;
[email protected]14392a52012-05-02 20:28:441086 }
[email protected]ceee8cd2013-03-08 04:59:511087 // Clear a pending contents that has been closed before being shown.
1088 for (PendingContents::iterator iter = pending_contents_.begin();
1089 iter != pending_contents_.end();
1090 ++iter) {
1091 if (iter->second != web_contents)
1092 continue;
1093 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511094 return;
1095 }
1096 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441097}
1098
[email protected]7fff43e2013-05-21 20:21:101099void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1100 if (!ContainsKey(destruction_observers_, web_contents)) {
1101 destruction_observers_[web_contents] =
1102 new DestructionObserver(this, web_contents);
1103 }
1104}
1105
1106void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1107 DestructionObservers::iterator iter =
1108 destruction_observers_.find(web_contents);
1109 if (iter != destruction_observers_.end()) {
1110 delete destruction_observers_[web_contents];
1111 destruction_observers_.erase(iter);
1112 }
1113}
1114
[email protected]b172aee2012-04-10 17:05:261115void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311116 observers_.AddObserver(observer);
1117}
1118
[email protected]b172aee2012-04-10 17:05:261119void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311120 observers_.RemoveObserver(observer);
1121}
1122
[email protected]b172aee2012-04-10 17:05:261123void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341124 if (delegate_)
1125 delegate_->ActivateContents(this);
1126}
1127
[email protected]b172aee2012-04-10 17:05:261128void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121129 if (delegate_)
1130 delegate_->DeactivateContents(this);
1131}
1132
[email protected]b172aee2012-04-10 17:05:261133void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481134 if (delegate_)
1135 delegate_->LostCapture();
1136}
1137
[email protected]b24b68a2012-09-24 21:57:261138void WebContentsImpl::RenderWidgetDeleted(
1139 RenderWidgetHostImpl* render_widget_host) {
1140 if (is_being_destroyed_) {
1141 // |created_widgets_| might have been destroyed.
1142 return;
1143 }
1144
1145 std::set<RenderWidgetHostImpl*>::iterator iter =
1146 created_widgets_.find(render_widget_host);
1147 if (iter != created_widgets_.end())
1148 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541149
1150 if (render_widget_host &&
1151 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491152 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1153 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541154 FOR_EACH_OBSERVER(WebContentsObserver,
1155 observers_,
1156 DidDestroyFullscreenWidget(
1157 fullscreen_widget_routing_id_));
1158 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1159 }
[email protected]b24b68a2012-09-24 21:57:261160}
1161
[email protected]b172aee2012-04-10 17:05:261162bool WebContentsImpl::PreHandleKeyboardEvent(
1163 const NativeWebKeyboardEvent& event,
1164 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481165 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131166 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481167}
1168
[email protected]b172aee2012-04-10 17:05:261169void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061170 if (browser_plugin_embedder_ &&
1171 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1172 return;
1173 }
1174
[email protected]63954792011-07-11 04:17:481175 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131176 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481177}
1178
[email protected]fb3f066e2013-02-12 19:12:521179bool WebContentsImpl::PreHandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461180 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191181#if !defined(OS_MACOSX)
1182 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1183 // isn't done for two reasons:
1184 // -the OS already has a gesture to do this through pinch-zoom
1185 // -if a user starts an inertial scroll, let's go, and presses control
1186 // (i.e. control+tab) then the OS's buffered scroll events will come in
1187 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521188 if (delegate_ &&
1189 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461190 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521191 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1192 return true;
1193 }
[email protected]bccc4472013-04-18 16:37:191194#endif
[email protected]fb3f066e2013-02-12 19:12:521195
1196 return false;
1197}
1198
[email protected]c73a2282013-04-29 21:10:411199#if defined(OS_WIN) && defined(USE_AURA)
1200gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1201 return accessible_parent_;
1202}
1203#endif
1204
[email protected]b172aee2012-04-10 17:05:261205void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431206 if (delegate_)
1207 delegate_->HandleMouseDown();
1208}
1209
[email protected]b172aee2012-04-10 17:05:261210void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481211 if (delegate_)
1212 delegate_->HandleMouseUp();
1213}
1214
[email protected]590a634e2012-07-19 16:38:231215void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481216 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231217 delegate_->HandlePointerActivate();
1218}
1219
1220void WebContentsImpl::HandleGestureBegin() {
1221 if (delegate_)
1222 delegate_->HandleGestureBegin();
1223}
1224
1225void WebContentsImpl::HandleGestureEnd() {
1226 if (delegate_)
1227 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481228}
1229
[email protected]b172aee2012-04-10 17:05:261230void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491231 // This method is being called to enter or leave renderer-initiated fullscreen
1232 // mode. Either way, make sure any existing fullscreen widget is shut down
1233 // first.
1234 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1235 if (widget_view)
1236 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1237
[email protected]8a5e0ca2011-08-25 06:30:471238 if (delegate_)
1239 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1240}
1241
[email protected]b172aee2012-04-10 17:05:261242bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381243 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121244}
1245
[email protected]a9c81f02012-06-01 00:15:441246void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1247 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371248 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441249 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371250 } else {
1251 GotResponseToLockMouseRequest(false);
1252 }
1253}
1254
[email protected]b172aee2012-04-10 17:05:261255void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371256 if (delegate_)
1257 delegate_->LostMouseLock();
1258}
1259
[email protected]bafe6cd2012-05-23 23:09:501260void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201261 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501262 int route_id,
[email protected]227692c52013-05-31 22:43:041263 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131264 const ViewHostMsg_CreateWindow_Params& params,
1265 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501266 // We usually create the new window in the same BrowsingInstance (group of
1267 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551268 // if the opener is being suppressed (in a non-guest), we create a new
1269 // SiteInstance in its own BrowsingInstance.
1270 bool is_guest = GetRenderProcessHost()->IsGuest();
1271
[email protected]04cbd3d2013-12-04 04:58:201272 // If the opener is to be suppressed, the new window can be in any process.
1273 // Since routing ids are process specific, we must not have one passed in
1274 // as argument here.
1275 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1276
[email protected]bafe6cd2012-05-23 23:09:501277 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551278 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571279 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501280 GetSiteInstance();
1281
[email protected]04cbd3d2013-12-04 04:58:201282 // A message to create a new window can only come from the active process for
1283 // this WebContentsImpl instance. If any other process sends the request,
1284 // it is invalid and the process must be terminated.
1285 if (GetRenderProcessHost()->GetID() != render_process_id) {
1286 base::ProcessHandle process_handle =
1287 RenderProcessHost::FromID(render_process_id)->GetHandle();
1288 if (process_handle != base::kNullProcessHandle) {
1289 RecordAction(
1290 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
1291 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1292 }
1293 return;
1294 }
1295
[email protected]d1198fd2012-08-13 22:50:191296 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341297 //
1298 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301299 const std::string& partition_id =
1300 GetContentClient()->browser()->
1301 GetStoragePartitionIdForSite(GetBrowserContext(),
1302 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461303 StoragePartition* partition = BrowserContext::GetStoragePartition(
1304 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411305 DOMStorageContextWrapper* dom_storage_context =
1306 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191307 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1308 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1309 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371310
1311 if (delegate_ &&
1312 !delegate_->ShouldCreateWebContents(this,
1313 route_id,
1314 params.window_container_type,
1315 params.frame_name,
1316 params.target_url,
1317 partition_id,
1318 session_storage_namespace)) {
1319 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1320 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1321 main_frame_route_id);
1322 return;
1323 }
1324
1325 // Create the new web contents. This will automatically create the new
1326 // WebContentsView. In the future, we may want to create the view separately.
1327 WebContentsImpl* new_contents =
1328 new WebContentsImpl(GetBrowserContext(),
1329 params.opener_suppressed ? NULL : this);
1330
[email protected]d1198fd2012-08-13 22:50:191331 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301332 partition_id,
[email protected]d1198fd2012-08-13 22:50:191333 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461334 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591335 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041336 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551337 if (!is_guest) {
1338 create_params.context = view_->GetNativeView();
1339 create_params.initial_size = view_->GetContainerSize();
1340 } else {
1341 // This makes |new_contents| act as a guest.
1342 // For more info, see comment above class BrowserPluginGuest.
1343 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1344 WebContentsImpl* new_contents_impl =
1345 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461346 BrowserPluginGuest::CreateWithOpener(instance_id,
1347 new_contents_impl->opener() != NULL,
1348 new_contents_impl,
1349 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551350 }
[email protected]1ac10dca2013-08-20 20:47:041351 if (params.disposition == NEW_BACKGROUND_TAB)
1352 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591353 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191354
[email protected]c4538072013-03-18 02:17:551355 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341356 // will be shown immediately).
1357 if (!params.opener_suppressed) {
1358 if (!is_guest) {
1359 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501360
[email protected]d70bea92013-04-05 04:23:341361 // TODO(brettw): It seems bogus that we have to call this function on the
1362 // newly created object and give it one of its own member variables.
1363 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1364 }
[email protected]bafe6cd2012-05-23 23:09:501365 // Save the created window associated with the route so we can show it
1366 // later.
1367 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1368 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101369 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501370 }
1371
1372 if (delegate_) {
1373 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131374 this, params.opener_frame_id, params.frame_name,
1375 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501376 }
1377
1378 if (params.opener_suppressed) {
1379 // When the opener is suppressed, the original renderer cannot access the
1380 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001381 bool was_blocked = false;
1382 if (delegate_) {
1383 gfx::Rect initial_pos;
1384 delegate_->AddNewContents(
1385 this, new_contents, params.disposition, initial_pos,
1386 params.user_gesture, &was_blocked);
1387 }
1388 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211389 OpenURLParams open_params(params.target_url,
1390 Referrer(),
1391 CURRENT_TAB,
1392 PAGE_TRANSITION_LINK,
1393 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301394 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001395 new_contents->OpenURL(open_params);
1396 }
[email protected]bafe6cd2012-05-23 23:09:501397 }
1398}
1399
[email protected]a8504022013-12-04 20:23:511400void WebContentsImpl::CreateNewWidget(int render_process_id,
1401 int route_id,
[email protected]180ef242013-11-07 06:50:461402 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511403 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501404}
1405
[email protected]a8504022013-12-04 20:23:511406void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1407 int route_id) {
1408 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501409}
1410
[email protected]a8504022013-12-04 20:23:511411void WebContentsImpl::CreateNewWidget(int render_process_id,
1412 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501413 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461414 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211415 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511416 // A message to create a new widget can only come from the active process for
1417 // this WebContentsImpl instance. If any other process sends the request,
1418 // it is invalid and the process must be terminated.
1419 if (process->GetID() != render_process_id) {
1420 base::ProcessHandle process_handle =
1421 RenderProcessHost::FromID(render_process_id)->GetHandle();
1422 if (process_handle != base::kNullProcessHandle) {
1423 RecordAction(
1424 UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
1425 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1426 }
1427 return;
1428 }
1429
[email protected]bafe6cd2012-05-23 23:09:501430 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041431 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261432 created_widgets_.insert(widget_host);
1433
[email protected]83918ec2013-01-10 15:37:191434 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1435 view_->CreateViewForPopupWidget(widget_host));
1436 if (!widget_view)
1437 return;
[email protected]bafe6cd2012-05-23 23:09:501438 if (!is_fullscreen) {
1439 // Popups should not get activated.
1440 widget_view->SetPopupType(popup_type);
1441 }
1442 // Save the created widget associated with the route so we can show it later.
1443 pending_widget_views_[route_id] = widget_view;
1444
1445#if defined(OS_MACOSX)
1446 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1447 // to allow it to survive the trip without being hosted.
1448 base::mac::NSObjectRetain(widget_view->GetNativeView());
1449#endif
1450}
1451
1452void WebContentsImpl::ShowCreatedWindow(int route_id,
1453 WindowOpenDisposition disposition,
1454 const gfx::Rect& initial_pos,
1455 bool user_gesture) {
1456 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001457 if (contents) {
1458 WebContentsDelegate* delegate = GetDelegate();
1459 if (delegate) {
1460 delegate->AddNewContents(
1461 this, contents, disposition, initial_pos, user_gesture, NULL);
1462 }
1463 }
[email protected]bafe6cd2012-05-23 23:09:501464}
1465
1466void WebContentsImpl::ShowCreatedWidget(int route_id,
1467 const gfx::Rect& initial_pos) {
1468 ShowCreatedWidget(route_id, false, initial_pos);
1469}
1470
1471void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1472 ShowCreatedWidget(route_id, true, gfx::Rect());
1473}
1474
1475void WebContentsImpl::ShowCreatedWidget(int route_id,
1476 bool is_fullscreen,
1477 const gfx::Rect& initial_pos) {
1478 if (delegate_)
1479 delegate_->RenderWidgetShowing();
1480
1481 RenderWidgetHostViewPort* widget_host_view =
1482 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1483 if (!widget_host_view)
1484 return;
[email protected]4aebbca2013-09-17 22:26:491485 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311486 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1487 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491488 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1489 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1490 delegate_->ToggleFullscreenModeForTab(this, true);
1491 } else {
1492 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491493 }
[email protected]4aebbca2013-09-17 22:26:491494 FOR_EACH_OBSERVER(WebContentsObserver,
1495 observers_,
1496 DidShowFullscreenWidget(route_id));
1497 if (!widget_host_view->HasFocus())
1498 widget_host_view->Focus();
1499 } else {
[email protected]f8497342013-02-05 22:15:021500 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491501 }
[email protected]89054502012-06-03 10:29:241502
1503 RenderWidgetHostImpl* render_widget_host_impl =
1504 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1505 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311506 // Only allow privileged mouse lock for fullscreen render widget, which is
1507 // used to implement Pepper Flash fullscreen.
1508 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501509
1510#if defined(OS_MACOSX)
1511 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1512 // properly embedded (or purposefully ignored) we can release the retain we
1513 // took in CreateNewWidget().
1514 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1515#endif
1516}
1517
1518WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1519 PendingContents::iterator iter = pending_contents_.find(route_id);
1520
1521 // Certain systems can block the creation of new windows. If we didn't succeed
1522 // in creating one, just return NULL.
1523 if (iter == pending_contents_.end()) {
1524 return NULL;
1525 }
1526
1527 WebContentsImpl* new_contents = iter->second;
1528 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101529 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501530
[email protected]d70bea92013-04-05 04:23:341531 // Don't initialize the guest WebContents immediately.
1532 if (new_contents->GetRenderProcessHost()->IsGuest())
1533 return new_contents;
1534
[email protected]bafe6cd2012-05-23 23:09:501535 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1536 !new_contents->GetRenderViewHost()->GetView())
1537 return NULL;
1538
1539 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1540 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1541 return new_contents;
1542}
1543
1544RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1545 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1546 if (iter == pending_widget_views_.end()) {
1547 DCHECK(false);
1548 return NULL;
1549 }
1550
1551 RenderWidgetHostView* widget_host_view = iter->second;
1552 pending_widget_views_.erase(route_id);
1553
1554 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1555 if (!widget_host->GetProcess()->HasConnection()) {
1556 // The view has gone away or the renderer crashed. Nothing to do.
1557 return NULL;
1558 }
1559
1560 return widget_host_view;
1561}
1562
[email protected]f56c7872013-06-18 12:31:571563void WebContentsImpl::ShowContextMenu(const ContextMenuParams& params) {
[email protected]bafe6cd2012-05-23 23:09:501564 // Allow WebContentsDelegates to handle the context menu operation first.
1565 if (delegate_ && delegate_->HandleContextMenu(params))
1566 return;
1567
[email protected]f56c7872013-06-18 12:31:571568 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501569}
1570
[email protected]f13b4202012-06-12 23:53:231571void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091572 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211573 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231574 if (delegate_)
1575 delegate_->RequestMediaAccessPermission(this, request, callback);
1576 else
[email protected]b5f76742013-04-29 15:05:591577 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231578}
1579
[email protected]cc9200432013-07-23 23:02:401580SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1581 SiteInstance* instance) {
1582 return controller_.GetSessionStorageNamespace(instance);
1583}
1584
[email protected]9b159a52013-10-03 17:24:551585FrameTree* WebContentsImpl::GetFrameTree() {
1586 return &frame_tree_;
1587}
1588
[email protected]32deec62013-05-15 23:55:041589void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1590 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441591 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041592}
1593
[email protected]b172aee2012-04-10 17:05:261594void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231595 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331596 if (delegate_)
1597 delegate_->UpdatePreferredSize(this, pref_size);
1598}
1599
[email protected]b172aee2012-04-10 17:05:261600void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341601 if (delegate_)
1602 delegate_->ResizeDueToAutoResize(this, new_size);
1603}
1604
[email protected]b172aee2012-04-10 17:05:261605WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201606 if (!delegate_)
1607 return NULL;
[email protected]00c37fc2011-08-02 00:22:501608
[email protected]e5d549d2011-12-28 01:29:201609 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201610 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341611}
1612
[email protected]6b618e62012-08-16 12:59:181613bool WebContentsImpl::Send(IPC::Message* message) {
1614 if (!GetRenderViewHost()) {
1615 delete message;
1616 return false;
1617 }
1618
1619 return GetRenderViewHost()->Send(message);
1620}
1621
[email protected]b172aee2012-04-10 17:05:261622bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501623 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251624 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231625 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251626 reload_type);
[email protected]876bc832010-09-07 16:29:541627}
[email protected]96d185d2009-04-24 03:28:541628
[email protected]ba45bfd2012-05-22 21:51:441629void WebContentsImpl::RenderViewForInterstitialPageCreated(
[email protected]8ff00d72012-10-23 19:12:211630 RenderViewHost* render_view_host) {
[email protected]ba45bfd2012-05-22 21:51:441631 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1632 RenderViewForInterstitialPageCreated(render_view_host));
1633}
1634
[email protected]20ca0382013-02-28 19:50:071635void WebContentsImpl::AttachInterstitialPage(
1636 InterstitialPageImpl* interstitial_page) {
1637 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211638 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291639
1640 // Cancel any visible dialogs so that they don't interfere with the
1641 // interstitial.
1642 if (dialog_manager_)
1643 dialog_manager_->CancelActiveAndPendingDialogs(this);
1644
[email protected]20ca0382013-02-28 19:50:071645 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1646 DidAttachInterstitialPage());
1647}
1648
1649void WebContentsImpl::DetachInterstitialPage() {
1650 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211651 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071652 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1653 DidDetachInterstitialPage());
1654}
1655
[email protected]b172aee2012-04-10 17:05:261656bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231657 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501658 NavigationController::ReloadType reload_type) {
[email protected]e11f0e92013-06-12 15:12:031659 TRACE_EVENT0("browser", "WebContentsImpl::NavigateToEntry");
1660
[email protected]19e81142011-10-03 16:19:401661 // The renderer will reject IPC messages with URLs longer than
1662 // this limit, so don't attempt to navigate with a longer URL.
[email protected]3adab1c2013-09-09 21:23:431663 if (entry.GetURL().spec().size() > kMaxURLChars) {
1664 LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars
1665 << " characters.";
[email protected]19e81142011-10-03 16:19:401666 return false;
[email protected]3adab1c2013-09-09 21:23:431667 }
[email protected]19e81142011-10-03 16:19:401668
[email protected]c80297782013-11-21 07:10:161669 // TODO(creis): Use entry->frame_tree_node_id() to pick which
[email protected]b0936d22013-11-28 06:47:361670 // RenderFrameHostManager to use.
[email protected]9f76c1e2012-03-05 15:15:581671 RenderViewHostImpl* dest_render_view_host =
[email protected]fa944cb82013-11-15 17:51:211672 static_cast<RenderViewHostImpl*>(GetRenderManager()->Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401673 if (!dest_render_view_host)
1674 return false; // Unable to create the desired render view host.
1675
[email protected]80a8fad2011-01-29 04:02:381676 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071677 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581678 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]24e18252012-04-16 21:26:271679 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501680 bool is_allowed_in_web_ui_renderer =
[email protected]86a0a6e2013-01-28 06:33:031681 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
1682 GetBrowserContext(), entry.GetURL(), data_urls_allowed);
[email protected]8ff00d72012-10-23 19:12:211683 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) &&
[email protected]1684454a2012-03-24 04:12:231684 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271685 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]8ff00d72012-10-23 19:12:211686 GetContentClient()->SetActiveURL(entry.GetURL());
[email protected]1684454a2012-03-24 04:12:231687 CHECK(0);
1688 }
[email protected]54ec6472010-04-09 19:39:581689
[email protected]7bb761892012-07-20 09:32:471690 // Notify observers that we will navigate in this RV.
1691 FOR_EACH_OBSERVER(WebContentsObserver,
1692 observers_,
1693 AboutToNavigateRenderView(dest_render_view_host));
1694
[email protected]96d185d2009-04-24 03:28:541695 // Used for page load time metrics.
1696 current_load_start_ = base::TimeTicks::Now();
1697
1698 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341699 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271700 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471701 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341702 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541703
[email protected]36fc0392011-12-25 03:59:511704 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541705 // HACK!! This code suppresses javascript: URLs from being added to
1706 // session history, which is what we want to do for javascript: URLs that
1707 // do not generate content. What we really need is a message from the
1708 // renderer telling us that a new page was not created. The same message
1709 // could be used for mailto: URLs and the like.
[email protected]44b05812013-08-19 07:59:351710 if (entry.GetURL().SchemeIs(kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541711 return false;
1712 }
1713
[email protected]3c9e1872010-11-18 16:17:491714 // Notify observers about navigation.
[email protected]0661cee2013-11-23 21:22:391715 FOR_EACH_OBSERVER(
1716 WebContentsObserver,
1717 observers_,
1718 DidStartNavigationToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541719
[email protected]09b29342011-06-24 19:18:481720 if (delegate_)
1721 delegate_->DidNavigateToPendingEntry(this);
1722
[email protected]d5f942ba2008-09-26 19:30:341723 return true;
1724}
1725
[email protected]b172aee2012-04-10 17:05:261726void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331727 const SiteInstance* site_instance,
1728 int history_length,
1729 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411730 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1731 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211732 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191733 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141734 return;
[email protected]9e1ad4b2011-08-14 16:49:191735 }
[email protected]9f76c1e2012-03-05 15:15:581736 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191737 if (!rvh) {
1738 NOTREACHED();
1739 return;
1740 }
[email protected]9f76c1e2012-03-05 15:15:581741 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191742 NOTREACHED();
1743 return;
1744 }
[email protected]6b618e62012-08-16 12:59:181745 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1746 history_length,
1747 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141748}
1749
[email protected]b172aee2012-04-10 17:05:261750void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271751 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211752 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541753 return;
1754 }
[email protected]9f76c1e2012-03-05 15:15:581755 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541756}
1757
[email protected]b172aee2012-04-10 17:05:261758bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211759 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541760}
1761
[email protected]b172aee2012-04-10 17:05:261762InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211763 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221764}
1765
[email protected]b172aee2012-04-10 17:05:261766bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161767 // WebKit creates Document object when MIME type is application/xhtml+xml,
1768 // so we also support this MIME type.
1769 return contents_mime_type_ == "text/html" ||
1770 contents_mime_type_ == "text/xml" ||
1771 contents_mime_type_ == "application/xhtml+xml" ||
1772 contents_mime_type_ == "text/plain" ||
1773 contents_mime_type_ == "text/css" ||
1774 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1775}
1776
[email protected]b172aee2012-04-10 17:05:261777void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591778 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161779 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551780 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011781 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141782 return;
[email protected]c7dd2f62011-07-18 15:57:591783 }
1784
1785 Stop();
1786
1787 // Create the save package and possibly prompt the user for the name to save
1788 // the page as. The user prompt is an asynchronous operation that runs on
1789 // another thread.
1790 save_package_ = new SavePackage(this);
1791 save_package_->GetSaveInfo();
1792}
1793
1794// Used in automated testing to bypass prompting the user for file names.
1795// Instead, the names and paths are hard coded rather than running them through
1796// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341797bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1798 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211799 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591800 // Stop the page from navigating.
1801 Stop();
1802
1803 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211804 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591805}
1806
[email protected]3c71576ce2013-07-23 02:00:011807void WebContentsImpl::SaveFrame(const GURL& url,
1808 const Referrer& referrer) {
1809 if (!GetURL().is_valid())
1810 return;
1811 bool is_main_frame = (url == GetURL());
1812
1813 DownloadManager* dlm =
1814 BrowserContext::GetDownloadManager(GetBrowserContext());
1815 if (!dlm)
1816 return;
1817 int64 post_id = -1;
1818 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271819 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011820 if (entry)
1821 post_id = entry->GetPostID();
1822 }
1823 scoped_ptr<DownloadUrlParameters> params(
1824 DownloadUrlParameters::FromWebContents(this, url));
1825 params->set_referrer(referrer);
1826 params->set_post_id(post_id);
1827 params->set_prefer_cache(true);
1828 if (post_id >= 0)
1829 params->set_method("POST");
1830 params->set_prompt(true);
1831 dlm->DownloadUrl(params.Pass());
1832}
1833
[email protected]b172aee2012-04-10 17:05:261834void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341835 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481836 const base::Callback<void(int64)>& callback) {
1837 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121838}
1839
[email protected]6286a372013-10-09 04:03:271840// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261841bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271842 NavigationEntryImpl* visible_entry =
1843 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1844 return (visible_entry != NULL &&
1845 visible_entry->site_instance() == GetSiteInstance() &&
1846 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321847}
1848
[email protected]b172aee2012-04-10 17:05:261849const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271850 return contents_mime_type_;
1851}
1852
[email protected]b172aee2012-04-10 17:05:261853bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271854 return notify_disconnection_;
1855}
1856
[email protected]b172aee2012-04-10 17:05:261857void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311858 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181859 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161860}
1861
[email protected]b172aee2012-04-10 17:05:261862void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311863 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181864 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161865}
1866
[email protected]8ff00d72012-10-23 19:12:211867RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271868 return &renderer_preferences_;
1869}
1870
[email protected]e35ccd52012-05-23 16:22:471871void WebContentsImpl::Close() {
1872 Close(GetRenderViewHost());
1873}
1874
[email protected]cf200a562013-05-03 16:24:291875void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461876 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291877 if (browser_plugin_embedder_.get())
1878 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1879 screen_x, screen_y, operation);
1880 if (GetRenderViewHost())
1881 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1882 screen_x, screen_y, operation);
1883}
1884
1885void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1886 int screen_x, int screen_y) {
1887 if (browser_plugin_embedder_.get())
1888 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1889 screen_x, screen_y);
1890 if (GetRenderViewHost())
1891 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1892 screen_x, screen_y);
1893}
1894
[email protected]b172aee2012-04-10 17:05:261895void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521896 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581897 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511898 if (delegate_)
1899 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291900 if (browser_plugin_embedder_.get())
1901 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341902}
1903
[email protected]e35ccd52012-05-23 16:22:471904void WebContentsImpl::UserGestureDone() {
1905 OnUserGesture();
1906}
1907
[email protected]b172aee2012-04-10 17:05:261908void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271909 closed_by_user_gesture_ = value;
1910}
1911
[email protected]b172aee2012-04-10 17:05:261912bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271913 return closed_by_user_gesture_;
1914}
1915
[email protected]b172aee2012-04-10 17:05:261916double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051917 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561918 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251919 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171920 return 0;
[email protected]b75b8292010-10-01 07:28:251921
1922 double zoom_level;
1923 if (temporary_zoom_settings_) {
1924 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581925 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251926 } else {
[email protected]2ae88d12011-10-14 09:11:191927 GURL url;
[email protected]6286a372013-10-09 04:03:271928 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191929 // Since zoom map is updated using rewritten URL, use rewritten URL
1930 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271931 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021932 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1933 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251934 }
[email protected]d0b8d092010-10-25 04:05:171935 return zoom_level;
1936}
[email protected]b75b8292010-10-01 07:28:251937
[email protected]b172aee2012-04-10 17:05:261938int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591939 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171940 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011941 // Calculate the zoom percent from the factor. Round up to the nearest whole
1942 // number.
[email protected]b75b8292010-10-01 07:28:251943 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491944 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251945 *enable_decrement = percent > minimum_zoom_percent_;
1946 *enable_increment = percent < maximum_zoom_percent_;
1947 return percent;
1948}
1949
[email protected]b172aee2012-04-10 17:05:261950void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501951 if (!delegate_)
1952 return;
1953
[email protected]6286a372013-10-09 04:03:271954 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1955 if (!entry)
[email protected]1788e772010-12-15 16:40:501956 return;
1957
[email protected]6286a372013-10-09 04:03:271958 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121959}
1960
[email protected]b172aee2012-04-10 17:05:261961void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041962 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271963 if (!delegate_)
1964 return;
1965
[email protected]691aa2f2013-05-28 22:52:041966 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271967}
1968
[email protected]b172aee2012-04-10 17:05:261969int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271970 return minimum_zoom_percent_;
1971}
1972
[email protected]b172aee2012-04-10 17:05:261973int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271974 return maximum_zoom_percent_;
1975}
1976
[email protected]b172aee2012-04-10 17:05:261977gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231978 return preferred_size_;
1979}
1980
[email protected]b172aee2012-04-10 17:05:261981bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271982 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581983 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271984}
1985
[email protected]b172aee2012-04-10 17:05:261986bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441987 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501988}
1989
[email protected]cb805452013-05-22 15:16:211990void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181991 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211992 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201993}
1994
[email protected]cb805452013-05-22 15:16:211995void WebContentsImpl::DidEndColorChooser() {
1996 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1997 color_chooser_identifier_));
1998 color_chooser_.reset();
1999 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202000}
2001
[email protected]41225fe2013-03-29 05:32:022002int WebContentsImpl::DownloadImage(const GURL& url,
2003 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302004 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022005 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:392006 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:302007 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022008 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392009 return id;
2010}
2011
[email protected]b172aee2012-04-10 17:05:262012bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272013 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202014 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332015 return true;
2016 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272017}
2018
[email protected]b172aee2012-04-10 17:05:262019void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272020 if (delegate_)
2021 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212022}
2023
[email protected]54047eb52012-05-08 21:45:572024void WebContentsImpl::DidStartProvisionalLoadForFrame(
[email protected]8ff00d72012-10-23 19:12:212025 RenderViewHost* render_view_host,
[email protected]54047eb52012-05-08 21:45:572026 int64 frame_id,
[email protected]d37c33e2012-10-12 13:35:132027 int64 parent_frame_id,
[email protected]54047eb52012-05-08 21:45:572028 bool is_main_frame,
[email protected]54047eb52012-05-08 21:45:572029 const GURL& url) {
[email protected]8ff00d72012-10-23 19:12:212030 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
[email protected]081dc522013-05-15 04:59:202031 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL);
[email protected]724159a2010-12-30 01:11:182032 GURL validated_url(url);
[email protected]8ff00d72012-10-23 19:12:212033 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572034 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082035 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182036
[email protected]442385d2013-08-09 02:38:412037 if (is_main_frame) {
[email protected]d974a0a2013-01-10 01:43:572038 DidChangeLoadProgress(0);
2039
[email protected]442385d2013-08-09 02:38:412040 // If there is no browser-initiated pending entry for this navigation and it
2041 // is not for the error URL, create a pending entry using the current
2042 // SiteInstance, and ensure the address bar updates accordingly. We don't
2043 // know the referrer or extra headers at this point, but the referrer will
2044 // be set properly upon commit.
[email protected]97d8f0d2013-10-29 16:49:212045 NavigationEntryImpl* pending_entry =
2046 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
[email protected]442385d2013-08-09 02:38:412047 bool has_browser_initiated_pending_entry = pending_entry &&
[email protected]97d8f0d2013-10-29 16:49:212048 !pending_entry->is_renderer_initiated();
[email protected]442385d2013-08-09 02:38:412049 if (!has_browser_initiated_pending_entry && !is_error_page) {
2050 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
2051 controller_.CreateNavigationEntry(validated_url,
2052 content::Referrer(),
2053 content::PAGE_TRANSITION_LINK,
2054 true /* is_renderer_initiated */,
2055 std::string(),
2056 GetBrowserContext()));
2057 entry->set_site_instance(
2058 static_cast<SiteInstanceImpl*>(GetSiteInstance()));
[email protected]3ed682bf2013-10-17 20:56:562059 // TODO(creis): If there's a pending entry already, find a safe way to
2060 // update it instead of replacing it and copying over things like this.
[email protected]97d8f0d2013-10-29 16:49:212061 if (pending_entry) {
2062 entry->set_transferred_global_request_id(
2063 pending_entry->transferred_global_request_id());
2064 entry->set_should_replace_entry(pending_entry->should_replace_entry());
[email protected]f8872902013-10-30 03:18:572065 entry->set_redirect_chain(pending_entry->redirect_chain());
[email protected]3ed682bf2013-10-17 20:56:562066 }
[email protected]442385d2013-08-09 02:38:412067 controller_.SetPendingEntry(entry);
2068 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
2069 }
[email protected]59167c22013-06-03 18:07:322070 }
2071
[email protected]0d60f0192011-04-14 12:40:102072 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252073 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]d37c33e2012-10-12 13:35:132074 DidStartProvisionalLoadForFrame(frame_id, parent_frame_id,
2075 is_main_frame, validated_url, is_error_page,
[email protected]ead9009e2013-01-07 22:06:322076 is_iframe_srcdoc, render_view_host));
[email protected]400992b2012-06-14 00:03:542077
2078 if (is_main_frame) {
2079 // Notify observers about the provisional change in the main frame URL.
2080 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2081 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]400992b2012-06-14 00:03:542082 render_view_host));
2083 }
2084}
2085
2086void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]8ff00d72012-10-23 19:12:212087 RenderViewHost* render_view_host,
[email protected]400992b2012-06-14 00:03:542088 int32 page_id,
[email protected]400992b2012-06-14 00:03:542089 const GURL& source_url,
2090 const GURL& target_url) {
2091 // TODO(creis): Remove this method and have the pre-rendering code listen to
[email protected]b0f724c2013-09-05 04:21:132092 // WebContentsObserver::DidGetRedirectForResourceRequest instead.
2093 // See http://crbug.com/78512.
[email protected]400992b2012-06-14 00:03:542094 GURL validated_source_url(source_url);
2095 GURL validated_target_url(target_url);
[email protected]8ff00d72012-10-23 19:12:212096 RenderProcessHost* render_process_host =
[email protected]400992b2012-06-14 00:03:542097 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082098 RenderViewHost::FilterURL(render_process_host, false, &validated_source_url);
2099 RenderViewHost::FilterURL(render_process_host, false, &validated_target_url);
[email protected]400992b2012-06-14 00:03:542100 NavigationEntry* entry;
2101 if (page_id == -1) {
2102 entry = controller_.GetPendingEntry();
2103 } else {
2104 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
2105 page_id);
2106 }
2107 if (!entry || entry->GetURL() != validated_source_url)
2108 return;
2109
2110 // Notify observers about the provisional change in the main frame URL.
2111 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2112 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]400992b2012-06-14 00:03:542113 render_view_host));
[email protected]724159a2010-12-30 01:11:182114}
2115
[email protected]54047eb52012-05-08 21:45:572116void WebContentsImpl::DidFailProvisionalLoadWithError(
[email protected]8ff00d72012-10-23 19:12:212117 RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:582118 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2119 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
2120 << ", error_code: " << params.error_code
2121 << ", error_description: " << params.error_description
2122 << ", is_main_frame: " << params.is_main_frame
2123 << ", showing_repost_interstitial: " <<
2124 params.showing_repost_interstitial
2125 << ", frame_id: " << params.frame_id;
2126 GURL validated_url(params.url);
[email protected]8ff00d72012-10-23 19:12:212127 RenderProcessHost* render_process_host =
[email protected]54047eb52012-05-08 21:45:572128 render_view_host->GetProcess();
[email protected]413fcd02012-10-30 00:20:082129 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]724159a2010-12-30 01:11:182130
[email protected]d7b175e2011-10-11 15:31:582131 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:182132 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2133 // This means that the interstitial won't be torn down properly, which is
2134 // bad. But if we have an interstitial, go back to another tab type, and
2135 // then load the same interstitial again, we could end up getting the first
2136 // interstitial's "failed" message (as a result of the cancel) when we're on
2137 // the second one.
2138 //
2139 // We can't tell this apart, so we think we're tearing down the current page
2140 // which will cause a crash later one. There is also some code in
[email protected]b0936d22013-11-28 06:47:362141 // RenderFrameHostManager::RendererAbortedProvisionalLoad that is commented
[email protected]724159a2010-12-30 01:11:182142 // out because of this problem.
2143 //
2144 // http://code.google.com/p/chromium/issues/detail?id=2855
2145 // Because this will not tear down the interstitial properly, if "back" is
2146 // back to another tab type, the interstitial will still be somewhat alive
2147 // in the previous tab type. If you navigate somewhere that activates the
2148 // tab with the interstitial again, you'll see a flash before the new load
2149 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:272150 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:182151 LOG(WARNING) << "Discarding message during interstitial.";
2152 return;
2153 }
2154
[email protected]fa944cb82013-11-15 17:51:212155 GetRenderManager()->RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:182156 }
2157
[email protected]b12eb222013-09-10 00:11:482158 // Do not usually clear the pending entry if one exists, so that the user's
2159 // typed URL is not lost when a navigation fails or is aborted. However, in
2160 // cases that we don't show the pending entry (e.g., renderer-initiated
2161 // navigations in an existing tab), we don't keep it around. That prevents
2162 // spoofs on in-page navigations that don't go through
2163 // DidStartProvisionalLoadForFrame.
2164 // In general, we allow the view to clear the pending entry and typed URL if
2165 // the user requests (e.g., hitting Escape with focus in the address bar).
2166 // Note: don't touch the transient entry, since an interstitial may exist.
2167 if (controller_.GetPendingEntry() != controller_.GetVisibleEntry())
2168 controller_.DiscardPendingEntry();
2169
[email protected]d8c660432011-12-22 20:51:252170 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:582171 observers_,
2172 DidFailProvisionalLoad(params.frame_id,
[email protected]2f673064c2013-10-22 04:01:442173 params.frame_unique_name,
[email protected]d7b175e2011-10-11 15:31:582174 params.is_main_frame,
2175 validated_url,
2176 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:462177 params.error_description,
2178 render_view_host));
[email protected]724159a2010-12-30 01:11:182179}
2180
[email protected]b172aee2012-04-10 17:05:262181void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182182 const GURL& url,
[email protected]70435962011-08-02 20:13:282183 const std::string& security_info,
2184 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182185 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282186 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192187 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182188 cache.Increment();
2189
2190 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082191 int cert_id = 0;
2192 net::CertStatus cert_status = 0;
2193 int security_bits = -1;
2194 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122195 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212196 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122197 &security_bits, &connection_status,
2198 &signed_certificate_timestamp_ids);
2199 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212200 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002201 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2202 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182203
[email protected]b0f724c2013-09-05 04:21:132204 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2205
2206 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2207 DidLoadResourceFromMemoryCache(details));
2208
[email protected]8bfc8272013-09-09 20:10:532209 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2210 scoped_refptr<net::URLRequestContextGetter> request_context(
2211 resource_type == ResourceType::MEDIA ?
2212 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2213 GetRenderProcessHost()->GetID()) :
2214 GetBrowserContext()->GetRequestContextForRenderProcess(
2215 GetRenderProcessHost()->GetID()));
2216 BrowserThread::PostTask(
2217 BrowserThread::IO,
2218 FROM_HERE,
2219 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2220 }
[email protected]724159a2010-12-30 01:11:182221}
2222
[email protected]b172aee2012-04-10 17:05:262223void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]8ff00d72012-10-23 19:12:212224 RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182225 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192226 SSLManager::NotifySSLInternalStateChanged(
2227 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182228}
2229
[email protected]b172aee2012-04-10 17:05:262230void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022231 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582232 LOG(WARNING) << security_origin << " ran insecure content from "
2233 << target_url.possibly_invalid_spec();
[email protected]8ff00d72012-10-23 19:12:212234 RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412235 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]8ff00d72012-10-23 19:12:212236 RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182237 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412238 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192239 SSLManager::NotifySSLInternalStateChanged(
2240 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182241}
2242
[email protected]b172aee2012-04-10 17:05:262243void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]c80725d52013-12-06 06:22:262244 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2245 DocumentLoadedInFrame(frame_id, message_source_));
[email protected]724159a2010-12-30 01:11:182246}
2247
[email protected]b172aee2012-04-10 17:05:262248void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:312249 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062250 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312251 bool is_main_frame) {
[email protected]b502ed462013-01-08 08:20:062252 GURL validated_url(url);
[email protected]c80725d52013-12-06 06:22:262253 RenderProcessHost* render_process_host = message_source_->GetProcess();
[email protected]b502ed462013-01-08 08:20:062254 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252255 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7bb761892012-07-20 09:32:472256 DidFinishLoad(frame_id, validated_url, is_main_frame,
[email protected]c80725d52013-12-06 06:22:262257 message_source_));
[email protected]1a55c5be2011-11-29 11:36:312258}
2259
[email protected]b172aee2012-04-10 17:05:262260void WebContentsImpl::OnDidFailLoadWithError(
2261 int64 frame_id,
[email protected]b502ed462013-01-08 08:20:062262 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262263 bool is_main_frame,
2264 int error_code,
[email protected]fcf75d42013-12-03 20:11:262265 const base::string16& error_description) {
[email protected]b502ed462013-01-08 08:20:062266 GURL validated_url(url);
[email protected]c80725d52013-12-06 06:22:262267 RenderProcessHost* render_process_host = message_source_->GetProcess();
[email protected]b502ed462013-01-08 08:20:062268 RenderViewHost::FilterURL(render_process_host, false, &validated_url);
[email protected]d8c660432011-12-22 20:51:252269 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:312270 DidFailLoad(frame_id, validated_url, is_main_frame,
[email protected]7bb761892012-07-20 09:32:472271 error_code, error_description,
[email protected]c80725d52013-12-06 06:22:262272 message_source_));
[email protected]724159a2010-12-30 01:11:182273}
2274
[email protected]b172aee2012-04-10 17:05:262275void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:262276 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:232277 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:252278 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:262279 if (!entry)
2280 return;
2281 // Note that we don't call NavigationController::GotToOffset() as we don't
2282 // want to create a pending navigation entry (it might end up lingering
2283 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252284 entry->SetTransitionType(
[email protected]8ff00d72012-10-23 19:12:212285 PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512286 entry->GetTransitionType() |
[email protected]8ff00d72012-10-23 19:12:212287 PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472288 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572289
2290 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2291 // it in now that we know. This allows us to find the entry when it commits.
2292 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232293 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332294 entry->set_site_instance(
2295 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572296 }
[email protected]216813952011-05-19 22:21:262297 }
2298}
2299
[email protected]b172aee2012-04-10 17:05:262300void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2301 int maximum_percent,
2302 bool remember) {
[email protected]216813952011-05-19 22:21:262303 minimum_zoom_percent_ = minimum_percent;
2304 maximum_zoom_percent_ = maximum_percent;
2305 temporary_zoom_settings_ = !remember;
2306}
2307
[email protected]b172aee2012-04-10 17:05:262308void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342309 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432310 if (!delegate_)
2311 return;
2312
[email protected]b9535422012-02-09 01:47:592313 ChildProcessSecurityPolicyImpl* policy =
2314 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222315 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592316 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212317}
2318
[email protected]b172aee2012-04-10 17:05:262319void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432320 if (delegate_)
2321 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202322}
2323
[email protected]b172aee2012-04-10 17:05:262324void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2325 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262326 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362327 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432328 if (!delegate_)
2329 return;
2330
[email protected]b9535422012-02-09 01:47:592331 ChildProcessSecurityPolicyImpl* policy =
2332 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322333 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592334 return;
[email protected]8f810632013-06-06 22:33:322335
[email protected]3a3b75a2012-06-01 08:38:362336 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202337}
2338
[email protected]b172aee2012-04-10 17:05:262339void WebContentsImpl::OnFindReply(int request_id,
2340 int number_of_matches,
2341 const gfx::Rect& selection_rect,
2342 int active_match_ordinal,
2343 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432344 if (delegate_) {
2345 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2346 active_match_ordinal, final_update);
2347 }
[email protected]b888919c2011-09-02 00:32:162348}
2349
[email protected]59363fc92012-09-05 03:46:312350#if defined(OS_ANDROID)
2351void WebContentsImpl::OnFindMatchRectsReply(
2352 int version,
2353 const std::vector<gfx::RectF>& rects,
2354 const gfx::RectF& active_rect) {
2355 if (delegate_)
2356 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2357}
[email protected]583418cc2013-01-17 14:01:102358
[email protected]1ff427972013-02-07 21:14:072359void WebContentsImpl::OnOpenDateTimeDialog(
2360 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092361 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2362 GetRenderViewHost(),
2363 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132364 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092365 value.minimum,
2366 value.maximum,
2367 value.step);
[email protected]583418cc2013-01-17 14:01:102368}
2369
[email protected]a794f3a2013-10-30 17:00:322370void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2371 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]c80725d52013-12-06 06:22:262372 message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322373}
2374
[email protected]59363fc92012-09-05 03:46:312375#endif
2376
[email protected]c80725d52013-12-06 06:22:262377void WebContentsImpl::OnCrashedPlugin(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422378 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442379 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422380 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452381}
2382
[email protected]b172aee2012-04-10 17:05:262383void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2384 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102385 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252386 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102387 AppCacheAccessed(manifest_url, blocked_by_policy));
2388}
2389
[email protected]8bc5ff02013-11-29 06:34:032390void WebContentsImpl::OnOpenColorChooser(
2391 int color_chooser_id,
2392 SkColor color,
2393 const std::vector<ColorSuggestion>& suggestions) {
2394 ColorChooser* new_color_chooser =
2395 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]cb805452013-05-22 15:16:212396 if (color_chooser_ == new_color_chooser)
2397 return;
2398 color_chooser_.reset(new_color_chooser);
2399 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202400}
2401
[email protected]b172aee2012-04-10 17:05:262402void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202403 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212404 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202405 color_chooser_->End();
2406}
2407
[email protected]b172aee2012-04-10 17:05:262408void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322409 SkColor color) {
[email protected]da8543762012-03-20 08:52:202410 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212411 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202412 color_chooser_->SetSelectedColor(color);
2413}
2414
[email protected]d0759f492012-04-19 22:50:502415// This exists for render views that don't have a WebUI, but do have WebUI
2416// bindings enabled.
2417void WebContentsImpl::OnWebUISend(const GURL& source_url,
2418 const std::string& name,
2419 const base::ListValue& args) {
2420 if (delegate_)
2421 delegate_->WebUISend(this, source_url, name, args);
2422}
2423
[email protected]d8415ad92012-08-23 14:40:502424void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442425 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502426 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342427 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162428 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442429 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162430 return;
[email protected]d8415ad92012-08-23 14:40:502431 }
2432
[email protected]8c8fc292012-11-23 18:57:162433 if (!delegate_->RequestPpapiBrokerPermission(
2434 this, url, plugin_path,
2435 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442436 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162437 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442438 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162439 }
[email protected]d8415ad92012-08-23 14:40:502440}
2441
[email protected]ea0309c2013-08-06 19:35:442442void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502443 bool result) {
[email protected]ea0309c2013-08-06 19:35:442444 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502445}
2446
[email protected]c4538072013-03-18 02:17:552447void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372448 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082449 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552450 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392451 // For more info, see comment above classes BrowserPluginEmbedder and
2452 // BrowserPluginGuest.
2453 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142454 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082455 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372456}
2457
[email protected]41225fe2013-03-29 05:32:022458void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392459 int id,
[email protected]749fadd2013-05-15 08:37:482460 int http_status_code,
[email protected]795c28972012-12-06 06:13:392461 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302462 const std::vector<SkBitmap>& bitmaps,
2463 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]41225fe2013-03-29 05:32:022464 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2465 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392466 // Currently WebContents notifies us of ANY downloads so that it is
2467 // possible to get here.
2468 return;
2469 }
2470 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302471 iter->second.Run(
2472 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392473 }
[email protected]41225fe2013-03-29 05:32:022474 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392475}
2476
2477void WebContentsImpl::OnUpdateFaviconURL(
2478 int32 page_id,
2479 const std::vector<FaviconURL>& candidates) {
2480 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2481 DidUpdateFaviconURL(page_id, candidates));
2482}
2483
[email protected]d9030b82013-07-19 08:26:062484void WebContentsImpl::OnMediaNotification(int64 player_cookie,
2485 bool has_video,
2486 bool has_audio,
2487 bool is_playing) {
2488 // Chrome OS does its own detection of audio and video.
2489#if !defined(OS_CHROMEOS)
2490 if (is_playing) {
2491 scoped_ptr<PowerSaveBlocker> blocker;
2492 if (has_video) {
2493 blocker = PowerSaveBlocker::Create(
2494 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep,
2495 "Playing video");
2496#if defined(OS_ANDROID)
2497 static_cast<PowerSaveBlockerImpl*>(blocker.get())->
[email protected]26f4aa4b2013-08-10 13:48:382498 InitDisplaySleepBlocker(GetView()->GetNativeView());
[email protected]d9030b82013-07-19 08:26:062499#endif
2500 } else if (has_audio) {
2501 blocker = PowerSaveBlocker::Create(
2502 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
2503 "Playing audio");
2504 }
2505
[email protected]c80725d52013-12-06 06:22:262506 if (blocker)
2507 power_save_blockers_[message_source_][player_cookie] = blocker.release();
[email protected]d9030b82013-07-19 08:26:062508 } else {
[email protected]c80725d52013-12-06 06:22:262509 delete power_save_blockers_[message_source_][player_cookie];
2510 power_save_blockers_[message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062511 }
2512#endif // !defined(OS_CHROMEOS)
2513}
2514
[email protected]9f268072013-11-07 00:02:152515void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2516 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2517 DidFirstVisuallyNonEmptyPaint(page_id));
2518}
[email protected]d9030b82013-07-19 08:26:062519
[email protected]e67ebf32013-02-13 11:07:192520void WebContentsImpl::DidChangeVisibleSSLState() {
2521 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2522 DidChangeVisibleSSLState());
2523}
2524
[email protected]17e286e2013-03-01 23:29:392525void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2526 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2527 BeforeFormRepostWarningShow());
2528}
2529
[email protected]ec6c05f2013-10-23 18:41:572530
2531void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2532 Activate();
2533 if (delegate_)
2534 delegate_->ShowRepostFormWarningDialog(this);
2535}
2536
[email protected]96d185d2009-04-24 03:28:542537// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592538// loading, or done loading.
2539void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2540 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262541 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542542 if (is_loading == is_loading_)
2543 return;
2544
2545 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262546 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2547 base::string16());
[email protected]96d185d2009-04-24 03:28:542548 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562549 upload_size_ = 0;
2550 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542551 }
2552
[email protected]fa944cb82013-11-15 17:51:212553 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542554
2555 is_loading_ = is_loading;
2556 waiting_for_response_ = is_loading;
2557
[email protected]6ebdc9b2010-09-27 16:55:572558 if (delegate_)
2559 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212560 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542561
[email protected]eab61442013-11-14 18:35:482562 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592563 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482564 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2565 "URL", url);
[email protected]91621872013-10-08 04:04:592566 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2567 DidStartLoading(render_view_host));
2568 } else {
[email protected]eab61442013-11-14 18:35:482569 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2570 "URL", url);
[email protected]91621872013-10-08 04:04:592571 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2572 DidStopLoading(render_view_host));
2573 }
[email protected]66798902013-10-01 18:40:162574
2575 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212576 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2577 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542578 if (details)
[email protected]8ff00d72012-10-23 19:12:212579 det = Details<LoadNotificationDetails>(details);
2580 NotificationService::current()->Notify(
2581 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542582}
2583
[email protected]b172aee2012-04-10 17:05:262584void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8ff00d72012-10-23 19:12:212585 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322586 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4e697b042011-07-08 06:44:562587 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322588 // Clear the status bubble. This is a workaround for a bug where WebKit
2589 // doesn't let us know that the cursor left an element during a
2590 // transition (this is also why the mouse cursor remains as a hand after
2591 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2592 // clear the bubble when a user navigates to a named anchor in the same
2593 // page.
[email protected]36fc0392011-12-25 03:59:512594 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322595 }
2596
[email protected]a6e82fc2010-02-24 22:28:142597 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472598 // Once the main frame is navigated, we're no longer considered to have
2599 // displayed insecure content.
2600 displayed_insecure_content_ = false;
[email protected]63e38082013-07-31 09:30:352601 SSLManager::NotifySSLInternalStateChanged(
2602 GetController().GetBrowserContext());
[email protected]aece2c7f2009-08-27 20:43:172603 }
[email protected]ce5c4502009-05-06 16:46:112604
[email protected]3c9e1872010-11-18 16:17:492605 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252606 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042607 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322608}
2609
[email protected]b172aee2012-04-10 17:05:262610void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322611 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:212612 const LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322613 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]4567f152013-07-31 13:20:112614 // If we navigate off the page, close all JavaScript dialogs.
2615 if (dialog_manager_ && !details.is_in_page)
2616 dialog_manager_->CancelActiveAndPendingDialogs(this);
[email protected]420ae012009-04-24 05:16:322617
[email protected]3c9e1872010-11-18 16:17:492618 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252619 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042620 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322621}
2622
[email protected]2f7b3c5a2013-06-21 04:59:252623bool WebContentsImpl::ShouldAssignSiteForURL(const GURL& url) {
[email protected]3d831992013-07-04 01:13:292624 // about:blank should not "use up" a new SiteInstance. The SiteInstance can
2625 // still be used for a normal web site.
2626 if (url == GURL(kAboutBlankURL))
2627 return false;
2628
2629 // The embedder will then have the opportunity to determine if the URL
2630 // should "use up" the SiteInstance.
2631 return GetContentClient()->browser()->ShouldAssignSiteForURL(url);
[email protected]2f7b3c5a2013-06-21 04:59:252632}
2633
[email protected]b172aee2012-04-10 17:05:262634void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462635 // If we are creating a RVH for a restored controller, then we need to make
2636 // sure the RenderView starts with a next_page_id_ larger than the number
2637 // of restored entries. This must be called before the RenderView starts
2638 // navigating (to avoid a race between the browser updating max_page_id and
2639 // the renderer updating next_page_id_). Because of this, we only call this
2640 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562641 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582642 if (max_restored_page_id >
2643 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2644 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2645 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322646}
2647
[email protected]b172aee2012-04-10 17:05:262648bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262649 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322650 // For file URLs without a title, use the pathname instead. In the case of a
2651 // synthesized title, we don't want the update to count toward the "one set
2652 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262653 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322654 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512655 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2656 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322657 explicit_set = false; // Don't count synthetic titles toward the set limit.
2658 } else {
[email protected]acafd272011-07-26 17:35:572659 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322660 explicit_set = true;
2661 }
2662
[email protected]987fc3a2011-05-26 14:18:092663 // If a page is created via window.open and never navigated,
2664 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552665 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092666 if (entry) {
[email protected]36fc0392011-12-25 03:59:512667 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092668 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322669
[email protected]36fc0392011-12-25 03:59:512670 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092671 } else {
2672 if (page_title_when_no_navigation_entry_ == final_title)
2673 return false; // Nothing changed, don't bother.
2674
2675 page_title_when_no_navigation_entry_ = final_title;
2676 }
[email protected]420ae012009-04-24 05:16:322677
[email protected]420ae012009-04-24 05:16:322678 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232679 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322680
[email protected]66798902013-10-01 18:40:162681 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532682 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162683
2684 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212685 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462686 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212687 NotificationService::current()->Notify(
2688 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2689 Source<WebContents>(this),
2690 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042691
[email protected]420ae012009-04-24 05:16:322692 return true;
2693}
2694
[email protected]7b712ee22013-10-03 00:57:282695void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2696 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322697 // After sending out a swap notification, we need to send a disconnect
2698 // notification so that clients that pick up a pointer to |this| can NULL the
2699 // pointer. See Bug 1230284.
2700 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112701 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282702 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112703
2704 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282705 std::pair<RenderViewHost*, RenderViewHost*> details =
2706 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212707 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282708 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212709 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282710 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392711
2712 // Ensure that the associated embedder gets cleared after a RenderViewHost
2713 // gets swapped, so we don't reuse the same embedder next time a
2714 // RenderViewHost is attached to this WebContents.
2715 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322716}
2717
[email protected]da7a7182013-09-06 08:11:112718// TODO(avi): Remove this entire function because this notification is already
2719// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262720void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322721 if (!notify_disconnection_)
2722 return;
2723
2724 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212725 NotificationService::current()->Notify(
2726 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2727 Source<WebContents>(this),
2728 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322729}
2730
[email protected]cbb1ef592013-06-05 19:49:462731void WebContentsImpl::NotifyNavigationEntryCommitted(
2732 const LoadCommittedDetails& load_details) {
2733 FOR_EACH_OBSERVER(
2734 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2735}
2736
[email protected]c80725d52013-12-06 06:22:262737void WebContentsImpl::PepperPluginHung(int plugin_child_id,
2738 const base::FilePath& path,
2739 bool is_hung) {
2740 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2741
2742 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2743 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]271ff5792013-12-04 22:29:312744}
2745
[email protected]5a3bdf52012-05-24 15:12:572746RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2747 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322748}
2749
[email protected]8d3347f2009-07-09 22:00:212750RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262751WebContentsImpl::GetRendererManagementDelegate() {
[email protected]fa944cb82013-11-15 17:51:212752 return GetRenderManager();
[email protected]8d3347f2009-07-09 22:00:212753}
2754
[email protected]8ff00d72012-10-23 19:12:212755RendererPreferences WebContentsImpl::GetRendererPrefs(
2756 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462757 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512758}
2759
[email protected]b172aee2012-04-10 17:05:262760WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172761 return this;
2762}
2763
[email protected]b172aee2012-04-10 17:05:262764gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172765 if (delegate_)
2766 return delegate_->GetRootWindowResizerRect();
2767 return gfx::Rect();
2768}
2769
[email protected]7a846df2012-09-20 19:17:392770void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272771 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392772 browser_plugin_embedder_.reset();
2773}
2774
[email protected]b172aee2012-04-10 17:05:262775void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442776 // Don't send notifications if we are just creating a swapped-out RVH for
2777 // the opener chain. These won't be used for view-source or WebUI, so it's
2778 // ok to return early.
2779 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2780 return;
2781
[email protected]86f98a22013-03-20 14:35:002782 if (delegate_)
2783 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082784
[email protected]8ff00d72012-10-23 19:12:212785 NotificationService::current()->Notify(
2786 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2787 Source<WebContents>(this),
2788 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322789
2790 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352791 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212792 if (GetRenderManager()->pending_web_ui())
2793 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322794
[email protected]6286a372013-10-09 04:03:272795 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332796 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322797 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182798 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582799 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322800 }
[email protected]0666aef2009-05-13 19:48:082801
[email protected]60780f412013-02-25 16:34:102802 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262803
2804 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252805 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322806}
2807
[email protected]b172aee2012-04-10 17:05:262808void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522809 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322810 // Don't notify the world, since this came from a renderer in the
2811 // background.
2812 return;
2813 }
2814
[email protected]da7a7182013-09-06 08:11:112815 notify_disconnection_ = true;
2816 // TODO(avi): Remove. http://crbug.com/170921
2817 NotificationService::current()->Notify(
2818 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2819 Source<WebContents>(this),
2820 NotificationService::NoDetails());
2821
[email protected]be1f56ab2011-12-22 06:55:312822 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232823 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302824
2825 // Restore the focus to the tab (otherwise the focus will be on the top
2826 // window).
[email protected]484ae5912010-09-29 19:16:142827 if (was_crashed && !FocusLocationBarByDefault() &&
2828 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062829 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142830 }
[email protected]32ded2212011-11-10 18:51:432831
[email protected]d8c660432011-12-22 20:51:252832 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322833}
2834
[email protected]ec6a7eb2013-04-22 17:34:222835void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2836 base::TerminationStatus status,
2837 int error_code) {
[email protected]151a63d2011-12-20 22:32:522838 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322839 // The pending page's RenderViewHost is gone.
2840 return;
2841 }
2842
[email protected]d9030b82013-07-19 08:26:062843 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592844 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322845 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232846 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312847 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322848
[email protected]d8c660432011-12-22 20:51:252849 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272850 observers_,
[email protected]58d5cfe2013-07-10 02:40:522851 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322852}
2853
[email protected]b172aee2012-04-10 17:05:262854void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062855 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212856 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252857 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062858}
2859
[email protected]b0f724c2013-09-05 04:21:132860void WebContentsImpl::DidGetResourceResponseStart(
2861 const ResourceRequestDetails& details) {
2862 controller_.ssl_manager()->DidStartResourceResponse(details);
2863
2864 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2865 DidGetResourceResponseStart(details));
2866
2867 // TODO(avi): Remove. http://crbug.com/170921
2868 NotificationService::current()->Notify(
2869 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2870 Source<WebContents>(this),
2871 Details<const ResourceRequestDetails>(&details));
2872}
2873
2874void WebContentsImpl::DidGetRedirectForResourceRequest(
2875 const ResourceRedirectDetails& details) {
2876 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2877
2878 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2879 DidGetRedirectForResourceRequest(details));
2880
2881 // TODO(avi): Remove. http://crbug.com/170921
2882 NotificationService::current()->Notify(
2883 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2884 Source<WebContents>(this),
2885 Details<const ResourceRedirectDetails>(&details));
2886}
2887
[email protected]b172aee2012-04-10 17:05:262888void WebContentsImpl::DidNavigate(
2889 RenderViewHost* rvh,
2890 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]9b159a52013-10-03 17:24:552891 if (frame_tree_.IsFirstNavigationAfterSwap()) {
2892 // First navigation should be a main frame navigation.
[email protected]50904452013-05-09 02:05:122893 DCHECK(PageTransitionIsMainFrame(params.transition));
[email protected]9b159a52013-10-03 17:24:552894 frame_tree_.OnFirstNavigationAfterSwap(params.frame_id);
[email protected]50904452013-05-09 02:05:122895 }
2896
[email protected]e3d92a7f2013-01-10 02:35:052897 if (PageTransitionIsMainFrame(params.transition)) {
2898 // When overscroll navigation gesture is enabled, a screenshot of the page
2899 // in its current state is taken so that it can be used during the
2900 // nav-gesture. It is necessary to take the screenshot here, before calling
[email protected]b0936d22013-11-28 06:47:362901 // RenderFrameHostManager::DidNavigateMainFrame, because that can change
[email protected]e3d92a7f2013-01-10 02:35:052902 // WebContents::GetRenderViewHost to return the new host, instead of the one
2903 // that may have just been swapped out.
[email protected]06325e12013-01-31 04:34:482904 if (delegate_ && delegate_->CanOverscrollContent())
2905 controller_.TakeScreenshot();
[email protected]e3d92a7f2013-01-10 02:35:052906
[email protected]fa944cb82013-11-15 17:51:212907 GetRenderManager()->DidNavigateMainFrame(rvh);
[email protected]e3d92a7f2013-01-10 02:35:052908 }
[email protected]8030f012009-09-25 18:09:372909
[email protected]434f69f2012-02-06 21:56:522910 // Update the site of the SiteInstance if it doesn't have one yet, unless
[email protected]2f7b3c5a2013-06-21 04:59:252911 // assigning a site is not necessary for this URL. In that case, the
2912 // SiteInstance can still be considered unused until a navigation to a real
2913 // page.
[email protected]434f69f2012-02-06 21:56:522914 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
[email protected]2f7b3c5a2013-06-21 04:59:252915 ShouldAssignSiteForURL(params.url)) {
[email protected]b6583592012-01-25 19:52:332916 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522917 }
[email protected]420ae012009-04-24 05:16:322918
2919 // Need to update MIME type here because it's referred to in
2920 // UpdateNavigationCommands() called by RendererDidNavigate() to
2921 // determine whether or not to enable the encoding menu.
2922 // It's updated only for the main frame. For a subframe,
2923 // RenderView::UpdateURL does not set params.contents_mime_type.
2924 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2925 // TODO(jungshik): Add a test for the encoding menu to avoid
2926 // regressing it again.
[email protected]8ff00d72012-10-23 19:12:212927 if (PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322928 contents_mime_type_ = params.contents_mime_type;
2929
[email protected]8ff00d72012-10-23 19:12:212930 LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002931 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392932
[email protected]1ae93fb2013-06-14 03:38:562933 // For now, keep track of each frame's URL in its FrameTreeNode. This lets
2934 // us estimate our process count for implementing OOP iframes.
2935 // TODO(creis): Remove this when we track which pages commit in each frame.
[email protected]9b159a52013-10-03 17:24:552936 frame_tree_.SetFrameUrl(params.frame_id, params.url);
[email protected]1ae93fb2013-06-14 03:38:562937
[email protected]a9c0bfe2010-09-17 08:35:222938 // Send notification about committed provisional loads. This notification is
2939 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2940 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]8ff00d72012-10-23 19:12:212941 if (details.type != NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072942 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2943 // that is not recorded in the navigation history. For the purpose of
2944 // tracking navigation events, we treat this event as a sub frame navigation
2945 // event.
2946 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]8ff00d72012-10-23 19:12:212947 PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222948 // Whether or not a page transition was triggered by going backward or
2949 // forward in the history is only stored in the navigation controller's
2950 // entry list.
2951 if (did_navigate &&
[email protected]6286a372013-10-09 04:03:272952 (controller_.GetLastCommittedEntry()->GetTransitionType() &
[email protected]8ff00d72012-10-23 19:12:212953 PAGE_TRANSITION_FORWARD_BACK)) {
2954 transition_type = PageTransitionFromInt(
2955 params.transition | PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222956 }
[email protected]0d60f0192011-04-14 12:40:102957 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252958 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]2f673064c2013-10-22 04:01:442959 DidCommitProvisionalLoadForFrame(
2960 params.frame_id,
2961 params.frame_unique_name,
2962 is_main_frame,
2963 params.url,
2964 transition_type,
2965 rvh));
[email protected]a9c0bfe2010-09-17 08:35:222966 }
2967
[email protected]76543b92009-08-31 17:27:452968 if (!did_navigate)
2969 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322970
2971 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2972 // for the appropriate notification (best) or you can add it to
2973 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2974 // necessary, please).
2975
2976 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002977 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322978 DidNavigateMainFramePostCommit(details, params);
[email protected]86f98a22013-03-20 14:35:002979 if (delegate_) {
[email protected]6934a702011-12-20 00:04:512980 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]86f98a22013-03-20 14:35:002981 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2982 }
[email protected]93f230e02011-06-01 14:40:002983 }
[email protected]420ae012009-04-24 05:16:322984 DidNavigateAnyFramePostCommit(rvh, details, params);
2985}
2986
[email protected]b172aee2012-04-10 17:05:262987void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2988 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042989 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152990 // Ensure that this state update comes from either the active RVH or one of
2991 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]fa944cb82013-11-15 17:51:212992 DCHECK(rvh == GetRenderViewHost() ||
2993 GetRenderManager()->IsOnSwappedOutList(rvh));
[email protected]420ae012009-04-24 05:16:322994
2995 // We must be prepared to handle state updates for any page, these occur
2996 // when the user is scrolling and entering form data, as well as when we're
2997 // leaving a page, in which case our state may have already been moved to
2998 // the next page. The navigation controller will look up the appropriate
2999 // NavigationEntry and update it when it is notified via the delegate.
3000
3001 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583002 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323003 if (entry_index < 0)
3004 return;
[email protected]10f417c52011-12-28 21:04:233005 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323006
[email protected]691aa2f2013-05-28 22:52:043007 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323008 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043009 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323010 controller_.NotifyEntryChanged(entry, entry_index);
3011}
3012
[email protected]b172aee2012-04-10 17:05:263013void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
3014 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:263015 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:263016 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:323017 // If we have a title, that's a pretty good indication that we've started
3018 // getting useful data.
3019 SetNotWaitingForResponse();
3020
[email protected]73eb2602012-02-09 19:50:553021 // Try to find the navigation entry, which might not be the current one.
3022 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:233023 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583024 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:093025
[email protected]73eb2602012-02-09 19:50:553026 // We can handle title updates when we don't have an entry in
3027 // UpdateTitleForEntry, but only if the update is from the current RVH.
3028 if (!entry && rvh != GetRenderViewHost())
3029 return;
3030
[email protected]a49e10b2011-08-01 23:57:463031 // TODO(evan): make use of title_direction.
3032 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:093033 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:323034 return;
3035
3036 // Broadcast notifications when the UI should be updated.
3037 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:213038 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:323039}
3040
[email protected]b172aee2012-04-10 17:05:263041void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
3042 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:313043 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:323044}
3045
[email protected]b172aee2012-04-10 17:05:263046void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513047 if (delegate_)
3048 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323049}
3050
[email protected]b172aee2012-04-10 17:05:263051void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103052#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293053 // The UI may be in an event-tracking loop, such as between the
3054 // mouse-down and mouse-up in text selection or a button click.
3055 // Defer the close until after tracking is complete, so that we
3056 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293057 // TODO(shess): This could get more fine-grained. For instance,
3058 // closing a tab in another window while selecting text in the
3059 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103060 if (view_->IsEventTracking()) {
3061 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293062 return;
3063 }
[email protected]60780f412013-02-25 16:34:103064#endif
[email protected]07707302009-11-06 00:50:293065
[email protected]420ae012009-04-24 05:16:323066 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523067 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513068 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323069}
3070
[email protected]b172aee2012-04-10 17:05:263071void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523072 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513073 delegate_->SwappedOut(this);
[email protected]e1986832013-06-14 07:27:283074
3075 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213076 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573077}
3078
[email protected]b172aee2012-04-10 17:05:263079void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513080 if (delegate_ && delegate_->IsPopupOrPanel(this))
3081 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323082}
3083
[email protected]8ff00d72012-10-23 19:12:213084void WebContentsImpl::DidStartLoading(RenderViewHost* render_view_host) {
[email protected]91621872013-10-08 04:04:593085 SetIsLoading(render_view_host, true, NULL);
[email protected]420ae012009-04-24 05:16:323086}
3087
[email protected]8ff00d72012-10-23 19:12:213088void WebContentsImpl::DidStopLoading(RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323089 scoped_ptr<LoadNotificationDetails> details;
3090
[email protected]9595fd82013-04-19 21:28:493091 // Use the last committed entry rather than the active one, in case a
3092 // pending entry has been created.
3093 NavigationEntry* entry = controller_.GetLastCommittedEntry();
3094
[email protected]420ae012009-04-24 05:16:323095 // An entry may not exist for a stop when loading an initial blank page or
3096 // if an iframe injected by script into a blank page finishes loading.
3097 if (entry) {
[email protected]420ae012009-04-24 05:16:323098 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
3099
3100 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513101 entry->GetVirtualURL(),
3102 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323103 elapsed,
3104 &controller_,
3105 controller_.GetCurrentEntryIndex()));
3106 }
3107
[email protected]91621872013-10-08 04:04:593108 SetIsLoading(render_view_host, false, details.get());
[email protected]420ae012009-04-24 05:16:323109}
3110
[email protected]b172aee2012-04-10 17:05:263111void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163112 controller_.DiscardNonCommittedEntries();
3113
3114 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213115 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163116}
3117
[email protected]b172aee2012-04-10 17:05:263118void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513119 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133120 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403121}
3122
[email protected]7cc78902012-12-06 02:32:263123void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393124 if (opener_) {
3125 // Clear our opener so that future cross-process navigations don't have an
3126 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103127 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393128 opener_ = NULL;
3129 }
[email protected]7cc78902012-12-06 02:32:263130
3131 // Notify all swapped out RenderViewHosts for this tab. This is important
3132 // in case we go back to them, or if another window in those processes tries
3133 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213134 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263135}
3136
[email protected]59167c22013-06-03 18:07:323137void WebContentsImpl::DidAccessInitialDocument() {
3138 // Update the URL display.
3139 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3140}
3141
[email protected]87717d0e2012-04-26 02:58:433142void WebContentsImpl::DocumentAvailableInMainFrame(
3143 RenderViewHost* render_view_host) {
3144 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3145 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103146}
3147
[email protected]b172aee2012-04-10 17:05:263148void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083149 RenderViewHost* render_view_host,
3150 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093151 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3152 DocumentOnLoadCompletedInMainFrame(page_id));
3153
3154 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213155 NotificationService::current()->Notify(
3156 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3157 Source<WebContents>(this),
3158 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083159}
3160
[email protected]196159d2012-05-04 17:26:543161void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
3162 const GURL& url,
[email protected]8ff00d72012-10-23 19:12:213163 const Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263164 WindowOpenDisposition disposition,
[email protected]e2caa032012-11-15 23:29:183165 int64 source_frame_id,
[email protected]866fa2cc2013-07-22 22:19:523166 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303167 bool user_gesture) {
[email protected]196159d2012-05-04 17:26:543168 // If this came from a swapped out RenderViewHost, we only allow the request
3169 // if we are still in the same BrowsingInstance.
3170 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
3171 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
3172 return;
3173 }
3174
[email protected]4ad5d77d2011-12-03 02:00:483175 // Delegate to RequestTransferURL because this is just the generic
3176 // case where |old_request_id| is empty.
[email protected]f8872902013-10-30 03:18:573177 // TODO(creis): Pass the redirect_chain into this method to support client
3178 // redirects. http://crbug.com/311721.
3179 std::vector<GURL> redirect_chain;
3180 RequestTransferURL(url, redirect_chain, referrer, PAGE_TRANSITION_LINK,
3181 disposition, source_frame_id, GlobalRequestID(),
[email protected]866fa2cc2013-07-22 22:19:523182 should_replace_current_entry, user_gesture);
[email protected]4ad5d77d2011-12-03 02:00:483183}
3184
[email protected]b172aee2012-04-10 17:05:263185void WebContentsImpl::RequestTransferURL(
3186 const GURL& url,
[email protected]f8872902013-10-30 03:18:573187 const std::vector<GURL>& redirect_chain,
[email protected]8ff00d72012-10-23 19:12:213188 const Referrer& referrer,
[email protected]f8872902013-10-30 03:18:573189 PageTransition page_transition,
[email protected]b172aee2012-04-10 17:05:263190 WindowOpenDisposition disposition,
3191 int64 source_frame_id,
[email protected]e2caa032012-11-15 23:29:183192 const GlobalRequestID& old_request_id,
[email protected]866fa2cc2013-07-22 22:19:523193 bool should_replace_current_entry,
[email protected]e7f2e7c2013-07-15 09:41:303194 bool user_gesture) {
[email protected]e5d549d2011-12-28 01:29:203195 WebContents* new_contents = NULL;
[email protected]9a60d1602013-09-11 04:09:123196 GURL dest_url(url);
3197 if (!GetContentClient()->browser()->ShouldAllowOpenURL(
[email protected]44d0930a2013-10-28 18:53:553198 GetSiteInstance(), url))
[email protected]9a60d1602013-09-11 04:09:123199 dest_url = GURL(kAboutBlankURL);
3200
[email protected]c80297782013-11-21 07:10:163201 // TODO(creis): Look up the FrameTreeNode ID corresponding to source_frame_id.
3202 int frame_tree_node_id = -1;
3203 OpenURLParams params(dest_url, referrer, source_frame_id,
3204 frame_tree_node_id, disposition,
[email protected]f8872902013-10-30 03:18:573205 page_transition, true /* is_renderer_initiated */);
3206 if (redirect_chain.size() > 0)
3207 params.redirect_chain = redirect_chain;
[email protected]44d0930a2013-10-28 18:53:553208 params.transferred_global_request_id = old_request_id;
3209 params.should_replace_current_entry = should_replace_current_entry;
3210 params.user_gesture = user_gesture;
3211
[email protected]fa944cb82013-11-15 17:51:213212 if (GetRenderManager()->web_ui()) {
[email protected]f8872902013-10-30 03:18:573213 // Web UI pages sometimes want to override the page transition type for
3214 // link clicks (e.g., so the new tab page can specify AUTO_BOOKMARK for
3215 // automatically generated suggestions). We don't override other types
3216 // like TYPED because they have different implications (e.g., autocomplete).
3217 if (PageTransitionCoreTypeIs(params.transition, PAGE_TRANSITION_LINK))
[email protected]fa944cb82013-11-15 17:51:213218 params.transition = GetRenderManager()->web_ui()->GetLinkTransitionType();
[email protected]44d0930a2013-10-28 18:53:553219
[email protected]e0112912011-02-02 22:54:353220 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:163221 // want web sites to see a referrer of "chrome://blah" (and some
3222 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:323223 // send to the site), so we send no referrer.
[email protected]44d0930a2013-10-28 18:53:553224 params.referrer = Referrer();
3225
3226 // Navigations in Web UI pages count as browser-initiated navigations.
3227 params.is_renderer_initiated = false;
[email protected]16a13fa2013-11-07 01:03:533228
3229 // TODO(creis): Remove this line. In the short term, it fixes a regression
3230 // (http://crbug.com/313572) by partially reverting r231370.
3231 // The underlying problem is that WebDataSource::replacesCurrentHistoryItem
3232 // should be returning false when the CWS goes to the sign-in page.
3233 // See http://crbug.com/311721.
3234 params.should_replace_current_entry = false;
[email protected]ae5184d62011-10-06 19:25:583235 }
[email protected]44d0930a2013-10-28 18:53:553236
3237 new_contents = OpenURL(params);
3238
[email protected]ae5184d62011-10-06 19:25:583239 if (new_contents) {
3240 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253241 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:583242 DidOpenRequestedURL(new_contents,
[email protected]9a60d1602013-09-11 04:09:123243 dest_url,
[email protected]ae5184d62011-10-06 19:25:583244 referrer,
3245 disposition,
[email protected]44d0930a2013-10-28 18:53:553246 params.transition,
[email protected]ae5184d62011-10-06 19:25:583247 source_frame_id));
[email protected]420ae012009-04-24 05:16:323248 }
3249}
3250
[email protected]e1c3a552012-05-04 20:51:323251void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3252 // Tell the active RenderViewHost to run unload handlers and close, as long
3253 // as the request came from a RenderViewHost in the same BrowsingInstance.
3254 // In most cases, we receive this from a swapped out RenderViewHost.
3255 // It is possible to receive it from one that has just been swapped in,
3256 // in which case we might as well deliver the message anyway.
3257 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3258 GetRenderViewHost()->ClosePage();
3259}
3260
[email protected]f546640b2012-05-15 00:03:493261void WebContentsImpl::RouteMessageEvent(
3262 RenderViewHost* rvh,
3263 const ViewMsg_PostMessage_Params& params) {
3264 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363265 // came from a RenderViewHost in the same BrowsingInstance or if this
3266 // WebContents is dedicated to a browser plugin guest.
3267 // Note: This check means that an embedder could theoretically receive a
3268 // postMessage from anyone (not just its own guests). However, this is
3269 // probably not a risk for apps since other pages won't have references
3270 // to App windows.
3271 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3272 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493273 return;
3274
3275 ViewMsg_PostMessage_Params new_params(params);
3276
[email protected]0bc7f3542013-10-21 15:05:533277 if (!params.message_port_ids.empty()) {
3278 MessagePortMessageFilter* message_port_message_filter =
3279 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3280 ->message_port_message_filter();
3281 std::vector<int> new_routing_ids(params.message_port_ids.size());
3282 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3283 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3284 MessagePortService::GetInstance()->UpdateMessagePort(
3285 params.message_port_ids[i],
3286 message_port_message_filter,
3287 new_routing_ids[i]);
3288 }
3289 new_params.new_routing_ids = new_routing_ids;
3290 }
3291
[email protected]f546640b2012-05-15 00:03:493292 // If there is a source_routing_id, translate it to the routing ID for
3293 // the equivalent swapped out RVH in the target process. If we need
3294 // to create a swapped out RVH for the source tab, we create its opener
3295 // chain as well, since those will also be accessible to the target page.
3296 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3297 // Try to look up the WebContents for the source page.
3298 WebContentsImpl* source_contents = NULL;
3299 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3300 rvh->GetProcess()->GetID(), params.source_routing_id);
3301 if (source_rvh) {
3302 source_contents = static_cast<WebContentsImpl*>(
3303 source_rvh->GetDelegate()->GetAsWebContents());
3304 }
3305
3306 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363307 if (GetBrowserPluginGuest()) {
3308 // We create a swapped out RenderView for the embedder in the guest's
3309 // render process but we intentionally do not expose the embedder's
3310 // opener chain to it.
3311 new_params.source_routing_id =
3312 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3313 } else {
3314 new_params.source_routing_id =
3315 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3316 }
[email protected]f546640b2012-05-15 00:03:493317 } else {
3318 // We couldn't find it, so don't pass a source frame.
3319 new_params.source_routing_id = MSG_ROUTING_NONE;
3320 }
3321 }
3322
3323 // In most cases, we receive this from a swapped out RenderViewHost.
3324 // It is possible to receive it from one that has just been swapped in,
3325 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183326 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493327}
3328
[email protected]b172aee2012-04-10 17:05:263329void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343330 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263331 const base::string16& message,
3332 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323333 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213334 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323335 IPC::Message* reply_msg,
3336 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073337 // Suppress JavaScript dialogs when requested. Also suppress messages when
3338 // showing an interstitial as it's shown over the previous page and we don't
3339 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503340 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583341 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:273342 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073343 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523344 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153345 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323346
3347 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213348 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433349 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153350 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3351 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433352 this,
3353 frame_url.GetOrigin(),
3354 accept_lang,
3355 javascript_message_type,
3356 message,
[email protected]51da7e32012-01-30 19:24:523357 default_prompt,
[email protected]b172aee2012-04-10 17:05:263358 base::Bind(&WebContentsImpl::OnDialogClosed,
3359 base::Unretained(this),
3360 rvh,
3361 reply_msg),
[email protected]51da7e32012-01-30 19:24:523362 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323363 }
[email protected]3ab9cb82011-06-03 18:02:073364
[email protected]6dd2f1e2013-09-11 15:06:013365 *did_suppress_message = suppress_this_message;
3366
[email protected]3ab9cb82011-06-03 18:02:073367 if (suppress_this_message) {
3368 // If we are suppressing messages, just reply as if the user immediately
3369 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263370 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073371 }
3372
[email protected]6dd2f1e2013-09-11 15:06:013373 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3374 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323375}
3376
[email protected]b172aee2012-04-10 17:05:263377void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263378 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263379 bool is_reload,
3380 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583381 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513382 if (delegate_)
3383 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073384
3385 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:583386 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:073387 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523388 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153389 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153390 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343391 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263392 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503393 return;
3394 }
[email protected]3ab9cb82011-06-03 18:02:073395
[email protected]7ab1e7d62009-10-14 23:32:013396 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153397 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3398 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323399 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263400 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523401 reply_msg));
[email protected]420ae012009-04-24 05:16:323402}
3403
[email protected]a796f202012-05-30 14:14:253404bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263405 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253406 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263407 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253408 if (!delegate_)
3409 return false;
3410 return delegate_->AddMessageToConsole(this, level, message, line_no,
3411 source_id);
3412}
3413
[email protected]b172aee2012-04-10 17:05:263414WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273415 // We want to base the page config off of the actual URL, rather than the
3416 // virtual URL.
3417 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3418 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003419 GURL url = controller_.GetActiveEntry()
3420 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153421
[email protected]fa944cb82013-11-15 17:51:213422 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323423}
3424
[email protected]0eba810b2012-10-18 03:19:363425int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213426 SiteInstance* instance) {
[email protected]fa944cb82013-11-15 17:51:213427 return GetRenderManager()->CreateRenderView(instance, MSG_ROUTING_NONE,
3428 true, true);
[email protected]0eba810b2012-10-18 03:19:363429}
3430
[email protected]b172aee2012-04-10 17:05:263431void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273432 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253433 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223434
[email protected]ea114722012-03-12 01:11:253435 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173436 if (rdh) // NULL in unittests.
3437 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253438}
3439
[email protected]b172aee2012-04-10 17:05:263440void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443441 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253442 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443443}
3444
[email protected]b172aee2012-04-10 17:05:263445void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563446 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263447 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153448 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523449 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153450 return;
3451
[email protected]9f76c1e2012-03-05 15:15:583452 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3453
[email protected]e5fc1632011-08-08 07:51:533454 // Ignore renderer unresponsive event if debugger is attached to the tab
3455 // since the event may be a result of the renderer sitting on a breakpoint.
3456 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363457 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533458 return;
3459
[email protected]2e9d79f2013-08-16 05:45:563460 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323461 // Hang occurred while firing the beforeunload/unload handler.
3462 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583463 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323464
[email protected]fa944cb82013-11-15 17:51:213465 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323466 return;
3467
3468 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563469 // nothing we can do to recover. If the hang is in the beforeunload handler,
3470 // pretend the beforeunload listeners have all fired and allow the delegate
3471 // to continue closing; the user will not have the option of cancelling the
3472 // close. Otherwise, pretend the unload listeners have all fired and close
3473 // the tab.
3474 bool close = true;
3475 if (is_during_beforeunload) {
3476 delegate_->BeforeUnloadFired(this, true, &close);
3477 }
3478 if (close)
3479 Close(rvh);
[email protected]420ae012009-04-24 05:16:323480 return;
3481 }
3482
[email protected]9f76c1e2012-03-05 15:15:583483 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473484 return;
3485
[email protected]6934a702011-12-20 00:04:513486 if (delegate_)
3487 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323488}
3489
[email protected]b172aee2012-04-10 17:05:263490void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513491 if (delegate_)
3492 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323493}
3494
[email protected]b172aee2012-04-10 17:05:263495void WebContentsImpl::LoadStateChanged(
3496 const GURL& url,
3497 const net::LoadStateWithParam& load_state,
3498 uint64 upload_position,
3499 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323500 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563501 upload_position_ = upload_position;
3502 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503503 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213504 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303505 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213506 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323507 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463508 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213509 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463510 }
[email protected]420ae012009-04-24 05:16:323511}
3512
[email protected]b172aee2012-04-10 17:05:263513void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:513514 if (delegate_)
3515 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:253516}
3517
[email protected]b172aee2012-04-10 17:05:263518void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553519 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323520 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123521 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3522 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513523 if (delegate_)
3524 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093525 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323526}
3527
[email protected]58d5cfe2013-07-10 02:40:523528void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543529 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233530 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223531 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543532}
3533
[email protected]b172aee2012-04-10 17:05:263534void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103535 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213536 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263537 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3538 // here during container initialization and normal window size will be set
3539 // later. In case of tab duplication this resizing to 0x0 prevents setting
3540 // normal size later so just ignore it.
3541 if (!size.IsEmpty())
3542 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323543}
3544
[email protected]af905902013-10-01 21:38:513545void WebContentsImpl::CancelModalDialogsForRenderManager() {
3546 // We need to cancel modal dialogs when doing a process swap, since the load
3547 // deferrer would prevent us from swapping out.
3548 if (dialog_manager_)
3549 dialog_manager_->CancelActiveAndPendingDialogs(this);
3550}
3551
[email protected]7b712ee22013-10-03 00:57:283552void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3553 RenderViewHost* new_host) {
3554 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083555
3556 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003557 if (delegate_)
3558 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393559
[email protected]7b712ee22013-10-03 00:57:283560 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543561}
3562
[email protected]14392a52012-05-02 20:28:443563int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3564 SiteInstance* instance) {
3565 if (!opener_)
3566 return MSG_ROUTING_NONE;
3567
3568 // Recursively create RenderViews for anything else in the opener chain.
3569 return opener_->CreateOpenerRenderViews(instance);
3570}
3571
3572int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3573 int opener_route_id = MSG_ROUTING_NONE;
3574
3575 // If this tab has an opener, ensure it has a RenderView in the given
3576 // SiteInstance as well.
3577 if (opener_)
3578 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3579
[email protected]45a22ad2013-02-21 03:25:003580 // If any of the renderers (current, pending, or swapped out) for this
3581 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213582 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3583 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373584
[email protected]fa944cb82013-11-15 17:51:213585 if (GetRenderManager()->pending_render_view_host() &&
3586 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3587 instance)
3588 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003589
[email protected]fa944cb82013-11-15 17:51:213590 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373591 instance);
3592 if (rvh)
3593 return rvh->GetRoutingID();
3594
[email protected]14392a52012-05-02 20:28:443595 // Create a swapped out RenderView in the given SiteInstance if none exists,
3596 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]fa944cb82013-11-15 17:51:213597 return GetRenderManager()->CreateRenderView(instance, opener_route_id,
3598 true, true);
[email protected]14392a52012-05-02 20:28:443599}
3600
[email protected]b172aee2012-04-10 17:05:263601NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193602 return GetController();
[email protected]3a3d47472010-07-15 21:03:543603}
3604
[email protected]b172aee2012-04-10 17:05:263605WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563606 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323607}
3608
[email protected]10f417c52011-12-28 21:04:233609NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263610 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323611 return controller_.GetLastCommittedEntry();
3612}
3613
[email protected]b172aee2012-04-10 17:05:263614bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:443615 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]e11f0e92013-06-12 15:12:033616 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443617 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:323618 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523619
[email protected]420ae012009-04-24 05:16:323620 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443621 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213622 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323623
[email protected]74ce1ad2011-12-16 21:51:463624 // Make sure we use the correct starting page_id in the new RenderView.
3625 UpdateMaxPageIDIfNecessary(render_view_host);
3626 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583627 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463628
[email protected]9f76c1e2012-03-05 15:15:583629 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263630 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493631 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133632 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523633 return false;
[email protected]14392a52012-05-02 20:28:443634 }
[email protected]a4127722011-04-27 23:13:523635
[email protected]a220b5932013-09-21 03:47:443636#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503637 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3638 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443639 if (rwh_view) {
3640 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3641 render_widget_host->WasResized();
3642 }
[email protected]f8233cc2011-05-31 20:24:503643#endif
3644
[email protected]420ae012009-04-24 05:16:323645 return true;
3646}
3647
[email protected]7d244f12013-08-22 21:41:513648#if defined(OS_ANDROID)
3649bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3650 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3651 MSG_ROUTING_NONE);
3652}
3653#endif
3654
[email protected]b172aee2012-04-10 17:05:263655void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3656 IPC::Message* reply_msg,
3657 bool success,
[email protected]fcf75d42013-12-03 20:11:263658 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543659 if (is_showing_before_unload_dialog_ && !success) {
3660 // If a beforeunload dialog is canceled, we need to stop the throbber from
3661 // spinning, since we forced it to start spinning in Navigate.
[email protected]89793072012-07-23 22:25:293662 DidStopLoading(rvh);
[email protected]15d160c02012-07-04 10:52:353663 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103664
[email protected]6d65a462013-06-21 21:29:123665 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3666 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543667 }
3668 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583669 static_cast<RenderViewHostImpl*>(
3670 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543671}
3672
[email protected]b172aee2012-04-10 17:05:263673void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213674 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123675 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103676}
[email protected]f45d2a72010-03-08 23:28:353677
[email protected]b172aee2012-04-10 17:05:263678void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103679 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443680 // Can be NULL during tests.
3681 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213682 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363683}
[email protected]9f76c1e2012-03-05 15:15:583684
[email protected]1ac10dca2013-08-20 20:47:043685bool WebContentsImpl::IsHidden() {
3686 return capturer_count_ == 0 && !should_normally_be_visible_;
3687}
3688
[email protected]b0936d22013-11-28 06:47:363689RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213690 return frame_tree_.root()->render_manager();
3691}
3692
[email protected]b172aee2012-04-10 17:05:263693RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583694 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3695}
[email protected]7900bfdb2012-05-24 19:31:243696
[email protected]f8497342013-02-05 22:15:023697BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393698 return browser_plugin_guest_.get();
3699}
3700
[email protected]738f57a2013-06-29 21:06:543701void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3702 CHECK(!browser_plugin_guest_);
3703 browser_plugin_guest_.reset(guest);
3704}
3705
[email protected]f8497342013-02-05 22:15:023706BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393707 return browser_plugin_embedder_.get();
3708}
[email protected]8ff00d72012-10-23 19:12:213709
[email protected]8eb04562013-03-06 03:41:143710BrowserPluginGuestManager*
3711 WebContentsImpl::GetBrowserPluginGuestManager() const {
3712 return static_cast<BrowserPluginGuestManager*>(
3713 GetBrowserContext()->GetUserData(
3714 browser_plugin::kBrowserPluginGuestManagerKeyName));
3715}
3716
[email protected]d9030b82013-07-19 08:26:063717void WebContentsImpl::ClearPowerSaveBlockers(
3718 RenderViewHost* render_view_host) {
3719 STLDeleteValues(&power_save_blockers_[render_view_host]);
3720 power_save_blockers_.erase(render_view_host);
3721}
3722
3723void WebContentsImpl::ClearAllPowerSaveBlockers() {
3724 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3725 i != power_save_blockers_.end(); ++i)
3726 STLDeleteValues(&power_save_blockers_[i->first]);
3727 power_save_blockers_.clear();
3728}
3729
[email protected]dc0fd432013-08-27 15:29:213730gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3731 gfx::Size size;
3732 if (delegate_)
3733 size = delegate_->GetSizeForNewRenderView(this);
3734 if (size.IsEmpty())
3735 size = view_->GetContainerSize();
3736 return size;
3737}
3738
[email protected]9b159a52013-10-03 17:24:553739void WebContentsImpl::OnFrameRemoved(
3740 RenderViewHostImpl* render_view_host,
3741 int64 frame_id) {
3742 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3743 FrameDetached(render_view_host, frame_id));
3744}
3745
[email protected]8ff00d72012-10-23 19:12:213746} // namespace content