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

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

Powered by Google App Engine
This is Rietveld 408576698