Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/settings/about_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "ash/system/chromeos/devicetype_utils.h" | 11 #include "ash/system/chromeos/devicetype_utils.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 36 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
| 37 #include "chrome/grit/chromium_strings.h" | 37 #include "chrome/grit/chromium_strings.h" |
| 38 #include "chrome/grit/generated_resources.h" | 38 #include "chrome/grit/generated_resources.h" |
| 39 #include "components/google/core/browser/google_util.h" | 39 #include "components/google/core/browser/google_util.h" |
| 40 #include "components/policy/core/common/policy_namespace.h" | 40 #include "components/policy/core/common/policy_namespace.h" |
| 41 #include "components/version_info/version_info.h" | 41 #include "components/version_info/version_info.h" |
| 42 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 44 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
| 45 #include "content/public/browser/web_ui.h" | 45 #include "content/public/browser/web_ui.h" |
| 46 #include "content/public/browser/web_ui_data_source.h" | |
| 46 #include "content/public/common/user_agent.h" | 47 #include "content/public/common/user_agent.h" |
| 47 #include "grit/components_chromium_strings.h" | 48 #include "grit/components_chromium_strings.h" |
| 48 #include "grit/components_google_chrome_strings.h" | 49 #include "grit/components_google_chrome_strings.h" |
| 49 #include "grit/components_strings.h" | 50 #include "grit/components_strings.h" |
| 50 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
| 51 #include "policy/policy_constants.h" | 52 #include "policy/policy_constants.h" |
| 52 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "v8/include/v8.h" | 54 #include "v8/include/v8.h" |
| 54 | 55 |
| 55 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) |
| 56 #include "base/files/file_util_proxy.h" | 57 #include "base/files/file_util_proxy.h" |
| 57 #include "base/i18n/time_formatting.h" | 58 #include "base/i18n/time_formatting.h" |
| 58 #include "base/sys_info.h" | 59 #include "base/sys_info.h" |
| 59 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 60 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 60 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" | 61 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" |
| 61 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 62 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 62 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 63 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 63 #include "chrome/browser/chromeos/settings/cros_settings.h" | 64 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 64 #include "chrome/browser/profiles/profile.h" | 65 #include "chrome/browser/profiles/profile.h" |
| 65 #include "chrome/browser/ui/webui/chromeos/image_source.h" | 66 #include "chrome/browser/ui/webui/chromeos/image_source.h" |
| 66 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h" | 67 #include "chrome/browser/ui/webui/help/help_utils_chromeos.h" |
| 67 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" | 68 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" |
| 68 #include "chromeos/chromeos_switches.h" | 69 #include "chromeos/chromeos_switches.h" |
| 69 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 70 #include "chromeos/dbus/power_manager_client.h" | 70 #include "chromeos/dbus/power_manager_client.h" |
| 71 #include "chromeos/system/statistics_provider.h" | 71 #include "chromeos/system/statistics_provider.h" |
| 72 #include "components/prefs/pref_service.h" | |
| 73 #include "components/user_manager/user_manager.h" | 72 #include "components/user_manager/user_manager.h" |
| 74 #endif | 73 #endif |
| 75 | 74 |
| 76 using base::ListValue; | 75 using base::ListValue; |
| 77 using content::BrowserThread; | 76 using content::BrowserThread; |
| 78 | 77 |
| 79 namespace { | 78 namespace { |
| 80 | 79 |
| 81 #if defined(OS_CHROMEOS) | 80 #if defined(OS_CHROMEOS) |
| 82 | 81 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 text_path = text_path.AppendASCII(kRegulatoryLabelTextFilename); | 197 text_path = text_path.AppendASCII(kRegulatoryLabelTextFilename); |
| 199 | 198 |
| 200 std::string contents; | 199 std::string contents; |
| 201 if (base::ReadFileToString(text_path, &contents)) | 200 if (base::ReadFileToString(text_path, &contents)) |
| 202 return contents; | 201 return contents; |
| 203 return std::string(); | 202 return std::string(); |
| 204 } | 203 } |
| 205 | 204 |
| 206 #endif // defined(OS_CHROMEOS) | 205 #endif // defined(OS_CHROMEOS) |
| 207 | 206 |
| 207 std::string UpdateStatusToString(VersionUpdater::Status status) { | |
| 208 std::string status_str; | |
| 209 switch (status) { | |
| 210 case VersionUpdater::CHECKING: | |
| 211 status_str = "checking"; | |
| 212 break; | |
| 213 case VersionUpdater::UPDATING: | |
| 214 status_str = "updating"; | |
| 215 break; | |
| 216 case VersionUpdater::NEARLY_UPDATED: | |
| 217 status_str = "nearly_updated"; | |
| 218 break; | |
| 219 case VersionUpdater::UPDATED: | |
| 220 status_str = "updated"; | |
| 221 break; | |
| 222 case VersionUpdater::FAILED: | |
| 223 case VersionUpdater::FAILED_OFFLINE: | |
| 224 case VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED: | |
| 225 status_str = "failed"; | |
| 226 break; | |
| 227 case VersionUpdater::DISABLED: | |
| 228 status_str = "disabled"; | |
| 229 break; | |
| 230 case VersionUpdater::DISABLED_BY_ADMIN: | |
| 231 status_str = "disabled_by_admin"; | |
| 232 break; | |
| 233 } | |
| 234 | |
| 235 return status_str; | |
| 236 } | |
| 237 | |
| 208 } // namespace | 238 } // namespace |
| 209 | 239 |
| 210 HelpHandler::HelpHandler() | 240 namespace settings { |
| 241 | |
| 242 AboutHandler::AboutHandler() | |
| 211 : policy_registrar_( | 243 : policy_registrar_( |
| 212 g_browser_process->policy_service(), | 244 g_browser_process->policy_service(), |
| 213 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())), | 245 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())), |
| 214 weak_factory_(this) { | 246 weak_factory_(this) { |
| 215 } | 247 } |
| 216 | 248 |
| 217 HelpHandler::~HelpHandler() { | 249 AboutHandler::~AboutHandler() {} |
| 218 } | |
| 219 | 250 |
| 220 void HelpHandler::GetLocalizedValues(base::DictionaryValue* localized_strings) { | 251 AboutHandler* AboutHandler::Create(content::WebUIDataSource* html_source, |
| 221 struct L10nResources { | 252 Profile* profile) { |
| 222 const char* name; | 253 html_source->AddString( |
| 223 int ids; | 254 "aboutBrowserVersion", |
| 224 }; | |
| 225 | |
| 226 static L10nResources resources[] = { | |
| 227 {"aboutTitle", IDS_ABOUT_TITLE}, | |
| 228 #if defined(OS_CHROMEOS) | |
| 229 {"aboutProductTitle", IDS_PRODUCT_OS_NAME}, | |
| 230 #else | |
| 231 {"aboutProductTitle", IDS_PRODUCT_NAME}, | |
| 232 #endif | |
| 233 {"aboutProductDescription", IDS_ABOUT_PRODUCT_DESCRIPTION}, | |
| 234 {"relaunch", IDS_RELAUNCH_BUTTON}, | |
| 235 #if defined(OS_CHROMEOS) | |
| 236 {"relaunchAndPowerwash", IDS_RELAUNCH_AND_POWERWASH_BUTTON}, | |
| 237 #endif | |
| 238 {"productName", IDS_PRODUCT_NAME}, | |
| 239 {"updateCheckStarted", IDS_UPGRADE_CHECK_STARTED}, | |
| 240 {"updating", IDS_UPGRADE_UPDATING}, | |
| 241 #if defined(OS_CHROMEOS) || defined(OS_WIN) | |
| 242 {"updateDisabledByPolicy", IDS_UPGRADE_DISABLED_BY_POLICY}, | |
| 243 #endif // defined(OS_CHROMEOS) || defined(OS_WIN) | |
| 244 #if defined(OS_CHROMEOS) | |
| 245 {"updateButton", IDS_UPGRADE_BUTTON}, | |
| 246 {"updatingChannelSwitch", IDS_UPGRADE_UPDATING_CHANNEL_SWITCH}, | |
| 247 #endif | |
| 248 {"updateAlmostDone", IDS_UPGRADE_SUCCESSFUL_RELAUNCH}, | |
| 249 #if defined(OS_CHROMEOS) | |
| 250 {"successfulChannelSwitch", IDS_UPGRADE_SUCCESSFUL_CHANNEL_SWITCH}, | |
| 251 #endif | |
| 252 {"getHelpWithChrome", IDS_GET_HELP_USING_CHROME}, | |
| 253 {"reportAnIssue", IDS_REPORT_AN_ISSUE}, | |
| 254 #if defined(OS_CHROMEOS) | |
| 255 {"platform", IDS_PLATFORM_LABEL}, | |
| 256 {"arcVersion", IDS_ARC_VERSION_LABEL}, | |
| 257 {"firmware", IDS_ABOUT_PAGE_FIRMWARE}, | |
| 258 {"showMoreInfo", IDS_SHOW_MORE_INFO}, | |
| 259 {"hideMoreInfo", IDS_HIDE_MORE_INFO}, | |
| 260 {"channel", IDS_ABOUT_PAGE_CHANNEL}, | |
| 261 {"stable", IDS_ABOUT_PAGE_CHANNEL_STABLE}, | |
| 262 {"beta", IDS_ABOUT_PAGE_CHANNEL_BETA}, | |
| 263 {"dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT}, | |
| 264 {"channel-changed", IDS_ABOUT_PAGE_CHANNEL_CHANGED}, | |
| 265 {"currentChannelStable", IDS_ABOUT_PAGE_CURRENT_CHANNEL_STABLE}, | |
| 266 {"currentChannelBeta", IDS_ABOUT_PAGE_CURRENT_CHANNEL_BETA}, | |
| 267 {"currentChannelDev", IDS_ABOUT_PAGE_CURRENT_CHANNEL_DEV}, | |
| 268 {"currentChannel", IDS_ABOUT_PAGE_CURRENT_CHANNEL}, | |
| 269 {"channelChangeButton", IDS_ABOUT_PAGE_CHANNEL_CHANGE_BUTTON}, | |
| 270 {"channelChangeDisallowedMessage", | |
| 271 IDS_ABOUT_PAGE_CHANNEL_CHANGE_DISALLOWED_MESSAGE}, | |
| 272 {"channelChangePageTitle", IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_TITLE}, | |
| 273 {"channelChangePagePowerwashTitle", | |
| 274 IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_POWERWASH_TITLE}, | |
| 275 {"channelChangePagePowerwashMessage", | |
| 276 IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_POWERWASH_MESSAGE}, | |
| 277 {"channelChangePageDelayedChangeTitle", | |
| 278 IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_DELAYED_CHANGE_TITLE}, | |
| 279 {"channelChangePageUnstableTitle", | |
| 280 IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_UNSTABLE_TITLE}, | |
| 281 {"channelChangePagePowerwashButton", | |
| 282 IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_POWERWASH_BUTTON}, | |
| 283 {"channelChangePageChangeButton", | |
| 284 IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_CHANGE_BUTTON}, | |
| 285 {"channelChangePageCancelButton", | |
| 286 IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_CANCEL_BUTTON}, | |
| 287 {"webkit", IDS_WEBKIT}, | |
| 288 {"userAgent", IDS_VERSION_UI_USER_AGENT}, | |
| 289 {"commandLine", IDS_VERSION_UI_COMMAND_LINE}, | |
| 290 {"buildDate", IDS_VERSION_UI_BUILD_DATE}, | |
| 291 #endif | |
| 292 #if defined(OS_MACOSX) || defined(OS_WIN) | |
| 293 {"learnMore", IDS_LEARN_MORE}, | |
| 294 #endif | |
| 295 #if defined(OS_MACOSX) | |
| 296 {"promote", IDS_ABOUT_CHROME_PROMOTE_UPDATER}, | |
| 297 #endif | |
| 298 }; | |
| 299 | |
| 300 for (size_t i = 0; i < arraysize(resources); ++i) { | |
| 301 localized_strings->SetString(resources[i].name, | |
| 302 l10n_util::GetStringUTF16(resources[i].ids)); | |
| 303 } | |
| 304 | |
| 305 #if defined(OS_CHROMEOS) | |
| 306 localized_strings->SetString("upToDate", ash::SubstituteChromeOSDeviceType( | |
| 307 IDS_UPGRADE_UP_TO_DATE)); | |
| 308 #else | |
| 309 localized_strings->SetString("upToDate", l10n_util::GetStringUTF16( | |
| 310 IDS_UPGRADE_UP_TO_DATE)); | |
| 311 #endif | |
| 312 | |
| 313 localized_strings->SetString("updateObsoleteSystem", | |
| 314 ObsoleteSystem::LocalizedObsoleteString()); | |
| 315 localized_strings->SetString("updateObsoleteSystemURL", | |
| 316 ObsoleteSystem::GetLinkURL()); | |
| 317 | |
| 318 localized_strings->SetString( | |
| 319 "browserVersion", | |
| 320 l10n_util::GetStringFUTF16(IDS_ABOUT_PRODUCT_VERSION, | 255 l10n_util::GetStringFUTF16(IDS_ABOUT_PRODUCT_VERSION, |
| 321 BuildBrowserVersionString())); | 256 BuildBrowserVersionString())); |
| 322 | 257 |
| 323 base::Time::Exploded exploded_time; | 258 base::Time::Exploded exploded_time; |
| 324 base::Time::Now().LocalExplode(&exploded_time); | 259 base::Time::Now().LocalExplode(&exploded_time); |
| 325 localized_strings->SetString( | 260 html_source->AddString( |
| 326 "productCopyright", | 261 "aboutProductCopyright", |
| 327 l10n_util::GetStringFUTF16(IDS_ABOUT_VERSION_COPYRIGHT, | 262 l10n_util::GetStringFUTF16(IDS_ABOUT_VERSION_COPYRIGHT, |
| 328 base::IntToString16(exploded_time.year))); | 263 base::IntToString16(exploded_time.year))); |
| 329 | 264 |
| 330 base::string16 license = l10n_util::GetStringFUTF16( | 265 base::string16 license = l10n_util::GetStringFUTF16( |
| 331 IDS_VERSION_UI_LICENSE, base::ASCIIToUTF16(chrome::kChromiumProjectURL), | 266 IDS_VERSION_UI_LICENSE, base::ASCIIToUTF16(chrome::kChromiumProjectURL), |
| 332 base::ASCIIToUTF16(chrome::kChromeUICreditsURL)); | 267 base::ASCIIToUTF16(chrome::kChromeUICreditsURL)); |
| 333 localized_strings->SetString("productLicense", license); | 268 html_source->AddString("aboutProductLicense", license); |
| 269 | |
| 270 html_source->AddBoolean("aboutObsolteNowOrSoon", | |
| 271 ObsoleteSystem::IsObsoleteNowOrSoon()); | |
| 272 html_source->AddBoolean( | |
| 273 "aboutObsolteEndOfTheLine", | |
| 274 ObsoleteSystem::IsObsoleteNowOrSoon() && | |
| 275 ObsoleteSystem::IsEndOfTheLine()); | |
| 334 | 276 |
| 335 #if defined(OS_CHROMEOS) | 277 #if defined(OS_CHROMEOS) |
| 336 base::string16 os_license = l10n_util::GetStringFUTF16( | 278 base::string16 os_license = l10n_util::GetStringFUTF16( |
| 337 IDS_ABOUT_CROS_VERSION_LICENSE, | 279 IDS_ABOUT_CROS_VERSION_LICENSE, |
| 338 base::ASCIIToUTF16(chrome::kChromeUIOSCreditsURL)); | 280 base::ASCIIToUTF16(chrome::kChromeUIOSCreditsURL)); |
| 339 localized_strings->SetString("productOsLicense", os_license); | 281 html_source->AddString("aboutProductOsLicense", os_license); |
| 340 | 282 |
| 341 base::string16 product_name = l10n_util::GetStringUTF16(IDS_PRODUCT_OS_NAME); | 283 html_source->AddBoolean("aboutCanChangeChannel", CanChangeChannel(profile)); |
| 342 localized_strings->SetString( | 284 html_source->AddBoolean("aboutEnterpriseManaged", IsEnterpriseManaged()); |
| 343 "channelChangePageDelayedChangeMessage", | |
| 344 l10n_util::GetStringFUTF16( | |
| 345 IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_DELAYED_CHANGE_MESSAGE, | |
| 346 product_name)); | |
| 347 localized_strings->SetString( | |
| 348 "channelChangePageUnstableMessage", | |
| 349 l10n_util::GetStringFUTF16( | |
| 350 IDS_ABOUT_PAGE_CHANNEL_CHANGE_PAGE_UNSTABLE_MESSAGE, | |
| 351 product_name)); | |
| 352 | 285 |
| 353 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 286 base::Time build_time = base::SysInfo::GetLsbReleaseTime(); |
| 354 chromeos::switches::kDisableNewChannelSwitcherUI)) { | 287 base::string16 build_date = base::TimeFormatFriendlyDate(build_time); |
| 355 localized_strings->SetBoolean("disableNewChannelSwitcherUI", true); | 288 html_source->AddString("aboutBuildDate", build_date); |
| 356 } | |
| 357 #endif | 289 #endif |
| 358 | 290 |
| 359 base::string16 tos = l10n_util::GetStringFUTF16( | 291 return new AboutHandler(); |
| 360 IDS_ABOUT_TERMS_OF_SERVICE, base::UTF8ToUTF16(chrome::kChromeUITermsURL)); | |
| 361 localized_strings->SetString("productTOS", tos); | |
| 362 | |
| 363 localized_strings->SetString("webkitVersion", content::GetWebKitVersion()); | |
| 364 | |
| 365 localized_strings->SetString("jsEngine", "V8"); | |
| 366 localized_strings->SetString("jsEngineVersion", v8::V8::GetVersion()); | |
| 367 | |
| 368 localized_strings->SetString("userAgentInfo", GetUserAgent()); | |
| 369 | |
| 370 base::CommandLine::StringType command_line = | |
| 371 base::CommandLine::ForCurrentProcess()->GetCommandLineString(); | |
| 372 localized_strings->SetString("commandLineInfo", command_line); | |
| 373 } | 292 } |
| 374 | 293 |
| 375 void HelpHandler::RegisterMessages() { | 294 void AboutHandler::RegisterMessages() { |
| 376 version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents())); | 295 version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents())); |
| 377 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 296 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
|
tommycli
2016/05/10 20:45:40
Can we put both registrar_ and policy_registrar_ n
dpapad
2016/05/10 22:03:02
Done for registrar_.
policy_registrar_ does not se
tommycli
2016/05/10 22:14:52
Ah, yes, I've run into that problem too. Here was
dpapad
2016/05/10 23:49:52
I see, that makes sense. I could follow the same s
tommycli
2016/05/10 23:54:54
SGTM. If you are OK with a browser crash, then rel
| |
| 378 content::NotificationService::AllSources()); | 297 content::NotificationService::AllSources()); |
| 379 policy_registrar_.Observe( | 298 policy_registrar_.Observe( |
| 380 policy::key::kDeviceAutoUpdateDisabled, | 299 policy::key::kDeviceAutoUpdateDisabled, |
| 381 base::Bind(&HelpHandler::OnDeviceAutoUpdatePolicyChanged, | 300 base::Bind(&AboutHandler::OnDeviceAutoUpdatePolicyChanged, |
| 382 base::Unretained(this))); | 301 base::Unretained(this))); |
| 383 | 302 |
| 384 web_ui()->RegisterMessageCallback("onPageLoaded", | 303 web_ui()->RegisterMessageCallback("refreshUpdateStatus", |
| 385 base::Bind(&HelpHandler::OnPageLoaded, base::Unretained(this))); | 304 base::Bind(&AboutHandler::HandleRefreshUpdateStatus, |
| 305 base::Unretained(this))); | |
| 386 web_ui()->RegisterMessageCallback("relaunchNow", | 306 web_ui()->RegisterMessageCallback("relaunchNow", |
| 387 base::Bind(&HelpHandler::RelaunchNow, base::Unretained(this))); | 307 base::Bind(&AboutHandler::HandleRelaunchNow, base::Unretained(this))); |
| 388 web_ui()->RegisterMessageCallback("openFeedbackDialog", | 308 web_ui()->RegisterMessageCallback("openFeedbackDialog", |
| 389 base::Bind(&HelpHandler::OpenFeedbackDialog, base::Unretained(this))); | 309 base::Bind(&AboutHandler::HandleOpenFeedbackDialog, |
| 310 base::Unretained(this))); | |
| 390 web_ui()->RegisterMessageCallback("openHelpPage", | 311 web_ui()->RegisterMessageCallback("openHelpPage", |
| 391 base::Bind(&HelpHandler::OpenHelpPage, base::Unretained(this))); | 312 base::Bind(&AboutHandler::HandleOpenHelpPage, base::Unretained(this))); |
| 392 #if defined(OS_CHROMEOS) | 313 #if defined(OS_CHROMEOS) |
| 393 web_ui()->RegisterMessageCallback("setChannel", | 314 web_ui()->RegisterMessageCallback("setChannel", |
| 394 base::Bind(&HelpHandler::SetChannel, base::Unretained(this))); | 315 base::Bind(&AboutHandler::SetChannel, base::Unretained(this))); |
| 395 web_ui()->RegisterMessageCallback("relaunchAndPowerwash", | |
| 396 base::Bind(&HelpHandler::RelaunchAndPowerwash, base::Unretained(this))); | |
| 397 web_ui()->RegisterMessageCallback("requestUpdate", | 316 web_ui()->RegisterMessageCallback("requestUpdate", |
| 398 base::Bind(&HelpHandler::RequestUpdate, base::Unretained(this))); | 317 base::Bind(&AboutHandler::HandleRequestUpdate, base::Unretained(this))); |
| 318 web_ui()->RegisterMessageCallback("getOsVersion", | |
| 319 base::Bind(&AboutHandler::HandleGetOsVersion, base::Unretained(this))); | |
| 320 web_ui()->RegisterMessageCallback("getArcVersion", | |
| 321 base::Bind(&AboutHandler::HandleGetArcVersion, base::Unretained(this))); | |
| 322 web_ui()->RegisterMessageCallback("getOsFirmware", | |
| 323 base::Bind(&AboutHandler::HandleGetOsFirmware, base::Unretained(this))); | |
| 324 web_ui()->RegisterMessageCallback("getRegulatoryInfo", | |
| 325 base::Bind(&AboutHandler::HandleGetRegulatoryInfo, | |
| 326 base::Unretained(this))); | |
| 327 web_ui()->RegisterMessageCallback("getCurrentChannel", | |
| 328 base::Bind(&AboutHandler::HandleGetCurrentChannel, | |
| 329 base::Unretained(this))); | |
| 330 web_ui()->RegisterMessageCallback("getTargetChannel", | |
| 331 base::Bind(&AboutHandler::HandleGetTargetChannel, | |
| 332 base::Unretained(this))); | |
| 399 #endif | 333 #endif |
| 400 #if defined(OS_MACOSX) | 334 #if defined(OS_MACOSX) |
| 401 web_ui()->RegisterMessageCallback("promoteUpdater", | 335 web_ui()->RegisterMessageCallback("promoteUpdater", |
| 402 base::Bind(&HelpHandler::PromoteUpdater, base::Unretained(this))); | 336 base::Bind(&AboutHandler::PromoteUpdater, base::Unretained(this))); |
| 403 #endif | 337 #endif |
| 404 | 338 |
| 405 #if defined(OS_CHROMEOS) | 339 #if defined(OS_CHROMEOS) |
| 406 // Handler for the product label image, which will be shown if available. | 340 // Handler for the product label image, which will be shown if available. |
| 407 content::URLDataSource::Add(Profile::FromWebUI(web_ui()), | 341 content::URLDataSource::Add(Profile::FromWebUI(web_ui()), |
| 408 new chromeos::ImageSource()); | 342 new chromeos::ImageSource()); |
| 409 #endif | 343 #endif |
| 410 } | 344 } |
| 411 | 345 |
| 412 void HelpHandler::Observe(int type, const content::NotificationSource& source, | 346 void AboutHandler::Observe(int type, const content::NotificationSource& source, |
| 413 const content::NotificationDetails& details) { | 347 const content::NotificationDetails& details) { |
| 414 switch (type) { | 348 switch (type) { |
| 415 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { | 349 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { |
| 416 // A version update is installed and ready to go. Refresh the UI so the | 350 // A version update is installed and ready to go. Refresh the UI so the |
| 417 // correct state will be shown. | 351 // correct state will be shown. |
| 418 RequestUpdate(NULL); | 352 RequestUpdate(); |
| 419 break; | 353 break; |
| 420 } | 354 } |
| 421 default: | 355 default: |
| 422 NOTREACHED(); | 356 NOTREACHED(); |
| 423 } | 357 } |
| 424 } | 358 } |
| 425 | 359 |
| 426 // static | 360 // static |
| 427 base::string16 HelpHandler::BuildBrowserVersionString() { | 361 base::string16 AboutHandler::BuildBrowserVersionString() { |
| 428 std::string version = version_info::GetVersionNumber(); | 362 std::string version = version_info::GetVersionNumber(); |
| 429 | 363 |
| 430 std::string modifier = chrome::GetChannelString(); | 364 std::string modifier = chrome::GetChannelString(); |
| 431 if (!modifier.empty()) | 365 if (!modifier.empty()) |
| 432 version += " " + modifier; | 366 version += " " + modifier; |
| 433 | 367 |
| 434 #if defined(ARCH_CPU_64_BITS) | 368 #if defined(ARCH_CPU_64_BITS) |
| 435 version += " (64-bit)"; | 369 version += " (64-bit)"; |
| 436 #endif | 370 #endif |
| 437 | 371 |
| 438 return base::UTF8ToUTF16(version); | 372 return base::UTF8ToUTF16(version); |
| 439 } | 373 } |
| 440 | 374 |
| 441 void HelpHandler::OnDeviceAutoUpdatePolicyChanged( | 375 void AboutHandler::OnDeviceAutoUpdatePolicyChanged( |
| 442 const base::Value* previous_policy, | 376 const base::Value* previous_policy, |
| 443 const base::Value* current_policy) { | 377 const base::Value* current_policy) { |
| 444 bool previous_auto_update_disabled = false; | 378 bool previous_auto_update_disabled = false; |
| 445 if (previous_policy) | 379 if (previous_policy) |
| 446 CHECK(previous_policy->GetAsBoolean(&previous_auto_update_disabled)); | 380 CHECK(previous_policy->GetAsBoolean(&previous_auto_update_disabled)); |
| 447 | 381 |
| 448 bool current_auto_update_disabled = false; | 382 bool current_auto_update_disabled = false; |
| 449 if (current_policy) | 383 if (current_policy) |
| 450 CHECK(current_policy->GetAsBoolean(¤t_auto_update_disabled)); | 384 CHECK(current_policy->GetAsBoolean(¤t_auto_update_disabled)); |
| 451 | 385 |
| 452 if (current_auto_update_disabled != previous_auto_update_disabled) { | 386 if (current_auto_update_disabled != previous_auto_update_disabled) { |
| 453 // Refresh the update status to refresh the status of the UI. | 387 // Refresh the update status to refresh the status of the UI. |
| 454 RefreshUpdateStatus(); | 388 HandleRefreshUpdateStatus(nullptr); |
| 455 } | 389 } |
| 456 } | 390 } |
| 457 | 391 |
| 458 void HelpHandler::RefreshUpdateStatus() { | 392 void AboutHandler::HandleRefreshUpdateStatus(const base::ListValue* args) { |
|
tommycli
2016/05/10 20:45:39
Optional suggestion: Consider making this an expli
dpapad
2016/05/10 22:03:02
I thought about this and decided not to convert th
| |
| 459 // On Chrome OS, do not check for an update automatically. | 393 // On Chrome OS, do not check for an update automatically. |
| 460 #if defined(OS_CHROMEOS) | 394 #if defined(OS_CHROMEOS) |
| 461 static_cast<VersionUpdaterCros*>(version_updater_.get())->GetUpdateStatus( | 395 static_cast<VersionUpdaterCros*>(version_updater_.get())->GetUpdateStatus( |
| 462 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this))); | 396 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this))); |
| 463 #else | 397 #else |
| 464 RequestUpdate(NULL); | 398 RequestUpdate(); |
| 465 #endif | |
| 466 } | |
| 467 | |
| 468 void HelpHandler::OnPageLoaded(const base::ListValue* args) { | |
| 469 #if defined(OS_CHROMEOS) | |
| 470 base::PostTaskAndReplyWithResult( | |
| 471 content::BrowserThread::GetBlockingPool(), | |
| 472 FROM_HERE, | |
| 473 base::Bind(&chromeos::version_loader::GetVersion, | |
| 474 chromeos::version_loader::VERSION_FULL), | |
| 475 base::Bind(&HelpHandler::OnOSVersion, | |
| 476 weak_factory_.GetWeakPtr())); | |
| 477 base::PostTaskAndReplyWithResult( | |
| 478 content::BrowserThread::GetBlockingPool(), | |
| 479 FROM_HERE, | |
| 480 base::Bind(&chromeos::version_loader::GetARCVersion), | |
| 481 base::Bind(&HelpHandler::OnARCVersion, | |
| 482 weak_factory_.GetWeakPtr())); | |
| 483 base::PostTaskAndReplyWithResult( | |
| 484 content::BrowserThread::GetBlockingPool(), | |
| 485 FROM_HERE, | |
| 486 base::Bind(&chromeos::version_loader::GetFirmware), | |
| 487 base::Bind(&HelpHandler::OnOSFirmware, | |
| 488 weak_factory_.GetWeakPtr())); | |
| 489 | |
| 490 web_ui()->CallJavascriptFunction( | |
| 491 "help.HelpPage.updateEnableReleaseChannel", | |
| 492 base::FundamentalValue(CanChangeChannel(Profile::FromWebUI(web_ui())))); | |
| 493 | |
| 494 base::Time build_time = base::SysInfo::GetLsbReleaseTime(); | |
| 495 base::string16 build_date = base::TimeFormatFriendlyDate(build_time); | |
| 496 web_ui()->CallJavascriptFunction("help.HelpPage.setBuildDate", | |
| 497 base::StringValue(build_date)); | |
| 498 #endif // defined(OS_CHROMEOS) | |
| 499 | |
| 500 RefreshUpdateStatus(); | |
| 501 | |
| 502 web_ui()->CallJavascriptFunction( | |
| 503 "help.HelpPage.setObsoleteSystem", | |
| 504 base::FundamentalValue(ObsoleteSystem::IsObsoleteNowOrSoon())); | |
| 505 web_ui()->CallJavascriptFunction( | |
| 506 "help.HelpPage.setObsoleteSystemEndOfTheLine", | |
| 507 base::FundamentalValue(ObsoleteSystem::IsObsoleteNowOrSoon() && | |
| 508 ObsoleteSystem::IsEndOfTheLine())); | |
| 509 | |
| 510 #if defined(OS_CHROMEOS) | |
| 511 web_ui()->CallJavascriptFunction( | |
| 512 "help.HelpPage.updateIsEnterpriseManaged", | |
| 513 base::FundamentalValue(IsEnterpriseManaged())); | |
| 514 // First argument to GetChannel() is a flag that indicates whether | |
| 515 // current channel should be returned (if true) or target channel | |
| 516 // (otherwise). | |
| 517 version_updater_->GetChannel(true, | |
| 518 base::Bind(&HelpHandler::OnCurrentChannel, weak_factory_.GetWeakPtr())); | |
| 519 version_updater_->GetChannel(false, | |
| 520 base::Bind(&HelpHandler::OnTargetChannel, weak_factory_.GetWeakPtr())); | |
| 521 | |
| 522 base::PostTaskAndReplyWithResult( | |
| 523 content::BrowserThread::GetBlockingPool(), | |
| 524 FROM_HERE, | |
| 525 base::Bind(&FindRegulatoryLabelDir), | |
| 526 base::Bind(&HelpHandler::OnRegulatoryLabelDirFound, | |
| 527 weak_factory_.GetWeakPtr())); | |
| 528 #endif | 399 #endif |
| 529 } | 400 } |
| 530 | 401 |
| 531 #if defined(OS_MACOSX) | 402 #if defined(OS_MACOSX) |
| 532 void HelpHandler::PromoteUpdater(const base::ListValue* args) { | 403 void AboutHandler::PromoteUpdater(const base::ListValue* args) { |
| 533 version_updater_->PromoteUpdater(); | 404 version_updater_->PromoteUpdater(); |
| 534 } | 405 } |
| 535 #endif | 406 #endif |
| 536 | 407 |
| 537 void HelpHandler::RelaunchNow(const base::ListValue* args) { | 408 void AboutHandler::HandleRelaunchNow(const base::ListValue* args) { |
| 538 DCHECK(args->empty()); | 409 DCHECK(args->empty()); |
| 539 version_updater_->RelaunchBrowser(); | 410 version_updater_->RelaunchBrowser(); |
| 540 } | 411 } |
| 541 | 412 |
| 542 void HelpHandler::OpenFeedbackDialog(const base::ListValue* args) { | 413 void AboutHandler::HandleOpenFeedbackDialog(const base::ListValue* args) { |
| 543 DCHECK(args->empty()); | 414 DCHECK(args->empty()); |
| 544 Browser* browser = chrome::FindBrowserWithWebContents( | 415 Browser* browser = chrome::FindBrowserWithWebContents( |
| 545 web_ui()->GetWebContents()); | 416 web_ui()->GetWebContents()); |
| 546 chrome::OpenFeedbackDialog(browser); | 417 chrome::OpenFeedbackDialog(browser); |
| 547 } | 418 } |
| 548 | 419 |
| 549 void HelpHandler::OpenHelpPage(const base::ListValue* args) { | 420 void AboutHandler::HandleOpenHelpPage(const base::ListValue* args) { |
| 550 DCHECK(args->empty()); | 421 DCHECK(args->empty()); |
| 551 Browser* browser = chrome::FindBrowserWithWebContents( | 422 Browser* browser = chrome::FindBrowserWithWebContents( |
| 552 web_ui()->GetWebContents()); | 423 web_ui()->GetWebContents()); |
| 553 chrome::ShowHelp(browser, chrome::HELP_SOURCE_WEBUI); | 424 chrome::ShowHelp(browser, chrome::HELP_SOURCE_WEBUI); |
| 554 } | 425 } |
| 555 | 426 |
| 556 #if defined(OS_CHROMEOS) | 427 #if defined(OS_CHROMEOS) |
| 557 | 428 |
| 558 void HelpHandler::SetChannel(const base::ListValue* args) { | 429 void AboutHandler::SetChannel(const base::ListValue* args) { |
| 559 DCHECK(args->GetSize() == 2); | 430 DCHECK(args->GetSize() == 2); |
| 560 | 431 |
| 561 if (!CanChangeChannel(Profile::FromWebUI(web_ui()))) { | 432 if (!CanChangeChannel(Profile::FromWebUI(web_ui()))) { |
| 562 LOG(WARNING) << "Non-owner tried to change release track."; | 433 LOG(WARNING) << "Non-owner tried to change release track."; |
| 563 return; | 434 return; |
| 564 } | 435 } |
| 565 | 436 |
| 566 base::string16 channel; | 437 base::string16 channel; |
| 567 bool is_powerwash_allowed; | 438 bool is_powerwash_allowed; |
| 568 if (!args->GetString(0, &channel) || | 439 if (!args->GetString(0, &channel) || |
| 569 !args->GetBoolean(1, &is_powerwash_allowed)) { | 440 !args->GetBoolean(1, &is_powerwash_allowed)) { |
| 570 LOG(ERROR) << "Can't parse SetChannel() args"; | 441 LOG(ERROR) << "Can't parse SetChannel() args"; |
| 571 return; | 442 return; |
| 572 } | 443 } |
| 573 | 444 |
| 574 version_updater_->SetChannel(base::UTF16ToUTF8(channel), | 445 version_updater_->SetChannel(base::UTF16ToUTF8(channel), |
| 575 is_powerwash_allowed); | 446 is_powerwash_allowed); |
| 576 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { | 447 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) { |
| 577 // Check for update after switching release channel. | 448 // Check for update after switching release channel. |
| 578 version_updater_->CheckForUpdate(base::Bind(&HelpHandler::SetUpdateStatus, | 449 version_updater_->CheckForUpdate(base::Bind(&AboutHandler::SetUpdateStatus, |
| 579 base::Unretained(this)), | 450 base::Unretained(this)), |
| 580 VersionUpdater::PromoteCallback()); | 451 VersionUpdater::PromoteCallback()); |
| 581 } | 452 } |
| 582 } | 453 } |
| 583 | 454 |
| 584 void HelpHandler::RelaunchAndPowerwash(const base::ListValue* args) { | 455 void AboutHandler::HandleGetOsVersion(const base::ListValue* args) { |
|
tommycli
2016/05/10 20:45:40
Consider coalescing these blocking pool calls into
tommycli
2016/05/10 20:45:40
Another optional thing: Consider coalescing all th
dpapad
2016/05/10 22:03:02
What would be the benefit of coalescing them? This
tommycli
2016/05/10 22:14:52
I was thinking of something like:
namespace {
//
dpapad
2016/05/10 23:49:52
Done. Thanks for the pointers.
| |
| 585 DCHECK(args->empty()); | 456 CHECK_EQ(1U, args->GetSize()); |
| 457 std::string callback_id; | |
| 458 CHECK(args->GetString(0, &callback_id)); | |
| 586 | 459 |
| 587 if (IsEnterpriseManaged()) | 460 base::PostTaskAndReplyWithResult( |
| 588 return; | 461 content::BrowserThread::GetBlockingPool(), |
| 462 FROM_HERE, | |
| 463 base::Bind(&chromeos::version_loader::GetVersion, | |
| 464 chromeos::version_loader::VERSION_FULL), | |
| 465 base::Bind(&AboutHandler::OnVersionReady, | |
| 466 weak_factory_.GetWeakPtr(), | |
| 467 callback_id)); | |
| 468 } | |
| 589 | 469 |
| 590 PrefService* prefs = g_browser_process->local_state(); | 470 void AboutHandler::HandleGetArcVersion(const base::ListValue* args) { |
| 591 prefs->SetBoolean(prefs::kFactoryResetRequested, true); | 471 CHECK_EQ(1U, args->GetSize()); |
| 592 prefs->CommitPendingWrite(); | 472 std::string callback_id; |
| 473 CHECK(args->GetString(0, &callback_id)); | |
| 593 | 474 |
| 594 // Perform sign out. Current chrome process will then terminate, new one will | 475 base::PostTaskAndReplyWithResult( |
| 595 // be launched (as if it was a restart). | 476 content::BrowserThread::GetBlockingPool(), |
| 596 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); | 477 FROM_HERE, |
| 478 base::Bind(&chromeos::version_loader::GetARCVersion), | |
| 479 base::Bind(&AboutHandler::OnVersionReady, | |
| 480 weak_factory_.GetWeakPtr(), | |
| 481 callback_id)); | |
| 482 } | |
| 483 | |
| 484 void AboutHandler::HandleGetOsFirmware(const base::ListValue* args) { | |
| 485 CHECK_EQ(1U, args->GetSize()); | |
| 486 std::string callback_id; | |
| 487 CHECK(args->GetString(0, &callback_id)); | |
| 488 | |
| 489 base::PostTaskAndReplyWithResult( | |
| 490 content::BrowserThread::GetBlockingPool(), | |
| 491 FROM_HERE, | |
| 492 base::Bind(&chromeos::version_loader::GetFirmware), | |
| 493 base::Bind(&AboutHandler::OnVersionReady, | |
| 494 weak_factory_.GetWeakPtr(), | |
| 495 callback_id)); | |
| 496 } | |
| 497 | |
| 498 void AboutHandler::OnVersionReady(std::string callback_id, | |
| 499 std::string version) { | |
| 500 ResolveJavascriptCallback( | |
| 501 base::StringValue(callback_id), base::StringValue(version)); | |
| 502 } | |
| 503 | |
| 504 void AboutHandler::HandleGetRegulatoryInfo(const base::ListValue* args) { | |
| 505 CHECK_EQ(1U, args->GetSize()); | |
| 506 std::string callback_id; | |
| 507 CHECK(args->GetString(0, &callback_id)); | |
| 508 | |
| 509 base::PostTaskAndReplyWithResult( | |
| 510 content::BrowserThread::GetBlockingPool(), | |
| 511 FROM_HERE, | |
| 512 base::Bind(&FindRegulatoryLabelDir), | |
| 513 base::Bind(&AboutHandler::OnRegulatoryLabelDirFound, | |
| 514 weak_factory_.GetWeakPtr(), | |
| 515 callback_id)); | |
| 516 } | |
| 517 | |
| 518 void AboutHandler::HandleGetCurrentChannel(const base::ListValue* args) { | |
| 519 CHECK_EQ(1U, args->GetSize()); | |
| 520 std::string callback_id; | |
| 521 CHECK(args->GetString(0, &callback_id)); | |
| 522 // First argument to GetChannel() is a flag that indicates whether | |
| 523 // current channel should be returned (if true) or target channel | |
| 524 // (otherwise). | |
| 525 version_updater_->GetChannel(true, | |
| 526 base::Bind(&AboutHandler::OnGetChannelReady, | |
| 527 weak_factory_.GetWeakPtr(), | |
| 528 callback_id)); | |
| 529 } | |
| 530 | |
| 531 void AboutHandler::HandleGetTargetChannel(const base::ListValue* args) { | |
| 532 CHECK_EQ(1U, args->GetSize()); | |
| 533 std::string callback_id; | |
| 534 CHECK(args->GetString(0, &callback_id)); | |
| 535 version_updater_->GetChannel(false, | |
| 536 base::Bind(&AboutHandler::OnGetChannelReady, | |
| 537 weak_factory_.GetWeakPtr(), | |
| 538 callback_id)); | |
| 539 } | |
| 540 | |
| 541 void AboutHandler::OnGetChannelReady(std::string callback_id, | |
| 542 const std::string& channel) { | |
| 543 ResolveJavascriptCallback( | |
| 544 base::StringValue(callback_id), base::StringValue(channel)); | |
| 545 } | |
| 546 | |
| 547 void AboutHandler::HandleRequestUpdate(const base::ListValue* args) { | |
| 548 RequestUpdate(); | |
| 597 } | 549 } |
| 598 | 550 |
| 599 #endif // defined(OS_CHROMEOS) | 551 #endif // defined(OS_CHROMEOS) |
| 600 | 552 |
| 601 void HelpHandler::RequestUpdate(const base::ListValue* args) { | 553 void AboutHandler::RequestUpdate() { |
| 602 VersionUpdater::PromoteCallback promote_callback; | |
| 603 version_updater_->CheckForUpdate( | 554 version_updater_->CheckForUpdate( |
| 604 base::Bind(&HelpHandler::SetUpdateStatus, base::Unretained(this)), | 555 base::Bind(&AboutHandler::SetUpdateStatus, base::Unretained(this)), |
| 605 #if defined(OS_MACOSX) | 556 #if defined(OS_MACOSX) |
| 606 base::Bind(&HelpHandler::SetPromotionState, base::Unretained(this))); | 557 base::Bind(&AboutHandler::SetPromotionState, base::Unretained(this))); |
| 607 #else | 558 #else |
| 608 VersionUpdater::PromoteCallback()); | 559 VersionUpdater::PromoteCallback()); |
| 609 #endif // OS_MACOSX | 560 #endif // OS_MACOSX |
| 610 } | 561 } |
| 611 | 562 |
| 612 void HelpHandler::SetUpdateStatus(VersionUpdater::Status status, | 563 void AboutHandler::SetUpdateStatus(VersionUpdater::Status status, |
| 613 int progress, const base::string16& message) { | 564 int progress, const base::string16& message) { |
| 614 // Only UPDATING state should have progress set. | 565 // Only UPDATING state should have progress set. |
| 615 DCHECK(status == VersionUpdater::UPDATING || progress == 0); | 566 DCHECK(status == VersionUpdater::UPDATING || progress == 0); |
| 616 | 567 |
| 617 std::string status_str; | 568 std::unique_ptr<base::DictionaryValue> event(new base::DictionaryValue); |
| 618 switch (status) { | 569 event->SetString("status", UpdateStatusToString(status)); |
| 619 case VersionUpdater::CHECKING: | 570 event->SetString("message", message); |
| 620 status_str = "checking"; | 571 event->SetInteger("progress", progress); |
| 621 break; | |
| 622 case VersionUpdater::UPDATING: | |
| 623 status_str = "updating"; | |
| 624 break; | |
| 625 case VersionUpdater::NEARLY_UPDATED: | |
| 626 status_str = "nearly_updated"; | |
| 627 break; | |
| 628 case VersionUpdater::UPDATED: | |
| 629 status_str = "updated"; | |
| 630 break; | |
| 631 case VersionUpdater::FAILED: | |
| 632 case VersionUpdater::FAILED_OFFLINE: | |
| 633 case VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED: | |
| 634 status_str = "failed"; | |
| 635 break; | |
| 636 case VersionUpdater::DISABLED: | |
| 637 status_str = "disabled"; | |
| 638 break; | |
| 639 case VersionUpdater::DISABLED_BY_ADMIN: | |
| 640 status_str = "disabled_by_admin"; | |
| 641 break; | |
| 642 } | |
| 643 | |
| 644 web_ui()->CallJavascriptFunction("help.HelpPage.setUpdateStatus", | |
| 645 base::StringValue(status_str), | |
| 646 base::StringValue(message)); | |
| 647 | |
| 648 if (status == VersionUpdater::UPDATING) { | |
| 649 web_ui()->CallJavascriptFunction("help.HelpPage.setProgress", | |
| 650 base::FundamentalValue(progress)); | |
| 651 } | |
| 652 | 572 |
| 653 #if defined(OS_CHROMEOS) | 573 #if defined(OS_CHROMEOS) |
| 654 if (status == VersionUpdater::FAILED_OFFLINE || | 574 if (status == VersionUpdater::FAILED_OFFLINE || |
| 655 status == VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED) { | 575 status == VersionUpdater::FAILED_CONNECTION_TYPE_DISALLOWED) { |
| 656 base::string16 types_msg = GetAllowedConnectionTypesMessage(); | 576 base::string16 types_msg = GetAllowedConnectionTypesMessage(); |
| 657 if (!types_msg.empty()) { | 577 if (!types_msg.empty()) |
| 658 web_ui()->CallJavascriptFunction( | 578 event->SetString("connectionTypes", types_msg); |
| 659 "help.HelpPage.setAndShowAllowedConnectionTypesMsg", | 579 else |
| 660 base::StringValue(types_msg)); | 580 event->Set("connectionTypes", base::Value::CreateNullValue()); |
| 661 } else { | |
| 662 web_ui()->CallJavascriptFunction( | |
| 663 "help.HelpPage.showAllowedConnectionTypesMsg", | |
| 664 base::FundamentalValue(false)); | |
| 665 } | |
| 666 } else { | 581 } else { |
| 667 web_ui()->CallJavascriptFunction( | 582 event->Set("connectionTypes", base::Value::CreateNullValue()); |
| 668 "help.HelpPage.showAllowedConnectionTypesMsg", | |
| 669 base::FundamentalValue(false)); | |
| 670 } | 583 } |
| 671 #endif // defined(OS_CHROMEOS) | 584 #endif // defined(OS_CHROMEOS) |
| 585 | |
| 586 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback", | |
| 587 base::StringValue("update-status-changed"), | |
| 588 *event); | |
| 672 } | 589 } |
| 673 | 590 |
| 674 #if defined(OS_MACOSX) | 591 #if defined(OS_MACOSX) |
| 675 void HelpHandler::SetPromotionState(VersionUpdater::PromotionState state) { | 592 void AboutHandler::SetPromotionState(VersionUpdater::PromotionState state) { |
| 676 std::string state_str; | 593 std::string state_str; |
| 677 switch (state) { | 594 switch (state) { |
| 678 case VersionUpdater::PROMOTE_HIDDEN: | 595 case VersionUpdater::PROMOTE_HIDDEN: |
| 679 state_str = "hidden"; | 596 state_str = "hidden"; |
| 680 break; | 597 break; |
| 681 case VersionUpdater::PROMOTE_ENABLED: | 598 case VersionUpdater::PROMOTE_ENABLED: |
| 682 state_str = "enabled"; | 599 state_str = "enabled"; |
| 683 break; | 600 break; |
| 684 case VersionUpdater::PROMOTE_DISABLED: | 601 case VersionUpdater::PROMOTE_DISABLED: |
| 685 state_str = "disabled"; | 602 state_str = "disabled"; |
| 686 break; | 603 break; |
| 687 } | 604 } |
| 688 | 605 |
| 689 web_ui()->CallJavascriptFunction("help.HelpPage.setPromotionState", | 606 web_ui()->CallJavascriptFunction("help.HelpPage.setPromotionState", |
| 690 base::StringValue(state_str)); | 607 base::StringValue(state_str)); |
| 691 } | 608 } |
| 692 #endif // defined(OS_MACOSX) | 609 #endif // defined(OS_MACOSX) |
| 693 | 610 |
| 694 #if defined(OS_CHROMEOS) | 611 #if defined(OS_CHROMEOS) |
| 695 void HelpHandler::OnOSVersion(const std::string& version) { | 612 void AboutHandler::OnRegulatoryLabelDirFound(std::string callback_id, |
| 696 web_ui()->CallJavascriptFunction("help.HelpPage.setOSVersion", | 613 const base::FilePath& path) { |
| 697 base::StringValue(version)); | 614 if (path.empty()) { |
| 698 } | 615 ResolveJavascriptCallback(base::StringValue(callback_id), |
|
tommycli
2016/05/10 20:45:40
Is this still considered a "success"? Or should it
dpapad
2016/05/10 22:03:02
Rejecting a promise is the equivalent of throwing
| |
| 699 | 616 *base::Value::CreateNullValue()); |
| 700 void HelpHandler::OnARCVersion(const std::string& firmware) { | |
| 701 web_ui()->CallJavascriptFunction("help.HelpPage.setARCVersion", | |
| 702 base::StringValue(firmware)); | |
| 703 } | |
| 704 | |
| 705 void HelpHandler::OnOSFirmware(const std::string& firmware) { | |
| 706 web_ui()->CallJavascriptFunction("help.HelpPage.setOSFirmware", | |
| 707 base::StringValue(firmware)); | |
| 708 } | |
| 709 | |
| 710 void HelpHandler::OnCurrentChannel(const std::string& channel) { | |
| 711 web_ui()->CallJavascriptFunction( | |
| 712 "help.HelpPage.updateCurrentChannel", base::StringValue(channel)); | |
| 713 } | |
| 714 | |
| 715 void HelpHandler::OnTargetChannel(const std::string& channel) { | |
| 716 web_ui()->CallJavascriptFunction( | |
| 717 "help.HelpPage.updateTargetChannel", base::StringValue(channel)); | |
| 718 } | |
| 719 | |
| 720 void HelpHandler::OnRegulatoryLabelDirFound(const base::FilePath& path) { | |
| 721 if (path.empty()) | |
| 722 return; | 617 return; |
| 618 } | |
| 723 | 619 |
| 724 base::PostTaskAndReplyWithResult( | 620 base::PostTaskAndReplyWithResult( |
| 725 content::BrowserThread::GetBlockingPool(), FROM_HERE, | 621 content::BrowserThread::GetBlockingPool(), FROM_HERE, |
| 726 base::Bind(&ReadRegulatoryLabelText, path), | 622 base::Bind(&ReadRegulatoryLabelText, path), |
| 727 base::Bind(&HelpHandler::OnRegulatoryLabelTextRead, | 623 base::Bind(&AboutHandler::OnRegulatoryLabelTextRead, |
| 728 weak_factory_.GetWeakPtr())); | 624 weak_factory_.GetWeakPtr(), |
| 729 | 625 callback_id, path)); |
| 730 // Send the image path to the WebUI. | |
| 731 OnRegulatoryLabelImageFound(path.AppendASCII(kRegulatoryLabelImageFilename)); | |
| 732 } | 626 } |
| 733 | 627 |
| 734 void HelpHandler::OnRegulatoryLabelImageFound(const base::FilePath& path) { | 628 void AboutHandler::OnRegulatoryLabelTextRead(std::string callback_id, |
| 629 const base::FilePath& path, | |
| 630 const std::string& text) { | |
| 631 std::unique_ptr<base::DictionaryValue> regulatory_info( | |
| 632 new base::DictionaryValue); | |
| 633 // Remove unnecessary whitespace. | |
| 634 regulatory_info->SetString("text", base::CollapseWhitespaceASCII(text, true)); | |
| 735 std::string url = std::string("chrome://") + chrome::kChromeOSAssetHost + | 635 std::string url = std::string("chrome://") + chrome::kChromeOSAssetHost + |
| 736 "/" + path.MaybeAsASCII(); | 636 "/" + path.MaybeAsASCII(); |
| 737 web_ui()->CallJavascriptFunction("help.HelpPage.setRegulatoryLabelPath", | 637 regulatory_info->SetString("url", url); |
| 738 base::StringValue(url)); | |
| 739 } | |
| 740 | 638 |
| 741 void HelpHandler::OnRegulatoryLabelTextRead(const std::string& text) { | 639 ResolveJavascriptCallback( |
| 742 // Remove unnecessary whitespace. | 640 base::StringValue(callback_id), *regulatory_info); |
| 743 web_ui()->CallJavascriptFunction( | |
| 744 "help.HelpPage.setRegulatoryLabelText", | |
| 745 base::StringValue(base::CollapseWhitespaceASCII(text, true))); | |
| 746 } | 641 } |
| 747 | 642 |
| 748 #endif // defined(OS_CHROMEOS) | 643 #endif // defined(OS_CHROMEOS) |
| 644 | |
| 645 } // namespace settings | |
| OLD | NEW |