Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/base_screen_handler.cc

Issue 2713513009: cros: Break BaseScreenHandler into two classes. (Closed)
Patch Set: Add comments, fix compile Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
8 #include "base/memory/ptr_util.h"
9 #include "base/values.h"
10 #include "chrome/browser/chromeos/login/screens/base_screen.h"
11 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
12 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
13 #include "components/login/localized_values_builder.h"
14 #include "content/public/browser/web_ui.h"
15
16 namespace chromeos { 7 namespace chromeos {
17 8
18 namespace { 9 BaseScreenHandler::BaseScreenHandler(OobeScreen oobe_screen)
19 const char kMethodContextChanged[] = "contextChanged"; 10 : oobe_screen_(oobe_screen) {}
20 } // namespace
21 11
22 JSCallsContainer::JSCallsContainer() = default; 12 BaseScreenHandler::~BaseScreenHandler() {}
23
24 JSCallsContainer::~JSCallsContainer() = default;
25
26 BaseScreenHandler::BaseScreenHandler() = default;
27
28 BaseScreenHandler::BaseScreenHandler(JSCallsContainer* js_calls_container)
29 : js_calls_container_(js_calls_container) {}
30
31 BaseScreenHandler::~BaseScreenHandler() {
32 if (base_screen_)
33 base_screen_->set_model_view_channel(nullptr);
34 }
35
36 void BaseScreenHandler::InitializeBase() {
37 page_is_ready_ = true;
38 Initialize();
39 if (!pending_context_changes_.empty()) {
40 CommitContextChanges(pending_context_changes_);
41 pending_context_changes_.Clear();
42 }
43 }
44
45 void BaseScreenHandler::GetLocalizedStrings(base::DictionaryValue* dict) {
46 auto builder = base::MakeUnique<::login::LocalizedValuesBuilder>(dict);
47 DeclareLocalizedValues(builder.get());
48 GetAdditionalParameters(dict);
49 }
50
51 void BaseScreenHandler::RegisterMessages() {
52 AddPrefixedCallback("userActed",
53 &BaseScreenHandler::HandleUserAction);
54 AddPrefixedCallback("contextChanged",
55 &BaseScreenHandler::HandleContextChanged);
56 DeclareJSCallbacks();
57 }
58
59 void BaseScreenHandler::CommitContextChanges(
60 const base::DictionaryValue& diff) {
61 if (!page_is_ready())
62 pending_context_changes_.MergeDictionary(&diff);
63 else
64 CallJS(kMethodContextChanged, diff);
65 }
66
67 void BaseScreenHandler::GetAdditionalParameters(base::DictionaryValue* dict) {
68 }
69
70 void BaseScreenHandler::CallJS(const std::string& method) {
71 web_ui()->CallJavascriptFunctionUnsafe(FullMethodPath(method));
72 }
73
74 void BaseScreenHandler::ShowScreen(OobeScreen screen) {
75 ShowScreenWithData(screen, nullptr);
76 }
77
78 void BaseScreenHandler::ShowScreenWithData(OobeScreen screen,
79 const base::DictionaryValue* data) {
80 if (!web_ui())
81 return;
82 base::DictionaryValue screen_params;
83 screen_params.SetString("id", GetOobeScreenName(screen));
84 if (data)
85 screen_params.SetWithoutPathExpansion("data", data->DeepCopy());
86 web_ui()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.showScreen",
87 screen_params);
88 }
89
90 OobeUI* BaseScreenHandler::GetOobeUI() const {
91 return static_cast<OobeUI*>(web_ui()->GetController());
92 }
93
94 OobeScreen BaseScreenHandler::GetCurrentScreen() const {
95 OobeUI* oobe_ui = GetOobeUI();
96 if (!oobe_ui)
97 return OobeScreen::SCREEN_UNKNOWN;
98 return oobe_ui->current_screen();
99 }
100
101 gfx::NativeWindow BaseScreenHandler::GetNativeWindow() {
102 return LoginDisplayHost::default_host()->GetNativeWindow();
103 }
104
105 void BaseScreenHandler::SetBaseScreen(BaseScreen* base_screen) {
106 if (base_screen_ == base_screen)
107 return;
108 if (base_screen_)
109 base_screen_->set_model_view_channel(nullptr);
110 base_screen_ = base_screen;
111 if (base_screen_)
112 base_screen_->set_model_view_channel(this);
113 }
114
115 std::string BaseScreenHandler::FullMethodPath(const std::string& method) const {
116 DCHECK(!method.empty());
117 return js_screen_path_prefix_ + method;
118 }
119
120 void BaseScreenHandler::HandleUserAction(const std::string& action_id) {
121 if (base_screen_)
122 base_screen_->OnUserAction(action_id);
123 }
124
125 void BaseScreenHandler::HandleContextChanged(
126 const base::DictionaryValue* diff) {
127 if (diff && base_screen_)
128 base_screen_->OnContextChanged(*diff);
129 }
130
131 void BaseScreenHandler::ExecuteDeferredJSCalls() {
132 DCHECK(!js_calls_container_->is_initialized());
133 js_calls_container_->mark_initialized();
134 for (const auto& deferred_js_call : js_calls_container_->deferred_js_calls())
135 deferred_js_call.Run();
136 js_calls_container_->deferred_js_calls().clear();
137 }
138 13
139 } // namespace chromeos 14 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698