Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "base/bind_helpers.h" | |
| 12 #include "base/callback.h" | |
| 13 #include "base/macros.h" | 8 #include "base/macros.h" |
| 14 #include "chrome/browser/chromeos/login/oobe_screen.h" | 9 #include "chrome/browser/chromeos/login/oobe_screen.h" |
| 15 #include "chrome/browser/chromeos/login/screens/model_view_channel.h" | 10 #include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.h" |
| 16 #include "components/login/base_screen_handler_utils.h" | |
| 17 #include "content/public/browser/web_ui.h" | |
| 18 #include "content/public/browser/web_ui_message_handler.h" | |
| 19 #include "ui/gfx/native_widget_types.h" | |
| 20 | |
| 21 namespace base { | |
| 22 class DictionaryValue; | |
| 23 class ListValue; | |
| 24 } | |
| 25 | |
| 26 namespace login { | |
| 27 class LocalizedValuesBuilder; | |
| 28 } | |
| 29 | 11 |
| 30 namespace chromeos { | 12 namespace chromeos { |
| 31 | 13 |
| 32 class BaseScreen; | 14 // Base class for the OOBE/Login WebUI handlers which provide methods specific |
| 33 class OobeUI; | 15 // to a particular OobeScreen. |
| 34 | 16 class BaseScreenHandler : public BaseWebUIHandler { |
| 35 // Base class for the OOBE/Login WebUI handlers. | |
| 36 class BaseScreenHandler : public content::WebUIMessageHandler, | |
| 37 public ModelViewChannel { | |
| 38 public: | 17 public: |
| 39 BaseScreenHandler(); | 18 explicit BaseScreenHandler(OobeScreen oobe_screen); |
| 40 ~BaseScreenHandler() override; | 19 ~BaseScreenHandler() override; |
| 41 | 20 |
| 42 // Gets localized strings to be used on the page. | 21 OobeScreen oobe_screen() const { return oobe_screen_; } |
|
Alexander Alekseev
2017/03/01 01:53:40
It looks like BaseScreenHandler is now empty and c
jdufault
2017/03/01 17:53:51
I'd like to move more logic from BaseWebUIHandler
| |
| 43 void GetLocalizedStrings( | |
| 44 base::DictionaryValue* localized_strings); | |
| 45 | |
| 46 // WebUIMessageHandler implementation: | |
| 47 void RegisterMessages() override; | |
| 48 | |
| 49 // ModelViewChannel implementation: | |
| 50 void CommitContextChanges(const base::DictionaryValue& diff) override; | |
| 51 | |
| 52 // This method is called when page is ready. It propagates to inherited class | |
| 53 // via virtual Initialize() method (see below). | |
| 54 void InitializeBase(); | |
| 55 | |
| 56 void set_async_assets_load_id(const std::string& async_assets_load_id) { | |
| 57 async_assets_load_id_ = async_assets_load_id; | |
| 58 } | |
| 59 const std::string& async_assets_load_id() const { | |
| 60 return async_assets_load_id_; | |
| 61 } | |
| 62 | |
| 63 // Set the prefix used when running CallJs with a method. For example, | |
| 64 // set_call_js_prefix("Oobe") | |
| 65 // CallJs("lock") -> Invokes JS global named "Oobe.lock" | |
| 66 void set_call_js_prefix(const std::string& prefix) { | |
| 67 js_screen_path_prefix_ = prefix + "."; | |
| 68 } | |
| 69 | |
| 70 protected: | |
| 71 // All subclasses should implement this method to provide localized values. | |
| 72 virtual void DeclareLocalizedValues( | |
| 73 ::login::LocalizedValuesBuilder* builder) = 0; | |
| 74 | |
| 75 // All subclasses should implement this method to register callbacks for JS | |
| 76 // messages. | |
| 77 // | |
| 78 // TODO (ygorshenin, crbug.com/433797): make this method purely vrtual when | |
| 79 // all screens will be switched to use ScreenContext. | |
| 80 virtual void DeclareJSCallbacks() {} | |
| 81 | |
| 82 // Subclasses can override these methods to pass additional parameters | |
| 83 // to loadTimeData. Generally, it is a bad approach, and it should be replaced | |
| 84 // with Context at some point. | |
| 85 virtual void GetAdditionalParameters(base::DictionaryValue* parameters); | |
| 86 | |
| 87 // Shortcut for calling JS methods on WebUI side. | |
| 88 void CallJS(const std::string& method); | |
| 89 | |
| 90 template<typename A1> | |
| 91 void CallJS(const std::string& method, const A1& arg1) { | |
| 92 web_ui()->CallJavascriptFunctionUnsafe(FullMethodPath(method), | |
| 93 ::login::MakeValue(arg1)); | |
| 94 } | |
| 95 | |
| 96 template<typename A1, typename A2> | |
| 97 void CallJS(const std::string& method, const A1& arg1, const A2& arg2) { | |
| 98 web_ui()->CallJavascriptFunctionUnsafe(FullMethodPath(method), | |
| 99 ::login::MakeValue(arg1), | |
| 100 ::login::MakeValue(arg2)); | |
| 101 } | |
| 102 | |
| 103 template<typename A1, typename A2, typename A3> | |
| 104 void CallJS(const std::string& method, | |
| 105 const A1& arg1, | |
| 106 const A2& arg2, | |
| 107 const A3& arg3) { | |
| 108 web_ui()->CallJavascriptFunctionUnsafe( | |
| 109 FullMethodPath(method), ::login::MakeValue(arg1), | |
| 110 ::login::MakeValue(arg2), ::login::MakeValue(arg3)); | |
| 111 } | |
| 112 | |
| 113 template<typename A1, typename A2, typename A3, typename A4> | |
| 114 void CallJS(const std::string& method, | |
| 115 const A1& arg1, | |
| 116 const A2& arg2, | |
| 117 const A3& arg3, | |
| 118 const A4& arg4) { | |
| 119 web_ui()->CallJavascriptFunctionUnsafe( | |
| 120 FullMethodPath(method), ::login::MakeValue(arg1), | |
| 121 ::login::MakeValue(arg2), ::login::MakeValue(arg3), | |
| 122 ::login::MakeValue(arg4)); | |
| 123 } | |
| 124 | |
| 125 // Shortcut methods for adding WebUI callbacks. | |
| 126 template<typename T> | |
| 127 void AddRawCallback(const std::string& name, | |
| 128 void (T::*method)(const base::ListValue* args)) { | |
| 129 web_ui()->RegisterMessageCallback( | |
| 130 name, | |
| 131 base::Bind(method, base::Unretained(static_cast<T*>(this)))); | |
| 132 } | |
| 133 | |
| 134 template<typename T, typename... Args> | |
| 135 void AddCallback(const std::string& name, void (T::*method)(Args...)) { | |
| 136 base::Callback<void(Args...)> callback = | |
| 137 base::Bind(method, base::Unretained(static_cast<T*>(this))); | |
| 138 web_ui()->RegisterMessageCallback( | |
| 139 name, base::Bind(&::login::CallbackWrapper<Args...>, callback)); | |
| 140 } | |
| 141 | |
| 142 template <typename Method> | |
| 143 void AddPrefixedCallback(const std::string& unprefixed_name, | |
| 144 const Method& method) { | |
| 145 AddCallback(FullMethodPath(unprefixed_name), method); | |
| 146 } | |
| 147 | |
| 148 // Called when the page is ready and handler can do initialization. | |
| 149 virtual void Initialize() = 0; | |
| 150 | |
| 151 // Show selected WebUI |screen|. | |
| 152 void ShowScreen(OobeScreen screen); | |
| 153 // Show selected WebUI |screen|. Pass screen initialization using the |data| | |
| 154 // parameter. | |
| 155 void ShowScreenWithData(OobeScreen screen, const base::DictionaryValue* data); | |
| 156 | |
| 157 // Returns the OobeUI instance. | |
| 158 OobeUI* GetOobeUI() const; | |
| 159 | |
| 160 // Returns current visible OOBE screen. | |
| 161 OobeScreen GetCurrentScreen() const; | |
| 162 | |
| 163 // Whether page is ready. | |
| 164 bool page_is_ready() const { return page_is_ready_; } | |
| 165 | |
| 166 // Returns the window which shows us. | |
| 167 virtual gfx::NativeWindow GetNativeWindow(); | |
| 168 | |
| 169 void SetBaseScreen(BaseScreen* base_screen); | |
| 170 | 22 |
| 171 private: | 23 private: |
| 172 // Returns full name of JS method based on screen and method | 24 // OobeScreen that this handler corresponds to. |
| 173 // names. | 25 OobeScreen oobe_screen_ = OobeScreen::SCREEN_UNKNOWN; |
| 174 std::string FullMethodPath(const std::string& method) const; | |
| 175 | |
| 176 // Handles user action. | |
| 177 void HandleUserAction(const std::string& action_id); | |
| 178 | |
| 179 // Handles situation when screen context is changed. | |
| 180 void HandleContextChanged(const base::DictionaryValue* diff); | |
| 181 | |
| 182 // Keeps whether page is ready. | |
| 183 bool page_is_ready_ = false; | |
| 184 | |
| 185 BaseScreen* base_screen_ = nullptr; | |
| 186 | |
| 187 // Full name of the corresponding JS screen object. Can be empty, if | |
| 188 // there are no corresponding screen object or several different | |
| 189 // objects. | |
| 190 std::string js_screen_path_prefix_; | |
| 191 | |
| 192 // The string id used in the async asset load in JS. If it is set to a | |
| 193 // non empty value, the Initialize will be deferred until the underlying load | |
| 194 // is finished. | |
| 195 std::string async_assets_load_id_; | |
| 196 | |
| 197 // Pending changes to context which will be sent when the page will be ready. | |
| 198 base::DictionaryValue pending_context_changes_; | |
| 199 | 26 |
| 200 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler); | 27 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler); |
| 201 }; | 28 }; |
| 202 | 29 |
| 203 } // namespace chromeos | 30 } // namespace chromeos |
| 204 | 31 |
| 205 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ | 32 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ |
| OLD | NEW |