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.
5 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
10 #include "content/public/browser/web_ui.h"
11 #include "ui/base/l10n/l10n_util.h"
15 LocalizedValuesBuilder::LocalizedValuesBuilder(base::DictionaryValue
* dict
)
19 void LocalizedValuesBuilder::Add(const std::string
& key
,
20 const std::string
& message
) {
21 dict_
->SetString(key
, message
);
24 void LocalizedValuesBuilder::Add(const std::string
& key
,
25 const base::string16
& message
) {
26 dict_
->SetString(key
, message
);
29 void LocalizedValuesBuilder::Add(const std::string
& key
, int message_id
) {
31 l10n_util::GetStringUTF16(message_id
));
34 void LocalizedValuesBuilder::AddF(const std::string
& key
,
36 const base::string16
& a
) {
38 l10n_util::GetStringFUTF16(message_id
, a
));
41 void LocalizedValuesBuilder::AddF(const std::string
& key
,
43 const base::string16
& a
,
44 const base::string16
& b
) {
46 l10n_util::GetStringFUTF16(message_id
, a
, b
));
49 void LocalizedValuesBuilder::AddF(const std::string
& key
,
52 AddF(key
, message_id
, l10n_util::GetStringUTF16(message_id_a
));
55 void LocalizedValuesBuilder::AddF(const std::string
& key
,
60 l10n_util::GetStringUTF16(message_id_a
),
61 l10n_util::GetStringUTF16(message_id_b
));
64 BaseScreenHandler::BaseScreenHandler()
65 : page_is_ready_(false) {
68 BaseScreenHandler::BaseScreenHandler(const std::string
& js_screen_path
)
69 : page_is_ready_(false),
70 js_screen_path_prefix_(js_screen_path
+ ".") {
71 CHECK(!js_screen_path
.empty());
74 BaseScreenHandler::~BaseScreenHandler() {
77 void BaseScreenHandler::InitializeBase() {
78 page_is_ready_
= true;
82 void BaseScreenHandler::GetLocalizedStrings(base::DictionaryValue
* dict
) {
83 scoped_ptr
<LocalizedValuesBuilder
> builder(new LocalizedValuesBuilder(dict
));
84 DeclareLocalizedValues(builder
.get());
85 GetAdditionalParameters(dict
);
88 void BaseScreenHandler::GetAdditionalParameters(base::DictionaryValue
* dict
) {
91 void BaseScreenHandler::CallJS(const std::string
& method
) {
92 web_ui()->CallJavascriptFunction(FullMethodPath(method
));
95 void BaseScreenHandler::ShowScreen(const char* screen_name
,
96 const base::DictionaryValue
* data
) {
99 base::DictionaryValue screen_params
;
100 screen_params
.SetString("id", screen_name
);
102 screen_params
.SetWithoutPathExpansion("data", data
->DeepCopy());
103 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showScreen", screen_params
);
106 gfx::NativeWindow
BaseScreenHandler::GetNativeWindow() {
107 return LoginDisplayHostImpl::default_host()->GetNativeWindow();
110 std::string
BaseScreenHandler::FullMethodPath(const std::string
& method
) const {
111 DCHECK(!method
.empty());
112 return js_screen_path_prefix_
+ method
;
115 } // namespace chromeos