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

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

Issue 2713513009: cros: Break BaseScreenHandler into two classes. (Closed)
Patch Set: Add comments, fix compile 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_webui_handler.h
diff --git a/chrome/browser/ui/webui/chromeos/login/base_screen_handler.h b/chrome/browser/ui/webui/chromeos/login/base_webui_handler.h
similarity index 85%
copy from chrome/browser/ui/webui/chromeos/login/base_screen_handler.h
copy to chrome/browser/ui/webui/chromeos/login/base_webui_handler.h
index 1fae31a4972d59e3a75e8a7f498ce2d661f266f7..aae5b269e1ac9c7a598b71e195e7301d163eef9b 100644
--- a/chrome/browser/ui/webui/chromeos/login/base_screen_handler.h
+++ b/chrome/browser/ui/webui/chromeos/login/base_webui_handler.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_
-#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_
+#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_WEBUI_HANDLER_H_
+#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_WEBUI_HANDLER_H_
#include <string>
@@ -33,7 +33,7 @@ class BaseScreen;
class OobeUI;
// A helper class to store deferred Javascript calls, shared by subclasses of
-// BaseScreenHandler.
+// BaseWebUIHandler.
class JSCallsContainer {
public:
JSCallsContainer();
@@ -60,17 +60,23 @@ class JSCallsContainer {
std::vector<base::Closure> deferred_js_calls_;
};
-// Base class for the OOBE/Login WebUI handlers.
-class BaseScreenHandler : public content::WebUIMessageHandler,
- public ModelViewChannel {
+// Base class for all oobe/login WebUI handlers. These handlers are the binding
+// layer that allow the C++ and JavaScript code to communicate.
+//
+// If the deriving type is associated with a specific OobeScreen, it should
+// derive from BaseScreenHandler instead of BaseWebUIHandler.
+//
+// TODO(jdufault): Move all OobeScreen related concepts out of BaseWebUIHandler
+// and into BaseScreenHandler.
+class BaseWebUIHandler : public content::WebUIMessageHandler,
+ public ModelViewChannel {
public:
- BaseScreenHandler();
- explicit BaseScreenHandler(JSCallsContainer* js_calls_container);
- ~BaseScreenHandler() override;
+ BaseWebUIHandler();
+ explicit BaseWebUIHandler(JSCallsContainer* js_calls_container);
+ ~BaseWebUIHandler() override;
// Gets localized strings to be used on the page.
- void GetLocalizedStrings(
- base::DictionaryValue* localized_strings);
+ void GetLocalizedStrings(base::DictionaryValue* localized_strings);
// WebUIMessageHandler implementation:
void RegisterMessages() override;
@@ -82,13 +88,6 @@ class BaseScreenHandler : public content::WebUIMessageHandler,
// 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"
@@ -96,6 +95,13 @@ class BaseScreenHandler : public content::WebUIMessageHandler,
js_screen_path_prefix_ = prefix + ".";
}
+ 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_;
+ }
+
protected:
// All subclasses should implement this method to provide localized values.
virtual void DeclareLocalizedValues(
@@ -116,20 +122,20 @@ class BaseScreenHandler : public content::WebUIMessageHandler,
// Shortcut for calling JS methods on WebUI side.
void CallJS(const std::string& method);
- template<typename A1>
+ 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>
+ 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>
+ template <typename A1, typename A2, typename A3>
void CallJS(const std::string& method,
const A1& arg1,
const A2& arg2,
@@ -139,7 +145,7 @@ class BaseScreenHandler : public content::WebUIMessageHandler,
::login::MakeValue(arg2), ::login::MakeValue(arg3));
}
- template<typename A1, typename A2, typename A3, typename A4>
+ template <typename A1, typename A2, typename A3, typename A4>
void CallJS(const std::string& method,
const A1& arg1,
const A2& arg2,
@@ -163,7 +169,7 @@ class BaseScreenHandler : public content::WebUIMessageHandler,
// parameter pack appears in the pattern, even though the elements of the
// Args pack are not actually in this code.
js_calls_container_->deferred_js_calls().push_back(base::Bind(
- &BaseScreenHandler::ExecuteDeferredJSCall<
+ &BaseWebUIHandler::ExecuteDeferredJSCall<
typename std::conditional<true, base::Value, Args>::type...>,
base::Unretained(this), function_name,
base::Passed(::login::MakeValue(args).CreateDeepCopy())...));
@@ -175,15 +181,14 @@ class BaseScreenHandler : public content::WebUIMessageHandler,
void ExecuteDeferredJSCalls();
// Shortcut methods for adding WebUI callbacks.
- template<typename T>
+ 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))));
+ name, base::Bind(method, base::Unretained(static_cast<T*>(this))));
}
- template<typename T, typename... Args>
+ 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)));
@@ -261,9 +266,9 @@ class BaseScreenHandler : public content::WebUIMessageHandler,
JSCallsContainer* js_calls_container_ = nullptr; // non-owning pointers.
- DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler);
+ DISALLOW_COPY_AND_ASSIGN(BaseWebUIHandler);
};
} // namespace chromeos
-#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_
+#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_WEBUI_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698