blob: d5248408acab8d55b725e5d04a8b223271aca783 [file] [log] [blame]
[email protected]7e7414ae2010-01-26 20:19:291// Copyright (c) 2010 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]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]06821f42d2010-05-03 22:34:357#if defined(OS_CHROMEOS)
8// For GdkScreen
9#include <gdk/gdk.h>
10#endif // defined(OS_CHROMEOS)
11
[email protected]a92b8642009-05-05 23:38:5612#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1113#include "app/resource_bundle.h"
[email protected]614519812010-03-19 08:20:5614#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4915#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3216#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0117#include "base/i18n/rtl.h"
[email protected]420ae012009-04-24 05:16:3218#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5419#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3720#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5421#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4522#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2123#include "chrome/browser/autofill/autofill_manager.h"
[email protected]66ba4932009-06-04 19:22:1324#include "chrome/browser/blocked_popup_container.h"
[email protected]420ae012009-04-24 05:16:3225#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]281918912010-05-27 22:05:1326#include "chrome/browser/browser.h"
[email protected]96d185d2009-04-24 03:28:5427#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5528#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1030#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5431#include "chrome/browser/debugger/devtools_manager.h"
[email protected]420ae012009-04-24 05:16:3232#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5433#include "chrome/browser/dom_ui/dom_ui.h"
34#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0235#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3236#include "chrome/browser/download/download_manager.h"
37#include "chrome/browser/download/download_request_manager.h"
[email protected]e7eaedde2009-09-25 20:09:4938#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0839#include "chrome/browser/extensions/extensions_service.h"
[email protected]523623c2010-05-19 16:03:4240#include "chrome/browser/history/top_sites.h"
[email protected]0189bc722009-08-28 21:56:4841#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5342#include "chrome/browser/find_bar_state.h"
[email protected]420ae012009-04-24 05:16:3243#include "chrome/browser/google_util.h"
[email protected]79580c62010-02-02 02:36:2544#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2645#include "chrome/browser/hung_renderer_dialog.h"
[email protected]12f74a92010-02-05 22:32:1446#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3247#include "chrome/browser/load_from_memory_cache_details.h"
48#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4449#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0550#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1051#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5752#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2453#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5754#include "chrome/browser/plugin_installer.h"
[email protected]052313b2010-02-19 09:43:0855#include "chrome/browser/pref_service.h"
[email protected]ce560f82009-06-03 09:39:4456#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0757#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1658#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5459#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3760#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0761#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5462#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3263#include "chrome/browser/renderer_preferences_util.h"
[email protected]152b8ba32010-03-29 19:40:1664#include "chrome/browser/search_engines/template_url_fetcher.h"
65#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1766#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1767#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5468#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1669#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4370#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1671#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]fdd61c62009-04-22 19:22:5772#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0273#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]449478302009-06-09 20:04:2874#include "chrome/browser/thumbnail_store.h"
[email protected]152b8ba32010-03-29 19:40:1675#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5876#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2777#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4978#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5779#include "chrome/common/extensions/extension_action.h"
[email protected]942690b132010-05-11 06:42:1480#include "chrome/common/extensions/extension_resource.h"
[email protected]bfd04a62009-02-01 18:16:5681#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2982#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3283#include "chrome/common/render_messages.h"
[email protected]1ee614862009-07-06 20:29:1884#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5485#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3786#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2687#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3288#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:0689#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:3790#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:3291#include "net/base/mime_util.h"
92#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:2993#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3294#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:1895#include "webkit/glue/password_form.h"
96#include "webkit/glue/webpreferences.h"
[email protected]3e45ba92009-02-20 21:09:0097
[email protected]420ae012009-04-24 05:16:3298// Cross-Site Navigations
99//
100// If a TabContents is told to navigate to a different web site (as determined
101// by SiteInstance), it will replace its current RenderViewHost with a new
102// RenderViewHost dedicated to the new SiteInstance. This works as follows:
103//
104// - Navigate determines whether the destination is cross-site, and if so,
105// it creates a pending_render_view_host_ and moves into the PENDING
106// RendererState.
107// - The pending RVH is "suspended," so that no navigation messages are sent to
108// its renderer until the onbeforeunload JavaScript handler has a chance to
109// run in the current RVH.
110// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
111// that it has a pending cross-site request. ResourceDispatcherHost will
112// check for this when the response arrives.
113// - The current RVH runs its onbeforeunload handler. If it returns false, we
114// cancel all the pending logic and go back to NORMAL. Otherwise we allow
115// the pending RVH to send the navigation request to its renderer.
116// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
117// checks CrossSiteRequestManager to see that the RVH responsible has a
118// pending cross-site request, and then installs a CrossSiteEventHandler.
119// - When RDH receives a response, the BufferedEventHandler determines whether
120// it is a download. If so, it sends a message to the new renderer causing
121// it to cancel the request, and the download proceeds in the download
122// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34123// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32124// doesn't affect any functionality.
125// - After RDH receives a response and determines that it is safe and not a
126// download, it pauses the response to first run the old page's onunload
127// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34128// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32129// to the current RVH.
130// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
131// the ResourceDispatcherHost, who unpauses the response. Data is then sent
132// to the pending RVH.
133// - The pending renderer sends a FrameNavigate message that invokes the
134// DidNavigate method. This replaces the current RVH with the
135// pending RVH and goes back to the NORMAL RendererState.
136
137namespace {
138
139// Amount of time we wait between when a key event is received and the renderer
140// is queried for its state and pushed to the NavigationEntry.
141const int kQueryStateDelay = 5000;
142
143const int kSyncWaitDelay = 40;
144
[email protected]304f8792009-08-19 21:28:09145#if defined(OS_CHROMEOS)
146// If a popup window is bigger than this fraction of the screen on chrome os,
147// turn it into a tab
148const float kMaxWidthFactor = 0.5;
149const float kMaxHeightFactor = 0.6;
150#endif
151
[email protected]420ae012009-04-24 05:16:32152// If another javascript message box is displayed within
153// kJavascriptMessageExpectedDelay of a previous javascript message box being
154// dismissed, display an option to suppress future message boxes from this
155// contents.
156const int kJavascriptMessageExpectedDelay = 1000;
157
[email protected]420ae012009-04-24 05:16:32158// The list of prefs we want to observe.
159const wchar_t* kPrefsToObserve[] = {
160 prefs::kAlternateErrorPagesEnabled,
161 prefs::kWebKitJavaEnabled,
162 prefs::kWebKitJavascriptEnabled,
163 prefs::kWebKitLoadsImagesAutomatically,
164 prefs::kWebKitPluginsEnabled,
165 prefs::kWebKitUsesUniversalDetector,
166 prefs::kWebKitSerifFontFamily,
167 prefs::kWebKitSansSerifFontFamily,
168 prefs::kWebKitFixedFontFamily,
169 prefs::kWebKitDefaultFontSize,
170 prefs::kWebKitDefaultFixedFontSize,
[email protected]1661a3c02010-05-20 16:32:36171 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32172 prefs::kDefaultCharset
173 // kWebKitStandardFontIsSerif needs to be added
174 // if we let users pick which font to use, serif or sans-serif when
175 // no font is specified or a CSS generic family (serif or sans-serif)
176 // is not specified.
177};
178
179const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
180
[email protected]420ae012009-04-24 05:16:32181// Returns true if the entry's transition type is FORM_SUBMIT.
182bool IsFormSubmit(const NavigationEntry* entry) {
183 return (PageTransition::StripQualifier(entry->transition_type()) ==
184 PageTransition::FORM_SUBMIT);
185}
186
187#if defined(OS_WIN)
188
189BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
190 // Note: erase is required to properly paint some widgets borders. This can
191 // be seen with textfields.
192 InvalidateRect(hwnd, NULL, TRUE);
193 return TRUE;
194}
195#endif
196
[email protected]5e369672009-11-03 23:48:30197ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16198 Profile* profile, const NavigationEntry& entry,
199 NavigationController::ReloadType reload_type) {
200 switch (reload_type) {
201 case NavigationController::RELOAD:
202 return ViewMsg_Navigate_Params::RELOAD;
203 case NavigationController::RELOAD_IGNORING_CACHE:
204 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
205 case NavigationController::NO_RELOAD:
206 break; // Fall through to rest of function.
207 }
[email protected]5e369672009-11-03 23:48:30208
209 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
210 profile->DidLastSessionExitCleanly())
211 return ViewMsg_Navigate_Params::RESTORE;
212
213 return ViewMsg_Navigate_Params::NORMAL;
214}
215
[email protected]3cc72b12010-03-18 23:03:00216void MakeNavigateParams(const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16217 NavigationController::ReloadType reload_type,
218 ViewMsg_Navigate_Params* params) {
[email protected]3cc72b12010-03-18 23:03:00219 const NavigationEntry& entry = *controller.pending_entry();
[email protected]056de2d2009-06-26 16:41:34220 params->page_id = entry.page_id();
[email protected]3cc72b12010-03-18 23:03:00221 params->pending_history_list_offset = controller.pending_entry_index();
222 params->current_history_list_offset = controller.last_committed_entry_index();
223 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34224 params->url = entry.url();
225 params->referrer = entry.referrer();
226 params->transition = entry.transition_type();
227 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00228 params->navigation_type =
229 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34230 params->request_time = base::Time::Now();
231}
232
[email protected]420ae012009-04-24 05:16:32233} // namespace
234
235// -----------------------------------------------------------------------------
236
[email protected]fdd61c62009-04-22 19:22:57237// static
238int TabContents::find_request_id_counter_ = -1;
239
[email protected]420ae012009-04-24 05:16:32240
[email protected]420ae012009-04-24 05:16:32241TabContents::TabContents(Profile* profile,
242 SiteInstance* site_instance,
243 int routing_id,
[email protected]34ac70502009-09-25 17:07:23244 const TabContents* base_tab_contents)
[email protected]b680ad22009-04-15 23:19:42245 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13246 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
247 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22248 TabContentsView::Create(this))),
249 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57250 property_bag_(),
251 registrar_(),
[email protected]d82ed61e2009-06-16 02:46:22252 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(*this)),
[email protected]fdd61c62009-04-22 19:22:57253 save_package_(),
[email protected]6db0def92010-03-02 19:55:45254 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21255 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57256 password_manager_(),
257 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06258 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22259 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]fdd61c62009-04-22 19:22:57260 select_file_dialog_(),
[email protected]d5f942ba2008-09-26 19:30:34261 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29262 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34263 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34264 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57265 current_load_start_(),
266 load_state_(net::LOAD_STATE_IDLE),
267 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56268 upload_size_(0),
269 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57270 received_page_title_(false),
271 is_starred_(false),
272 contents_mime_type_(),
273 encoding_(),
[email protected]332af7732009-03-11 13:21:35274 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49275 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47276 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57277 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57278 find_ui_active_(false),
279 find_op_aborted_(false),
280 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12281 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12282 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08283 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57284 capturing_contents_(false),
285 is_being_destroyed_(false),
286 notify_disconnection_(false),
287 history_requests_(),
288#if defined(OS_WIN)
289 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
290#endif
291 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44292 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01293 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54294 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54295 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16296 language_state_(&controller_),
[email protected]0cce15f2010-05-21 16:58:39297 closed_by_user_gesture_(false) {
[email protected]7ff431e2010-01-07 18:18:54298 renderer_preferences_util::UpdateFromSystemSettings(
299 &renderer_preferences_, profile);
300
[email protected]9fb83e82010-07-02 18:24:55301 content_settings_delegate_.reset(
302 new TabSpecificContentSettings(this, profile));
303
[email protected]16779842009-07-08 23:45:29304#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02305 // Make sure the thumbnailer is started before starting the render manager.
306 // The thumbnailer will want to listen for RVH creations, one of which will
307 // happen in RVHManager::Init.
308 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
309 if (generator)
310 generator->StartThumbnailing();
311#endif
312
[email protected]12636df2009-09-28 22:32:21313 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32314
[email protected]34ac70502009-09-25 17:07:23315 // We have the initial size of the view be based on the size of the passed in
316 // tab contents (normally a tab from the same window).
317 view_->CreateView(base_tab_contents ?
318 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32319
320 // Register for notifications about all interested prefs change.
321 PrefService* prefs = profile->GetPrefs();
322 if (prefs) {
323 for (int i = 0; i < kPrefsToObserveLength; ++i)
324 prefs->AddPrefObserver(kPrefsToObserve[i], this);
325 }
326
327 // Register for notifications about URL starredness changing on any profile.
328 registrar_.Add(this, NotificationType::URLS_STARRED,
329 NotificationService::AllSources());
330 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
331 NotificationService::AllSources());
332 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
333 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09334#if defined(OS_LINUX)
335 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
336 NotificationService::AllSources());
337#endif
[email protected]420ae012009-04-24 05:16:32338
[email protected]6c32ce72010-03-08 05:18:06339 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
340 NotificationService::AllSources());
341
[email protected]79580c62010-02-02 02:36:25342 // Register for notifications about content setting changes.
343 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
344 NotificationService::AllSources());
345
[email protected]a888b29e62010-04-01 13:38:57346 // Listen for extension changes so we can update extension_for_current_page_.
347 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
348 NotificationService::AllSources());
349 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
350 NotificationService::AllSources());
351 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
352 NotificationService::AllSources());
353
[email protected]c8865482009-07-23 20:40:10354 // Set-up the showing of the omnibox search infobar if applicable.
355 if (OmniboxSearchHint::IsEnabled(profile))
356 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35357}
initial.commit09911bf2008-07-26 23:55:29358
359TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32360 is_being_destroyed_ = true;
361
[email protected]bfe4c1582009-10-02 18:11:09362 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32363 registrar_.RemoveAll();
364
365 // Unregister the notifications of all observed prefs change.
366 PrefService* prefs = profile()->GetPrefs();
367 if (prefs) {
368 for (int i = 0; i < kPrefsToObserveLength; ++i)
369 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
370 }
371
[email protected]420ae012009-04-24 05:16:32372 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00373 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32374
[email protected]420ae012009-04-24 05:16:32375 // First cleanly close all child windows.
376 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
377 // some of these to close. CloseWindows is async, so it might get called
378 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49379 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32380
[email protected]8cc8d492010-02-02 10:40:49381 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13382 if (blocked_popups_)
383 blocked_popups_->Destroy();
384
[email protected]420ae012009-04-24 05:16:32385 // Notify any observer that have a reference on this tab contents.
386 NotificationService::current()->Notify(
387 NotificationType::TAB_CONTENTS_DESTROYED,
388 Source<TabContents>(this),
389 NotificationService::NoDetails());
390
[email protected]1e5e74f2009-05-27 20:55:12391 // Notify any lasting InfobarDelegates that have not yet been removed that
392 // whatever infobar they were handling in this TabContents has closed,
393 // because the TabContents is going away entirely.
394 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
395 // notification may trigger infobars calls that access their delegate. (and
396 // some implementations of InfoBarDelegate do delete themselves on
397 // InfoBarClosed()).
398 for (int i = 0; i < infobar_delegate_count(); ++i) {
399 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
400 delegate->InfoBarClosed();
401 }
402 infobar_delegates_.clear();
403
[email protected]420ae012009-04-24 05:16:32404 // TODO(brettw) this should be moved to the view.
405#if defined(OS_WIN)
406 // If we still have a window handle, destroy it. GetNativeView can return
407 // NULL if this contents was part of a window that closed.
408 if (GetNativeView())
409 ::DestroyWindow(GetNativeView());
410#endif
[email protected]7ab1e7d62009-10-14 23:32:01411
412 // OnCloseStarted isn't called in unit tests.
413 if (!tab_close_start_time_.is_null()) {
414 UMA_HISTOGRAM_TIMES("Tab.Close",
415 base::TimeTicks::Now() - tab_close_start_time_);
416 }
initial.commit09911bf2008-07-26 23:55:29417}
418
[email protected]d5f942ba2008-09-26 19:30:34419// static
420void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32421 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
422
423 WebPreferences pref_defaults;
424 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
425 pref_defaults.javascript_enabled);
426 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
427 pref_defaults.web_security_enabled);
428 prefs->RegisterBooleanPref(
429 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
430 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
431 pref_defaults.loads_images_automatically);
432 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
433 pref_defaults.plugins_enabled);
434 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
435 pref_defaults.dom_paste_enabled);
436 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
437 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14438 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32439 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
440 pref_defaults.text_areas_are_resizable);
441 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
442 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36443 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
444 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32445
446 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
447 IDS_ACCEPT_LANGUAGES);
448 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
449 IDS_DEFAULT_ENCODING);
450 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
451 IDS_STANDARD_FONT_IS_SERIF);
452 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
453 IDS_FIXED_FONT_FAMILY);
454 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
455 IDS_SERIF_FONT_FAMILY);
456 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
457 IDS_SANS_SERIF_FONT_FAMILY);
458 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
459 IDS_CURSIVE_FONT_FAMILY);
460 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
461 IDS_FANTASY_FONT_FAMILY);
462 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
463 IDS_DEFAULT_FONT_SIZE);
464 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
465 IDS_DEFAULT_FIXED_FONT_SIZE);
466 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
467 IDS_MINIMUM_FONT_SIZE);
468 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
469 IDS_MINIMUM_LOGICAL_FONT_SIZE);
470 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
471 IDS_USES_UNIVERSAL_DETECTOR);
472 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
473 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29474}
475
[email protected]13367f72009-07-08 16:39:02476// Returns true if contains content rendered by an extension.
477bool TabContents::HostsExtension() const {
478 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34479}
480
[email protected]cf28ec52010-04-09 22:56:34481AutoFillManager* TabContents::GetAutoFillManager() {
482 if (autofill_manager_.get() == NULL)
483 autofill_manager_.reset(new AutoFillManager(this));
484 return autofill_manager_.get();
485}
486
[email protected]6e95706d2009-04-23 22:55:01487PasswordManager* TabContents::GetPasswordManager() {
488 if (password_manager_.get() == NULL)
489 password_manager_.reset(new PasswordManager(this));
490 return password_manager_.get();
491}
492
493PluginInstaller* TabContents::GetPluginInstaller() {
494 if (plugin_installer_.get() == NULL)
495 plugin_installer_.reset(new PluginInstaller(this));
496 return plugin_installer_.get();
497}
498
[email protected]8cb5d5b2010-02-09 11:36:16499RenderProcessHost* TabContents::GetRenderProcessHost() const {
500 return render_manager_.current_host()->process();
501}
502
[email protected]98aa0b52010-05-06 17:03:08503void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46504 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08505 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10506
[email protected]98aa0b52010-05-06 17:03:08507 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57508
[email protected]fca656c2010-02-10 20:30:10509 NotificationService::current()->Notify(
510 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
511 Source<TabContents>(this),
512 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49513}
514
[email protected]98aa0b52010-05-06 17:03:08515void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
516 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40517 return;
518
519 ExtensionsService* extension_service = profile()->GetExtensionsService();
520 if (extension_service && extension_service->is_ready()) {
521 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08522 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40523 if (extension)
[email protected]98aa0b52010-05-06 17:03:08524 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40525 }
526}
527
[email protected]98aa0b52010-05-06 17:03:08528SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]8eb043b2010-04-30 07:19:51529 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because
530 // for those windows, we already have a big icon in the top-left outside any
531 // tab. Having big tab icons too looks kinda redonk.
[email protected]06821f42d2010-05-03 22:34:35532 Browser* browser = delegate_ ? delegate_->GetBrowser() : NULL;
533 if (browser && browser->type() == Browser::TYPE_EXTENSION_APP)
[email protected]8eb043b2010-04-30 07:19:51534 return NULL;
[email protected]8eb043b2010-04-30 07:19:51535
[email protected]98aa0b52010-05-06 17:03:08536 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51537 return NULL;
538
[email protected]98aa0b52010-05-06 17:03:08539 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51540}
541
[email protected]d5f942ba2008-09-26 19:30:34542const GURL& TabContents::GetURL() const {
543 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57544 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54545 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34546}
547
[email protected]96d185d2009-04-24 03:28:54548const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55549 // Transient entries take precedence. They are used for interstitial pages
550 // that are shown on top of existing pages.
551 NavigationEntry* entry = controller_.GetTransientEntry();
552 if (entry)
553 return entry->GetTitleForDisplay(&controller_);
554
[email protected]96d185d2009-04-24 03:28:54555 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
556 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
557 if (our_dom_ui) {
558 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55559 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54560 if (!(entry && entry->IsViewSourceMode())) {
561 // Give the DOM UI the chance to override our title.
562 const string16& title = our_dom_ui->overridden_title();
563 if (!title.empty())
564 return title;
565 }
566 }
567
568 // We use the title for the last committed entry rather than a pending
569 // navigation entry. For example, when the user types in a URL, we want to
570 // keep the old page's title until the new load has committed and we get a new
571 // title.
[email protected]96d185d2009-04-24 03:28:54572 entry = controller_.GetLastCommittedEntry();
573 if (entry)
574 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54575 return EmptyString16();
576}
577
[email protected]bbbc1ef2010-02-12 18:03:41578// static
579string16 TabContents::GetDefaultTitle() {
580 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
581}
582
[email protected]d5f942ba2008-09-26 19:30:34583int32 TabContents::GetMaxPageID() {
584 if (GetSiteInstance())
585 return GetSiteInstance()->max_page_id();
586 else
587 return max_page_id_;
588}
589
590void TabContents::UpdateMaxPageID(int32 page_id) {
591 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34592 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34593 // testing.
594 if (GetSiteInstance())
595 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16596 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34597}
598
[email protected]96d185d2009-04-24 03:28:54599SiteInstance* TabContents::GetSiteInstance() const {
600 return render_manager_.current_host()->site_instance();
601}
602
[email protected]96d185d2009-04-24 03:28:54603bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15604 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54605 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15606 if (entry && (entry->IsViewSourceMode() ||
607 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54608 return true;
[email protected]8ab24cc2009-11-13 20:56:15609 }
[email protected]83e3895b2009-06-11 00:07:16610
[email protected]96d185d2009-04-24 03:28:54611 DOMUI* dom_ui = GetDOMUIForCurrentState();
612 if (dom_ui)
613 return !dom_ui->should_hide_url();
614 return true;
615}
616
[email protected]d5f942ba2008-09-26 19:30:34617SkBitmap TabContents::GetFavIcon() const {
618 // Like GetTitle(), we also want to use the favicon for the last committed
619 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57620 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47621 if (entry)
622 return entry->favicon().bitmap();
623
[email protected]ce3fa3c2009-04-20 19:55:57624 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34625 if (entry)
626 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34627 return SkBitmap();
628}
629
[email protected]0b303cc2009-09-28 22:35:15630bool TabContents::FavIconIsValid() const {
631 NavigationEntry* entry = controller_.GetTransientEntry();
632 if (entry)
633 return entry->favicon().is_valid();
634
635 entry = controller_.GetLastCommittedEntry();
636 if (entry)
637 return entry->favicon().is_valid();
638
639 return false;
640}
641
[email protected]96d185d2009-04-24 03:28:54642bool TabContents::ShouldDisplayFavIcon() {
643 // Always display a throbber during pending loads.
644 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
645 return true;
646
647 DOMUI* dom_ui = GetDOMUIForCurrentState();
648 if (dom_ui)
649 return !dom_ui->hide_favicon();
650 return true;
651}
652
[email protected]96d185d2009-04-24 03:28:54653std::wstring TabContents::GetStatusText() const {
654 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
655 return std::wstring();
656
657 switch (load_state_) {
658 case net::LOAD_STATE_WAITING_FOR_CACHE:
659 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04660 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
661 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54662 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
663 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
664 case net::LOAD_STATE_RESOLVING_HOST:
665 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
666 case net::LOAD_STATE_CONNECTING:
667 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06668 case net::LOAD_STATE_SSL_HANDSHAKE:
669 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54670 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56671 if (upload_size_)
672 return l10n_util::GetStringF(
673 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
674 static_cast<int>((100 * upload_position_) / upload_size_));
675 else
676 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54677 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
678 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
679 load_state_host_);
680 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
681 case net::LOAD_STATE_IDLE:
682 case net::LOAD_STATE_READING_RESPONSE:
683 break;
684 }
685
686 return std::wstring();
687}
688
[email protected]d5f942ba2008-09-26 19:30:34689void TabContents::SetIsCrashed(bool state) {
690 if (state == is_crashed_)
691 return;
692
693 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50694 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34695}
696
[email protected]744ef172009-10-16 21:53:46697void TabContents::PageActionStateChanged() {
698 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00699}
[email protected]ce5c4502009-05-06 16:46:11700
[email protected]d5f942ba2008-09-26 19:30:34701void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
702 if (delegate_)
703 delegate_->NavigationStateChanged(this, changed_flags);
704}
705
[email protected]96d185d2009-04-24 03:28:54706void TabContents::DidBecomeSelected() {
707 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16708 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
709 if (rwhv) {
710 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43711#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16712 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43713#endif
714 }
[email protected]96d185d2009-04-24 03:28:54715
[email protected]8cb5d5b2010-02-09 11:36:16716 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54717}
718
719void TabContents::WasHidden() {
720 if (!capturing_contents()) {
721 // |render_view_host()| can be NULL if the user middle clicks a link to open
722 // a tab in then background, then closes the tab before selecting it. This
723 // is because closing the tab calls TabContents::Destroy(), which removes
724 // the |render_view_host()|; then when we actually destroy the window,
725 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16726 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
727 if (rwhv)
728 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54729 }
730
731 NotificationService::current()->Notify(
732 NotificationType::TAB_CONTENTS_HIDDEN,
733 Source<TabContents>(this),
734 NotificationService::NoDetails());
735}
736
[email protected]d5f942ba2008-09-26 19:30:34737void TabContents::Activate() {
738 if (delegate_)
739 delegate_->ActivateContents(this);
740}
741
[email protected]96d185d2009-04-24 03:28:54742void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16743 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
744 if (rwhv)
745 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54746}
747
748void TabContents::HideContents() {
749 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
750 // our superclass HideContents(), because some callers want to be very picky
751 // about the order in which these get called. In addition to making the code
752 // here practically impossible to understand, this also means we end up
753 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34754 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54755 WasHidden();
756}
757
[email protected]c0588052008-10-27 23:01:50758void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34759 WindowOpenDisposition disposition,
760 PageTransition::Type transition) {
761 if (delegate_)
[email protected]c0588052008-10-27 23:01:50762 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34763}
764
[email protected]1ccb3568d2010-02-19 10:51:16765bool TabContents::NavigateToPendingEntry(
766 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54767 const NavigationEntry& entry = *controller_.pending_entry();
768
769 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
770 if (!dest_render_view_host)
771 return false; // Unable to create the desired render view host.
772
[email protected]770dd8b2010-05-24 18:11:39773 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
774 dest_render_view_host->EnablePreferredSizeChangedMode(
775 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
776 }
[email protected]9fb325e2010-05-06 18:23:24777
[email protected]0352e5472010-04-29 00:11:40778 // For security, we should never send non-DOM-UI URLs (other than about:blank)
779 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58780 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40781 bool is_allowed_in_dom_ui_renderer =
782 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
783 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58784 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40785 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58786
[email protected]96d185d2009-04-24 03:28:54787 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12788 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32789 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00790 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
791 dest_render_view_host,
792 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32793 }
[email protected]96d185d2009-04-24 03:28:54794
795 // Used for page load time metrics.
796 current_load_start_ = base::TimeTicks::Now();
797
798 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34799 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00800 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34801 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54802
803 if (entry.page_id() == -1) {
804 // HACK!! This code suppresses javascript: URLs from being added to
805 // session history, which is what we want to do for javascript: URLs that
806 // do not generate content. What we really need is a message from the
807 // renderer telling us that a new page was not created. The same message
808 // could be used for mailto: URLs and the like.
809 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
810 return false;
811 }
812
813 // Clear any provisional password saves - this stops password infobars
814 // showing up on pages the user navigates to while the right page is
815 // loading.
816 GetPasswordManager()->ClearProvisionalSave();
817
[email protected]1ccb3568d2010-02-19 10:51:16818 if (reload_type != NavigationController::NO_RELOAD &&
819 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48820 FaviconService* favicon_service =
821 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
822 if (favicon_service)
823 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54824 }
825
[email protected]d5f942ba2008-09-26 19:30:34826 return true;
827}
828
[email protected]96d185d2009-04-24 03:28:54829void TabContents::Stop() {
830 render_manager_.Stop();
831 printing_.Stop();
832}
833
[email protected]96d185d2009-04-24 03:28:54834void TabContents::DisassociateFromPopupCount() {
835 render_view_host()->DisassociateFromPopupCount();
836}
837
838TabContents* TabContents::Clone() {
839 // We create a new SiteInstance so that the new tab won't share processes
840 // with the old one. This can be changed in the future if we need it to share
841 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32842 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54843 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21844 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54845 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08846 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08847 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54848 return tc;
849}
850
[email protected]4d677202009-07-19 07:37:12851void TabContents::ShowPageInfo(const GURL& url,
852 const NavigationEntry::SSLStatus& ssl,
853 bool show_history) {
854 if (!delegate_)
855 return;
856
[email protected]bb678332009-07-21 00:15:50857 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12858}
859
initial.commit09911bf2008-07-26 23:55:29860ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28861 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29862 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28863 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29864 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44865
866 if (child_windows_.size() == 1) {
867 window->ShowConstrainedWindow();
868 BlockTabContent(true);
869 }
870
initial.commit09911bf2008-07-26 23:55:29871 return window;
872}
873
[email protected]fa1cf0b82010-01-15 21:49:44874void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55875 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
876 if (rwhv)
877 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44878 render_view_host()->set_ignore_input_events(blocked);
879 if (delegate_)
880 delegate_->SetTabContentBlocked(this, blocked);
881}
882
initial.commit09911bf2008-07-26 23:55:29883void TabContents::AddNewContents(TabContents* new_contents,
884 WindowOpenDisposition disposition,
885 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29886 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29887 if (!delegate_)
888 return;
889
[email protected]35f7d212009-04-29 21:19:27890 if ((disposition == NEW_POPUP) && !user_gesture &&
891 !CommandLine::ForCurrentProcess()->HasSwitch(
892 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22893 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31894 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29895 delegate_->GetConstrainingContents(this)->AddPopup(
896 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31897 } else {
[email protected]304f8792009-08-19 21:28:09898#if defined(OS_CHROMEOS)
899 if (disposition == NEW_POPUP) {
900 // If the popup is bigger than a given factor of the screen, then
901 // turn it into a foreground tab (on chrome os only)
902 GdkScreen* screen = gdk_screen_get_default();
903 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
904 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
905 if (initial_pos.width() > max_width ||
906 initial_pos.height() > max_height) {
907 disposition = NEW_FOREGROUND_TAB;
908 }
909 }
910#endif
911
[email protected]0aa55312008-10-17 21:53:08912 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29913 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
914 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49915 NotificationService::current()->Notify(
916 NotificationType::TAB_ADDED,
917 Source<TabContentsDelegate>(delegate_),
918 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29919 }
initial.commit09911bf2008-07-26 23:55:29920
[email protected]8cc8d492010-02-02 10:40:49921 // TODO(pkasting): Why is this necessary?
922 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:29923}
924
[email protected]bcd9dc42010-01-23 16:38:18925bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:20926 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:20927 bool is_js_code, const std::string& code_string,
928 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51929 RenderViewHost* host = render_view_host();
930 if (!host)
931 return false;
932
933 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
934 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
935 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35936}
937
[email protected]96d185d2009-04-24 03:28:54938void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49939 if (is_being_destroyed_)
940 return;
[email protected]9fb83e82010-07-02 18:24:55941 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49942 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40943 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:54944}
945
[email protected]5c9e97a2009-09-09 23:48:30946gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54947 return view_->GetContentNativeView();
948}
949
950gfx::NativeView TabContents::GetNativeView() const {
951 return view_->GetNativeView();
952}
953
954void TabContents::GetContainerBounds(gfx::Rect *out) const {
955 view_->GetContainerBounds(out);
956}
957
958void TabContents::Focus() {
959 view_->Focus();
960}
961
[email protected]90daadb42009-06-08 21:27:28962void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54963 if (showing_interstitial_page()) {
964 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
965 return;
966 }
[email protected]96d185d2009-04-24 03:28:54967 render_view_host()->SetInitialFocus(reverse);
968}
969
970bool TabContents::FocusLocationBarByDefault() {
971 DOMUI* dom_ui = GetDOMUIForCurrentState();
972 if (dom_ui)
973 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43974 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25975 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43976 return true;
[email protected]96d185d2009-04-24 03:28:54977 return false;
978}
979
[email protected]a26dc362010-04-23 01:48:58980void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38981 if (delegate())
[email protected]a26dc362010-04-23 01:48:58982 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38983}
984
[email protected]616ed5a2008-11-21 22:27:24985void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32986 if (delegate_ && !delegate_->infobars_enabled()) {
987 delegate->InfoBarClosed();
988 return;
989 }
990
[email protected]616ed5a2008-11-21 22:27:24991 // Look through the existing InfoBarDelegates we have for a match. If we've
992 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:05993 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:45994 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
995 // Tell the new infobar to close so that it can clean itself up.
996 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:24997 return;
[email protected]6d27a7b2009-12-18 23:25:45998 }
[email protected]616ed5a2008-11-21 22:27:24999 }
1000
1001 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561002 NotificationService::current()->Notify(
1003 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1004 Source<TabContents>(this),
1005 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241006
1007 // Add ourselves as an observer for navigations the first time a delegate is
1008 // added. We use this notification to expire InfoBars that need to expire on
1009 // page transitions.
1010 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561011 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571012 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241013 }
1014}
1015
1016void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321017 if (delegate_ && !delegate_->infobars_enabled()) {
1018 return;
1019 }
1020
[email protected]616ed5a2008-11-21 22:27:241021 std::vector<InfoBarDelegate*>::iterator it =
1022 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1023 if (it != infobar_delegates_.end()) {
1024 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561025 NotificationService::current()->Notify(
1026 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1027 Source<TabContents>(this),
1028 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:051029 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:241030
[email protected]6a02963e2009-01-06 16:58:031031 // Remove ourselves as an observer if we are tracking no more InfoBars.
1032 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:561033 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571034 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031035 }
[email protected]616ed5a2008-11-21 22:27:241036 }
1037}
[email protected]3edd9522009-03-04 22:19:411038
[email protected]f81821c2009-08-07 01:29:471039void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1040 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321041 if (delegate_ && !delegate_->infobars_enabled()) {
1042 new_delegate->InfoBarClosed();
1043 return;
1044 }
1045
[email protected]f81821c2009-08-07 01:29:471046 std::vector<InfoBarDelegate*>::iterator it =
1047 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1048 DCHECK(it != infobar_delegates_.end());
1049
1050 // Notify the container about the change of plans.
1051 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1052 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1053 old_delegate, new_delegate));
1054 NotificationService::current()->Notify(
1055 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1056 Source<TabContents>(this),
1057 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1058
1059 // Remove the old one.
1060 infobar_delegates_.erase(it);
1061
1062 // Add the new one.
1063 infobar_delegates_.push_back(new_delegate);
1064}
1065
[email protected]20ede072009-10-06 00:28:351066bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271067 if (showing_interstitial_page())
1068 return false;
1069
[email protected]96d185d2009-04-24 03:28:541070 // See GetDOMUIForCurrentState() comment for more info. This case is very
1071 // similar, but for non-first loads, we want to use the committed entry. This
1072 // is so the bookmarks bar disappears at the same time the page does.
1073 if (controller_.GetLastCommittedEntry()) {
1074 // Not the first load, always use the committed DOM UI.
1075 if (render_manager_.dom_ui())
1076 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1077 return false; // Default.
1078 }
1079
1080 // When it's the first load, we know either the pending one or the committed
1081 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1082 // of them will be valid, so we can just check both.
1083 if (render_manager_.pending_dom_ui())
1084 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1085 if (render_manager_.dom_ui())
1086 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1087 return false; // Default.
1088}
1089
[email protected]d8f16ae2009-08-30 03:47:261090bool TabContents::IsExtensionShelfAlwaysVisible() {
1091 // See GetDOMUIForCurrentState() comment for more info. This case is very
1092 // similar, but for non-first loads, we want to use the committed entry. This
1093 // is so the bookmarks bar disappears at the same time the page does.
1094 if (controller_.GetLastCommittedEntry()) {
1095 // Not the first load, always use the committed DOM UI.
1096 if (render_manager_.dom_ui())
1097 return render_manager_.dom_ui()->force_extension_shelf_visible();
1098 return false; // Default.
1099 }
1100
1101 // When it's the first load, we know either the pending one or the committed
1102 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1103 // of them will be valid, so we can just check both.
1104 if (render_manager_.pending_dom_ui())
1105 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
1106 if (render_manager_.dom_ui())
1107 return render_manager_.dom_ui()->force_extension_shelf_visible();
1108 return false; // Default.
1109}
1110
[email protected]3edd9522009-03-04 22:19:411111void TabContents::ToolbarSizeChanged(bool is_animating) {
1112 TabContentsDelegate* d = delegate();
1113 if (d)
1114 d->ToolbarSizeChanged(this, is_animating);
1115}
[email protected]616ed5a2008-11-21 22:27:241116
[email protected]fc6fb7fb2009-11-07 02:35:041117bool TabContents::CanDownload(int request_id) {
1118 TabContentsDelegate* d = delegate();
1119 if (d)
1120 return d->CanDownload(request_id);
1121 return true;
1122}
1123
[email protected]d5f942ba2008-09-26 19:30:341124void TabContents::OnStartDownload(DownloadItem* download) {
1125 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341126
1127 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311128 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341129
[email protected]c70f9b82010-04-21 07:31:111130 if (tab_contents && tab_contents->delegate()) {
[email protected]59560e0b2009-06-04 03:30:221131 tab_contents->delegate()->OnStartDownload(download);
[email protected]c70f9b82010-04-21 07:31:111132 // If the download occurs in a new tab, close it
1133 if (controller_.IsInitialNavigation() && (tab_contents == this))
1134 delegate()->CloseContents(this);
1135 }
[email protected]3edd9522009-03-04 22:19:411136}
[email protected]3edd9522009-03-04 22:19:411137
[email protected]d5f942ba2008-09-26 19:30:341138void TabContents::WillClose(ConstrainedWindow* window) {
1139 ConstrainedWindowList::iterator it =
1140 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441141 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341142 if (it != child_windows_.end())
1143 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371144 if (child_windows_.size() > 0) {
1145 if (removed_topmost_window) {
1146 child_windows_[0]->ShowConstrainedWindow();
1147 }
[email protected]fa1cf0b82010-01-15 21:49:441148 BlockTabContent(true);
1149 } else {
1150 BlockTabContent(false);
1151 }
[email protected]66ba4932009-06-04 19:22:131152}
[email protected]d5f942ba2008-09-26 19:30:341153
[email protected]66ba4932009-06-04 19:22:131154void TabContents::WillCloseBlockedPopupContainer(
1155 BlockedPopupContainer* container) {
1156 DCHECK(blocked_popups_ == container);
1157 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491158 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341159}
1160
[email protected]d5f942ba2008-09-26 19:30:341161void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351162#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061163 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351164#endif
[email protected]d5f942ba2008-09-26 19:30:341165}
1166
[email protected]c1dc9f132009-11-20 23:13:211167void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121168 bool forward_direction,
1169 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211170 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011171 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211172 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531173 string16 last_search_prepopulate_text =
1174 FindBarState::GetLastPrepopulateText(profile());
1175
[email protected]87fae512009-12-11 02:20:211176 // Try the last thing we searched for on this tab, then the last thing
1177 // searched for on any tab.
1178 if (!previous_find_text_.empty())
1179 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531180 else if (!last_search_prepopulate_text.empty())
1181 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211182 else
[email protected]e491f1c2009-05-22 20:28:121183 return;
[email protected]e491f1c2009-05-22 20:28:121184 }
[email protected]6e95706d2009-04-23 22:55:011185
[email protected]101c90e2009-10-26 21:14:441186 // Keep track of the previous search.
1187 previous_find_text_ = find_text_;
1188
[email protected]6e95706d2009-04-23 22:55:011189 // This is a FindNext operation if we are searching for the same text again,
1190 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1191 // exception to this is if the Find was aborted (then we don't want FindNext
1192 // because the highlighting has been cleared and we need it to reappear). We
1193 // therefore treat FindNext after an aborted Find operation as a full fledged
1194 // Find.
[email protected]c1dc9f132009-11-20 23:13:211195 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121196 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011197 !find_op_aborted_;
1198 if (!find_next)
1199 current_find_request_id_ = find_request_id_counter_++;
1200
[email protected]c1dc9f132009-11-20 23:13:211201 if (!search_string.empty())
1202 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121203 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011204
1205 find_op_aborted_ = false;
1206
1207 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531208 FindBarState* find_bar_state = profile()->GetFindBarState();
1209 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011210 render_view_host()->StartFinding(current_find_request_id_,
1211 find_text_,
1212 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121213 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011214 find_next);
1215}
1216
[email protected]5bc8fe92010-03-11 18:19:001217void TabContents::StopFinding(
1218 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011219 if (selection_action == FindBarController::kClearSelection) {
1220 // kClearSelection means the find string has been cleared by the user, but
1221 // the UI has not been dismissed. In that case we want to clear the
1222 // previously remembered search (http://crbug.com/42639).
1223 previous_find_text_ = string16();
1224 } else {
[email protected]2d2dffc2009-06-09 21:41:001225 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011226 if (!find_text_.empty())
1227 previous_find_text_ = find_text_;
1228 }
[email protected]101c90e2009-10-26 21:14:441229 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011230 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121231 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001232 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011233}
1234
[email protected]420ae012009-04-24 05:16:321235void TabContents::OnSavePage() {
1236 // If we can not save the page, try to download it.
1237 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1238 DownloadManager* dlm = profile()->GetDownloadManager();
1239 const GURL& current_page_url = GetURL();
1240 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221241 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321242 return;
1243 }
1244
1245 Stop();
1246
1247 // Create the save package and possibly prompt the user for the name to save
1248 // the page as. The user prompt is an asynchronous operation that runs on
1249 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221250 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321251 save_package_->GetSaveInfo();
1252}
1253
1254// Used in automated testing to bypass prompting the user for file names.
1255// Instead, the names and paths are hard coded rather than running them through
1256// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111257bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321258 SavePackage::SavePackageType save_type) {
1259 // Stop the page from navigating.
1260 Stop();
1261
[email protected]828cabe2009-09-26 22:47:111262 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591263 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321264}
1265
[email protected]89d6e6e2009-12-03 23:06:511266void TabContents::EmailPageLocation() {
1267 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1268 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1269 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1270 title + "&body=%0A%0A" + page_url;
1271 platform_util::OpenExternal(GURL(mailto));
1272}
1273
[email protected]420ae012009-04-24 05:16:321274void TabContents::PrintPreview() {
1275 // We don't show the print preview yet, only the print dialog.
1276 PrintNow();
1277}
1278
1279bool TabContents::PrintNow() {
1280 // We can't print interstitial page for now.
1281 if (showing_interstitial_page())
1282 return false;
1283
1284 return render_view_host()->PrintPages();
1285}
1286
[email protected]82270452009-06-19 15:58:011287void TabContents::PrintingDone(int document_cookie, bool success) {
1288 render_view_host()->PrintingDone(document_cookie, success);
1289}
1290
[email protected]420ae012009-04-24 05:16:321291bool TabContents::IsActiveEntry(int32 page_id) {
1292 NavigationEntry* active_entry = controller_.GetActiveEntry();
1293 return (active_entry != NULL &&
1294 active_entry->site_instance() == GetSiteInstance() &&
1295 active_entry->page_id() == page_id);
1296}
1297
[email protected]b2fe07d12010-02-09 14:38:081298void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161299 set_encoding(encoding);
1300 render_view_host()->SetPageEncoding(encoding);
1301}
1302
[email protected]b2fe07d12010-02-09 14:38:081303void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161304 reset_encoding();
1305 render_view_host()->ResetPageEncodingToDefault();
1306}
1307
1308void TabContents::WindowMoveOrResizeStarted() {
1309 render_view_host()->WindowMoveOrResizeStarted();
1310}
1311
[email protected]3f8eb7f2009-10-02 23:58:051312void TabContents::LogNewTabTime(const std::string& event_name) {
1313 // Not all new tab pages get timed. In those cases, we don't have a
1314 // new_tab_start_time_.
1315 if (new_tab_start_time_.is_null())
1316 return;
1317
1318 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441319 MetricEventDurationDetails details(event_name,
1320 static_cast<int>(duration.InMilliseconds()));
1321
[email protected]7ab1e7d62009-10-14 23:32:011322 if (event_name == "Tab.NewTabScriptStart") {
1323 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1324 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1325 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1326 } else if (event_name == "Tab.NewTabOnload") {
1327 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051328 // The new tab page has finished loading; reset it.
1329 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441330 } else {
1331 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051332 }
[email protected]84abba62009-10-07 17:01:441333 NotificationService::current()->Notify(
1334 NotificationType::METRIC_EVENT_DURATION,
1335 Source<TabContents>(this),
1336 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051337}
1338
[email protected]7ab1e7d62009-10-14 23:32:011339void TabContents::OnCloseStarted() {
1340 if (tab_close_start_time_.is_null())
1341 tab_close_start_time_ = base::TimeTicks::Now();
1342}
1343
[email protected]46624bf2010-06-09 16:04:191344bool TabContents::ShouldAcceptDragAndDrop() const {
1345#if defined(OS_CHROMEOS)
1346 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1347 // See http://crosbug.com/2413
1348 return delegate() && !delegate()->IsPopup(const_cast<TabContents*>(this));
1349#else
1350 return true;
1351#endif
1352}
1353
[email protected]c37e3b62010-01-22 00:15:171354TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171355 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161356
1357 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081358 if (extension_app_)
1359 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161360 else if (entry)
1361 tab_nav.SetFromNavigationEntry(*entry);
1362
[email protected]c37e3b62010-01-22 00:15:171363 std::vector<TabNavigation> navigations;
1364 navigations.push_back(tab_nav);
1365
1366 TabContents* new_contents =
1367 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081368 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171369 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171370
[email protected]98aa0b52010-05-06 17:03:081371 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161372 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1373
[email protected]c37e3b62010-01-22 00:15:171374 return new_contents;
1375}
1376
[email protected]96d185d2009-04-24 03:28:541377// Notifies the RenderWidgetHost instance about the fact that the page is
1378// loading, or done loading and calls the base implementation.
1379void TabContents::SetIsLoading(bool is_loading,
1380 LoadNotificationDetails* details) {
1381 if (is_loading == is_loading_)
1382 return;
1383
1384 if (!is_loading) {
1385 load_state_ = net::LOAD_STATE_IDLE;
1386 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561387 upload_size_ = 0;
1388 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541389 }
1390
1391 render_manager_.SetIsLoading(is_loading);
1392
1393 is_loading_ = is_loading;
1394 waiting_for_response_ = is_loading;
1395
1396 if (delegate_)
1397 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351398 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541399
1400 NotificationType type = is_loading ? NotificationType::LOAD_START :
1401 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111402 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541403 if (details)
1404 det = Details<LoadNotificationDetails>(details);
1405 NotificationService::current()->Notify(type,
1406 Source<NavigationController>(&controller_),
1407 det);
1408}
1409
[email protected]b6c874582009-05-08 19:38:311410void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291411 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061412 // A page can't spawn popups (or do anything else, either) until its load
1413 // commits, so when we reach here, the popup was spawned by the
1414 // NavigationController's last committed entry, not the active entry. For
1415 // example, if a page opens a popup in an onunload() handler, then the active
1416 // entry is the page to be loaded as we navigate away from the unloading
1417 // page. For this reason, we can't use GetURL() to get the opener URL,
1418 // because it returns the active entry.
1419 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1420 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1421
1422 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491423 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]57eda82a2010-05-05 21:28:061424 creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491425 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1426 } else {
1427 if (!blocked_popups_)
1428 blocked_popups_ = new BlockedPopupContainer(this);
1429 blocked_popups_->AddTabContents(new_contents, initial_pos);
[email protected]9fb83e82010-07-02 18:24:551430 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS);
[email protected]8cc8d492010-02-02 10:40:491431 }
[email protected]b9681312008-11-07 00:08:261432}
[email protected]616ed5a2008-11-21 22:27:241433
1434namespace {
1435bool TransitionIsReload(PageTransition::Type transition) {
1436 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1437}
1438}
1439
1440void TabContents::ExpireInfoBars(
1441 const NavigationController::LoadCommittedDetails& details) {
1442 // Only hide InfoBars when the user has done something that makes the main
1443 // frame load. We don't want various automatic or subframe navigations making
1444 // it disappear.
1445 if (!details.is_user_initiated_main_frame_load())
1446 return;
1447
[email protected]f86a07022008-11-25 01:06:051448 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241449 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051450 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241451 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241452 }
1453}
[email protected]fdd61c62009-04-22 19:22:571454
[email protected]96d185d2009-04-24 03:28:541455DOMUI* TabContents::GetDOMUIForCurrentState() {
1456 // When there is a pending navigation entry, we want to use the pending DOMUI
1457 // that goes along with it to control the basic flags. For example, we want to
1458 // show the pending URL in the URL bar, so we want the display_url flag to
1459 // be from the pending entry.
1460 //
1461 // The confusion comes because there are multiple possibilities for the
1462 // initial load in a tab as a side effect of the way the RenderViewHostManager
1463 // works.
1464 //
1465 // - For the very first tab the load looks "normal". The new tab DOM UI is
1466 // the pending one, and we want it to apply here.
1467 //
1468 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1469 // get switched to the one previously associated with the new tab pages.
1470 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1471 // have a committed DOM UI in this case.
1472 //
1473 // This condition handles all of these cases:
1474 //
1475 // - First load in first tab: no committed nav entry + pending nav entry +
1476 // pending dom ui:
1477 // -> Use pending DOM UI if any.
1478 //
1479 // - First load in second tab: no committed nav entry + pending nav entry +
1480 // no pending DOM UI:
1481 // -> Use the committed DOM UI if any.
1482 //
1483 // - Second navigation in any tab: committed nav entry + pending nav entry:
1484 // -> Use pending DOM UI if any.
1485 //
1486 // - Normal state with no load: committed nav entry + no pending nav entry:
1487 // -> Use committed DOM UI.
1488 if (controller_.pending_entry() &&
1489 (controller_.GetLastCommittedEntry() ||
1490 render_manager_.pending_dom_ui()))
1491 return render_manager_.pending_dom_ui();
1492 return render_manager_.dom_ui();
1493}
[email protected]420ae012009-04-24 05:16:321494
1495void TabContents::DidNavigateMainFramePostCommit(
1496 const NavigationController::LoadCommittedDetails& details,
1497 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441498 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1499 // If this is a window.open navigation, use the same DOMUI as the renderer
1500 // that opened the window, as long as both renderers have the same
1501 // privileges.
1502 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1503 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1504 // dom_ui might be NULL if the URL refers to a non-existent extension.
1505 if (dom_ui) {
1506 render_manager_.SetDOMUIPostCommit(dom_ui);
1507 dom_ui->RenderViewCreated(render_view_host());
1508 }
1509 }
1510 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1511 }
1512
[email protected]420ae012009-04-24 05:16:321513 if (details.is_user_initiated_main_frame_load()) {
1514 // Clear the status bubble. This is a workaround for a bug where WebKit
1515 // doesn't let us know that the cursor left an element during a
1516 // transition (this is also why the mouse cursor remains as a hand after
1517 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1518 // clear the bubble when a user navigates to a named anchor in the same
1519 // page.
1520 UpdateTargetURL(details.entry->page_id(), GURL());
1521
1522 // UpdateHelpersForDidNavigate will handle the case where the password_form
1523 // origin is valid.
1524 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1525 // cleaned up and covered by tests.
1526 if (!params.password_form.origin.is_valid())
1527 GetPasswordManager()->DidNavigate();
1528 }
1529
1530 // The keyword generator uses the navigation entries, so must be called after
1531 // the commit.
1532 GenerateKeywordIfNecessary(params);
1533
1534 // Allow the new page to set the title again.
1535 received_page_title_ = false;
1536
1537 // Get the favicon, either from history or request it from the net.
1538 fav_icon_helper_.FetchFavIcon(details.entry->url());
1539
[email protected]0de80162010-02-03 04:52:351540 // Clear all page actions, blocked content notifications and browser actions
1541 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141542 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081543 ExtensionsService* service = profile()->GetExtensionsService();
1544 if (service) {
1545 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571546 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081547 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521548 if (browser_action) {
1549 browser_action->ClearAllValuesForTab(controller().session_id().id());
1550 NotificationService::current()->Notify(
1551 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571552 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521553 NotificationService::NoDetails());
1554 }
[email protected]92c6f9b92009-10-24 04:35:081555
[email protected]5d246db22009-10-27 06:17:571556 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521557 service->extensions()->at(i)->page_action();
1558 if (page_action) {
1559 page_action->ClearAllValuesForTab(controller().session_id().id());
1560 PageActionStateChanged();
1561 }
[email protected]92c6f9b92009-10-24 04:35:081562 }
[email protected]aece2c7f2009-08-27 20:43:171563 }
[email protected]0de80162010-02-03 04:52:351564
1565 // Close blocked popups.
1566 if (blocked_popups_) {
[email protected]0fbd70332010-06-01 19:28:341567 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]0de80162010-02-03 04:52:351568 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461569 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351570 }
1571
1572 // Clear "blocked" flags.
[email protected]9fb83e82010-07-02 18:24:551573 content_settings_delegate_->ClearBlockedContentSettings();
1574 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471575
1576 // Once the main frame is navigated, we're no longer considered to have
1577 // displayed insecure content.
1578 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171579 }
[email protected]ce5c4502009-05-06 16:46:111580
[email protected]8cc8d492010-02-02 10:40:491581 // Close constrained windows if necessary.
1582 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1583 details.previous_url, details.entry->url()))
1584 CloseConstrainedWindows();
1585
[email protected]420ae012009-04-24 05:16:321586 // Update the starred state.
1587 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531588
1589 // Clear the cache of forms in AutoFill.
1590 if (autofill_manager_.get())
1591 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321592}
1593
1594void TabContents::DidNavigateAnyFramePostCommit(
1595 RenderViewHost* render_view_host,
1596 const NavigationController::LoadCommittedDetails& details,
1597 const ViewHostMsg_FrameNavigate_Params& params) {
1598 // If we navigate, start showing messages again. This does nothing to prevent
1599 // a malicious script from spamming messages, since the script could just
1600 // reload the page to stop blocking.
1601 suppress_javascript_messages_ = false;
1602
[email protected]420ae012009-04-24 05:16:321603 // Notify the password manager of the navigation or form submit.
1604 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1605 // cleaned up and covered by tests.
1606 if (params.password_form.origin.is_valid())
1607 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551608
1609 // Let the LanguageState clear its state.
[email protected]34cec8d82010-03-05 18:27:011610 bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
1611 details.type == NavigationType::SAME_PAGE;
1612 language_state_.DidNavigate(reload, details.is_in_page);
[email protected]420ae012009-04-24 05:16:321613}
1614
[email protected]8cc8d492010-02-02 10:40:491615void TabContents::CloseConstrainedWindows() {
1616 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321617 // We use indices instead of iterators in case CloseWindow does something
1618 // that may invalidate an iterator.
1619 int size = static_cast<int>(child_windows_.size());
1620 for (int i = size - 1; i >= 0; --i) {
1621 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441622 if (window) {
[email protected]420ae012009-04-24 05:16:321623 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441624 BlockTabContent(false);
1625 }
[email protected]420ae012009-04-24 05:16:321626 }
1627}
1628
1629void TabContents::UpdateStarredStateForCurrentURL() {
1630 BookmarkModel* model = profile()->GetBookmarkModel();
1631 const bool old_state = is_starred_;
1632 is_starred_ = (model && model->IsBookmarked(GetURL()));
1633
1634 if (is_starred_ != old_state && delegate())
1635 delegate()->URLStarredChanged(this, is_starred_);
1636}
1637
1638void TabContents::UpdateAlternateErrorPageURL() {
1639 GURL url = GetAlternateErrorPageURL();
1640 render_view_host()->SetAlternateErrorPageURL(url);
1641}
1642
1643void TabContents::UpdateWebPreferences() {
1644 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1645}
1646
1647void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1648 RenderViewHost* rvh) {
1649 // If we are creating a RVH for a restored controller, then we might
1650 // have more page IDs than the SiteInstance's current max page ID. We must
1651 // make sure that the max page ID is larger than any restored page ID.
1652 // Note that it is ok for conflicting page IDs to exist in another tab
1653 // (i.e., NavigationController), but if any page ID is larger than the max,
1654 // the back/forward list will get confused.
1655 int max_restored_page_id = controller_.max_restored_page_id();
1656 if (max_restored_page_id > 0) {
1657 int curr_max_page_id = site_instance->max_page_id();
1658 if (max_restored_page_id > curr_max_page_id) {
1659 // Need to update the site instance immediately.
1660 site_instance->UpdateMaxPageID(max_restored_page_id);
1661
1662 // Also tell the renderer to update its internal representation. We
1663 // need to reserve enough IDs to make all restored page IDs less than
1664 // the max.
1665 if (curr_max_page_id < 0)
1666 curr_max_page_id = 0;
1667 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1668 }
1669 }
1670}
1671
1672void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541673 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471674 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321675 const ViewHostMsg_FrameNavigate_Params& params) {
1676 if (profile()->IsOffTheRecord())
1677 return;
1678
1679 // Add to history service.
1680 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1681 if (hs) {
1682 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541683 virtual_url != params.url) {
1684 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321685 // types of URLs, we will display a magic URL that is different from where
1686 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541687 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1688 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321689 // to sub-frames.
1690 std::vector<GURL> redirects = params.redirects;
1691 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541692 redirects.back() = virtual_url;
1693 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471694 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321695 } else {
1696 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471697 params.transition, params.redirects,
1698 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321699 }
1700 }
1701}
1702
1703bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1704 const std::wstring& title) {
1705 // For file URLs without a title, use the pathname instead. In the case of a
1706 // synthesized title, we don't want the update to count toward the "one set
1707 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251708 string16 final_title;
[email protected]420ae012009-04-24 05:16:321709 bool explicit_set;
1710 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251711 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321712 explicit_set = false; // Don't count synthetic titles toward the set limit.
1713 } else {
[email protected]e53668962010-06-23 15:35:251714 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321715 explicit_set = true;
1716 }
1717
[email protected]e53668962010-06-23 15:35:251718 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321719 return false; // Nothing changed, don't bother.
1720
[email protected]e53668962010-06-23 15:35:251721 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321722
1723 // Update the history system for this page.
1724 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1725 HistoryService* hs =
1726 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1727 if (hs)
[email protected]ebe89e062009-08-13 23:16:541728 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321729
1730 // Don't allow the title to be saved again for explicitly set ones.
1731 received_page_title_ = explicit_set;
1732 }
1733
1734 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251735 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321736
[email protected]cbc0e1b2010-04-12 18:33:041737 NotificationService::current()->Notify(
1738 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1739 Source<TabContents>(this),
1740 NotificationService::NoDetails());
1741
[email protected]420ae012009-04-24 05:16:321742 return true;
1743}
1744
1745void TabContents::NotifySwapped() {
1746 // After sending out a swap notification, we need to send a disconnect
1747 // notification so that clients that pick up a pointer to |this| can NULL the
1748 // pointer. See Bug 1230284.
1749 notify_disconnection_ = true;
1750 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341751 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221752 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321753 NotificationService::NoDetails());
1754}
1755
1756void TabContents::NotifyConnected() {
1757 notify_disconnection_ = true;
1758 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341759 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221760 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321761 NotificationService::NoDetails());
1762}
1763
1764void TabContents::NotifyDisconnected() {
1765 if (!notify_disconnection_)
1766 return;
1767
1768 notify_disconnection_ = false;
1769 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341770 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221771 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321772 NotificationService::NoDetails());
1773}
1774
1775void TabContents::GenerateKeywordIfNecessary(
1776 const ViewHostMsg_FrameNavigate_Params& params) {
1777 if (!params.searchable_form_url.is_valid())
1778 return;
1779
1780 if (profile()->IsOffTheRecord())
1781 return;
1782
1783 int last_index = controller_.last_committed_entry_index();
1784 // When there was no previous page, the last index will be 0. This is
1785 // normally due to a form submit that opened in a new tab.
1786 // TODO(brettw) bug 916126: we should support keywords when form submits
1787 // happen in new tabs.
1788 if (last_index <= 0)
1789 return;
1790 const NavigationEntry* previous_entry =
1791 controller_.GetEntryAtIndex(last_index - 1);
1792 if (IsFormSubmit(previous_entry)) {
1793 // Only generate a keyword if the previous page wasn't itself a form
1794 // submit.
1795 return;
1796 }
1797
1798 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1799 previous_entry->user_typed_url() : previous_entry->url();
1800 std::wstring keyword =
1801 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1802 if (keyword.empty())
1803 return;
1804
1805 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1806 if (!url_model)
1807 return;
1808
1809 if (!url_model->loaded()) {
1810 url_model->Load();
1811 return;
1812 }
1813
1814 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191815 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321816 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1817 return;
1818
1819 if (current_url) {
1820 if (current_url->originating_url().is_valid()) {
1821 // The existing keyword was generated from an OpenSearch description
1822 // document, don't regenerate.
1823 return;
1824 }
1825 url_model->Remove(current_url);
1826 }
1827 TemplateURL* new_url = new TemplateURL();
1828 new_url->set_keyword(keyword);
1829 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191830 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321831 new_url->add_input_encoding(params.searchable_form_encoding);
1832 DCHECK(controller_.GetLastCommittedEntry());
1833 const GURL& favicon_url =
1834 controller_.GetLastCommittedEntry()->favicon().url();
1835 if (favicon_url.is_valid()) {
1836 new_url->SetFavIconURL(favicon_url);
1837 } else {
1838 // The favicon url isn't valid. This means there really isn't a favicon,
1839 // or the favicon url wasn't obtained before the load started. This assumes
1840 // the later.
1841 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1842 // its url.
1843 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1844 }
1845 new_url->set_safe_for_autoreplace(true);
1846 url_model->Add(new_url);
1847}
1848
[email protected]bf5c2ff392009-07-08 16:24:331849void TabContents::OnUserGesture() {
1850 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1851 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1852 if (drm)
1853 drm->OnUserGesture(this);
[email protected]e7eaedde2009-09-25 20:09:491854 ExternalProtocolHandler::OnUserGesture();
[email protected]bf5c2ff392009-07-08 16:24:331855 controller_.OnUserGesture();
1856}
1857
1858void TabContents::OnFindReply(int request_id,
1859 int number_of_matches,
1860 const gfx::Rect& selection_rect,
1861 int active_match_ordinal,
1862 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421863 // Ignore responses for requests that have been aborted.
1864 if (find_op_aborted_)
1865 return;
1866
[email protected]bf5c2ff392009-07-08 16:24:331867 // Ignore responses for requests other than the one we have most recently
1868 // issued. That way we won't act on stale results when the user has
1869 // already typed in another query.
1870 if (request_id != current_find_request_id_)
1871 return;
1872
1873 if (number_of_matches == -1)
1874 number_of_matches = last_search_result_.number_of_matches();
1875 if (active_match_ordinal == -1)
1876 active_match_ordinal = last_search_result_.active_match_ordinal();
1877
1878 gfx::Rect selection = selection_rect;
1879 if (selection.IsEmpty())
1880 selection = last_search_result_.selection_rect();
1881
1882 // Notify the UI, automation and any other observers that a find result was
1883 // found.
1884 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1885 selection, active_match_ordinal,
1886 final_update);
1887 NotificationService::current()->Notify(
1888 NotificationType::FIND_RESULT_AVAILABLE,
1889 Source<TabContents>(this),
1890 Details<FindNotificationDetails>(&last_search_result_));
1891}
1892
1893void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381894 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1895 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331896}
1897
[email protected]bf5c2ff392009-07-08 16:24:331898void TabContents::OnMissingPluginStatus(int status) {
1899#if defined(OS_WIN)
1900// TODO(PORT): pull in when plug-ins work
1901 GetPluginInstaller()->OnMissingPluginStatus(status);
1902#endif
1903}
1904
1905void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331906 DCHECK(!plugin_path.value().empty());
1907
1908 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351909#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331910 scoped_ptr<FileVersionInfo> version_info(
1911 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1912 if (version_info.get()) {
1913 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371914 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331915 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371916#if defined(OS_MACOSX)
1917 // Many plugins on the Mac have .plugin in the actual name, which looks
1918 // terrible, so look for that and strip it off if present.
1919 const std::wstring plugin_extension(L".plugin");
1920 if (EndsWith(plugin_name, plugin_extension, true))
1921 plugin_name.erase(plugin_name.length() - plugin_extension.length());
1922#endif // OS_MACOSX
1923 }
[email protected]bf5c2ff392009-07-08 16:24:331924 }
[email protected]4a560ed2009-07-13 23:35:261925#else
1926 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1927#endif
[email protected]2ae8a922010-06-28 20:27:531928 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
1929 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:331930 AddInfoBar(new SimpleAlertInfoBarDelegate(
1931 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
[email protected]2ae8a922010-06-28 20:27:531932 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:331933}
1934
1935void TabContents::OnCrashedWorker() {
1936 AddInfoBar(new SimpleAlertInfoBarDelegate(
1937 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:421938 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331939}
1940
1941void TabContents::OnDidGetApplicationInfo(
1942 int32 page_id,
1943 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511944 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331945
[email protected]ed5431872009-11-17 08:39:511946 if (delegate())
1947 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331948}
1949
[email protected]a2cf65eb2010-01-18 08:20:381950void TabContents::OnPageContents(const GURL& url,
1951 int renderer_process_id,
1952 int32 page_id,
[email protected]e5106202010-06-11 21:12:361953 const string16& contents,
[email protected]a8a81292010-01-21 00:32:451954 const std::string& language) {
[email protected]a2cf65eb2010-01-18 08:20:381955 // Don't index any https pages. People generally don't want their bank
1956 // accounts, etc. indexed on their computer, especially since some of these
1957 // things are not marked cachable.
1958 // TODO(brettw) we may want to consider more elaborate heuristics such as
1959 // the cachability of the page. We may also want to consider subframes (this
1960 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271961 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1962 // content indexing for chromeos in some future releases.
1963#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381964 if (!url.SchemeIsSecure()) {
1965 Profile* p = profile();
1966 if (p && !p->IsOffTheRecord()) {
1967 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1968 if (hs)
1969 hs->SetPageContents(url, contents);
1970 }
1971 }
[email protected]ccd40a52010-05-11 16:15:271972#endif
[email protected]a8a81292010-01-21 00:32:451973
[email protected]3b1c1812010-02-12 21:53:551974 language_state_.LanguageDetermined(language);
[email protected]a8a81292010-01-21 00:32:451975
1976 std::string lang = language;
1977 NotificationService::current()->Notify(
1978 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151979 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451980 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:381981}
1982
[email protected]7e0831b2010-02-01 08:45:151983void TabContents::OnPageTranslated(int32 page_id,
1984 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:161985 const std::string& translated_lang,
1986 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:551987 language_state_.set_current_language(translated_lang);
1988 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:161989 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:151990 NotificationService::current()->Notify(
1991 NotificationType::PAGE_TRANSLATED,
1992 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:161993 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:151994}
1995
[email protected]bf5c2ff392009-07-08 16:24:331996void TabContents::DidStartProvisionalLoadForFrame(
1997 RenderViewHost* render_view_host,
1998 bool is_main_frame,
1999 const GURL& url) {
2000 ProvisionalLoadDetails details(is_main_frame,
2001 controller_.IsURLInPageNavigation(url),
2002 url, std::string(), false);
2003 NotificationService::current()->Notify(
2004 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2005 Source<NavigationController>(&controller_),
2006 Details<ProvisionalLoadDetails>(&details));
2007}
2008
2009void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202010 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332011 NotificationService::current()->Notify(
2012 NotificationType::RESOURCE_RESPONSE_STARTED,
2013 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202014 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332015}
2016
[email protected]3dbb80b2010-02-09 22:41:202017void TabContents::DidRedirectResource(
2018 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332019 NotificationService::current()->Notify(
2020 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2021 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202022 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332023}
2024
2025void TabContents::DidLoadResourceFromMemoryCache(
2026 const GURL& url,
2027 const std::string& frame_origin,
2028 const std::string& main_frame_origin,
2029 const std::string& security_info) {
2030 // Send out a notification that we loaded a resource from our memory cache.
2031 int cert_id = 0, cert_status = 0, security_bits = 0;
2032 SSLManager::DeserializeSecurityInfo(security_info,
2033 &cert_id, &cert_status,
2034 &security_bits);
2035 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162036 GetRenderProcessHost()->id(), cert_id,
2037 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332038
2039 NotificationService::current()->Notify(
2040 NotificationType::LOAD_FROM_MEMORY_CACHE,
2041 Source<NavigationController>(&controller_),
2042 Details<LoadFromMemoryCacheDetails>(&details));
2043}
2044
[email protected]e3d60e5d2009-09-25 21:08:292045void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472046 displayed_insecure_content_ = true;
2047 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292048}
2049
2050void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592051 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292052}
2053
[email protected]bf5c2ff392009-07-08 16:24:332054void TabContents::DidFailProvisionalLoadWithError(
2055 RenderViewHost* render_view_host,
2056 bool is_main_frame,
2057 int error_code,
2058 const GURL& url,
2059 bool showing_repost_interstitial) {
2060 if (net::ERR_ABORTED == error_code) {
2061 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2062 // This means that the interstitial won't be torn down properly, which is
2063 // bad. But if we have an interstitial, go back to another tab type, and
2064 // then load the same interstitial again, we could end up getting the first
2065 // interstitial's "failed" message (as a result of the cancel) when we're on
2066 // the second one.
2067 //
2068 // We can't tell this apart, so we think we're tearing down the current page
2069 // which will cause a crash later one. There is also some code in
2070 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2071 // out because of this problem.
2072 //
2073 // http://code.google.com/p/chromium/issues/detail?id=2855
2074 // Because this will not tear down the interstitial properly, if "back" is
2075 // back to another tab type, the interstitial will still be somewhat alive
2076 // in the previous tab type. If you navigate somewhere that activates the
2077 // tab with the interstitial again, you'll see a flash before the new load
2078 // commits of the interstitial page.
2079 if (showing_interstitial_page()) {
2080 LOG(WARNING) << "Discarding message during interstitial.";
2081 return;
2082 }
2083
2084 // This will discard our pending entry if we cancelled the load (e.g., if we
2085 // decided to download the file instead of load it). Only discard the
2086 // pending entry if the URLs match, otherwise the user initiated a navigate
2087 // before the page loaded so that the discard would discard the wrong entry.
2088 NavigationEntry* pending_entry = controller_.pending_entry();
2089 if (pending_entry && pending_entry->url() == url) {
2090 controller_.DiscardNonCommittedEntries();
2091 // Update the URL display.
2092 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2093 }
2094
2095 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2096 }
2097
2098 // Send out a notification that we failed a provisional load with an error.
2099 ProvisionalLoadDetails details(is_main_frame,
2100 controller_.IsURLInPageNavigation(url),
2101 url, std::string(), false);
2102 details.set_error_code(error_code);
2103
2104 NotificationService::current()->Notify(
2105 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2106 Source<NavigationController>(&controller_),
2107 Details<ProvisionalLoadDetails>(&details));
2108}
2109
2110void TabContents::DocumentLoadedInFrame() {
2111 controller_.DocumentLoadedInFrame();
2112}
2113
[email protected]9fb83e82010-07-02 18:24:552114void TabContents::OnContentSettingsChange() {
[email protected]614c0e12010-03-25 10:12:562115 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242116 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562117}
2118
[email protected]8d3347f2009-07-09 22:00:212119RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322120 return view_.get();
2121}
2122
[email protected]8d3347f2009-07-09 22:00:212123RenderViewHostDelegate::RendererManagement*
2124TabContents::GetRendererManagementDelegate() {
2125 return &render_manager_;
2126}
2127
[email protected]bf5c2ff392009-07-08 16:24:332128RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212129 TabContents::GetBrowserIntegrationDelegate() {
2130 return this;
[email protected]bf5c2ff392009-07-08 16:24:332131}
2132
[email protected]8d3347f2009-07-09 22:00:212133RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2134 return this;
[email protected]bf5c2ff392009-07-08 16:24:332135}
2136
[email protected]46ba9082010-06-22 10:00:582137RenderViewHostDelegate::ContentSettings*
2138TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552139 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582140}
2141
[email protected]8d3347f2009-07-09 22:00:212142RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322143 return save_package_.get(); // May be NULL, but we can return NULL.
2144}
2145
[email protected]8d3347f2009-07-09 22:00:212146RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
2147 return &printing_;
2148}
2149
2150RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2151 return &fav_icon_helper_;
2152}
2153
[email protected]e8dbd674b2010-03-11 18:34:402154RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452155 if (autocomplete_history_manager_.get() == NULL)
2156 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2157 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332158}
2159
[email protected]21674df2009-10-28 19:51:212160RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342161 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212162}
2163
[email protected]fd571bb2010-03-19 01:23:542164AutomationResourceRoutingDelegate*
2165TabContents::GetAutomationResourceRoutingDelegate() {
2166 return delegate();
2167}
2168
[email protected]ced90ae12010-02-20 02:06:162169RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2170 return bookmark_drag_;
2171}
2172
2173void TabContents::SetBookmarkDragDelegate(
2174 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2175 bookmark_drag_ = bookmark_drag;
2176}
2177
[email protected]9fb83e82010-07-02 18:24:552178TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2179 return content_settings_delegate_.get();
2180}
2181
[email protected]93623c5d2009-12-10 21:40:322182RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462183 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512184}
2185
[email protected]57c6a652009-05-04 07:58:342186TabContents* TabContents::GetAsTabContents() {
2187 return this;
2188}
2189
[email protected]7b291f92009-08-14 05:43:532190ViewType::Type TabContents::GetRenderViewType() const {
2191 return ViewType::TAB_CONTENTS;
2192}
2193
2194int TabContents::GetBrowserWindowID() const {
2195 return controller().window_id().id();
2196}
2197
[email protected]420ae012009-04-24 05:16:322198void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062199 NotificationService::current()->Notify(
2200 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2201 Source<TabContents>(this),
2202 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322203 NavigationEntry* entry = controller_.GetActiveEntry();
2204 if (!entry)
2205 return;
2206
2207 // When we're creating views, we're still doing initial setup, so we always
2208 // use the pending DOM UI rather than any possibly existing committed one.
2209 if (render_manager_.pending_dom_ui()) {
2210 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2211 }
2212
2213 if (entry->IsViewSourceMode()) {
2214 // Put the renderer in view source mode.
2215 render_view_host->Send(
2216 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2217 }
[email protected]0666aef2009-05-13 19:48:082218
2219 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322220}
2221
2222void TabContents::RenderViewReady(RenderViewHost* rvh) {
2223 if (rvh != render_view_host()) {
2224 // Don't notify the world, since this came from a renderer in the
2225 // background.
2226 return;
2227 }
2228
2229 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302230 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322231 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302232
2233 // Restore the focus to the tab (otherwise the focus will be on the top
2234 // window).
2235 if (was_crashed && !FocusLocationBarByDefault())
2236 Focus();
[email protected]420ae012009-04-24 05:16:322237}
2238
2239void TabContents::RenderViewGone(RenderViewHost* rvh) {
2240 // Ask the print preview if this renderer was valuable.
2241 if (!printing_.OnRenderViewGone(rvh))
2242 return;
2243 if (rvh != render_view_host()) {
2244 // The pending page's RenderViewHost is gone.
2245 return;
2246 }
2247
2248 SetIsLoading(false, NULL);
2249 NotifyDisconnected();
2250 SetIsCrashed(true);
2251
[email protected]ff9efc62010-02-18 22:10:542252 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212253 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542254 RemoveInfoBar(GetInfoBarDelegateAt(i));
2255
[email protected]8e537302009-06-10 21:19:582256 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552257 // Only do this if we're not in browser shutdown, so that TabContents
2258 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2259 // visible do not flash a sad tab page.
2260 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2261 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322262
2263 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002264 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322265}
2266
[email protected]2e4633c2009-07-09 16:58:062267void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2268 NotificationService::current()->Notify(
2269 NotificationType::RENDER_VIEW_HOST_DELETED,
2270 Source<TabContents>(this),
2271 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482272 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062273}
2274
[email protected]420ae012009-04-24 05:16:322275void TabContents::DidNavigate(RenderViewHost* rvh,
2276 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372277 int extra_invalidate_flags = 0;
2278
2279 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352280 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372281 bool was_extension_shelf_visible = IsExtensionShelfAlwaysVisible();
2282
[email protected]420ae012009-04-24 05:16:322283 render_manager_.DidNavigateMainFrame(rvh);
2284
[email protected]20ede072009-10-06 00:28:352285 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372286 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
2287 if (was_extension_shelf_visible != IsExtensionShelfAlwaysVisible())
2288 extra_invalidate_flags |= INVALIDATE_EXTENSION_SHELF;
2289 }
2290
[email protected]420ae012009-04-24 05:16:322291 // Update the site of the SiteInstance if it doesn't have one yet.
2292 if (!GetSiteInstance()->has_site())
2293 GetSiteInstance()->SetSite(params.url);
2294
2295 // Need to update MIME type here because it's referred to in
2296 // UpdateNavigationCommands() called by RendererDidNavigate() to
2297 // determine whether or not to enable the encoding menu.
2298 // It's updated only for the main frame. For a subframe,
2299 // RenderView::UpdateURL does not set params.contents_mime_type.
2300 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2301 // TODO(jungshik): Add a test for the encoding menu to avoid
2302 // regressing it again.
2303 if (PageTransition::IsMainFrame(params.transition))
2304 contents_mime_type_ = params.contents_mime_type;
2305
2306 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372307 bool did_navigate = controller_.RendererDidNavigate(
2308 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392309
2310 // Update history. Note that this needs to happen after the entry is complete,
2311 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352312 if (params.should_update_history &&
2313 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392314 // Most of the time, the displayURL matches the loaded URL, but for about:
2315 // URLs, we use a data: URL as the real value. We actually want to save
2316 // the about: URL to the history db and keep the data: URL hidden. This is
2317 // what the TabContents' URL getter does.
2318 UpdateHistoryForNavigation(GetURL(), details, params);
2319 }
2320
[email protected]76543b92009-08-31 17:27:452321 if (!did_navigate)
2322 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322323
2324 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2325 // for the appropriate notification (best) or you can add it to
2326 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2327 // necessary, please).
2328
2329 // Run post-commit tasks.
2330 if (details.is_main_frame)
2331 DidNavigateMainFramePostCommit(details, params);
2332 DidNavigateAnyFramePostCommit(rvh, details, params);
2333}
2334
2335void TabContents::UpdateState(RenderViewHost* rvh,
2336 int32 page_id,
2337 const std::string& state) {
2338 DCHECK(rvh == render_view_host());
2339
2340 // We must be prepared to handle state updates for any page, these occur
2341 // when the user is scrolling and entering form data, as well as when we're
2342 // leaving a page, in which case our state may have already been moved to
2343 // the next page. The navigation controller will look up the appropriate
2344 // NavigationEntry and update it when it is notified via the delegate.
2345
2346 int entry_index = controller_.GetEntryIndexWithPageID(
2347 GetSiteInstance(), page_id);
2348 if (entry_index < 0)
2349 return;
2350 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2351
2352 if (state == entry->content_state())
2353 return; // Nothing to update.
2354 entry->set_content_state(state);
2355 controller_.NotifyEntryChanged(entry, entry_index);
2356}
2357
2358void TabContents::UpdateTitle(RenderViewHost* rvh,
2359 int32 page_id, const std::wstring& title) {
2360 // If we have a title, that's a pretty good indication that we've started
2361 // getting useful data.
2362 SetNotWaitingForResponse();
2363
2364 DCHECK(rvh == render_view_host());
2365 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2366 page_id);
2367 if (!entry || !UpdateTitleForEntry(entry, title))
2368 return;
2369
2370 // Broadcast notifications when the UI should be updated.
2371 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032372 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322373}
2374
[email protected]420ae012009-04-24 05:16:322375void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402376 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322377 set_encoding(encoding);
2378}
2379
2380void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2381 if (delegate())
2382 delegate()->UpdateTargetURL(this, url);
2383}
2384
2385void TabContents::UpdateThumbnail(const GURL& url,
2386 const SkBitmap& bitmap,
2387 const ThumbnailScore& score) {
2388 // Tell History about this thumbnail
[email protected]523623c2010-05-19 16:03:422389 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492390 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422391 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282392 } else {
2393 HistoryService* hs;
2394 if (!profile()->IsOffTheRecord() &&
2395 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2396 hs->SetPageThumbnail(url, bitmap, score);
2397 }
[email protected]420ae012009-04-24 05:16:322398 }
2399}
2400
[email protected]c4e98902010-06-01 10:20:142401void TabContents::UpdateInspectorSetting(const std::string& key,
2402 const std::string& value) {
2403 DictionaryValue* inspector_settings =
2404 profile()->GetPrefs()->GetMutableDictionary(
2405 prefs::kWebKitInspectorSettings);
[email protected]628cf5a52010-06-07 14:25:332406 inspector_settings->SetWithoutPathExpansion(UTF8ToWide(key),
2407 Value::CreateStringValue(value));
[email protected]0df30122009-06-03 12:13:082408}
2409
[email protected]45aafc92010-06-07 14:18:532410void TabContents::ClearInspectorSettings() {
2411 DictionaryValue* inspector_settings =
2412 profile()->GetPrefs()->GetMutableDictionary(
2413 prefs::kWebKitInspectorSettings);
2414 inspector_settings->Clear();
2415}
2416
[email protected]420ae012009-04-24 05:16:322417void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292418 // The UI may be in an event-tracking loop, such as between the
2419 // mouse-down and mouse-up in text selection or a button click.
2420 // Defer the close until after tracking is complete, so that we
2421 // don't free objects out from under the UI.
2422 // TODO(shess): This could probably be integrated with the
2423 // IsDoingDrag() test below. Punting for now because I need more
2424 // research to understand how this impacts platforms other than Mac.
2425 // TODO(shess): This could get more fine-grained. For instance,
2426 // closing a tab in another window while selecting text in the
2427 // current window's Omnibox should be just fine.
2428 if (view()->IsEventTracking()) {
2429 view()->CloseTabAfterEventTracking();
2430 return;
2431 }
2432
[email protected]24a4d1062009-07-10 23:10:422433 // If we close the tab while we're in the middle of a drag, we'll crash.
2434 // Instead, cancel the drag and close it as soon as the drag ends.
2435 if (view()->IsDoingDrag()) {
2436 view()->CancelDragAndCloseTab();
2437 return;
2438 }
2439
[email protected]420ae012009-04-24 05:16:322440 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2441 if (delegate() && rvh == render_view_host())
2442 delegate()->CloseContents(this);
2443}
2444
2445void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2446 if (delegate() && delegate()->IsPopup(this))
2447 delegate()->MoveContents(this, new_bounds);
2448}
2449
[email protected]7ab1e7d62009-10-14 23:32:012450void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322451 SetIsLoading(true, NULL);
2452}
2453
[email protected]7ab1e7d62009-10-14 23:32:012454void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322455 scoped_ptr<LoadNotificationDetails> details;
2456
2457 NavigationEntry* entry = controller_.GetActiveEntry();
2458 // An entry may not exist for a stop when loading an initial blank page or
2459 // if an iframe injected by script into a blank page finishes loading.
2460 if (entry) {
[email protected]420ae012009-04-24 05:16:322461 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2462
2463 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542464 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322465 entry->transition_type(),
2466 elapsed,
2467 &controller_,
2468 controller_.GetCurrentEntryIndex()));
2469 }
2470
2471 // Tell PasswordManager we've finished a page load, which serves as a
2472 // green light to save pending passwords and reset itself.
2473 GetPasswordManager()->DidStopLoading();
2474
2475 SetIsLoading(false, details.get());
2476}
2477
[email protected]420ae012009-04-24 05:16:322478void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2479 const GURL& source_url,
2480 const GURL& target_url) {
2481 NavigationEntry* entry;
2482 if (page_id == -1)
2483 entry = controller_.pending_entry();
2484 else
2485 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2486 if (!entry || entry->url() != source_url)
2487 return;
2488 entry->set_url(target_url);
2489}
2490
[email protected]420ae012009-04-24 05:16:322491void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2492 WindowOpenDisposition disposition) {
2493 if (render_manager_.dom_ui()) {
2494 // When we're a DOM UI, it will provide a page transition type for us (this
2495 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2496 // generated suggestions).
2497 //
2498 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162499 // want web sites to see a referrer of "chrome://blah" (and some
2500 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322501 // send to the site), so we send no referrer.
2502 OpenURL(url, GURL(), disposition,
2503 render_manager_.dom_ui()->link_transition_type());
2504 } else {
2505 OpenURL(url, referrer, disposition, PageTransition::LINK);
2506 }
2507}
2508
[email protected]1ee614862009-07-06 20:29:182509void TabContents::DomOperationResponse(const std::string& json_string,
2510 int automation_id) {
2511}
2512
[email protected]420ae012009-04-24 05:16:322513void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]438c97d2010-05-21 23:30:152514 const ListValue* content,
[email protected]bb64b512010-04-02 21:01:392515 const GURL& source_url,
[email protected]811bfe32009-07-01 08:46:252516 int request_id,
2517 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322518 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442519 // This can happen if someone uses window.open() to open an extension URL
2520 // from a non-extension context.
2521 render_view_host()->BlockExtensionRequest(request_id);
[email protected]420ae012009-04-24 05:16:322522 return;
2523 }
[email protected]bb64b512010-04-02 21:01:392524 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, source_url,
2525 request_id,
[email protected]811bfe32009-07-01 08:46:252526 has_callback);
[email protected]420ae012009-04-24 05:16:322527}
2528
2529void TabContents::ProcessExternalHostMessage(const std::string& message,
2530 const std::string& origin,
2531 const std::string& target) {
2532 if (delegate())
2533 delegate()->ForwardMessageToExternalHost(message, origin, target);
2534}
2535
[email protected]cdaf8d02010-03-30 19:52:472536void TabContents::RunFileChooser(
2537 const ViewHostMsg_RunFileChooser_Params &params) {
[email protected]420ae012009-04-24 05:16:322538 if (!select_file_dialog_.get())
2539 select_file_dialog_ = SelectFileDialog::Create(this);
[email protected]cdaf8d02010-03-30 19:52:472540
2541 SelectFileDialog::Type dialog_type;
2542 switch (params.mode) {
2543 case ViewHostMsg_RunFileChooser_Params::Open:
2544 dialog_type = SelectFileDialog::SELECT_OPEN_FILE;
2545 break;
2546 case ViewHostMsg_RunFileChooser_Params::OpenMultiple:
2547 dialog_type = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
2548 break;
2549 case ViewHostMsg_RunFileChooser_Params::Save:
2550 dialog_type = SelectFileDialog::SELECT_SAVEAS_FILE;
2551 break;
2552 default:
[email protected]bed31952010-03-30 20:07:592553 dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning.
[email protected]cdaf8d02010-03-30 19:52:472554 NOTREACHED();
2555 }
[email protected]35896a32010-06-09 08:42:512556 FilePath default_file_name = params.default_file_name;
2557 if (default_file_name.empty())
2558 default_file_name = profile()->last_selected_directory();
[email protected]cdaf8d02010-03-30 19:52:472559 select_file_dialog_->SelectFile(dialog_type, params.title,
[email protected]35896a32010-06-09 08:42:512560 default_file_name,
[email protected]420ae012009-04-24 05:16:322561 NULL, 0, FILE_PATH_LITERAL(""),
2562 view_->GetTopLevelNativeWindow(), NULL);
2563}
2564
2565void TabContents::RunJavaScriptMessage(
2566 const std::wstring& message,
2567 const std::wstring& default_prompt,
2568 const GURL& frame_url,
2569 const int flags,
2570 IPC::Message* reply_msg,
2571 bool* did_suppress_message) {
2572 // Suppress javascript messages when requested and when inside a constrained
2573 // popup window (because that activates them and breaks them out of the
2574 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552575 // Also suppress messages when showing an interstitial. The interstitial is
2576 // shown over the previous page, we don't want the hidden page dialogs to
2577 // interfere with the interstitial.
2578 bool suppress_this_message = suppress_javascript_messages_ ||
2579 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322580 if (delegate())
2581 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312582 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322583
2584 *did_suppress_message = suppress_this_message;
2585
2586 if (!suppress_this_message) {
2587 base::TimeDelta time_since_last_message(
2588 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2589 bool show_suppress_checkbox = false;
2590 // Show a checkbox offering to suppress further messages if this message is
2591 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2592 if (time_since_last_message <
2593 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2594 show_suppress_checkbox = true;
2595
[email protected]d82ed61e2009-06-16 02:46:222596 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322597 show_suppress_checkbox, reply_msg);
2598 } else {
2599 // If we are suppressing messages, just reply as is if the user immediately
2600 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542601 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322602 }
2603}
2604
2605void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2606 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012607 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222608 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322609}
2610
2611void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2612 const std::string& json_arguments,
2613 IPC::Message* reply_msg) {
2614 if (delegate()) {
2615 HtmlDialogUIDelegate* dialog_delegate =
2616 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222617 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322618 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2619 }
2620}
2621
[email protected]4d44a1c2010-04-28 19:20:412622void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562623 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412624 GetPasswordManager()->PasswordFormsFound(forms);
2625}
2626
2627void TabContents::PasswordFormsVisible(
2628 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2629 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322630}
2631
[email protected]420ae012009-04-24 05:16:322632// Checks to see if we should generate a keyword based on the OSDD, and if
2633// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2634void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2635 int32 page_id, const GURL& url,
2636 bool autodetected) {
2637 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2638 DCHECK(url.is_valid());
2639 if (!IsActiveEntry(page_id))
2640 return;
2641 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2642 if (!url_model)
2643 return;
2644 if (!url_model->loaded()) {
2645 url_model->Load();
2646 return;
2647 }
2648 if (!profile()->GetTemplateURLFetcher())
2649 return;
2650
2651 if (profile()->IsOffTheRecord())
2652 return;
2653
2654 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2655 DCHECK(entry);
2656
2657 const NavigationEntry* base_entry = entry;
2658 if (IsFormSubmit(base_entry)) {
2659 // If the current page is a form submit, find the last page that was not
2660 // a form submit and use its url to generate the keyword from.
2661 int index = controller_.last_committed_entry_index() - 1;
2662 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2663 index--;
2664 if (index >= 0)
2665 base_entry = controller_.GetEntryAtIndex(index);
2666 else
2667 base_entry = NULL;
2668 }
2669
2670 // We want to use the user typed URL if available since that represents what
2671 // the user typed to get here, and fall back on the regular URL if not.
2672 if (!base_entry)
2673 return;
2674 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2675 base_entry->user_typed_url() : base_entry->url();
2676 if (!keyword_url.is_valid())
2677 return;
2678 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2679 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532680
2681 // For JS added OSDD empty keyword is OK because we will generate keyword
2682 // later from OSDD content.
2683 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322684 return;
2685 const TemplateURL* template_url =
2686 url_model->GetTemplateURLForKeyword(keyword);
2687 if (template_url && (!template_url->safe_for_autoreplace() ||
2688 template_url->originating_url() == url)) {
2689 // Either there is a user created TemplateURL for this keyword, or the
2690 // keyword has the same OSDD url and we've parsed it.
2691 return;
2692 }
2693
2694 // Download the OpenSearch description document. If this is successful a
2695 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322696 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2697 keyword,
2698 url,
2699 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162700 this,
[email protected]420ae012009-04-24 05:16:322701 autodetected);
2702}
2703
[email protected]420ae012009-04-24 05:16:322704GURL TabContents::GetAlternateErrorPageURL() const {
2705 GURL url;
2706 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2707 if (profile()->IsOffTheRecord())
2708 return url;
2709
2710 PrefService* prefs = profile()->GetPrefs();
2711 DCHECK(prefs);
2712 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152713 url = google_util::AppendGoogleLocaleParam(
2714 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322715 url = google_util::AppendGoogleTLDParam(url);
2716 }
2717 return url;
2718}
2719
2720WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062721 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552722 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062723 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322724}
2725
[email protected]fa1cf0b82010-01-15 21:49:442726void TabContents::OnIgnoredUIEvent() {
2727 if (constrained_window_count()) {
2728 ConstrainedWindow* window = *constrained_window_begin();
2729 window->FocusConstrainedWindow();
2730 }
2731}
2732
[email protected]420ae012009-04-24 05:16:322733void TabContents::OnJSOutOfMemory() {
2734 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]938e1f92010-04-01 18:09:422735 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL, true));
[email protected]420ae012009-04-24 05:16:322736}
2737
[email protected]420ae012009-04-24 05:16:322738void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2739 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342740 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322741 // delivered to a pending RenderViewHost. We must first run the onunload
2742 // handler of the old RenderViewHost before we can allow it to proceed.
2743 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2744 new_request_id);
2745}
2746
2747bool TabContents::CanBlur() const {
2748 return delegate() ? delegate()->CanBlur() : true;
2749}
2750
2751gfx::Rect TabContents::GetRootWindowResizerRect() const {
2752 if (delegate())
2753 return delegate()->GetRootWindowResizerRect();
2754 return gfx::Rect();
2755}
2756
2757void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2758 bool is_during_unload) {
2759 if (is_during_unload) {
2760 // Hang occurred while firing the beforeunload/unload handler.
2761 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112762 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322763
2764 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2765 return;
2766
2767 // If the tab hangs in the beforeunload/unload handler there's really
2768 // nothing we can do to recover. Pretend the unload listeners have
2769 // all fired and close the tab. If the hang is in the beforeunload handler
2770 // then the user will not have the option of cancelling the close.
2771 Close(rvh);
2772 return;
2773 }
2774
2775 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002776 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322777}
2778
2779void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002780 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322781}
2782
2783void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562784 net::LoadState load_state,
2785 uint64 upload_position,
2786 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322787 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562788 upload_position_ = upload_position;
2789 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292790 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192791 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292792 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532793 load_state_host_ =
2794 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322795 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2796 SetNotWaitingForResponse();
2797 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502798 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322799}
2800
[email protected]1ee614862009-07-06 20:29:182801bool TabContents::IsExternalTabContainer() const {
2802 if (!delegate())
2803 return false;
2804
2805 return delegate()->IsExternalTabContainer();
2806}
2807
[email protected]1ee614862009-07-06 20:29:182808void TabContents::DidInsertCSS() {
2809 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322810}
2811
[email protected]130efb02009-09-18 18:54:352812void TabContents::FocusedNodeChanged() {
2813 NotificationService::current()->Notify(
2814 NotificationType::FOCUS_CHANGED_IN_PAGE,
2815 Source<RenderViewHost>(render_view_host()),
2816 NotificationService::NoDetails());
2817}
2818
[email protected]420ae012009-04-24 05:16:322819void TabContents::FileSelected(const FilePath& path,
2820 int index, void* params) {
[email protected]35896a32010-06-09 08:42:512821 profile()->set_last_selected_directory(path.DirName());
[email protected]cdaf8d02010-03-30 19:52:472822 std::vector<FilePath> files;
2823 files.push_back(path);
2824 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322825}
2826
2827void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2828 void* params) {
[email protected]35896a32010-06-09 08:42:512829 if (!files.empty())
2830 profile()->set_last_selected_directory(files[0].DirName());
[email protected]cdaf8d02010-03-30 19:52:472831 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322832}
2833
2834void TabContents::FileSelectionCanceled(void* params) {
2835 // If the user cancels choosing a file to upload we pass back an
2836 // empty vector.
[email protected]cdaf8d02010-03-30 19:52:472837 render_view_host()->FilesSelectedInChooser(std::vector<FilePath>());
[email protected]420ae012009-04-24 05:16:322838}
2839
2840void TabContents::BeforeUnloadFiredFromRenderManager(
2841 bool proceed,
2842 bool* proceed_to_fire_unload) {
2843 if (delegate())
2844 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2845}
2846
2847void TabContents::UpdateRenderViewSizeForRenderManager() {
2848 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262849 gfx::Size size = view_->GetContainerSize();
2850 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2851 // here during container initialization and normal window size will be set
2852 // later. In case of tab duplication this resizing to 0x0 prevents setting
2853 // normal size later so just ignore it.
2854 if (!size.IsEmpty())
2855 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322856}
2857
2858DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222859 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322860}
2861
2862NavigationEntry*
2863TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2864 return controller_.GetLastCommittedEntry();
2865}
2866
2867bool TabContents::CreateRenderViewForRenderManager(
2868 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322869 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522870
2871 scoped_refptr<URLRequestContextGetter> request_context = request_context_;
2872 if (!request_context.get())
2873 request_context = profile()->GetRequestContext();
2874
[email protected]8ab04652010-06-12 02:47:262875 if (!render_view_host->CreateRenderView(request_context, string16()))
[email protected]420ae012009-04-24 05:16:322876 return false;
2877
2878 // Now that the RenderView has been created, we need to tell it its size.
2879 rwh_view->SetSize(view_->GetContainerSize());
2880
2881 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2882 render_view_host);
2883 return true;
2884}
2885
2886void TabContents::Observe(NotificationType type,
2887 const NotificationSource& source,
2888 const NotificationDetails& details) {
2889 switch (type.value) {
2890 case NotificationType::BOOKMARK_MODEL_LOADED:
2891 // BookmarkModel finished loading, fall through to update starred state.
2892 case NotificationType::URLS_STARRED: {
2893 // Somewhere, a URL has been starred.
2894 // Ignore notifications for profiles other than our current one.
2895 Profile* source_profile = Source<Profile>(source).ptr();
2896 if (!source_profile || !source_profile->IsSameProfile(profile()))
2897 return;
2898
2899 UpdateStarredStateForCurrentURL();
2900 break;
2901 }
2902 case NotificationType::PREF_CHANGED: {
2903 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2904 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2905 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2906 UpdateAlternateErrorPageURL();
2907 } else if (*pref_name_in == prefs::kDefaultCharset ||
2908 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2909 ) {
2910 UpdateWebPreferences();
2911 } else {
2912 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2913 }
2914 break;
2915 }
2916 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2917 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2918 break;
2919
2920 case NotificationType::NAV_ENTRY_COMMITTED: {
2921 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2922
2923 NavigationController::LoadCommittedDetails& committed_details =
2924 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2925 ExpireInfoBars(committed_details);
2926 break;
2927 }
2928
[email protected]d3ba77272009-09-03 00:06:092929#if defined(OS_LINUX)
2930 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542931 renderer_preferences_util::UpdateFromSystemSettings(
2932 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092933 render_view_host()->SyncRendererPrefs();
2934 break;
2935 }
2936#endif
2937
[email protected]6c32ce72010-03-08 05:18:062938 case NotificationType::USER_STYLE_SHEET_UPDATED:
2939 UpdateWebPreferences();
2940 break;
2941
[email protected]79580c62010-02-02 02:36:252942 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:292943 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:252944 settings_details(details);
[email protected]79580c62010-02-02 02:36:252945 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492946 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292947 if (entry)
[email protected]da0c8e92010-02-09 23:25:492948 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292949 if (settings_details.ptr()->update_all() ||
2950 settings_details.ptr()->pattern().Matches(entry_url)) {
2951 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232952 profile()->GetHostContentSettingsMap()->
2953 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252954 }
2955 break;
2956 }
2957
[email protected]e5adff72010-06-14 18:13:062958 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:572959 break;
[email protected]a888b29e62010-04-01 13:38:572960
2961 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:062962 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:572963 break;
[email protected]a888b29e62010-04-01 13:38:572964
[email protected]420ae012009-04-24 05:16:322965 default:
2966 NOTREACHED();
2967 }
2968}
[email protected]aacd7cc2009-09-02 14:51:102969
[email protected]98aa0b52010-05-06 17:03:082970void TabContents::UpdateExtensionAppIcon(Extension* extension) {
2971 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432972
[email protected]a888b29e62010-04-01 13:38:572973 if (extension) {
[email protected]98aa0b52010-05-06 17:03:082974 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
2975 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:572976 extension,
2977 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
2978 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
2979 Extension::EXTENSION_ICON_SMALLISH),
2980 ImageLoadingTracker::CACHE);
2981 } else {
[email protected]98aa0b52010-05-06 17:03:082982 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:572983 }
2984}
2985
2986Extension* TabContents::GetExtensionContaining(const GURL& url) {
2987 ExtensionsService* extensions_service = profile()->GetExtensionsService();
2988 if (!extensions_service)
2989 return NULL;
2990
2991 Extension* extension = extensions_service->GetExtensionByURL(url);
2992 return extension ?
2993 extension : extensions_service->GetExtensionByWebExtent(url);
2994}
2995
[email protected]a888b29e62010-04-01 13:38:572996void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
2997 int index) {
2998 if (image) {
[email protected]98aa0b52010-05-06 17:03:082999 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573000 NotifyNavigationStateChanged(INVALIDATE_TAB);
3001 }
3002}
3003
[email protected]beb440c2009-11-06 04:08:543004std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3005 bool is_alert) {
3006 if (!frame_url.has_host())
3007 return l10n_util::GetString(
3008 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3009 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3010
3011 // We really only want the scheme, hostname, and port.
3012 GURL::Replacements replacements;
3013 replacements.ClearUsername();
3014 replacements.ClearPassword();
3015 replacements.ClearPath();
3016 replacements.ClearQuery();
3017 replacements.ClearRef();
3018 GURL clean_url = frame_url.ReplaceComponents(replacements);
3019
3020 // TODO(brettw) it should be easier than this to do the correct language
3021 // handling without getting the accept language from the profile.
3022 std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0,
[email protected]ddd231e2010-06-29 20:35:193023 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)));
[email protected]beb440c2009-11-06 04:08:543024 // Force URL to have LTR directionality.
[email protected]4a4afe32010-05-05 01:39:563025 base::i18n::GetDisplayStringInLTRDirectionality(&base_address);
[email protected]beb440c2009-11-06 04:08:543026
3027 return l10n_util::GetStringF(
3028 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
3029 base_address);
3030}
3031
3032gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3033 return view_->GetTopLevelNativeWindow();
3034}
3035
3036void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3037 bool success,
3038 const std::wstring& prompt) {
3039 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3040 if (is_showing_before_unload_dialog_ && !success) {
3041 // If a beforeunload dialog is canceled, we need to stop the throbber from
3042 // spinning, since we forced it to start spinning in Navigate.
3043 DidStopLoading();
3044
3045 tab_close_start_time_ = base::TimeTicks();
3046 }
3047 is_showing_before_unload_dialog_ = false;
3048 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3049}
3050
3051void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3052 set_suppress_javascript_messages(suppress_message_boxes);
3053}
3054
[email protected]41fc0322009-09-04 22:23:403055void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103056 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3057}
[email protected]f45d2a72010-03-08 23:28:353058
3059void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3060 app_icon_ = app_icon;
3061 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3062}
[email protected]ea68c06a2010-04-23 17:25:373063
3064// After a successful *new* login attempt, we take the PasswordFormManager in
3065// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3066// the user makes up their mind with the "save password" infobar. Note if the
3067// login is one we already know about, the end of the line is
3068// provisional_save_manager_ because we just update it on success and so such
3069// forms never end up in an infobar.
3070class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3071 public:
3072 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463073 PasswordFormManager* form_to_save)
3074 : ConfirmInfoBarDelegate(tab_contents),
3075 form_to_save_(form_to_save),
3076 infobar_response_(kNoResponse) {
[email protected]ea68c06a2010-04-23 17:25:373077 }
3078
3079 virtual ~SavePasswordInfoBarDelegate() { }
3080
3081 // Overridden from ConfirmInfoBarDelegate:
3082 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463083 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
3084 infobar_response_, kNumResponseTypes);
[email protected]ea68c06a2010-04-23 17:25:373085 delete this;
3086 }
3087
3088 virtual std::wstring GetMessageText() const {
3089 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
3090 }
3091
3092 virtual SkBitmap* GetIcon() const {
3093 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3094 IDR_INFOBAR_SAVE_PASSWORD);
3095 }
3096
3097 virtual int GetButtons() const {
3098 return BUTTON_OK | BUTTON_CANCEL;
3099 }
3100
3101 virtual std::wstring GetButtonLabel(InfoBarButton button) const {
3102 if (button == BUTTON_OK)
3103 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
3104 if (button == BUTTON_CANCEL)
3105 return l10n_util::GetString(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
3106 NOTREACHED();
3107 return std::wstring();
3108 }
3109
3110 virtual bool Accept() {
3111 DCHECK(form_to_save_.get());
3112 form_to_save_->Save();
[email protected]12bb6822010-06-16 02:00:463113 infobar_response_ = kRememberPassword;
[email protected]ea68c06a2010-04-23 17:25:373114 return true;
3115 }
3116
3117 virtual bool Cancel() {
3118 DCHECK(form_to_save_.get());
3119 form_to_save_->PermanentlyBlacklist();
[email protected]12bb6822010-06-16 02:00:463120 infobar_response_ = kDontRememberPassword;
[email protected]ea68c06a2010-04-23 17:25:373121 return true;
3122 }
3123
3124 private:
3125 // The PasswordFormManager managing the form we're asking the user about,
3126 // and should update as per her decision.
3127 scoped_ptr<PasswordFormManager> form_to_save_;
3128
[email protected]12bb6822010-06-16 02:00:463129 // Used to track the results we get from the info bar.
3130 enum ResponseType {
3131 kNoResponse = 0,
3132 kRememberPassword,
3133 kDontRememberPassword,
3134 kNumResponseTypes,
3135 };
3136 ResponseType infobar_response_;
3137
[email protected]ea68c06a2010-04-23 17:25:373138 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3139};
3140
3141void TabContents::FillPasswordForm(
3142 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
3143 render_view_host()->FillPasswordForm(form_data);
3144}
3145
3146void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3147 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3148}
3149
3150Profile* TabContents::GetProfileForPasswordManager() {
3151 return profile();
3152}
3153
3154bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3155 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3156}