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/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 15 LocalizedValuesBuilder::LocalizedValuesBuilder(base::DictionaryValue* dict) 16 : dict_(dict) { 17 } 18 19 void LocalizedValuesBuilder::Add(const std::string& key, 20 const std::string& message) { 21 dict_->SetString(key, message); 22 } 23 24 void LocalizedValuesBuilder::Add(const std::string& key, 25 const base::string16& message) { 26 dict_->SetString(key, message); 27 } 28 29 void LocalizedValuesBuilder::Add(const std::string& key, int message_id) { 30 dict_->SetString(key, 31 l10n_util::GetStringUTF16(message_id)); 32 } 33 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 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 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 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 64 BaseScreenHandler::BaseScreenHandler() 65 : page_is_ready_(false) { 66 } 67 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 74 BaseScreenHandler::~BaseScreenHandler() { 75 } 76 77 void BaseScreenHandler::InitializeBase() { 78 page_is_ready_ = true; 79 Initialize(); 80 } 81 82 void BaseScreenHandler::GetLocalizedStrings(base::DictionaryValue* dict) { 83 scoped_ptr<LocalizedValuesBuilder> builder(new LocalizedValuesBuilder(dict)); 84 DeclareLocalizedValues(builder.get()); 85 GetAdditionalParameters(dict); 86 } 87 88 void BaseScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) { 89 } 90 91 void BaseScreenHandler::CallJS(const std::string& method) { 92 web_ui()->CallJavascriptFunction(FullMethodPath(method)); 93 } 94 95 void BaseScreenHandler::ShowScreen(const char* screen_name, 96 const base::DictionaryValue* data) { 97 if (!web_ui()) 98 return; 99 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 106 gfx::NativeWindow BaseScreenHandler::GetNativeWindow() { 107 return LoginDisplayHostImpl::default_host()->GetNativeWindow(); 108 } 109 110 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