blob: d3e993d1e3cce509a2516c91cfdf8fa09ddfb89e [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),
284 extension_app_for_current_page_(NULL),
[email protected]fdd61c62009-04-22 19:22:57285 capturing_contents_(false),
286 is_being_destroyed_(false),
287 notify_disconnection_(false),
288 history_requests_(),
289#if defined(OS_WIN)
290 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
291#endif
292 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44293 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01294 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54295 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54296 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16297 language_state_(&controller_),
[email protected]b3df5a42010-05-11 14:31:09298 geolocation_settings_state_(profile),
[email protected]0cce15f2010-05-21 16:58:39299 requested_accessibility_tree_(false),
300 closed_by_user_gesture_(false) {
[email protected]0de80162010-02-03 04:52:35301 ClearBlockedContentSettings();
[email protected]7ff431e2010-01-07 18:18:54302 renderer_preferences_util::UpdateFromSystemSettings(
303 &renderer_preferences_, profile);
304
[email protected]16779842009-07-08 23:45:29305#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02306 // Make sure the thumbnailer is started before starting the render manager.
307 // The thumbnailer will want to listen for RVH creations, one of which will
308 // happen in RVHManager::Init.
309 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
310 if (generator)
311 generator->StartThumbnailing();
312#endif
313
[email protected]12636df2009-09-28 22:32:21314 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32315
[email protected]34ac70502009-09-25 17:07:23316 // We have the initial size of the view be based on the size of the passed in
317 // tab contents (normally a tab from the same window).
318 view_->CreateView(base_tab_contents ?
319 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32320
321 // Register for notifications about all interested prefs change.
322 PrefService* prefs = profile->GetPrefs();
323 if (prefs) {
324 for (int i = 0; i < kPrefsToObserveLength; ++i)
325 prefs->AddPrefObserver(kPrefsToObserve[i], this);
326 }
327
328 // Register for notifications about URL starredness changing on any profile.
329 registrar_.Add(this, NotificationType::URLS_STARRED,
330 NotificationService::AllSources());
331 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
332 NotificationService::AllSources());
333 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
334 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09335#if defined(OS_LINUX)
336 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
337 NotificationService::AllSources());
338#endif
[email protected]420ae012009-04-24 05:16:32339
[email protected]6c32ce72010-03-08 05:18:06340 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
341 NotificationService::AllSources());
342
[email protected]79580c62010-02-02 02:36:25343 // Register for notifications about content setting changes.
344 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
345 NotificationService::AllSources());
346
[email protected]a888b29e62010-04-01 13:38:57347 // Listen for extension changes so we can update extension_for_current_page_.
348 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
349 NotificationService::AllSources());
350 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
351 NotificationService::AllSources());
352 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
353 NotificationService::AllSources());
354
[email protected]c8865482009-07-23 20:40:10355 // Set-up the showing of the omnibox search infobar if applicable.
356 if (OmniboxSearchHint::IsEnabled(profile))
357 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]b3df5a42010-05-11 14:31:09358
359 renderer_accessible_ =
360 CommandLine::ForCurrentProcess()->HasSwitch(
361 switches::kEnableRendererAccessibility);
[email protected]332af7732009-03-11 13:21:35362}
initial.commit09911bf2008-07-26 23:55:29363
364TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32365 is_being_destroyed_ = true;
366
[email protected]bfe4c1582009-10-02 18:11:09367 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32368 registrar_.RemoveAll();
369
370 // Unregister the notifications of all observed prefs change.
371 PrefService* prefs = profile()->GetPrefs();
372 if (prefs) {
373 for (int i = 0; i < kPrefsToObserveLength; ++i)
374 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
375 }
376
[email protected]420ae012009-04-24 05:16:32377 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00378 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32379
[email protected]420ae012009-04-24 05:16:32380 // First cleanly close all child windows.
381 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
382 // some of these to close. CloseWindows is async, so it might get called
383 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49384 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32385
[email protected]8cc8d492010-02-02 10:40:49386 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13387 if (blocked_popups_)
388 blocked_popups_->Destroy();
389
[email protected]420ae012009-04-24 05:16:32390 // Notify any observer that have a reference on this tab contents.
391 NotificationService::current()->Notify(
392 NotificationType::TAB_CONTENTS_DESTROYED,
393 Source<TabContents>(this),
394 NotificationService::NoDetails());
395
[email protected]1e5e74f2009-05-27 20:55:12396 // Notify any lasting InfobarDelegates that have not yet been removed that
397 // whatever infobar they were handling in this TabContents has closed,
398 // because the TabContents is going away entirely.
399 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
400 // notification may trigger infobars calls that access their delegate. (and
401 // some implementations of InfoBarDelegate do delete themselves on
402 // InfoBarClosed()).
403 for (int i = 0; i < infobar_delegate_count(); ++i) {
404 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
405 delegate->InfoBarClosed();
406 }
407 infobar_delegates_.clear();
408
[email protected]420ae012009-04-24 05:16:32409 // TODO(brettw) this should be moved to the view.
410#if defined(OS_WIN)
411 // If we still have a window handle, destroy it. GetNativeView can return
412 // NULL if this contents was part of a window that closed.
413 if (GetNativeView())
414 ::DestroyWindow(GetNativeView());
415#endif
[email protected]7ab1e7d62009-10-14 23:32:01416
417 // OnCloseStarted isn't called in unit tests.
418 if (!tab_close_start_time_.is_null()) {
419 UMA_HISTOGRAM_TIMES("Tab.Close",
420 base::TimeTicks::Now() - tab_close_start_time_);
421 }
initial.commit09911bf2008-07-26 23:55:29422}
423
[email protected]d5f942ba2008-09-26 19:30:34424// static
425void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32426 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
427
428 WebPreferences pref_defaults;
429 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
430 pref_defaults.javascript_enabled);
431 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
432 pref_defaults.web_security_enabled);
433 prefs->RegisterBooleanPref(
434 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
435 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
436 pref_defaults.loads_images_automatically);
437 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
438 pref_defaults.plugins_enabled);
439 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
440 pref_defaults.dom_paste_enabled);
441 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
442 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14443 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32444 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
445 pref_defaults.text_areas_are_resizable);
446 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
447 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36448 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
449 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32450
451 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
452 IDS_ACCEPT_LANGUAGES);
453 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
454 IDS_DEFAULT_ENCODING);
455 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
456 IDS_STANDARD_FONT_IS_SERIF);
457 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
458 IDS_FIXED_FONT_FAMILY);
459 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
460 IDS_SERIF_FONT_FAMILY);
461 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
462 IDS_SANS_SERIF_FONT_FAMILY);
463 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
464 IDS_CURSIVE_FONT_FAMILY);
465 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
466 IDS_FANTASY_FONT_FAMILY);
467 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
468 IDS_DEFAULT_FONT_SIZE);
469 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
470 IDS_DEFAULT_FIXED_FONT_SIZE);
471 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
472 IDS_MINIMUM_FONT_SIZE);
473 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
474 IDS_MINIMUM_LOGICAL_FONT_SIZE);
475 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
476 IDS_USES_UNIVERSAL_DETECTOR);
477 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
478 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29479}
480
[email protected]13367f72009-07-08 16:39:02481// Returns true if contains content rendered by an extension.
482bool TabContents::HostsExtension() const {
483 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34484}
485
[email protected]cf28ec52010-04-09 22:56:34486AutoFillManager* TabContents::GetAutoFillManager() {
487 if (autofill_manager_.get() == NULL)
488 autofill_manager_.reset(new AutoFillManager(this));
489 return autofill_manager_.get();
490}
491
[email protected]6e95706d2009-04-23 22:55:01492PasswordManager* TabContents::GetPasswordManager() {
493 if (password_manager_.get() == NULL)
494 password_manager_.reset(new PasswordManager(this));
495 return password_manager_.get();
496}
497
498PluginInstaller* TabContents::GetPluginInstaller() {
499 if (plugin_installer_.get() == NULL)
500 plugin_installer_.reset(new PluginInstaller(this));
501 return plugin_installer_.get();
502}
503
[email protected]8cb5d5b2010-02-09 11:36:16504RenderProcessHost* TabContents::GetRenderProcessHost() const {
505 return render_manager_.current_host()->process();
506}
507
[email protected]98aa0b52010-05-06 17:03:08508void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46509 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08510 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10511
[email protected]98aa0b52010-05-06 17:03:08512 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57513
[email protected]fca656c2010-02-10 20:30:10514 NotificationService::current()->Notify(
515 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
516 Source<TabContents>(this),
517 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49518}
519
[email protected]98aa0b52010-05-06 17:03:08520void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
521 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40522 return;
523
524 ExtensionsService* extension_service = profile()->GetExtensionsService();
525 if (extension_service && extension_service->is_ready()) {
526 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08527 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40528 if (extension)
[email protected]98aa0b52010-05-06 17:03:08529 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40530 }
531}
532
[email protected]98aa0b52010-05-06 17:03:08533SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]8eb043b2010-04-30 07:19:51534 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because
535 // for those windows, we already have a big icon in the top-left outside any
536 // tab. Having big tab icons too looks kinda redonk.
[email protected]06821f42d2010-05-03 22:34:35537 Browser* browser = delegate_ ? delegate_->GetBrowser() : NULL;
538 if (browser && browser->type() == Browser::TYPE_EXTENSION_APP)
[email protected]8eb043b2010-04-30 07:19:51539 return NULL;
[email protected]8eb043b2010-04-30 07:19:51540
[email protected]98aa0b52010-05-06 17:03:08541 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51542 return NULL;
543
[email protected]98aa0b52010-05-06 17:03:08544 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51545}
546
[email protected]d5f942ba2008-09-26 19:30:34547const GURL& TabContents::GetURL() const {
548 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57549 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54550 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34551}
552
[email protected]96d185d2009-04-24 03:28:54553const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55554 // Transient entries take precedence. They are used for interstitial pages
555 // that are shown on top of existing pages.
556 NavigationEntry* entry = controller_.GetTransientEntry();
557 if (entry)
558 return entry->GetTitleForDisplay(&controller_);
559
[email protected]96d185d2009-04-24 03:28:54560 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
561 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
562 if (our_dom_ui) {
563 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55564 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54565 if (!(entry && entry->IsViewSourceMode())) {
566 // Give the DOM UI the chance to override our title.
567 const string16& title = our_dom_ui->overridden_title();
568 if (!title.empty())
569 return title;
570 }
571 }
572
573 // We use the title for the last committed entry rather than a pending
574 // navigation entry. For example, when the user types in a URL, we want to
575 // keep the old page's title until the new load has committed and we get a new
576 // title.
[email protected]96d185d2009-04-24 03:28:54577 entry = controller_.GetLastCommittedEntry();
578 if (entry)
579 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54580 return EmptyString16();
581}
582
[email protected]bbbc1ef2010-02-12 18:03:41583// static
584string16 TabContents::GetDefaultTitle() {
585 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
586}
587
[email protected]d5f942ba2008-09-26 19:30:34588int32 TabContents::GetMaxPageID() {
589 if (GetSiteInstance())
590 return GetSiteInstance()->max_page_id();
591 else
592 return max_page_id_;
593}
594
595void TabContents::UpdateMaxPageID(int32 page_id) {
596 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34597 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34598 // testing.
599 if (GetSiteInstance())
600 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16601 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34602}
603
[email protected]96d185d2009-04-24 03:28:54604SiteInstance* TabContents::GetSiteInstance() const {
605 return render_manager_.current_host()->site_instance();
606}
607
[email protected]96d185d2009-04-24 03:28:54608bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15609 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54610 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15611 if (entry && (entry->IsViewSourceMode() ||
612 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54613 return true;
[email protected]8ab24cc2009-11-13 20:56:15614 }
[email protected]83e3895b2009-06-11 00:07:16615
[email protected]96d185d2009-04-24 03:28:54616 DOMUI* dom_ui = GetDOMUIForCurrentState();
617 if (dom_ui)
618 return !dom_ui->should_hide_url();
619 return true;
620}
621
[email protected]d5f942ba2008-09-26 19:30:34622SkBitmap TabContents::GetFavIcon() const {
623 // Like GetTitle(), we also want to use the favicon for the last committed
624 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57625 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47626 if (entry)
627 return entry->favicon().bitmap();
628
[email protected]ce3fa3c2009-04-20 19:55:57629 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34630 if (entry)
631 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34632 return SkBitmap();
633}
634
[email protected]0b303cc2009-09-28 22:35:15635bool TabContents::FavIconIsValid() const {
636 NavigationEntry* entry = controller_.GetTransientEntry();
637 if (entry)
638 return entry->favicon().is_valid();
639
640 entry = controller_.GetLastCommittedEntry();
641 if (entry)
642 return entry->favicon().is_valid();
643
644 return false;
645}
646
[email protected]96d185d2009-04-24 03:28:54647bool TabContents::ShouldDisplayFavIcon() {
648 // Always display a throbber during pending loads.
649 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
650 return true;
651
652 DOMUI* dom_ui = GetDOMUIForCurrentState();
653 if (dom_ui)
654 return !dom_ui->hide_favicon();
655 return true;
656}
657
[email protected]2d5a3592010-01-30 04:29:52658bool TabContents::IsContentBlocked(ContentSettingsType content_type) const {
[email protected]8cc8d492010-02-02 10:40:49659 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS)
660 return blocked_popups_ != NULL;
661
[email protected]0de80162010-02-03 04:52:35662 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES ||
663 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT ||
[email protected]3dbb80b2010-02-09 22:41:20664 content_type == CONTENT_SETTINGS_TYPE_PLUGINS ||
665 content_type == CONTENT_SETTINGS_TYPE_COOKIES)
[email protected]0de80162010-02-03 04:52:35666 return content_blocked_[content_type];
667
[email protected]b1235062010-03-25 17:31:27668 // TODO(joth): remove once fully implemented.
669 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
670 return false;
671
[email protected]3dbb80b2010-02-09 22:41:20672 NOTREACHED();
[email protected]2d5a3592010-01-30 04:29:52673 return false;
674}
675
[email protected]96d185d2009-04-24 03:28:54676std::wstring TabContents::GetStatusText() const {
677 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
678 return std::wstring();
679
680 switch (load_state_) {
681 case net::LOAD_STATE_WAITING_FOR_CACHE:
682 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04683 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
684 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54685 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
686 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
687 case net::LOAD_STATE_RESOLVING_HOST:
688 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
689 case net::LOAD_STATE_CONNECTING:
690 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06691 case net::LOAD_STATE_SSL_HANDSHAKE:
692 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54693 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56694 if (upload_size_)
695 return l10n_util::GetStringF(
696 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
697 static_cast<int>((100 * upload_position_) / upload_size_));
698 else
699 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54700 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
701 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
702 load_state_host_);
703 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
704 case net::LOAD_STATE_IDLE:
705 case net::LOAD_STATE_READING_RESPONSE:
706 break;
707 }
708
709 return std::wstring();
710}
711
[email protected]d5f942ba2008-09-26 19:30:34712void TabContents::SetIsCrashed(bool state) {
713 if (state == is_crashed_)
714 return;
715
716 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50717 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34718}
719
[email protected]744ef172009-10-16 21:53:46720void TabContents::PageActionStateChanged() {
721 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00722}
[email protected]ce5c4502009-05-06 16:46:11723
[email protected]d5f942ba2008-09-26 19:30:34724void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
725 if (delegate_)
726 delegate_->NavigationStateChanged(this, changed_flags);
727}
728
[email protected]96d185d2009-04-24 03:28:54729void TabContents::DidBecomeSelected() {
730 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16731 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
732 if (rwhv) {
733 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43734#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16735 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43736#endif
737 }
[email protected]96d185d2009-04-24 03:28:54738
[email protected]8cb5d5b2010-02-09 11:36:16739 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54740}
741
742void TabContents::WasHidden() {
743 if (!capturing_contents()) {
744 // |render_view_host()| can be NULL if the user middle clicks a link to open
745 // a tab in then background, then closes the tab before selecting it. This
746 // is because closing the tab calls TabContents::Destroy(), which removes
747 // the |render_view_host()|; then when we actually destroy the window,
748 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16749 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
750 if (rwhv)
751 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54752 }
753
754 NotificationService::current()->Notify(
755 NotificationType::TAB_CONTENTS_HIDDEN,
756 Source<TabContents>(this),
757 NotificationService::NoDetails());
758}
759
[email protected]d5f942ba2008-09-26 19:30:34760void TabContents::Activate() {
761 if (delegate_)
762 delegate_->ActivateContents(this);
763}
764
[email protected]96d185d2009-04-24 03:28:54765void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16766 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
767 if (rwhv)
768 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54769}
770
771void TabContents::HideContents() {
772 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
773 // our superclass HideContents(), because some callers want to be very picky
774 // about the order in which these get called. In addition to making the code
775 // here practically impossible to understand, this also means we end up
776 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34777 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54778 WasHidden();
779}
780
[email protected]c0588052008-10-27 23:01:50781void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34782 WindowOpenDisposition disposition,
783 PageTransition::Type transition) {
784 if (delegate_)
[email protected]c0588052008-10-27 23:01:50785 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34786}
787
[email protected]1ccb3568d2010-02-19 10:51:16788bool TabContents::NavigateToPendingEntry(
789 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54790 const NavigationEntry& entry = *controller_.pending_entry();
791
792 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
793 if (!dest_render_view_host)
794 return false; // Unable to create the desired render view host.
795
[email protected]770dd8b2010-05-24 18:11:39796 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
797 dest_render_view_host->EnablePreferredSizeChangedMode(
798 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
799 }
[email protected]9fb325e2010-05-06 18:23:24800
[email protected]0352e5472010-04-29 00:11:40801 // For security, we should never send non-DOM-UI URLs (other than about:blank)
802 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58803 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40804 bool is_allowed_in_dom_ui_renderer =
805 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
806 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58807 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40808 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58809
[email protected]96d185d2009-04-24 03:28:54810 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12811 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32812 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00813 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
814 dest_render_view_host,
815 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32816 }
[email protected]96d185d2009-04-24 03:28:54817
818 // Used for page load time metrics.
819 current_load_start_ = base::TimeTicks::Now();
820
821 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34822 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00823 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34824 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54825
826 if (entry.page_id() == -1) {
827 // HACK!! This code suppresses javascript: URLs from being added to
828 // session history, which is what we want to do for javascript: URLs that
829 // do not generate content. What we really need is a message from the
830 // renderer telling us that a new page was not created. The same message
831 // could be used for mailto: URLs and the like.
832 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
833 return false;
834 }
835
836 // Clear any provisional password saves - this stops password infobars
837 // showing up on pages the user navigates to while the right page is
838 // loading.
839 GetPasswordManager()->ClearProvisionalSave();
840
[email protected]1ccb3568d2010-02-19 10:51:16841 if (reload_type != NavigationController::NO_RELOAD &&
842 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48843 FaviconService* favicon_service =
844 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
845 if (favicon_service)
846 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54847 }
848
[email protected]a888b29e62010-04-01 13:38:57849 // The url likely changed, see if there is an extension whose extent contains
850 // the current page.
[email protected]98aa0b52010-05-06 17:03:08851 UpdateExtensionAppForCurrentPage();
[email protected]a888b29e62010-04-01 13:38:57852
[email protected]d5f942ba2008-09-26 19:30:34853 return true;
854}
855
[email protected]96d185d2009-04-24 03:28:54856void TabContents::Stop() {
857 render_manager_.Stop();
858 printing_.Stop();
859}
860
[email protected]96d185d2009-04-24 03:28:54861void TabContents::DisassociateFromPopupCount() {
862 render_view_host()->DisassociateFromPopupCount();
863}
864
865TabContents* TabContents::Clone() {
866 // We create a new SiteInstance so that the new tab won't share processes
867 // with the old one. This can be changed in the future if we need it to share
868 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32869 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54870 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21871 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54872 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08873 tc->extension_app_ = extension_app_;
874 tc->extension_app_for_current_page_ = extension_app_for_current_page_;
875 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54876 return tc;
877}
878
[email protected]4d677202009-07-19 07:37:12879void TabContents::ShowPageInfo(const GURL& url,
880 const NavigationEntry::SSLStatus& ssl,
881 bool show_history) {
882 if (!delegate_)
883 return;
884
[email protected]bb678332009-07-21 00:15:50885 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12886}
887
initial.commit09911bf2008-07-26 23:55:29888ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28889 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29890 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28891 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29892 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44893
894 if (child_windows_.size() == 1) {
895 window->ShowConstrainedWindow();
896 BlockTabContent(true);
897 }
898
initial.commit09911bf2008-07-26 23:55:29899 return window;
900}
901
[email protected]fa1cf0b82010-01-15 21:49:44902void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55903 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
904 if (rwhv)
905 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44906 render_view_host()->set_ignore_input_events(blocked);
907 if (delegate_)
908 delegate_->SetTabContentBlocked(this, blocked);
909}
910
initial.commit09911bf2008-07-26 23:55:29911void TabContents::AddNewContents(TabContents* new_contents,
912 WindowOpenDisposition disposition,
913 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29914 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29915 if (!delegate_)
916 return;
917
[email protected]35f7d212009-04-29 21:19:27918 if ((disposition == NEW_POPUP) && !user_gesture &&
919 !CommandLine::ForCurrentProcess()->HasSwitch(
920 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22921 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31922 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29923 delegate_->GetConstrainingContents(this)->AddPopup(
924 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31925 } else {
[email protected]304f8792009-08-19 21:28:09926#if defined(OS_CHROMEOS)
927 if (disposition == NEW_POPUP) {
928 // If the popup is bigger than a given factor of the screen, then
929 // turn it into a foreground tab (on chrome os only)
930 GdkScreen* screen = gdk_screen_get_default();
931 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
932 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
933 if (initial_pos.width() > max_width ||
934 initial_pos.height() > max_height) {
935 disposition = NEW_FOREGROUND_TAB;
936 }
937 }
938#endif
939
[email protected]0aa55312008-10-17 21:53:08940 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29941 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
942 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49943 NotificationService::current()->Notify(
944 NotificationType::TAB_ADDED,
945 Source<TabContentsDelegate>(delegate_),
946 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29947 }
initial.commit09911bf2008-07-26 23:55:29948
[email protected]8cc8d492010-02-02 10:40:49949 // TODO(pkasting): Why is this necessary?
950 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:29951}
952
[email protected]bcd9dc42010-01-23 16:38:18953bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:20954 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:20955 bool is_js_code, const std::string& code_string,
956 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51957 RenderViewHost* host = render_view_host();
958 if (!host)
959 return false;
960
961 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
962 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
963 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35964}
965
[email protected]96d185d2009-04-24 03:28:54966void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49967 if (is_being_destroyed_)
968 return;
969 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40970 render_view_host()->AllowScriptToClose(!visible);
[email protected]0de80162010-02-03 04:52:35971 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:24972 delegate_->OnContentSettingsChange(this);
[email protected]96d185d2009-04-24 03:28:54973}
974
[email protected]5c9e97a2009-09-09 23:48:30975gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54976 return view_->GetContentNativeView();
977}
978
979gfx::NativeView TabContents::GetNativeView() const {
980 return view_->GetNativeView();
981}
982
983void TabContents::GetContainerBounds(gfx::Rect *out) const {
984 view_->GetContainerBounds(out);
985}
986
987void TabContents::Focus() {
988 view_->Focus();
989}
990
[email protected]90daadb42009-06-08 21:27:28991void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54992 if (showing_interstitial_page()) {
993 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
994 return;
995 }
[email protected]96d185d2009-04-24 03:28:54996 render_view_host()->SetInitialFocus(reverse);
997}
998
999bool TabContents::FocusLocationBarByDefault() {
1000 DOMUI* dom_ui = GetDOMUIForCurrentState();
1001 if (dom_ui)
1002 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431003 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251004 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431005 return true;
[email protected]96d185d2009-04-24 03:28:541006 return false;
1007}
1008
[email protected]a26dc362010-04-23 01:48:581009void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381010 if (delegate())
[email protected]a26dc362010-04-23 01:48:581011 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381012}
1013
[email protected]616ed5a2008-11-21 22:27:241014void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321015 if (delegate_ && !delegate_->infobars_enabled()) {
1016 delegate->InfoBarClosed();
1017 return;
1018 }
1019
[email protected]616ed5a2008-11-21 22:27:241020 // Look through the existing InfoBarDelegates we have for a match. If we've
1021 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051022 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451023 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1024 // Tell the new infobar to close so that it can clean itself up.
1025 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241026 return;
[email protected]6d27a7b2009-12-18 23:25:451027 }
[email protected]616ed5a2008-11-21 22:27:241028 }
1029
1030 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561031 NotificationService::current()->Notify(
1032 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1033 Source<TabContents>(this),
1034 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241035
1036 // Add ourselves as an observer for navigations the first time a delegate is
1037 // added. We use this notification to expire InfoBars that need to expire on
1038 // page transitions.
1039 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561040 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571041 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241042 }
1043}
1044
1045void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321046 if (delegate_ && !delegate_->infobars_enabled()) {
1047 return;
1048 }
1049
[email protected]616ed5a2008-11-21 22:27:241050 std::vector<InfoBarDelegate*>::iterator it =
1051 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1052 if (it != infobar_delegates_.end()) {
1053 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561054 NotificationService::current()->Notify(
1055 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1056 Source<TabContents>(this),
1057 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:051058 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:241059
[email protected]6a02963e2009-01-06 16:58:031060 // Remove ourselves as an observer if we are tracking no more InfoBars.
1061 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:561062 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571063 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031064 }
[email protected]616ed5a2008-11-21 22:27:241065 }
1066}
[email protected]3edd9522009-03-04 22:19:411067
[email protected]f81821c2009-08-07 01:29:471068void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1069 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321070 if (delegate_ && !delegate_->infobars_enabled()) {
1071 new_delegate->InfoBarClosed();
1072 return;
1073 }
1074
[email protected]f81821c2009-08-07 01:29:471075 std::vector<InfoBarDelegate*>::iterator it =
1076 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1077 DCHECK(it != infobar_delegates_.end());
1078
1079 // Notify the container about the change of plans.
1080 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1081 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1082 old_delegate, new_delegate));
1083 NotificationService::current()->Notify(
1084 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1085 Source<TabContents>(this),
1086 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1087
1088 // Remove the old one.
1089 infobar_delegates_.erase(it);
1090
1091 // Add the new one.
1092 infobar_delegates_.push_back(new_delegate);
1093}
1094
[email protected]20ede072009-10-06 00:28:351095bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271096 if (showing_interstitial_page())
1097 return false;
1098
[email protected]96d185d2009-04-24 03:28:541099 // See GetDOMUIForCurrentState() comment for more info. This case is very
1100 // similar, but for non-first loads, we want to use the committed entry. This
1101 // is so the bookmarks bar disappears at the same time the page does.
1102 if (controller_.GetLastCommittedEntry()) {
1103 // Not the first load, always use the committed DOM UI.
1104 if (render_manager_.dom_ui())
1105 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1106 return false; // Default.
1107 }
1108
1109 // When it's the first load, we know either the pending one or the committed
1110 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1111 // of them will be valid, so we can just check both.
1112 if (render_manager_.pending_dom_ui())
1113 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1114 if (render_manager_.dom_ui())
1115 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1116 return false; // Default.
1117}
1118
[email protected]d8f16ae2009-08-30 03:47:261119bool TabContents::IsExtensionShelfAlwaysVisible() {
1120 // See GetDOMUIForCurrentState() comment for more info. This case is very
1121 // similar, but for non-first loads, we want to use the committed entry. This
1122 // is so the bookmarks bar disappears at the same time the page does.
1123 if (controller_.GetLastCommittedEntry()) {
1124 // Not the first load, always use the committed DOM UI.
1125 if (render_manager_.dom_ui())
1126 return render_manager_.dom_ui()->force_extension_shelf_visible();
1127 return false; // Default.
1128 }
1129
1130 // When it's the first load, we know either the pending one or the committed
1131 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1132 // of them will be valid, so we can just check both.
1133 if (render_manager_.pending_dom_ui())
1134 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
1135 if (render_manager_.dom_ui())
1136 return render_manager_.dom_ui()->force_extension_shelf_visible();
1137 return false; // Default.
1138}
1139
[email protected]3edd9522009-03-04 22:19:411140void TabContents::ToolbarSizeChanged(bool is_animating) {
1141 TabContentsDelegate* d = delegate();
1142 if (d)
1143 d->ToolbarSizeChanged(this, is_animating);
1144}
[email protected]616ed5a2008-11-21 22:27:241145
[email protected]fc6fb7fb2009-11-07 02:35:041146bool TabContents::CanDownload(int request_id) {
1147 TabContentsDelegate* d = delegate();
1148 if (d)
1149 return d->CanDownload(request_id);
1150 return true;
1151}
1152
[email protected]d5f942ba2008-09-26 19:30:341153void TabContents::OnStartDownload(DownloadItem* download) {
1154 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341155
1156 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311157 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341158
[email protected]c70f9b82010-04-21 07:31:111159 if (tab_contents && tab_contents->delegate()) {
[email protected]59560e0b2009-06-04 03:30:221160 tab_contents->delegate()->OnStartDownload(download);
[email protected]c70f9b82010-04-21 07:31:111161 // If the download occurs in a new tab, close it
1162 if (controller_.IsInitialNavigation() && (tab_contents == this))
1163 delegate()->CloseContents(this);
1164 }
[email protected]3edd9522009-03-04 22:19:411165}
[email protected]3edd9522009-03-04 22:19:411166
[email protected]d5f942ba2008-09-26 19:30:341167void TabContents::WillClose(ConstrainedWindow* window) {
1168 ConstrainedWindowList::iterator it =
1169 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441170 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341171 if (it != child_windows_.end())
1172 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371173 if (child_windows_.size() > 0) {
1174 if (removed_topmost_window) {
1175 child_windows_[0]->ShowConstrainedWindow();
1176 }
[email protected]fa1cf0b82010-01-15 21:49:441177 BlockTabContent(true);
1178 } else {
1179 BlockTabContent(false);
1180 }
[email protected]66ba4932009-06-04 19:22:131181}
[email protected]d5f942ba2008-09-26 19:30:341182
[email protected]66ba4932009-06-04 19:22:131183void TabContents::WillCloseBlockedPopupContainer(
1184 BlockedPopupContainer* container) {
1185 DCHECK(blocked_popups_ == container);
1186 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491187 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341188}
1189
[email protected]d5f942ba2008-09-26 19:30:341190void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351191#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061192 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351193#endif
[email protected]d5f942ba2008-09-26 19:30:341194}
1195
[email protected]c1dc9f132009-11-20 23:13:211196void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121197 bool forward_direction,
1198 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211199 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011200 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211201 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531202 string16 last_search_prepopulate_text =
1203 FindBarState::GetLastPrepopulateText(profile());
1204
[email protected]87fae512009-12-11 02:20:211205 // Try the last thing we searched for on this tab, then the last thing
1206 // searched for on any tab.
1207 if (!previous_find_text_.empty())
1208 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531209 else if (!last_search_prepopulate_text.empty())
1210 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211211 else
[email protected]e491f1c2009-05-22 20:28:121212 return;
[email protected]e491f1c2009-05-22 20:28:121213 }
[email protected]6e95706d2009-04-23 22:55:011214
[email protected]101c90e2009-10-26 21:14:441215 // Keep track of the previous search.
1216 previous_find_text_ = find_text_;
1217
[email protected]6e95706d2009-04-23 22:55:011218 // This is a FindNext operation if we are searching for the same text again,
1219 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1220 // exception to this is if the Find was aborted (then we don't want FindNext
1221 // because the highlighting has been cleared and we need it to reappear). We
1222 // therefore treat FindNext after an aborted Find operation as a full fledged
1223 // Find.
[email protected]c1dc9f132009-11-20 23:13:211224 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121225 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011226 !find_op_aborted_;
1227 if (!find_next)
1228 current_find_request_id_ = find_request_id_counter_++;
1229
[email protected]c1dc9f132009-11-20 23:13:211230 if (!search_string.empty())
1231 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121232 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011233
1234 find_op_aborted_ = false;
1235
1236 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531237 FindBarState* find_bar_state = profile()->GetFindBarState();
1238 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011239 render_view_host()->StartFinding(current_find_request_id_,
1240 find_text_,
1241 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121242 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011243 find_next);
1244}
1245
[email protected]5bc8fe92010-03-11 18:19:001246void TabContents::StopFinding(
1247 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011248 if (selection_action == FindBarController::kClearSelection) {
1249 // kClearSelection means the find string has been cleared by the user, but
1250 // the UI has not been dismissed. In that case we want to clear the
1251 // previously remembered search (http://crbug.com/42639).
1252 previous_find_text_ = string16();
1253 } else {
[email protected]2d2dffc2009-06-09 21:41:001254 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011255 if (!find_text_.empty())
1256 previous_find_text_ = find_text_;
1257 }
[email protected]101c90e2009-10-26 21:14:441258 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011259 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121260 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001261 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011262}
1263
[email protected]420ae012009-04-24 05:16:321264void TabContents::OnSavePage() {
1265 // If we can not save the page, try to download it.
1266 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1267 DownloadManager* dlm = profile()->GetDownloadManager();
1268 const GURL& current_page_url = GetURL();
1269 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221270 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321271 return;
1272 }
1273
1274 Stop();
1275
1276 // Create the save package and possibly prompt the user for the name to save
1277 // the page as. The user prompt is an asynchronous operation that runs on
1278 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221279 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321280 save_package_->GetSaveInfo();
1281}
1282
1283// Used in automated testing to bypass prompting the user for file names.
1284// Instead, the names and paths are hard coded rather than running them through
1285// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111286bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321287 SavePackage::SavePackageType save_type) {
1288 // Stop the page from navigating.
1289 Stop();
1290
[email protected]828cabe2009-09-26 22:47:111291 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591292 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321293}
1294
[email protected]89d6e6e2009-12-03 23:06:511295void TabContents::EmailPageLocation() {
1296 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1297 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1298 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1299 title + "&body=%0A%0A" + page_url;
1300 platform_util::OpenExternal(GURL(mailto));
1301}
1302
[email protected]420ae012009-04-24 05:16:321303void TabContents::PrintPreview() {
1304 // We don't show the print preview yet, only the print dialog.
1305 PrintNow();
1306}
1307
1308bool TabContents::PrintNow() {
1309 // We can't print interstitial page for now.
1310 if (showing_interstitial_page())
1311 return false;
1312
1313 return render_view_host()->PrintPages();
1314}
1315
[email protected]82270452009-06-19 15:58:011316void TabContents::PrintingDone(int document_cookie, bool success) {
1317 render_view_host()->PrintingDone(document_cookie, success);
1318}
1319
[email protected]420ae012009-04-24 05:16:321320bool TabContents::IsActiveEntry(int32 page_id) {
1321 NavigationEntry* active_entry = controller_.GetActiveEntry();
1322 return (active_entry != NULL &&
1323 active_entry->site_instance() == GetSiteInstance() &&
1324 active_entry->page_id() == page_id);
1325}
1326
[email protected]b2fe07d12010-02-09 14:38:081327void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161328 set_encoding(encoding);
1329 render_view_host()->SetPageEncoding(encoding);
1330}
1331
[email protected]b2fe07d12010-02-09 14:38:081332void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161333 reset_encoding();
1334 render_view_host()->ResetPageEncodingToDefault();
1335}
1336
1337void TabContents::WindowMoveOrResizeStarted() {
1338 render_view_host()->WindowMoveOrResizeStarted();
1339}
1340
[email protected]3f8eb7f2009-10-02 23:58:051341void TabContents::LogNewTabTime(const std::string& event_name) {
1342 // Not all new tab pages get timed. In those cases, we don't have a
1343 // new_tab_start_time_.
1344 if (new_tab_start_time_.is_null())
1345 return;
1346
1347 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441348 MetricEventDurationDetails details(event_name,
1349 static_cast<int>(duration.InMilliseconds()));
1350
[email protected]7ab1e7d62009-10-14 23:32:011351 if (event_name == "Tab.NewTabScriptStart") {
1352 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1353 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1354 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1355 } else if (event_name == "Tab.NewTabOnload") {
1356 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051357 // The new tab page has finished loading; reset it.
1358 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441359 } else {
1360 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051361 }
[email protected]84abba62009-10-07 17:01:441362 NotificationService::current()->Notify(
1363 NotificationType::METRIC_EVENT_DURATION,
1364 Source<TabContents>(this),
1365 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051366}
1367
[email protected]7ab1e7d62009-10-14 23:32:011368void TabContents::OnCloseStarted() {
1369 if (tab_close_start_time_.is_null())
1370 tab_close_start_time_ = base::TimeTicks::Now();
1371}
1372
[email protected]c37e3b62010-01-22 00:15:171373TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171374 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161375
1376 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081377 if (extension_app_)
1378 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161379 else if (entry)
1380 tab_nav.SetFromNavigationEntry(*entry);
1381
[email protected]c37e3b62010-01-22 00:15:171382 std::vector<TabNavigation> navigations;
1383 navigations.push_back(tab_nav);
1384
1385 TabContents* new_contents =
1386 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081387 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171388 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171389
[email protected]98aa0b52010-05-06 17:03:081390 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161391 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1392
[email protected]c37e3b62010-01-22 00:15:171393 return new_contents;
1394}
1395
[email protected]0de80162010-02-03 04:52:351396// Resets the |content_blocked_| array.
1397void TabContents::ClearBlockedContentSettings() {
[email protected]15cf526b2010-02-12 06:33:491398 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
[email protected]0de80162010-02-03 04:52:351399 content_blocked_[i] = false;
1400}
1401
[email protected]96d185d2009-04-24 03:28:541402// Notifies the RenderWidgetHost instance about the fact that the page is
1403// loading, or done loading and calls the base implementation.
1404void TabContents::SetIsLoading(bool is_loading,
1405 LoadNotificationDetails* details) {
1406 if (is_loading == is_loading_)
1407 return;
1408
1409 if (!is_loading) {
1410 load_state_ = net::LOAD_STATE_IDLE;
1411 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561412 upload_size_ = 0;
1413 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541414 }
1415
1416 render_manager_.SetIsLoading(is_loading);
1417
1418 is_loading_ = is_loading;
1419 waiting_for_response_ = is_loading;
1420
1421 if (delegate_)
1422 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351423 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541424
1425 NotificationType type = is_loading ? NotificationType::LOAD_START :
1426 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111427 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541428 if (details)
1429 det = Details<LoadNotificationDetails>(details);
1430 NotificationService::current()->Notify(type,
1431 Source<NavigationController>(&controller_),
1432 det);
1433}
1434
[email protected]b6c874582009-05-08 19:38:311435void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291436 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061437 // A page can't spawn popups (or do anything else, either) until its load
1438 // commits, so when we reach here, the popup was spawned by the
1439 // NavigationController's last committed entry, not the active entry. For
1440 // example, if a page opens a popup in an onunload() handler, then the active
1441 // entry is the page to be loaded as we navigate away from the unloading
1442 // page. For this reason, we can't use GetURL() to get the opener URL,
1443 // because it returns the active entry.
1444 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1445 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1446
1447 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491448 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]57eda82a2010-05-05 21:28:061449 creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491450 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1451 } else {
1452 if (!blocked_popups_)
1453 blocked_popups_ = new BlockedPopupContainer(this);
1454 blocked_popups_->AddTabContents(new_contents, initial_pos);
1455 }
[email protected]b9681312008-11-07 00:08:261456}
[email protected]616ed5a2008-11-21 22:27:241457
1458namespace {
1459bool TransitionIsReload(PageTransition::Type transition) {
1460 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1461}
1462}
1463
1464void TabContents::ExpireInfoBars(
1465 const NavigationController::LoadCommittedDetails& details) {
1466 // Only hide InfoBars when the user has done something that makes the main
1467 // frame load. We don't want various automatic or subframe navigations making
1468 // it disappear.
1469 if (!details.is_user_initiated_main_frame_load())
1470 return;
1471
[email protected]f86a07022008-11-25 01:06:051472 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241473 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051474 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241475 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241476 }
1477}
[email protected]fdd61c62009-04-22 19:22:571478
[email protected]96d185d2009-04-24 03:28:541479DOMUI* TabContents::GetDOMUIForCurrentState() {
1480 // When there is a pending navigation entry, we want to use the pending DOMUI
1481 // that goes along with it to control the basic flags. For example, we want to
1482 // show the pending URL in the URL bar, so we want the display_url flag to
1483 // be from the pending entry.
1484 //
1485 // The confusion comes because there are multiple possibilities for the
1486 // initial load in a tab as a side effect of the way the RenderViewHostManager
1487 // works.
1488 //
1489 // - For the very first tab the load looks "normal". The new tab DOM UI is
1490 // the pending one, and we want it to apply here.
1491 //
1492 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1493 // get switched to the one previously associated with the new tab pages.
1494 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1495 // have a committed DOM UI in this case.
1496 //
1497 // This condition handles all of these cases:
1498 //
1499 // - First load in first tab: no committed nav entry + pending nav entry +
1500 // pending dom ui:
1501 // -> Use pending DOM UI if any.
1502 //
1503 // - First load in second tab: no committed nav entry + pending nav entry +
1504 // no pending DOM UI:
1505 // -> Use the committed DOM UI if any.
1506 //
1507 // - Second navigation in any tab: committed nav entry + pending nav entry:
1508 // -> Use pending DOM UI if any.
1509 //
1510 // - Normal state with no load: committed nav entry + no pending nav entry:
1511 // -> Use committed DOM UI.
1512 if (controller_.pending_entry() &&
1513 (controller_.GetLastCommittedEntry() ||
1514 render_manager_.pending_dom_ui()))
1515 return render_manager_.pending_dom_ui();
1516 return render_manager_.dom_ui();
1517}
[email protected]420ae012009-04-24 05:16:321518
1519void TabContents::DidNavigateMainFramePostCommit(
1520 const NavigationController::LoadCommittedDetails& details,
1521 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441522 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1523 // If this is a window.open navigation, use the same DOMUI as the renderer
1524 // that opened the window, as long as both renderers have the same
1525 // privileges.
1526 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1527 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1528 // dom_ui might be NULL if the URL refers to a non-existent extension.
1529 if (dom_ui) {
1530 render_manager_.SetDOMUIPostCommit(dom_ui);
1531 dom_ui->RenderViewCreated(render_view_host());
1532 }
1533 }
1534 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1535 }
1536
[email protected]420ae012009-04-24 05:16:321537 if (details.is_user_initiated_main_frame_load()) {
1538 // Clear the status bubble. This is a workaround for a bug where WebKit
1539 // doesn't let us know that the cursor left an element during a
1540 // transition (this is also why the mouse cursor remains as a hand after
1541 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1542 // clear the bubble when a user navigates to a named anchor in the same
1543 // page.
1544 UpdateTargetURL(details.entry->page_id(), GURL());
1545
1546 // UpdateHelpersForDidNavigate will handle the case where the password_form
1547 // origin is valid.
1548 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1549 // cleaned up and covered by tests.
1550 if (!params.password_form.origin.is_valid())
1551 GetPasswordManager()->DidNavigate();
1552 }
1553
1554 // The keyword generator uses the navigation entries, so must be called after
1555 // the commit.
1556 GenerateKeywordIfNecessary(params);
1557
1558 // Allow the new page to set the title again.
1559 received_page_title_ = false;
1560
1561 // Get the favicon, either from history or request it from the net.
1562 fav_icon_helper_.FetchFavIcon(details.entry->url());
1563
[email protected]0de80162010-02-03 04:52:351564 // Clear all page actions, blocked content notifications and browser actions
1565 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141566 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081567 ExtensionsService* service = profile()->GetExtensionsService();
1568 if (service) {
1569 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571570 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081571 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521572 if (browser_action) {
1573 browser_action->ClearAllValuesForTab(controller().session_id().id());
1574 NotificationService::current()->Notify(
1575 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571576 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521577 NotificationService::NoDetails());
1578 }
[email protected]92c6f9b92009-10-24 04:35:081579
[email protected]5d246db22009-10-27 06:17:571580 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521581 service->extensions()->at(i)->page_action();
1582 if (page_action) {
1583 page_action->ClearAllValuesForTab(controller().session_id().id());
1584 PageActionStateChanged();
1585 }
[email protected]92c6f9b92009-10-24 04:35:081586 }
[email protected]aece2c7f2009-08-27 20:43:171587 }
[email protected]0de80162010-02-03 04:52:351588
1589 // Close blocked popups.
1590 if (blocked_popups_) {
[email protected]0fbd70332010-06-01 19:28:341591 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]0de80162010-02-03 04:52:351592 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461593 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351594 }
1595
1596 // Clear "blocked" flags.
1597 ClearBlockedContentSettings();
[email protected]777a7b62010-05-11 13:28:161598 geolocation_settings_state_.DidNavigate(details);
[email protected]0de80162010-02-03 04:52:351599 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241600 delegate_->OnContentSettingsChange(this);
[email protected]f17a0ee2010-05-17 17:38:471601
1602 // Once the main frame is navigated, we're no longer considered to have
1603 // displayed insecure content.
1604 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171605 }
[email protected]ce5c4502009-05-06 16:46:111606
[email protected]8cc8d492010-02-02 10:40:491607 // Close constrained windows if necessary.
1608 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1609 details.previous_url, details.entry->url()))
1610 CloseConstrainedWindows();
1611
[email protected]420ae012009-04-24 05:16:321612 // Update the starred state.
1613 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531614
1615 // Clear the cache of forms in AutoFill.
1616 if (autofill_manager_.get())
1617 autofill_manager_->Reset();
[email protected]a888b29e62010-04-01 13:38:571618
1619 // The url likely changed, see if there is an extension whose extent contains
1620 // the current page.
[email protected]98aa0b52010-05-06 17:03:081621 UpdateExtensionAppForCurrentPage();
[email protected]420ae012009-04-24 05:16:321622}
1623
1624void TabContents::DidNavigateAnyFramePostCommit(
1625 RenderViewHost* render_view_host,
1626 const NavigationController::LoadCommittedDetails& details,
1627 const ViewHostMsg_FrameNavigate_Params& params) {
1628 // If we navigate, start showing messages again. This does nothing to prevent
1629 // a malicious script from spamming messages, since the script could just
1630 // reload the page to stop blocking.
1631 suppress_javascript_messages_ = false;
1632
[email protected]420ae012009-04-24 05:16:321633 // Notify the password manager of the navigation or form submit.
1634 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1635 // cleaned up and covered by tests.
1636 if (params.password_form.origin.is_valid())
1637 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551638
1639 // Let the LanguageState clear its state.
[email protected]34cec8d82010-03-05 18:27:011640 bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
1641 details.type == NavigationType::SAME_PAGE;
1642 language_state_.DidNavigate(reload, details.is_in_page);
[email protected]420ae012009-04-24 05:16:321643}
1644
[email protected]8cc8d492010-02-02 10:40:491645void TabContents::CloseConstrainedWindows() {
1646 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321647 // We use indices instead of iterators in case CloseWindow does something
1648 // that may invalidate an iterator.
1649 int size = static_cast<int>(child_windows_.size());
1650 for (int i = size - 1; i >= 0; --i) {
1651 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441652 if (window) {
[email protected]420ae012009-04-24 05:16:321653 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441654 BlockTabContent(false);
1655 }
[email protected]420ae012009-04-24 05:16:321656 }
1657}
1658
1659void TabContents::UpdateStarredStateForCurrentURL() {
1660 BookmarkModel* model = profile()->GetBookmarkModel();
1661 const bool old_state = is_starred_;
1662 is_starred_ = (model && model->IsBookmarked(GetURL()));
1663
1664 if (is_starred_ != old_state && delegate())
1665 delegate()->URLStarredChanged(this, is_starred_);
1666}
1667
1668void TabContents::UpdateAlternateErrorPageURL() {
1669 GURL url = GetAlternateErrorPageURL();
1670 render_view_host()->SetAlternateErrorPageURL(url);
1671}
1672
1673void TabContents::UpdateWebPreferences() {
1674 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1675}
1676
1677void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1678 RenderViewHost* rvh) {
1679 // If we are creating a RVH for a restored controller, then we might
1680 // have more page IDs than the SiteInstance's current max page ID. We must
1681 // make sure that the max page ID is larger than any restored page ID.
1682 // Note that it is ok for conflicting page IDs to exist in another tab
1683 // (i.e., NavigationController), but if any page ID is larger than the max,
1684 // the back/forward list will get confused.
1685 int max_restored_page_id = controller_.max_restored_page_id();
1686 if (max_restored_page_id > 0) {
1687 int curr_max_page_id = site_instance->max_page_id();
1688 if (max_restored_page_id > curr_max_page_id) {
1689 // Need to update the site instance immediately.
1690 site_instance->UpdateMaxPageID(max_restored_page_id);
1691
1692 // Also tell the renderer to update its internal representation. We
1693 // need to reserve enough IDs to make all restored page IDs less than
1694 // the max.
1695 if (curr_max_page_id < 0)
1696 curr_max_page_id = 0;
1697 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1698 }
1699 }
1700}
1701
1702void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541703 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471704 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321705 const ViewHostMsg_FrameNavigate_Params& params) {
1706 if (profile()->IsOffTheRecord())
1707 return;
1708
1709 // Add to history service.
1710 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1711 if (hs) {
1712 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541713 virtual_url != params.url) {
1714 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321715 // types of URLs, we will display a magic URL that is different from where
1716 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541717 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1718 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321719 // to sub-frames.
1720 std::vector<GURL> redirects = params.redirects;
1721 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541722 redirects.back() = virtual_url;
1723 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471724 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321725 } else {
1726 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471727 params.transition, params.redirects,
1728 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321729 }
1730 }
1731}
1732
1733bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1734 const std::wstring& title) {
1735 // For file URLs without a title, use the pathname instead. In the case of a
1736 // synthesized title, we don't want the update to count toward the "one set
1737 // per page of the title to history."
1738 std::wstring final_title;
1739 bool explicit_set;
1740 if (entry->url().SchemeIsFile() && title.empty()) {
1741 final_title = UTF8ToWide(entry->url().ExtractFileName());
1742 explicit_set = false; // Don't count synthetic titles toward the set limit.
1743 } else {
1744 TrimWhitespace(title, TRIM_ALL, &final_title);
1745 explicit_set = true;
1746 }
1747
1748 if (final_title == UTF16ToWideHack(entry->title()))
1749 return false; // Nothing changed, don't bother.
1750
1751 entry->set_title(WideToUTF16Hack(final_title));
1752
1753 // Update the history system for this page.
1754 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1755 HistoryService* hs =
1756 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1757 if (hs)
[email protected]ebe89e062009-08-13 23:16:541758 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321759
1760 // Don't allow the title to be saved again for explicitly set ones.
1761 received_page_title_ = explicit_set;
1762 }
1763
1764 // Lastly, set the title for the view.
1765 view_->SetPageTitle(final_title);
1766
[email protected]cbc0e1b2010-04-12 18:33:041767 NotificationService::current()->Notify(
1768 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1769 Source<TabContents>(this),
1770 NotificationService::NoDetails());
1771
[email protected]420ae012009-04-24 05:16:321772 return true;
1773}
1774
1775void TabContents::NotifySwapped() {
1776 // After sending out a swap notification, we need to send a disconnect
1777 // notification so that clients that pick up a pointer to |this| can NULL the
1778 // pointer. See Bug 1230284.
1779 notify_disconnection_ = true;
1780 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341781 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221782 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321783 NotificationService::NoDetails());
1784}
1785
1786void TabContents::NotifyConnected() {
1787 notify_disconnection_ = true;
1788 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341789 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221790 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321791 NotificationService::NoDetails());
1792}
1793
1794void TabContents::NotifyDisconnected() {
1795 if (!notify_disconnection_)
1796 return;
1797
1798 notify_disconnection_ = false;
1799 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341800 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221801 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321802 NotificationService::NoDetails());
1803}
1804
1805void TabContents::GenerateKeywordIfNecessary(
1806 const ViewHostMsg_FrameNavigate_Params& params) {
1807 if (!params.searchable_form_url.is_valid())
1808 return;
1809
1810 if (profile()->IsOffTheRecord())
1811 return;
1812
1813 int last_index = controller_.last_committed_entry_index();
1814 // When there was no previous page, the last index will be 0. This is
1815 // normally due to a form submit that opened in a new tab.
1816 // TODO(brettw) bug 916126: we should support keywords when form submits
1817 // happen in new tabs.
1818 if (last_index <= 0)
1819 return;
1820 const NavigationEntry* previous_entry =
1821 controller_.GetEntryAtIndex(last_index - 1);
1822 if (IsFormSubmit(previous_entry)) {
1823 // Only generate a keyword if the previous page wasn't itself a form
1824 // submit.
1825 return;
1826 }
1827
1828 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1829 previous_entry->user_typed_url() : previous_entry->url();
1830 std::wstring keyword =
1831 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1832 if (keyword.empty())
1833 return;
1834
1835 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1836 if (!url_model)
1837 return;
1838
1839 if (!url_model->loaded()) {
1840 url_model->Load();
1841 return;
1842 }
1843
1844 const TemplateURL* current_url;
1845 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1846 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1847 return;
1848
1849 if (current_url) {
1850 if (current_url->originating_url().is_valid()) {
1851 // The existing keyword was generated from an OpenSearch description
1852 // document, don't regenerate.
1853 return;
1854 }
1855 url_model->Remove(current_url);
1856 }
1857 TemplateURL* new_url = new TemplateURL();
1858 new_url->set_keyword(keyword);
1859 new_url->set_short_name(keyword);
1860 new_url->SetURL(url, 0, 0);
1861 new_url->add_input_encoding(params.searchable_form_encoding);
1862 DCHECK(controller_.GetLastCommittedEntry());
1863 const GURL& favicon_url =
1864 controller_.GetLastCommittedEntry()->favicon().url();
1865 if (favicon_url.is_valid()) {
1866 new_url->SetFavIconURL(favicon_url);
1867 } else {
1868 // The favicon url isn't valid. This means there really isn't a favicon,
1869 // or the favicon url wasn't obtained before the load started. This assumes
1870 // the later.
1871 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1872 // its url.
1873 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1874 }
1875 new_url->set_safe_for_autoreplace(true);
1876 url_model->Add(new_url);
1877}
1878
[email protected]bf5c2ff392009-07-08 16:24:331879void TabContents::OnUserGesture() {
1880 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1881 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1882 if (drm)
1883 drm->OnUserGesture(this);
[email protected]e7eaedde2009-09-25 20:09:491884 ExternalProtocolHandler::OnUserGesture();
[email protected]bf5c2ff392009-07-08 16:24:331885 controller_.OnUserGesture();
1886}
1887
1888void TabContents::OnFindReply(int request_id,
1889 int number_of_matches,
1890 const gfx::Rect& selection_rect,
1891 int active_match_ordinal,
1892 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421893 // Ignore responses for requests that have been aborted.
1894 if (find_op_aborted_)
1895 return;
1896
[email protected]bf5c2ff392009-07-08 16:24:331897 // Ignore responses for requests other than the one we have most recently
1898 // issued. That way we won't act on stale results when the user has
1899 // already typed in another query.
1900 if (request_id != current_find_request_id_)
1901 return;
1902
1903 if (number_of_matches == -1)
1904 number_of_matches = last_search_result_.number_of_matches();
1905 if (active_match_ordinal == -1)
1906 active_match_ordinal = last_search_result_.active_match_ordinal();
1907
1908 gfx::Rect selection = selection_rect;
1909 if (selection.IsEmpty())
1910 selection = last_search_result_.selection_rect();
1911
1912 // Notify the UI, automation and any other observers that a find result was
1913 // found.
1914 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1915 selection, active_match_ordinal,
1916 final_update);
1917 NotificationService::current()->Notify(
1918 NotificationType::FIND_RESULT_AVAILABLE,
1919 Source<TabContents>(this),
1920 Details<FindNotificationDetails>(&last_search_result_));
1921}
1922
1923void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381924 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1925 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331926}
1927
[email protected]bf5c2ff392009-07-08 16:24:331928void TabContents::OnMissingPluginStatus(int status) {
1929#if defined(OS_WIN)
1930// TODO(PORT): pull in when plug-ins work
1931 GetPluginInstaller()->OnMissingPluginStatus(status);
1932#endif
1933}
1934
1935void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331936 DCHECK(!plugin_path.value().empty());
1937
1938 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351939#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331940 scoped_ptr<FileVersionInfo> version_info(
1941 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1942 if (version_info.get()) {
1943 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371944 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331945 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371946#if defined(OS_MACOSX)
1947 // Many plugins on the Mac have .plugin in the actual name, which looks
1948 // terrible, so look for that and strip it off if present.
1949 const std::wstring plugin_extension(L".plugin");
1950 if (EndsWith(plugin_name, plugin_extension, true))
1951 plugin_name.erase(plugin_name.length() - plugin_extension.length());
1952#endif // OS_MACOSX
1953 }
[email protected]bf5c2ff392009-07-08 16:24:331954 }
[email protected]4a560ed2009-07-13 23:35:261955#else
1956 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1957#endif
[email protected]bf5c2ff392009-07-08 16:24:331958 AddInfoBar(new SimpleAlertInfoBarDelegate(
1959 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
[email protected]938e1f92010-04-01 18:09:421960 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331961}
1962
1963void TabContents::OnCrashedWorker() {
1964 AddInfoBar(new SimpleAlertInfoBarDelegate(
1965 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:421966 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331967}
1968
1969void TabContents::OnDidGetApplicationInfo(
1970 int32 page_id,
1971 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511972 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331973
[email protected]ed5431872009-11-17 08:39:511974 if (delegate())
1975 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331976}
1977
[email protected]a2cf65eb2010-01-18 08:20:381978void TabContents::OnPageContents(const GURL& url,
1979 int renderer_process_id,
1980 int32 page_id,
[email protected]a8a81292010-01-21 00:32:451981 const std::wstring& contents,
1982 const std::string& language) {
[email protected]a2cf65eb2010-01-18 08:20:381983 // Don't index any https pages. People generally don't want their bank
1984 // accounts, etc. indexed on their computer, especially since some of these
1985 // things are not marked cachable.
1986 // TODO(brettw) we may want to consider more elaborate heuristics such as
1987 // the cachability of the page. We may also want to consider subframes (this
1988 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271989 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1990 // content indexing for chromeos in some future releases.
1991#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381992 if (!url.SchemeIsSecure()) {
1993 Profile* p = profile();
1994 if (p && !p->IsOffTheRecord()) {
1995 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1996 if (hs)
1997 hs->SetPageContents(url, contents);
1998 }
1999 }
[email protected]ccd40a52010-05-11 16:15:272000#endif
[email protected]a8a81292010-01-21 00:32:452001
[email protected]3b1c1812010-02-12 21:53:552002 language_state_.LanguageDetermined(language);
[email protected]a8a81292010-01-21 00:32:452003
2004 std::string lang = language;
2005 NotificationService::current()->Notify(
2006 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152007 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452008 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382009}
2010
[email protected]7e0831b2010-02-01 08:45:152011void TabContents::OnPageTranslated(int32 page_id,
2012 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162013 const std::string& translated_lang,
2014 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552015 language_state_.set_current_language(translated_lang);
2016 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162017 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152018 NotificationService::current()->Notify(
2019 NotificationType::PAGE_TRANSLATED,
2020 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162021 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152022}
2023
[email protected]bf5c2ff392009-07-08 16:24:332024void TabContents::DidStartProvisionalLoadForFrame(
2025 RenderViewHost* render_view_host,
2026 bool is_main_frame,
2027 const GURL& url) {
2028 ProvisionalLoadDetails details(is_main_frame,
2029 controller_.IsURLInPageNavigation(url),
2030 url, std::string(), false);
2031 NotificationService::current()->Notify(
2032 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2033 Source<NavigationController>(&controller_),
2034 Details<ProvisionalLoadDetails>(&details));
2035}
2036
2037void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202038 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332039 NotificationService::current()->Notify(
2040 NotificationType::RESOURCE_RESPONSE_STARTED,
2041 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202042 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332043}
2044
[email protected]3dbb80b2010-02-09 22:41:202045void TabContents::DidRedirectResource(
2046 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332047 NotificationService::current()->Notify(
2048 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2049 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202050 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332051}
2052
2053void TabContents::DidLoadResourceFromMemoryCache(
2054 const GURL& url,
2055 const std::string& frame_origin,
2056 const std::string& main_frame_origin,
2057 const std::string& security_info) {
2058 // Send out a notification that we loaded a resource from our memory cache.
2059 int cert_id = 0, cert_status = 0, security_bits = 0;
2060 SSLManager::DeserializeSecurityInfo(security_info,
2061 &cert_id, &cert_status,
2062 &security_bits);
2063 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162064 GetRenderProcessHost()->id(), cert_id,
2065 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332066
2067 NotificationService::current()->Notify(
2068 NotificationType::LOAD_FROM_MEMORY_CACHE,
2069 Source<NavigationController>(&controller_),
2070 Details<LoadFromMemoryCacheDetails>(&details));
2071}
2072
[email protected]e3d60e5d2009-09-25 21:08:292073void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472074 displayed_insecure_content_ = true;
2075 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292076}
2077
2078void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592079 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292080}
2081
[email protected]bf5c2ff392009-07-08 16:24:332082void TabContents::DidFailProvisionalLoadWithError(
2083 RenderViewHost* render_view_host,
2084 bool is_main_frame,
2085 int error_code,
2086 const GURL& url,
2087 bool showing_repost_interstitial) {
2088 if (net::ERR_ABORTED == error_code) {
2089 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2090 // This means that the interstitial won't be torn down properly, which is
2091 // bad. But if we have an interstitial, go back to another tab type, and
2092 // then load the same interstitial again, we could end up getting the first
2093 // interstitial's "failed" message (as a result of the cancel) when we're on
2094 // the second one.
2095 //
2096 // We can't tell this apart, so we think we're tearing down the current page
2097 // which will cause a crash later one. There is also some code in
2098 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2099 // out because of this problem.
2100 //
2101 // http://code.google.com/p/chromium/issues/detail?id=2855
2102 // Because this will not tear down the interstitial properly, if "back" is
2103 // back to another tab type, the interstitial will still be somewhat alive
2104 // in the previous tab type. If you navigate somewhere that activates the
2105 // tab with the interstitial again, you'll see a flash before the new load
2106 // commits of the interstitial page.
2107 if (showing_interstitial_page()) {
2108 LOG(WARNING) << "Discarding message during interstitial.";
2109 return;
2110 }
2111
2112 // This will discard our pending entry if we cancelled the load (e.g., if we
2113 // decided to download the file instead of load it). Only discard the
2114 // pending entry if the URLs match, otherwise the user initiated a navigate
2115 // before the page loaded so that the discard would discard the wrong entry.
2116 NavigationEntry* pending_entry = controller_.pending_entry();
2117 if (pending_entry && pending_entry->url() == url) {
2118 controller_.DiscardNonCommittedEntries();
2119 // Update the URL display.
2120 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2121 }
2122
2123 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2124 }
2125
2126 // Send out a notification that we failed a provisional load with an error.
2127 ProvisionalLoadDetails details(is_main_frame,
2128 controller_.IsURLInPageNavigation(url),
2129 url, std::string(), false);
2130 details.set_error_code(error_code);
2131
2132 NotificationService::current()->Notify(
2133 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2134 Source<NavigationController>(&controller_),
2135 Details<ProvisionalLoadDetails>(&details));
2136}
2137
2138void TabContents::DocumentLoadedInFrame() {
2139 controller_.DocumentLoadedInFrame();
[email protected]b3df5a42010-05-11 14:31:092140 if (renderer_accessible_ && !requested_accessibility_tree_) {
2141 render_view_host()->RequestAccessibilityTree();
2142 requested_accessibility_tree_ = true;
2143 }
[email protected]bf5c2ff392009-07-08 16:24:332144}
2145
[email protected]0de80162010-02-03 04:52:352146void TabContents::OnContentBlocked(ContentSettingsType type) {
[email protected]b1235062010-03-25 17:31:272147 // TODO(joth): remove once fully implemented.
2148 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION);
[email protected]0de80162010-02-03 04:52:352149 content_blocked_[type] = true;
2150 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242151 delegate_->OnContentSettingsChange(this);
[email protected]0de80162010-02-03 04:52:352152}
2153
[email protected]614c0e12010-03-25 10:12:562154void TabContents::OnGeolocationPermissionSet(const GURL& requesting_origin,
2155 bool allowed) {
[email protected]777a7b62010-05-11 13:28:162156 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin,
2157 allowed);
[email protected]614c0e12010-03-25 10:12:562158 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242159 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562160}
2161
[email protected]8d3347f2009-07-09 22:00:212162RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322163 return view_.get();
2164}
2165
[email protected]8d3347f2009-07-09 22:00:212166RenderViewHostDelegate::RendererManagement*
2167TabContents::GetRendererManagementDelegate() {
2168 return &render_manager_;
2169}
2170
[email protected]bf5c2ff392009-07-08 16:24:332171RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212172 TabContents::GetBrowserIntegrationDelegate() {
2173 return this;
[email protected]bf5c2ff392009-07-08 16:24:332174}
2175
[email protected]8d3347f2009-07-09 22:00:212176RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2177 return this;
[email protected]bf5c2ff392009-07-08 16:24:332178}
2179
[email protected]8d3347f2009-07-09 22:00:212180RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322181 return save_package_.get(); // May be NULL, but we can return NULL.
2182}
2183
[email protected]8d3347f2009-07-09 22:00:212184RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
2185 return &printing_;
2186}
2187
2188RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2189 return &fav_icon_helper_;
2190}
2191
[email protected]e8dbd674b2010-03-11 18:34:402192RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452193 if (autocomplete_history_manager_.get() == NULL)
2194 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2195 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332196}
2197
[email protected]21674df2009-10-28 19:51:212198RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342199 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212200}
2201
[email protected]fd571bb2010-03-19 01:23:542202AutomationResourceRoutingDelegate*
2203TabContents::GetAutomationResourceRoutingDelegate() {
2204 return delegate();
2205}
2206
[email protected]ced90ae12010-02-20 02:06:162207RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2208 return bookmark_drag_;
2209}
2210
2211void TabContents::SetBookmarkDragDelegate(
2212 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2213 bookmark_drag_ = bookmark_drag;
2214}
2215
[email protected]93623c5d2009-12-10 21:40:322216RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462217 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512218}
2219
[email protected]57c6a652009-05-04 07:58:342220TabContents* TabContents::GetAsTabContents() {
2221 return this;
2222}
2223
[email protected]7b291f92009-08-14 05:43:532224ViewType::Type TabContents::GetRenderViewType() const {
2225 return ViewType::TAB_CONTENTS;
2226}
2227
2228int TabContents::GetBrowserWindowID() const {
2229 return controller().window_id().id();
2230}
2231
[email protected]420ae012009-04-24 05:16:322232void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062233 NotificationService::current()->Notify(
2234 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2235 Source<TabContents>(this),
2236 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322237 NavigationEntry* entry = controller_.GetActiveEntry();
2238 if (!entry)
2239 return;
2240
2241 // When we're creating views, we're still doing initial setup, so we always
2242 // use the pending DOM UI rather than any possibly existing committed one.
2243 if (render_manager_.pending_dom_ui()) {
2244 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2245 }
2246
2247 if (entry->IsViewSourceMode()) {
2248 // Put the renderer in view source mode.
2249 render_view_host->Send(
2250 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2251 }
[email protected]0666aef2009-05-13 19:48:082252
2253 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322254}
2255
2256void TabContents::RenderViewReady(RenderViewHost* rvh) {
2257 if (rvh != render_view_host()) {
2258 // Don't notify the world, since this came from a renderer in the
2259 // background.
2260 return;
2261 }
2262
2263 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302264 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322265 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302266
2267 // Restore the focus to the tab (otherwise the focus will be on the top
2268 // window).
2269 if (was_crashed && !FocusLocationBarByDefault())
2270 Focus();
[email protected]420ae012009-04-24 05:16:322271}
2272
2273void TabContents::RenderViewGone(RenderViewHost* rvh) {
2274 // Ask the print preview if this renderer was valuable.
2275 if (!printing_.OnRenderViewGone(rvh))
2276 return;
2277 if (rvh != render_view_host()) {
2278 // The pending page's RenderViewHost is gone.
2279 return;
2280 }
2281
2282 SetIsLoading(false, NULL);
2283 NotifyDisconnected();
2284 SetIsCrashed(true);
2285
[email protected]ff9efc62010-02-18 22:10:542286 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212287 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542288 RemoveInfoBar(GetInfoBarDelegateAt(i));
2289
[email protected]8e537302009-06-10 21:19:582290 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552291 // Only do this if we're not in browser shutdown, so that TabContents
2292 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2293 // visible do not flash a sad tab page.
2294 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2295 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322296
2297 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002298 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322299}
2300
[email protected]2e4633c2009-07-09 16:58:062301void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2302 NotificationService::current()->Notify(
2303 NotificationType::RENDER_VIEW_HOST_DELETED,
2304 Source<TabContents>(this),
2305 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482306 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062307}
2308
[email protected]420ae012009-04-24 05:16:322309void TabContents::DidNavigate(RenderViewHost* rvh,
2310 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372311 int extra_invalidate_flags = 0;
2312
[email protected]b3df5a42010-05-11 14:31:092313 requested_accessibility_tree_ = false;
2314
[email protected]8030f012009-09-25 18:09:372315 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352316 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372317 bool was_extension_shelf_visible = IsExtensionShelfAlwaysVisible();
2318
[email protected]420ae012009-04-24 05:16:322319 render_manager_.DidNavigateMainFrame(rvh);
2320
[email protected]20ede072009-10-06 00:28:352321 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372322 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
2323 if (was_extension_shelf_visible != IsExtensionShelfAlwaysVisible())
2324 extra_invalidate_flags |= INVALIDATE_EXTENSION_SHELF;
2325 }
2326
[email protected]420ae012009-04-24 05:16:322327 // Update the site of the SiteInstance if it doesn't have one yet.
2328 if (!GetSiteInstance()->has_site())
2329 GetSiteInstance()->SetSite(params.url);
2330
2331 // Need to update MIME type here because it's referred to in
2332 // UpdateNavigationCommands() called by RendererDidNavigate() to
2333 // determine whether or not to enable the encoding menu.
2334 // It's updated only for the main frame. For a subframe,
2335 // RenderView::UpdateURL does not set params.contents_mime_type.
2336 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2337 // TODO(jungshik): Add a test for the encoding menu to avoid
2338 // regressing it again.
2339 if (PageTransition::IsMainFrame(params.transition))
2340 contents_mime_type_ = params.contents_mime_type;
2341
2342 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372343 bool did_navigate = controller_.RendererDidNavigate(
2344 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392345
2346 // Update history. Note that this needs to happen after the entry is complete,
2347 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352348 if (params.should_update_history &&
2349 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392350 // Most of the time, the displayURL matches the loaded URL, but for about:
2351 // URLs, we use a data: URL as the real value. We actually want to save
2352 // the about: URL to the history db and keep the data: URL hidden. This is
2353 // what the TabContents' URL getter does.
2354 UpdateHistoryForNavigation(GetURL(), details, params);
2355 }
2356
[email protected]76543b92009-08-31 17:27:452357 if (!did_navigate)
2358 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322359
2360 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2361 // for the appropriate notification (best) or you can add it to
2362 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2363 // necessary, please).
2364
2365 // Run post-commit tasks.
2366 if (details.is_main_frame)
2367 DidNavigateMainFramePostCommit(details, params);
2368 DidNavigateAnyFramePostCommit(rvh, details, params);
2369}
2370
2371void TabContents::UpdateState(RenderViewHost* rvh,
2372 int32 page_id,
2373 const std::string& state) {
2374 DCHECK(rvh == render_view_host());
2375
2376 // We must be prepared to handle state updates for any page, these occur
2377 // when the user is scrolling and entering form data, as well as when we're
2378 // leaving a page, in which case our state may have already been moved to
2379 // the next page. The navigation controller will look up the appropriate
2380 // NavigationEntry and update it when it is notified via the delegate.
2381
2382 int entry_index = controller_.GetEntryIndexWithPageID(
2383 GetSiteInstance(), page_id);
2384 if (entry_index < 0)
2385 return;
2386 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2387
2388 if (state == entry->content_state())
2389 return; // Nothing to update.
2390 entry->set_content_state(state);
2391 controller_.NotifyEntryChanged(entry, entry_index);
2392}
2393
2394void TabContents::UpdateTitle(RenderViewHost* rvh,
2395 int32 page_id, const std::wstring& title) {
2396 // If we have a title, that's a pretty good indication that we've started
2397 // getting useful data.
2398 SetNotWaitingForResponse();
2399
2400 DCHECK(rvh == render_view_host());
2401 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2402 page_id);
2403 if (!entry || !UpdateTitleForEntry(entry, title))
2404 return;
2405
2406 // Broadcast notifications when the UI should be updated.
2407 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032408 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322409}
2410
[email protected]420ae012009-04-24 05:16:322411void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402412 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322413 set_encoding(encoding);
2414}
2415
2416void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2417 if (delegate())
2418 delegate()->UpdateTargetURL(this, url);
2419}
2420
2421void TabContents::UpdateThumbnail(const GURL& url,
2422 const SkBitmap& bitmap,
2423 const ThumbnailScore& score) {
2424 // Tell History about this thumbnail
[email protected]523623c2010-05-19 16:03:422425 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492426 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422427 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282428 } else {
2429 HistoryService* hs;
2430 if (!profile()->IsOffTheRecord() &&
2431 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2432 hs->SetPageThumbnail(url, bitmap, score);
2433 }
[email protected]420ae012009-04-24 05:16:322434 }
2435}
2436
[email protected]c4e98902010-06-01 10:20:142437void TabContents::UpdateInspectorSetting(const std::string& key,
2438 const std::string& value) {
2439 DictionaryValue* inspector_settings =
2440 profile()->GetPrefs()->GetMutableDictionary(
2441 prefs::kWebKitInspectorSettings);
2442 inspector_settings->SetString(UTF8ToWide(key), value);
[email protected]0df30122009-06-03 12:13:082443}
2444
[email protected]420ae012009-04-24 05:16:322445void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292446 // The UI may be in an event-tracking loop, such as between the
2447 // mouse-down and mouse-up in text selection or a button click.
2448 // Defer the close until after tracking is complete, so that we
2449 // don't free objects out from under the UI.
2450 // TODO(shess): This could probably be integrated with the
2451 // IsDoingDrag() test below. Punting for now because I need more
2452 // research to understand how this impacts platforms other than Mac.
2453 // TODO(shess): This could get more fine-grained. For instance,
2454 // closing a tab in another window while selecting text in the
2455 // current window's Omnibox should be just fine.
2456 if (view()->IsEventTracking()) {
2457 view()->CloseTabAfterEventTracking();
2458 return;
2459 }
2460
[email protected]24a4d1062009-07-10 23:10:422461 // If we close the tab while we're in the middle of a drag, we'll crash.
2462 // Instead, cancel the drag and close it as soon as the drag ends.
2463 if (view()->IsDoingDrag()) {
2464 view()->CancelDragAndCloseTab();
2465 return;
2466 }
2467
[email protected]420ae012009-04-24 05:16:322468 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2469 if (delegate() && rvh == render_view_host())
2470 delegate()->CloseContents(this);
2471}
2472
2473void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2474 if (delegate() && delegate()->IsPopup(this))
2475 delegate()->MoveContents(this, new_bounds);
2476}
2477
[email protected]7ab1e7d62009-10-14 23:32:012478void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322479 SetIsLoading(true, NULL);
2480}
2481
[email protected]7ab1e7d62009-10-14 23:32:012482void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322483 scoped_ptr<LoadNotificationDetails> details;
2484
2485 NavigationEntry* entry = controller_.GetActiveEntry();
2486 // An entry may not exist for a stop when loading an initial blank page or
2487 // if an iframe injected by script into a blank page finishes loading.
2488 if (entry) {
[email protected]420ae012009-04-24 05:16:322489 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2490
2491 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542492 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322493 entry->transition_type(),
2494 elapsed,
2495 &controller_,
2496 controller_.GetCurrentEntryIndex()));
2497 }
2498
2499 // Tell PasswordManager we've finished a page load, which serves as a
2500 // green light to save pending passwords and reset itself.
2501 GetPasswordManager()->DidStopLoading();
2502
2503 SetIsLoading(false, details.get());
2504}
2505
[email protected]420ae012009-04-24 05:16:322506void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2507 const GURL& source_url,
2508 const GURL& target_url) {
2509 NavigationEntry* entry;
2510 if (page_id == -1)
2511 entry = controller_.pending_entry();
2512 else
2513 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2514 if (!entry || entry->url() != source_url)
2515 return;
2516 entry->set_url(target_url);
2517}
2518
[email protected]420ae012009-04-24 05:16:322519void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2520 WindowOpenDisposition disposition) {
2521 if (render_manager_.dom_ui()) {
2522 // When we're a DOM UI, it will provide a page transition type for us (this
2523 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2524 // generated suggestions).
2525 //
2526 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162527 // want web sites to see a referrer of "chrome://blah" (and some
2528 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322529 // send to the site), so we send no referrer.
2530 OpenURL(url, GURL(), disposition,
2531 render_manager_.dom_ui()->link_transition_type());
2532 } else {
2533 OpenURL(url, referrer, disposition, PageTransition::LINK);
2534 }
2535}
2536
[email protected]1ee614862009-07-06 20:29:182537void TabContents::DomOperationResponse(const std::string& json_string,
2538 int automation_id) {
2539}
2540
[email protected]420ae012009-04-24 05:16:322541void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]438c97d2010-05-21 23:30:152542 const ListValue* content,
[email protected]bb64b512010-04-02 21:01:392543 const GURL& source_url,
[email protected]811bfe32009-07-01 08:46:252544 int request_id,
2545 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322546 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442547 // This can happen if someone uses window.open() to open an extension URL
2548 // from a non-extension context.
2549 render_view_host()->BlockExtensionRequest(request_id);
[email protected]420ae012009-04-24 05:16:322550 return;
2551 }
[email protected]bb64b512010-04-02 21:01:392552 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, source_url,
2553 request_id,
[email protected]811bfe32009-07-01 08:46:252554 has_callback);
[email protected]420ae012009-04-24 05:16:322555}
2556
2557void TabContents::ProcessExternalHostMessage(const std::string& message,
2558 const std::string& origin,
2559 const std::string& target) {
2560 if (delegate())
2561 delegate()->ForwardMessageToExternalHost(message, origin, target);
2562}
2563
[email protected]cdaf8d02010-03-30 19:52:472564void TabContents::RunFileChooser(
2565 const ViewHostMsg_RunFileChooser_Params &params) {
[email protected]420ae012009-04-24 05:16:322566 if (!select_file_dialog_.get())
2567 select_file_dialog_ = SelectFileDialog::Create(this);
[email protected]cdaf8d02010-03-30 19:52:472568
2569 SelectFileDialog::Type dialog_type;
2570 switch (params.mode) {
2571 case ViewHostMsg_RunFileChooser_Params::Open:
2572 dialog_type = SelectFileDialog::SELECT_OPEN_FILE;
2573 break;
2574 case ViewHostMsg_RunFileChooser_Params::OpenMultiple:
2575 dialog_type = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
2576 break;
2577 case ViewHostMsg_RunFileChooser_Params::Save:
2578 dialog_type = SelectFileDialog::SELECT_SAVEAS_FILE;
2579 break;
2580 default:
[email protected]bed31952010-03-30 20:07:592581 dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning.
[email protected]cdaf8d02010-03-30 19:52:472582 NOTREACHED();
2583 }
2584 select_file_dialog_->SelectFile(dialog_type, params.title,
2585 params.default_file_name,
[email protected]420ae012009-04-24 05:16:322586 NULL, 0, FILE_PATH_LITERAL(""),
2587 view_->GetTopLevelNativeWindow(), NULL);
2588}
2589
2590void TabContents::RunJavaScriptMessage(
2591 const std::wstring& message,
2592 const std::wstring& default_prompt,
2593 const GURL& frame_url,
2594 const int flags,
2595 IPC::Message* reply_msg,
2596 bool* did_suppress_message) {
2597 // Suppress javascript messages when requested and when inside a constrained
2598 // popup window (because that activates them and breaks them out of the
2599 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552600 // Also suppress messages when showing an interstitial. The interstitial is
2601 // shown over the previous page, we don't want the hidden page dialogs to
2602 // interfere with the interstitial.
2603 bool suppress_this_message = suppress_javascript_messages_ ||
2604 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322605 if (delegate())
2606 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312607 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322608
2609 *did_suppress_message = suppress_this_message;
2610
2611 if (!suppress_this_message) {
2612 base::TimeDelta time_since_last_message(
2613 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2614 bool show_suppress_checkbox = false;
2615 // Show a checkbox offering to suppress further messages if this message is
2616 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2617 if (time_since_last_message <
2618 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2619 show_suppress_checkbox = true;
2620
[email protected]d82ed61e2009-06-16 02:46:222621 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322622 show_suppress_checkbox, reply_msg);
2623 } else {
2624 // If we are suppressing messages, just reply as is if the user immediately
2625 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542626 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322627 }
2628}
2629
2630void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2631 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012632 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222633 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322634}
2635
2636void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2637 const std::string& json_arguments,
2638 IPC::Message* reply_msg) {
2639 if (delegate()) {
2640 HtmlDialogUIDelegate* dialog_delegate =
2641 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222642 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322643 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2644 }
2645}
2646
[email protected]4d44a1c2010-04-28 19:20:412647void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562648 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412649 GetPasswordManager()->PasswordFormsFound(forms);
2650}
2651
2652void TabContents::PasswordFormsVisible(
2653 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2654 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322655}
2656
[email protected]420ae012009-04-24 05:16:322657// Checks to see if we should generate a keyword based on the OSDD, and if
2658// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2659void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2660 int32 page_id, const GURL& url,
2661 bool autodetected) {
2662 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2663 DCHECK(url.is_valid());
2664 if (!IsActiveEntry(page_id))
2665 return;
2666 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2667 if (!url_model)
2668 return;
2669 if (!url_model->loaded()) {
2670 url_model->Load();
2671 return;
2672 }
2673 if (!profile()->GetTemplateURLFetcher())
2674 return;
2675
2676 if (profile()->IsOffTheRecord())
2677 return;
2678
2679 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2680 DCHECK(entry);
2681
2682 const NavigationEntry* base_entry = entry;
2683 if (IsFormSubmit(base_entry)) {
2684 // If the current page is a form submit, find the last page that was not
2685 // a form submit and use its url to generate the keyword from.
2686 int index = controller_.last_committed_entry_index() - 1;
2687 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2688 index--;
2689 if (index >= 0)
2690 base_entry = controller_.GetEntryAtIndex(index);
2691 else
2692 base_entry = NULL;
2693 }
2694
2695 // We want to use the user typed URL if available since that represents what
2696 // the user typed to get here, and fall back on the regular URL if not.
2697 if (!base_entry)
2698 return;
2699 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2700 base_entry->user_typed_url() : base_entry->url();
2701 if (!keyword_url.is_valid())
2702 return;
2703 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2704 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532705
2706 // For JS added OSDD empty keyword is OK because we will generate keyword
2707 // later from OSDD content.
2708 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322709 return;
2710 const TemplateURL* template_url =
2711 url_model->GetTemplateURLForKeyword(keyword);
2712 if (template_url && (!template_url->safe_for_autoreplace() ||
2713 template_url->originating_url() == url)) {
2714 // Either there is a user created TemplateURL for this keyword, or the
2715 // keyword has the same OSDD url and we've parsed it.
2716 return;
2717 }
2718
2719 // Download the OpenSearch description document. If this is successful a
2720 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322721 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2722 keyword,
2723 url,
2724 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162725 this,
[email protected]420ae012009-04-24 05:16:322726 autodetected);
2727}
2728
[email protected]420ae012009-04-24 05:16:322729GURL TabContents::GetAlternateErrorPageURL() const {
2730 GURL url;
2731 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2732 if (profile()->IsOffTheRecord())
2733 return url;
2734
2735 PrefService* prefs = profile()->GetPrefs();
2736 DCHECK(prefs);
2737 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152738 url = google_util::AppendGoogleLocaleParam(
2739 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322740 url = google_util::AppendGoogleTLDParam(url);
2741 }
2742 return url;
2743}
2744
2745WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062746 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552747 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062748 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322749}
2750
[email protected]fa1cf0b82010-01-15 21:49:442751void TabContents::OnIgnoredUIEvent() {
2752 if (constrained_window_count()) {
2753 ConstrainedWindow* window = *constrained_window_begin();
2754 window->FocusConstrainedWindow();
2755 }
2756}
2757
[email protected]420ae012009-04-24 05:16:322758void TabContents::OnJSOutOfMemory() {
2759 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]938e1f92010-04-01 18:09:422760 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL, true));
[email protected]420ae012009-04-24 05:16:322761}
2762
[email protected]420ae012009-04-24 05:16:322763void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2764 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342765 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322766 // delivered to a pending RenderViewHost. We must first run the onunload
2767 // handler of the old RenderViewHost before we can allow it to proceed.
2768 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2769 new_request_id);
2770}
2771
2772bool TabContents::CanBlur() const {
2773 return delegate() ? delegate()->CanBlur() : true;
2774}
2775
2776gfx::Rect TabContents::GetRootWindowResizerRect() const {
2777 if (delegate())
2778 return delegate()->GetRootWindowResizerRect();
2779 return gfx::Rect();
2780}
2781
2782void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2783 bool is_during_unload) {
2784 if (is_during_unload) {
2785 // Hang occurred while firing the beforeunload/unload handler.
2786 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112787 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322788
2789 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2790 return;
2791
2792 // If the tab hangs in the beforeunload/unload handler there's really
2793 // nothing we can do to recover. Pretend the unload listeners have
2794 // all fired and close the tab. If the hang is in the beforeunload handler
2795 // then the user will not have the option of cancelling the close.
2796 Close(rvh);
2797 return;
2798 }
2799
2800 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002801 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322802}
2803
2804void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002805 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322806}
2807
2808void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562809 net::LoadState load_state,
2810 uint64 upload_position,
2811 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322812 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562813 upload_position_ = upload_position;
2814 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292815 std::wstring languages =
2816 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]d686e812009-06-03 19:10:292817 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532818 load_state_host_ =
2819 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322820 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2821 SetNotWaitingForResponse();
2822 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502823 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322824}
2825
[email protected]1ee614862009-07-06 20:29:182826bool TabContents::IsExternalTabContainer() const {
2827 if (!delegate())
2828 return false;
2829
2830 return delegate()->IsExternalTabContainer();
2831}
2832
[email protected]1ee614862009-07-06 20:29:182833void TabContents::DidInsertCSS() {
2834 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322835}
2836
[email protected]130efb02009-09-18 18:54:352837void TabContents::FocusedNodeChanged() {
2838 NotificationService::current()->Notify(
2839 NotificationType::FOCUS_CHANGED_IN_PAGE,
2840 Source<RenderViewHost>(render_view_host()),
2841 NotificationService::NoDetails());
2842}
2843
[email protected]420ae012009-04-24 05:16:322844void TabContents::FileSelected(const FilePath& path,
2845 int index, void* params) {
[email protected]cdaf8d02010-03-30 19:52:472846 std::vector<FilePath> files;
2847 files.push_back(path);
2848 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322849}
2850
2851void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2852 void* params) {
[email protected]cdaf8d02010-03-30 19:52:472853 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322854}
2855
2856void TabContents::FileSelectionCanceled(void* params) {
2857 // If the user cancels choosing a file to upload we pass back an
2858 // empty vector.
[email protected]cdaf8d02010-03-30 19:52:472859 render_view_host()->FilesSelectedInChooser(std::vector<FilePath>());
[email protected]420ae012009-04-24 05:16:322860}
2861
2862void TabContents::BeforeUnloadFiredFromRenderManager(
2863 bool proceed,
2864 bool* proceed_to_fire_unload) {
2865 if (delegate())
2866 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2867}
2868
2869void TabContents::UpdateRenderViewSizeForRenderManager() {
2870 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262871 gfx::Size size = view_->GetContainerSize();
2872 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2873 // here during container initialization and normal window size will be set
2874 // later. In case of tab duplication this resizing to 0x0 prevents setting
2875 // normal size later so just ignore it.
2876 if (!size.IsEmpty())
2877 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322878}
2879
2880DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222881 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322882}
2883
2884NavigationEntry*
2885TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2886 return controller_.GetLastCommittedEntry();
2887}
2888
2889bool TabContents::CreateRenderViewForRenderManager(
2890 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322891 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522892
2893 scoped_refptr<URLRequestContextGetter> request_context = request_context_;
2894 if (!request_context.get())
2895 request_context = profile()->GetRequestContext();
2896
2897 if (!render_view_host->CreateRenderView(request_context))
[email protected]420ae012009-04-24 05:16:322898 return false;
2899
2900 // Now that the RenderView has been created, we need to tell it its size.
2901 rwh_view->SetSize(view_->GetContainerSize());
2902
2903 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2904 render_view_host);
2905 return true;
2906}
2907
2908void TabContents::Observe(NotificationType type,
2909 const NotificationSource& source,
2910 const NotificationDetails& details) {
2911 switch (type.value) {
2912 case NotificationType::BOOKMARK_MODEL_LOADED:
2913 // BookmarkModel finished loading, fall through to update starred state.
2914 case NotificationType::URLS_STARRED: {
2915 // Somewhere, a URL has been starred.
2916 // Ignore notifications for profiles other than our current one.
2917 Profile* source_profile = Source<Profile>(source).ptr();
2918 if (!source_profile || !source_profile->IsSameProfile(profile()))
2919 return;
2920
2921 UpdateStarredStateForCurrentURL();
2922 break;
2923 }
2924 case NotificationType::PREF_CHANGED: {
2925 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2926 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2927 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2928 UpdateAlternateErrorPageURL();
2929 } else if (*pref_name_in == prefs::kDefaultCharset ||
2930 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2931 ) {
2932 UpdateWebPreferences();
2933 } else {
2934 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2935 }
2936 break;
2937 }
2938 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2939 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2940 break;
2941
2942 case NotificationType::NAV_ENTRY_COMMITTED: {
2943 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2944
2945 NavigationController::LoadCommittedDetails& committed_details =
2946 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2947 ExpireInfoBars(committed_details);
2948 break;
2949 }
2950
[email protected]d3ba77272009-09-03 00:06:092951#if defined(OS_LINUX)
2952 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542953 renderer_preferences_util::UpdateFromSystemSettings(
2954 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092955 render_view_host()->SyncRendererPrefs();
2956 break;
2957 }
2958#endif
2959
[email protected]6c32ce72010-03-08 05:18:062960 case NotificationType::USER_STYLE_SHEET_UPDATED:
2961 UpdateWebPreferences();
2962 break;
2963
[email protected]79580c62010-02-02 02:36:252964 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:292965 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:252966 settings_details(details);
[email protected]79580c62010-02-02 02:36:252967 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492968 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292969 if (entry)
[email protected]da0c8e92010-02-09 23:25:492970 entry_url = entry->url();
[email protected]79580c62010-02-02 02:36:252971 Source<HostContentSettingsMap> content_settings(source);
[email protected]0314ae02010-04-08 09:18:292972 if (settings_details.ptr()->update_all() ||
2973 settings_details.ptr()->pattern().Matches(entry_url)) {
2974 render_view_host()->SendContentSettings(entry_url,
[email protected]da0c8e92010-02-09 23:25:492975 content_settings.ptr()->GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252976 }
2977 break;
2978 }
2979
[email protected]a888b29e62010-04-01 13:38:572980 case NotificationType::EXTENSION_LOADED: {
[email protected]98aa0b52010-05-06 17:03:082981 if (!extension_app_ && !extension_app_for_current_page_ &&
[email protected]a888b29e62010-04-01 13:38:572982 Source<Profile>(source).ptr() == profile()) {
[email protected]98aa0b52010-05-06 17:03:082983 UpdateExtensionAppForCurrentPage();
2984 if (extension_app_for_current_page_)
[email protected]a888b29e62010-04-01 13:38:572985 NotifyNavigationStateChanged(INVALIDATE_TAB);
2986 }
2987 break;
2988 }
2989
2990 case NotificationType::EXTENSION_UNLOADED:
2991 case NotificationType::EXTENSION_UNLOADED_DISABLED: {
[email protected]98aa0b52010-05-06 17:03:082992 if (extension_app_for_current_page_ ==
[email protected]a888b29e62010-04-01 13:38:572993 Details<Extension>(details).ptr()) {
[email protected]98aa0b52010-05-06 17:03:082994 extension_app_for_current_page_ = NULL;
2995 UpdateExtensionAppForCurrentPage();
[email protected]a888b29e62010-04-01 13:38:572996 NotifyNavigationStateChanged(INVALIDATE_TAB);
2997 }
2998 break;
2999 }
3000
[email protected]420ae012009-04-24 05:16:323001 default:
3002 NOTREACHED();
3003 }
3004}
[email protected]aacd7cc2009-09-02 14:51:103005
[email protected]98aa0b52010-05-06 17:03:083006void TabContents::UpdateExtensionAppIcon(Extension* extension) {
3007 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433008
[email protected]a888b29e62010-04-01 13:38:573009 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083010 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3011 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573012 extension,
3013 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
3014 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3015 Extension::EXTENSION_ICON_SMALLISH),
3016 ImageLoadingTracker::CACHE);
3017 } else {
[email protected]98aa0b52010-05-06 17:03:083018 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573019 }
3020}
3021
3022Extension* TabContents::GetExtensionContaining(const GURL& url) {
3023 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3024 if (!extensions_service)
3025 return NULL;
3026
3027 Extension* extension = extensions_service->GetExtensionByURL(url);
3028 return extension ?
3029 extension : extensions_service->GetExtensionByWebExtent(url);
3030}
3031
[email protected]98aa0b52010-05-06 17:03:083032void TabContents::UpdateExtensionAppForCurrentPage() {
3033 if (extension_app_) {
[email protected]a888b29e62010-04-01 13:38:573034 // Tab has an explicit app extension; nothing to do.
3035 return;
3036 }
3037
3038 // Check the current extension before iterating through all extensions.
[email protected]98aa0b52010-05-06 17:03:083039 if (extension_app_for_current_page_ &&
3040 extension_app_for_current_page_->web_extent().ContainsURL(GetURL())) {
[email protected]a888b29e62010-04-01 13:38:573041 return;
3042 }
3043
[email protected]98aa0b52010-05-06 17:03:083044 extension_app_for_current_page_ = GetExtensionContaining(GetURL());
3045 UpdateExtensionAppIcon(extension_app_for_current_page_);
[email protected]a888b29e62010-04-01 13:38:573046}
3047
3048void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3049 int index) {
3050 if (image) {
[email protected]98aa0b52010-05-06 17:03:083051 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573052 NotifyNavigationStateChanged(INVALIDATE_TAB);
3053 }
3054}
3055
[email protected]beb440c2009-11-06 04:08:543056std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3057 bool is_alert) {
3058 if (!frame_url.has_host())
3059 return l10n_util::GetString(
3060 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3061 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3062
3063 // We really only want the scheme, hostname, and port.
3064 GURL::Replacements replacements;
3065 replacements.ClearUsername();
3066 replacements.ClearPassword();
3067 replacements.ClearPath();
3068 replacements.ClearQuery();
3069 replacements.ClearRef();
3070 GURL clean_url = frame_url.ReplaceComponents(replacements);
3071
3072 // TODO(brettw) it should be easier than this to do the correct language
3073 // handling without getting the accept language from the profile.
3074 std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0,
3075 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
3076 // Force URL to have LTR directionality.
[email protected]4a4afe32010-05-05 01:39:563077 base::i18n::GetDisplayStringInLTRDirectionality(&base_address);
[email protected]beb440c2009-11-06 04:08:543078
3079 return l10n_util::GetStringF(
3080 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
3081 base_address);
3082}
3083
3084gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3085 return view_->GetTopLevelNativeWindow();
3086}
3087
3088void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3089 bool success,
3090 const std::wstring& prompt) {
3091 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3092 if (is_showing_before_unload_dialog_ && !success) {
3093 // If a beforeunload dialog is canceled, we need to stop the throbber from
3094 // spinning, since we forced it to start spinning in Navigate.
3095 DidStopLoading();
3096
3097 tab_close_start_time_ = base::TimeTicks();
3098 }
3099 is_showing_before_unload_dialog_ = false;
3100 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3101}
3102
3103void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3104 set_suppress_javascript_messages(suppress_message_boxes);
3105}
3106
[email protected]41fc0322009-09-04 22:23:403107void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103108 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3109}
[email protected]f45d2a72010-03-08 23:28:353110
3111void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3112 app_icon_ = app_icon;
3113 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3114}
[email protected]ea68c06a2010-04-23 17:25:373115
3116// After a successful *new* login attempt, we take the PasswordFormManager in
3117// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3118// the user makes up their mind with the "save password" infobar. Note if the
3119// login is one we already know about, the end of the line is
3120// provisional_save_manager_ because we just update it on success and so such
3121// forms never end up in an infobar.
3122class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3123 public:
3124 SavePasswordInfoBarDelegate(TabContents* tab_contents,
3125 PasswordFormManager* form_to_save) :
3126 ConfirmInfoBarDelegate(tab_contents),
3127 form_to_save_(form_to_save) {
3128 }
3129
3130 virtual ~SavePasswordInfoBarDelegate() { }
3131
3132 // Overridden from ConfirmInfoBarDelegate:
3133 virtual void InfoBarClosed() {
3134 delete this;
3135 }
3136
3137 virtual std::wstring GetMessageText() const {
3138 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
3139 }
3140
3141 virtual SkBitmap* GetIcon() const {
3142 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3143 IDR_INFOBAR_SAVE_PASSWORD);
3144 }
3145
3146 virtual int GetButtons() const {
3147 return BUTTON_OK | BUTTON_CANCEL;
3148 }
3149
3150 virtual std::wstring GetButtonLabel(InfoBarButton button) const {
3151 if (button == BUTTON_OK)
3152 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
3153 if (button == BUTTON_CANCEL)
3154 return l10n_util::GetString(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
3155 NOTREACHED();
3156 return std::wstring();
3157 }
3158
3159 virtual bool Accept() {
3160 DCHECK(form_to_save_.get());
3161 form_to_save_->Save();
3162 return true;
3163 }
3164
3165 virtual bool Cancel() {
3166 DCHECK(form_to_save_.get());
3167 form_to_save_->PermanentlyBlacklist();
3168 return true;
3169 }
3170
3171 private:
3172 // The PasswordFormManager managing the form we're asking the user about,
3173 // and should update as per her decision.
3174 scoped_ptr<PasswordFormManager> form_to_save_;
3175
3176 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3177};
3178
3179void TabContents::FillPasswordForm(
3180 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
3181 render_view_host()->FillPasswordForm(form_data);
3182}
3183
3184void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3185 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3186}
3187
3188Profile* TabContents::GetProfileForPasswordManager() {
3189 return profile();
3190}
3191
3192bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3193 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3194}