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

Unified Diff: chrome/browser/ui/webui/chromeos/login/base_screen_handler.h

Issue 2713513009: cros: Break BaseScreenHandler into two classes. (Closed)
Patch Set: Initial upload Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chromeos/login/base_screen_handler.h
diff --git a/chrome/browser/ui/webui/chromeos/login/base_screen_handler.h b/chrome/browser/ui/webui/chromeos/login/base_screen_handler.h
index 2e46198a8b3133fcf74b2347f5bbe7d6a0bf5daf..05916e7c70e0d83d6b0421dd217aa663fe1a5b3c 100644
--- a/chrome/browser/ui/webui/chromeos/login/base_screen_handler.h
+++ b/chrome/browser/ui/webui/chromeos/login/base_screen_handler.h
@@ -5,197 +5,24 @@
#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_
-#include <string>
-
-#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/callback.h"
#include "base/macros.h"
#include "chrome/browser/chromeos/login/oobe_screen.h"
-#include "chrome/browser/chromeos/login/screens/model_view_channel.h"
-#include "components/login/base_screen_handler_utils.h"
-#include "content/public/browser/web_ui.h"
-#include "content/public/browser/web_ui_message_handler.h"
-#include "ui/gfx/native_widget_types.h"
-
-namespace base {
-class DictionaryValue;
-class ListValue;
-}
-
-namespace login {
-class LocalizedValuesBuilder;
-}
+#include "chrome/browser/ui/webui/chromeos/login/base_webui_handler.h"
namespace chromeos {
-class BaseScreen;
-class OobeUI;
-
-// Base class for the OOBE/Login WebUI handlers.
-class BaseScreenHandler : public content::WebUIMessageHandler,
- public ModelViewChannel {
+// Base class for the OOBE/Login WebUI handlers which provide methods specific
+// to a particular OobeScreen.
+class BaseScreenHandler : public BaseWebUIHandler {
public:
- BaseScreenHandler();
+ explicit BaseScreenHandler(OobeScreen oobe_screen);
~BaseScreenHandler() override;
- // Gets localized strings to be used on the page.
- void GetLocalizedStrings(
- base::DictionaryValue* localized_strings);
-
- // WebUIMessageHandler implementation:
- void RegisterMessages() override;
-
- // ModelViewChannel implementation:
- void CommitContextChanges(const base::DictionaryValue& diff) override;
-
- // This method is called when page is ready. It propagates to inherited class
- // via virtual Initialize() method (see below).
- void InitializeBase();
-
- void set_async_assets_load_id(const std::string& async_assets_load_id) {
- async_assets_load_id_ = async_assets_load_id;
- }
- const std::string& async_assets_load_id() const {
- return async_assets_load_id_;
- }
-
- // Set the prefix used when running CallJs with a method. For example,
- // set_call_js_prefix("Oobe")
- // CallJs("lock") -> Invokes JS global named "Oobe.lock"
- void set_call_js_prefix(const std::string& prefix) {
- js_screen_path_prefix_ = prefix + ".";
- }
-
- protected:
- // All subclasses should implement this method to provide localized values.
- virtual void DeclareLocalizedValues(
- ::login::LocalizedValuesBuilder* builder) = 0;
-
- // All subclasses should implement this method to register callbacks for JS
- // messages.
- //
- // TODO (ygorshenin, crbug.com/433797): make this method purely vrtual when
- // all screens will be switched to use ScreenContext.
- virtual void DeclareJSCallbacks() {}
-
- // Subclasses can override these methods to pass additional parameters
- // to loadTimeData. Generally, it is a bad approach, and it should be replaced
- // with Context at some point.
- virtual void GetAdditionalParameters(base::DictionaryValue* parameters);
-
- // Shortcut for calling JS methods on WebUI side.
- void CallJS(const std::string& method);
-
- template<typename A1>
- void CallJS(const std::string& method, const A1& arg1) {
- web_ui()->CallJavascriptFunctionUnsafe(FullMethodPath(method),
- ::login::MakeValue(arg1));
- }
-
- template<typename A1, typename A2>
- void CallJS(const std::string& method, const A1& arg1, const A2& arg2) {
- web_ui()->CallJavascriptFunctionUnsafe(FullMethodPath(method),
- ::login::MakeValue(arg1),
- ::login::MakeValue(arg2));
- }
-
- template<typename A1, typename A2, typename A3>
- void CallJS(const std::string& method,
- const A1& arg1,
- const A2& arg2,
- const A3& arg3) {
- web_ui()->CallJavascriptFunctionUnsafe(
- FullMethodPath(method), ::login::MakeValue(arg1),
- ::login::MakeValue(arg2), ::login::MakeValue(arg3));
- }
-
- template<typename A1, typename A2, typename A3, typename A4>
- void CallJS(const std::string& method,
- const A1& arg1,
- const A2& arg2,
- const A3& arg3,
- const A4& arg4) {
- web_ui()->CallJavascriptFunctionUnsafe(
- FullMethodPath(method), ::login::MakeValue(arg1),
- ::login::MakeValue(arg2), ::login::MakeValue(arg3),
- ::login::MakeValue(arg4));
- }
-
- // Shortcut methods for adding WebUI callbacks.
- template<typename T>
- void AddRawCallback(const std::string& name,
- void (T::*method)(const base::ListValue* args)) {
- web_ui()->RegisterMessageCallback(
- name,
- base::Bind(method, base::Unretained(static_cast<T*>(this))));
- }
-
- template<typename T, typename... Args>
- void AddCallback(const std::string& name, void (T::*method)(Args...)) {
- base::Callback<void(Args...)> callback =
- base::Bind(method, base::Unretained(static_cast<T*>(this)));
- web_ui()->RegisterMessageCallback(
- name, base::Bind(&::login::CallbackWrapper<Args...>, callback));
- }
-
- template <typename Method>
- void AddPrefixedCallback(const std::string& unprefixed_name,
- const Method& method) {
- AddCallback(FullMethodPath(unprefixed_name), method);
- }
-
- // Called when the page is ready and handler can do initialization.
- virtual void Initialize() = 0;
-
- // Show selected WebUI |screen|.
- void ShowScreen(OobeScreen screen);
- // Show selected WebUI |screen|. Pass screen initialization using the |data|
- // parameter.
- void ShowScreenWithData(OobeScreen screen, const base::DictionaryValue* data);
-
- // Returns the OobeUI instance.
- OobeUI* GetOobeUI() const;
-
- // Returns current visible OOBE screen.
- OobeScreen GetCurrentScreen() const;
-
- // Whether page is ready.
- bool page_is_ready() const { return page_is_ready_; }
-
- // Returns the window which shows us.
- virtual gfx::NativeWindow GetNativeWindow();
-
- void SetBaseScreen(BaseScreen* base_screen);
+ 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
private:
- // Returns full name of JS method based on screen and method
- // names.
- std::string FullMethodPath(const std::string& method) const;
-
- // Handles user action.
- void HandleUserAction(const std::string& action_id);
-
- // Handles situation when screen context is changed.
- void HandleContextChanged(const base::DictionaryValue* diff);
-
- // Keeps whether page is ready.
- bool page_is_ready_ = false;
-
- BaseScreen* base_screen_ = nullptr;
-
- // Full name of the corresponding JS screen object. Can be empty, if
- // there are no corresponding screen object or several different
- // objects.
- std::string js_screen_path_prefix_;
-
- // The string id used in the async asset load in JS. If it is set to a
- // non empty value, the Initialize will be deferred until the underlying load
- // is finished.
- std::string async_assets_load_id_;
-
- // Pending changes to context which will be sent when the page will be ready.
- base::DictionaryValue pending_context_changes_;
+ // OobeScreen that this handler corresponds to.
+ OobeScreen oobe_screen_ = OobeScreen::SCREEN_UNKNOWN;
DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler);
};

Powered by Google App Engine
This is Rietveld 408576698