Index: chrome/browser/ui/webui/chromeos/login/oobe_ui.h |
diff --git a/chrome/browser/ui/webui/chromeos/login/oobe_ui.h b/chrome/browser/ui/webui/chromeos/login/oobe_ui.h |
index 80e080728fd97959a31b3233af3867d83fb7c671..1ee84627722512816778d71306c340b966ea1c7d 100644 |
--- a/chrome/browser/ui/webui/chromeos/login/oobe_ui.h |
+++ b/chrome/browser/ui/webui/chromeos/login/oobe_ui.h |
@@ -16,6 +16,7 @@ |
#include "base/observer_list.h" |
#include "chrome/browser/chromeos/login/oobe_screen.h" |
#include "chrome/browser/chromeos/settings/shutdown_policy_handler.h" |
+#include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" |
#include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h" |
#include "content/public/browser/web_ui_controller.h" |
@@ -32,7 +33,6 @@ class AppLaunchSplashScreenActor; |
class ArcKioskSplashScreenActor; |
class ArcTermsOfServiceScreenActor; |
class AutoEnrollmentCheckScreenActor; |
-class BaseScreenHandler; |
class ControllerPairingScreenActor; |
class CoreOobeActor; |
class DeviceDisabledScreenActor; |
@@ -166,7 +166,44 @@ class OobeUI : public content::WebUIController, |
// changed). |
void UpdateLocalizedStringsIfNeeded(); |
+ // Executes javascript calls that were deferred while the instance was not |
+ // initialized yet. |
+ void ExecuteDeferredJSCalls(); |
+ |
+ // Calls javascript method if the instance is already initialized, or defers |
+ // the call until it gets initialized. |
+ template <typename... Args> |
+ void CallJSOrDefer(const std::string& function_name, |
+ BaseScreenHandler* screen_handler, |
+ const Args&... args) { |
+ if (is_initialized_) { |
+ screen_handler->CallJS(function_name, args...); |
+ } else { |
+ // Note that std::conditional is used here in order to obtain a sequence |
+ // of base::Value types with the length equal to sizeof...(Args); the C++ |
+ // template parameter pack expansion rules require that the name of the |
+ // parameter pack appears in the pattern, even though the elements of the |
+ // Args pack are not actually in this code. |
+ deferred_js_calls_.push_back(base::Bind( |
+ &OobeUI::ExecuteDeferredJSCall< |
+ typename std::conditional<true, base::Value, Args>::type...>, |
+ base::Unretained(this), function_name, screen_handler, |
+ base::Passed(::login::MakeValue(args).CreateDeepCopy())...)); |
+ } |
+ } |
+ |
private: |
+ // Calls javascript method. |
+ // |
+ // Note that the Args template parameter pack should consist of types |
+ // convertible to base::Value. |
+ template <typename... Args> |
+ void ExecuteDeferredJSCall(const std::string& function_name, |
+ BaseScreenHandler* screen_handler, |
+ std::unique_ptr<Args>... args) { |
+ screen_handler->CallJS(function_name, *args...); |
+ } |
+ |
void AddScreenHandler(std::unique_ptr<BaseScreenHandler> handler); |
// CoreOobeHandler::Delegate implementation: |
@@ -258,6 +295,16 @@ class OobeUI : public content::WebUIController, |
std::unique_ptr<ash::ScreenDimmer> screen_dimmer_; |
+ // Whether the instance is initialized. |
+ // |
+ // The instance becomes initialized after the corresponding message is |
+ // received from javascript side. |
+ bool is_initialized_ = false; |
+ |
+ // Javascript calls that have been deferred while the instance was not |
+ // initialized yet. |
+ std::vector<base::Closure> deferred_js_calls_; |
+ |
DISALLOW_COPY_AND_ASSIGN(OobeUI); |
}; |