OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/help/help_handler.h" | 5 #include "chrome/browser/ui/webui/help/help_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/google/google_util.h" | 17 #include "chrome/browser/google/google_util.h" |
18 #include "chrome/browser/policy/browser_policy_connector.h" | 18 #include "chrome/browser/policy/browser_policy_connector.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_list.h" | 20 #include "chrome/browser/ui/browser_list.h" |
21 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
24 #include "content/public/browser/browser_thread.h" | |
24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/web_ui.h" | 26 #include "content/public/browser/web_ui.h" |
26 #include "content/public/common/content_client.h" | 27 #include "content/public/common/content_client.h" |
27 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
28 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
29 #include "grit/google_chrome_strings.h" | 30 #include "grit/google_chrome_strings.h" |
30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
32 #include "v8/include/v8.h" | 33 #include "v8/include/v8.h" |
33 #include "webkit/glue/user_agent.h" | 34 #include "webkit/glue/user_agent.h" |
34 #include "webkit/glue/webkit_glue.h" | 35 #include "webkit/glue/webkit_glue.h" |
35 | 36 |
36 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
38 #include "base/i18n/time_formatting.h" | |
39 #include "base/sys_info.h" | |
37 #include "chrome/browser/chromeos/login/user_manager.h" | 40 #include "chrome/browser/chromeos/login/user_manager.h" |
38 #include "chrome/browser/chromeos/cros_settings.h" | 41 #include "chrome/browser/chromeos/cros_settings.h" |
39 #include "chrome/browser/profiles/profile.h" | 42 #include "chrome/browser/profiles/profile.h" |
40 #include "chrome/browser/prefs/pref_service.h" | 43 #include "chrome/browser/prefs/pref_service.h" |
41 #endif | 44 #endif |
42 | 45 |
43 using base::ListValue; | 46 using base::ListValue; |
47 using content::BrowserThread; | |
44 | 48 |
45 namespace { | 49 namespace { |
46 | 50 |
47 // Returns the browser version as a string. | 51 // Returns the browser version as a string. |
48 string16 BuildBrowserVersionString() { | 52 string16 BuildBrowserVersionString() { |
49 chrome::VersionInfo version_info; | 53 chrome::VersionInfo version_info; |
50 DCHECK(version_info.is_valid()); | 54 DCHECK(version_info.is_valid()); |
51 | 55 |
52 std::string browser_version = version_info.Version(); | 56 std::string browser_version = version_info.Version(); |
53 std::string version_modifier = | 57 std::string version_modifier = |
(...skipping 29 matching lines...) Expand all Loading... | |
83 std::string user = chromeos::UserManager::Get()->GetLoggedInUser().email(); | 87 std::string user = chromeos::UserManager::Get()->GetLoggedInUser().email(); |
84 size_t at_pos = user.find('@'); | 88 size_t at_pos = user.find('@'); |
85 if (at_pos != std::string::npos && at_pos + 1 < user.length()) | 89 if (at_pos != std::string::npos && at_pos + 1 < user.length()) |
86 domain = user.substr(user.find('@') + 1); | 90 domain = user.substr(user.find('@') + 1); |
87 return domain == g_browser_process->browser_policy_connector()-> | 91 return domain == g_browser_process->browser_policy_connector()-> |
88 GetEnterpriseDomain(); | 92 GetEnterpriseDomain(); |
89 } | 93 } |
90 return false; | 94 return false; |
91 } | 95 } |
92 | 96 |
97 // Retrieves the time of the last Chrome OS update and converts it to a human- | |
98 // readable string. Note that this method uses an i18n-friendly library, so | |
99 // the returned string will already be properly translated. | |
100 string16 CreateLastUpdatedString() { | |
101 base::Time time; | |
102 | |
103 if (!base::SysInfo::GetTimeLastUpdated(&time)) { | |
104 // If the time of the last update cannot be retrieved, punt and just set | |
105 // the last update time to be the current time. | |
106 time = base::Time::Now(); | |
107 } | |
108 | |
109 return base::TimeFormatFriendlyDate(time); | |
110 } | |
111 | |
112 // Wrapper function to add the "Last Updated" string to |localized_strings|. | |
113 // This function is called from the File thread to ensure that it does not | |
114 // slow down the UI thread. | |
115 void AddLastUpdatedString(DictionaryValue* localized_strings) { | |
116 localized_strings->SetString("lastUpdatedDate", CreateLastUpdatedString()); | |
117 } | |
118 | |
93 #endif // defined(OS_CHROMEOS) | 119 #endif // defined(OS_CHROMEOS) |
94 | 120 |
95 } // namespace | 121 } // namespace |
96 | 122 |
97 HelpHandler::HelpHandler() | 123 HelpHandler::HelpHandler() |
98 : version_updater_(VersionUpdater::Create()) { | 124 : version_updater_(VersionUpdater::Create()) { |
99 } | 125 } |
100 | 126 |
101 HelpHandler::~HelpHandler() { | 127 HelpHandler::~HelpHandler() { |
102 } | 128 } |
(...skipping 26 matching lines...) Expand all Loading... | |
129 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, | 155 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, |
130 { "showMoreInfo", IDS_SHOW_MORE_INFO }, | 156 { "showMoreInfo", IDS_SHOW_MORE_INFO }, |
131 { "hideMoreInfo", IDS_HIDE_MORE_INFO }, | 157 { "hideMoreInfo", IDS_HIDE_MORE_INFO }, |
132 { "channel", IDS_ABOUT_PAGE_CHANNEL }, | 158 { "channel", IDS_ABOUT_PAGE_CHANNEL }, |
133 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, | 159 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, |
134 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, | 160 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, |
135 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, | 161 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, |
136 { "webkit", IDS_WEBKIT }, | 162 { "webkit", IDS_WEBKIT }, |
137 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, | 163 { "userAgent", IDS_ABOUT_VERSION_USER_AGENT }, |
138 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, | 164 { "commandLine", IDS_ABOUT_VERSION_COMMAND_LINE }, |
165 { "lastUpdated", IDS_ABOUT_VERSION_LAST_UPDATED }, | |
139 #endif | 166 #endif |
140 #if defined(OS_MACOSX) | 167 #if defined(OS_MACOSX) |
141 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, | 168 { "promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER }, |
142 #endif | 169 #endif |
143 }; | 170 }; |
144 | 171 |
145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { | 172 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { |
146 localized_strings->SetString(resources[i].name, | 173 localized_strings->SetString(resources[i].name, |
147 l10n_util::GetStringUTF16(resources[i].ids)); | 174 l10n_util::GetStringUTF16(resources[i].ids)); |
148 } | 175 } |
149 | 176 |
150 localized_strings->SetString( | 177 localized_strings->SetString( |
151 "browserVersion", | 178 "browserVersion", |
152 l10n_util::GetStringFUTF16(IDS_ABOUT_PRODUCT_VERSION, | 179 l10n_util::GetStringFUTF16(IDS_ABOUT_PRODUCT_VERSION, |
153 BuildBrowserVersionString())); | 180 BuildBrowserVersionString())); |
154 | 181 |
155 string16 license = l10n_util::GetStringFUTF16( | 182 string16 license = l10n_util::GetStringFUTF16( |
156 IDS_ABOUT_VERSION_LICENSE, | 183 IDS_ABOUT_VERSION_LICENSE, |
157 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( | 184 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( |
158 chrome::kChromiumProjectURL)), | 185 chrome::kChromiumProjectURL)), |
159 ASCIIToUTF16(chrome::kChromeUICreditsURL)); | 186 ASCIIToUTF16(chrome::kChromeUICreditsURL)); |
160 localized_strings->SetString("productLicense", license); | 187 localized_strings->SetString("productLicense", license); |
161 | 188 |
162 #if defined(OS_CHROMEOS) | 189 #if defined(OS_CHROMEOS) |
163 string16 os_license = l10n_util::GetStringFUTF16( | 190 string16 os_license = l10n_util::GetStringFUTF16( |
164 IDS_ABOUT_CROS_VERSION_LICENSE, | 191 IDS_ABOUT_CROS_VERSION_LICENSE, |
165 ASCIIToUTF16(chrome::kChromeUIOSCreditsURL)); | 192 ASCIIToUTF16(chrome::kChromeUIOSCreditsURL)); |
166 localized_strings->SetString("productOsLicense", os_license); | 193 localized_strings->SetString("productOsLicense", os_license); |
194 | |
195 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
196 base::Bind(&AddLastUpdatedString, localized_strings)); | |
Evan Stade
2012/04/16 19:42:51
there is a race here, and besides which localized_
Kyle Horimoto
2012/04/17 18:31:45
Done.
| |
167 #endif | 197 #endif |
168 | 198 |
169 string16 tos = l10n_util::GetStringFUTF16( | 199 string16 tos = l10n_util::GetStringFUTF16( |
170 IDS_ABOUT_TERMS_OF_SERVICE, UTF8ToUTF16(chrome::kChromeUITermsURL)); | 200 IDS_ABOUT_TERMS_OF_SERVICE, UTF8ToUTF16(chrome::kChromeUITermsURL)); |
171 localized_strings->SetString("productTOS", tos); | 201 localized_strings->SetString("productTOS", tos); |
172 | 202 |
173 localized_strings->SetString("webkitVersion", | 203 localized_strings->SetString("webkitVersion", |
174 webkit_glue::GetWebKitVersion()); | 204 webkit_glue::GetWebKitVersion()); |
175 | 205 |
176 localized_strings->SetString("jsEngine", "V8"); | 206 localized_strings->SetString("jsEngine", "V8"); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", | 404 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", |
375 *firmware_string); | 405 *firmware_string); |
376 } | 406 } |
377 | 407 |
378 void HelpHandler::OnReleaseChannel(const std::string& channel) { | 408 void HelpHandler::OnReleaseChannel(const std::string& channel) { |
379 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); | 409 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); |
380 web_ui()->CallJavascriptFunction( | 410 web_ui()->CallJavascriptFunction( |
381 "help.HelpPage.updateSelectedChannel", *channel_string); | 411 "help.HelpPage.updateSelectedChannel", *channel_string); |
382 } | 412 } |
383 #endif // defined(OS_CHROMEOS) | 413 #endif // defined(OS_CHROMEOS) |
OLD | NEW |