| 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> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "components/login/base_screen_handler_utils.h" | 14 #include "components/login/base_screen_handler_utils.h" |
| 15 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
| 16 #include "content/public/browser/web_ui_message_handler.h" | 16 #include "content/public/browser/web_ui_message_handler.h" |
| 17 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class DictionaryValue; | 20 class DictionaryValue; |
| 21 class ListValue; | 21 class ListValue; |
| 22 class Value; | 22 class Value; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace chromeos { | 25 namespace chromeos { |
| 26 | 26 |
| 27 class BaseScreen; |
| 28 |
| 27 // Class that collects Localized Values for translation. | 29 // Class that collects Localized Values for translation. |
| 28 class LocalizedValuesBuilder { | 30 class LocalizedValuesBuilder { |
| 29 public: | 31 public: |
| 30 explicit LocalizedValuesBuilder(base::DictionaryValue* dict); | 32 explicit LocalizedValuesBuilder(base::DictionaryValue* dict); |
| 31 // Method to declare localized value. |key| is the i18n key used in html. | 33 // Method to declare localized value. |key| is the i18n key used in html. |
| 32 // |message| is text of the message. | 34 // |message| is text of the message. |
| 33 void Add(const std::string& key, const std::string& message); | 35 void Add(const std::string& key, const std::string& message); |
| 34 | 36 |
| 35 // Method to declare localized value. |key| is the i18n key used in html. | 37 // Method to declare localized value. |key| is the i18n key used in html. |
| 36 // |message| is text of the message. | 38 // |message| is text of the message. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 85 |
| 84 // C-tor used when JS screen prefix is needed. | 86 // C-tor used when JS screen prefix is needed. |
| 85 explicit BaseScreenHandler(const std::string& js_screen_path); | 87 explicit BaseScreenHandler(const std::string& js_screen_path); |
| 86 | 88 |
| 87 virtual ~BaseScreenHandler(); | 89 virtual ~BaseScreenHandler(); |
| 88 | 90 |
| 89 // Gets localized strings to be used on the page. | 91 // Gets localized strings to be used on the page. |
| 90 void GetLocalizedStrings( | 92 void GetLocalizedStrings( |
| 91 base::DictionaryValue* localized_strings); | 93 base::DictionaryValue* localized_strings); |
| 92 | 94 |
| 95 // WebUIMessageHandler implementation: |
| 96 virtual void RegisterMessages() override; |
| 97 |
| 93 // This method is called when page is ready. It propagates to inherited class | 98 // This method is called when page is ready. It propagates to inherited class |
| 94 // via virtual Initialize() method (see below). | 99 // via virtual Initialize() method (see below). |
| 95 void InitializeBase(); | 100 void InitializeBase(); |
| 96 | 101 |
| 97 void set_async_assets_load_id(const std::string& async_assets_load_id) { | 102 void set_async_assets_load_id(const std::string& async_assets_load_id) { |
| 98 async_assets_load_id_ = async_assets_load_id; | 103 async_assets_load_id_ = async_assets_load_id; |
| 99 } | 104 } |
| 100 const std::string& async_assets_load_id() const { | 105 const std::string& async_assets_load_id() const { |
| 101 return async_assets_load_id_; | 106 return async_assets_load_id_; |
| 102 } | 107 } |
| 103 | 108 |
| 104 protected: | 109 protected: |
| 105 // All subclasses should implement this method to provide localized values. | 110 // All subclasses should implement this method to provide localized values. |
| 106 virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) = 0; | 111 virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) = 0; |
| 107 | 112 |
| 113 // All subclasses should implement this method to register callbacks for JS |
| 114 // messages. |
| 115 // |
| 116 // TODO (ygorshenin, crbug.com/433797): make this method purely vrtual when |
| 117 // all screens will be switched to use ScreenContext. |
| 118 virtual void DeclareJSCallbacks() {} |
| 119 |
| 108 // Subclasses can override these methods to pass additional parameters | 120 // Subclasses can override these methods to pass additional parameters |
| 109 // to loadTimeData. Generally, it is a bad approach, and it should be replaced | 121 // to loadTimeData. Generally, it is a bad approach, and it should be replaced |
| 110 // with Context at some point. | 122 // with Context at some point. |
| 111 virtual void GetAdditionalParameters(base::DictionaryValue* parameters); | 123 virtual void GetAdditionalParameters(base::DictionaryValue* parameters); |
| 112 | 124 |
| 113 // Shortcut for calling JS methods on WebUI side. | 125 // Shortcut for calling JS methods on WebUI side. |
| 114 void CallJS(const std::string& method); | 126 void CallJS(const std::string& method); |
| 115 | 127 |
| 116 template<typename A1> | 128 template<typename A1> |
| 117 void CallJS(const std::string& method, const A1& arg1) { | 129 void CallJS(const std::string& method, const A1& arg1) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // Show selected WebUI |screen|. Optionally it can pass screen initialization | 226 // Show selected WebUI |screen|. Optionally it can pass screen initialization |
| 215 // data via |data| parameter. | 227 // data via |data| parameter. |
| 216 void ShowScreen(const char* screen, const base::DictionaryValue* data); | 228 void ShowScreen(const char* screen, const base::DictionaryValue* data); |
| 217 | 229 |
| 218 // Whether page is ready. | 230 // Whether page is ready. |
| 219 bool page_is_ready() const { return page_is_ready_; } | 231 bool page_is_ready() const { return page_is_ready_; } |
| 220 | 232 |
| 221 // Returns the window which shows us. | 233 // Returns the window which shows us. |
| 222 virtual gfx::NativeWindow GetNativeWindow(); | 234 virtual gfx::NativeWindow GetNativeWindow(); |
| 223 | 235 |
| 236 void set_base_screen(BaseScreen* base_screen) { base_screen_ = base_screen; } |
| 237 |
| 224 private: | 238 private: |
| 225 // Returns full name of JS method based on screen and method | 239 // Returns full name of JS method based on screen and method |
| 226 // names. | 240 // names. |
| 227 std::string FullMethodPath(const std::string& method) const; | 241 std::string FullMethodPath(const std::string& method) const; |
| 228 | 242 |
| 243 // Handles situation when screen context is changed. |
| 244 void HandleContextChanged(const base::DictionaryValue* diff); |
| 245 |
| 229 // Keeps whether page is ready. | 246 // Keeps whether page is ready. |
| 230 bool page_is_ready_; | 247 bool page_is_ready_; |
| 231 | 248 |
| 249 BaseScreen* base_screen_; |
| 250 |
| 232 base::DictionaryValue* localized_values_; | 251 base::DictionaryValue* localized_values_; |
| 233 | 252 |
| 234 // Full name of the corresponding JS screen object. Can be empty, if | 253 // Full name of the corresponding JS screen object. Can be empty, if |
| 235 // there are no corresponding screen object or several different | 254 // there are no corresponding screen object or several different |
| 236 // objects. | 255 // objects. |
| 237 std::string js_screen_path_prefix_; | 256 std::string js_screen_path_prefix_; |
| 238 | 257 |
| 239 // The string id used in the async asset load in JS. If it is set to a | 258 // The string id used in the async asset load in JS. If it is set to a |
| 240 // non empty value, the Initialize will be deferred until the underlying load | 259 // non empty value, the Initialize will be deferred until the underlying load |
| 241 // is finished. | 260 // is finished. |
| 242 std::string async_assets_load_id_; | 261 std::string async_assets_load_id_; |
| 243 | 262 |
| 244 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler); | 263 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler); |
| 245 }; | 264 }; |
| 246 | 265 |
| 247 } // namespace chromeos | 266 } // namespace chromeos |
| 248 | 267 |
| 249 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ | 268 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ |
| OLD | NEW |