blob: e3d1870c790c41692e78cca23afb9890f0930fd5 [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]b3df5a42010-05-11 14:31:09297 geolocation_settings_state_(profile),
[email protected]0cce15f2010-05-21 16:58:39298 closed_by_user_gesture_(false) {
[email protected]0de80162010-02-03 04:52:35299 ClearBlockedContentSettings();
[email protected]7ff431e2010-01-07 18:18:54300 renderer_preferences_util::UpdateFromSystemSettings(
301 &renderer_preferences_, profile);
302
[email protected]16779842009-07-08 23:45:29303#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02304 // Make sure the thumbnailer is started before starting the render manager.
305 // The thumbnailer will want to listen for RVH creations, one of which will
306 // happen in RVHManager::Init.
307 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
308 if (generator)
309 generator->StartThumbnailing();
310#endif
311
[email protected]12636df2009-09-28 22:32:21312 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32313
[email protected]34ac70502009-09-25 17:07:23314 // We have the initial size of the view be based on the size of the passed in
315 // tab contents (normally a tab from the same window).
316 view_->CreateView(base_tab_contents ?
317 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32318
319 // Register for notifications about all interested prefs change.
320 PrefService* prefs = profile->GetPrefs();
321 if (prefs) {
322 for (int i = 0; i < kPrefsToObserveLength; ++i)
323 prefs->AddPrefObserver(kPrefsToObserve[i], this);
324 }
325
326 // Register for notifications about URL starredness changing on any profile.
327 registrar_.Add(this, NotificationType::URLS_STARRED,
328 NotificationService::AllSources());
329 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
330 NotificationService::AllSources());
331 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
332 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09333#if defined(OS_LINUX)
334 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
335 NotificationService::AllSources());
336#endif
[email protected]420ae012009-04-24 05:16:32337
[email protected]6c32ce72010-03-08 05:18:06338 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
339 NotificationService::AllSources());
340
[email protected]79580c62010-02-02 02:36:25341 // Register for notifications about content setting changes.
342 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
343 NotificationService::AllSources());
344
[email protected]a888b29e62010-04-01 13:38:57345 // Listen for extension changes so we can update extension_for_current_page_.
346 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
347 NotificationService::AllSources());
348 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
349 NotificationService::AllSources());
350 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
351 NotificationService::AllSources());
352
[email protected]c8865482009-07-23 20:40:10353 // Set-up the showing of the omnibox search infobar if applicable.
354 if (OmniboxSearchHint::IsEnabled(profile))
355 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35356}
initial.commit09911bf2008-07-26 23:55:29357
358TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32359 is_being_destroyed_ = true;
360
[email protected]bfe4c1582009-10-02 18:11:09361 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32362 registrar_.RemoveAll();
363
364 // Unregister the notifications of all observed prefs change.
365 PrefService* prefs = profile()->GetPrefs();
366 if (prefs) {
367 for (int i = 0; i < kPrefsToObserveLength; ++i)
368 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
369 }
370
[email protected]420ae012009-04-24 05:16:32371 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00372 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32373
[email protected]420ae012009-04-24 05:16:32374 // First cleanly close all child windows.
375 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
376 // some of these to close. CloseWindows is async, so it might get called
377 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49378 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32379
[email protected]8cc8d492010-02-02 10:40:49380 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13381 if (blocked_popups_)
382 blocked_popups_->Destroy();
383
[email protected]420ae012009-04-24 05:16:32384 // Notify any observer that have a reference on this tab contents.
385 NotificationService::current()->Notify(
386 NotificationType::TAB_CONTENTS_DESTROYED,
387 Source<TabContents>(this),
388 NotificationService::NoDetails());
389
[email protected]1e5e74f2009-05-27 20:55:12390 // Notify any lasting InfobarDelegates that have not yet been removed that
391 // whatever infobar they were handling in this TabContents has closed,
392 // because the TabContents is going away entirely.
393 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
394 // notification may trigger infobars calls that access their delegate. (and
395 // some implementations of InfoBarDelegate do delete themselves on
396 // InfoBarClosed()).
397 for (int i = 0; i < infobar_delegate_count(); ++i) {
398 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
399 delegate->InfoBarClosed();
400 }
401 infobar_delegates_.clear();
402
[email protected]420ae012009-04-24 05:16:32403 // TODO(brettw) this should be moved to the view.
404#if defined(OS_WIN)
405 // If we still have a window handle, destroy it. GetNativeView can return
406 // NULL if this contents was part of a window that closed.
407 if (GetNativeView())
408 ::DestroyWindow(GetNativeView());
409#endif
[email protected]7ab1e7d62009-10-14 23:32:01410
411 // OnCloseStarted isn't called in unit tests.
412 if (!tab_close_start_time_.is_null()) {
413 UMA_HISTOGRAM_TIMES("Tab.Close",
414 base::TimeTicks::Now() - tab_close_start_time_);
415 }
initial.commit09911bf2008-07-26 23:55:29416}
417
[email protected]d5f942ba2008-09-26 19:30:34418// static
419void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32420 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
421
422 WebPreferences pref_defaults;
423 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
424 pref_defaults.javascript_enabled);
425 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
426 pref_defaults.web_security_enabled);
427 prefs->RegisterBooleanPref(
428 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
429 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
430 pref_defaults.loads_images_automatically);
431 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
432 pref_defaults.plugins_enabled);
433 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
434 pref_defaults.dom_paste_enabled);
435 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
436 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14437 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32438 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
439 pref_defaults.text_areas_are_resizable);
440 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
441 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36442 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
443 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32444
445 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
446 IDS_ACCEPT_LANGUAGES);
447 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
448 IDS_DEFAULT_ENCODING);
449 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
450 IDS_STANDARD_FONT_IS_SERIF);
451 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
452 IDS_FIXED_FONT_FAMILY);
453 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
454 IDS_SERIF_FONT_FAMILY);
455 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
456 IDS_SANS_SERIF_FONT_FAMILY);
457 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
458 IDS_CURSIVE_FONT_FAMILY);
459 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
460 IDS_FANTASY_FONT_FAMILY);
461 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
462 IDS_DEFAULT_FONT_SIZE);
463 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
464 IDS_DEFAULT_FIXED_FONT_SIZE);
465 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
466 IDS_MINIMUM_FONT_SIZE);
467 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
468 IDS_MINIMUM_LOGICAL_FONT_SIZE);
469 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
470 IDS_USES_UNIVERSAL_DETECTOR);
471 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
472 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29473}
474
[email protected]13367f72009-07-08 16:39:02475// Returns true if contains content rendered by an extension.
476bool TabContents::HostsExtension() const {
477 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34478}
479
[email protected]cf28ec52010-04-09 22:56:34480AutoFillManager* TabContents::GetAutoFillManager() {
481 if (autofill_manager_.get() == NULL)
482 autofill_manager_.reset(new AutoFillManager(this));
483 return autofill_manager_.get();
484}
485
[email protected]6e95706d2009-04-23 22:55:01486PasswordManager* TabContents::GetPasswordManager() {
487 if (password_manager_.get() == NULL)
488 password_manager_.reset(new PasswordManager(this));
489 return password_manager_.get();
490}
491
492PluginInstaller* TabContents::GetPluginInstaller() {
493 if (plugin_installer_.get() == NULL)
494 plugin_installer_.reset(new PluginInstaller(this));
495 return plugin_installer_.get();
496}
497
[email protected]8cb5d5b2010-02-09 11:36:16498RenderProcessHost* TabContents::GetRenderProcessHost() const {
499 return render_manager_.current_host()->process();
500}
501
[email protected]98aa0b52010-05-06 17:03:08502void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46503 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08504 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10505
[email protected]98aa0b52010-05-06 17:03:08506 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57507
[email protected]fca656c2010-02-10 20:30:10508 NotificationService::current()->Notify(
509 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
510 Source<TabContents>(this),
511 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49512}
513
[email protected]98aa0b52010-05-06 17:03:08514void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
515 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40516 return;
517
518 ExtensionsService* extension_service = profile()->GetExtensionsService();
519 if (extension_service && extension_service->is_ready()) {
520 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08521 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40522 if (extension)
[email protected]98aa0b52010-05-06 17:03:08523 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40524 }
525}
526
[email protected]98aa0b52010-05-06 17:03:08527SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]8eb043b2010-04-30 07:19:51528 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because
529 // for those windows, we already have a big icon in the top-left outside any
530 // tab. Having big tab icons too looks kinda redonk.
[email protected]06821f42d2010-05-03 22:34:35531 Browser* browser = delegate_ ? delegate_->GetBrowser() : NULL;
532 if (browser && browser->type() == Browser::TYPE_EXTENSION_APP)
[email protected]8eb043b2010-04-30 07:19:51533 return NULL;
[email protected]8eb043b2010-04-30 07:19:51534
[email protected]98aa0b52010-05-06 17:03:08535 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51536 return NULL;
537
[email protected]98aa0b52010-05-06 17:03:08538 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51539}
540
[email protected]d5f942ba2008-09-26 19:30:34541const GURL& TabContents::GetURL() const {
542 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57543 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54544 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34545}
546
[email protected]96d185d2009-04-24 03:28:54547const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55548 // Transient entries take precedence. They are used for interstitial pages
549 // that are shown on top of existing pages.
550 NavigationEntry* entry = controller_.GetTransientEntry();
551 if (entry)
552 return entry->GetTitleForDisplay(&controller_);
553
[email protected]96d185d2009-04-24 03:28:54554 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
555 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
556 if (our_dom_ui) {
557 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55558 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54559 if (!(entry && entry->IsViewSourceMode())) {
560 // Give the DOM UI the chance to override our title.
561 const string16& title = our_dom_ui->overridden_title();
562 if (!title.empty())
563 return title;
564 }
565 }
566
567 // We use the title for the last committed entry rather than a pending
568 // navigation entry. For example, when the user types in a URL, we want to
569 // keep the old page's title until the new load has committed and we get a new
570 // title.
[email protected]96d185d2009-04-24 03:28:54571 entry = controller_.GetLastCommittedEntry();
572 if (entry)
573 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54574 return EmptyString16();
575}
576
[email protected]bbbc1ef2010-02-12 18:03:41577// static
578string16 TabContents::GetDefaultTitle() {
579 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
580}
581
[email protected]d5f942ba2008-09-26 19:30:34582int32 TabContents::GetMaxPageID() {
583 if (GetSiteInstance())
584 return GetSiteInstance()->max_page_id();
585 else
586 return max_page_id_;
587}
588
589void TabContents::UpdateMaxPageID(int32 page_id) {
590 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34591 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34592 // testing.
593 if (GetSiteInstance())
594 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16595 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34596}
597
[email protected]96d185d2009-04-24 03:28:54598SiteInstance* TabContents::GetSiteInstance() const {
599 return render_manager_.current_host()->site_instance();
600}
601
[email protected]96d185d2009-04-24 03:28:54602bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15603 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54604 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15605 if (entry && (entry->IsViewSourceMode() ||
606 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54607 return true;
[email protected]8ab24cc2009-11-13 20:56:15608 }
[email protected]83e3895b2009-06-11 00:07:16609
[email protected]96d185d2009-04-24 03:28:54610 DOMUI* dom_ui = GetDOMUIForCurrentState();
611 if (dom_ui)
612 return !dom_ui->should_hide_url();
613 return true;
614}
615
[email protected]d5f942ba2008-09-26 19:30:34616SkBitmap TabContents::GetFavIcon() const {
617 // Like GetTitle(), we also want to use the favicon for the last committed
618 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57619 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47620 if (entry)
621 return entry->favicon().bitmap();
622
[email protected]ce3fa3c2009-04-20 19:55:57623 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34624 if (entry)
625 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34626 return SkBitmap();
627}
628
[email protected]0b303cc2009-09-28 22:35:15629bool TabContents::FavIconIsValid() const {
630 NavigationEntry* entry = controller_.GetTransientEntry();
631 if (entry)
632 return entry->favicon().is_valid();
633
634 entry = controller_.GetLastCommittedEntry();
635 if (entry)
636 return entry->favicon().is_valid();
637
638 return false;
639}
640
[email protected]96d185d2009-04-24 03:28:54641bool TabContents::ShouldDisplayFavIcon() {
642 // Always display a throbber during pending loads.
643 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
644 return true;
645
646 DOMUI* dom_ui = GetDOMUIForCurrentState();
647 if (dom_ui)
648 return !dom_ui->hide_favicon();
649 return true;
650}
651
[email protected]2d5a3592010-01-30 04:29:52652bool TabContents::IsContentBlocked(ContentSettingsType content_type) const {
[email protected]aa43bc02010-06-21 13:46:36653 DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
654 << "Geolocation settings handled by GeolocationContentSettingsMap";
[email protected]8cc8d492010-02-02 10:40:49655 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS)
656 return blocked_popups_ != NULL;
657
[email protected]0de80162010-02-03 04:52:35658 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES ||
659 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT ||
[email protected]3dbb80b2010-02-09 22:41:20660 content_type == CONTENT_SETTINGS_TYPE_PLUGINS ||
661 content_type == CONTENT_SETTINGS_TYPE_COOKIES)
[email protected]0de80162010-02-03 04:52:35662 return content_blocked_[content_type];
663
[email protected]3dbb80b2010-02-09 22:41:20664 NOTREACHED();
[email protected]2d5a3592010-01-30 04:29:52665 return false;
666}
667
[email protected]96d185d2009-04-24 03:28:54668std::wstring TabContents::GetStatusText() const {
669 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
670 return std::wstring();
671
672 switch (load_state_) {
673 case net::LOAD_STATE_WAITING_FOR_CACHE:
674 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04675 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
676 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54677 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
678 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
679 case net::LOAD_STATE_RESOLVING_HOST:
680 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
681 case net::LOAD_STATE_CONNECTING:
682 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06683 case net::LOAD_STATE_SSL_HANDSHAKE:
684 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54685 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56686 if (upload_size_)
687 return l10n_util::GetStringF(
688 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
689 static_cast<int>((100 * upload_position_) / upload_size_));
690 else
691 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54692 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
693 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
694 load_state_host_);
695 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
696 case net::LOAD_STATE_IDLE:
697 case net::LOAD_STATE_READING_RESPONSE:
698 break;
699 }
700
701 return std::wstring();
702}
703
[email protected]d5f942ba2008-09-26 19:30:34704void TabContents::SetIsCrashed(bool state) {
705 if (state == is_crashed_)
706 return;
707
708 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50709 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34710}
711
[email protected]744ef172009-10-16 21:53:46712void TabContents::PageActionStateChanged() {
713 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00714}
[email protected]ce5c4502009-05-06 16:46:11715
[email protected]d5f942ba2008-09-26 19:30:34716void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
717 if (delegate_)
718 delegate_->NavigationStateChanged(this, changed_flags);
719}
720
[email protected]96d185d2009-04-24 03:28:54721void TabContents::DidBecomeSelected() {
722 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16723 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
724 if (rwhv) {
725 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43726#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16727 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43728#endif
729 }
[email protected]96d185d2009-04-24 03:28:54730
[email protected]8cb5d5b2010-02-09 11:36:16731 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54732}
733
734void TabContents::WasHidden() {
735 if (!capturing_contents()) {
736 // |render_view_host()| can be NULL if the user middle clicks a link to open
737 // a tab in then background, then closes the tab before selecting it. This
738 // is because closing the tab calls TabContents::Destroy(), which removes
739 // the |render_view_host()|; then when we actually destroy the window,
740 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16741 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
742 if (rwhv)
743 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54744 }
745
746 NotificationService::current()->Notify(
747 NotificationType::TAB_CONTENTS_HIDDEN,
748 Source<TabContents>(this),
749 NotificationService::NoDetails());
750}
751
[email protected]d5f942ba2008-09-26 19:30:34752void TabContents::Activate() {
753 if (delegate_)
754 delegate_->ActivateContents(this);
755}
756
[email protected]96d185d2009-04-24 03:28:54757void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16758 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
759 if (rwhv)
760 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54761}
762
763void TabContents::HideContents() {
764 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
765 // our superclass HideContents(), because some callers want to be very picky
766 // about the order in which these get called. In addition to making the code
767 // here practically impossible to understand, this also means we end up
768 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34769 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54770 WasHidden();
771}
772
[email protected]c0588052008-10-27 23:01:50773void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34774 WindowOpenDisposition disposition,
775 PageTransition::Type transition) {
776 if (delegate_)
[email protected]c0588052008-10-27 23:01:50777 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34778}
779
[email protected]1ccb3568d2010-02-19 10:51:16780bool TabContents::NavigateToPendingEntry(
781 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54782 const NavigationEntry& entry = *controller_.pending_entry();
783
784 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
785 if (!dest_render_view_host)
786 return false; // Unable to create the desired render view host.
787
[email protected]770dd8b2010-05-24 18:11:39788 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
789 dest_render_view_host->EnablePreferredSizeChangedMode(
790 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
791 }
[email protected]9fb325e2010-05-06 18:23:24792
[email protected]0352e5472010-04-29 00:11:40793 // For security, we should never send non-DOM-UI URLs (other than about:blank)
794 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58795 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40796 bool is_allowed_in_dom_ui_renderer =
797 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
798 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58799 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40800 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58801
[email protected]96d185d2009-04-24 03:28:54802 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12803 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32804 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00805 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
806 dest_render_view_host,
807 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32808 }
[email protected]96d185d2009-04-24 03:28:54809
810 // Used for page load time metrics.
811 current_load_start_ = base::TimeTicks::Now();
812
813 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34814 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00815 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34816 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54817
818 if (entry.page_id() == -1) {
819 // HACK!! This code suppresses javascript: URLs from being added to
820 // session history, which is what we want to do for javascript: URLs that
821 // do not generate content. What we really need is a message from the
822 // renderer telling us that a new page was not created. The same message
823 // could be used for mailto: URLs and the like.
824 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
825 return false;
826 }
827
828 // Clear any provisional password saves - this stops password infobars
829 // showing up on pages the user navigates to while the right page is
830 // loading.
831 GetPasswordManager()->ClearProvisionalSave();
832
[email protected]1ccb3568d2010-02-19 10:51:16833 if (reload_type != NavigationController::NO_RELOAD &&
834 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48835 FaviconService* favicon_service =
836 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
837 if (favicon_service)
838 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54839 }
840
[email protected]d5f942ba2008-09-26 19:30:34841 return true;
842}
843
[email protected]96d185d2009-04-24 03:28:54844void TabContents::Stop() {
845 render_manager_.Stop();
846 printing_.Stop();
847}
848
[email protected]96d185d2009-04-24 03:28:54849void TabContents::DisassociateFromPopupCount() {
850 render_view_host()->DisassociateFromPopupCount();
851}
852
853TabContents* TabContents::Clone() {
854 // We create a new SiteInstance so that the new tab won't share processes
855 // with the old one. This can be changed in the future if we need it to share
856 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32857 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54858 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21859 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54860 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08861 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08862 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54863 return tc;
864}
865
[email protected]4d677202009-07-19 07:37:12866void TabContents::ShowPageInfo(const GURL& url,
867 const NavigationEntry::SSLStatus& ssl,
868 bool show_history) {
869 if (!delegate_)
870 return;
871
[email protected]bb678332009-07-21 00:15:50872 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12873}
874
initial.commit09911bf2008-07-26 23:55:29875ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28876 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29877 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28878 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29879 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44880
881 if (child_windows_.size() == 1) {
882 window->ShowConstrainedWindow();
883 BlockTabContent(true);
884 }
885
initial.commit09911bf2008-07-26 23:55:29886 return window;
887}
888
[email protected]fa1cf0b82010-01-15 21:49:44889void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55890 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
891 if (rwhv)
892 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44893 render_view_host()->set_ignore_input_events(blocked);
894 if (delegate_)
895 delegate_->SetTabContentBlocked(this, blocked);
896}
897
initial.commit09911bf2008-07-26 23:55:29898void TabContents::AddNewContents(TabContents* new_contents,
899 WindowOpenDisposition disposition,
900 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29901 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29902 if (!delegate_)
903 return;
904
[email protected]35f7d212009-04-29 21:19:27905 if ((disposition == NEW_POPUP) && !user_gesture &&
906 !CommandLine::ForCurrentProcess()->HasSwitch(
907 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22908 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31909 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29910 delegate_->GetConstrainingContents(this)->AddPopup(
911 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31912 } else {
[email protected]304f8792009-08-19 21:28:09913#if defined(OS_CHROMEOS)
914 if (disposition == NEW_POPUP) {
915 // If the popup is bigger than a given factor of the screen, then
916 // turn it into a foreground tab (on chrome os only)
917 GdkScreen* screen = gdk_screen_get_default();
918 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
919 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
920 if (initial_pos.width() > max_width ||
921 initial_pos.height() > max_height) {
922 disposition = NEW_FOREGROUND_TAB;
923 }
924 }
925#endif
926
[email protected]0aa55312008-10-17 21:53:08927 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29928 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
929 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49930 NotificationService::current()->Notify(
931 NotificationType::TAB_ADDED,
932 Source<TabContentsDelegate>(delegate_),
933 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29934 }
initial.commit09911bf2008-07-26 23:55:29935
[email protected]8cc8d492010-02-02 10:40:49936 // TODO(pkasting): Why is this necessary?
937 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:29938}
939
[email protected]bcd9dc42010-01-23 16:38:18940bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:20941 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:20942 bool is_js_code, const std::string& code_string,
943 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51944 RenderViewHost* host = render_view_host();
945 if (!host)
946 return false;
947
948 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
949 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
950 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35951}
952
[email protected]96d185d2009-04-24 03:28:54953void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49954 if (is_being_destroyed_)
955 return;
956 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40957 render_view_host()->AllowScriptToClose(!visible);
[email protected]0de80162010-02-03 04:52:35958 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:24959 delegate_->OnContentSettingsChange(this);
[email protected]96d185d2009-04-24 03:28:54960}
961
[email protected]5c9e97a2009-09-09 23:48:30962gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54963 return view_->GetContentNativeView();
964}
965
966gfx::NativeView TabContents::GetNativeView() const {
967 return view_->GetNativeView();
968}
969
970void TabContents::GetContainerBounds(gfx::Rect *out) const {
971 view_->GetContainerBounds(out);
972}
973
974void TabContents::Focus() {
975 view_->Focus();
976}
977
[email protected]90daadb42009-06-08 21:27:28978void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54979 if (showing_interstitial_page()) {
980 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
981 return;
982 }
[email protected]96d185d2009-04-24 03:28:54983 render_view_host()->SetInitialFocus(reverse);
984}
985
986bool TabContents::FocusLocationBarByDefault() {
987 DOMUI* dom_ui = GetDOMUIForCurrentState();
988 if (dom_ui)
989 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43990 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25991 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43992 return true;
[email protected]96d185d2009-04-24 03:28:54993 return false;
994}
995
[email protected]a26dc362010-04-23 01:48:58996void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38997 if (delegate())
[email protected]a26dc362010-04-23 01:48:58998 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38999}
1000
[email protected]616ed5a2008-11-21 22:27:241001void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321002 if (delegate_ && !delegate_->infobars_enabled()) {
1003 delegate->InfoBarClosed();
1004 return;
1005 }
1006
[email protected]616ed5a2008-11-21 22:27:241007 // Look through the existing InfoBarDelegates we have for a match. If we've
1008 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051009 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451010 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1011 // Tell the new infobar to close so that it can clean itself up.
1012 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241013 return;
[email protected]6d27a7b2009-12-18 23:25:451014 }
[email protected]616ed5a2008-11-21 22:27:241015 }
1016
1017 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561018 NotificationService::current()->Notify(
1019 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1020 Source<TabContents>(this),
1021 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241022
1023 // Add ourselves as an observer for navigations the first time a delegate is
1024 // added. We use this notification to expire InfoBars that need to expire on
1025 // page transitions.
1026 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561027 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571028 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241029 }
1030}
1031
1032void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321033 if (delegate_ && !delegate_->infobars_enabled()) {
1034 return;
1035 }
1036
[email protected]616ed5a2008-11-21 22:27:241037 std::vector<InfoBarDelegate*>::iterator it =
1038 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1039 if (it != infobar_delegates_.end()) {
1040 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561041 NotificationService::current()->Notify(
1042 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1043 Source<TabContents>(this),
1044 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:051045 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:241046
[email protected]6a02963e2009-01-06 16:58:031047 // Remove ourselves as an observer if we are tracking no more InfoBars.
1048 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:561049 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571050 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031051 }
[email protected]616ed5a2008-11-21 22:27:241052 }
1053}
[email protected]3edd9522009-03-04 22:19:411054
[email protected]f81821c2009-08-07 01:29:471055void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1056 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321057 if (delegate_ && !delegate_->infobars_enabled()) {
1058 new_delegate->InfoBarClosed();
1059 return;
1060 }
1061
[email protected]f81821c2009-08-07 01:29:471062 std::vector<InfoBarDelegate*>::iterator it =
1063 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1064 DCHECK(it != infobar_delegates_.end());
1065
1066 // Notify the container about the change of plans.
1067 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1068 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1069 old_delegate, new_delegate));
1070 NotificationService::current()->Notify(
1071 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1072 Source<TabContents>(this),
1073 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1074
1075 // Remove the old one.
1076 infobar_delegates_.erase(it);
1077
1078 // Add the new one.
1079 infobar_delegates_.push_back(new_delegate);
1080}
1081
[email protected]20ede072009-10-06 00:28:351082bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271083 if (showing_interstitial_page())
1084 return false;
1085
[email protected]96d185d2009-04-24 03:28:541086 // See GetDOMUIForCurrentState() comment for more info. This case is very
1087 // similar, but for non-first loads, we want to use the committed entry. This
1088 // is so the bookmarks bar disappears at the same time the page does.
1089 if (controller_.GetLastCommittedEntry()) {
1090 // Not the first load, always use the committed DOM UI.
1091 if (render_manager_.dom_ui())
1092 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1093 return false; // Default.
1094 }
1095
1096 // When it's the first load, we know either the pending one or the committed
1097 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1098 // of them will be valid, so we can just check both.
1099 if (render_manager_.pending_dom_ui())
1100 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1101 if (render_manager_.dom_ui())
1102 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1103 return false; // Default.
1104}
1105
[email protected]d8f16ae2009-08-30 03:47:261106bool TabContents::IsExtensionShelfAlwaysVisible() {
1107 // See GetDOMUIForCurrentState() comment for more info. This case is very
1108 // similar, but for non-first loads, we want to use the committed entry. This
1109 // is so the bookmarks bar disappears at the same time the page does.
1110 if (controller_.GetLastCommittedEntry()) {
1111 // Not the first load, always use the committed DOM UI.
1112 if (render_manager_.dom_ui())
1113 return render_manager_.dom_ui()->force_extension_shelf_visible();
1114 return false; // Default.
1115 }
1116
1117 // When it's the first load, we know either the pending one or the committed
1118 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1119 // of them will be valid, so we can just check both.
1120 if (render_manager_.pending_dom_ui())
1121 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
1122 if (render_manager_.dom_ui())
1123 return render_manager_.dom_ui()->force_extension_shelf_visible();
1124 return false; // Default.
1125}
1126
[email protected]3edd9522009-03-04 22:19:411127void TabContents::ToolbarSizeChanged(bool is_animating) {
1128 TabContentsDelegate* d = delegate();
1129 if (d)
1130 d->ToolbarSizeChanged(this, is_animating);
1131}
[email protected]616ed5a2008-11-21 22:27:241132
[email protected]fc6fb7fb2009-11-07 02:35:041133bool TabContents::CanDownload(int request_id) {
1134 TabContentsDelegate* d = delegate();
1135 if (d)
1136 return d->CanDownload(request_id);
1137 return true;
1138}
1139
[email protected]d5f942ba2008-09-26 19:30:341140void TabContents::OnStartDownload(DownloadItem* download) {
1141 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341142
1143 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311144 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341145
[email protected]c70f9b82010-04-21 07:31:111146 if (tab_contents && tab_contents->delegate()) {
[email protected]59560e0b2009-06-04 03:30:221147 tab_contents->delegate()->OnStartDownload(download);
[email protected]c70f9b82010-04-21 07:31:111148 // If the download occurs in a new tab, close it
1149 if (controller_.IsInitialNavigation() && (tab_contents == this))
1150 delegate()->CloseContents(this);
1151 }
[email protected]3edd9522009-03-04 22:19:411152}
[email protected]3edd9522009-03-04 22:19:411153
[email protected]d5f942ba2008-09-26 19:30:341154void TabContents::WillClose(ConstrainedWindow* window) {
1155 ConstrainedWindowList::iterator it =
1156 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441157 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341158 if (it != child_windows_.end())
1159 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371160 if (child_windows_.size() > 0) {
1161 if (removed_topmost_window) {
1162 child_windows_[0]->ShowConstrainedWindow();
1163 }
[email protected]fa1cf0b82010-01-15 21:49:441164 BlockTabContent(true);
1165 } else {
1166 BlockTabContent(false);
1167 }
[email protected]66ba4932009-06-04 19:22:131168}
[email protected]d5f942ba2008-09-26 19:30:341169
[email protected]66ba4932009-06-04 19:22:131170void TabContents::WillCloseBlockedPopupContainer(
1171 BlockedPopupContainer* container) {
1172 DCHECK(blocked_popups_ == container);
1173 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491174 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341175}
1176
[email protected]d5f942ba2008-09-26 19:30:341177void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351178#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061179 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351180#endif
[email protected]d5f942ba2008-09-26 19:30:341181}
1182
[email protected]c1dc9f132009-11-20 23:13:211183void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121184 bool forward_direction,
1185 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211186 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011187 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211188 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531189 string16 last_search_prepopulate_text =
1190 FindBarState::GetLastPrepopulateText(profile());
1191
[email protected]87fae512009-12-11 02:20:211192 // Try the last thing we searched for on this tab, then the last thing
1193 // searched for on any tab.
1194 if (!previous_find_text_.empty())
1195 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531196 else if (!last_search_prepopulate_text.empty())
1197 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211198 else
[email protected]e491f1c2009-05-22 20:28:121199 return;
[email protected]e491f1c2009-05-22 20:28:121200 }
[email protected]6e95706d2009-04-23 22:55:011201
[email protected]101c90e2009-10-26 21:14:441202 // Keep track of the previous search.
1203 previous_find_text_ = find_text_;
1204
[email protected]6e95706d2009-04-23 22:55:011205 // This is a FindNext operation if we are searching for the same text again,
1206 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1207 // exception to this is if the Find was aborted (then we don't want FindNext
1208 // because the highlighting has been cleared and we need it to reappear). We
1209 // therefore treat FindNext after an aborted Find operation as a full fledged
1210 // Find.
[email protected]c1dc9f132009-11-20 23:13:211211 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121212 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011213 !find_op_aborted_;
1214 if (!find_next)
1215 current_find_request_id_ = find_request_id_counter_++;
1216
[email protected]c1dc9f132009-11-20 23:13:211217 if (!search_string.empty())
1218 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121219 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011220
1221 find_op_aborted_ = false;
1222
1223 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531224 FindBarState* find_bar_state = profile()->GetFindBarState();
1225 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011226 render_view_host()->StartFinding(current_find_request_id_,
1227 find_text_,
1228 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121229 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011230 find_next);
1231}
1232
[email protected]5bc8fe92010-03-11 18:19:001233void TabContents::StopFinding(
1234 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011235 if (selection_action == FindBarController::kClearSelection) {
1236 // kClearSelection means the find string has been cleared by the user, but
1237 // the UI has not been dismissed. In that case we want to clear the
1238 // previously remembered search (http://crbug.com/42639).
1239 previous_find_text_ = string16();
1240 } else {
[email protected]2d2dffc2009-06-09 21:41:001241 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011242 if (!find_text_.empty())
1243 previous_find_text_ = find_text_;
1244 }
[email protected]101c90e2009-10-26 21:14:441245 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011246 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121247 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001248 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011249}
1250
[email protected]420ae012009-04-24 05:16:321251void TabContents::OnSavePage() {
1252 // If we can not save the page, try to download it.
1253 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1254 DownloadManager* dlm = profile()->GetDownloadManager();
1255 const GURL& current_page_url = GetURL();
1256 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221257 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321258 return;
1259 }
1260
1261 Stop();
1262
1263 // Create the save package and possibly prompt the user for the name to save
1264 // the page as. The user prompt is an asynchronous operation that runs on
1265 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221266 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321267 save_package_->GetSaveInfo();
1268}
1269
1270// Used in automated testing to bypass prompting the user for file names.
1271// Instead, the names and paths are hard coded rather than running them through
1272// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111273bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321274 SavePackage::SavePackageType save_type) {
1275 // Stop the page from navigating.
1276 Stop();
1277
[email protected]828cabe2009-09-26 22:47:111278 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591279 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321280}
1281
[email protected]89d6e6e2009-12-03 23:06:511282void TabContents::EmailPageLocation() {
1283 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1284 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1285 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1286 title + "&body=%0A%0A" + page_url;
1287 platform_util::OpenExternal(GURL(mailto));
1288}
1289
[email protected]420ae012009-04-24 05:16:321290void TabContents::PrintPreview() {
1291 // We don't show the print preview yet, only the print dialog.
1292 PrintNow();
1293}
1294
1295bool TabContents::PrintNow() {
1296 // We can't print interstitial page for now.
1297 if (showing_interstitial_page())
1298 return false;
1299
1300 return render_view_host()->PrintPages();
1301}
1302
[email protected]82270452009-06-19 15:58:011303void TabContents::PrintingDone(int document_cookie, bool success) {
1304 render_view_host()->PrintingDone(document_cookie, success);
1305}
1306
[email protected]420ae012009-04-24 05:16:321307bool TabContents::IsActiveEntry(int32 page_id) {
1308 NavigationEntry* active_entry = controller_.GetActiveEntry();
1309 return (active_entry != NULL &&
1310 active_entry->site_instance() == GetSiteInstance() &&
1311 active_entry->page_id() == page_id);
1312}
1313
[email protected]b2fe07d12010-02-09 14:38:081314void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161315 set_encoding(encoding);
1316 render_view_host()->SetPageEncoding(encoding);
1317}
1318
[email protected]b2fe07d12010-02-09 14:38:081319void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161320 reset_encoding();
1321 render_view_host()->ResetPageEncodingToDefault();
1322}
1323
1324void TabContents::WindowMoveOrResizeStarted() {
1325 render_view_host()->WindowMoveOrResizeStarted();
1326}
1327
[email protected]3f8eb7f2009-10-02 23:58:051328void TabContents::LogNewTabTime(const std::string& event_name) {
1329 // Not all new tab pages get timed. In those cases, we don't have a
1330 // new_tab_start_time_.
1331 if (new_tab_start_time_.is_null())
1332 return;
1333
1334 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441335 MetricEventDurationDetails details(event_name,
1336 static_cast<int>(duration.InMilliseconds()));
1337
[email protected]7ab1e7d62009-10-14 23:32:011338 if (event_name == "Tab.NewTabScriptStart") {
1339 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1340 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1341 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1342 } else if (event_name == "Tab.NewTabOnload") {
1343 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051344 // The new tab page has finished loading; reset it.
1345 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441346 } else {
1347 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051348 }
[email protected]84abba62009-10-07 17:01:441349 NotificationService::current()->Notify(
1350 NotificationType::METRIC_EVENT_DURATION,
1351 Source<TabContents>(this),
1352 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051353}
1354
[email protected]7ab1e7d62009-10-14 23:32:011355void TabContents::OnCloseStarted() {
1356 if (tab_close_start_time_.is_null())
1357 tab_close_start_time_ = base::TimeTicks::Now();
1358}
1359
[email protected]46624bf2010-06-09 16:04:191360bool TabContents::ShouldAcceptDragAndDrop() const {
1361#if defined(OS_CHROMEOS)
1362 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1363 // See http://crosbug.com/2413
1364 return delegate() && !delegate()->IsPopup(const_cast<TabContents*>(this));
1365#else
1366 return true;
1367#endif
1368}
1369
[email protected]c37e3b62010-01-22 00:15:171370TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171371 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161372
1373 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081374 if (extension_app_)
1375 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161376 else if (entry)
1377 tab_nav.SetFromNavigationEntry(*entry);
1378
[email protected]c37e3b62010-01-22 00:15:171379 std::vector<TabNavigation> navigations;
1380 navigations.push_back(tab_nav);
1381
1382 TabContents* new_contents =
1383 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081384 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171385 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171386
[email protected]98aa0b52010-05-06 17:03:081387 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161388 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1389
[email protected]c37e3b62010-01-22 00:15:171390 return new_contents;
1391}
1392
[email protected]0de80162010-02-03 04:52:351393// Resets the |content_blocked_| array.
1394void TabContents::ClearBlockedContentSettings() {
[email protected]15cf526b2010-02-12 06:33:491395 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
[email protected]0de80162010-02-03 04:52:351396 content_blocked_[i] = false;
1397}
1398
[email protected]96d185d2009-04-24 03:28:541399// Notifies the RenderWidgetHost instance about the fact that the page is
1400// loading, or done loading and calls the base implementation.
1401void TabContents::SetIsLoading(bool is_loading,
1402 LoadNotificationDetails* details) {
1403 if (is_loading == is_loading_)
1404 return;
1405
1406 if (!is_loading) {
1407 load_state_ = net::LOAD_STATE_IDLE;
1408 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561409 upload_size_ = 0;
1410 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541411 }
1412
1413 render_manager_.SetIsLoading(is_loading);
1414
1415 is_loading_ = is_loading;
1416 waiting_for_response_ = is_loading;
1417
1418 if (delegate_)
1419 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351420 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541421
1422 NotificationType type = is_loading ? NotificationType::LOAD_START :
1423 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111424 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541425 if (details)
1426 det = Details<LoadNotificationDetails>(details);
1427 NotificationService::current()->Notify(type,
1428 Source<NavigationController>(&controller_),
1429 det);
1430}
1431
[email protected]b6c874582009-05-08 19:38:311432void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291433 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061434 // A page can't spawn popups (or do anything else, either) until its load
1435 // commits, so when we reach here, the popup was spawned by the
1436 // NavigationController's last committed entry, not the active entry. For
1437 // example, if a page opens a popup in an onunload() handler, then the active
1438 // entry is the page to be loaded as we navigate away from the unloading
1439 // page. For this reason, we can't use GetURL() to get the opener URL,
1440 // because it returns the active entry.
1441 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1442 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1443
1444 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491445 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]57eda82a2010-05-05 21:28:061446 creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491447 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1448 } else {
1449 if (!blocked_popups_)
1450 blocked_popups_ = new BlockedPopupContainer(this);
1451 blocked_popups_->AddTabContents(new_contents, initial_pos);
1452 }
[email protected]b9681312008-11-07 00:08:261453}
[email protected]616ed5a2008-11-21 22:27:241454
1455namespace {
1456bool TransitionIsReload(PageTransition::Type transition) {
1457 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1458}
1459}
1460
1461void TabContents::ExpireInfoBars(
1462 const NavigationController::LoadCommittedDetails& details) {
1463 // Only hide InfoBars when the user has done something that makes the main
1464 // frame load. We don't want various automatic or subframe navigations making
1465 // it disappear.
1466 if (!details.is_user_initiated_main_frame_load())
1467 return;
1468
[email protected]f86a07022008-11-25 01:06:051469 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241470 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051471 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241472 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241473 }
1474}
[email protected]fdd61c62009-04-22 19:22:571475
[email protected]96d185d2009-04-24 03:28:541476DOMUI* TabContents::GetDOMUIForCurrentState() {
1477 // When there is a pending navigation entry, we want to use the pending DOMUI
1478 // that goes along with it to control the basic flags. For example, we want to
1479 // show the pending URL in the URL bar, so we want the display_url flag to
1480 // be from the pending entry.
1481 //
1482 // The confusion comes because there are multiple possibilities for the
1483 // initial load in a tab as a side effect of the way the RenderViewHostManager
1484 // works.
1485 //
1486 // - For the very first tab the load looks "normal". The new tab DOM UI is
1487 // the pending one, and we want it to apply here.
1488 //
1489 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1490 // get switched to the one previously associated with the new tab pages.
1491 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1492 // have a committed DOM UI in this case.
1493 //
1494 // This condition handles all of these cases:
1495 //
1496 // - First load in first tab: no committed nav entry + pending nav entry +
1497 // pending dom ui:
1498 // -> Use pending DOM UI if any.
1499 //
1500 // - First load in second tab: no committed nav entry + pending nav entry +
1501 // no pending DOM UI:
1502 // -> Use the committed DOM UI if any.
1503 //
1504 // - Second navigation in any tab: committed nav entry + pending nav entry:
1505 // -> Use pending DOM UI if any.
1506 //
1507 // - Normal state with no load: committed nav entry + no pending nav entry:
1508 // -> Use committed DOM UI.
1509 if (controller_.pending_entry() &&
1510 (controller_.GetLastCommittedEntry() ||
1511 render_manager_.pending_dom_ui()))
1512 return render_manager_.pending_dom_ui();
1513 return render_manager_.dom_ui();
1514}
[email protected]420ae012009-04-24 05:16:321515
1516void TabContents::DidNavigateMainFramePostCommit(
1517 const NavigationController::LoadCommittedDetails& details,
1518 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441519 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1520 // If this is a window.open navigation, use the same DOMUI as the renderer
1521 // that opened the window, as long as both renderers have the same
1522 // privileges.
1523 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1524 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1525 // dom_ui might be NULL if the URL refers to a non-existent extension.
1526 if (dom_ui) {
1527 render_manager_.SetDOMUIPostCommit(dom_ui);
1528 dom_ui->RenderViewCreated(render_view_host());
1529 }
1530 }
1531 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1532 }
1533
[email protected]420ae012009-04-24 05:16:321534 if (details.is_user_initiated_main_frame_load()) {
1535 // Clear the status bubble. This is a workaround for a bug where WebKit
1536 // doesn't let us know that the cursor left an element during a
1537 // transition (this is also why the mouse cursor remains as a hand after
1538 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1539 // clear the bubble when a user navigates to a named anchor in the same
1540 // page.
1541 UpdateTargetURL(details.entry->page_id(), GURL());
1542
1543 // UpdateHelpersForDidNavigate will handle the case where the password_form
1544 // origin is valid.
1545 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1546 // cleaned up and covered by tests.
1547 if (!params.password_form.origin.is_valid())
1548 GetPasswordManager()->DidNavigate();
1549 }
1550
1551 // The keyword generator uses the navigation entries, so must be called after
1552 // the commit.
1553 GenerateKeywordIfNecessary(params);
1554
1555 // Allow the new page to set the title again.
1556 received_page_title_ = false;
1557
1558 // Get the favicon, either from history or request it from the net.
1559 fav_icon_helper_.FetchFavIcon(details.entry->url());
1560
[email protected]0de80162010-02-03 04:52:351561 // Clear all page actions, blocked content notifications and browser actions
1562 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141563 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081564 ExtensionsService* service = profile()->GetExtensionsService();
1565 if (service) {
1566 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571567 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081568 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521569 if (browser_action) {
1570 browser_action->ClearAllValuesForTab(controller().session_id().id());
1571 NotificationService::current()->Notify(
1572 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571573 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521574 NotificationService::NoDetails());
1575 }
[email protected]92c6f9b92009-10-24 04:35:081576
[email protected]5d246db22009-10-27 06:17:571577 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521578 service->extensions()->at(i)->page_action();
1579 if (page_action) {
1580 page_action->ClearAllValuesForTab(controller().session_id().id());
1581 PageActionStateChanged();
1582 }
[email protected]92c6f9b92009-10-24 04:35:081583 }
[email protected]aece2c7f2009-08-27 20:43:171584 }
[email protected]0de80162010-02-03 04:52:351585
1586 // Close blocked popups.
1587 if (blocked_popups_) {
[email protected]0fbd70332010-06-01 19:28:341588 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]0de80162010-02-03 04:52:351589 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461590 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351591 }
1592
1593 // Clear "blocked" flags.
1594 ClearBlockedContentSettings();
[email protected]777a7b62010-05-11 13:28:161595 geolocation_settings_state_.DidNavigate(details);
[email protected]0de80162010-02-03 04:52:351596 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241597 delegate_->OnContentSettingsChange(this);
[email protected]f17a0ee2010-05-17 17:38:471598
1599 // Once the main frame is navigated, we're no longer considered to have
1600 // displayed insecure content.
1601 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171602 }
[email protected]ce5c4502009-05-06 16:46:111603
[email protected]8cc8d492010-02-02 10:40:491604 // Close constrained windows if necessary.
1605 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1606 details.previous_url, details.entry->url()))
1607 CloseConstrainedWindows();
1608
[email protected]420ae012009-04-24 05:16:321609 // Update the starred state.
1610 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531611
1612 // Clear the cache of forms in AutoFill.
1613 if (autofill_manager_.get())
1614 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321615}
1616
1617void TabContents::DidNavigateAnyFramePostCommit(
1618 RenderViewHost* render_view_host,
1619 const NavigationController::LoadCommittedDetails& details,
1620 const ViewHostMsg_FrameNavigate_Params& params) {
1621 // If we navigate, start showing messages again. This does nothing to prevent
1622 // a malicious script from spamming messages, since the script could just
1623 // reload the page to stop blocking.
1624 suppress_javascript_messages_ = false;
1625
[email protected]420ae012009-04-24 05:16:321626 // Notify the password manager of the navigation or form submit.
1627 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1628 // cleaned up and covered by tests.
1629 if (params.password_form.origin.is_valid())
1630 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551631
1632 // Let the LanguageState clear its state.
[email protected]34cec8d82010-03-05 18:27:011633 bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
1634 details.type == NavigationType::SAME_PAGE;
1635 language_state_.DidNavigate(reload, details.is_in_page);
[email protected]420ae012009-04-24 05:16:321636}
1637
[email protected]8cc8d492010-02-02 10:40:491638void TabContents::CloseConstrainedWindows() {
1639 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321640 // We use indices instead of iterators in case CloseWindow does something
1641 // that may invalidate an iterator.
1642 int size = static_cast<int>(child_windows_.size());
1643 for (int i = size - 1; i >= 0; --i) {
1644 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441645 if (window) {
[email protected]420ae012009-04-24 05:16:321646 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441647 BlockTabContent(false);
1648 }
[email protected]420ae012009-04-24 05:16:321649 }
1650}
1651
1652void TabContents::UpdateStarredStateForCurrentURL() {
1653 BookmarkModel* model = profile()->GetBookmarkModel();
1654 const bool old_state = is_starred_;
1655 is_starred_ = (model && model->IsBookmarked(GetURL()));
1656
1657 if (is_starred_ != old_state && delegate())
1658 delegate()->URLStarredChanged(this, is_starred_);
1659}
1660
1661void TabContents::UpdateAlternateErrorPageURL() {
1662 GURL url = GetAlternateErrorPageURL();
1663 render_view_host()->SetAlternateErrorPageURL(url);
1664}
1665
1666void TabContents::UpdateWebPreferences() {
1667 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1668}
1669
1670void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1671 RenderViewHost* rvh) {
1672 // If we are creating a RVH for a restored controller, then we might
1673 // have more page IDs than the SiteInstance's current max page ID. We must
1674 // make sure that the max page ID is larger than any restored page ID.
1675 // Note that it is ok for conflicting page IDs to exist in another tab
1676 // (i.e., NavigationController), but if any page ID is larger than the max,
1677 // the back/forward list will get confused.
1678 int max_restored_page_id = controller_.max_restored_page_id();
1679 if (max_restored_page_id > 0) {
1680 int curr_max_page_id = site_instance->max_page_id();
1681 if (max_restored_page_id > curr_max_page_id) {
1682 // Need to update the site instance immediately.
1683 site_instance->UpdateMaxPageID(max_restored_page_id);
1684
1685 // Also tell the renderer to update its internal representation. We
1686 // need to reserve enough IDs to make all restored page IDs less than
1687 // the max.
1688 if (curr_max_page_id < 0)
1689 curr_max_page_id = 0;
1690 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1691 }
1692 }
1693}
1694
1695void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541696 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471697 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321698 const ViewHostMsg_FrameNavigate_Params& params) {
1699 if (profile()->IsOffTheRecord())
1700 return;
1701
1702 // Add to history service.
1703 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1704 if (hs) {
1705 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541706 virtual_url != params.url) {
1707 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321708 // types of URLs, we will display a magic URL that is different from where
1709 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541710 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1711 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321712 // to sub-frames.
1713 std::vector<GURL> redirects = params.redirects;
1714 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541715 redirects.back() = virtual_url;
1716 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471717 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321718 } else {
1719 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471720 params.transition, params.redirects,
1721 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321722 }
1723 }
1724}
1725
1726bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1727 const std::wstring& title) {
1728 // For file URLs without a title, use the pathname instead. In the case of a
1729 // synthesized title, we don't want the update to count toward the "one set
1730 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251731 string16 final_title;
[email protected]420ae012009-04-24 05:16:321732 bool explicit_set;
1733 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251734 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321735 explicit_set = false; // Don't count synthetic titles toward the set limit.
1736 } else {
[email protected]e53668962010-06-23 15:35:251737 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321738 explicit_set = true;
1739 }
1740
[email protected]e53668962010-06-23 15:35:251741 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321742 return false; // Nothing changed, don't bother.
1743
[email protected]e53668962010-06-23 15:35:251744 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321745
1746 // Update the history system for this page.
1747 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1748 HistoryService* hs =
1749 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1750 if (hs)
[email protected]ebe89e062009-08-13 23:16:541751 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321752
1753 // Don't allow the title to be saved again for explicitly set ones.
1754 received_page_title_ = explicit_set;
1755 }
1756
1757 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251758 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321759
[email protected]cbc0e1b2010-04-12 18:33:041760 NotificationService::current()->Notify(
1761 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1762 Source<TabContents>(this),
1763 NotificationService::NoDetails());
1764
[email protected]420ae012009-04-24 05:16:321765 return true;
1766}
1767
1768void TabContents::NotifySwapped() {
1769 // After sending out a swap notification, we need to send a disconnect
1770 // notification so that clients that pick up a pointer to |this| can NULL the
1771 // pointer. See Bug 1230284.
1772 notify_disconnection_ = true;
1773 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341774 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221775 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321776 NotificationService::NoDetails());
1777}
1778
1779void TabContents::NotifyConnected() {
1780 notify_disconnection_ = true;
1781 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341782 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221783 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321784 NotificationService::NoDetails());
1785}
1786
1787void TabContents::NotifyDisconnected() {
1788 if (!notify_disconnection_)
1789 return;
1790
1791 notify_disconnection_ = false;
1792 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341793 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221794 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321795 NotificationService::NoDetails());
1796}
1797
1798void TabContents::GenerateKeywordIfNecessary(
1799 const ViewHostMsg_FrameNavigate_Params& params) {
1800 if (!params.searchable_form_url.is_valid())
1801 return;
1802
1803 if (profile()->IsOffTheRecord())
1804 return;
1805
1806 int last_index = controller_.last_committed_entry_index();
1807 // When there was no previous page, the last index will be 0. This is
1808 // normally due to a form submit that opened in a new tab.
1809 // TODO(brettw) bug 916126: we should support keywords when form submits
1810 // happen in new tabs.
1811 if (last_index <= 0)
1812 return;
1813 const NavigationEntry* previous_entry =
1814 controller_.GetEntryAtIndex(last_index - 1);
1815 if (IsFormSubmit(previous_entry)) {
1816 // Only generate a keyword if the previous page wasn't itself a form
1817 // submit.
1818 return;
1819 }
1820
1821 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1822 previous_entry->user_typed_url() : previous_entry->url();
1823 std::wstring keyword =
1824 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1825 if (keyword.empty())
1826 return;
1827
1828 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1829 if (!url_model)
1830 return;
1831
1832 if (!url_model->loaded()) {
1833 url_model->Load();
1834 return;
1835 }
1836
1837 const TemplateURL* current_url;
1838 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1839 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1840 return;
1841
1842 if (current_url) {
1843 if (current_url->originating_url().is_valid()) {
1844 // The existing keyword was generated from an OpenSearch description
1845 // document, don't regenerate.
1846 return;
1847 }
1848 url_model->Remove(current_url);
1849 }
1850 TemplateURL* new_url = new TemplateURL();
1851 new_url->set_keyword(keyword);
1852 new_url->set_short_name(keyword);
1853 new_url->SetURL(url, 0, 0);
1854 new_url->add_input_encoding(params.searchable_form_encoding);
1855 DCHECK(controller_.GetLastCommittedEntry());
1856 const GURL& favicon_url =
1857 controller_.GetLastCommittedEntry()->favicon().url();
1858 if (favicon_url.is_valid()) {
1859 new_url->SetFavIconURL(favicon_url);
1860 } else {
1861 // The favicon url isn't valid. This means there really isn't a favicon,
1862 // or the favicon url wasn't obtained before the load started. This assumes
1863 // the later.
1864 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1865 // its url.
1866 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1867 }
1868 new_url->set_safe_for_autoreplace(true);
1869 url_model->Add(new_url);
1870}
1871
[email protected]bf5c2ff392009-07-08 16:24:331872void TabContents::OnUserGesture() {
1873 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1874 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1875 if (drm)
1876 drm->OnUserGesture(this);
[email protected]e7eaedde2009-09-25 20:09:491877 ExternalProtocolHandler::OnUserGesture();
[email protected]bf5c2ff392009-07-08 16:24:331878 controller_.OnUserGesture();
1879}
1880
1881void TabContents::OnFindReply(int request_id,
1882 int number_of_matches,
1883 const gfx::Rect& selection_rect,
1884 int active_match_ordinal,
1885 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421886 // Ignore responses for requests that have been aborted.
1887 if (find_op_aborted_)
1888 return;
1889
[email protected]bf5c2ff392009-07-08 16:24:331890 // Ignore responses for requests other than the one we have most recently
1891 // issued. That way we won't act on stale results when the user has
1892 // already typed in another query.
1893 if (request_id != current_find_request_id_)
1894 return;
1895
1896 if (number_of_matches == -1)
1897 number_of_matches = last_search_result_.number_of_matches();
1898 if (active_match_ordinal == -1)
1899 active_match_ordinal = last_search_result_.active_match_ordinal();
1900
1901 gfx::Rect selection = selection_rect;
1902 if (selection.IsEmpty())
1903 selection = last_search_result_.selection_rect();
1904
1905 // Notify the UI, automation and any other observers that a find result was
1906 // found.
1907 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1908 selection, active_match_ordinal,
1909 final_update);
1910 NotificationService::current()->Notify(
1911 NotificationType::FIND_RESULT_AVAILABLE,
1912 Source<TabContents>(this),
1913 Details<FindNotificationDetails>(&last_search_result_));
1914}
1915
1916void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381917 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1918 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331919}
1920
[email protected]bf5c2ff392009-07-08 16:24:331921void TabContents::OnMissingPluginStatus(int status) {
1922#if defined(OS_WIN)
1923// TODO(PORT): pull in when plug-ins work
1924 GetPluginInstaller()->OnMissingPluginStatus(status);
1925#endif
1926}
1927
1928void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331929 DCHECK(!plugin_path.value().empty());
1930
1931 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351932#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331933 scoped_ptr<FileVersionInfo> version_info(
1934 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1935 if (version_info.get()) {
1936 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371937 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331938 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371939#if defined(OS_MACOSX)
1940 // Many plugins on the Mac have .plugin in the actual name, which looks
1941 // terrible, so look for that and strip it off if present.
1942 const std::wstring plugin_extension(L".plugin");
1943 if (EndsWith(plugin_name, plugin_extension, true))
1944 plugin_name.erase(plugin_name.length() - plugin_extension.length());
1945#endif // OS_MACOSX
1946 }
[email protected]bf5c2ff392009-07-08 16:24:331947 }
[email protected]4a560ed2009-07-13 23:35:261948#else
1949 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1950#endif
[email protected]2ae8a922010-06-28 20:27:531951 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
1952 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:331953 AddInfoBar(new SimpleAlertInfoBarDelegate(
1954 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
[email protected]2ae8a922010-06-28 20:27:531955 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:331956}
1957
1958void TabContents::OnCrashedWorker() {
1959 AddInfoBar(new SimpleAlertInfoBarDelegate(
1960 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:421961 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331962}
1963
1964void TabContents::OnDidGetApplicationInfo(
1965 int32 page_id,
1966 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511967 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331968
[email protected]ed5431872009-11-17 08:39:511969 if (delegate())
1970 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331971}
1972
[email protected]a2cf65eb2010-01-18 08:20:381973void TabContents::OnPageContents(const GURL& url,
1974 int renderer_process_id,
1975 int32 page_id,
[email protected]e5106202010-06-11 21:12:361976 const string16& contents,
[email protected]a8a81292010-01-21 00:32:451977 const std::string& language) {
[email protected]a2cf65eb2010-01-18 08:20:381978 // Don't index any https pages. People generally don't want their bank
1979 // accounts, etc. indexed on their computer, especially since some of these
1980 // things are not marked cachable.
1981 // TODO(brettw) we may want to consider more elaborate heuristics such as
1982 // the cachability of the page. We may also want to consider subframes (this
1983 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271984 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1985 // content indexing for chromeos in some future releases.
1986#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381987 if (!url.SchemeIsSecure()) {
1988 Profile* p = profile();
1989 if (p && !p->IsOffTheRecord()) {
1990 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1991 if (hs)
1992 hs->SetPageContents(url, contents);
1993 }
1994 }
[email protected]ccd40a52010-05-11 16:15:271995#endif
[email protected]a8a81292010-01-21 00:32:451996
[email protected]3b1c1812010-02-12 21:53:551997 language_state_.LanguageDetermined(language);
[email protected]a8a81292010-01-21 00:32:451998
1999 std::string lang = language;
2000 NotificationService::current()->Notify(
2001 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152002 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452003 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382004}
2005
[email protected]7e0831b2010-02-01 08:45:152006void TabContents::OnPageTranslated(int32 page_id,
2007 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162008 const std::string& translated_lang,
2009 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552010 language_state_.set_current_language(translated_lang);
2011 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162012 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152013 NotificationService::current()->Notify(
2014 NotificationType::PAGE_TRANSLATED,
2015 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162016 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152017}
2018
[email protected]bf5c2ff392009-07-08 16:24:332019void TabContents::DidStartProvisionalLoadForFrame(
2020 RenderViewHost* render_view_host,
2021 bool is_main_frame,
2022 const GURL& url) {
2023 ProvisionalLoadDetails details(is_main_frame,
2024 controller_.IsURLInPageNavigation(url),
2025 url, std::string(), false);
2026 NotificationService::current()->Notify(
2027 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2028 Source<NavigationController>(&controller_),
2029 Details<ProvisionalLoadDetails>(&details));
2030}
2031
2032void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202033 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332034 NotificationService::current()->Notify(
2035 NotificationType::RESOURCE_RESPONSE_STARTED,
2036 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202037 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332038}
2039
[email protected]3dbb80b2010-02-09 22:41:202040void TabContents::DidRedirectResource(
2041 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332042 NotificationService::current()->Notify(
2043 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2044 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202045 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332046}
2047
2048void TabContents::DidLoadResourceFromMemoryCache(
2049 const GURL& url,
2050 const std::string& frame_origin,
2051 const std::string& main_frame_origin,
2052 const std::string& security_info) {
2053 // Send out a notification that we loaded a resource from our memory cache.
2054 int cert_id = 0, cert_status = 0, security_bits = 0;
2055 SSLManager::DeserializeSecurityInfo(security_info,
2056 &cert_id, &cert_status,
2057 &security_bits);
2058 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162059 GetRenderProcessHost()->id(), cert_id,
2060 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332061
2062 NotificationService::current()->Notify(
2063 NotificationType::LOAD_FROM_MEMORY_CACHE,
2064 Source<NavigationController>(&controller_),
2065 Details<LoadFromMemoryCacheDetails>(&details));
2066}
2067
[email protected]e3d60e5d2009-09-25 21:08:292068void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472069 displayed_insecure_content_ = true;
2070 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292071}
2072
2073void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592074 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292075}
2076
[email protected]bf5c2ff392009-07-08 16:24:332077void TabContents::DidFailProvisionalLoadWithError(
2078 RenderViewHost* render_view_host,
2079 bool is_main_frame,
2080 int error_code,
2081 const GURL& url,
2082 bool showing_repost_interstitial) {
2083 if (net::ERR_ABORTED == error_code) {
2084 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2085 // This means that the interstitial won't be torn down properly, which is
2086 // bad. But if we have an interstitial, go back to another tab type, and
2087 // then load the same interstitial again, we could end up getting the first
2088 // interstitial's "failed" message (as a result of the cancel) when we're on
2089 // the second one.
2090 //
2091 // We can't tell this apart, so we think we're tearing down the current page
2092 // which will cause a crash later one. There is also some code in
2093 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2094 // out because of this problem.
2095 //
2096 // http://code.google.com/p/chromium/issues/detail?id=2855
2097 // Because this will not tear down the interstitial properly, if "back" is
2098 // back to another tab type, the interstitial will still be somewhat alive
2099 // in the previous tab type. If you navigate somewhere that activates the
2100 // tab with the interstitial again, you'll see a flash before the new load
2101 // commits of the interstitial page.
2102 if (showing_interstitial_page()) {
2103 LOG(WARNING) << "Discarding message during interstitial.";
2104 return;
2105 }
2106
2107 // This will discard our pending entry if we cancelled the load (e.g., if we
2108 // decided to download the file instead of load it). Only discard the
2109 // pending entry if the URLs match, otherwise the user initiated a navigate
2110 // before the page loaded so that the discard would discard the wrong entry.
2111 NavigationEntry* pending_entry = controller_.pending_entry();
2112 if (pending_entry && pending_entry->url() == url) {
2113 controller_.DiscardNonCommittedEntries();
2114 // Update the URL display.
2115 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2116 }
2117
2118 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2119 }
2120
2121 // Send out a notification that we failed a provisional load with an error.
2122 ProvisionalLoadDetails details(is_main_frame,
2123 controller_.IsURLInPageNavigation(url),
2124 url, std::string(), false);
2125 details.set_error_code(error_code);
2126
2127 NotificationService::current()->Notify(
2128 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2129 Source<NavigationController>(&controller_),
2130 Details<ProvisionalLoadDetails>(&details));
2131}
2132
2133void TabContents::DocumentLoadedInFrame() {
2134 controller_.DocumentLoadedInFrame();
2135}
2136
[email protected]0de80162010-02-03 04:52:352137void TabContents::OnContentBlocked(ContentSettingsType type) {
[email protected]aa43bc02010-06-21 13:46:362138 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION)
2139 << "Geolocation settings handled by OnGeolocationPermissionSet";
[email protected]0de80162010-02-03 04:52:352140 content_blocked_[type] = true;
2141 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242142 delegate_->OnContentSettingsChange(this);
[email protected]0de80162010-02-03 04:52:352143}
2144
[email protected]614c0e12010-03-25 10:12:562145void TabContents::OnGeolocationPermissionSet(const GURL& requesting_origin,
2146 bool allowed) {
[email protected]777a7b62010-05-11 13:28:162147 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin,
2148 allowed);
[email protected]614c0e12010-03-25 10:12:562149 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242150 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562151}
2152
[email protected]8d3347f2009-07-09 22:00:212153RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322154 return view_.get();
2155}
2156
[email protected]8d3347f2009-07-09 22:00:212157RenderViewHostDelegate::RendererManagement*
2158TabContents::GetRendererManagementDelegate() {
2159 return &render_manager_;
2160}
2161
[email protected]bf5c2ff392009-07-08 16:24:332162RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212163 TabContents::GetBrowserIntegrationDelegate() {
2164 return this;
[email protected]bf5c2ff392009-07-08 16:24:332165}
2166
[email protected]8d3347f2009-07-09 22:00:212167RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2168 return this;
[email protected]bf5c2ff392009-07-08 16:24:332169}
2170
[email protected]46ba9082010-06-22 10:00:582171RenderViewHostDelegate::ContentSettings*
2172TabContents::GetContentSettingsDelegate() {
2173 return this;
2174}
2175
[email protected]8d3347f2009-07-09 22:00:212176RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322177 return save_package_.get(); // May be NULL, but we can return NULL.
2178}
2179
[email protected]8d3347f2009-07-09 22:00:212180RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
2181 return &printing_;
2182}
2183
2184RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2185 return &fav_icon_helper_;
2186}
2187
[email protected]e8dbd674b2010-03-11 18:34:402188RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452189 if (autocomplete_history_manager_.get() == NULL)
2190 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2191 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332192}
2193
[email protected]21674df2009-10-28 19:51:212194RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342195 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212196}
2197
[email protected]fd571bb2010-03-19 01:23:542198AutomationResourceRoutingDelegate*
2199TabContents::GetAutomationResourceRoutingDelegate() {
2200 return delegate();
2201}
2202
[email protected]ced90ae12010-02-20 02:06:162203RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2204 return bookmark_drag_;
2205}
2206
2207void TabContents::SetBookmarkDragDelegate(
2208 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2209 bookmark_drag_ = bookmark_drag;
2210}
2211
[email protected]93623c5d2009-12-10 21:40:322212RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462213 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512214}
2215
[email protected]57c6a652009-05-04 07:58:342216TabContents* TabContents::GetAsTabContents() {
2217 return this;
2218}
2219
[email protected]7b291f92009-08-14 05:43:532220ViewType::Type TabContents::GetRenderViewType() const {
2221 return ViewType::TAB_CONTENTS;
2222}
2223
2224int TabContents::GetBrowserWindowID() const {
2225 return controller().window_id().id();
2226}
2227
[email protected]420ae012009-04-24 05:16:322228void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062229 NotificationService::current()->Notify(
2230 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2231 Source<TabContents>(this),
2232 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322233 NavigationEntry* entry = controller_.GetActiveEntry();
2234 if (!entry)
2235 return;
2236
2237 // When we're creating views, we're still doing initial setup, so we always
2238 // use the pending DOM UI rather than any possibly existing committed one.
2239 if (render_manager_.pending_dom_ui()) {
2240 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2241 }
2242
2243 if (entry->IsViewSourceMode()) {
2244 // Put the renderer in view source mode.
2245 render_view_host->Send(
2246 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2247 }
[email protected]0666aef2009-05-13 19:48:082248
2249 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322250}
2251
2252void TabContents::RenderViewReady(RenderViewHost* rvh) {
2253 if (rvh != render_view_host()) {
2254 // Don't notify the world, since this came from a renderer in the
2255 // background.
2256 return;
2257 }
2258
2259 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302260 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322261 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302262
2263 // Restore the focus to the tab (otherwise the focus will be on the top
2264 // window).
2265 if (was_crashed && !FocusLocationBarByDefault())
2266 Focus();
[email protected]420ae012009-04-24 05:16:322267}
2268
2269void TabContents::RenderViewGone(RenderViewHost* rvh) {
2270 // Ask the print preview if this renderer was valuable.
2271 if (!printing_.OnRenderViewGone(rvh))
2272 return;
2273 if (rvh != render_view_host()) {
2274 // The pending page's RenderViewHost is gone.
2275 return;
2276 }
2277
2278 SetIsLoading(false, NULL);
2279 NotifyDisconnected();
2280 SetIsCrashed(true);
2281
[email protected]ff9efc62010-02-18 22:10:542282 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212283 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542284 RemoveInfoBar(GetInfoBarDelegateAt(i));
2285
[email protected]8e537302009-06-10 21:19:582286 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552287 // Only do this if we're not in browser shutdown, so that TabContents
2288 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2289 // visible do not flash a sad tab page.
2290 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2291 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322292
2293 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002294 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322295}
2296
[email protected]2e4633c2009-07-09 16:58:062297void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2298 NotificationService::current()->Notify(
2299 NotificationType::RENDER_VIEW_HOST_DELETED,
2300 Source<TabContents>(this),
2301 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482302 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062303}
2304
[email protected]420ae012009-04-24 05:16:322305void TabContents::DidNavigate(RenderViewHost* rvh,
2306 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372307 int extra_invalidate_flags = 0;
2308
2309 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352310 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372311 bool was_extension_shelf_visible = IsExtensionShelfAlwaysVisible();
2312
[email protected]420ae012009-04-24 05:16:322313 render_manager_.DidNavigateMainFrame(rvh);
2314
[email protected]20ede072009-10-06 00:28:352315 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372316 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
2317 if (was_extension_shelf_visible != IsExtensionShelfAlwaysVisible())
2318 extra_invalidate_flags |= INVALIDATE_EXTENSION_SHELF;
2319 }
2320
[email protected]420ae012009-04-24 05:16:322321 // Update the site of the SiteInstance if it doesn't have one yet.
2322 if (!GetSiteInstance()->has_site())
2323 GetSiteInstance()->SetSite(params.url);
2324
2325 // Need to update MIME type here because it's referred to in
2326 // UpdateNavigationCommands() called by RendererDidNavigate() to
2327 // determine whether or not to enable the encoding menu.
2328 // It's updated only for the main frame. For a subframe,
2329 // RenderView::UpdateURL does not set params.contents_mime_type.
2330 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2331 // TODO(jungshik): Add a test for the encoding menu to avoid
2332 // regressing it again.
2333 if (PageTransition::IsMainFrame(params.transition))
2334 contents_mime_type_ = params.contents_mime_type;
2335
2336 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372337 bool did_navigate = controller_.RendererDidNavigate(
2338 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392339
2340 // Update history. Note that this needs to happen after the entry is complete,
2341 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352342 if (params.should_update_history &&
2343 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392344 // Most of the time, the displayURL matches the loaded URL, but for about:
2345 // URLs, we use a data: URL as the real value. We actually want to save
2346 // the about: URL to the history db and keep the data: URL hidden. This is
2347 // what the TabContents' URL getter does.
2348 UpdateHistoryForNavigation(GetURL(), details, params);
2349 }
2350
[email protected]76543b92009-08-31 17:27:452351 if (!did_navigate)
2352 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322353
2354 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2355 // for the appropriate notification (best) or you can add it to
2356 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2357 // necessary, please).
2358
2359 // Run post-commit tasks.
2360 if (details.is_main_frame)
2361 DidNavigateMainFramePostCommit(details, params);
2362 DidNavigateAnyFramePostCommit(rvh, details, params);
2363}
2364
2365void TabContents::UpdateState(RenderViewHost* rvh,
2366 int32 page_id,
2367 const std::string& state) {
2368 DCHECK(rvh == render_view_host());
2369
2370 // We must be prepared to handle state updates for any page, these occur
2371 // when the user is scrolling and entering form data, as well as when we're
2372 // leaving a page, in which case our state may have already been moved to
2373 // the next page. The navigation controller will look up the appropriate
2374 // NavigationEntry and update it when it is notified via the delegate.
2375
2376 int entry_index = controller_.GetEntryIndexWithPageID(
2377 GetSiteInstance(), page_id);
2378 if (entry_index < 0)
2379 return;
2380 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2381
2382 if (state == entry->content_state())
2383 return; // Nothing to update.
2384 entry->set_content_state(state);
2385 controller_.NotifyEntryChanged(entry, entry_index);
2386}
2387
2388void TabContents::UpdateTitle(RenderViewHost* rvh,
2389 int32 page_id, const std::wstring& title) {
2390 // If we have a title, that's a pretty good indication that we've started
2391 // getting useful data.
2392 SetNotWaitingForResponse();
2393
2394 DCHECK(rvh == render_view_host());
2395 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2396 page_id);
2397 if (!entry || !UpdateTitleForEntry(entry, title))
2398 return;
2399
2400 // Broadcast notifications when the UI should be updated.
2401 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032402 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322403}
2404
[email protected]420ae012009-04-24 05:16:322405void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402406 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322407 set_encoding(encoding);
2408}
2409
2410void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2411 if (delegate())
2412 delegate()->UpdateTargetURL(this, url);
2413}
2414
2415void TabContents::UpdateThumbnail(const GURL& url,
2416 const SkBitmap& bitmap,
2417 const ThumbnailScore& score) {
2418 // Tell History about this thumbnail
[email protected]523623c2010-05-19 16:03:422419 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492420 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422421 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282422 } else {
2423 HistoryService* hs;
2424 if (!profile()->IsOffTheRecord() &&
2425 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2426 hs->SetPageThumbnail(url, bitmap, score);
2427 }
[email protected]420ae012009-04-24 05:16:322428 }
2429}
2430
[email protected]c4e98902010-06-01 10:20:142431void TabContents::UpdateInspectorSetting(const std::string& key,
2432 const std::string& value) {
2433 DictionaryValue* inspector_settings =
2434 profile()->GetPrefs()->GetMutableDictionary(
2435 prefs::kWebKitInspectorSettings);
[email protected]628cf5a52010-06-07 14:25:332436 inspector_settings->SetWithoutPathExpansion(UTF8ToWide(key),
2437 Value::CreateStringValue(value));
[email protected]0df30122009-06-03 12:13:082438}
2439
[email protected]45aafc92010-06-07 14:18:532440void TabContents::ClearInspectorSettings() {
2441 DictionaryValue* inspector_settings =
2442 profile()->GetPrefs()->GetMutableDictionary(
2443 prefs::kWebKitInspectorSettings);
2444 inspector_settings->Clear();
2445}
2446
[email protected]420ae012009-04-24 05:16:322447void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292448 // The UI may be in an event-tracking loop, such as between the
2449 // mouse-down and mouse-up in text selection or a button click.
2450 // Defer the close until after tracking is complete, so that we
2451 // don't free objects out from under the UI.
2452 // TODO(shess): This could probably be integrated with the
2453 // IsDoingDrag() test below. Punting for now because I need more
2454 // research to understand how this impacts platforms other than Mac.
2455 // TODO(shess): This could get more fine-grained. For instance,
2456 // closing a tab in another window while selecting text in the
2457 // current window's Omnibox should be just fine.
2458 if (view()->IsEventTracking()) {
2459 view()->CloseTabAfterEventTracking();
2460 return;
2461 }
2462
[email protected]24a4d1062009-07-10 23:10:422463 // If we close the tab while we're in the middle of a drag, we'll crash.
2464 // Instead, cancel the drag and close it as soon as the drag ends.
2465 if (view()->IsDoingDrag()) {
2466 view()->CancelDragAndCloseTab();
2467 return;
2468 }
2469
[email protected]420ae012009-04-24 05:16:322470 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2471 if (delegate() && rvh == render_view_host())
2472 delegate()->CloseContents(this);
2473}
2474
2475void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2476 if (delegate() && delegate()->IsPopup(this))
2477 delegate()->MoveContents(this, new_bounds);
2478}
2479
[email protected]7ab1e7d62009-10-14 23:32:012480void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322481 SetIsLoading(true, NULL);
2482}
2483
[email protected]7ab1e7d62009-10-14 23:32:012484void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322485 scoped_ptr<LoadNotificationDetails> details;
2486
2487 NavigationEntry* entry = controller_.GetActiveEntry();
2488 // An entry may not exist for a stop when loading an initial blank page or
2489 // if an iframe injected by script into a blank page finishes loading.
2490 if (entry) {
[email protected]420ae012009-04-24 05:16:322491 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2492
2493 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542494 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322495 entry->transition_type(),
2496 elapsed,
2497 &controller_,
2498 controller_.GetCurrentEntryIndex()));
2499 }
2500
2501 // Tell PasswordManager we've finished a page load, which serves as a
2502 // green light to save pending passwords and reset itself.
2503 GetPasswordManager()->DidStopLoading();
2504
2505 SetIsLoading(false, details.get());
2506}
2507
[email protected]420ae012009-04-24 05:16:322508void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2509 const GURL& source_url,
2510 const GURL& target_url) {
2511 NavigationEntry* entry;
2512 if (page_id == -1)
2513 entry = controller_.pending_entry();
2514 else
2515 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2516 if (!entry || entry->url() != source_url)
2517 return;
2518 entry->set_url(target_url);
2519}
2520
[email protected]420ae012009-04-24 05:16:322521void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2522 WindowOpenDisposition disposition) {
2523 if (render_manager_.dom_ui()) {
2524 // When we're a DOM UI, it will provide a page transition type for us (this
2525 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2526 // generated suggestions).
2527 //
2528 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162529 // want web sites to see a referrer of "chrome://blah" (and some
2530 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322531 // send to the site), so we send no referrer.
2532 OpenURL(url, GURL(), disposition,
2533 render_manager_.dom_ui()->link_transition_type());
2534 } else {
2535 OpenURL(url, referrer, disposition, PageTransition::LINK);
2536 }
2537}
2538
[email protected]1ee614862009-07-06 20:29:182539void TabContents::DomOperationResponse(const std::string& json_string,
2540 int automation_id) {
2541}
2542
[email protected]420ae012009-04-24 05:16:322543void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]438c97d2010-05-21 23:30:152544 const ListValue* content,
[email protected]bb64b512010-04-02 21:01:392545 const GURL& source_url,
[email protected]811bfe32009-07-01 08:46:252546 int request_id,
2547 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322548 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442549 // This can happen if someone uses window.open() to open an extension URL
2550 // from a non-extension context.
2551 render_view_host()->BlockExtensionRequest(request_id);
[email protected]420ae012009-04-24 05:16:322552 return;
2553 }
[email protected]bb64b512010-04-02 21:01:392554 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, source_url,
2555 request_id,
[email protected]811bfe32009-07-01 08:46:252556 has_callback);
[email protected]420ae012009-04-24 05:16:322557}
2558
2559void TabContents::ProcessExternalHostMessage(const std::string& message,
2560 const std::string& origin,
2561 const std::string& target) {
2562 if (delegate())
2563 delegate()->ForwardMessageToExternalHost(message, origin, target);
2564}
2565
[email protected]cdaf8d02010-03-30 19:52:472566void TabContents::RunFileChooser(
2567 const ViewHostMsg_RunFileChooser_Params &params) {
[email protected]420ae012009-04-24 05:16:322568 if (!select_file_dialog_.get())
2569 select_file_dialog_ = SelectFileDialog::Create(this);
[email protected]cdaf8d02010-03-30 19:52:472570
2571 SelectFileDialog::Type dialog_type;
2572 switch (params.mode) {
2573 case ViewHostMsg_RunFileChooser_Params::Open:
2574 dialog_type = SelectFileDialog::SELECT_OPEN_FILE;
2575 break;
2576 case ViewHostMsg_RunFileChooser_Params::OpenMultiple:
2577 dialog_type = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
2578 break;
2579 case ViewHostMsg_RunFileChooser_Params::Save:
2580 dialog_type = SelectFileDialog::SELECT_SAVEAS_FILE;
2581 break;
2582 default:
[email protected]bed31952010-03-30 20:07:592583 dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning.
[email protected]cdaf8d02010-03-30 19:52:472584 NOTREACHED();
2585 }
[email protected]35896a32010-06-09 08:42:512586 FilePath default_file_name = params.default_file_name;
2587 if (default_file_name.empty())
2588 default_file_name = profile()->last_selected_directory();
[email protected]cdaf8d02010-03-30 19:52:472589 select_file_dialog_->SelectFile(dialog_type, params.title,
[email protected]35896a32010-06-09 08:42:512590 default_file_name,
[email protected]420ae012009-04-24 05:16:322591 NULL, 0, FILE_PATH_LITERAL(""),
2592 view_->GetTopLevelNativeWindow(), NULL);
2593}
2594
2595void TabContents::RunJavaScriptMessage(
2596 const std::wstring& message,
2597 const std::wstring& default_prompt,
2598 const GURL& frame_url,
2599 const int flags,
2600 IPC::Message* reply_msg,
2601 bool* did_suppress_message) {
2602 // Suppress javascript messages when requested and when inside a constrained
2603 // popup window (because that activates them and breaks them out of the
2604 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552605 // Also suppress messages when showing an interstitial. The interstitial is
2606 // shown over the previous page, we don't want the hidden page dialogs to
2607 // interfere with the interstitial.
2608 bool suppress_this_message = suppress_javascript_messages_ ||
2609 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322610 if (delegate())
2611 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312612 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322613
2614 *did_suppress_message = suppress_this_message;
2615
2616 if (!suppress_this_message) {
2617 base::TimeDelta time_since_last_message(
2618 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2619 bool show_suppress_checkbox = false;
2620 // Show a checkbox offering to suppress further messages if this message is
2621 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2622 if (time_since_last_message <
2623 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2624 show_suppress_checkbox = true;
2625
[email protected]d82ed61e2009-06-16 02:46:222626 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322627 show_suppress_checkbox, reply_msg);
2628 } else {
2629 // If we are suppressing messages, just reply as is if the user immediately
2630 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542631 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322632 }
2633}
2634
2635void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2636 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012637 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222638 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322639}
2640
2641void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2642 const std::string& json_arguments,
2643 IPC::Message* reply_msg) {
2644 if (delegate()) {
2645 HtmlDialogUIDelegate* dialog_delegate =
2646 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222647 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322648 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2649 }
2650}
2651
[email protected]4d44a1c2010-04-28 19:20:412652void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562653 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412654 GetPasswordManager()->PasswordFormsFound(forms);
2655}
2656
2657void TabContents::PasswordFormsVisible(
2658 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2659 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322660}
2661
[email protected]420ae012009-04-24 05:16:322662// Checks to see if we should generate a keyword based on the OSDD, and if
2663// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2664void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2665 int32 page_id, const GURL& url,
2666 bool autodetected) {
2667 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2668 DCHECK(url.is_valid());
2669 if (!IsActiveEntry(page_id))
2670 return;
2671 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2672 if (!url_model)
2673 return;
2674 if (!url_model->loaded()) {
2675 url_model->Load();
2676 return;
2677 }
2678 if (!profile()->GetTemplateURLFetcher())
2679 return;
2680
2681 if (profile()->IsOffTheRecord())
2682 return;
2683
2684 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2685 DCHECK(entry);
2686
2687 const NavigationEntry* base_entry = entry;
2688 if (IsFormSubmit(base_entry)) {
2689 // If the current page is a form submit, find the last page that was not
2690 // a form submit and use its url to generate the keyword from.
2691 int index = controller_.last_committed_entry_index() - 1;
2692 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2693 index--;
2694 if (index >= 0)
2695 base_entry = controller_.GetEntryAtIndex(index);
2696 else
2697 base_entry = NULL;
2698 }
2699
2700 // We want to use the user typed URL if available since that represents what
2701 // the user typed to get here, and fall back on the regular URL if not.
2702 if (!base_entry)
2703 return;
2704 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2705 base_entry->user_typed_url() : base_entry->url();
2706 if (!keyword_url.is_valid())
2707 return;
2708 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2709 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532710
2711 // For JS added OSDD empty keyword is OK because we will generate keyword
2712 // later from OSDD content.
2713 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322714 return;
2715 const TemplateURL* template_url =
2716 url_model->GetTemplateURLForKeyword(keyword);
2717 if (template_url && (!template_url->safe_for_autoreplace() ||
2718 template_url->originating_url() == url)) {
2719 // Either there is a user created TemplateURL for this keyword, or the
2720 // keyword has the same OSDD url and we've parsed it.
2721 return;
2722 }
2723
2724 // Download the OpenSearch description document. If this is successful a
2725 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322726 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2727 keyword,
2728 url,
2729 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162730 this,
[email protected]420ae012009-04-24 05:16:322731 autodetected);
2732}
2733
[email protected]420ae012009-04-24 05:16:322734GURL TabContents::GetAlternateErrorPageURL() const {
2735 GURL url;
2736 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2737 if (profile()->IsOffTheRecord())
2738 return url;
2739
2740 PrefService* prefs = profile()->GetPrefs();
2741 DCHECK(prefs);
2742 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152743 url = google_util::AppendGoogleLocaleParam(
2744 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322745 url = google_util::AppendGoogleTLDParam(url);
2746 }
2747 return url;
2748}
2749
2750WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062751 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552752 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062753 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322754}
2755
[email protected]fa1cf0b82010-01-15 21:49:442756void TabContents::OnIgnoredUIEvent() {
2757 if (constrained_window_count()) {
2758 ConstrainedWindow* window = *constrained_window_begin();
2759 window->FocusConstrainedWindow();
2760 }
2761}
2762
[email protected]420ae012009-04-24 05:16:322763void TabContents::OnJSOutOfMemory() {
2764 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]938e1f92010-04-01 18:09:422765 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL, true));
[email protected]420ae012009-04-24 05:16:322766}
2767
[email protected]420ae012009-04-24 05:16:322768void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2769 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342770 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322771 // delivered to a pending RenderViewHost. We must first run the onunload
2772 // handler of the old RenderViewHost before we can allow it to proceed.
2773 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2774 new_request_id);
2775}
2776
2777bool TabContents::CanBlur() const {
2778 return delegate() ? delegate()->CanBlur() : true;
2779}
2780
2781gfx::Rect TabContents::GetRootWindowResizerRect() const {
2782 if (delegate())
2783 return delegate()->GetRootWindowResizerRect();
2784 return gfx::Rect();
2785}
2786
2787void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2788 bool is_during_unload) {
2789 if (is_during_unload) {
2790 // Hang occurred while firing the beforeunload/unload handler.
2791 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112792 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322793
2794 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2795 return;
2796
2797 // If the tab hangs in the beforeunload/unload handler there's really
2798 // nothing we can do to recover. Pretend the unload listeners have
2799 // all fired and close the tab. If the hang is in the beforeunload handler
2800 // then the user will not have the option of cancelling the close.
2801 Close(rvh);
2802 return;
2803 }
2804
2805 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002806 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322807}
2808
2809void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002810 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322811}
2812
2813void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562814 net::LoadState load_state,
2815 uint64 upload_position,
2816 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322817 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562818 upload_position_ = upload_position;
2819 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292820 std::wstring languages =
2821 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]d686e812009-06-03 19:10:292822 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532823 load_state_host_ =
2824 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322825 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2826 SetNotWaitingForResponse();
2827 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502828 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322829}
2830
[email protected]1ee614862009-07-06 20:29:182831bool TabContents::IsExternalTabContainer() const {
2832 if (!delegate())
2833 return false;
2834
2835 return delegate()->IsExternalTabContainer();
2836}
2837
[email protected]1ee614862009-07-06 20:29:182838void TabContents::DidInsertCSS() {
2839 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322840}
2841
[email protected]130efb02009-09-18 18:54:352842void TabContents::FocusedNodeChanged() {
2843 NotificationService::current()->Notify(
2844 NotificationType::FOCUS_CHANGED_IN_PAGE,
2845 Source<RenderViewHost>(render_view_host()),
2846 NotificationService::NoDetails());
2847}
2848
[email protected]420ae012009-04-24 05:16:322849void TabContents::FileSelected(const FilePath& path,
2850 int index, void* params) {
[email protected]35896a32010-06-09 08:42:512851 profile()->set_last_selected_directory(path.DirName());
[email protected]cdaf8d02010-03-30 19:52:472852 std::vector<FilePath> files;
2853 files.push_back(path);
2854 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322855}
2856
2857void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2858 void* params) {
[email protected]35896a32010-06-09 08:42:512859 if (!files.empty())
2860 profile()->set_last_selected_directory(files[0].DirName());
[email protected]cdaf8d02010-03-30 19:52:472861 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322862}
2863
2864void TabContents::FileSelectionCanceled(void* params) {
2865 // If the user cancels choosing a file to upload we pass back an
2866 // empty vector.
[email protected]cdaf8d02010-03-30 19:52:472867 render_view_host()->FilesSelectedInChooser(std::vector<FilePath>());
[email protected]420ae012009-04-24 05:16:322868}
2869
2870void TabContents::BeforeUnloadFiredFromRenderManager(
2871 bool proceed,
2872 bool* proceed_to_fire_unload) {
2873 if (delegate())
2874 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2875}
2876
2877void TabContents::UpdateRenderViewSizeForRenderManager() {
2878 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262879 gfx::Size size = view_->GetContainerSize();
2880 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2881 // here during container initialization and normal window size will be set
2882 // later. In case of tab duplication this resizing to 0x0 prevents setting
2883 // normal size later so just ignore it.
2884 if (!size.IsEmpty())
2885 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322886}
2887
2888DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222889 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322890}
2891
2892NavigationEntry*
2893TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2894 return controller_.GetLastCommittedEntry();
2895}
2896
2897bool TabContents::CreateRenderViewForRenderManager(
2898 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322899 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522900
2901 scoped_refptr<URLRequestContextGetter> request_context = request_context_;
2902 if (!request_context.get())
2903 request_context = profile()->GetRequestContext();
2904
[email protected]8ab04652010-06-12 02:47:262905 if (!render_view_host->CreateRenderView(request_context, string16()))
[email protected]420ae012009-04-24 05:16:322906 return false;
2907
2908 // Now that the RenderView has been created, we need to tell it its size.
2909 rwh_view->SetSize(view_->GetContainerSize());
2910
2911 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2912 render_view_host);
2913 return true;
2914}
2915
2916void TabContents::Observe(NotificationType type,
2917 const NotificationSource& source,
2918 const NotificationDetails& details) {
2919 switch (type.value) {
2920 case NotificationType::BOOKMARK_MODEL_LOADED:
2921 // BookmarkModel finished loading, fall through to update starred state.
2922 case NotificationType::URLS_STARRED: {
2923 // Somewhere, a URL has been starred.
2924 // Ignore notifications for profiles other than our current one.
2925 Profile* source_profile = Source<Profile>(source).ptr();
2926 if (!source_profile || !source_profile->IsSameProfile(profile()))
2927 return;
2928
2929 UpdateStarredStateForCurrentURL();
2930 break;
2931 }
2932 case NotificationType::PREF_CHANGED: {
2933 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2934 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2935 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2936 UpdateAlternateErrorPageURL();
2937 } else if (*pref_name_in == prefs::kDefaultCharset ||
2938 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2939 ) {
2940 UpdateWebPreferences();
2941 } else {
2942 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2943 }
2944 break;
2945 }
2946 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2947 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2948 break;
2949
2950 case NotificationType::NAV_ENTRY_COMMITTED: {
2951 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2952
2953 NavigationController::LoadCommittedDetails& committed_details =
2954 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2955 ExpireInfoBars(committed_details);
2956 break;
2957 }
2958
[email protected]d3ba77272009-09-03 00:06:092959#if defined(OS_LINUX)
2960 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542961 renderer_preferences_util::UpdateFromSystemSettings(
2962 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092963 render_view_host()->SyncRendererPrefs();
2964 break;
2965 }
2966#endif
2967
[email protected]6c32ce72010-03-08 05:18:062968 case NotificationType::USER_STYLE_SHEET_UPDATED:
2969 UpdateWebPreferences();
2970 break;
2971
[email protected]79580c62010-02-02 02:36:252972 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:292973 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:252974 settings_details(details);
[email protected]79580c62010-02-02 02:36:252975 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492976 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292977 if (entry)
[email protected]da0c8e92010-02-09 23:25:492978 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292979 if (settings_details.ptr()->update_all() ||
2980 settings_details.ptr()->pattern().Matches(entry_url)) {
2981 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232982 profile()->GetHostContentSettingsMap()->
2983 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252984 }
2985 break;
2986 }
2987
[email protected]e5adff72010-06-14 18:13:062988 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:572989 break;
[email protected]a888b29e62010-04-01 13:38:572990
2991 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:062992 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:572993 break;
[email protected]a888b29e62010-04-01 13:38:572994
[email protected]420ae012009-04-24 05:16:322995 default:
2996 NOTREACHED();
2997 }
2998}
[email protected]aacd7cc2009-09-02 14:51:102999
[email protected]98aa0b52010-05-06 17:03:083000void TabContents::UpdateExtensionAppIcon(Extension* extension) {
3001 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433002
[email protected]a888b29e62010-04-01 13:38:573003 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083004 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3005 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573006 extension,
3007 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
3008 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3009 Extension::EXTENSION_ICON_SMALLISH),
3010 ImageLoadingTracker::CACHE);
3011 } else {
[email protected]98aa0b52010-05-06 17:03:083012 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573013 }
3014}
3015
3016Extension* TabContents::GetExtensionContaining(const GURL& url) {
3017 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3018 if (!extensions_service)
3019 return NULL;
3020
3021 Extension* extension = extensions_service->GetExtensionByURL(url);
3022 return extension ?
3023 extension : extensions_service->GetExtensionByWebExtent(url);
3024}
3025
[email protected]a888b29e62010-04-01 13:38:573026void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3027 int index) {
3028 if (image) {
[email protected]98aa0b52010-05-06 17:03:083029 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573030 NotifyNavigationStateChanged(INVALIDATE_TAB);
3031 }
3032}
3033
[email protected]beb440c2009-11-06 04:08:543034std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3035 bool is_alert) {
3036 if (!frame_url.has_host())
3037 return l10n_util::GetString(
3038 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3039 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3040
3041 // We really only want the scheme, hostname, and port.
3042 GURL::Replacements replacements;
3043 replacements.ClearUsername();
3044 replacements.ClearPassword();
3045 replacements.ClearPath();
3046 replacements.ClearQuery();
3047 replacements.ClearRef();
3048 GURL clean_url = frame_url.ReplaceComponents(replacements);
3049
3050 // TODO(brettw) it should be easier than this to do the correct language
3051 // handling without getting the accept language from the profile.
3052 std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0,
3053 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
3054 // Force URL to have LTR directionality.
[email protected]4a4afe32010-05-05 01:39:563055 base::i18n::GetDisplayStringInLTRDirectionality(&base_address);
[email protected]beb440c2009-11-06 04:08:543056
3057 return l10n_util::GetStringF(
3058 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
3059 base_address);
3060}
3061
3062gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3063 return view_->GetTopLevelNativeWindow();
3064}
3065
3066void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3067 bool success,
3068 const std::wstring& prompt) {
3069 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3070 if (is_showing_before_unload_dialog_ && !success) {
3071 // If a beforeunload dialog is canceled, we need to stop the throbber from
3072 // spinning, since we forced it to start spinning in Navigate.
3073 DidStopLoading();
3074
3075 tab_close_start_time_ = base::TimeTicks();
3076 }
3077 is_showing_before_unload_dialog_ = false;
3078 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3079}
3080
3081void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3082 set_suppress_javascript_messages(suppress_message_boxes);
3083}
3084
[email protected]41fc0322009-09-04 22:23:403085void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103086 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3087}
[email protected]f45d2a72010-03-08 23:28:353088
3089void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3090 app_icon_ = app_icon;
3091 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3092}
[email protected]ea68c06a2010-04-23 17:25:373093
3094// After a successful *new* login attempt, we take the PasswordFormManager in
3095// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3096// the user makes up their mind with the "save password" infobar. Note if the
3097// login is one we already know about, the end of the line is
3098// provisional_save_manager_ because we just update it on success and so such
3099// forms never end up in an infobar.
3100class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3101 public:
3102 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463103 PasswordFormManager* form_to_save)
3104 : ConfirmInfoBarDelegate(tab_contents),
3105 form_to_save_(form_to_save),
3106 infobar_response_(kNoResponse) {
[email protected]ea68c06a2010-04-23 17:25:373107 }
3108
3109 virtual ~SavePasswordInfoBarDelegate() { }
3110
3111 // Overridden from ConfirmInfoBarDelegate:
3112 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463113 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
3114 infobar_response_, kNumResponseTypes);
[email protected]ea68c06a2010-04-23 17:25:373115 delete this;
3116 }
3117
3118 virtual std::wstring GetMessageText() const {
3119 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
3120 }
3121
3122 virtual SkBitmap* GetIcon() const {
3123 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3124 IDR_INFOBAR_SAVE_PASSWORD);
3125 }
3126
3127 virtual int GetButtons() const {
3128 return BUTTON_OK | BUTTON_CANCEL;
3129 }
3130
3131 virtual std::wstring GetButtonLabel(InfoBarButton button) const {
3132 if (button == BUTTON_OK)
3133 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
3134 if (button == BUTTON_CANCEL)
3135 return l10n_util::GetString(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
3136 NOTREACHED();
3137 return std::wstring();
3138 }
3139
3140 virtual bool Accept() {
3141 DCHECK(form_to_save_.get());
3142 form_to_save_->Save();
[email protected]12bb6822010-06-16 02:00:463143 infobar_response_ = kRememberPassword;
[email protected]ea68c06a2010-04-23 17:25:373144 return true;
3145 }
3146
3147 virtual bool Cancel() {
3148 DCHECK(form_to_save_.get());
3149 form_to_save_->PermanentlyBlacklist();
[email protected]12bb6822010-06-16 02:00:463150 infobar_response_ = kDontRememberPassword;
[email protected]ea68c06a2010-04-23 17:25:373151 return true;
3152 }
3153
3154 private:
3155 // The PasswordFormManager managing the form we're asking the user about,
3156 // and should update as per her decision.
3157 scoped_ptr<PasswordFormManager> form_to_save_;
3158
[email protected]12bb6822010-06-16 02:00:463159 // Used to track the results we get from the info bar.
3160 enum ResponseType {
3161 kNoResponse = 0,
3162 kRememberPassword,
3163 kDontRememberPassword,
3164 kNumResponseTypes,
3165 };
3166 ResponseType infobar_response_;
3167
[email protected]ea68c06a2010-04-23 17:25:373168 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3169};
3170
3171void TabContents::FillPasswordForm(
3172 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
3173 render_view_host()->FillPasswordForm(form_data);
3174}
3175
3176void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3177 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3178}
3179
3180Profile* TabContents::GetProfileForPasswordManager() {
3181 return profile();
3182}
3183
3184bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3185 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3186}