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/chromeos/login/base_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 9 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 10 #include "components/login/localized_values_builder.h" |
10 #include "content/public/browser/web_ui.h" | 11 #include "content/public/browser/web_ui.h" |
11 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
12 | 13 |
13 namespace chromeos { | 14 namespace chromeos { |
14 | 15 |
15 namespace { | 16 namespace { |
16 const char kMethodContextChanged[] = "contextChanged"; | 17 const char kMethodContextChanged[] = "contextChanged"; |
17 } // namespace | 18 } // namespace |
18 | 19 |
19 LocalizedValuesBuilder::LocalizedValuesBuilder(base::DictionaryValue* dict) | |
20 : dict_(dict) { | |
21 } | |
22 | |
23 void LocalizedValuesBuilder::Add(const std::string& key, | |
24 const std::string& message) { | |
25 dict_->SetString(key, message); | |
26 } | |
27 | |
28 void LocalizedValuesBuilder::Add(const std::string& key, | |
29 const base::string16& message) { | |
30 dict_->SetString(key, message); | |
31 } | |
32 | |
33 void LocalizedValuesBuilder::Add(const std::string& key, int message_id) { | |
34 dict_->SetString(key, | |
35 l10n_util::GetStringUTF16(message_id)); | |
36 } | |
37 | |
38 void LocalizedValuesBuilder::AddF(const std::string& key, | |
39 int message_id, | |
40 const base::string16& a) { | |
41 dict_->SetString(key, | |
42 l10n_util::GetStringFUTF16(message_id, a)); | |
43 } | |
44 | |
45 void LocalizedValuesBuilder::AddF(const std::string& key, | |
46 int message_id, | |
47 const base::string16& a, | |
48 const base::string16& b) { | |
49 dict_->SetString(key, | |
50 l10n_util::GetStringFUTF16(message_id, a, b)); | |
51 } | |
52 | |
53 void LocalizedValuesBuilder::AddF(const std::string& key, | |
54 int message_id, | |
55 int message_id_a) { | |
56 AddF(key, message_id, l10n_util::GetStringUTF16(message_id_a)); | |
57 } | |
58 | |
59 void LocalizedValuesBuilder::AddF(const std::string& key, | |
60 int message_id, | |
61 int message_id_a, | |
62 int message_id_b) { | |
63 AddF(key, message_id, | |
64 l10n_util::GetStringUTF16(message_id_a), | |
65 l10n_util::GetStringUTF16(message_id_b)); | |
66 } | |
67 | |
68 BaseScreenHandler::BaseScreenHandler() | 20 BaseScreenHandler::BaseScreenHandler() |
69 : page_is_ready_(false), base_screen_(nullptr) { | 21 : page_is_ready_(false), base_screen_(nullptr) { |
70 } | 22 } |
71 | 23 |
72 BaseScreenHandler::BaseScreenHandler(const std::string& js_screen_path) | 24 BaseScreenHandler::BaseScreenHandler(const std::string& js_screen_path) |
73 : page_is_ready_(false), | 25 : page_is_ready_(false), |
74 base_screen_(nullptr), | 26 base_screen_(nullptr), |
75 js_screen_path_prefix_(js_screen_path + ".") { | 27 js_screen_path_prefix_(js_screen_path + ".") { |
76 CHECK(!js_screen_path.empty()); | 28 CHECK(!js_screen_path.empty()); |
77 } | 29 } |
78 | 30 |
79 BaseScreenHandler::~BaseScreenHandler() { | 31 BaseScreenHandler::~BaseScreenHandler() { |
80 } | 32 } |
81 | 33 |
82 void BaseScreenHandler::InitializeBase() { | 34 void BaseScreenHandler::InitializeBase() { |
83 page_is_ready_ = true; | 35 page_is_ready_ = true; |
84 Initialize(); | 36 Initialize(); |
85 if (!pending_context_changes_.empty()) { | 37 if (!pending_context_changes_.empty()) { |
86 CommitContextChanges(pending_context_changes_); | 38 CommitContextChanges(pending_context_changes_); |
87 pending_context_changes_.Clear(); | 39 pending_context_changes_.Clear(); |
88 } | 40 } |
89 } | 41 } |
90 | 42 |
91 void BaseScreenHandler::GetLocalizedStrings(base::DictionaryValue* dict) { | 43 void BaseScreenHandler::GetLocalizedStrings(base::DictionaryValue* dict) { |
92 scoped_ptr<LocalizedValuesBuilder> builder(new LocalizedValuesBuilder(dict)); | 44 auto builder = make_scoped_ptr(new ::login::LocalizedValuesBuilder(dict)); |
93 DeclareLocalizedValues(builder.get()); | 45 DeclareLocalizedValues(builder.get()); |
94 GetAdditionalParameters(dict); | 46 GetAdditionalParameters(dict); |
95 } | 47 } |
96 | 48 |
97 void BaseScreenHandler::RegisterMessages() { | 49 void BaseScreenHandler::RegisterMessages() { |
98 AddPrefixedCallback("userActed", | 50 AddPrefixedCallback("userActed", |
99 &BaseScreenHandler::HandleUserAction); | 51 &BaseScreenHandler::HandleUserAction); |
100 AddPrefixedCallback("contextChanged", | 52 AddPrefixedCallback("contextChanged", |
101 &BaseScreenHandler::HandleContextChanged); | 53 &BaseScreenHandler::HandleContextChanged); |
102 DeclareJSCallbacks(); | 54 DeclareJSCallbacks(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 base_screen_->OnUserAction(action_id); | 104 base_screen_->OnUserAction(action_id); |
153 } | 105 } |
154 | 106 |
155 void BaseScreenHandler::HandleContextChanged( | 107 void BaseScreenHandler::HandleContextChanged( |
156 const base::DictionaryValue* diff) { | 108 const base::DictionaryValue* diff) { |
157 if (diff && base_screen_) | 109 if (diff && base_screen_) |
158 base_screen_->OnContextChanged(*diff); | 110 base_screen_->OnContextChanged(*diff); |
159 } | 111 } |
160 | 112 |
161 } // namespace chromeos | 113 } // namespace chromeos |
OLD | NEW |