Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/options2/chromeos/about_page_handler2.h" | 5 #include "chrome/browser/ui/webui/about_page/about_page_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 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/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 20 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
| 21 #include "chrome/browser/chromeos/dbus/update_engine_client.h" | 21 #include "chrome/browser/chromeos/dbus/update_engine_client.h" |
| 22 #include "chrome/browser/chromeos/login/user_manager.h" | 22 #include "chrome/browser/chromeos/login/user_manager.h" |
| 23 #include "chrome/browser/chromeos/login/wizard_controller.h" | 23 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 24 #include "chrome/browser/google/google_util.h" | 24 #include "chrome/browser/google/google_util.h" |
| 25 #include "chrome/common/chrome_version_info.h" | 25 #include "chrome/common/chrome_version_info.h" |
| 26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 27 #include "content/browser/webui/web_ui.h" | |
| 27 #include "content/public/common/content_client.h" | 28 #include "content/public/common/content_client.h" |
| 28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 29 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "grit/locale_settings.h" | 32 #include "grit/locale_settings.h" |
| 32 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
| 35 #include "v8/include/v8.h" | 36 #include "v8/include/v8.h" |
| 36 #include "webkit/glue/user_agent.h" | 37 #include "webkit/glue/user_agent.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 52 | 53 |
| 53 // Returns a substring [start, end) from |text|. | 54 // Returns a substring [start, end) from |text|. |
| 54 std::string StringSubRange(const std::string& text, size_t start, | 55 std::string StringSubRange(const std::string& text, size_t start, |
| 55 size_t end) { | 56 size_t end) { |
| 56 DCHECK(end > start); | 57 DCHECK(end > start); |
| 57 return text.substr(start, end - start); | 58 return text.substr(start, end - start); |
| 58 } | 59 } |
| 59 | 60 |
| 60 } // namespace | 61 } // namespace |
| 61 | 62 |
| 62 namespace chromeos { | 63 using chromeos::DBusThreadManager; |
| 63 namespace options2 { | 64 using chromeos::UpdateEngineClient; |
| 65 using chromeos::UserManager; | |
| 66 using chromeos::VersionLoader; | |
| 67 using chromeos::WizardController; | |
| 64 | 68 |
| 65 class AboutPageHandler::UpdateObserver | 69 class AboutPageHandler::UpdateObserver |
| 66 : public UpdateEngineClient::Observer { | 70 : public UpdateEngineClient::Observer { |
| 67 public: | 71 public: |
| 68 explicit UpdateObserver(AboutPageHandler* handler) : page_handler_(handler) {} | 72 explicit UpdateObserver(AboutPageHandler* handler) : page_handler_(handler) {} |
| 69 virtual ~UpdateObserver() {} | 73 virtual ~UpdateObserver() {} |
| 70 | 74 |
| 71 AboutPageHandler* page_handler() const { return page_handler_; } | 75 AboutPageHandler* page_handler() const { return page_handler_; } |
| 72 | 76 |
| 73 private: | 77 private: |
| 74 virtual void UpdateStatusChanged( | 78 virtual void UpdateStatusChanged( |
| 75 const UpdateEngineClient::Status& status) OVERRIDE { | 79 const UpdateEngineClient::Status& status) OVERRIDE { |
| 76 page_handler_->UpdateStatus(status); | 80 page_handler_->UpdateStatus(status); |
| 77 } | 81 } |
| 78 | 82 |
| 79 AboutPageHandler* page_handler_; | 83 AboutPageHandler* page_handler_; |
| 80 | 84 |
| 81 DISALLOW_COPY_AND_ASSIGN(UpdateObserver); | 85 DISALLOW_COPY_AND_ASSIGN(UpdateObserver); |
| 82 }; | 86 }; |
| 83 | 87 |
| 84 AboutPageHandler::AboutPageHandler() | 88 AboutPageHandler::AboutPageHandler() |
| 85 : progress_(-1), | 89 : progress_(-1), |
| 86 sticky_(false), | 90 sticky_(false), |
| 87 started_(false) | 91 started_(false) { |
| 88 {} | 92 } |
| 89 | 93 |
| 90 AboutPageHandler::~AboutPageHandler() { | 94 AboutPageHandler::~AboutPageHandler() { |
| 91 if (update_observer_.get()) { | 95 if (update_observer_.get()) { |
| 92 DBusThreadManager::Get()->GetUpdateEngineClient()-> | 96 DBusThreadManager::Get()->GetUpdateEngineClient()-> |
| 93 RemoveObserver(update_observer_.get()); | 97 RemoveObserver(update_observer_.get()); |
| 94 } | 98 } |
| 95 } | 99 } |
| 96 | 100 |
| 97 void AboutPageHandler::GetLocalizedValues(DictionaryValue* localized_strings) { | 101 void AboutPageHandler::GetLocalizedValues(DictionaryValue* localized_strings) { |
| 98 DCHECK(localized_strings); | 102 DCHECK(localized_strings); |
| 99 | 103 |
| 100 static OptionsStringResource resources[] = { | 104 struct L10nResources { |
| 105 const char* name; | |
| 106 int ids; | |
| 107 }; | |
| 108 | |
| 109 static L10nResources resources[] = { | |
| 110 { "pageTitle", IDS_ABOUT_TAB_TITLE }, | |
|
Dan Beam
2012/01/09 23:05:51
Do you think it would be worth alpha sorting these
Evan Stade
2012/01/09 23:31:16
no I prefer to keep the related ones together, e.g
Dan Beam
2012/01/09 23:53:14
If it's in preference order or an order I'm not aw
| |
| 101 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, | 111 { "firmware", IDS_ABOUT_PAGE_FIRMWARE }, |
| 102 { "product", IDS_PRODUCT_OS_NAME }, | 112 { "product", IDS_PRODUCT_OS_NAME }, |
| 103 { "os", IDS_PRODUCT_OS_NAME }, | 113 { "os", IDS_PRODUCT_OS_NAME }, |
| 104 { "platform", IDS_PLATFORM_LABEL }, | 114 { "platform", IDS_PLATFORM_LABEL }, |
| 105 { "loading", IDS_ABOUT_PAGE_LOADING }, | 115 { "loading", IDS_ABOUT_PAGE_LOADING }, |
| 106 { "check_now", IDS_ABOUT_PAGE_CHECK_NOW }, | 116 { "check_now", IDS_ABOUT_PAGE_CHECK_NOW }, |
| 107 { "update_status", IDS_UPGRADE_CHECK_STARTED }, | 117 { "update_status", IDS_UPGRADE_CHECK_STARTED }, |
| 108 { "restart_now", IDS_RELAUNCH_AND_UPDATE }, | 118 { "restart_now", IDS_RELAUNCH_AND_UPDATE }, |
| 109 { "browser", IDS_PRODUCT_NAME }, | 119 { "browser", IDS_PRODUCT_NAME }, |
| 110 { "more_info", IDS_ABOUT_PAGE_MORE_INFO }, | 120 { "more_info", IDS_ABOUT_PAGE_MORE_INFO }, |
| 111 { "copyright", IDS_ABOUT_VERSION_COPYRIGHT }, | 121 { "copyright", IDS_ABOUT_VERSION_COPYRIGHT }, |
| 112 { "channel", IDS_ABOUT_PAGE_CHANNEL }, | 122 { "channel", IDS_ABOUT_PAGE_CHANNEL }, |
| 113 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, | 123 { "stable", IDS_ABOUT_PAGE_CHANNEL_STABLE }, |
| 114 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, | 124 { "beta", IDS_ABOUT_PAGE_CHANNEL_BETA }, |
| 115 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, | 125 { "dev", IDS_ABOUT_PAGE_CHANNEL_DEVELOPMENT }, |
| 116 { "canary", IDS_ABOUT_PAGE_CHANNEL_CANARY }, | 126 { "canary", IDS_ABOUT_PAGE_CHANNEL_CANARY }, |
| 117 { "channel_warning_header", IDS_ABOUT_PAGE_CHANNEL_WARNING_HEADER }, | 127 { "channel_warning_header", IDS_ABOUT_PAGE_CHANNEL_WARNING_HEADER }, |
| 118 { "channel_warning_text", IDS_ABOUT_PAGE_CHANNEL_WARNING_TEXT }, | 128 { "channel_warning_text", IDS_ABOUT_PAGE_CHANNEL_WARNING_TEXT }, |
| 119 { "user_agent", IDS_ABOUT_VERSION_USER_AGENT }, | 129 { "user_agent", IDS_ABOUT_VERSION_USER_AGENT }, |
| 120 { "command_line", IDS_ABOUT_VERSION_COMMAND_LINE }, | 130 { "command_line", IDS_ABOUT_VERSION_COMMAND_LINE }, |
| 121 }; | 131 }; |
| 122 | 132 |
| 123 RegisterStrings(localized_strings, resources, arraysize(resources)); | 133 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resources); ++i) { |
|
Dan Beam
2012/01/09 23:05:51
^ didn't know about this macro, cool!
Evan Stade
2012/01/09 23:31:16
fyi, better to use arraysize() where possible
| |
| 124 RegisterTitle(localized_strings, "aboutPage", IDS_ABOUT_TAB_TITLE); | 134 localized_strings->SetString(resources[i].name, |
| 135 l10n_util::GetStringUTF16(resources[i].ids)); | |
|
Dan Beam
2012/01/09 23:05:51
Should we both DCHECK()ing that the key doesn't ex
Evan Stade
2012/01/09 23:31:16
I don't think so, it seems a little overly cautiou
Dan Beam
2012/01/09 23:53:14
But what happens when you start to merge dictionar
Evan Stade
2012/01/10 00:04:50
that's indeed possible, if we wanted to fold about
| |
| 136 } | |
| 125 | 137 |
| 126 // browser version | 138 // browser version |
| 127 | 139 |
| 128 chrome::VersionInfo version_info; | 140 chrome::VersionInfo version_info; |
| 129 DCHECK(version_info.is_valid()); | 141 DCHECK(version_info.is_valid()); |
| 130 | 142 |
| 131 std::string browser_version = version_info.Version(); | 143 std::string browser_version = version_info.Version(); |
| 132 std::string version_modifier = | 144 std::string version_modifier = |
| 133 chrome::VersionInfo::GetVersionStringModifier(); | 145 chrome::VersionInfo::GetVersionStringModifier(); |
| 134 if (!version_modifier.empty()) | 146 if (!version_modifier.empty()) |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 if (DBusThreadManager::Get()->GetUpdateEngineClient() | 421 if (DBusThreadManager::Get()->GetUpdateEngineClient() |
| 410 ->HasObserver(observer)) { | 422 ->HasObserver(observer)) { |
| 411 // If UpdateEngineClient still has the observer, then the page handler | 423 // If UpdateEngineClient still has the observer, then the page handler |
| 412 // is valid. | 424 // is valid. |
| 413 AboutPageHandler* handler = observer->page_handler(); | 425 AboutPageHandler* handler = observer->page_handler(); |
| 414 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); | 426 scoped_ptr<Value> channel_string(Value::CreateStringValue(channel)); |
| 415 handler->web_ui()->CallJavascriptFunction( | 427 handler->web_ui()->CallJavascriptFunction( |
| 416 "AboutPage.updateSelectedOptionCallback", *channel_string); | 428 "AboutPage.updateSelectedOptionCallback", *channel_string); |
| 417 } | 429 } |
| 418 } | 430 } |
| 419 | |
| 420 } // namespace options2 | |
| 421 } // namespace chromeos | |
| OLD | NEW |