• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/chromeos/login/base_screen_handler.h"
6 
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
10 #include "content/public/browser/web_ui.h"
11 #include "ui/base/l10n/l10n_util.h"
12 
13 namespace chromeos {
14 
LocalizedValuesBuilder(base::DictionaryValue * dict)15 LocalizedValuesBuilder::LocalizedValuesBuilder(base::DictionaryValue* dict)
16     : dict_(dict) {
17 }
18 
Add(const std::string & key,const std::string & message)19 void LocalizedValuesBuilder::Add(const std::string& key,
20                                  const std::string& message) {
21   dict_->SetString(key, message);
22 }
23 
Add(const std::string & key,const base::string16 & message)24 void LocalizedValuesBuilder::Add(const std::string& key,
25                                  const base::string16& message) {
26   dict_->SetString(key, message);
27 }
28 
Add(const std::string & key,int message_id)29 void LocalizedValuesBuilder::Add(const std::string& key, int message_id) {
30   dict_->SetString(key,
31                    l10n_util::GetStringUTF16(message_id));
32 }
33 
AddF(const std::string & key,int message_id,const base::string16 & a)34 void LocalizedValuesBuilder::AddF(const std::string& key,
35                                   int message_id,
36                                   const base::string16& a) {
37   dict_->SetString(key,
38                    l10n_util::GetStringFUTF16(message_id, a));
39 }
40 
AddF(const std::string & key,int message_id,const base::string16 & a,const base::string16 & b)41 void LocalizedValuesBuilder::AddF(const std::string& key,
42                                   int message_id,
43                                   const base::string16& a,
44                                   const base::string16& b) {
45   dict_->SetString(key,
46                    l10n_util::GetStringFUTF16(message_id, a, b));
47 }
48 
AddF(const std::string & key,int message_id,int message_id_a)49 void LocalizedValuesBuilder::AddF(const std::string& key,
50                                   int message_id,
51                                   int message_id_a) {
52     AddF(key, message_id, l10n_util::GetStringUTF16(message_id_a));
53 }
54 
AddF(const std::string & key,int message_id,int message_id_a,int message_id_b)55 void LocalizedValuesBuilder::AddF(const std::string& key,
56                                   int message_id,
57                                   int message_id_a,
58                                   int message_id_b) {
59     AddF(key, message_id,
60          l10n_util::GetStringUTF16(message_id_a),
61          l10n_util::GetStringUTF16(message_id_b));
62 }
63 
BaseScreenHandler()64 BaseScreenHandler::BaseScreenHandler()
65     : page_is_ready_(false) {
66 }
67 
BaseScreenHandler(const std::string & js_screen_path)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());
72 }
73 
~BaseScreenHandler()74 BaseScreenHandler::~BaseScreenHandler() {
75 }
76 
InitializeBase()77 void BaseScreenHandler::InitializeBase() {
78   page_is_ready_ = true;
79   Initialize();
80 }
81 
GetLocalizedStrings(base::DictionaryValue * dict)82 void BaseScreenHandler::GetLocalizedStrings(base::DictionaryValue* dict) {
83   scoped_ptr<LocalizedValuesBuilder> builder(new LocalizedValuesBuilder(dict));
84   DeclareLocalizedValues(builder.get());
85   GetAdditionalParameters(dict);
86 }
87 
GetAdditionalParameters(base::DictionaryValue * dict)88 void BaseScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) {
89 }
90 
CallJS(const std::string & method)91 void BaseScreenHandler::CallJS(const std::string& method) {
92   web_ui()->CallJavascriptFunction(FullMethodPath(method));
93 }
94 
ShowScreen(const char * screen_name,const base::DictionaryValue * data)95 void BaseScreenHandler::ShowScreen(const char* screen_name,
96                                    const base::DictionaryValue* data) {
97   if (!web_ui())
98     return;
99   base::DictionaryValue screen_params;
100   screen_params.SetString("id", screen_name);
101   if (data)
102     screen_params.SetWithoutPathExpansion("data", data->DeepCopy());
103   web_ui()->CallJavascriptFunction("cr.ui.Oobe.showScreen", screen_params);
104 }
105 
GetNativeWindow()106 gfx::NativeWindow BaseScreenHandler::GetNativeWindow() {
107   return LoginDisplayHostImpl::default_host()->GetNativeWindow();
108 }
109 
FullMethodPath(const std::string & method) const110 std::string BaseScreenHandler::FullMethodPath(const std::string& method) const {
111   DCHECK(!method.empty());
112   return js_screen_path_prefix_ + method;
113 }
114 
115 }  // namespace chromeos
116