| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/dom_ui/new_tab_ui.h" | 5 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "base/string_piece.h" | 8 #include "base/string_piece.h" |
| 9 #include "chrome/app/locales/locale_settings.h" | 9 #include "chrome/app/locales/locale_settings.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_resources.h" | 12 #include "chrome/browser/browser_resources.h" |
| 13 #include "chrome/browser/history_tab_ui.h" | 13 #include "chrome/browser/history_tab_ui.h" |
| 14 #include "chrome/browser/history/page_usage_data.h" | 14 #include "chrome/browser/history/page_usage_data.h" |
| 15 #include "chrome/browser/navigation_entry.h" | 15 #include "chrome/browser/navigation_entry.h" |
| 16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 17 #include "chrome/browser/render_view_host.h" | 17 #include "chrome/browser/render_view_host.h" |
| 18 #include "chrome/browser/template_url.h" | 18 #include "chrome/browser/template_url.h" |
| 19 #include "chrome/browser/user_data_manager.h" |
| 19 #include "chrome/browser/user_metrics.h" | 20 #include "chrome/browser/user_metrics.h" |
| 20 #include "chrome/browser/views/keyword_editor_view.h" | 21 #include "chrome/browser/views/keyword_editor_view.h" |
| 21 #include "chrome/common/jstemplate_builder.h" | 22 #include "chrome/common/jstemplate_builder.h" |
| 22 #include "chrome/common/l10n_util.h" | 23 #include "chrome/common/l10n_util.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/pref_service.h" | 25 #include "chrome/common/pref_service.h" |
| 25 #include "chrome/common/resource_bundle.h" | 26 #include "chrome/common/resource_bundle.h" |
| 26 | 27 |
| 27 #include "chromium_strings.h" | 28 #include "chromium_strings.h" |
| 28 #include "generated_resources.h" | 29 #include "generated_resources.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 162 } |
| 162 | 163 |
| 163 void NewTabHTMLSource::StartDataRequest(const std::string& path, | 164 void NewTabHTMLSource::StartDataRequest(const std::string& path, |
| 164 int request_id) { | 165 int request_id) { |
| 165 if (!path.empty()) { | 166 if (!path.empty()) { |
| 166 // A path under new-tab was requested; it's likely a bad relative | 167 // A path under new-tab was requested; it's likely a bad relative |
| 167 // URL from the new tab page, but in any case it's an error. | 168 // URL from the new tab page, but in any case it's an error. |
| 168 NOTREACHED(); | 169 NOTREACHED(); |
| 169 return; | 170 return; |
| 170 } | 171 } |
| 172 |
| 173 // Show the profile name in the title and most visited labels if the current |
| 174 // profile is not the default. |
| 175 std::wstring title; |
| 176 std::wstring most_visited; |
| 177 if (UserDataManager::Get()->is_current_profile_default()) { |
| 178 title = l10n_util::GetString(IDS_NEW_TAB_TITLE); |
| 179 most_visited = l10n_util::GetString(IDS_NEW_TAB_MOST_VISITED); |
| 180 } else { |
| 181 // Get the current profile name. |
| 182 std::wstring profile_name = |
| 183 UserDataManager::Get()->current_profile_name(); |
| 184 title = l10n_util::GetStringF(IDS_NEW_TAB_TITLE_WITH_PROFILE_NAME, |
| 185 profile_name); |
| 186 most_visited = l10n_util::GetStringF( |
| 187 IDS_NEW_TAB_MOST_VISITED_WITH_PROFILE_NAME, |
| 188 profile_name); |
| 189 } |
| 171 DictionaryValue localized_strings; | 190 DictionaryValue localized_strings; |
| 172 localized_strings.SetString(L"title", | 191 localized_strings.SetString(L"title", title); |
| 173 l10n_util::GetString(IDS_NEW_TAB_TITLE)); | 192 localized_strings.SetString(L"mostvisited", most_visited); |
| 174 localized_strings.SetString(L"mostvisited", | |
| 175 l10n_util::GetString(IDS_NEW_TAB_MOST_VISITED)); | |
| 176 localized_strings.SetString(L"searches", | 193 localized_strings.SetString(L"searches", |
| 177 l10n_util::GetString(IDS_NEW_TAB_SEARCHES)); | 194 l10n_util::GetString(IDS_NEW_TAB_SEARCHES)); |
| 178 localized_strings.SetString(L"bookmarks", | 195 localized_strings.SetString(L"bookmarks", |
| 179 l10n_util::GetString(IDS_NEW_TAB_BOOKMARKS)); | 196 l10n_util::GetString(IDS_NEW_TAB_BOOKMARKS)); |
| 180 localized_strings.SetString(L"showhistory", | 197 localized_strings.SetString(L"showhistory", |
| 181 l10n_util::GetString(IDS_NEW_TAB_HISTORY_SHOW)); | 198 l10n_util::GetString(IDS_NEW_TAB_HISTORY_SHOW)); |
| 182 localized_strings.SetString(L"searchhistory", | 199 localized_strings.SetString(L"searchhistory", |
| 183 l10n_util::GetString(IDS_NEW_TAB_HISTORY_SEARCH)); | 200 l10n_util::GetString(IDS_NEW_TAB_HISTORY_SEARCH)); |
| 184 localized_strings.SetString(L"closedtabs", | 201 localized_strings.SetString(L"closedtabs", |
| 185 l10n_util::GetString(IDS_NEW_TAB_CLOSED_TABS)); | 202 l10n_util::GetString(IDS_NEW_TAB_CLOSED_TABS)); |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 return GURL(url); | 851 return GURL(url); |
| 835 } | 852 } |
| 836 | 853 |
| 837 NewTabUIContents::NewTabUIContents(Profile* profile, | 854 NewTabUIContents::NewTabUIContents(Profile* profile, |
| 838 SiteInstance* instance, RenderViewHostFactory* render_view_factory) : | 855 SiteInstance* instance, RenderViewHostFactory* render_view_factory) : |
| 839 DOMUIHost(profile, instance, render_view_factory), | 856 DOMUIHost(profile, instance, render_view_factory), |
| 840 motd_message_id_(0), | 857 motd_message_id_(0), |
| 841 incognito_(false), | 858 incognito_(false), |
| 842 most_visited_handler_(NULL) { | 859 most_visited_handler_(NULL) { |
| 843 set_type(TAB_CONTENTS_NEW_TAB_UI); | 860 set_type(TAB_CONTENTS_NEW_TAB_UI); |
| 844 set_forced_title(l10n_util::GetString(IDS_NEW_TAB_TITLE)); | 861 |
| 862 // Show profile name in the title if the current profile is not the default. |
| 863 std::wstring title; |
| 864 if (UserDataManager::Get()->is_current_profile_default()) { |
| 865 title = l10n_util::GetString(IDS_NEW_TAB_TITLE); |
| 866 } else { |
| 867 title = l10n_util::GetStringF( |
| 868 IDS_NEW_TAB_TITLE_WITH_PROFILE_NAME, |
| 869 UserDataManager::Get()->current_profile_name()); |
| 870 } |
| 871 set_forced_title(title); |
| 845 | 872 |
| 846 if (profile->IsOffTheRecord()) | 873 if (profile->IsOffTheRecord()) |
| 847 incognito_ = true; | 874 incognito_ = true; |
| 848 | 875 |
| 849 if (NewTabHTMLSource::first_view() && | 876 if (NewTabHTMLSource::first_view() && |
| 850 (profile->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 || | 877 (profile->GetPrefs()->GetInteger(prefs::kRestoreOnStartup) != 0 || |
| 851 !profile->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) | 878 !profile->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) |
| 852 ) { | 879 ) { |
| 853 NewTabHTMLSource::set_first_view(false); | 880 NewTabHTMLSource::set_first_view(false); |
| 854 } | 881 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 void NewTabUIContents::RequestOpenURL(const GURL& url, | 956 void NewTabUIContents::RequestOpenURL(const GURL& url, |
| 930 const GURL& /*referrer*/, | 957 const GURL& /*referrer*/, |
| 931 WindowOpenDisposition disposition) { | 958 WindowOpenDisposition disposition) { |
| 932 // The user opened a URL on the page (including "open in new window"). | 959 // The user opened a URL on the page (including "open in new window"). |
| 933 // We count all such clicks as AUTO_BOOKMARK, which increments the site's | 960 // We count all such clicks as AUTO_BOOKMARK, which increments the site's |
| 934 // visit count (which is used for ranking the most visited entries). | 961 // visit count (which is used for ranking the most visited entries). |
| 935 // Note this means we're including clicks on not only most visited thumbnails, | 962 // Note this means we're including clicks on not only most visited thumbnails, |
| 936 // but also clicks on recently bookmarked. | 963 // but also clicks on recently bookmarked. |
| 937 OpenURL(url, GURL(), disposition, PageTransition::AUTO_BOOKMARK); | 964 OpenURL(url, GURL(), disposition, PageTransition::AUTO_BOOKMARK); |
| 938 } | 965 } |
| OLD | NEW |