| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "ash/system/devicetype_utils.h" | 11 #include "ash/system/devicetype_utils.h" |
| 12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 18 #include "base/i18n/message_formatter.h" | 18 #include "base/i18n/message_formatter.h" |
| 19 #include "base/location.h" | 19 #include "base/location.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
| 22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/task_scheduler/post_task.h" | 24 #include "base/task_scheduler/post_task.h" |
| 25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 26 #include "base/values.h" | 26 #include "base/values.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 29 #include "chrome/browser/chrome_notification_types.h" | |
| 30 #include "chrome/browser/lifetime/application_lifetime.h" | 29 #include "chrome/browser/lifetime/application_lifetime.h" |
| 31 #include "chrome/browser/obsolete_system/obsolete_system.h" | 30 #include "chrome/browser/obsolete_system/obsolete_system.h" |
| 32 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/browser_commands.h" | 32 #include "chrome/browser/ui/browser_commands.h" |
| 34 #include "chrome/browser/ui/browser_finder.h" | 33 #include "chrome/browser/ui/browser_finder.h" |
| 35 #include "chrome/browser/ui/chrome_pages.h" | 34 #include "chrome/browser/ui/chrome_pages.h" |
| 35 #include "chrome/browser/upgrade_detector.h" |
| 36 #include "chrome/common/channel_info.h" | 36 #include "chrome/common/channel_info.h" |
| 37 #include "chrome/common/chrome_content_client.h" | 37 #include "chrome/common/chrome_content_client.h" |
| 38 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
| 40 #include "chrome/grit/chromium_strings.h" | 40 #include "chrome/grit/chromium_strings.h" |
| 41 #include "chrome/grit/generated_resources.h" | 41 #include "chrome/grit/generated_resources.h" |
| 42 #include "components/google/core/browser/google_util.h" | 42 #include "components/google/core/browser/google_util.h" |
| 43 #include "components/policy/core/common/policy_namespace.h" | 43 #include "components/policy/core/common/policy_namespace.h" |
| 44 #include "components/policy/policy_constants.h" | 44 #include "components/policy/policy_constants.h" |
| 45 #include "components/strings/grit/components_chromium_strings.h" | 45 #include "components/strings/grit/components_chromium_strings.h" |
| 46 #include "components/strings/grit/components_strings.h" | 46 #include "components/strings/grit/components_strings.h" |
| 47 #include "components/version_info/version_info.h" | 47 #include "components/version_info/version_info.h" |
| 48 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
| 49 #include "content/public/browser/notification_service.h" | |
| 50 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| 51 #include "content/public/browser/web_ui.h" | 50 #include "content/public/browser/web_ui.h" |
| 52 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "v8/include/v8-version-string.h" | 52 #include "v8/include/v8-version-string.h" |
| 54 | 53 |
| 55 #if defined(OS_CHROMEOS) | 54 #if defined(OS_CHROMEOS) |
| 56 #include "base/files/file_util_proxy.h" | 55 #include "base/files/file_util_proxy.h" |
| 57 #include "base/i18n/time_formatting.h" | 56 #include "base/i18n/time_formatting.h" |
| 58 #include "base/sys_info.h" | 57 #include "base/sys_info.h" |
| 59 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 58 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 if (base::ReadFileToString(text_path, &contents)) | 199 if (base::ReadFileToString(text_path, &contents)) |
| 201 return contents; | 200 return contents; |
| 202 return std::string(); | 201 return std::string(); |
| 203 } | 202 } |
| 204 #endif // defined(OS_CHROMEOS) | 203 #endif // defined(OS_CHROMEOS) |
| 205 | 204 |
| 206 } // namespace | 205 } // namespace |
| 207 | 206 |
| 208 HelpHandler::HelpHandler() | 207 HelpHandler::HelpHandler() |
| 209 : policy_registrar_( | 208 : policy_registrar_( |
| 210 g_browser_process->policy_service(), | 209 g_browser_process->policy_service(), |
| 211 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())), | 210 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())), |
| 211 apply_changes_from_upgrade_observer_(false), |
| 212 weak_factory_(this) { | 212 weak_factory_(this) { |
| 213 UpgradeDetector::GetInstance()->AddObserver(this); |
| 213 } | 214 } |
| 214 | 215 |
| 215 HelpHandler::~HelpHandler() { | 216 HelpHandler::~HelpHandler() { |
| 217 UpgradeDetector::GetInstance()->RemoveObserver(this); |
| 216 } | 218 } |
| 217 | 219 |
| 218 void HelpHandler::GetLocalizedValues(base::DictionaryValue* localized_strings) { | 220 void HelpHandler::GetLocalizedValues(base::DictionaryValue* localized_strings) { |
| 219 struct L10nResources { | 221 struct L10nResources { |
| 220 const char* name; | 222 const char* name; |
| 221 int ids; | 223 int ids; |
| 222 }; | 224 }; |
| 223 | 225 |
| 224 static L10nResources resources[] = { | 226 static L10nResources resources[] = { |
| 225 {"aboutTitle", IDS_ABOUT_TITLE}, | 227 {"aboutTitle", IDS_ABOUT_TITLE}, |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 369 |
| 368 localized_strings->SetString("userAgentInfo", GetUserAgent()); | 370 localized_strings->SetString("userAgentInfo", GetUserAgent()); |
| 369 | 371 |
| 370 base::CommandLine::StringType command_line = | 372 base::CommandLine::StringType command_line = |
| 371 base::CommandLine::ForCurrentProcess()->GetCommandLineString(); | 373 base::CommandLine::ForCurrentProcess()->GetCommandLineString(); |
| 372 localized_strings->SetString("commandLineInfo", command_line); | 374 localized_strings->SetString("commandLineInfo", command_line); |
| 373 } | 375 } |
| 374 | 376 |
| 375 void HelpHandler::RegisterMessages() { | 377 void HelpHandler::RegisterMessages() { |
| 376 version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents())); | 378 version_updater_.reset(VersionUpdater::Create(web_ui()->GetWebContents())); |
| 377 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 379 apply_changes_from_upgrade_observer_ = true; |
| 378 content::NotificationService::AllSources()); | |
| 379 policy_registrar_.Observe( | 380 policy_registrar_.Observe( |
| 380 policy::key::kDeviceAutoUpdateDisabled, | 381 policy::key::kDeviceAutoUpdateDisabled, |
| 381 base::Bind(&HelpHandler::OnDeviceAutoUpdatePolicyChanged, | 382 base::Bind(&HelpHandler::OnDeviceAutoUpdatePolicyChanged, |
| 382 base::Unretained(this))); | 383 base::Unretained(this))); |
| 383 | 384 |
| 384 web_ui()->RegisterMessageCallback("onPageLoaded", | 385 web_ui()->RegisterMessageCallback("onPageLoaded", |
| 385 base::Bind(&HelpHandler::OnPageLoaded, base::Unretained(this))); | 386 base::Bind(&HelpHandler::OnPageLoaded, base::Unretained(this))); |
| 386 web_ui()->RegisterMessageCallback("relaunchNow", | 387 web_ui()->RegisterMessageCallback("relaunchNow", |
| 387 base::Bind(&HelpHandler::RelaunchNow, base::Unretained(this))); | 388 base::Bind(&HelpHandler::RelaunchNow, base::Unretained(this))); |
| 388 web_ui()->RegisterMessageCallback("openFeedbackDialog", | 389 web_ui()->RegisterMessageCallback("openFeedbackDialog", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 402 base::Bind(&HelpHandler::PromoteUpdater, base::Unretained(this))); | 403 base::Bind(&HelpHandler::PromoteUpdater, base::Unretained(this))); |
| 403 #endif | 404 #endif |
| 404 | 405 |
| 405 #if defined(OS_CHROMEOS) | 406 #if defined(OS_CHROMEOS) |
| 406 // Handler for the product label image, which will be shown if available. | 407 // Handler for the product label image, which will be shown if available. |
| 407 content::URLDataSource::Add(Profile::FromWebUI(web_ui()), | 408 content::URLDataSource::Add(Profile::FromWebUI(web_ui()), |
| 408 new chromeos::ImageSource()); | 409 new chromeos::ImageSource()); |
| 409 #endif | 410 #endif |
| 410 } | 411 } |
| 411 | 412 |
| 412 void HelpHandler::Observe(int type, const content::NotificationSource& source, | 413 void HelpHandler::OnUpgradeRecommended() { |
| 413 const content::NotificationDetails& details) { | 414 if (apply_changes_from_upgrade_observer_) { |
| 414 DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type); | 415 // A version update is installed and ready to go. Refresh the UI so the |
| 415 | 416 // correct state will be shown. |
| 416 // A version update is installed and ready to go. Refresh the UI so the | 417 RequestUpdate(nullptr); |
| 417 // correct state will be shown. | 418 } |
| 418 RequestUpdate(nullptr); | |
| 419 } | 419 } |
| 420 | 420 |
| 421 // static | 421 // static |
| 422 base::string16 HelpHandler::BuildBrowserVersionString() { | 422 base::string16 HelpHandler::BuildBrowserVersionString() { |
| 423 std::string version = version_info::GetVersionNumber(); | 423 std::string version = version_info::GetVersionNumber(); |
| 424 | 424 |
| 425 std::string modifier = chrome::GetChannelString(); | 425 std::string modifier = chrome::GetChannelString(); |
| 426 if (!modifier.empty()) | 426 if (!modifier.empty()) |
| 427 version += " " + modifier; | 427 version += " " + modifier; |
| 428 | 428 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 base::Value("device_supported"), | 757 base::Value("device_supported"), |
| 758 base::Value("")); | 758 base::Value("")); |
| 759 } else { | 759 } else { |
| 760 web_ui()->CallJavascriptFunctionUnsafe( | 760 web_ui()->CallJavascriptFunctionUnsafe( |
| 761 "help.HelpPage.updateEolMessage", base::Value("device_endoflife"), | 761 "help.HelpPage.updateEolMessage", base::Value("device_endoflife"), |
| 762 base::Value(l10n_util::GetStringUTF16(IDS_ABOUT_PAGE_EOL_EOL))); | 762 base::Value(l10n_util::GetStringUTF16(IDS_ABOUT_PAGE_EOL_EOL))); |
| 763 } | 763 } |
| 764 } | 764 } |
| 765 | 765 |
| 766 #endif // defined(OS_CHROMEOS) | 766 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |