| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/help/help_handler.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" |
| 12 #include "base/string16.h" |
| 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" |
| 15 #include "chrome/browser/google/google_util.h" |
| 16 #include "chrome/common/chrome_version_info.h" |
| 17 #include "chrome/common/url_constants.h" |
| 18 #include "content/public/browser/web_ui.h" |
| 19 #include "grit/chromium_strings.h" |
| 20 #include "grit/generated_resources.h" |
| 21 #include "grit/google_chrome_strings.h" |
| 22 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" |
| 24 |
| 25 namespace { |
| 26 |
| 27 // Returns the browser version as a string. |
| 28 string16 BuildBrowserVersionString() { |
| 29 chrome::VersionInfo version_info; |
| 30 DCHECK(version_info.is_valid()); |
| 31 |
| 32 std::string browser_version = version_info.Version(); |
| 33 std::string version_modifier = |
| 34 chrome::VersionInfo::GetVersionStringModifier(); |
| 35 if (!version_modifier.empty()) |
| 36 browser_version += " " + version_modifier; |
| 37 |
| 38 #if !defined(GOOGLE_CHROME_BUILD) |
| 39 browser_version += " ("; |
| 40 browser_version += version_info.LastChange(); |
| 41 browser_version += ")"; |
| 42 #endif |
| 43 |
| 44 return UTF8ToUTF16(browser_version); |
| 45 } |
| 46 |
| 47 } // namespace |
| 48 |
| 49 HelpHandler::HelpHandler() |
| 50 : version_updater_(VersionUpdater::Create()) { |
| 51 } |
| 52 |
| 53 HelpHandler::~HelpHandler() { |
| 54 } |
| 55 |
| 56 void HelpHandler::GetLocalizedValues(DictionaryValue* localized_strings) { |
| 57 DCHECK(localized_strings); |
| 58 DCHECK(localized_strings->empty()); |
| 59 |
| 60 struct L10nResources { |
| 61 const char* name; |
| 62 int ids; |
| 63 }; |
| 64 |
| 65 static L10nResources resources[] = { |
| 66 { "helpTitle", IDS_HELP_TITLE }, |
| 67 { "aboutProductTitle", IDS_ABOUT_CHROME_TITLE }, |
| 68 { "aboutProductDescription", IDS_ABOUT_PRODUCT_DESCRIPTION }, |
| 69 { "relaunch", IDS_RELAUNCH_BUTTON }, |
| 70 { "productName", IDS_PRODUCT_NAME }, |
| 71 { "productCopyright", IDS_ABOUT_VERSION_COPYRIGHT }, |
| 72 { "updateCheckStarted", IDS_UPGRADE_CHECK_STARTED }, |
| 73 { "upToDate", IDS_UPGRADE_UP_TO_DATE }, |
| 74 { "updating", IDS_UPGRADE_UPDATING }, |
| 75 { "updateAlmostDone", IDS_UPGRADE_SUCCESSFUL_RELAUNCH }, |
| 76 // TODO(jhawkins): Verify the following UI is only in the official build. |
| 77 #if defined(OFFICIAL_BUILD) |
| 78 { "getHelpWithChrome", IDS_GET_HELP_USING_CHROME }, |
| 79 { "reportAProblem", IDS_REPORT_A_PROBLEM }, |
| 80 #endif |
| 81 }; |
| 82 |
| 83 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { |
| 84 localized_strings->SetString(resources[i].name, |
| 85 l10n_util::GetStringUTF16(resources[i].ids)); |
| 86 } |
| 87 |
| 88 localized_strings->SetString( |
| 89 "browserVersion", |
| 90 l10n_util::GetStringFUTF16(IDS_ABOUT_PRODUCT_VERSION, |
| 91 BuildBrowserVersionString())); |
| 92 |
| 93 string16 license = l10n_util::GetStringFUTF16( |
| 94 IDS_ABOUT_VERSION_LICENSE, |
| 95 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( |
| 96 chrome::kChromiumProjectURL)), |
| 97 ASCIIToUTF16(chrome::kChromeUICreditsURL)); |
| 98 localized_strings->SetString("productLicense", license); |
| 99 |
| 100 string16 tos = l10n_util::GetStringFUTF16( |
| 101 IDS_ABOUT_TERMS_OF_SERVICE, UTF8ToUTF16(chrome::kChromeUITermsURL)); |
| 102 localized_strings->SetString("productTOS", tos); |
| 103 } |
| 104 |
| 105 void HelpHandler::RegisterMessages() { |
| 106 web_ui()->RegisterMessageCallback("checkForUpdate", |
| 107 base::Bind(&HelpHandler::CheckForUpdate, base::Unretained(this))); |
| 108 web_ui()->RegisterMessageCallback("relaunchNow", |
| 109 base::Bind(&HelpHandler::RelaunchNow, base::Unretained(this))); |
| 110 } |
| 111 |
| 112 void HelpHandler::CheckForUpdate(const ListValue* args) { |
| 113 version_updater_->CheckForUpdate( |
| 114 base::Bind(&HelpHandler::UpdateStatus, base::Unretained(this))); |
| 115 } |
| 116 |
| 117 void HelpHandler::RelaunchNow(const ListValue* args) { |
| 118 version_updater_->RelaunchBrowser(); |
| 119 } |
| 120 |
| 121 void HelpHandler::UpdateStatus(VersionUpdater::Status status, int progress) { |
| 122 // Only UPDATING state should have progress set. |
| 123 DCHECK(status == VersionUpdater::UPDATING || progress == 0); |
| 124 |
| 125 std::string status_str; |
| 126 switch (status) { |
| 127 case VersionUpdater::CHECKING: |
| 128 status_str = "checking"; |
| 129 break; |
| 130 case VersionUpdater::UPDATING: |
| 131 status_str = "updating"; |
| 132 break; |
| 133 case VersionUpdater::NEARLY_UPDATED: |
| 134 status_str = "nearly_updated"; |
| 135 break; |
| 136 case VersionUpdater::UPDATED: |
| 137 status_str = "updated"; |
| 138 break; |
| 139 } |
| 140 |
| 141 scoped_ptr<Value> status_value(Value::CreateStringValue(status_str)); |
| 142 web_ui()->CallJavascriptFunction("HelpPage.setUpdateStatus", *status_value); |
| 143 |
| 144 if (status == VersionUpdater::UPDATING) { |
| 145 scoped_ptr<Value> progress_value(Value::CreateIntegerValue(progress)); |
| 146 web_ui()->CallJavascriptFunction("HelpPage.setProgress", *progress_value); |
| 147 } |
| 148 } |
| OLD | NEW |