blob: c1949677acd5d2f12e05b702d59d3250b0b33080 [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]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]8dd709fb2012-04-06 00:49:0617#include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h"
[email protected]b9535422012-02-09 01:47:5918#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4419#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0420#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4621#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1222#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1623#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3224#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5425#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0526#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0027#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0128#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2531#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]48227592012-03-19 13:13:4432#include "content/public/browser/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3333#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3734#include "content/browser/web_contents/interstitial_page_impl.h"
35#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5636#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2437#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5138#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5840#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1141#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2042#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4443#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4444#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1745#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4646#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1547#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2748#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0049#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4850#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3851#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4252#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2553#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1054#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5055#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2156#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4857#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1858#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5459#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0360#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1661#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2962#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5463#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3464#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3765#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]ce9751942011-09-21 01:57:2466#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3167#include "webkit/glue/webpreferences.h"
68
[email protected]68b52252012-04-04 19:26:1369#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:3570#include "content/browser/web_contents/web_contents_view_aura.h"
[email protected]68b52252012-04-04 19:26:1371#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:3572#include "content/browser/web_contents/web_contents_view_win.h"
[email protected]38b098f2012-03-14 21:11:5773#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:3574#include "content/browser/web_contents/web_contents_view_gtk.h"
[email protected]38b098f2012-03-14 21:11:5775#elif defined(OS_MACOSX)
[email protected]0c4e92e62012-04-11 15:19:0076#include "content/browser/web_contents/web_contents_view_mac.h"
[email protected]b9b751f22011-03-25 14:04:1277#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5778#elif defined(OS_ANDROID)
[email protected]0c4e92e62012-04-11 15:19:0079#include "content/browser/web_contents/web_contents_view_android.h"
[email protected]38b098f2012-03-14 21:11:5780#endif
[email protected]3e45ba92009-02-20 21:09:0081
[email protected]420ae012009-04-24 05:16:3282// Cross-Site Navigations
83//
[email protected]b172aee2012-04-10 17:05:2684// If a WebContentsImpl is told to navigate to a different web site (as
85// determined by SiteInstance), it will replace its current RenderViewHost with
86// a new RenderViewHost dedicated to the new SiteInstance. This works as
87// follows:
[email protected]420ae012009-04-24 05:16:3288//
89// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4690// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3291// - The pending RVH is "suspended," so that no navigation messages are sent to
92// its renderer until the onbeforeunload JavaScript handler has a chance to
93// run in the current RVH.
94// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
95// that it has a pending cross-site request. ResourceDispatcherHost will
96// check for this when the response arrives.
97// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4698// cancel all the pending logic. Otherwise we allow the pending RVH to send
99// the navigation request to its renderer.
100// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
101// main resource load on the pending RVH. It checks CrossSiteRequestManager
102// to see that it is a cross-site request, and installs a
103// CrossSiteResourceHandler.
104// - When RDH receives a response, the BufferedResourceHandler determines
105// whether it is a download. If so, it sends a message to the new renderer
106// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26107// pending RVH remains until the next DidNavigate event for this
108// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32109// - After RDH receives a response and determines that it is safe and not a
110// download, it pauses the response to first run the old page's onunload
111// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26112// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32113// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15114// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32115// the ResourceDispatcherHost, who unpauses the response. Data is then sent
116// to the pending RVH.
117// - The pending renderer sends a FrameNavigate message that invokes the
118// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46119// pending RVH.
[email protected]992db4c2011-05-12 15:37:15120// - The previous renderer is kept swapped out in RenderViewHostManager in case
121// the user goes back. The process only stays live if another tab is using
122// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32123
[email protected]0e12d7d2011-12-01 16:21:44124using content::DevToolsAgentHost;
125using content::DevToolsAgentHostRegistry;
126using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17127using content::DownloadItem;
128using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20129using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56130using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13131using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27132using content::LoadNotificationDetails;
[email protected]c5eed492012-01-04 17:07:50133using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23134using content::NavigationEntry;
135using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20136using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11137using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57138using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27139using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11140using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58141using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04142using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25143using content::ResourceDispatcherHostImpl;
[email protected]adbfb8df2012-02-24 01:19:43144using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33145using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17146using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38147using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09148using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25149using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56150using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22151using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50152using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44153
[email protected]420ae012009-04-24 05:16:32154namespace {
155
156// Amount of time we wait between when a key event is received and the renderer
157// is queried for its state and pushed to the NavigationEntry.
158const int kQueryStateDelay = 5000;
159
[email protected]6ebdc9b2010-09-27 16:55:57160const int kSyncWaitDelay = 40;
161
[email protected]82114f52012-03-20 22:53:41162const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05163
[email protected]420ae012009-04-24 05:16:32164#if defined(OS_WIN)
165
166BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
167 // Note: erase is required to properly paint some widgets borders. This can
168 // be seen with textfields.
169 InvalidateRect(hwnd, NULL, TRUE);
170 return TRUE;
171}
172#endif
173
[email protected]2c5569662011-03-22 20:45:02174ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23175 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50176 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16177 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47178 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02179 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47180 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02181 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47182 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16183 break; // Fall through to rest of function.
184 }
[email protected]5e369672009-11-03 23:48:30185
[email protected]59246c572012-02-10 13:32:13186 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
187 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23188 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13189 browser_context->DidLastSessionExitCleanly()) {
190 if (entry.GetHasPostData())
191 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02192 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13193 }
[email protected]5e369672009-11-03 23:48:30194
[email protected]2c5569662011-03-22 20:45:02195 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30196}
197
[email protected]10f417c52011-12-28 21:04:23198void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47199 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42200 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50201 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16202 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51203 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54204 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55205 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
206 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51207 params->url = entry.GetURL();
208 params->referrer = entry.GetReferrer();
209 params->transition = entry.GetTransitionType();
210 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00211 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55212 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34213 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47214 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48215 params->transferred_request_child_id =
216 entry.transferred_global_request_id().child_id;
217 params->transferred_request_request_id =
218 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47219
220 if (delegate)
221 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34222}
223
[email protected]420ae012009-04-24 05:16:32224} // namespace
225
[email protected]a81343d232011-12-27 07:39:20226namespace content {
227
228WebContents* WebContents::Create(
229 BrowserContext* browser_context,
230 SiteInstance* site_instance,
231 int routing_id,
[email protected]b172aee2012-04-10 17:05:26232 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20233 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26234 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43235 browser_context,
236 site_instance,
237 routing_id,
[email protected]b172aee2012-04-10 17:05:26238 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]adbfb8df2012-02-24 01:19:43239 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20240}
241}
[email protected]f4f50ef2011-01-21 19:01:19242
[email protected]b172aee2012-04-10 17:05:26243// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32244
[email protected]b172aee2012-04-10 17:05:26245WebContentsImpl::WebContentsImpl(
246 content::BrowserContext* browser_context,
247 SiteInstance* site_instance,
248 int routing_id,
249 const WebContentsImpl* base_web_contents,
250 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42251 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07252 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37253 this, browser_context, session_storage_namespace)),
[email protected]d82ed61e2009-06-16 02:46:22254 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34255 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23256 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
257 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34258 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21259 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56260 upload_size_(0),
261 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47262 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57263 capturing_contents_(false),
264 is_being_destroyed_(false),
265 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55266 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57267#if defined(OS_WIN)
268 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
269#endif
[email protected]7ab1e7d62009-10-14 23:32:01270 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56271 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38272 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25273 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01274 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25275 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01276 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00277 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43278 content_restrictions_(0),
[email protected]e018d3b2012-04-17 13:24:15279 view_type_(content::VIEW_TYPE_WEB_CONTENTS),
[email protected]da8543762012-03-20 08:52:20280 has_opener_(false),
281 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37282 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32283
[email protected]38b098f2012-03-14 21:11:57284 view_.reset(content::GetContentClient()->browser()->
285 OverrideCreateWebContentsView(this));
286 if (!view_.get()) {
287 content::WebContentsViewDelegate* delegate =
288 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
289 this);
[email protected]68b52252012-04-04 19:26:13290#if defined(USE_AURA)
[email protected]6eddfd442012-04-11 16:18:35291 view_.reset(new WebContentsViewAura(this, delegate));
[email protected]68b52252012-04-04 19:26:13292#elif defined(OS_WIN)
[email protected]6eddfd442012-04-11 16:18:35293 view_.reset(new WebContentsViewWin(this, delegate));
[email protected]38b098f2012-03-14 21:11:57294#elif defined(TOOLKIT_GTK)
[email protected]6eddfd442012-04-11 16:18:35295 view_.reset(new content::WebContentsViewGtk(this, delegate));
[email protected]38b098f2012-03-14 21:11:57296#elif defined(OS_MACOSX)
297 view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate));
298#elif defined(OS_ANDROID)
299 view_.reset(new WebContentsViewAndroid(this));
300#endif
[email protected]dbd407f2012-03-14 21:30:37301 (void)delegate;
[email protected]38b098f2012-03-14 21:11:57302 }
303 CHECK(view_.get());
304
[email protected]ca13a442012-04-17 14:00:12305 // We have the initial size of the view be based on the size of the view of
306 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26307 view_->CreateView(base_web_contents ?
308 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00309
310#if defined(ENABLE_JAVA_BRIDGE)
311 java_bridge_dispatcher_host_manager_.reset(
312 new JavaBridgeDispatcherHostManager(this));
313#endif
[email protected]8dd709fb2012-04-06 00:49:06314
315 browser_plugin_web_contents_observer_.reset(
316 new content::BrowserPluginWebContentsObserver(this));
[email protected]332af7732009-03-11 13:21:35317}
initial.commit09911bf2008-07-26 23:55:29318
[email protected]b172aee2012-04-10 17:05:26319WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32320 is_being_destroyed_ = true;
321
[email protected]3ab9cb82011-06-03 18:02:07322 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55323 if (dialog_creator_)
324 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07325
[email protected]da8543762012-03-20 08:52:20326 if (color_chooser_)
327 color_chooser_->End();
328
[email protected]420ae012009-04-24 05:16:32329 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32330
[email protected]ca13a442012-04-17 14:00:12331 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07332 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09333 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
334 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07335 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32336
337 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07338#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32339 // If we still have a window handle, destroy it. GetNativeView can return
340 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42341 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52342 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58343 if (host && host->GetView())
344 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42345 }
[email protected]420ae012009-04-24 05:16:32346#endif
[email protected]7ab1e7d62009-10-14 23:32:01347
348 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15349 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01350 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15351 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01352 }
[email protected]b5a1d11c2011-02-17 03:09:42353
[email protected]2db9bd72012-04-13 20:20:56354 FOR_EACH_OBSERVER(WebContentsObserver,
355 observers_,
356 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08357
[email protected]6934a702011-12-20 00:04:51358 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42359}
360
[email protected]b172aee2012-04-10 17:05:26361WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
362 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54363 WebPreferences prefs;
364
365 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
366
367 prefs.developer_extras_enabled = true;
368 prefs.javascript_enabled =
369 !command_line.HasSwitch(switches::kDisableJavaScript);
370 prefs.web_security_enabled =
371 !command_line.HasSwitch(switches::kDisableWebSecurity);
372 prefs.plugins_enabled =
373 !command_line.HasSwitch(switches::kDisablePlugins);
374 prefs.java_enabled =
375 !command_line.HasSwitch(switches::kDisableJava);
376
377 prefs.uses_page_cache =
378 command_line.HasSwitch(switches::kEnableFastback);
379 prefs.remote_fonts_enabled =
380 !command_line.HasSwitch(switches::kDisableRemoteFonts);
381 prefs.xss_auditor_enabled =
382 !command_line.HasSwitch(switches::kDisableXSSAuditor);
383 prefs.application_cache_enabled =
384 !command_line.HasSwitch(switches::kDisableApplicationCache);
385
386 prefs.local_storage_enabled =
387 !command_line.HasSwitch(switches::kDisableLocalStorage);
388 prefs.databases_enabled =
389 !command_line.HasSwitch(switches::kDisableDatabases);
390 prefs.webaudio_enabled =
391 !command_line.HasSwitch(switches::kDisableWebAudio);
392
393 prefs.experimental_webgl_enabled =
394 GpuProcessHost::gpu_enabled() &&
395 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
396 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
397
398 prefs.gl_multisampling_enabled =
399 !command_line.HasSwitch(switches::kDisableGLMultisampling);
400 prefs.privileged_webgl_extensions_enabled =
401 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
402 prefs.site_specific_quirks_enabled =
403 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
404 prefs.allow_file_access_from_file_urls =
405 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
406 prefs.show_composited_layer_borders =
407 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
408 prefs.show_composited_layer_tree =
409 command_line.HasSwitch(switches::kShowCompositedLayerTree);
410 prefs.show_fps_counter =
411 command_line.HasSwitch(switches::kShowFPSCounter);
412 prefs.accelerated_compositing_enabled =
413 GpuProcessHost::gpu_enabled() &&
414 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54415 prefs.force_compositing_mode =
416 command_line.HasSwitch(switches::kForceCompositingMode);
417 prefs.fixed_position_compositing_enabled =
418 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
419 prefs.accelerated_2d_canvas_enabled =
420 GpuProcessHost::gpu_enabled() &&
421 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58422 prefs.deferred_2d_canvas_enabled =
423 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36424 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31425 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54426 prefs.accelerated_painting_enabled =
427 GpuProcessHost::gpu_enabled() &&
428 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
429 prefs.accelerated_filters_enabled =
430 GpuProcessHost::gpu_enabled() &&
431 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
432 prefs.accelerated_layers_enabled =
433 prefs.accelerated_animation_enabled =
434 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54435 prefs.accelerated_plugins_enabled =
436 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
437 prefs.accelerated_video_enabled =
438 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
439 prefs.partial_swap_enabled =
440 command_line.HasSwitch(switches::kEnablePartialSwap);
441 prefs.interactive_form_validation_enabled =
442 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
443 prefs.fullscreen_enabled =
444 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16445 prefs.css_regions_enabled =
446 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29447 prefs.css_shaders_enabled =
448 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]64d69de42012-02-06 00:19:54449
450#if defined(OS_MACOSX)
451 bool default_enable_scroll_animator = true;
452#else
453 // On CrOS, the launcher always passes in the --enable flag.
454 bool default_enable_scroll_animator = false;
455#endif
456 prefs.enable_scroll_animator = default_enable_scroll_animator;
457 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
458 prefs.enable_scroll_animator = true;
459 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
460 prefs.enable_scroll_animator = false;
461
462 prefs.visual_word_movement_enabled =
463 command_line.HasSwitch(switches::kEnableVisualWordMovement);
464 prefs.per_tile_painting_enabled =
465 command_line.HasSwitch(switches::kEnablePerTilePainting);
466
467 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32468 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54469 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11470 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
471 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54472 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11473 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54474 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11475 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54476 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11477 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54478 prefs.gl_multisampling_enabled = false;
479
480 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45481 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32482 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54483 prefs.accelerated_video_enabled = false;
484 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45485 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54486 }
487 }
488
[email protected]b9535422012-02-09 01:47:59489 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58490 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54491 prefs.loads_images_automatically = true;
492 prefs.javascript_enabled = true;
493 }
494
495 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
496
497 // Force accelerated compositing and 2d canvas off for chrome:, about: and
498 // chrome-devtools: pages (unless it's specifically allowed).
499 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54500 url.SchemeIs(chrome::kChromeUIScheme) ||
501 (url.SchemeIs(chrome::kAboutScheme) &&
502 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25503 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54504 prefs.accelerated_compositing_enabled = false;
505 prefs.accelerated_2d_canvas_enabled = false;
506 }
507
[email protected]43d9d782012-03-01 15:40:09508 int default_device_scale_factor;
509 base::StringToInt(command_line.GetSwitchValueASCII(
510 switches::kDefaultDeviceScaleFactor),
511 &default_device_scale_factor);
512
513 prefs.default_device_scale_factor = default_device_scale_factor;
514
[email protected]2e21fe292012-03-02 22:52:32515 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54516
517 return prefs;
518}
519
[email protected]b172aee2012-04-10 17:05:26520NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20521 return controller_;
522}
523
[email protected]b172aee2012-04-10 17:05:26524RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28525 return &render_manager_;
526}
527
[email protected]b172aee2012-04-10 17:05:26528bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56529 if (GetWebUI() &&
530 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17531 return true;
[email protected]d2353452012-01-19 19:53:56532 }
[email protected]f82d57b52011-04-27 19:13:17533
[email protected]d8c660432011-12-22 20:51:25534 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
535 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10536 while ((observer = it.GetNext()) != NULL)
537 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53538 return true;
[email protected]403415a2011-01-10 18:57:53539
[email protected]724159a2010-12-30 01:11:18540 bool handled = true;
541 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26542 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58543 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
544 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24545 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
546 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18547 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
548 OnDidStartProvisionalLoadForFrame)
549 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
550 OnDidRedirectProvisionalLoad)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
552 OnDidFailProvisionalLoadWithError)
553 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
554 OnDidLoadResourceFromMemoryCache)
555 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
556 OnDidDisplayInsecureContent)
557 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
558 OnDidRunInsecureContent)
559 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
560 OnDocumentLoadedInFrame)
561 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26562 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
563 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17564 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
565 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25566 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26567 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59568 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21569 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20570 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
571 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
572 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16573 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45574 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10575 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20576 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
577 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
578 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
579 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29580 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]724159a2010-12-30 01:11:18581 IPC_MESSAGE_UNHANDLED(handled = false)
582 IPC_END_MESSAGE_MAP_EX()
583
584 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38585 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18586 GetRenderProcessHost()->ReceivedBadMessage();
587 }
588
589 return handled;
590}
591
[email protected]b172aee2012-04-10 17:05:26592void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18593 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23594 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51595 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18596}
597
[email protected]b172aee2012-04-10 17:05:26598NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56599 return controller_;
600}
601
[email protected]b172aee2012-04-10 17:05:26602const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56603 return controller_;
604}
605
[email protected]b172aee2012-04-10 17:05:26606content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55607 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30608}
609
[email protected]b172aee2012-04-10 17:05:26610void WebContentsImpl::SetViewType(content::ViewType type) {
[email protected]f5fa20e2011-12-21 22:35:56611 view_type_ = type;
612}
613
[email protected]b172aee2012-04-10 17:05:26614content::ViewType WebContentsImpl::GetViewType() const {
[email protected]ea049a02011-12-25 21:37:09615 return view_type_;
616}
617
[email protected]b172aee2012-04-10 17:05:26618const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31619 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23620 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51621 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31622}
623
624
[email protected]b172aee2012-04-10 17:05:26625const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31626 return &property_bag_;
627}
628
[email protected]b172aee2012-04-10 17:05:26629base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31630 return &property_bag_;
631}
632
[email protected]b172aee2012-04-10 17:05:26633content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31634 return delegate_;
635}
636
[email protected]b172aee2012-04-10 17:05:26637void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31638 // TODO(cbentzel): remove this debugging code?
639 if (delegate == delegate_)
640 return;
641 if (delegate_)
642 delegate_->Detach(this);
643 delegate_ = delegate;
644 if (delegate_)
645 delegate_->Attach(this);
646}
647
[email protected]b172aee2012-04-10 17:05:26648content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41649 RenderViewHostImpl* host = render_manager_.current_host();
650 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16651}
652
[email protected]b172aee2012-04-10 17:05:26653RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31654 return render_manager_.current_host();
655}
656
[email protected]b172aee2012-04-10 17:05:26657RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31658 return render_manager_.GetRenderWidgetHostView();
659}
660
[email protected]b172aee2012-04-10 17:05:26661content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31662 return view_.get();
663}
664
[email protected]b172aee2012-04-10 17:05:26665content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50666 WebUIControllerFactory* factory =
667 content::GetContentClient()->browser()->GetWebUIControllerFactory();
668 if (!factory)
669 return NULL;
[email protected]d2353452012-01-19 19:53:56670 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22671 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50672 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22673 if (controller) {
674 web_ui->SetController(controller);
675 return web_ui;
676 }
677
678 delete web_ui;
679 return NULL;
680}
681
[email protected]b172aee2012-04-10 17:05:26682content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31683 return render_manager_.web_ui() ? render_manager_.web_ui()
684 : render_manager_.pending_web_ui();
685}
686
[email protected]b172aee2012-04-10 17:05:26687content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31688 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34689}
690
[email protected]b172aee2012-04-10 17:05:26691const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55692 // Transient entries take precedence. They are used for interstitial pages
693 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23694 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08695 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20696 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30697 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23698 if (entry) {
[email protected]b5cca982011-05-26 04:42:08699 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23700 }
[email protected]7ade2732011-02-10 00:13:58701 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
702 render_manager_.pending_web_ui() : render_manager_.web_ui();
703 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54704 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55705 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54706 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35707 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22708 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54709 if (!title.empty())
710 return title;
711 }
712 }
713
714 // We use the title for the last committed entry rather than a pending
715 // navigation entry. For example, when the user types in a URL, we want to
716 // keep the old page's title until the new load has committed and we get a new
717 // title.
[email protected]96d185d2009-04-24 03:28:54718 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23719 if (entry) {
[email protected]b5cca982011-05-26 04:42:08720 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23721 }
[email protected]987fc3a2011-05-26 14:18:09722
723 // |page_title_when_no_navigation_entry_| is finally used
724 // if no title cannot be retrieved.
725 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54726}
727
[email protected]b172aee2012-04-10 17:05:26728int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46729 return GetMaxPageIDForSiteInstance(GetSiteInstance());
730}
731
[email protected]b172aee2012-04-10 17:05:26732int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
733 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33734 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
735 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46736
[email protected]b6583592012-01-25 19:52:33737 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34738}
739
[email protected]b172aee2012-04-10 17:05:26740void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46741 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
742}
743
[email protected]b172aee2012-04-10 17:05:26744void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33745 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46746 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33747 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34748}
749
[email protected]b172aee2012-04-10 17:05:26750void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
751 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57752}
753
[email protected]b172aee2012-04-10 17:05:26754SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58755 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54756}
757
[email protected]b172aee2012-04-10 17:05:26758SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38759 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
760 render_manager_.pending_render_view_host() :
761 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58762 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38763}
764
[email protected]b172aee2012-04-10 17:05:26765bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31766 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49767}
768
[email protected]b172aee2012-04-10 17:05:26769bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31770 return waiting_for_response_;
771}
772
[email protected]b172aee2012-04-10 17:05:26773const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31774 return load_state_;
775}
776
[email protected]b172aee2012-04-10 17:05:26777const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31778 return load_state_host_;
779}
780
[email protected]b172aee2012-04-10 17:05:26781uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31782 return upload_size_;
783}
784
[email protected]b172aee2012-04-10 17:05:26785uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31786 return upload_position_;
787}
788
[email protected]b172aee2012-04-10 17:05:26789const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31790 return encoding_;
791}
792
[email protected]b172aee2012-04-10 17:05:26793bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31794 return displayed_insecure_content_;
795}
796
[email protected]b172aee2012-04-10 17:05:26797void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31798 capturing_contents_ = cap;
799}
800
[email protected]b172aee2012-04-10 17:05:26801bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31802 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
803 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
804 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49805}
806
[email protected]b172aee2012-04-10 17:05:26807void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
808 int error_code) {
[email protected]443b80e2010-12-14 00:42:23809 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34810 return;
811
[email protected]443b80e2010-12-14 00:42:23812 crashed_status_ = status;
813 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46814 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34815}
816
[email protected]b172aee2012-04-10 17:05:26817base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31818 return crashed_status_;
819}
820
[email protected]b172aee2012-04-10 17:05:26821bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31822 return is_being_destroyed_;
823}
824
[email protected]b172aee2012-04-10 17:05:26825void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34826 if (delegate_)
827 delegate_->NavigationStateChanged(this, changed_flags);
828}
829
[email protected]b172aee2012-04-10 17:05:26830void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54831 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04832 RenderWidgetHostViewPort* rwhv =
833 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16834 if (rwhv) {
835 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43836#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16837 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43838#endif
839 }
[email protected]96d185d2009-04-24 03:28:54840
[email protected]5ac20162010-11-24 23:33:11841 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38842
[email protected]d8c660432011-12-22 20:51:25843 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59844
845 // The resize rect might have changed while this was inactive -- send the new
846 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58847 RenderViewHostImpl* rvh =
848 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59849 if (rvh) {
850 rvh->ResizeRectChanged(GetRootWindowResizerRect());
851 }
[email protected]96d185d2009-04-24 03:28:54852}
853
[email protected]be1f56ab2011-12-22 06:55:31854
[email protected]b172aee2012-04-10 17:05:26855base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31856 return last_selected_time_;
857}
858
[email protected]b172aee2012-04-10 17:05:26859void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31860 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52861 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
862 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26863 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52864 // removes the |GetRenderViewHost()|; then when we actually destroy the
865 // window, OnWindowPosChanged() notices and calls HideContents() (which
866 // calls us).
[email protected]c30585c2012-02-16 15:02:04867 RenderWidgetHostViewPort* rwhv =
868 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16869 if (rwhv)
870 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54871 }
872
[email protected]ad50def52011-10-19 23:17:07873 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09874 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
875 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07876 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54877}
878
[email protected]b172aee2012-04-10 17:05:26879void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04880 RenderWidgetHostViewPort* rwhv =
881 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31882 if (rwhv)
883 rwhv->DidBecomeSelected();
884}
885
[email protected]b172aee2012-04-10 17:05:26886void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31887 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
888 // our superclass HideContents(), because some callers want to be very picky
889 // about the order in which these get called. In addition to making the code
890 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26891 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
892 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31893 WasHidden();
894}
895
[email protected]b172aee2012-04-10 17:05:26896bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31897 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27898 return WillNotifyDisconnection() &&
899 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58900 !static_cast<RenderViewHostImpl*>(
901 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31902}
903
[email protected]b172aee2012-04-10 17:05:26904void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27905 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25906 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27907}
908
[email protected]b172aee2012-04-10 17:05:26909WebContents* WebContentsImpl::Clone() {
[email protected]0bfbf882011-12-22 18:19:27910 // We create a new SiteInstance so that the new tab won't share processes
911 // with the old one. This can be changed in the future if we need it to share
912 // processes for some reason.
[email protected]b172aee2012-04-10 17:05:26913 WebContentsImpl* tc = new WebContentsImpl(
[email protected]0bfbf882011-12-22 18:19:27914 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33915 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27916 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20917 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27918 return tc;
919}
920
[email protected]b172aee2012-04-10 17:05:26921void WebContentsImpl::AddNewContents(WebContents* new_contents,
922 WindowOpenDisposition disposition,
923 const gfx::Rect& initial_pos,
924 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27925 if (!delegate_)
926 return;
927
928 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
929 user_gesture);
930}
931
[email protected]b172aee2012-04-10 17:05:26932gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27933 return view_->GetContentNativeView();
934}
935
[email protected]b172aee2012-04-10 17:05:26936gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27937 return view_->GetNativeView();
938}
939
[email protected]b172aee2012-04-10 17:05:26940void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:27941 view_->GetContainerBounds(out);
942}
943
[email protected]b172aee2012-04-10 17:05:26944void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:27945 view_->Focus();
946}
947
[email protected]b172aee2012-04-10 17:05:26948void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31949 observers_.AddObserver(observer);
950}
951
[email protected]b172aee2012-04-10 17:05:26952void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31953 observers_.RemoveObserver(observer);
954}
955
[email protected]b172aee2012-04-10 17:05:26956void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:34957 if (delegate_)
958 delegate_->ActivateContents(this);
959}
960
[email protected]b172aee2012-04-10 17:05:26961void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:12962 if (delegate_)
963 delegate_->DeactivateContents(this);
964}
965
[email protected]b172aee2012-04-10 17:05:26966void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:48967 if (delegate_)
968 delegate_->LostCapture();
969}
970
[email protected]b172aee2012-04-10 17:05:26971bool WebContentsImpl::PreHandleKeyboardEvent(
972 const NativeWebKeyboardEvent& event,
973 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:48974 return delegate_ &&
975 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
976}
977
[email protected]b172aee2012-04-10 17:05:26978void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:48979 if (delegate_)
980 delegate_->HandleKeyboardEvent(event);
981}
982
[email protected]b172aee2012-04-10 17:05:26983void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:43984 if (delegate_)
985 delegate_->HandleMouseDown();
986}
987
[email protected]b172aee2012-04-10 17:05:26988void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:48989 if (delegate_)
990 delegate_->HandleMouseUp();
991}
992
[email protected]b172aee2012-04-10 17:05:26993void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:48994 if (delegate_)
995 delegate_->HandleMouseActivate();
996}
997
[email protected]b172aee2012-04-10 17:05:26998void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:47999 if (delegate_)
1000 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1001}
1002
[email protected]b172aee2012-04-10 17:05:261003bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381004 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121005}
1006
[email protected]b172aee2012-04-10 17:05:261007void WebContentsImpl::RequestToLockMouse() {
[email protected]e9621112011-10-17 05:38:371008 if (delegate_) {
1009 delegate_->RequestToLockMouse(this);
1010 } else {
1011 GotResponseToLockMouseRequest(false);
1012 }
1013}
1014
[email protected]b172aee2012-04-10 17:05:261015void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371016 if (delegate_)
1017 delegate_->LostMouseLock();
1018}
1019
[email protected]b172aee2012-04-10 17:05:261020void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231021 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331022 if (delegate_)
1023 delegate_->UpdatePreferredSize(this, pref_size);
1024}
1025
[email protected]b172aee2012-04-10 17:05:261026void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341027 if (delegate_)
1028 delegate_->ResizeDueToAutoResize(this, new_size);
1029}
1030
[email protected]b172aee2012-04-10 17:05:261031void WebContentsImpl::WebUISend(RenderViewHost* render_view_host,
1032 const GURL& source_url,
1033 const std::string& name,
1034 const base::ListValue& args) {
[email protected]32ded2212011-11-10 18:51:431035 if (delegate_)
1036 delegate_->WebUISend(this, source_url, name, args);
1037}
1038
[email protected]b172aee2012-04-10 17:05:261039WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201040 if (!delegate_)
1041 return NULL;
[email protected]00c37fc2011-08-02 00:22:501042
[email protected]e5d549d2011-12-28 01:29:201043 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1044 // Notify observers.
1045 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1046 DidOpenURL(params.url, params.referrer,
1047 params.disposition, params.transition));
1048 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341049}
1050
[email protected]b172aee2012-04-10 17:05:261051bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501052 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251053 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231054 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251055 reload_type);
[email protected]876bc832010-09-07 16:29:541056}
[email protected]96d185d2009-04-24 03:28:541057
[email protected]b172aee2012-04-10 17:05:261058bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231059 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501060 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401061 // The renderer will reject IPC messages with URLs longer than
1062 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511063 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401064 return false;
1065
[email protected]9f76c1e2012-03-05 15:15:581066 RenderViewHostImpl* dest_render_view_host =
1067 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401068 if (!dest_render_view_host)
1069 return false; // Unable to create the desired render view host.
1070
[email protected]80a8fad2011-01-29 04:02:381071 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071072 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581073 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501074 WebUIControllerFactory* factory =
1075 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271076 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501077 bool is_allowed_in_web_ui_renderer =
1078 factory &&
[email protected]24e18252012-04-16 21:26:271079 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1080 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231081 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1082 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271083 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231084 content::GetContentClient()->SetActiveURL(entry.GetURL());
1085 CHECK(0);
1086 }
[email protected]54ec6472010-04-09 19:39:581087
[email protected]96d185d2009-04-24 03:28:541088 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441089 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521090 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441091 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511092 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541093
1094 // Used for page load time metrics.
1095 current_load_start_ = base::TimeTicks::Now();
1096
1097 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341098 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271099 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471100 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341101 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541102
[email protected]36fc0392011-12-25 03:59:511103 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541104 // HACK!! This code suppresses javascript: URLs from being added to
1105 // session history, which is what we want to do for javascript: URLs that
1106 // do not generate content. What we really need is a message from the
1107 // renderer telling us that a new page was not created. The same message
1108 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511109 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541110 return false;
1111 }
1112
[email protected]3c9e1872010-11-18 16:17:491113 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251114 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041115 observers_,
[email protected]36fc0392011-12-25 03:59:511116 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541117
[email protected]09b29342011-06-24 19:18:481118 if (delegate_)
1119 delegate_->DidNavigateToPendingEntry(this);
1120
[email protected]d5f942ba2008-09-26 19:30:341121 return true;
1122}
1123
[email protected]b172aee2012-04-10 17:05:261124void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331125 const SiteInstance* site_instance,
1126 int history_length,
1127 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411128 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1129 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191130 if (render_manager_.pending_render_view_host()) {
1131 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141132 return;
[email protected]9e1ad4b2011-08-14 16:49:191133 }
[email protected]9f76c1e2012-03-05 15:15:581134 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191135 if (!rvh) {
1136 NOTREACHED();
1137 return;
1138 }
[email protected]9f76c1e2012-03-05 15:15:581139 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191140 NOTREACHED();
1141 return;
1142 }
[email protected]9f76c1e2012-03-05 15:15:581143 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191144 history_length,
1145 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141146}
1147
[email protected]b172aee2012-04-10 17:05:261148void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271149 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541150 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1151 return;
1152 }
[email protected]9f76c1e2012-03-05 15:15:581153 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541154}
1155
[email protected]b172aee2012-04-10 17:05:261156bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271157 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541158}
1159
[email protected]b172aee2012-04-10 17:05:261160InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271161 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221162}
1163
[email protected]b172aee2012-04-10 17:05:261164bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161165 // WebKit creates Document object when MIME type is application/xhtml+xml,
1166 // so we also support this MIME type.
1167 return contents_mime_type_ == "text/html" ||
1168 contents_mime_type_ == "text/xml" ||
1169 contents_mime_type_ == "application/xhtml+xml" ||
1170 contents_mime_type_ == "text/plain" ||
1171 contents_mime_type_ == "text/css" ||
1172 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1173}
1174
[email protected]b172aee2012-04-10 17:05:261175void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591176 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161177 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481178 download_stats::RecordDownloadSource(
1179 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261180 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141181 return;
[email protected]c7dd2f62011-07-18 15:57:591182 }
1183
1184 Stop();
1185
1186 // Create the save package and possibly prompt the user for the name to save
1187 // the page as. The user prompt is an asynchronous operation that runs on
1188 // another thread.
1189 save_package_ = new SavePackage(this);
1190 save_package_->GetSaveInfo();
1191}
1192
1193// Used in automated testing to bypass prompting the user for file names.
1194// Instead, the names and paths are hard coded rather than running them through
1195// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261196bool WebContentsImpl::SavePage(const FilePath& main_file,
1197 const FilePath& dir_path,
1198 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591199 // Stop the page from navigating.
1200 Stop();
1201
1202 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1203 return save_package_->Init();
1204}
1205
[email protected]b172aee2012-04-10 17:05:261206void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121207 const FilePath& file,
1208 const base::Callback<void(const FilePath&, int64)>& callback) {
1209 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1210}
1211
[email protected]b172aee2012-04-10 17:05:261212bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231213 NavigationEntryImpl* active_entry =
1214 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321215 return (active_entry != NULL &&
1216 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511217 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321218}
1219
[email protected]b172aee2012-04-10 17:05:261220const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271221 return contents_mime_type_;
1222}
1223
[email protected]b172aee2012-04-10 17:05:261224bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271225 return notify_disconnection_;
1226}
1227
[email protected]b172aee2012-04-10 17:05:261228void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311229 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581230 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1231 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161232}
1233
[email protected]b172aee2012-04-10 17:05:261234void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311235 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581236 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1237 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161238}
1239
[email protected]b172aee2012-04-10 17:05:261240content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271241 return &renderer_preferences_;
1242}
1243
[email protected]b172aee2012-04-10 17:05:261244void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271245 new_tab_start_time_ = time;
1246}
1247
[email protected]b172aee2012-04-10 17:05:261248base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271249 return new_tab_start_time_;
1250}
1251
[email protected]b172aee2012-04-10 17:05:261252void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151253 if (close_start_time_.is_null())
1254 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011255}
1256
[email protected]b172aee2012-04-10 17:05:261257bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191258#if defined(OS_CHROMEOS)
1259 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1260 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511261 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201262 return false;
1263 return true;
[email protected]46624bf2010-06-09 16:04:191264#else
1265 return true;
1266#endif
1267}
1268
[email protected]b172aee2012-04-10 17:05:261269void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521270 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581271 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511272 if (delegate_)
1273 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341274}
1275
[email protected]b172aee2012-04-10 17:05:261276void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271277 closed_by_user_gesture_ = value;
1278}
1279
[email protected]b172aee2012-04-10 17:05:261280bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271281 return closed_by_user_gesture_;
1282}
1283
[email protected]b172aee2012-04-10 17:05:261284double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051285 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561286 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251287 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171288 return 0;
[email protected]b75b8292010-10-01 07:28:251289
1290 double zoom_level;
1291 if (temporary_zoom_settings_) {
1292 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581293 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251294 } else {
[email protected]2ae88d12011-10-14 09:11:191295 GURL url;
[email protected]10f417c52011-12-28 21:04:231296 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191297 // Since zoom map is updated using rewritten URL, use rewritten URL
1298 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511299 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191300 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251301 }
[email protected]d0b8d092010-10-25 04:05:171302 return zoom_level;
1303}
[email protected]b75b8292010-10-01 07:28:251304
[email protected]b172aee2012-04-10 17:05:261305int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1306 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171307 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011308 // Calculate the zoom percent from the factor. Round up to the nearest whole
1309 // number.
[email protected]b75b8292010-10-01 07:28:251310 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011311 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251312 *enable_decrement = percent > minimum_zoom_percent_;
1313 *enable_increment = percent < maximum_zoom_percent_;
1314 return percent;
1315}
1316
[email protected]b172aee2012-04-10 17:05:261317void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501318 if (!delegate_)
1319 return;
1320
[email protected]10f417c52011-12-28 21:04:231321 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501322 if (!active_entry)
1323 return;
1324
[email protected]36fc0392011-12-25 03:59:511325 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121326}
1327
[email protected]b172aee2012-04-10 17:05:261328void WebContentsImpl::ViewFrameSource(const GURL& url,
1329 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271330 if (!delegate_)
1331 return;
1332
1333 delegate_->ViewSourceForFrame(this, url, content_state);
1334}
1335
[email protected]b172aee2012-04-10 17:05:261336int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271337 return minimum_zoom_percent_;
1338}
1339
[email protected]b172aee2012-04-10 17:05:261340int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271341 return maximum_zoom_percent_;
1342}
1343
[email protected]b172aee2012-04-10 17:05:261344gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231345 return preferred_size_;
1346}
1347
[email protected]b172aee2012-04-10 17:05:261348int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271349 return content_restrictions_;
1350}
1351
[email protected]b172aee2012-04-10 17:05:261352WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501353 WebUIControllerFactory* factory =
1354 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1355 if (!factory)
1356 return WebUI::kNoWebUI;
1357 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271358}
1359
[email protected]b172aee2012-04-10 17:05:261360content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271361 // When there is a pending navigation entry, we want to use the pending WebUI
1362 // that goes along with it to control the basic flags. For example, we want to
1363 // show the pending URL in the URL bar, so we want the display_url flag to
1364 // be from the pending entry.
1365 //
1366 // The confusion comes because there are multiple possibilities for the
1367 // initial load in a tab as a side effect of the way the RenderViewHostManager
1368 // works.
1369 //
1370 // - For the very first tab the load looks "normal". The new tab Web UI is
1371 // the pending one, and we want it to apply here.
1372 //
1373 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1374 // get switched to the one previously associated with the new tab pages.
1375 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1376 // have a committed Web UI in this case.
1377 //
1378 // This condition handles all of these cases:
1379 //
1380 // - First load in first tab: no committed nav entry + pending nav entry +
1381 // pending dom ui:
1382 // -> Use pending Web UI if any.
1383 //
1384 // - First load in second tab: no committed nav entry + pending nav entry +
1385 // no pending Web UI:
1386 // -> Use the committed Web UI if any.
1387 //
1388 // - Second navigation in any tab: committed nav entry + pending nav entry:
1389 // -> Use pending Web UI if any.
1390 //
1391 // - Normal state with no load: committed nav entry + no pending nav entry:
1392 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251393 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271394 (controller_.GetLastCommittedEntry() ||
1395 render_manager_.pending_web_ui()))
1396 return render_manager_.pending_web_ui();
1397 return render_manager_.web_ui();
1398}
1399
[email protected]b172aee2012-04-10 17:05:261400bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271401 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581402 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271403}
1404
[email protected]b172aee2012-04-10 17:05:261405bool WebContentsImpl::HasOpener() const {
[email protected]a0358d72012-03-09 14:06:501406 return has_opener_;
1407}
1408
[email protected]b172aee2012-04-10 17:05:261409void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
1410 const SkColor& color) {
[email protected]da8543762012-03-20 08:52:201411 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1412 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1413}
1414
[email protected]b172aee2012-04-10 17:05:261415void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201416 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1417 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1418 if (delegate_)
1419 delegate_->DidEndColorChooser();
1420 color_chooser_ = NULL;
1421}
1422
[email protected]b172aee2012-04-10 17:05:261423bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471424 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271425 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221426 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231427 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411428 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271429}
1430
[email protected]b172aee2012-04-10 17:05:261431void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271432 if (delegate_)
1433 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211434}
1435
[email protected]b172aee2012-04-10 17:05:261436void WebContentsImpl::OnRegisterIntentService(const string16& action,
1437 const string16& type,
1438 const string16& href,
1439 const string16& title,
1440 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511441 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301442 this, action, type, href, title, disposition);
1443}
1444
[email protected]b172aee2012-04-10 17:05:261445void WebContentsImpl::OnWebIntentDispatch(
1446 const webkit_glue::WebIntentData& intent,
1447 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001448 WebIntentsDispatcherImpl* intents_dispatcher =
1449 new WebIntentsDispatcherImpl(this, intent, intent_id);
1450 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301451}
1452
[email protected]b172aee2012-04-10 17:05:261453void WebContentsImpl::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1454 bool is_main_frame,
1455 const GURL& opener_url,
1456 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281457 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181458 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451459 GURL validated_opener_url(opener_url);
[email protected]9f76c1e2012-03-05 15:15:581460 GetRenderViewHostImpl()->FilterURL(
1461 ChildProcessSecurityPolicyImpl::GetInstance(),
1462 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451463 false,
[email protected]9f76c1e2012-03-05 15:15:581464 &validated_url);
[email protected]6b7cd8f2012-03-21 21:02:451465 GetRenderViewHostImpl()->FilterURL(
1466 ChildProcessSecurityPolicyImpl::GetInstance(),
1467 GetRenderProcessHost()->GetID(),
1468 true,
1469 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181470
[email protected]8093a542011-05-13 07:29:321471 RenderViewHost* rvh =
1472 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521473 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101474 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251475 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101476 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321477 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101478
[email protected]724159a2010-12-30 01:11:181479 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591480 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251481 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451482 ProvisionalChangeToMainFrameUrl(validated_url,
1483 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181484 }
1485}
1486
[email protected]b172aee2012-04-10 17:05:261487void WebContentsImpl::OnDidRedirectProvisionalLoad(int32 page_id,
1488 const GURL& opener_url,
1489 const GURL& source_url,
1490 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491491 // TODO(creis): Remove this method and have the pre-rendering code listen to
1492 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1493 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451494 GURL validated_source_url(source_url);
1495 GURL validated_target_url(target_url);
1496 GURL validated_opener_url(opener_url);
1497 GetRenderViewHostImpl()->FilterURL(
1498 ChildProcessSecurityPolicyImpl::GetInstance(),
1499 GetRenderProcessHost()->GetID(),
1500 false,
1501 &validated_source_url);
1502 GetRenderViewHostImpl()->FilterURL(
1503 ChildProcessSecurityPolicyImpl::GetInstance(),
1504 GetRenderProcessHost()->GetID(),
1505 false,
1506 &validated_target_url);
1507 GetRenderViewHostImpl()->FilterURL(
1508 ChildProcessSecurityPolicyImpl::GetInstance(),
1509 GetRenderProcessHost()->GetID(),
1510 true,
1511 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231512 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181513 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251514 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181515 else
1516 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]6b7cd8f2012-03-21 21:02:451517 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181518 return;
[email protected]e7d50892011-01-19 21:47:381519
[email protected]4850a7f2011-03-08 23:36:591520 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251521 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451522 ProvisionalChangeToMainFrameUrl(validated_target_url,
1523 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181524}
1525
[email protected]b172aee2012-04-10 17:05:261526void WebContentsImpl::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581527 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1528 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1529 << ", error_code: " << params.error_code
1530 << ", error_description: " << params.error_description
1531 << ", is_main_frame: " << params.is_main_frame
1532 << ", showing_repost_interstitial: " <<
1533 params.showing_repost_interstitial
1534 << ", frame_id: " << params.frame_id;
1535 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581536 GetRenderViewHostImpl()->FilterURL(
1537 ChildProcessSecurityPolicyImpl::GetInstance(),
1538 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451539 false,
[email protected]9f76c1e2012-03-05 15:15:581540 &validated_url);
[email protected]724159a2010-12-30 01:11:181541
[email protected]d7b175e2011-10-11 15:31:581542 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181543 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1544 // This means that the interstitial won't be torn down properly, which is
1545 // bad. But if we have an interstitial, go back to another tab type, and
1546 // then load the same interstitial again, we could end up getting the first
1547 // interstitial's "failed" message (as a result of the cancel) when we're on
1548 // the second one.
1549 //
1550 // We can't tell this apart, so we think we're tearing down the current page
1551 // which will cause a crash later one. There is also some code in
1552 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1553 // out because of this problem.
1554 //
1555 // http://code.google.com/p/chromium/issues/detail?id=2855
1556 // Because this will not tear down the interstitial properly, if "back" is
1557 // back to another tab type, the interstitial will still be somewhat alive
1558 // in the previous tab type. If you navigate somewhere that activates the
1559 // tab with the interstitial again, you'll see a flash before the new load
1560 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271561 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181562 LOG(WARNING) << "Discarding message during interstitial.";
1563 return;
1564 }
1565
[email protected]02102f82011-06-13 20:37:021566 // Discard our pending entry if the load canceled (e.g. if we decided to
1567 // download the file instead of load it). We do not verify that the URL
1568 // being canceled matches the pending entry's URL because they will not
1569 // match if a redirect occurred (in which case we do not want to leave a
1570 // stale redirect URL showing). This means that we also cancel the pending
1571 // entry if the user started a new navigation. As a result, the navigation
1572 // controller may not remember that a load is in progress, but the
1573 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251574 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161575 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181576
[email protected]151a63d2011-12-20 22:32:521577 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181578 }
1579
[email protected]d8c660432011-12-22 20:51:251580 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581581 observers_,
1582 DidFailProvisionalLoad(params.frame_id,
1583 params.is_main_frame,
1584 validated_url,
1585 params.error_code,
1586 params.error_description));
[email protected]724159a2010-12-30 01:11:181587}
1588
[email protected]b172aee2012-04-10 17:05:261589void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181590 const GURL& url,
[email protected]70435962011-08-02 20:13:281591 const std::string& security_info,
1592 const std::string& http_method,
1593 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191594 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181595 cache.Increment();
1596
1597 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081598 int cert_id = 0;
1599 net::CertStatus cert_status = 0;
1600 int security_bits = -1;
1601 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511602 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1603 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301604 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161605 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181606
[email protected]ad50def52011-10-19 23:17:071607 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271608 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501609 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531610 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181611}
1612
[email protected]b172aee2012-04-10 17:05:261613void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381614 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181615 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201616 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181617}
1618
[email protected]b172aee2012-04-10 17:05:261619void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021620 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231621 LOG(INFO) << security_origin << " ran insecure content from "
1622 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381623 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411624 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1625 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181626 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411627 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201628 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181629}
1630
[email protected]b172aee2012-04-10 17:05:261631void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181632 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251633 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101634 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181635}
1636
[email protected]b172aee2012-04-10 17:05:261637void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311638 int64 frame_id,
1639 const GURL& validated_url,
1640 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251641 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311642 DidFinishLoad(frame_id, validated_url, is_main_frame));
1643}
1644
[email protected]b172aee2012-04-10 17:05:261645void WebContentsImpl::OnDidFailLoadWithError(
1646 int64 frame_id,
1647 const GURL& validated_url,
1648 bool is_main_frame,
1649 int error_code,
1650 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251651 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311652 DidFailLoad(frame_id, validated_url, is_main_frame,
1653 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181654}
1655
[email protected]b172aee2012-04-10 17:05:261656void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271657 content_restrictions_ = restrictions;
1658 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171659}
1660
[email protected]b172aee2012-04-10 17:05:261661void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261662 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231663 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251664 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261665 if (!entry)
1666 return;
1667 // Note that we don't call NavigationController::GotToOffset() as we don't
1668 // want to create a pending navigation entry (it might end up lingering
1669 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251670 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581671 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511672 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581673 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471674 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571675
1676 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1677 // it in now that we know. This allows us to find the entry when it commits.
1678 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231679 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331680 entry->set_site_instance(
1681 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571682 }
[email protected]216813952011-05-19 22:21:261683 }
1684}
1685
[email protected]b172aee2012-04-10 17:05:261686void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
1687 int maximum_percent,
1688 bool remember) {
[email protected]216813952011-05-19 22:21:261689 minimum_zoom_percent_ = minimum_percent;
1690 maximum_zoom_percent_ = maximum_percent;
1691 temporary_zoom_settings_ = !remember;
1692}
1693
[email protected]b172aee2012-04-10 17:05:261694void WebContentsImpl::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481695 download_stats::RecordDownloadSource(
1696 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261697 // Check if the URL to save matches the URL of the main frame. Since this
1698 // message originates from Pepper plugins, it may not be the case if the
1699 // plugin is an embedded element.
1700 GURL main_frame_url = GetURL();
1701 if (!main_frame_url.is_valid())
1702 return;
1703 bool is_main_frame = (url == main_frame_url);
1704 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271705}
1706
[email protected]b172aee2012-04-10 17:05:261707void WebContentsImpl::OnEnumerateDirectory(int request_id,
1708 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591709 ChildProcessSecurityPolicyImpl* policy =
1710 ChildProcessSecurityPolicyImpl::GetInstance();
1711 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1712 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211713}
1714
[email protected]b172aee2012-04-10 17:05:261715void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511716 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201717}
1718
[email protected]b172aee2012-04-10 17:05:261719void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
1720 const GURL& url,
1721 const string16& title) {
[email protected]b9535422012-02-09 01:47:591722 ChildProcessSecurityPolicyImpl* policy =
1723 ChildProcessSecurityPolicyImpl::GetInstance();
1724 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1725 return;
[email protected]6934a702011-12-20 00:04:511726 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201727}
1728
[email protected]b172aee2012-04-10 17:05:261729void WebContentsImpl::OnFindReply(int request_id,
1730 int number_of_matches,
1731 const gfx::Rect& selection_rect,
1732 int active_match_ordinal,
1733 bool final_update) {
[email protected]6934a702011-12-20 00:04:511734 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1735 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001736 // Send a notification to the renderer that we are ready to receive more
1737 // results from the scoping effort of the Find operation. The FindInPage
1738 // scoping is asynchronous and periodically sends results back up to the
1739 // browser using IPC. In an effort to not spam the browser we have the
1740 // browser send an ACK for each FindReply message and have the renderer
1741 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581742 GetRenderViewHostImpl()->Send(
1743 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161744}
1745
[email protected]b172aee2012-04-10 17:05:261746void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511747 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451748}
1749
[email protected]b172aee2012-04-10 17:05:261750void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
1751 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:101752 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251753 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101754 AppCacheAccessed(manifest_url, blocked_by_policy));
1755}
1756
[email protected]b172aee2012-04-10 17:05:261757void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
1758 const SkColor& color) {
[email protected]da8543762012-03-20 08:52:201759 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1760}
1761
[email protected]b172aee2012-04-10 17:05:261762void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201763 if (color_chooser_ &&
1764 color_chooser_id == color_chooser_->identifier())
1765 color_chooser_->End();
1766}
1767
[email protected]b172aee2012-04-10 17:05:261768void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
1769 const SkColor& color) {
[email protected]da8543762012-03-20 08:52:201770 if (color_chooser_ &&
1771 color_chooser_id == color_chooser_->identifier())
1772 color_chooser_->SetSelectedColor(color);
1773}
1774
[email protected]9f2a9d72012-04-16 16:02:221775void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
1776 const FilePath& path,
1777 bool is_hung) {
[email protected]8be45842012-04-13 19:49:291778 if (delegate_)
1779 delegate_->PluginHungStatusChanged(this, plugin_child_id, path, is_hung);
1780}
1781
[email protected]96d185d2009-04-24 03:28:541782// Notifies the RenderWidgetHost instance about the fact that the page is
1783// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:261784void WebContentsImpl::SetIsLoading(bool is_loading,
1785 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:541786 if (is_loading == is_loading_)
1787 return;
1788
1789 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211790 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541791 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561792 upload_size_ = 0;
1793 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541794 }
1795
1796 render_manager_.SetIsLoading(is_loading);
1797
1798 is_loading_ = is_loading;
1799 waiting_for_response_ = is_loading;
1800
[email protected]6ebdc9b2010-09-27 16:55:571801 if (delegate_)
1802 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461803 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541804
[email protected]432115822011-07-10 15:52:271805 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1806 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071807 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541808 if (details)
[email protected]6c2381d2011-10-19 02:52:531809 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071810 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501811 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541812 det);
1813}
1814
[email protected]b172aee2012-04-10 17:05:261815void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131816 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321817 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561818 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381819 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441820 // that opened the window, as long as both renderers have the same
1821 // privileges.
[email protected]1fd1a502011-03-30 16:55:561822 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561823 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581824 // web_ui might be NULL if the URL refers to a non-existent extension.
1825 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401826 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521827 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441828 }
1829 }
[email protected]1fd1a502011-03-30 16:55:561830 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441831 }
1832
[email protected]4e697b042011-07-08 06:44:561833 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321834 // Clear the status bubble. This is a workaround for a bug where WebKit
1835 // doesn't let us know that the cursor left an element during a
1836 // transition (this is also why the mouse cursor remains as a hand after
1837 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1838 // clear the bubble when a user navigates to a named anchor in the same
1839 // page.
[email protected]36fc0392011-12-25 03:59:511840 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321841 }
1842
[email protected]a6e82fc2010-02-24 22:28:141843 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471844 // Once the main frame is navigated, we're no longer considered to have
1845 // displayed insecure content.
1846 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171847 }
[email protected]ce5c4502009-05-06 16:46:111848
[email protected]3c9e1872010-11-18 16:17:491849 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251850 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041851 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321852}
1853
[email protected]b172aee2012-04-10 17:05:261854void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:321855 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131856 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321857 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061858 // If we navigate off the page, reset JavaScript state. This does nothing
1859 // to prevent a malicious script from spamming messages, since the script
1860 // could just reload the page to stop blocking.
1861 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551862 dialog_creator_->ResetJavaScriptState(this);
1863 dialog_creator_ = NULL;
1864 }
[email protected]420ae012009-04-24 05:16:321865
[email protected]3c9e1872010-11-18 16:17:491866 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251867 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041868 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321869}
1870
[email protected]b172aee2012-04-10 17:05:261871void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:461872 // If we are creating a RVH for a restored controller, then we need to make
1873 // sure the RenderView starts with a next_page_id_ larger than the number
1874 // of restored entries. This must be called before the RenderView starts
1875 // navigating (to avoid a race between the browser updating max_page_id and
1876 // the renderer updating next_page_id_). Because of this, we only call this
1877 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561878 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581879 if (max_restored_page_id >
1880 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1881 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1882 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321883}
1884
[email protected]b172aee2012-04-10 17:05:261885bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
1886 const string16& title) {
[email protected]420ae012009-04-24 05:16:321887 // For file URLs without a title, use the pathname instead. In the case of a
1888 // synthesized title, we don't want the update to count toward the "one set
1889 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511890 string16 final_title;
[email protected]420ae012009-04-24 05:16:321891 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511892 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1893 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321894 explicit_set = false; // Don't count synthetic titles toward the set limit.
1895 } else {
[email protected]acafd272011-07-26 17:35:571896 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321897 explicit_set = true;
1898 }
1899
[email protected]987fc3a2011-05-26 14:18:091900 // If a page is created via window.open and never navigated,
1901 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551902 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091903 if (entry) {
[email protected]36fc0392011-12-25 03:59:511904 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091905 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321906
[email protected]36fc0392011-12-25 03:59:511907 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091908 } else {
1909 if (page_title_when_no_navigation_entry_ == final_title)
1910 return false; // Nothing changed, don't bother.
1911
1912 page_title_when_no_navigation_entry_ = final_title;
1913 }
[email protected]420ae012009-04-24 05:16:321914
[email protected]420ae012009-04-24 05:16:321915 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231916 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321917
[email protected]2bb171882012-03-07 02:09:461918 std::pair<content::NavigationEntry*, bool> details =
1919 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141920
[email protected]ad50def52011-10-19 23:17:071921 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441922 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1923 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461924 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041925
[email protected]420ae012009-04-24 05:16:321926 return true;
1927}
1928
[email protected]b172aee2012-04-10 17:05:261929void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:321930 // After sending out a swap notification, we need to send a disconnect
1931 // notification so that clients that pick up a pointer to |this| can NULL the
1932 // pointer. See Bug 1230284.
1933 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071934 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201935 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1936 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071937 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321938}
1939
[email protected]b172aee2012-04-10 17:05:261940void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:321941 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071942 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121943 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1944 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071945 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321946}
1947
[email protected]b172aee2012-04-10 17:05:261948void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:321949 if (!notify_disconnection_)
1950 return;
1951
1952 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071953 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321954 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1955 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071956 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321957}
1958
[email protected]b172aee2012-04-10 17:05:261959RenderViewHostDelegate::View* WebContentsImpl::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321960 return view_.get();
1961}
1962
[email protected]8d3347f2009-07-09 22:00:211963RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:261964WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:211965 return &render_manager_;
1966}
1967
[email protected]b172aee2012-04-10 17:05:261968content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371969 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461970 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511971}
1972
[email protected]b172aee2012-04-10 17:05:261973WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:171974 return this;
1975}
1976
[email protected]b172aee2012-04-10 17:05:261977content::ViewType WebContentsImpl::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431978 return view_type_;
[email protected]7b291f92009-08-14 05:43:531979}
1980
[email protected]b172aee2012-04-10 17:05:261981gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:171982 if (delegate_)
1983 return delegate_->GetRootWindowResizerRect();
1984 return gfx::Rect();
1985}
1986
[email protected]b172aee2012-04-10 17:05:261987void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071988 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271989 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321990 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531991 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231992 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321993 if (!entry)
1994 return;
1995
1996 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351997 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561998 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581999 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322000
2001 if (entry->IsViewSourceMode()) {
2002 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582003 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2004 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322005 }
[email protected]0666aef2009-05-13 19:48:082006
[email protected]d487beefe2011-12-21 05:41:212007 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262008
2009 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252010 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322011}
2012
[email protected]b172aee2012-04-10 17:05:262013void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522014 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322015 // Don't notify the world, since this came from a renderer in the
2016 // background.
2017 return;
2018 }
2019
2020 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312021 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232022 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302023
2024 // Restore the focus to the tab (otherwise the focus will be on the top
2025 // window).
[email protected]484ae5912010-09-29 19:16:142026 if (was_crashed && !FocusLocationBarByDefault() &&
2027 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302028 Focus();
[email protected]484ae5912010-09-29 19:16:142029 }
[email protected]32ded2212011-11-10 18:51:432030
[email protected]d8c660432011-12-22 20:51:252031 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322032}
2033
[email protected]b172aee2012-04-10 17:05:262034void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2035 base::TerminationStatus status,
2036 int error_code) {
[email protected]151a63d2011-12-20 22:32:522037 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322038 // The pending page's RenderViewHost is gone.
2039 return;
2040 }
2041
2042 SetIsLoading(false, NULL);
2043 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232044 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312045 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322046
[email protected]d8c660432011-12-22 20:51:252047 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272048 observers_,
[email protected]be1f56ab2011-12-22 06:55:312049 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322050}
2051
[email protected]b172aee2012-04-10 17:05:262052void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482053 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252054 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062055}
2056
[email protected]b172aee2012-04-10 17:05:262057void WebContentsImpl::DidNavigate(
2058 RenderViewHost* rvh,
2059 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582060 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322061 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372062
[email protected]434f69f2012-02-06 21:56:522063 // Update the site of the SiteInstance if it doesn't have one yet, unless
2064 // this is for about:blank. In that case, the SiteInstance can still be
2065 // considered unused until a navigation to a real page.
2066 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2067 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332068 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522069 }
[email protected]420ae012009-04-24 05:16:322070
2071 // Need to update MIME type here because it's referred to in
2072 // UpdateNavigationCommands() called by RendererDidNavigate() to
2073 // determine whether or not to enable the encoding menu.
2074 // It's updated only for the main frame. For a subframe,
2075 // RenderView::UpdateURL does not set params.contents_mime_type.
2076 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2077 // TODO(jungshik): Add a test for the encoding menu to avoid
2078 // regressing it again.
[email protected]2905f742011-10-13 03:51:582079 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322080 contents_mime_type_ = params.contents_mime_type;
2081
[email protected]8286f51a2011-05-31 17:39:132082 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002083 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392084
[email protected]a9c0bfe2010-09-17 08:35:222085 // Send notification about committed provisional loads. This notification is
2086 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2087 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082088 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072089 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2090 // that is not recorded in the navigation history. For the purpose of
2091 // tracking navigation events, we treat this event as a sub frame navigation
2092 // event.
2093 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582094 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222095 // Whether or not a page transition was triggered by going backward or
2096 // forward in the history is only stored in the navigation controller's
2097 // entry list.
2098 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512099 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582100 content::PAGE_TRANSITION_FORWARD_BACK)) {
2101 transition_type = content::PageTransitionFromInt(
2102 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222103 }
[email protected]0d60f0192011-04-14 12:40:102104 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252105 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102106 DidCommitProvisionalLoadForFrame(params.frame_id,
2107 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222108 }
2109
[email protected]76543b92009-08-31 17:27:452110 if (!did_navigate)
2111 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322112
2113 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2114 // for the appropriate notification (best) or you can add it to
2115 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2116 // necessary, please).
2117
2118 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002119 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322120 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512121 if (delegate_)
2122 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002123 }
[email protected]420ae012009-04-24 05:16:322124 DidNavigateAnyFramePostCommit(rvh, details, params);
2125}
2126
[email protected]b172aee2012-04-10 17:05:262127void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2128 int32 page_id,
2129 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152130 // Ensure that this state update comes from either the active RVH or one of
2131 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522132 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322133
2134 // We must be prepared to handle state updates for any page, these occur
2135 // when the user is scrolling and entering form data, as well as when we're
2136 // leaving a page, in which case our state may have already been moved to
2137 // the next page. The navigation controller will look up the appropriate
2138 // NavigationEntry and update it when it is notified via the delegate.
2139
2140 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582141 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322142 if (entry_index < 0)
2143 return;
[email protected]10f417c52011-12-28 21:04:232144 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322145
[email protected]36fc0392011-12-25 03:59:512146 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322147 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512148 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322149 controller_.NotifyEntryChanged(entry, entry_index);
2150}
2151
[email protected]b172aee2012-04-10 17:05:262152void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2153 int32 page_id,
2154 const string16& title,
2155 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322156 // If we have a title, that's a pretty good indication that we've started
2157 // getting useful data.
2158 SetNotWaitingForResponse();
2159
[email protected]73eb2602012-02-09 19:50:552160 // Try to find the navigation entry, which might not be the current one.
2161 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232162 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582163 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092164
[email protected]73eb2602012-02-09 19:50:552165 // We can handle title updates when we don't have an entry in
2166 // UpdateTitleForEntry, but only if the update is from the current RVH.
2167 if (!entry && rvh != GetRenderViewHost())
2168 return;
2169
[email protected]a49e10b2011-08-01 23:57:462170 // TODO(evan): make use of title_direction.
2171 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092172 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322173 return;
2174
2175 // Broadcast notifications when the UI should be updated.
2176 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462177 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322178}
2179
[email protected]b172aee2012-04-10 17:05:262180void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2181 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312182 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322183}
2184
[email protected]b172aee2012-04-10 17:05:262185void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512186 if (delegate_)
2187 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322188}
2189
[email protected]b172aee2012-04-10 17:05:262190void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292191 // The UI may be in an event-tracking loop, such as between the
2192 // mouse-down and mouse-up in text selection or a button click.
2193 // Defer the close until after tracking is complete, so that we
2194 // don't free objects out from under the UI.
2195 // TODO(shess): This could probably be integrated with the
2196 // IsDoingDrag() test below. Punting for now because I need more
2197 // research to understand how this impacts platforms other than Mac.
2198 // TODO(shess): This could get more fine-grained. For instance,
2199 // closing a tab in another window while selecting text in the
2200 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212201 if (GetView()->IsEventTracking()) {
2202 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292203 return;
2204 }
2205
[email protected]24a4d1062009-07-10 23:10:422206 // If we close the tab while we're in the middle of a drag, we'll crash.
2207 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212208 if (GetView()->IsDoingDrag()) {
2209 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422210 return;
2211 }
2212
[email protected]420ae012009-04-24 05:16:322213 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522214 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512215 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322216}
2217
[email protected]b172aee2012-04-10 17:05:262218void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522219 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512220 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572221}
2222
[email protected]b172aee2012-04-10 17:05:262223void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512224 if (delegate_ && delegate_->IsPopupOrPanel(this))
2225 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322226}
2227
[email protected]b172aee2012-04-10 17:05:262228void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322229 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492230
[email protected]82114f52012-03-20 22:53:412231 if (delegate_ && content_restrictions_)
2232 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492233
2234 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252235 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322236}
2237
[email protected]b172aee2012-04-10 17:05:262238void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322239 scoped_ptr<LoadNotificationDetails> details;
2240
[email protected]10f417c52011-12-28 21:04:232241 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322242 // An entry may not exist for a stop when loading an initial blank page or
2243 // if an iframe injected by script into a blank page finishes loading.
2244 if (entry) {
[email protected]420ae012009-04-24 05:16:322245 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2246
2247 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512248 entry->GetVirtualURL(),
2249 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322250 elapsed,
2251 &controller_,
2252 controller_.GetCurrentEntryIndex()));
2253 }
2254
[email protected]420ae012009-04-24 05:16:322255 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492256
2257 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252258 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322259}
2260
[email protected]b172aee2012-04-10 17:05:262261void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162262 controller_.DiscardNonCommittedEntries();
2263
2264 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462265 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162266}
2267
[email protected]b172aee2012-04-10 17:05:262268void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512269 if (delegate_)
2270 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402271}
2272
[email protected]b172aee2012-04-10 17:05:262273void WebContentsImpl::DocumentAvailableInMainFrame(
[email protected]952a68e2011-11-17 00:36:102274 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252275 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102276 DocumentAvailableInMainFrame());
2277}
2278
[email protected]b172aee2012-04-10 17:05:262279void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082280 RenderViewHost* render_view_host,
2281 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072282 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272283 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322284 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532285 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082286}
2287
[email protected]b172aee2012-04-10 17:05:262288void WebContentsImpl::RequestOpenURL(const GURL& url,
2289 const content::Referrer& referrer,
2290 WindowOpenDisposition disposition,
2291 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482292 // Delegate to RequestTransferURL because this is just the generic
2293 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582294 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482295 GlobalRequestID());
2296}
2297
[email protected]b172aee2012-04-10 17:05:262298void WebContentsImpl::RequestTransferURL(
2299 const GURL& url,
2300 const content::Referrer& referrer,
2301 WindowOpenDisposition disposition,
2302 int64 source_frame_id,
2303 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202304 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582305 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582306 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352307 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322308 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2309 // generated suggestions).
2310 //
[email protected]e0112912011-02-02 22:54:352311 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162312 // want web sites to see a referrer of "chrome://blah" (and some
2313 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322314 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432315 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222316 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482317 false /* is_renderer_initiated */);
2318 params.transferred_global_request_id = old_request_id;
2319 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222320 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322321 } else {
[email protected]6bf6a6b52012-02-03 15:41:432322 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482323 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2324 params.transferred_global_request_id = old_request_id;
2325 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582326 }
2327 if (new_contents) {
2328 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252329 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582330 DidOpenRequestedURL(new_contents,
2331 url,
2332 referrer,
2333 disposition,
2334 transition_type,
2335 source_frame_id));
[email protected]420ae012009-04-24 05:16:322336 }
2337}
2338
[email protected]b172aee2012-04-10 17:05:262339void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342340 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412341 const string16& message,
2342 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322343 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472344 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322345 IPC::Message* reply_msg,
2346 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072347 // Suppress JavaScript dialogs when requested. Also suppress messages when
2348 // showing an interstitial as it's shown over the previous page and we don't
2349 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502350 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582351 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272352 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072353 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522354 delegate_->ShouldSuppressDialogs() ||
2355 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322356
2357 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432358 std::string accept_lang = content::GetContentClient()->browser()->
2359 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552360 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522361 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432362 this,
2363 frame_url.GetOrigin(),
2364 accept_lang,
2365 javascript_message_type,
2366 message,
[email protected]51da7e32012-01-30 19:24:522367 default_prompt,
[email protected]b172aee2012-04-10 17:05:262368 base::Bind(&WebContentsImpl::OnDialogClosed,
2369 base::Unretained(this),
2370 rvh,
2371 reply_msg),
[email protected]51da7e32012-01-30 19:24:522372 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322373 }
[email protected]3ab9cb82011-06-03 18:02:072374
2375 if (suppress_this_message) {
2376 // If we are suppressing messages, just reply as if the user immediately
2377 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342378 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072379 }
2380
2381 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322382}
2383
[email protected]b172aee2012-04-10 17:05:262384void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2385 const string16& message,
2386 bool is_reload,
2387 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582388 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512389 if (delegate_)
2390 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072391
2392 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582393 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072394 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522395 delegate_->ShouldSuppressDialogs() ||
2396 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152397 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342398 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582399 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502400 return;
2401 }
[email protected]3ab9cb82011-06-03 18:02:072402
[email protected]7ab1e7d62009-10-14 23:32:012403 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552404 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522405 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322406 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262407 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522408 reply_msg));
[email protected]420ae012009-04-24 05:16:322409}
2410
[email protected]b172aee2012-04-10 17:05:262411WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332412 // We want to base the page config off of the real URL, rather than the
2413 // display URL.
2414 GURL url = controller_.GetActiveEntry()
2415 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2416 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322417}
2418
[email protected]b172aee2012-04-10 17:05:262419void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272420 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252421 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222422
[email protected]ea114722012-03-12 01:11:252423 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172424 if (rdh) // NULL in unittests.
2425 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252426}
2427
[email protected]b172aee2012-04-10 17:05:262428void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442429 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252430 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442431}
2432
[email protected]b172aee2012-04-10 17:05:262433void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2434 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152435 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522436 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152437 return;
2438
[email protected]9f76c1e2012-03-05 15:15:582439 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2440
[email protected]e5fc1632011-08-08 07:51:532441 // Ignore renderer unresponsive event if debugger is attached to the tab
2442 // since the event may be a result of the renderer sitting on a breakpoint.
2443 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442444 DevToolsAgentHost* agent =
2445 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2446 if (agent &&
2447 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532448 return;
2449
[email protected]420ae012009-04-24 05:16:322450 if (is_during_unload) {
2451 // Hang occurred while firing the beforeunload/unload handler.
2452 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582453 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322454
2455 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2456 return;
2457
2458 // If the tab hangs in the beforeunload/unload handler there's really
2459 // nothing we can do to recover. Pretend the unload listeners have
2460 // all fired and close the tab. If the hang is in the beforeunload handler
2461 // then the user will not have the option of cancelling the close.
2462 Close(rvh);
2463 return;
2464 }
2465
[email protected]9f76c1e2012-03-05 15:15:582466 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472467 return;
2468
[email protected]6934a702011-12-20 00:04:512469 if (delegate_)
2470 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322471}
2472
[email protected]b172aee2012-04-10 17:05:262473void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512474 if (delegate_)
2475 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322476}
2477
[email protected]b172aee2012-04-10 17:05:262478void WebContentsImpl::LoadStateChanged(
2479 const GURL& url,
2480 const net::LoadStateWithParam& load_state,
2481 uint64 upload_position,
2482 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322483 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562484 upload_position_ = upload_position;
2485 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502486 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202487 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302488 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212489 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322490 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462491 if (IsLoading()) {
2492 NotifyNavigationStateChanged(
2493 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2494 }
[email protected]420ae012009-04-24 05:16:322495}
2496
[email protected]b172aee2012-04-10 17:05:262497void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512498 if (delegate_)
2499 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252500}
2501
[email protected]b172aee2012-04-10 17:05:262502void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322503 bool proceed,
2504 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512505 if (delegate_)
2506 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322507}
2508
[email protected]b172aee2012-04-10 17:05:262509void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542510 RenderViewHost* render_view_host) {
2511 DidStartLoading();
2512}
2513
[email protected]b172aee2012-04-10 17:05:262514void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542515 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232516 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2517 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542518}
2519
[email protected]b172aee2012-04-10 17:05:262520void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102521 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262522 gfx::Size size = view_->GetContainerSize();
2523 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2524 // here during container initialization and normal window size will be set
2525 // later. In case of tab duplication this resizing to 0x0 prevents setting
2526 // normal size later so just ignore it.
2527 if (!size.IsEmpty())
2528 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322529}
2530
[email protected]b172aee2012-04-10 17:05:262531void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542532 NotifySwapped();
2533}
2534
[email protected]b172aee2012-04-10 17:05:262535NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202536 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542537}
2538
[email protected]b172aee2012-04-10 17:05:262539WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562540 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322541}
2542
[email protected]10f417c52011-12-28 21:04:232543NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262544 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322545 return controller_.GetLastCommittedEntry();
2546}
2547
[email protected]b172aee2012-04-10 17:05:262548bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]420ae012009-04-24 05:16:322549 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442550 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322551 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522552
[email protected]420ae012009-04-24 05:16:322553 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442554 if (rwh_view)
2555 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322556
[email protected]74ce1ad2011-12-16 21:51:462557 // Make sure we use the correct starting page_id in the new RenderView.
2558 UpdateMaxPageIDIfNecessary(render_view_host);
2559 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582560 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462561
[email protected]9f76c1e2012-03-05 15:15:582562 if (!static_cast<RenderViewHostImpl*>(
2563 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522564 return false;
2565
[email protected]e60c0232011-11-11 19:56:352566#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502567 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2568 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442569 if (rwh_view) {
2570 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2571 render_widget_host->WasResized();
2572 }
[email protected]f8233cc2011-05-31 20:24:502573#endif
2574
[email protected]420ae012009-04-24 05:16:322575 return true;
2576}
2577
[email protected]b172aee2012-04-10 17:05:262578void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
2579 IPC::Message* reply_msg,
2580 bool success,
2581 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542582 if (is_showing_before_unload_dialog_ && !success) {
2583 // If a beforeunload dialog is canceled, we need to stop the throbber from
2584 // spinning, since we forced it to start spinning in Navigate.
2585 DidStopLoading();
2586
[email protected]3bbacc5b2012-04-17 17:46:152587 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:542588 }
2589 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582590 static_cast<RenderViewHostImpl*>(
2591 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542592}
2593
[email protected]b172aee2012-04-10 17:05:262594void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122595 encoding_ = content::GetContentClient()->browser()->
2596 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102597}
[email protected]f45d2a72010-03-08 23:28:352598
[email protected]b172aee2012-04-10 17:05:262599void WebContentsImpl::SaveURL(const GURL& url,
2600 const GURL& referrer,
2601 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142602 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2603 if (!dlm)
2604 return;
2605 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262606 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142607 const NavigationEntry* entry = controller_.GetActiveEntry();
2608 if (entry)
2609 post_id = entry->GetPostID();
2610 }
[email protected]29a5ffc82012-03-13 19:35:582611 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142612 save_info.prompt_for_save_location = true;
2613 dlm->DownloadUrl(url,
2614 referrer,
2615 "",
2616 true, // prefer_cache
2617 post_id,
2618 save_info,
[email protected]89e6aa72012-03-12 22:51:332619 this,
2620 DownloadManager::OnStartedCallback());
[email protected]27678b2a2012-02-04 22:09:142621}
2622
[email protected]b172aee2012-04-10 17:05:262623void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212624 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442625 // Can be NULL during tests.
2626 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212627 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362628}
[email protected]9f76c1e2012-03-05 15:15:582629
[email protected]b172aee2012-04-10 17:05:262630RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:582631 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2632}