blob: feec297f10f63b9b0f83f01a73b51f5f012c9a75 [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]b9535422012-02-09 01:47:5917#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4418#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0419#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4620#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1221#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1622#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3223#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5424#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0525#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0026#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0127#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3028#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3229#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2530#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3331#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3732#include "content/browser/web_contents/interstitial_page_impl.h"
33#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5634#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2435#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5136#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0237#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5838#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1139#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2040#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4441#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4442#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1743#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1444#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4645#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1546#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2747#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0048#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4849#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3250#include "content/public/browser/resource_request_details.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]d353541f2012-05-03 22:45:4166#include "ui/base/ui_base_switches.h"
67#include "ui/gfx/monitor.h"
68#include "ui/gfx/screen.h"
[email protected]ce9751942011-09-21 01:57:2469#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3170#include "webkit/glue/webpreferences.h"
71
[email protected]f66df822012-05-18 16:52:1772#if defined(OS_MACOSX)
[email protected]d353541f2012-05-03 22:45:4173#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5774#endif
[email protected]3e45ba92009-02-20 21:09:0075
[email protected]420ae012009-04-24 05:16:3276// Cross-Site Navigations
77//
[email protected]b172aee2012-04-10 17:05:2678// If a WebContentsImpl is told to navigate to a different web site (as
79// determined by SiteInstance), it will replace its current RenderViewHost with
80// a new RenderViewHost dedicated to the new SiteInstance. This works as
81// follows:
[email protected]420ae012009-04-24 05:16:3282//
83// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4684// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3285// - The pending RVH is "suspended," so that no navigation messages are sent to
86// its renderer until the onbeforeunload JavaScript handler has a chance to
87// run in the current RVH.
88// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
89// that it has a pending cross-site request. ResourceDispatcherHost will
90// check for this when the response arrives.
91// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4692// cancel all the pending logic. Otherwise we allow the pending RVH to send
93// the navigation request to its renderer.
94// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
95// main resource load on the pending RVH. It checks CrossSiteRequestManager
96// to see that it is a cross-site request, and installs a
97// CrossSiteResourceHandler.
98// - When RDH receives a response, the BufferedResourceHandler determines
99// whether it is a download. If so, it sends a message to the new renderer
100// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26101// pending RVH remains until the next DidNavigate event for this
102// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32103// - After RDH receives a response and determines that it is safe and not a
104// download, it pauses the response to first run the old page's onunload
105// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26106// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32107// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15108// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32109// the ResourceDispatcherHost, who unpauses the response. Data is then sent
110// to the pending RVH.
111// - The pending renderer sends a FrameNavigate message that invokes the
112// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46113// pending RVH.
[email protected]992db4c2011-05-12 15:37:15114// - The previous renderer is kept swapped out in RenderViewHostManager in case
115// the user goes back. The process only stays live if another tab is using
116// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32117
[email protected]0e12d7d2011-12-01 16:21:44118using content::DevToolsAgentHost;
119using content::DevToolsAgentHostRegistry;
120using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17121using content::DownloadItem;
122using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14123using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20124using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56125using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13126using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27127using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54128using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50129using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23130using content::NavigationEntry;
131using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20132using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11133using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57134using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27135using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11136using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58137using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04138using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25139using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14140using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43141using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33142using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38143using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09144using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25145using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56146using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22147using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50148using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25149using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44150
[email protected]420ae012009-04-24 05:16:32151namespace {
152
153// Amount of time we wait between when a key event is received and the renderer
154// is queried for its state and pushed to the NavigationEntry.
155const int kQueryStateDelay = 5000;
156
[email protected]6ebdc9b2010-09-27 16:55:57157const int kSyncWaitDelay = 40;
158
[email protected]82114f52012-03-20 22:53:41159const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05160
[email protected]420ae012009-04-24 05:16:32161#if defined(OS_WIN)
162
163BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
164 // Note: erase is required to properly paint some widgets borders. This can
165 // be seen with textfields.
166 InvalidateRect(hwnd, NULL, TRUE);
167 return TRUE;
168}
169#endif
170
[email protected]2c5569662011-03-22 20:45:02171ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23172 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50173 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16174 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47175 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02176 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47177 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02178 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47179 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16180 break; // Fall through to rest of function.
181 }
[email protected]5e369672009-11-03 23:48:30182
[email protected]59246c572012-02-10 13:32:13183 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
184 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23185 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13186 browser_context->DidLastSessionExitCleanly()) {
187 if (entry.GetHasPostData())
188 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02189 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13190 }
[email protected]5e369672009-11-03 23:48:30191
[email protected]2c5569662011-03-22 20:45:02192 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30193}
194
[email protected]10f417c52011-12-28 21:04:23195void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47196 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42197 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50198 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16199 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51200 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54201 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55202 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
203 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51204 params->url = entry.GetURL();
205 params->referrer = entry.GetReferrer();
206 params->transition = entry.GetTransitionType();
207 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00208 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55209 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34210 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47211 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48212 params->transferred_request_child_id =
213 entry.transferred_global_request_id().child_id;
214 params->transferred_request_request_id =
215 entry.transferred_global_request_id().request_id;
[email protected]80744782012-05-04 01:47:00216 // Avoid downloading when in view-source mode.
217 params->allow_download = !entry.IsViewSourceMode();
[email protected]6c6b02d2011-09-02 03:36:47218
219 if (delegate)
220 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34221}
222
[email protected]f98f5092012-05-19 00:08:14223int GetSwitchValueAsInt(
224 const CommandLine& command_line,
225 const std::string& switch_string,
226 int min_value) {
227 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
228 int int_value;
229 if (base::StringToInt(string_value, &int_value))
230 return std::max(min_value, int_value);
231 else
232 return min_value;
233}
234
[email protected]420ae012009-04-24 05:16:32235} // namespace
236
[email protected]a81343d232011-12-27 07:39:20237namespace content {
238
239WebContents* WebContents::Create(
240 BrowserContext* browser_context,
241 SiteInstance* site_instance,
242 int routing_id,
[email protected]b172aee2012-04-10 17:05:26243 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20244 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26245 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43246 browser_context,
247 site_instance,
248 routing_id,
[email protected]b172aee2012-04-10 17:05:26249 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44250 NULL,
[email protected]adbfb8df2012-02-24 01:19:43251 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20252}
[email protected]746d3052012-05-22 15:15:47253
254WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
255 return rvh->GetDelegate()->GetAsWebContents();
256}
257
[email protected]a81343d232011-12-27 07:39:20258}
[email protected]f4f50ef2011-01-21 19:01:19259
[email protected]b172aee2012-04-10 17:05:26260// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32261
[email protected]b172aee2012-04-10 17:05:26262WebContentsImpl::WebContentsImpl(
263 content::BrowserContext* browser_context,
264 SiteInstance* site_instance,
265 int routing_id,
266 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44267 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26268 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42269 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07270 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37271 this, browser_context, session_storage_namespace)),
[email protected]14392a52012-05-02 20:28:44272 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05273 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34274 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23275 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
276 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34277 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21278 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56279 upload_size_(0),
280 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47281 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57282 capturing_contents_(false),
283 is_being_destroyed_(false),
284 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55285 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57286#if defined(OS_WIN)
287 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
288#endif
[email protected]7ab1e7d62009-10-14 23:32:01289 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56290 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38291 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25292 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01293 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25294 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01295 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00296 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43297 content_restrictions_(0),
[email protected]c8160f22012-05-14 06:44:03298 view_type_(content::VIEW_TYPE_INVALID),
[email protected]da8543762012-03-20 08:52:20299 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37300 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32301
[email protected]38b098f2012-03-14 21:11:57302 view_.reset(content::GetContentClient()->browser()->
303 OverrideCreateWebContentsView(this));
304 if (!view_.get()) {
305 content::WebContentsViewDelegate* delegate =
306 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
307 this);
[email protected]f66df822012-05-18 16:52:17308 view_.reset(CreateWebContentsView(this, delegate));
[email protected]38b098f2012-03-14 21:11:57309 }
310 CHECK(view_.get());
311
[email protected]ca13a442012-04-17 14:00:12312 // We have the initial size of the view be based on the size of the view of
313 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26314 view_->CreateView(base_web_contents ?
315 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00316
[email protected]14392a52012-05-02 20:28:44317 // Listen for whether our opener gets destroyed.
318 if (opener_) {
319 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
320 content::Source<WebContents>(opener_));
321 }
322
[email protected]483623eb2011-10-25 09:30:00323#if defined(ENABLE_JAVA_BRIDGE)
324 java_bridge_dispatcher_host_manager_.reset(
325 new JavaBridgeDispatcherHostManager(this));
326#endif
[email protected]332af7732009-03-11 13:21:35327}
initial.commit09911bf2008-07-26 23:55:29328
[email protected]b172aee2012-04-10 17:05:26329WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32330 is_being_destroyed_ = true;
331
[email protected]3ab9cb82011-06-03 18:02:07332 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55333 if (dialog_creator_)
334 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07335
[email protected]da8543762012-03-20 08:52:20336 if (color_chooser_)
337 color_chooser_->End();
338
[email protected]420ae012009-04-24 05:16:32339 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32340
[email protected]ca13a442012-04-17 14:00:12341 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07342 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09343 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
344 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07345 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32346
347 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07348#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32349 // If we still have a window handle, destroy it. GetNativeView can return
350 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42351 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52352 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58353 if (host && host->GetView())
354 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42355 }
[email protected]420ae012009-04-24 05:16:32356#endif
[email protected]7ab1e7d62009-10-14 23:32:01357
358 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15359 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01360 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15361 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01362 }
[email protected]b5a1d11c2011-02-17 03:09:42363
[email protected]2db9bd72012-04-13 20:20:56364 FOR_EACH_OBSERVER(WebContentsObserver,
365 observers_,
366 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08367
[email protected]6934a702011-12-20 00:04:51368 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42369}
370
[email protected]b172aee2012-04-10 17:05:26371WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
372 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54373 WebPreferences prefs;
374
375 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
376
377 prefs.developer_extras_enabled = true;
378 prefs.javascript_enabled =
379 !command_line.HasSwitch(switches::kDisableJavaScript);
380 prefs.web_security_enabled =
381 !command_line.HasSwitch(switches::kDisableWebSecurity);
382 prefs.plugins_enabled =
383 !command_line.HasSwitch(switches::kDisablePlugins);
384 prefs.java_enabled =
385 !command_line.HasSwitch(switches::kDisableJava);
386
387 prefs.uses_page_cache =
388 command_line.HasSwitch(switches::kEnableFastback);
389 prefs.remote_fonts_enabled =
390 !command_line.HasSwitch(switches::kDisableRemoteFonts);
391 prefs.xss_auditor_enabled =
392 !command_line.HasSwitch(switches::kDisableXSSAuditor);
393 prefs.application_cache_enabled =
394 !command_line.HasSwitch(switches::kDisableApplicationCache);
395
396 prefs.local_storage_enabled =
397 !command_line.HasSwitch(switches::kDisableLocalStorage);
398 prefs.databases_enabled =
399 !command_line.HasSwitch(switches::kDisableDatabases);
400 prefs.webaudio_enabled =
401 !command_line.HasSwitch(switches::kDisableWebAudio);
402
403 prefs.experimental_webgl_enabled =
404 GpuProcessHost::gpu_enabled() &&
405 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
406 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
407
408 prefs.gl_multisampling_enabled =
409 !command_line.HasSwitch(switches::kDisableGLMultisampling);
410 prefs.privileged_webgl_extensions_enabled =
411 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
412 prefs.site_specific_quirks_enabled =
413 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
414 prefs.allow_file_access_from_file_urls =
415 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
416 prefs.show_composited_layer_borders =
417 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
418 prefs.show_composited_layer_tree =
419 command_line.HasSwitch(switches::kShowCompositedLayerTree);
420 prefs.show_fps_counter =
421 command_line.HasSwitch(switches::kShowFPSCounter);
422 prefs.accelerated_compositing_enabled =
423 GpuProcessHost::gpu_enabled() &&
424 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54425 prefs.force_compositing_mode =
426 command_line.HasSwitch(switches::kForceCompositingMode);
427 prefs.fixed_position_compositing_enabled =
428 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
429 prefs.accelerated_2d_canvas_enabled =
430 GpuProcessHost::gpu_enabled() &&
431 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58432 prefs.deferred_2d_canvas_enabled =
433 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36434 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31435 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54436 prefs.accelerated_painting_enabled =
437 GpuProcessHost::gpu_enabled() &&
438 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
439 prefs.accelerated_filters_enabled =
440 GpuProcessHost::gpu_enabled() &&
441 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
442 prefs.accelerated_layers_enabled =
443 prefs.accelerated_animation_enabled =
444 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54445 prefs.accelerated_plugins_enabled =
446 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
447 prefs.accelerated_video_enabled =
448 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
449 prefs.partial_swap_enabled =
450 command_line.HasSwitch(switches::kEnablePartialSwap);
451 prefs.interactive_form_validation_enabled =
452 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
453 prefs.fullscreen_enabled =
454 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16455 prefs.css_regions_enabled =
456 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29457 prefs.css_shaders_enabled =
458 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]64d69de42012-02-06 00:19:54459
460#if defined(OS_MACOSX)
461 bool default_enable_scroll_animator = true;
462#else
463 // On CrOS, the launcher always passes in the --enable flag.
464 bool default_enable_scroll_animator = false;
465#endif
466 prefs.enable_scroll_animator = default_enable_scroll_animator;
467 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
468 prefs.enable_scroll_animator = true;
469 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
470 prefs.enable_scroll_animator = false;
471
472 prefs.visual_word_movement_enabled =
473 command_line.HasSwitch(switches::kEnableVisualWordMovement);
474 prefs.per_tile_painting_enabled =
475 command_line.HasSwitch(switches::kEnablePerTilePainting);
476
477 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32478 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54479 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11480 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
481 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54482 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11483 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54484 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11485 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54486 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11487 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54488 prefs.gl_multisampling_enabled = false;
489
490 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45491 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32492 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54493 prefs.accelerated_video_enabled = false;
494 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45495 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09496 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54497 }
498 }
499
[email protected]b9535422012-02-09 01:47:59500 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58501 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54502 prefs.loads_images_automatically = true;
503 prefs.javascript_enabled = true;
504 }
505
506 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
507
508 // Force accelerated compositing and 2d canvas off for chrome:, about: and
509 // chrome-devtools: pages (unless it's specifically allowed).
510 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54511 url.SchemeIs(chrome::kChromeUIScheme) ||
512 (url.SchemeIs(chrome::kAboutScheme) &&
513 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25514 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54515 prefs.accelerated_compositing_enabled = false;
516 prefs.accelerated_2d_canvas_enabled = false;
517 }
[email protected]8b3b36152012-05-01 04:55:07518#if defined(OS_MACOSX)
519 // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
520 // crbug.com/125690.
[email protected]82c9a8e2012-05-02 01:07:23521 prefs.default_device_scale_factor =
522 gfx::Monitor::GetDefaultDeviceScaleFactor();
[email protected]8b3b36152012-05-01 04:55:07523#else
524 if (rvh->GetView()) {
525 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
526 rvh->GetView()->GetNativeView());
527 prefs.default_device_scale_factor =
528 static_cast<int>(monitor.device_scale_factor());
529 } else {
[email protected]82c9a8e2012-05-02 01:07:23530 prefs.default_device_scale_factor =
531 gfx::Monitor::GetDefaultDeviceScaleFactor();;
[email protected]8b3b36152012-05-01 04:55:07532 }
533#endif
[email protected]43d9d782012-03-01 15:40:09534
[email protected]f98f5092012-05-19 00:08:14535 if (command_line.HasSwitch(switches::kDefaultTileWidth))
536 prefs.default_tile_width =
537 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
538 if (command_line.HasSwitch(switches::kDefaultTileHeight))
539 prefs.default_tile_height =
540 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
541 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
542 prefs.max_untiled_layer_width =
543 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
544 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
545 prefs.max_untiled_layer_height =
546 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
547
[email protected]2e21fe292012-03-02 22:52:32548 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54549
550 return prefs;
551}
552
[email protected]b172aee2012-04-10 17:05:26553NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20554 return controller_;
555}
556
[email protected]b172aee2012-04-10 17:05:26557RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28558 return &render_manager_;
559}
560
[email protected]b172aee2012-04-10 17:05:26561bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56562 if (GetWebUI() &&
563 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17564 return true;
[email protected]d2353452012-01-19 19:53:56565 }
[email protected]f82d57b52011-04-27 19:13:17566
[email protected]d8c660432011-12-22 20:51:25567 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
568 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10569 while ((observer = it.GetNext()) != NULL)
570 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53571 return true;
[email protected]403415a2011-01-10 18:57:53572
[email protected]724159a2010-12-30 01:11:18573 bool handled = true;
574 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26575 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58576 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
577 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24578 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
579 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18580 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
581 OnDidLoadResourceFromMemoryCache)
582 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
583 OnDidDisplayInsecureContent)
584 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
585 OnDidRunInsecureContent)
586 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
587 OnDocumentLoadedInFrame)
588 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26589 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
590 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17591 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
592 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25593 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26594 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59595 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21596 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20597 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
598 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
599 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16600 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45601 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10602 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20603 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
604 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
605 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
606 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29607 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50608 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18609 IPC_MESSAGE_UNHANDLED(handled = false)
610 IPC_END_MESSAGE_MAP_EX()
611
612 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38613 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18614 GetRenderProcessHost()->ReceivedBadMessage();
615 }
616
617 return handled;
618}
619
[email protected]b172aee2012-04-10 17:05:26620void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18621 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23622 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51623 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18624}
625
[email protected]b172aee2012-04-10 17:05:26626NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56627 return controller_;
628}
629
[email protected]b172aee2012-04-10 17:05:26630const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56631 return controller_;
632}
633
[email protected]b172aee2012-04-10 17:05:26634content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55635 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30636}
637
[email protected]b172aee2012-04-10 17:05:26638void WebContentsImpl::SetViewType(content::ViewType type) {
[email protected]f5fa20e2011-12-21 22:35:56639 view_type_ = type;
640}
641
[email protected]b172aee2012-04-10 17:05:26642content::ViewType WebContentsImpl::GetViewType() const {
[email protected]ea049a02011-12-25 21:37:09643 return view_type_;
644}
645
[email protected]b172aee2012-04-10 17:05:26646const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31647 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23648 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51649 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31650}
651
652
[email protected]b172aee2012-04-10 17:05:26653const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31654 return &property_bag_;
655}
656
[email protected]b172aee2012-04-10 17:05:26657base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31658 return &property_bag_;
659}
660
[email protected]b172aee2012-04-10 17:05:26661content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31662 return delegate_;
663}
664
[email protected]b172aee2012-04-10 17:05:26665void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31666 // TODO(cbentzel): remove this debugging code?
667 if (delegate == delegate_)
668 return;
669 if (delegate_)
670 delegate_->Detach(this);
671 delegate_ = delegate;
672 if (delegate_)
673 delegate_->Attach(this);
674}
675
[email protected]b172aee2012-04-10 17:05:26676content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41677 RenderViewHostImpl* host = render_manager_.current_host();
678 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16679}
680
[email protected]b172aee2012-04-10 17:05:26681RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31682 return render_manager_.current_host();
683}
684
[email protected]b172aee2012-04-10 17:05:26685RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31686 return render_manager_.GetRenderWidgetHostView();
687}
688
[email protected]b172aee2012-04-10 17:05:26689content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31690 return view_.get();
691}
692
[email protected]b172aee2012-04-10 17:05:26693content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50694 WebUIControllerFactory* factory =
695 content::GetContentClient()->browser()->GetWebUIControllerFactory();
696 if (!factory)
697 return NULL;
[email protected]d2353452012-01-19 19:53:56698 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22699 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50700 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22701 if (controller) {
702 web_ui->SetController(controller);
703 return web_ui;
704 }
705
706 delete web_ui;
707 return NULL;
708}
709
[email protected]b172aee2012-04-10 17:05:26710content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31711 return render_manager_.web_ui() ? render_manager_.web_ui()
712 : render_manager_.pending_web_ui();
713}
714
[email protected]b172aee2012-04-10 17:05:26715content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31716 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34717}
718
[email protected]86ef6a392012-05-11 22:03:11719void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
720 user_agent_override_ = override;
721}
722
723const std::string& WebContentsImpl::GetUserAgentOverride() const {
724 return user_agent_override_;
725}
726
[email protected]b172aee2012-04-10 17:05:26727const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55728 // Transient entries take precedence. They are used for interstitial pages
729 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23730 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08731 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20732 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30733 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23734 if (entry) {
[email protected]b5cca982011-05-26 04:42:08735 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23736 }
[email protected]7ade2732011-02-10 00:13:58737 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
738 render_manager_.pending_web_ui() : render_manager_.web_ui();
739 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54740 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55741 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54742 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35743 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22744 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54745 if (!title.empty())
746 return title;
747 }
748 }
749
750 // We use the title for the last committed entry rather than a pending
751 // navigation entry. For example, when the user types in a URL, we want to
752 // keep the old page's title until the new load has committed and we get a new
753 // title.
[email protected]96d185d2009-04-24 03:28:54754 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23755 if (entry) {
[email protected]b5cca982011-05-26 04:42:08756 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23757 }
[email protected]987fc3a2011-05-26 14:18:09758
759 // |page_title_when_no_navigation_entry_| is finally used
760 // if no title cannot be retrieved.
761 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54762}
763
[email protected]b172aee2012-04-10 17:05:26764int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46765 return GetMaxPageIDForSiteInstance(GetSiteInstance());
766}
767
[email protected]b172aee2012-04-10 17:05:26768int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
769 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33770 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
771 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46772
[email protected]b6583592012-01-25 19:52:33773 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34774}
775
[email protected]b172aee2012-04-10 17:05:26776void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46777 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
778}
779
[email protected]b172aee2012-04-10 17:05:26780void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33781 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46782 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33783 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34784}
785
[email protected]b172aee2012-04-10 17:05:26786void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
787 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57788}
789
[email protected]b172aee2012-04-10 17:05:26790SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58791 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54792}
793
[email protected]b172aee2012-04-10 17:05:26794SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38795 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
796 render_manager_.pending_render_view_host() :
797 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58798 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38799}
800
[email protected]b172aee2012-04-10 17:05:26801bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31802 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49803}
804
[email protected]b172aee2012-04-10 17:05:26805bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31806 return waiting_for_response_;
807}
808
[email protected]b172aee2012-04-10 17:05:26809const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31810 return load_state_;
811}
812
[email protected]b172aee2012-04-10 17:05:26813const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31814 return load_state_host_;
815}
816
[email protected]b172aee2012-04-10 17:05:26817uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31818 return upload_size_;
819}
820
[email protected]b172aee2012-04-10 17:05:26821uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31822 return upload_position_;
823}
824
[email protected]b172aee2012-04-10 17:05:26825const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31826 return encoding_;
827}
828
[email protected]b172aee2012-04-10 17:05:26829bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31830 return displayed_insecure_content_;
831}
832
[email protected]b172aee2012-04-10 17:05:26833void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31834 capturing_contents_ = cap;
835}
836
[email protected]b172aee2012-04-10 17:05:26837bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31838 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
839 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
840 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49841}
842
[email protected]b172aee2012-04-10 17:05:26843void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
844 int error_code) {
[email protected]443b80e2010-12-14 00:42:23845 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34846 return;
847
[email protected]443b80e2010-12-14 00:42:23848 crashed_status_ = status;
849 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46850 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34851}
852
[email protected]b172aee2012-04-10 17:05:26853base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31854 return crashed_status_;
855}
856
[email protected]b172aee2012-04-10 17:05:26857bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31858 return is_being_destroyed_;
859}
860
[email protected]b172aee2012-04-10 17:05:26861void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34862 if (delegate_)
863 delegate_->NavigationStateChanged(this, changed_flags);
864}
865
[email protected]b172aee2012-04-10 17:05:26866void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54867 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04868 RenderWidgetHostViewPort* rwhv =
869 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16870 if (rwhv) {
871 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43872#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16873 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43874#endif
875 }
[email protected]96d185d2009-04-24 03:28:54876
[email protected]5ac20162010-11-24 23:33:11877 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38878
[email protected]d8c660432011-12-22 20:51:25879 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59880
881 // The resize rect might have changed while this was inactive -- send the new
882 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58883 RenderViewHostImpl* rvh =
884 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59885 if (rvh) {
886 rvh->ResizeRectChanged(GetRootWindowResizerRect());
887 }
[email protected]96d185d2009-04-24 03:28:54888}
889
[email protected]be1f56ab2011-12-22 06:55:31890
[email protected]b172aee2012-04-10 17:05:26891base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31892 return last_selected_time_;
893}
894
[email protected]b172aee2012-04-10 17:05:26895void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31896 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52897 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
898 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26899 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52900 // removes the |GetRenderViewHost()|; then when we actually destroy the
901 // window, OnWindowPosChanged() notices and calls HideContents() (which
902 // calls us).
[email protected]c30585c2012-02-16 15:02:04903 RenderWidgetHostViewPort* rwhv =
904 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16905 if (rwhv)
906 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54907 }
908
[email protected]ad50def52011-10-19 23:17:07909 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09910 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
911 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07912 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54913}
914
[email protected]b172aee2012-04-10 17:05:26915void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04916 RenderWidgetHostViewPort* rwhv =
917 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31918 if (rwhv)
919 rwhv->DidBecomeSelected();
920}
921
[email protected]b172aee2012-04-10 17:05:26922void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31923 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
924 // our superclass HideContents(), because some callers want to be very picky
925 // about the order in which these get called. In addition to making the code
926 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26927 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
928 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31929 WasHidden();
930}
931
[email protected]b172aee2012-04-10 17:05:26932bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31933 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27934 return WillNotifyDisconnection() &&
935 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58936 !static_cast<RenderViewHostImpl*>(
937 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31938}
939
[email protected]b172aee2012-04-10 17:05:26940void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27941 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25942 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27943}
944
[email protected]b172aee2012-04-10 17:05:26945WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44946 // We use our current SiteInstance since the cloned entry will use it anyway.
947 // We pass |this| for the |base_web_contents| to size the view correctly, and
948 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26949 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44950 GetBrowserContext(), GetSiteInstance(),
951 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20952 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27953 return tc;
954}
955
[email protected]b172aee2012-04-10 17:05:26956void WebContentsImpl::AddNewContents(WebContents* new_contents,
957 WindowOpenDisposition disposition,
958 const gfx::Rect& initial_pos,
959 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27960 if (!delegate_)
961 return;
962
963 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
964 user_gesture);
965}
966
[email protected]b172aee2012-04-10 17:05:26967gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27968 return view_->GetContentNativeView();
969}
970
[email protected]b172aee2012-04-10 17:05:26971gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:27972 return view_->GetNativeView();
973}
974
[email protected]b172aee2012-04-10 17:05:26975void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:27976 view_->GetContainerBounds(out);
977}
978
[email protected]b172aee2012-04-10 17:05:26979void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:27980 view_->Focus();
981}
982
[email protected]14392a52012-05-02 20:28:44983void WebContentsImpl::Observe(int type,
984 const content::NotificationSource& source,
985 const content::NotificationDetails& details) {
986 switch (type) {
987 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
988 OnWebContentsDestroyed(
989 content::Source<content::WebContents>(source).ptr());
990 break;
991 default:
992 NOTREACHED();
993 }
994}
995
996void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
997 // Clear the opener if it has been closed.
998 if (web_contents == opener_) {
999 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1000 content::Source<WebContents>(opener_));
1001 opener_ = NULL;
1002 }
1003}
1004
[email protected]b172aee2012-04-10 17:05:261005void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311006 observers_.AddObserver(observer);
1007}
1008
[email protected]b172aee2012-04-10 17:05:261009void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311010 observers_.RemoveObserver(observer);
1011}
1012
[email protected]b172aee2012-04-10 17:05:261013void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341014 if (delegate_)
1015 delegate_->ActivateContents(this);
1016}
1017
[email protected]b172aee2012-04-10 17:05:261018void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121019 if (delegate_)
1020 delegate_->DeactivateContents(this);
1021}
1022
[email protected]b172aee2012-04-10 17:05:261023void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481024 if (delegate_)
1025 delegate_->LostCapture();
1026}
1027
[email protected]b172aee2012-04-10 17:05:261028bool WebContentsImpl::PreHandleKeyboardEvent(
1029 const NativeWebKeyboardEvent& event,
1030 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481031 return delegate_ &&
1032 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1033}
1034
[email protected]b172aee2012-04-10 17:05:261035void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481036 if (delegate_)
1037 delegate_->HandleKeyboardEvent(event);
1038}
1039
[email protected]b172aee2012-04-10 17:05:261040void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431041 if (delegate_)
1042 delegate_->HandleMouseDown();
1043}
1044
[email protected]b172aee2012-04-10 17:05:261045void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481046 if (delegate_)
1047 delegate_->HandleMouseUp();
1048}
1049
[email protected]b172aee2012-04-10 17:05:261050void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481051 if (delegate_)
1052 delegate_->HandleMouseActivate();
1053}
1054
[email protected]b172aee2012-04-10 17:05:261055void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471056 if (delegate_)
1057 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1058}
1059
[email protected]b172aee2012-04-10 17:05:261060bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381061 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121062}
1063
[email protected]42252e02012-04-26 16:29:391064void WebContentsImpl::RequestToLockMouse(bool user_gesture) {
[email protected]e9621112011-10-17 05:38:371065 if (delegate_) {
[email protected]42252e02012-04-26 16:29:391066 delegate_->RequestToLockMouse(this, user_gesture);
[email protected]e9621112011-10-17 05:38:371067 } else {
1068 GotResponseToLockMouseRequest(false);
1069 }
1070}
1071
[email protected]b172aee2012-04-10 17:05:261072void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371073 if (delegate_)
1074 delegate_->LostMouseLock();
1075}
1076
[email protected]b172aee2012-04-10 17:05:261077void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231078 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331079 if (delegate_)
1080 delegate_->UpdatePreferredSize(this, pref_size);
1081}
1082
[email protected]b172aee2012-04-10 17:05:261083void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341084 if (delegate_)
1085 delegate_->ResizeDueToAutoResize(this, new_size);
1086}
1087
[email protected]b172aee2012-04-10 17:05:261088WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201089 if (!delegate_)
1090 return NULL;
[email protected]00c37fc2011-08-02 00:22:501091
[email protected]e5d549d2011-12-28 01:29:201092 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1093 // Notify observers.
1094 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1095 DidOpenURL(params.url, params.referrer,
1096 params.disposition, params.transition));
1097 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341098}
1099
[email protected]b172aee2012-04-10 17:05:261100bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501101 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251102 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231103 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251104 reload_type);
[email protected]876bc832010-09-07 16:29:541105}
[email protected]96d185d2009-04-24 03:28:541106
[email protected]b172aee2012-04-10 17:05:261107bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231108 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501109 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401110 // The renderer will reject IPC messages with URLs longer than
1111 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511112 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401113 return false;
1114
[email protected]9f76c1e2012-03-05 15:15:581115 RenderViewHostImpl* dest_render_view_host =
1116 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401117 if (!dest_render_view_host)
1118 return false; // Unable to create the desired render view host.
1119
[email protected]80a8fad2011-01-29 04:02:381120 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071121 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581122 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501123 WebUIControllerFactory* factory =
1124 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271125 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501126 bool is_allowed_in_web_ui_renderer =
1127 factory &&
[email protected]24e18252012-04-16 21:26:271128 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1129 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231130 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1131 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271132 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231133 content::GetContentClient()->SetActiveURL(entry.GetURL());
1134 CHECK(0);
1135 }
[email protected]54ec6472010-04-09 19:39:581136
[email protected]96d185d2009-04-24 03:28:541137 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441138 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521139 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441140 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511141 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541142
1143 // Used for page load time metrics.
1144 current_load_start_ = base::TimeTicks::Now();
1145
1146 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341147 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271148 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471149 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341150 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541151
[email protected]36fc0392011-12-25 03:59:511152 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541153 // HACK!! This code suppresses javascript: URLs from being added to
1154 // session history, which is what we want to do for javascript: URLs that
1155 // do not generate content. What we really need is a message from the
1156 // renderer telling us that a new page was not created. The same message
1157 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511158 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541159 return false;
1160 }
1161
[email protected]3c9e1872010-11-18 16:17:491162 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251163 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041164 observers_,
[email protected]36fc0392011-12-25 03:59:511165 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541166
[email protected]09b29342011-06-24 19:18:481167 if (delegate_)
1168 delegate_->DidNavigateToPendingEntry(this);
1169
[email protected]d5f942ba2008-09-26 19:30:341170 return true;
1171}
1172
[email protected]b172aee2012-04-10 17:05:261173void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331174 const SiteInstance* site_instance,
1175 int history_length,
1176 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411177 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1178 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191179 if (render_manager_.pending_render_view_host()) {
1180 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141181 return;
[email protected]9e1ad4b2011-08-14 16:49:191182 }
[email protected]9f76c1e2012-03-05 15:15:581183 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191184 if (!rvh) {
1185 NOTREACHED();
1186 return;
1187 }
[email protected]9f76c1e2012-03-05 15:15:581188 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191189 NOTREACHED();
1190 return;
1191 }
[email protected]9f76c1e2012-03-05 15:15:581192 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191193 history_length,
1194 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141195}
1196
[email protected]b172aee2012-04-10 17:05:261197void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271198 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541199 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1200 return;
1201 }
[email protected]9f76c1e2012-03-05 15:15:581202 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541203}
1204
[email protected]b172aee2012-04-10 17:05:261205bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271206 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541207}
1208
[email protected]b172aee2012-04-10 17:05:261209InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271210 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221211}
1212
[email protected]b172aee2012-04-10 17:05:261213bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161214 // WebKit creates Document object when MIME type is application/xhtml+xml,
1215 // so we also support this MIME type.
1216 return contents_mime_type_ == "text/html" ||
1217 contents_mime_type_ == "text/xml" ||
1218 contents_mime_type_ == "application/xhtml+xml" ||
1219 contents_mime_type_ == "text/plain" ||
1220 contents_mime_type_ == "text/css" ||
1221 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1222}
1223
[email protected]b172aee2012-04-10 17:05:261224void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591225 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161226 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481227 download_stats::RecordDownloadSource(
1228 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461229 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141230 return;
[email protected]c7dd2f62011-07-18 15:57:591231 }
1232
1233 Stop();
1234
1235 // Create the save package and possibly prompt the user for the name to save
1236 // the page as. The user prompt is an asynchronous operation that runs on
1237 // another thread.
1238 save_package_ = new SavePackage(this);
1239 save_package_->GetSaveInfo();
1240}
1241
1242// Used in automated testing to bypass prompting the user for file names.
1243// Instead, the names and paths are hard coded rather than running them through
1244// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261245bool WebContentsImpl::SavePage(const FilePath& main_file,
1246 const FilePath& dir_path,
1247 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591248 // Stop the page from navigating.
1249 Stop();
1250
1251 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271252 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591253}
1254
[email protected]b172aee2012-04-10 17:05:261255void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121256 const FilePath& file,
1257 const base::Callback<void(const FilePath&, int64)>& callback) {
1258 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1259}
1260
[email protected]b172aee2012-04-10 17:05:261261bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231262 NavigationEntryImpl* active_entry =
1263 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321264 return (active_entry != NULL &&
1265 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511266 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321267}
1268
[email protected]b172aee2012-04-10 17:05:261269const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271270 return contents_mime_type_;
1271}
1272
[email protected]b172aee2012-04-10 17:05:261273bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271274 return notify_disconnection_;
1275}
1276
[email protected]b172aee2012-04-10 17:05:261277void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311278 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581279 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1280 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161281}
1282
[email protected]b172aee2012-04-10 17:05:261283void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311284 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581285 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1286 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161287}
1288
[email protected]b172aee2012-04-10 17:05:261289content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271290 return &renderer_preferences_;
1291}
1292
[email protected]b172aee2012-04-10 17:05:261293void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271294 new_tab_start_time_ = time;
1295}
1296
[email protected]b172aee2012-04-10 17:05:261297base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271298 return new_tab_start_time_;
1299}
1300
[email protected]b172aee2012-04-10 17:05:261301void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151302 if (close_start_time_.is_null())
1303 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011304}
1305
[email protected]b172aee2012-04-10 17:05:261306bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191307#if defined(OS_CHROMEOS)
1308 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1309 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511310 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201311 return false;
1312 return true;
[email protected]46624bf2010-06-09 16:04:191313#else
1314 return true;
1315#endif
1316}
1317
[email protected]b172aee2012-04-10 17:05:261318void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521319 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581320 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511321 if (delegate_)
1322 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341323}
1324
[email protected]b172aee2012-04-10 17:05:261325void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271326 closed_by_user_gesture_ = value;
1327}
1328
[email protected]b172aee2012-04-10 17:05:261329bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271330 return closed_by_user_gesture_;
1331}
1332
[email protected]b172aee2012-04-10 17:05:261333double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051334 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561335 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251336 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171337 return 0;
[email protected]b75b8292010-10-01 07:28:251338
1339 double zoom_level;
1340 if (temporary_zoom_settings_) {
1341 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581342 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251343 } else {
[email protected]2ae88d12011-10-14 09:11:191344 GURL url;
[email protected]10f417c52011-12-28 21:04:231345 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191346 // Since zoom map is updated using rewritten URL, use rewritten URL
1347 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511348 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191349 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251350 }
[email protected]d0b8d092010-10-25 04:05:171351 return zoom_level;
1352}
[email protected]b75b8292010-10-01 07:28:251353
[email protected]b172aee2012-04-10 17:05:261354int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1355 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171356 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011357 // Calculate the zoom percent from the factor. Round up to the nearest whole
1358 // number.
[email protected]b75b8292010-10-01 07:28:251359 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011360 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251361 *enable_decrement = percent > minimum_zoom_percent_;
1362 *enable_increment = percent < maximum_zoom_percent_;
1363 return percent;
1364}
1365
[email protected]b172aee2012-04-10 17:05:261366void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501367 if (!delegate_)
1368 return;
1369
[email protected]10f417c52011-12-28 21:04:231370 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501371 if (!active_entry)
1372 return;
1373
[email protected]36fc0392011-12-25 03:59:511374 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121375}
1376
[email protected]b172aee2012-04-10 17:05:261377void WebContentsImpl::ViewFrameSource(const GURL& url,
1378 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271379 if (!delegate_)
1380 return;
1381
1382 delegate_->ViewSourceForFrame(this, url, content_state);
1383}
1384
[email protected]b172aee2012-04-10 17:05:261385int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271386 return minimum_zoom_percent_;
1387}
1388
[email protected]b172aee2012-04-10 17:05:261389int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271390 return maximum_zoom_percent_;
1391}
1392
[email protected]b172aee2012-04-10 17:05:261393gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231394 return preferred_size_;
1395}
1396
[email protected]b172aee2012-04-10 17:05:261397int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271398 return content_restrictions_;
1399}
1400
[email protected]b172aee2012-04-10 17:05:261401WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501402 WebUIControllerFactory* factory =
1403 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1404 if (!factory)
1405 return WebUI::kNoWebUI;
1406 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271407}
1408
[email protected]b172aee2012-04-10 17:05:261409content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271410 // When there is a pending navigation entry, we want to use the pending WebUI
1411 // that goes along with it to control the basic flags. For example, we want to
1412 // show the pending URL in the URL bar, so we want the display_url flag to
1413 // be from the pending entry.
1414 //
1415 // The confusion comes because there are multiple possibilities for the
1416 // initial load in a tab as a side effect of the way the RenderViewHostManager
1417 // works.
1418 //
1419 // - For the very first tab the load looks "normal". The new tab Web UI is
1420 // the pending one, and we want it to apply here.
1421 //
1422 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1423 // get switched to the one previously associated with the new tab pages.
1424 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1425 // have a committed Web UI in this case.
1426 //
1427 // This condition handles all of these cases:
1428 //
1429 // - First load in first tab: no committed nav entry + pending nav entry +
1430 // pending dom ui:
1431 // -> Use pending Web UI if any.
1432 //
1433 // - First load in second tab: no committed nav entry + pending nav entry +
1434 // no pending Web UI:
1435 // -> Use the committed Web UI if any.
1436 //
1437 // - Second navigation in any tab: committed nav entry + pending nav entry:
1438 // -> Use pending Web UI if any.
1439 //
1440 // - Normal state with no load: committed nav entry + no pending nav entry:
1441 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251442 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271443 (controller_.GetLastCommittedEntry() ||
1444 render_manager_.pending_web_ui()))
1445 return render_manager_.pending_web_ui();
1446 return render_manager_.web_ui();
1447}
1448
[email protected]b172aee2012-04-10 17:05:261449bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271450 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581451 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271452}
1453
[email protected]b172aee2012-04-10 17:05:261454bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441455 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501456}
1457
[email protected]b172aee2012-04-10 17:05:261458void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321459 SkColor color) {
[email protected]da8543762012-03-20 08:52:201460 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1461 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1462}
1463
[email protected]b172aee2012-04-10 17:05:261464void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201465 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1466 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1467 if (delegate_)
1468 delegate_->DidEndColorChooser();
1469 color_chooser_ = NULL;
1470}
1471
[email protected]b172aee2012-04-10 17:05:261472bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471473 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271474 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221475 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231476 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411477 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271478}
1479
[email protected]b172aee2012-04-10 17:05:261480void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271481 if (delegate_)
1482 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211483}
1484
[email protected]b172aee2012-04-10 17:05:261485void WebContentsImpl::OnRegisterIntentService(const string16& action,
1486 const string16& type,
1487 const string16& href,
1488 const string16& title,
1489 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511490 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301491 this, action, type, href, title, disposition);
1492}
1493
[email protected]b172aee2012-04-10 17:05:261494void WebContentsImpl::OnWebIntentDispatch(
1495 const webkit_glue::WebIntentData& intent,
1496 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001497 WebIntentsDispatcherImpl* intents_dispatcher =
1498 new WebIntentsDispatcherImpl(this, intent, intent_id);
1499 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301500}
1501
[email protected]54047eb52012-05-08 21:45:571502void WebContentsImpl::DidStartProvisionalLoadForFrame(
1503 content::RenderViewHost* render_view_host,
1504 int64 frame_id,
1505 bool is_main_frame,
1506 const GURL& opener_url,
1507 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281508 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181509 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451510 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571511 RenderViewHostImpl* render_view_host_impl =
1512 static_cast<RenderViewHostImpl*>(render_view_host);
1513 content::RenderProcessHost* render_process_host =
1514 render_view_host->GetProcess();
1515 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581516 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571517 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451518 false,
[email protected]9f76c1e2012-03-05 15:15:581519 &validated_url);
[email protected]54047eb52012-05-08 21:45:571520 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451521 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571522 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451523 true,
1524 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181525
[email protected]0d60f0192011-04-14 12:40:101526 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251527 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101528 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571529 validated_url, is_error_page, render_view_host));
[email protected]0d60f0192011-04-14 12:40:101530
[email protected]724159a2010-12-30 01:11:181531 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591532 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251533 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451534 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]ef16c3e2012-05-16 22:13:461535 validated_opener_url,
1536 render_view_host));
[email protected]724159a2010-12-30 01:11:181537 }
1538}
1539
[email protected]54047eb52012-05-08 21:45:571540void WebContentsImpl::DidRedirectProvisionalLoad(
1541 content::RenderViewHost* render_view_host,
1542 int32 page_id,
1543 const GURL& opener_url,
1544 const GURL& source_url,
1545 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491546 // TODO(creis): Remove this method and have the pre-rendering code listen to
1547 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1548 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451549 GURL validated_source_url(source_url);
1550 GURL validated_target_url(target_url);
1551 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571552 RenderViewHostImpl* render_view_host_impl =
1553 static_cast<RenderViewHostImpl*>(render_view_host);
1554 content::RenderProcessHost* render_process_host =
1555 render_view_host->GetProcess();
1556 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451557 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571558 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451559 false,
1560 &validated_source_url);
[email protected]54047eb52012-05-08 21:45:571561 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451562 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571563 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451564 false,
1565 &validated_target_url);
[email protected]54047eb52012-05-08 21:45:571566 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451567 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571568 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451569 true,
1570 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231571 NavigationEntry* entry;
[email protected]54047eb52012-05-08 21:45:571572 if (page_id == -1) {
[email protected]022af742011-12-28 18:37:251573 entry = controller_.GetPendingEntry();
[email protected]54047eb52012-05-08 21:45:571574 } else {
1575 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1576 page_id);
1577 }
[email protected]6b7cd8f2012-03-21 21:02:451578 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181579 return;
[email protected]e7d50892011-01-19 21:47:381580
[email protected]4850a7f2011-03-08 23:36:591581 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251582 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451583 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]ef16c3e2012-05-16 22:13:461584 validated_opener_url,
1585 render_view_host));
[email protected]724159a2010-12-30 01:11:181586}
1587
[email protected]54047eb52012-05-08 21:45:571588void WebContentsImpl::DidFailProvisionalLoadWithError(
1589 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581590 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1591 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1592 << ", error_code: " << params.error_code
1593 << ", error_description: " << params.error_description
1594 << ", is_main_frame: " << params.is_main_frame
1595 << ", showing_repost_interstitial: " <<
1596 params.showing_repost_interstitial
1597 << ", frame_id: " << params.frame_id;
1598 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571599 RenderViewHostImpl* render_view_host_impl =
1600 static_cast<RenderViewHostImpl*>(render_view_host);
1601 content::RenderProcessHost* render_process_host =
1602 render_view_host->GetProcess();
1603 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581604 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571605 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451606 false,
[email protected]9f76c1e2012-03-05 15:15:581607 &validated_url);
[email protected]724159a2010-12-30 01:11:181608
[email protected]d7b175e2011-10-11 15:31:581609 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181610 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1611 // This means that the interstitial won't be torn down properly, which is
1612 // bad. But if we have an interstitial, go back to another tab type, and
1613 // then load the same interstitial again, we could end up getting the first
1614 // interstitial's "failed" message (as a result of the cancel) when we're on
1615 // the second one.
1616 //
1617 // We can't tell this apart, so we think we're tearing down the current page
1618 // which will cause a crash later one. There is also some code in
1619 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1620 // out because of this problem.
1621 //
1622 // http://code.google.com/p/chromium/issues/detail?id=2855
1623 // Because this will not tear down the interstitial properly, if "back" is
1624 // back to another tab type, the interstitial will still be somewhat alive
1625 // in the previous tab type. If you navigate somewhere that activates the
1626 // tab with the interstitial again, you'll see a flash before the new load
1627 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271628 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181629 LOG(WARNING) << "Discarding message during interstitial.";
1630 return;
1631 }
1632
[email protected]02102f82011-06-13 20:37:021633 // Discard our pending entry if the load canceled (e.g. if we decided to
1634 // download the file instead of load it). We do not verify that the URL
1635 // being canceled matches the pending entry's URL because they will not
1636 // match if a redirect occurred (in which case we do not want to leave a
1637 // stale redirect URL showing). This means that we also cancel the pending
1638 // entry if the user started a new navigation. As a result, the navigation
1639 // controller may not remember that a load is in progress, but the
1640 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251641 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161642 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181643
[email protected]54047eb52012-05-08 21:45:571644 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181645 }
1646
[email protected]d8c660432011-12-22 20:51:251647 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581648 observers_,
1649 DidFailProvisionalLoad(params.frame_id,
1650 params.is_main_frame,
1651 validated_url,
1652 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461653 params.error_description,
1654 render_view_host));
[email protected]724159a2010-12-30 01:11:181655}
1656
[email protected]b172aee2012-04-10 17:05:261657void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181658 const GURL& url,
[email protected]70435962011-08-02 20:13:281659 const std::string& security_info,
1660 const std::string& http_method,
1661 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191662 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181663 cache.Increment();
1664
1665 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081666 int cert_id = 0;
1667 net::CertStatus cert_status = 0;
1668 int security_bits = -1;
1669 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511670 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1671 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301672 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161673 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181674
[email protected]ad50def52011-10-19 23:17:071675 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271676 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501677 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531678 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181679}
1680
[email protected]b172aee2012-04-10 17:05:261681void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381682 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181683 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201684 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181685}
1686
[email protected]b172aee2012-04-10 17:05:261687void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021688 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231689 LOG(INFO) << security_origin << " ran insecure content from "
1690 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381691 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411692 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1693 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181694 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411695 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201696 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181697}
1698
[email protected]b172aee2012-04-10 17:05:261699void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181700 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251701 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101702 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181703}
1704
[email protected]b172aee2012-04-10 17:05:261705void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311706 int64 frame_id,
1707 const GURL& validated_url,
1708 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251709 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311710 DidFinishLoad(frame_id, validated_url, is_main_frame));
1711}
1712
[email protected]b172aee2012-04-10 17:05:261713void WebContentsImpl::OnDidFailLoadWithError(
1714 int64 frame_id,
1715 const GURL& validated_url,
1716 bool is_main_frame,
1717 int error_code,
1718 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251719 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311720 DidFailLoad(frame_id, validated_url, is_main_frame,
1721 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181722}
1723
[email protected]b172aee2012-04-10 17:05:261724void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271725 content_restrictions_ = restrictions;
1726 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171727}
1728
[email protected]b172aee2012-04-10 17:05:261729void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261730 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231731 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251732 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261733 if (!entry)
1734 return;
1735 // Note that we don't call NavigationController::GotToOffset() as we don't
1736 // want to create a pending navigation entry (it might end up lingering
1737 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251738 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581739 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511740 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581741 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471742 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571743
1744 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1745 // it in now that we know. This allows us to find the entry when it commits.
1746 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231747 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331748 entry->set_site_instance(
1749 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571750 }
[email protected]216813952011-05-19 22:21:261751 }
1752}
1753
[email protected]b172aee2012-04-10 17:05:261754void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
1755 int maximum_percent,
1756 bool remember) {
[email protected]216813952011-05-19 22:21:261757 minimum_zoom_percent_ = minimum_percent;
1758 maximum_zoom_percent_ = maximum_percent;
1759 temporary_zoom_settings_ = !remember;
1760}
1761
[email protected]20b433a2012-05-15 21:23:461762void WebContentsImpl::OnSaveURL(const GURL& url,
1763 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:481764 download_stats::RecordDownloadSource(
1765 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261766 // Check if the URL to save matches the URL of the main frame. Since this
1767 // message originates from Pepper plugins, it may not be the case if the
1768 // plugin is an embedded element.
1769 GURL main_frame_url = GetURL();
1770 if (!main_frame_url.is_valid())
1771 return;
1772 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:461773 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271774}
1775
[email protected]b172aee2012-04-10 17:05:261776void WebContentsImpl::OnEnumerateDirectory(int request_id,
1777 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591778 ChildProcessSecurityPolicyImpl* policy =
1779 ChildProcessSecurityPolicyImpl::GetInstance();
1780 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1781 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211782}
1783
[email protected]b172aee2012-04-10 17:05:261784void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511785 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201786}
1787
[email protected]b172aee2012-04-10 17:05:261788void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
1789 const GURL& url,
1790 const string16& title) {
[email protected]b9535422012-02-09 01:47:591791 ChildProcessSecurityPolicyImpl* policy =
1792 ChildProcessSecurityPolicyImpl::GetInstance();
1793 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1794 return;
[email protected]6934a702011-12-20 00:04:511795 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201796}
1797
[email protected]b172aee2012-04-10 17:05:261798void WebContentsImpl::OnFindReply(int request_id,
1799 int number_of_matches,
1800 const gfx::Rect& selection_rect,
1801 int active_match_ordinal,
1802 bool final_update) {
[email protected]6934a702011-12-20 00:04:511803 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1804 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001805 // Send a notification to the renderer that we are ready to receive more
1806 // results from the scoping effort of the Find operation. The FindInPage
1807 // scoping is asynchronous and periodically sends results back up to the
1808 // browser using IPC. In an effort to not spam the browser we have the
1809 // browser send an ACK for each FindReply message and have the renderer
1810 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581811 GetRenderViewHostImpl()->Send(
1812 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161813}
1814
[email protected]b172aee2012-04-10 17:05:261815void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:441816 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1817 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:451818}
1819
[email protected]b172aee2012-04-10 17:05:261820void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
1821 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:101822 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251823 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101824 AppCacheAccessed(manifest_url, blocked_by_policy));
1825}
1826
[email protected]b172aee2012-04-10 17:05:261827void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321828 SkColor color) {
[email protected]da8543762012-03-20 08:52:201829 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1830}
1831
[email protected]b172aee2012-04-10 17:05:261832void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201833 if (color_chooser_ &&
1834 color_chooser_id == color_chooser_->identifier())
1835 color_chooser_->End();
1836}
1837
[email protected]b172aee2012-04-10 17:05:261838void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321839 SkColor color) {
[email protected]da8543762012-03-20 08:52:201840 if (color_chooser_ &&
1841 color_chooser_id == color_chooser_->identifier())
1842 color_chooser_->SetSelectedColor(color);
1843}
1844
[email protected]9f2a9d72012-04-16 16:02:221845void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
1846 const FilePath& path,
1847 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:441848 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1849 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:291850}
1851
[email protected]d0759f492012-04-19 22:50:501852// This exists for render views that don't have a WebUI, but do have WebUI
1853// bindings enabled.
1854void WebContentsImpl::OnWebUISend(const GURL& source_url,
1855 const std::string& name,
1856 const base::ListValue& args) {
1857 if (delegate_)
1858 delegate_->WebUISend(this, source_url, name, args);
1859}
1860
[email protected]96d185d2009-04-24 03:28:541861// Notifies the RenderWidgetHost instance about the fact that the page is
1862// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:261863void WebContentsImpl::SetIsLoading(bool is_loading,
1864 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:541865 if (is_loading == is_loading_)
1866 return;
1867
1868 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211869 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541870 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561871 upload_size_ = 0;
1872 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541873 }
1874
1875 render_manager_.SetIsLoading(is_loading);
1876
1877 is_loading_ = is_loading;
1878 waiting_for_response_ = is_loading;
1879
[email protected]6ebdc9b2010-09-27 16:55:571880 if (delegate_)
1881 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461882 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541883
[email protected]432115822011-07-10 15:52:271884 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1885 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071886 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541887 if (details)
[email protected]6c2381d2011-10-19 02:52:531888 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071889 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501890 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541891 det);
1892}
1893
[email protected]b172aee2012-04-10 17:05:261894void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131895 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321896 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561897 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381898 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441899 // that opened the window, as long as both renderers have the same
1900 // privileges.
[email protected]1fd1a502011-03-30 16:55:561901 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561902 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581903 // web_ui might be NULL if the URL refers to a non-existent extension.
1904 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401905 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521906 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441907 }
1908 }
[email protected]1fd1a502011-03-30 16:55:561909 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441910 }
1911
[email protected]4e697b042011-07-08 06:44:561912 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321913 // Clear the status bubble. This is a workaround for a bug where WebKit
1914 // doesn't let us know that the cursor left an element during a
1915 // transition (this is also why the mouse cursor remains as a hand after
1916 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1917 // clear the bubble when a user navigates to a named anchor in the same
1918 // page.
[email protected]36fc0392011-12-25 03:59:511919 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321920 }
1921
[email protected]a6e82fc2010-02-24 22:28:141922 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471923 // Once the main frame is navigated, we're no longer considered to have
1924 // displayed insecure content.
1925 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171926 }
[email protected]ce5c4502009-05-06 16:46:111927
[email protected]3c9e1872010-11-18 16:17:491928 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251929 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041930 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321931}
1932
[email protected]b172aee2012-04-10 17:05:261933void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:321934 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131935 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321936 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061937 // If we navigate off the page, reset JavaScript state. This does nothing
1938 // to prevent a malicious script from spamming messages, since the script
1939 // could just reload the page to stop blocking.
1940 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551941 dialog_creator_->ResetJavaScriptState(this);
1942 dialog_creator_ = NULL;
1943 }
[email protected]420ae012009-04-24 05:16:321944
[email protected]3c9e1872010-11-18 16:17:491945 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251946 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041947 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321948}
1949
[email protected]b172aee2012-04-10 17:05:261950void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:461951 // If we are creating a RVH for a restored controller, then we need to make
1952 // sure the RenderView starts with a next_page_id_ larger than the number
1953 // of restored entries. This must be called before the RenderView starts
1954 // navigating (to avoid a race between the browser updating max_page_id and
1955 // the renderer updating next_page_id_). Because of this, we only call this
1956 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561957 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581958 if (max_restored_page_id >
1959 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1960 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1961 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321962}
1963
[email protected]b172aee2012-04-10 17:05:261964bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
1965 const string16& title) {
[email protected]420ae012009-04-24 05:16:321966 // For file URLs without a title, use the pathname instead. In the case of a
1967 // synthesized title, we don't want the update to count toward the "one set
1968 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511969 string16 final_title;
[email protected]420ae012009-04-24 05:16:321970 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511971 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1972 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321973 explicit_set = false; // Don't count synthetic titles toward the set limit.
1974 } else {
[email protected]acafd272011-07-26 17:35:571975 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321976 explicit_set = true;
1977 }
1978
[email protected]987fc3a2011-05-26 14:18:091979 // If a page is created via window.open and never navigated,
1980 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551981 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091982 if (entry) {
[email protected]36fc0392011-12-25 03:59:511983 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091984 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321985
[email protected]36fc0392011-12-25 03:59:511986 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091987 } else {
1988 if (page_title_when_no_navigation_entry_ == final_title)
1989 return false; // Nothing changed, don't bother.
1990
1991 page_title_when_no_navigation_entry_ = final_title;
1992 }
[email protected]420ae012009-04-24 05:16:321993
[email protected]420ae012009-04-24 05:16:321994 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231995 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321996
[email protected]2bb171882012-03-07 02:09:461997 std::pair<content::NavigationEntry*, bool> details =
1998 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141999
[email protected]ad50def52011-10-19 23:17:072000 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442001 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2002 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462003 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042004
[email protected]420ae012009-04-24 05:16:322005 return true;
2006}
2007
[email protected]b172aee2012-04-10 17:05:262008void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322009 // After sending out a swap notification, we need to send a disconnect
2010 // notification so that clients that pick up a pointer to |this| can NULL the
2011 // pointer. See Bug 1230284.
2012 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072013 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202014 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2015 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072016 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322017}
2018
[email protected]b172aee2012-04-10 17:05:262019void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322020 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072021 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122022 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2023 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072024 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322025}
2026
[email protected]b172aee2012-04-10 17:05:262027void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322028 if (!notify_disconnection_)
2029 return;
2030
2031 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072032 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322033 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2034 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072035 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322036}
2037
[email protected]b172aee2012-04-10 17:05:262038RenderViewHostDelegate::View* WebContentsImpl::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322039 return view_.get();
2040}
2041
[email protected]8d3347f2009-07-09 22:00:212042RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262043WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212044 return &render_manager_;
2045}
2046
[email protected]b172aee2012-04-10 17:05:262047content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372048 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462049 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512050}
2051
[email protected]b172aee2012-04-10 17:05:262052WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172053 return this;
2054}
2055
[email protected]b172aee2012-04-10 17:05:262056content::ViewType WebContentsImpl::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:432057 return view_type_;
[email protected]7b291f92009-08-14 05:43:532058}
2059
[email protected]b172aee2012-04-10 17:05:262060gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172061 if (delegate_)
2062 return delegate_->GetRootWindowResizerRect();
2063 return gfx::Rect();
2064}
2065
[email protected]b172aee2012-04-10 17:05:262066void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442067 // Don't send notifications if we are just creating a swapped-out RVH for
2068 // the opener chain. These won't be used for view-source or WebUI, so it's
2069 // ok to return early.
2070 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2071 return;
2072
[email protected]ad50def52011-10-19 23:17:072073 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272074 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322075 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532076 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232077 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322078 if (!entry)
2079 return;
2080
2081 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352082 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562083 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582084 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322085
2086 if (entry->IsViewSourceMode()) {
2087 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582088 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2089 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322090 }
[email protected]0666aef2009-05-13 19:48:082091
[email protected]d487beefe2011-12-21 05:41:212092 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262093
2094 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252095 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322096}
2097
[email protected]b172aee2012-04-10 17:05:262098void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522099 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322100 // Don't notify the world, since this came from a renderer in the
2101 // background.
2102 return;
2103 }
2104
2105 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312106 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232107 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302108
2109 // Restore the focus to the tab (otherwise the focus will be on the top
2110 // window).
[email protected]484ae5912010-09-29 19:16:142111 if (was_crashed && !FocusLocationBarByDefault() &&
2112 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302113 Focus();
[email protected]484ae5912010-09-29 19:16:142114 }
[email protected]32ded2212011-11-10 18:51:432115
[email protected]d8c660432011-12-22 20:51:252116 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322117}
2118
[email protected]b172aee2012-04-10 17:05:262119void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2120 base::TerminationStatus status,
2121 int error_code) {
[email protected]151a63d2011-12-20 22:32:522122 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322123 // The pending page's RenderViewHost is gone.
2124 return;
2125 }
2126
2127 SetIsLoading(false, NULL);
2128 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232129 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312130 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322131
[email protected]d8c660432011-12-22 20:51:252132 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272133 observers_,
[email protected]be1f56ab2011-12-22 06:55:312134 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322135}
2136
[email protected]b172aee2012-04-10 17:05:262137void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482138 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252139 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062140}
2141
[email protected]b172aee2012-04-10 17:05:262142void WebContentsImpl::DidNavigate(
2143 RenderViewHost* rvh,
2144 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582145 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322146 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372147
[email protected]434f69f2012-02-06 21:56:522148 // Update the site of the SiteInstance if it doesn't have one yet, unless
2149 // this is for about:blank. In that case, the SiteInstance can still be
2150 // considered unused until a navigation to a real page.
2151 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2152 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332153 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522154 }
[email protected]420ae012009-04-24 05:16:322155
2156 // Need to update MIME type here because it's referred to in
2157 // UpdateNavigationCommands() called by RendererDidNavigate() to
2158 // determine whether or not to enable the encoding menu.
2159 // It's updated only for the main frame. For a subframe,
2160 // RenderView::UpdateURL does not set params.contents_mime_type.
2161 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2162 // TODO(jungshik): Add a test for the encoding menu to avoid
2163 // regressing it again.
[email protected]2905f742011-10-13 03:51:582164 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322165 contents_mime_type_ = params.contents_mime_type;
2166
[email protected]8286f51a2011-05-31 17:39:132167 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002168 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392169
[email protected]a9c0bfe2010-09-17 08:35:222170 // Send notification about committed provisional loads. This notification is
2171 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2172 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082173 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072174 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2175 // that is not recorded in the navigation history. For the purpose of
2176 // tracking navigation events, we treat this event as a sub frame navigation
2177 // event.
2178 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582179 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222180 // Whether or not a page transition was triggered by going backward or
2181 // forward in the history is only stored in the navigation controller's
2182 // entry list.
2183 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512184 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582185 content::PAGE_TRANSITION_FORWARD_BACK)) {
2186 transition_type = content::PageTransitionFromInt(
2187 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222188 }
[email protected]0d60f0192011-04-14 12:40:102189 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252190 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102191 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462192 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222193 }
2194
[email protected]76543b92009-08-31 17:27:452195 if (!did_navigate)
2196 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322197
2198 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2199 // for the appropriate notification (best) or you can add it to
2200 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2201 // necessary, please).
2202
2203 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002204 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322205 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512206 if (delegate_)
2207 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002208 }
[email protected]420ae012009-04-24 05:16:322209 DidNavigateAnyFramePostCommit(rvh, details, params);
2210}
2211
[email protected]b172aee2012-04-10 17:05:262212void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2213 int32 page_id,
2214 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152215 // Ensure that this state update comes from either the active RVH or one of
2216 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522217 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322218
2219 // We must be prepared to handle state updates for any page, these occur
2220 // when the user is scrolling and entering form data, as well as when we're
2221 // leaving a page, in which case our state may have already been moved to
2222 // the next page. The navigation controller will look up the appropriate
2223 // NavigationEntry and update it when it is notified via the delegate.
2224
2225 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582226 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322227 if (entry_index < 0)
2228 return;
[email protected]10f417c52011-12-28 21:04:232229 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322230
[email protected]36fc0392011-12-25 03:59:512231 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322232 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512233 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322234 controller_.NotifyEntryChanged(entry, entry_index);
2235}
2236
[email protected]b172aee2012-04-10 17:05:262237void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2238 int32 page_id,
2239 const string16& title,
2240 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322241 // If we have a title, that's a pretty good indication that we've started
2242 // getting useful data.
2243 SetNotWaitingForResponse();
2244
[email protected]73eb2602012-02-09 19:50:552245 // Try to find the navigation entry, which might not be the current one.
2246 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232247 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582248 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092249
[email protected]73eb2602012-02-09 19:50:552250 // We can handle title updates when we don't have an entry in
2251 // UpdateTitleForEntry, but only if the update is from the current RVH.
2252 if (!entry && rvh != GetRenderViewHost())
2253 return;
2254
[email protected]a49e10b2011-08-01 23:57:462255 // TODO(evan): make use of title_direction.
2256 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092257 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322258 return;
2259
2260 // Broadcast notifications when the UI should be updated.
2261 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462262 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322263}
2264
[email protected]b172aee2012-04-10 17:05:262265void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2266 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312267 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322268}
2269
[email protected]b172aee2012-04-10 17:05:262270void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512271 if (delegate_)
2272 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322273}
2274
[email protected]b172aee2012-04-10 17:05:262275void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292276 // The UI may be in an event-tracking loop, such as between the
2277 // mouse-down and mouse-up in text selection or a button click.
2278 // Defer the close until after tracking is complete, so that we
2279 // don't free objects out from under the UI.
2280 // TODO(shess): This could probably be integrated with the
2281 // IsDoingDrag() test below. Punting for now because I need more
2282 // research to understand how this impacts platforms other than Mac.
2283 // TODO(shess): This could get more fine-grained. For instance,
2284 // closing a tab in another window while selecting text in the
2285 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212286 if (GetView()->IsEventTracking()) {
2287 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292288 return;
2289 }
2290
[email protected]24a4d1062009-07-10 23:10:422291 // If we close the tab while we're in the middle of a drag, we'll crash.
2292 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212293 if (GetView()->IsDoingDrag()) {
2294 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422295 return;
2296 }
2297
[email protected]420ae012009-04-24 05:16:322298 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522299 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512300 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322301}
2302
[email protected]b172aee2012-04-10 17:05:262303void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522304 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512305 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572306}
2307
[email protected]b172aee2012-04-10 17:05:262308void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512309 if (delegate_ && delegate_->IsPopupOrPanel(this))
2310 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322311}
2312
[email protected]b172aee2012-04-10 17:05:262313void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322314 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492315
[email protected]82114f52012-03-20 22:53:412316 if (delegate_ && content_restrictions_)
2317 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492318
2319 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252320 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322321}
2322
[email protected]b172aee2012-04-10 17:05:262323void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322324 scoped_ptr<LoadNotificationDetails> details;
2325
[email protected]10f417c52011-12-28 21:04:232326 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322327 // An entry may not exist for a stop when loading an initial blank page or
2328 // if an iframe injected by script into a blank page finishes loading.
2329 if (entry) {
[email protected]420ae012009-04-24 05:16:322330 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2331
2332 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512333 entry->GetVirtualURL(),
2334 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322335 elapsed,
2336 &controller_,
2337 controller_.GetCurrentEntryIndex()));
2338 }
2339
[email protected]420ae012009-04-24 05:16:322340 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492341
2342 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252343 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322344}
2345
[email protected]b172aee2012-04-10 17:05:262346void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162347 controller_.DiscardNonCommittedEntries();
2348
2349 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462350 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162351}
2352
[email protected]b172aee2012-04-10 17:05:262353void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512354 if (delegate_)
2355 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402356}
2357
[email protected]87717d0e2012-04-26 02:58:432358void WebContentsImpl::DocumentAvailableInMainFrame(
2359 RenderViewHost* render_view_host) {
2360 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2361 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102362}
2363
[email protected]b172aee2012-04-10 17:05:262364void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082365 RenderViewHost* render_view_host,
2366 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072367 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272368 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322369 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532370 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082371}
2372
[email protected]196159d2012-05-04 17:26:542373void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2374 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262375 const content::Referrer& referrer,
2376 WindowOpenDisposition disposition,
2377 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542378 // If this came from a swapped out RenderViewHost, we only allow the request
2379 // if we are still in the same BrowsingInstance.
2380 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2381 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2382 return;
2383 }
2384
[email protected]4ad5d77d2011-12-03 02:00:482385 // Delegate to RequestTransferURL because this is just the generic
2386 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582387 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482388 GlobalRequestID());
2389}
2390
[email protected]b172aee2012-04-10 17:05:262391void WebContentsImpl::RequestTransferURL(
2392 const GURL& url,
2393 const content::Referrer& referrer,
2394 WindowOpenDisposition disposition,
2395 int64 source_frame_id,
2396 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202397 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582398 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582399 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352400 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322401 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2402 // generated suggestions).
2403 //
[email protected]e0112912011-02-02 22:54:352404 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162405 // want web sites to see a referrer of "chrome://blah" (and some
2406 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322407 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432408 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222409 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482410 false /* is_renderer_initiated */);
2411 params.transferred_global_request_id = old_request_id;
2412 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222413 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322414 } else {
[email protected]6bf6a6b52012-02-03 15:41:432415 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482416 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2417 params.transferred_global_request_id = old_request_id;
2418 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582419 }
2420 if (new_contents) {
2421 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252422 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582423 DidOpenRequestedURL(new_contents,
2424 url,
2425 referrer,
2426 disposition,
2427 transition_type,
2428 source_frame_id));
[email protected]420ae012009-04-24 05:16:322429 }
2430}
2431
[email protected]e1c3a552012-05-04 20:51:322432void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2433 // Tell the active RenderViewHost to run unload handlers and close, as long
2434 // as the request came from a RenderViewHost in the same BrowsingInstance.
2435 // In most cases, we receive this from a swapped out RenderViewHost.
2436 // It is possible to receive it from one that has just been swapped in,
2437 // in which case we might as well deliver the message anyway.
2438 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2439 GetRenderViewHost()->ClosePage();
2440}
2441
[email protected]f546640b2012-05-15 00:03:492442void WebContentsImpl::RouteMessageEvent(
2443 RenderViewHost* rvh,
2444 const ViewMsg_PostMessage_Params& params) {
2445 // Only deliver the message to the active RenderViewHost if the request
2446 // came from a RenderViewHost in the same BrowsingInstance.
2447 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2448 return;
2449
2450 ViewMsg_PostMessage_Params new_params(params);
2451
2452 // If there is a source_routing_id, translate it to the routing ID for
2453 // the equivalent swapped out RVH in the target process. If we need
2454 // to create a swapped out RVH for the source tab, we create its opener
2455 // chain as well, since those will also be accessible to the target page.
2456 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2457 // Try to look up the WebContents for the source page.
2458 WebContentsImpl* source_contents = NULL;
2459 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2460 rvh->GetProcess()->GetID(), params.source_routing_id);
2461 if (source_rvh) {
2462 source_contents = static_cast<WebContentsImpl*>(
2463 source_rvh->GetDelegate()->GetAsWebContents());
2464 }
2465
2466 if (source_contents) {
2467 new_params.source_routing_id =
2468 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2469 } else {
2470 // We couldn't find it, so don't pass a source frame.
2471 new_params.source_routing_id = MSG_ROUTING_NONE;
2472 }
2473 }
2474
2475 // In most cases, we receive this from a swapped out RenderViewHost.
2476 // It is possible to receive it from one that has just been swapped in,
2477 // in which case we might as well deliver the message anyway.
2478 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2479 GetRenderViewHost()->GetRoutingID(), new_params));
2480}
2481
[email protected]b172aee2012-04-10 17:05:262482void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342483 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412484 const string16& message,
2485 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322486 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472487 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322488 IPC::Message* reply_msg,
2489 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072490 // Suppress JavaScript dialogs when requested. Also suppress messages when
2491 // showing an interstitial as it's shown over the previous page and we don't
2492 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502493 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582494 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272495 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072496 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522497 delegate_->ShouldSuppressDialogs() ||
2498 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322499
2500 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432501 std::string accept_lang = content::GetContentClient()->browser()->
2502 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552503 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522504 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432505 this,
2506 frame_url.GetOrigin(),
2507 accept_lang,
2508 javascript_message_type,
2509 message,
[email protected]51da7e32012-01-30 19:24:522510 default_prompt,
[email protected]b172aee2012-04-10 17:05:262511 base::Bind(&WebContentsImpl::OnDialogClosed,
2512 base::Unretained(this),
2513 rvh,
2514 reply_msg),
[email protected]51da7e32012-01-30 19:24:522515 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322516 }
[email protected]3ab9cb82011-06-03 18:02:072517
2518 if (suppress_this_message) {
2519 // If we are suppressing messages, just reply as if the user immediately
2520 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342521 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072522 }
2523
2524 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322525}
2526
[email protected]b172aee2012-04-10 17:05:262527void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2528 const string16& message,
2529 bool is_reload,
2530 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582531 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512532 if (delegate_)
2533 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072534
2535 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582536 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072537 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522538 delegate_->ShouldSuppressDialogs() ||
2539 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152540 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342541 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582542 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502543 return;
2544 }
[email protected]3ab9cb82011-06-03 18:02:072545
[email protected]7ab1e7d62009-10-14 23:32:012546 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552547 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522548 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322549 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262550 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522551 reply_msg));
[email protected]420ae012009-04-24 05:16:322552}
2553
[email protected]b172aee2012-04-10 17:05:262554WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332555 // We want to base the page config off of the real URL, rather than the
2556 // display URL.
2557 GURL url = controller_.GetActiveEntry()
2558 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2559 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322560}
2561
[email protected]b172aee2012-04-10 17:05:262562void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272563 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252564 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222565
[email protected]ea114722012-03-12 01:11:252566 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172567 if (rdh) // NULL in unittests.
2568 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252569}
2570
[email protected]b172aee2012-04-10 17:05:262571void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442572 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252573 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442574}
2575
[email protected]b172aee2012-04-10 17:05:262576void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2577 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152578 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522579 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152580 return;
2581
[email protected]9f76c1e2012-03-05 15:15:582582 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2583
[email protected]e5fc1632011-08-08 07:51:532584 // Ignore renderer unresponsive event if debugger is attached to the tab
2585 // since the event may be a result of the renderer sitting on a breakpoint.
2586 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442587 DevToolsAgentHost* agent =
2588 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2589 if (agent &&
2590 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532591 return;
2592
[email protected]420ae012009-04-24 05:16:322593 if (is_during_unload) {
2594 // Hang occurred while firing the beforeunload/unload handler.
2595 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582596 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322597
2598 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2599 return;
2600
2601 // If the tab hangs in the beforeunload/unload handler there's really
2602 // nothing we can do to recover. Pretend the unload listeners have
2603 // all fired and close the tab. If the hang is in the beforeunload handler
2604 // then the user will not have the option of cancelling the close.
2605 Close(rvh);
2606 return;
2607 }
2608
[email protected]9f76c1e2012-03-05 15:15:582609 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472610 return;
2611
[email protected]6934a702011-12-20 00:04:512612 if (delegate_)
2613 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322614}
2615
[email protected]b172aee2012-04-10 17:05:262616void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512617 if (delegate_)
2618 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322619}
2620
[email protected]b172aee2012-04-10 17:05:262621void WebContentsImpl::LoadStateChanged(
2622 const GURL& url,
2623 const net::LoadStateWithParam& load_state,
2624 uint64 upload_position,
2625 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322626 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562627 upload_position_ = upload_position;
2628 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502629 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202630 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302631 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212632 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322633 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462634 if (IsLoading()) {
2635 NotifyNavigationStateChanged(
2636 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2637 }
[email protected]420ae012009-04-24 05:16:322638}
2639
[email protected]b172aee2012-04-10 17:05:262640void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512641 if (delegate_)
2642 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252643}
2644
[email protected]b172aee2012-04-10 17:05:262645void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322646 bool proceed,
2647 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512648 if (delegate_)
2649 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322650}
2651
[email protected]b172aee2012-04-10 17:05:262652void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542653 RenderViewHost* render_view_host) {
2654 DidStartLoading();
2655}
2656
[email protected]b172aee2012-04-10 17:05:262657void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542658 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232659 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2660 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542661}
2662
[email protected]b172aee2012-04-10 17:05:262663void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102664 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262665 gfx::Size size = view_->GetContainerSize();
2666 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2667 // here during container initialization and normal window size will be set
2668 // later. In case of tab duplication this resizing to 0x0 prevents setting
2669 // normal size later so just ignore it.
2670 if (!size.IsEmpty())
2671 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322672}
2673
[email protected]b172aee2012-04-10 17:05:262674void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542675 NotifySwapped();
2676}
2677
[email protected]14392a52012-05-02 20:28:442678int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2679 SiteInstance* instance) {
2680 if (!opener_)
2681 return MSG_ROUTING_NONE;
2682
2683 // Recursively create RenderViews for anything else in the opener chain.
2684 return opener_->CreateOpenerRenderViews(instance);
2685}
2686
2687int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2688 int opener_route_id = MSG_ROUTING_NONE;
2689
2690 // If this tab has an opener, ensure it has a RenderView in the given
2691 // SiteInstance as well.
2692 if (opener_)
2693 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2694
2695 // Create a swapped out RenderView in the given SiteInstance if none exists,
2696 // setting its opener to the given route_id. Return the new view's route_id.
2697 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2698}
2699
[email protected]b172aee2012-04-10 17:05:262700NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202701 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542702}
2703
[email protected]b172aee2012-04-10 17:05:262704WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562705 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322706}
2707
[email protected]10f417c52011-12-28 21:04:232708NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262709 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322710 return controller_.GetLastCommittedEntry();
2711}
2712
[email protected]b172aee2012-04-10 17:05:262713bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442714 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442715 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322716 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522717
[email protected]420ae012009-04-24 05:16:322718 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442719 if (rwh_view)
2720 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322721
[email protected]74ce1ad2011-12-16 21:51:462722 // Make sure we use the correct starting page_id in the new RenderView.
2723 UpdateMaxPageIDIfNecessary(render_view_host);
2724 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582725 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462726
[email protected]9f76c1e2012-03-05 15:15:582727 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:492728 render_view_host)->CreateRenderView(string16(),
2729 opener_route_id,
2730 max_page_id,
2731 -1)) {
[email protected]a4127722011-04-27 23:13:522732 return false;
[email protected]14392a52012-05-02 20:28:442733 }
[email protected]a4127722011-04-27 23:13:522734
[email protected]e60c0232011-11-11 19:56:352735#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502736 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2737 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442738 if (rwh_view) {
2739 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2740 render_widget_host->WasResized();
2741 }
[email protected]f8233cc2011-05-31 20:24:502742#endif
2743
[email protected]420ae012009-04-24 05:16:322744 return true;
2745}
2746
[email protected]b172aee2012-04-10 17:05:262747void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
2748 IPC::Message* reply_msg,
2749 bool success,
2750 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542751 if (is_showing_before_unload_dialog_ && !success) {
2752 // If a beforeunload dialog is canceled, we need to stop the throbber from
2753 // spinning, since we forced it to start spinning in Navigate.
2754 DidStopLoading();
2755
[email protected]3bbacc5b2012-04-17 17:46:152756 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:542757 }
2758 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582759 static_cast<RenderViewHostImpl*>(
2760 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542761}
2762
[email protected]b172aee2012-04-10 17:05:262763void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122764 encoding_ = content::GetContentClient()->browser()->
2765 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102766}
[email protected]f45d2a72010-03-08 23:28:352767
[email protected]b172aee2012-04-10 17:05:262768void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:462769 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:262770 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142771 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2772 if (!dlm)
2773 return;
2774 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262775 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142776 const NavigationEntry* entry = controller_.GetActiveEntry();
2777 if (entry)
2778 post_id = entry->GetPostID();
2779 }
[email protected]29a5ffc82012-03-13 19:35:582780 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142781 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:142782 scoped_ptr<DownloadUrlParameters> params(
2783 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]20b433a2012-05-15 21:23:462784 // TODO(jochen): Pass in the referrer policy as well.
2785 params->set_referrer(referrer.url);
[email protected]c5a5c0842012-05-04 20:05:142786 params->set_post_id(post_id);
2787 params->set_prefer_cache(true);
2788 if (post_id >= 0)
2789 params->set_method("POST");
2790 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:142791}
2792
[email protected]b172aee2012-04-10 17:05:262793void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212794 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442795 // Can be NULL during tests.
2796 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212797 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362798}
[email protected]9f76c1e2012-03-05 15:15:582799
[email protected]b172aee2012-04-10 17:05:262800RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:582801 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2802}