cros: Remove ScreenContext from error screen

Bug: 926511
Change-Id: Ia11b785b453b72e4f009353d7ad7168a471db743
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1444235
Reviewed-by: Alexander Alekseev <alemate@chromium.org>
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#639725}
diff --git a/chrome/browser/chromeos/login/screens/error_screen.cc b/chrome/browser/chromeos/login/screens/error_screen.cc
index 74ea887..eed00ba 100644
--- a/chrome/browser/chromeos/login/screens/error_screen.cc
+++ b/chrome/browser/chromeos/login/screens/error_screen.cc
@@ -51,15 +51,6 @@
 
 namespace {
 
-constexpr const char kContextKeyErrorStateCode[] = "error-state-code";
-constexpr const char kContextKeyErrorStateNetwork[] = "error-state-network";
-constexpr const char kContextKeyGuestSigninAllowed[] = "guest-signin-allowed";
-constexpr const char kContextKeyOfflineSigninAllowed[] =
-    "offline-signin-allowed";
-constexpr const char kContextKeyShowConnectingIndicator[] =
-    "show-connecting-indicator";
-constexpr const char kContextKeyUIState[] = "ui-state";
-
 // Returns the current running kiosk app profile in a kiosk session. Otherwise,
 // returns nullptr.
 Profile* GetAppProfile() {
@@ -101,11 +92,13 @@
 }
 
 void ErrorScreen::AllowGuestSignin(bool allowed) {
-  GetContextEditor().SetBoolean(kContextKeyGuestSigninAllowed, allowed);
+  if (view_)
+    view_->SetGuestSigninAllowed(allowed);
 }
 
 void ErrorScreen::AllowOfflineLogin(bool allowed) {
-  GetContextEditor().SetBoolean(kContextKeyOfflineSigninAllowed, allowed);
+  if (view_)
+    view_->SetOfflineSigninAllowed(allowed);
 }
 
 void ErrorScreen::FixCaptivePortal() {
@@ -138,16 +131,17 @@
 
 void ErrorScreen::SetUIState(NetworkError::UIState ui_state) {
   ui_state_ = ui_state;
-  GetContextEditor().SetInteger(kContextKeyUIState,
-                                static_cast<int>(ui_state_));
+  if (view_)
+    view_->SetUIState(ui_state);
 }
 
 void ErrorScreen::SetErrorState(NetworkError::ErrorState error_state,
                                 const std::string& network) {
   error_state_ = error_state;
-  GetContextEditor()
-      .SetInteger(kContextKeyErrorStateCode, static_cast<int>(error_state_))
-      .SetString(kContextKeyErrorStateNetwork, network);
+  if (view_) {
+    view_->SetErrorStateCode(error_state);
+    view_->SetErrorStateNetwork(network);
+  }
 }
 
 void ErrorScreen::SetParentScreen(OobeScreen parent_screen) {
@@ -167,7 +161,8 @@
 }
 
 void ErrorScreen::ShowConnectingIndicator(bool show) {
-  GetContextEditor().SetBoolean(kContextKeyShowConnectingIndicator, show);
+  if (view_)
+    view_->SetShowConnectingIndicator(show);
 }
 
 ErrorScreen::ConnectRequestCallbackSubscription
diff --git a/chrome/browser/chromeos/login/screens/mock_error_screen.h b/chrome/browser/chromeos/login/screens/mock_error_screen.h
index 981cf33..4c7daee7 100644
--- a/chrome/browser/chromeos/login/screens/mock_error_screen.h
+++ b/chrome/browser/chromeos/login/screens/mock_error_screen.h
@@ -42,6 +42,12 @@
   MOCK_METHOD1(MockBind, void(ErrorScreen* screen));
   MOCK_METHOD0(MockUnbind, void());
   MOCK_METHOD1(ShowOobeScreen, void(OobeScreen screen));
+  MOCK_METHOD1(SetErrorStateCode, void(NetworkError::ErrorState error_state));
+  MOCK_METHOD1(SetErrorStateNetwork, void(const std::string& network_name));
+  MOCK_METHOD1(SetGuestSigninAllowed, void(bool value));
+  MOCK_METHOD1(SetOfflineSigninAllowed, void(bool value));
+  MOCK_METHOD1(SetShowConnectingIndicator, void(bool value));
+  MOCK_METHOD1(SetUIState, void(NetworkError::UIState ui_state));
 
  private:
   ErrorScreen* screen_ = nullptr;
diff --git a/chrome/browser/chromeos/login/screens/network_error_view.h b/chrome/browser/chromeos/login/screens/network_error_view.h
index d81175b..88e61238 100644
--- a/chrome/browser/chromeos/login/screens/network_error_view.h
+++ b/chrome/browser/chromeos/login/screens/network_error_view.h
@@ -7,6 +7,7 @@
 
 #include "base/strings/string16.h"
 #include "chrome/browser/chromeos/login/oobe_screen.h"
+#include "chrome/browser/chromeos/login/screens/network_error.h"
 
 namespace chromeos {
 
@@ -34,6 +35,24 @@
 
   // Switches to |screen|.
   virtual void ShowOobeScreen(OobeScreen screen) = 0;
+
+  // Sets current error state of the screen.
+  virtual void SetErrorStateCode(NetworkError::ErrorState error_state) = 0;
+
+  // Sets current error network state of the screen.
+  virtual void SetErrorStateNetwork(const std::string& network_name) = 0;
+
+  // Is guest signin allowed?
+  virtual void SetGuestSigninAllowed(bool value) = 0;
+
+  // Is offline signin allowed?
+  virtual void SetOfflineSigninAllowed(bool value) = 0;
+
+  // Updates visibility of the label indicating we're reconnecting.
+  virtual void SetShowConnectingIndicator(bool value) = 0;
+
+  // Sets current UI state of the screen.
+  virtual void SetUIState(NetworkError::UIState ui_state) = 0;
 };
 
 }  // namespace chromeos
diff --git a/chrome/browser/resources/chromeos/login/screen_error_message.js b/chrome/browser/resources/chromeos/login/screen_error_message.js
index 178d9ad5..ad16872 100644
--- a/chrome/browser/resources/chromeos/login/screen_error_message.js
+++ b/chrome/browser/resources/chromeos/login/screen_error_message.js
@@ -7,13 +7,6 @@
  */
 
 login.createScreen('ErrorMessageScreen', 'error-message', function() {
-  var CONTEXT_KEY_ERROR_STATE_CODE = 'error-state-code';
-  var CONTEXT_KEY_ERROR_STATE_NETWORK = 'error-state-network';
-  var CONTEXT_KEY_GUEST_SIGNIN_ALLOWED = 'guest-signin-allowed';
-  var CONTEXT_KEY_OFFLINE_SIGNIN_ALLOWED = 'offline-signin-allowed';
-  var CONTEXT_KEY_SHOW_CONNECTING_INDICATOR = 'show-connecting-indicator';
-  var CONTEXT_KEY_UI_STATE = 'ui-state';
-
   var USER_ACTION_CONFIGURE_CERTS = 'configure-certs';
   var USER_ACTION_DIAGNOSE = 'diagnose';
   var USER_ACTION_LAUNCH_OOBE_GUEST = 'launch-oobe-guest';
@@ -72,9 +65,15 @@
 
   return {
     EXTERNAL_API: [
-      'updateLocalizedContent', 'onBeforeShow', 'onBeforeHide',
-      'allowGuestSignin', 'allowOfflineLogin', 'setUIState', 'setErrorState',
-      'showConnectingIndicator'
+      'updateLocalizedContent',
+      'onBeforeShow',
+      'onBeforeHide',
+      'allowGuestSignin',
+      'allowOfflineLogin',
+      'setUIState',
+      'setErrorState',
+      'showConnectingIndicator',
+      'setErrorStateNetwork',
     ],
 
     // Error screen initial UI state.
@@ -104,29 +103,6 @@
       this.updateLocalizedContent();
 
       var self = this;
-      this.context.addObserver(
-          CONTEXT_KEY_ERROR_STATE_CODE, function(error_state) {
-            self.setErrorState(error_state);
-          });
-      this.context.addObserver(
-          CONTEXT_KEY_ERROR_STATE_NETWORK, function(network) {
-            self.setNetwork_(network);
-          });
-      this.context.addObserver(
-          CONTEXT_KEY_GUEST_SIGNIN_ALLOWED, function(allowed) {
-            self.allowGuestSignin(allowed);
-          });
-      this.context.addObserver(
-          CONTEXT_KEY_OFFLINE_SIGNIN_ALLOWED, function(allowed) {
-            self.allowOfflineLogin(allowed);
-          });
-      this.context.addObserver(
-          CONTEXT_KEY_SHOW_CONNECTING_INDICATOR, function(show) {
-            self.showConnectingIndicator(show);
-          });
-      this.context.addObserver(CONTEXT_KEY_UI_STATE, function(ui_state) {
-        self.setUIState(ui_state);
-      });
       $('error-message-back-button')
           .addEventListener('tap', this.cancel.bind(this));
 
@@ -370,6 +346,14 @@
     },
 
     /**
+     * Sets current error network state of the screen.
+     * @param {string} network Name of the current network
+     */
+    setErrorStateNetwork: function(value) {
+      this.setNetwork_(value);
+    },
+
+    /**
      * Updates visibility of the label indicating we're reconnecting.
      * @param {boolean} show Whether the label should be shown.
      */
diff --git a/chrome/browser/ui/webui/chromeos/login/error_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/error_screen_handler.cc
index b4fcfa1..1cb5084 100644
--- a/chrome/browser/ui/webui/chromeos/login/error_screen_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/login/error_screen_handler.cc
@@ -22,8 +22,7 @@
 namespace chromeos {
 
 ErrorScreenHandler::ErrorScreenHandler(JSCallsContainer* js_calls_container)
-    : BaseScreenHandler(kScreenId, js_calls_container),
-      weak_ptr_factory_(this) {
+    : BaseScreenHandler(kScreenId, js_calls_container) {
   set_call_js_prefix(kJsScreenPath);
 }
 
@@ -63,6 +62,32 @@
   ShowScreen(screen);
 }
 
+void ErrorScreenHandler::SetErrorStateCode(
+    NetworkError::ErrorState error_state) {
+  CallJS("login.ErrorMessageScreen.setErrorState",
+         static_cast<int>(error_state));
+}
+
+void ErrorScreenHandler::SetErrorStateNetwork(const std::string& network_name) {
+  CallJS("login.ErrorMessageScreen.setErrorStateNetwork", network_name);
+}
+
+void ErrorScreenHandler::SetGuestSigninAllowed(bool value) {
+  CallJS("login.ErrorMessageScreen.allowGuestSignin", value);
+}
+
+void ErrorScreenHandler::SetOfflineSigninAllowed(bool value) {
+  CallJS("login.ErrorMessageScreen.allowOfflineLogin", value);
+}
+
+void ErrorScreenHandler::SetShowConnectingIndicator(bool value) {
+  CallJS("login.ErrorMessageScreen.showConnectingIndicator", value);
+}
+
+void ErrorScreenHandler::SetUIState(NetworkError::UIState ui_state) {
+  CallJS("login.ErrorMessageScreen.setUIState", static_cast<int>(ui_state));
+}
+
 void ErrorScreenHandler::RegisterMessages() {
   AddCallback("hideCaptivePortal",
               &ErrorScreenHandler::HandleHideCaptivePortal);
diff --git a/chrome/browser/ui/webui/chromeos/login/error_screen_handler.h b/chrome/browser/ui/webui/chromeos/login/error_screen_handler.h
index d79f03da..efe8c73 100644
--- a/chrome/browser/ui/webui/chromeos/login/error_screen_handler.h
+++ b/chrome/browser/ui/webui/chromeos/login/error_screen_handler.h
@@ -25,6 +25,12 @@
   void Bind(ErrorScreen* screen) override;
   void Unbind() override;
   void ShowOobeScreen(OobeScreen screen) override;
+  void SetErrorStateCode(NetworkError::ErrorState error_state) override;
+  void SetErrorStateNetwork(const std::string& network_name) override;
+  void SetGuestSigninAllowed(bool value) override;
+  void SetOfflineSigninAllowed(bool value) override;
+  void SetShowConnectingIndicator(bool value) override;
+  void SetUIState(NetworkError::UIState ui_state) override;
 
   // WebUIMessageHandler:
   void RegisterMessages() override;
@@ -46,7 +52,7 @@
   // Whether the error screen is currently shown.
   bool showing_ = false;
 
-  base::WeakPtrFactory<ErrorScreenHandler> weak_ptr_factory_;
+  base::WeakPtrFactory<ErrorScreenHandler> weak_ptr_factory_{this};
 
   DISALLOW_COPY_AND_ASSIGN(ErrorScreenHandler);
 };