Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / base_screen_handler.cc
blobc0d0c7530341062eef427797c0fdc74be42c39d3
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/ui/login_display_host_impl.h"
10 #include "components/login/localized_values_builder.h"
11 #include "content/public/browser/web_ui.h"
12 #include "ui/base/l10n/l10n_util.h"
14 namespace chromeos {
16 namespace {
17 const char kMethodContextChanged[] = "contextChanged";
18 } // namespace
20 BaseScreenHandler::BaseScreenHandler()
21 : page_is_ready_(false), base_screen_(nullptr) {
24 BaseScreenHandler::BaseScreenHandler(const std::string& js_screen_path)
25 : page_is_ready_(false),
26 base_screen_(nullptr),
27 js_screen_path_prefix_(js_screen_path + ".") {
28 CHECK(!js_screen_path.empty());
31 BaseScreenHandler::~BaseScreenHandler() {
34 void BaseScreenHandler::InitializeBase() {
35 page_is_ready_ = true;
36 Initialize();
37 if (!pending_context_changes_.empty()) {
38 CommitContextChanges(pending_context_changes_);
39 pending_context_changes_.Clear();
43 void BaseScreenHandler::GetLocalizedStrings(base::DictionaryValue* dict) {
44 auto builder = make_scoped_ptr(new ::login::LocalizedValuesBuilder(dict));
45 DeclareLocalizedValues(builder.get());
46 GetAdditionalParameters(dict);
49 void BaseScreenHandler::RegisterMessages() {
50 AddPrefixedCallback("userActed",
51 &BaseScreenHandler::HandleUserAction);
52 AddPrefixedCallback("contextChanged",
53 &BaseScreenHandler::HandleContextChanged);
54 DeclareJSCallbacks();
57 void BaseScreenHandler::CommitContextChanges(
58 const base::DictionaryValue& diff) {
59 if (!page_is_ready())
60 pending_context_changes_.MergeDictionary(&diff);
61 else
62 CallJS(kMethodContextChanged, diff);
65 void BaseScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) {
68 void BaseScreenHandler::CallJS(const std::string& method) {
69 web_ui()->CallJavascriptFunction(FullMethodPath(method));
72 void BaseScreenHandler::ShowScreen(const char* screen_name,
73 const base::DictionaryValue* data) {
74 if (!web_ui())
75 return;
76 base::DictionaryValue screen_params;
77 screen_params.SetString("id", screen_name);
78 if (data)
79 screen_params.SetWithoutPathExpansion("data", data->DeepCopy());
80 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showScreen", screen_params);
83 gfx::NativeWindow BaseScreenHandler::GetNativeWindow() {
84 return LoginDisplayHostImpl::default_host()->GetNativeWindow();
87 void BaseScreenHandler::SetBaseScreen(BaseScreen* base_screen) {
88 if (base_screen_ == base_screen)
89 return;
90 if (base_screen_)
91 base_screen_->set_model_view_channel(nullptr);
92 base_screen_ = base_screen;
93 if (base_screen_)
94 base_screen_->set_model_view_channel(this);
97 std::string BaseScreenHandler::FullMethodPath(const std::string& method) const {
98 DCHECK(!method.empty());
99 return js_screen_path_prefix_ + method;
102 void BaseScreenHandler::HandleUserAction(const std::string& action_id) {
103 if (base_screen_)
104 base_screen_->OnUserAction(action_id);
107 void BaseScreenHandler::HandleContextChanged(
108 const base::DictionaryValue* diff) {
109 if (diff && base_screen_)
110 base_screen_->OnContextChanged(*diff);
113 } // namespace chromeos