From 46c2064c3f4af9437ed87ffdb777978d37f47366 Mon Sep 17 00:00:00 2001
From: joedow <joedow@chromium.org>
Date: Mon, 31 Oct 2016 13:29:51 -0700
Subject: [PATCH] CRD Webapp changes to support Confirmation Dialog It2Me state

This change adds a new state to the CRD webapp.  This state
is sent to the Webapp/client to indicate that the remote user has
started the connection process but has not yet completed it.  For our
purposes, this state will signal that the local user must take action
(i.e. click Share on the confirmation dialog) and we can use it to
updated the text / UI state on the local machine.

The strings and webapp dialog are also updated to inform the user that
an action is required on their part to complete the process.

BUG=658459

Review-Url: https://codereview.chromium.org/2453193004
Cr-Commit-Position: refs/heads/master@{#428790}
---
 remoting/resources/remoting_strings.grd   |  5 ++++-
 remoting/webapp/base/js/ui_mode.js        |  1 +
 remoting/webapp/crd/html/dialog_host.html |  5 +++++
 remoting/webapp/crd/js/host_screen.js     |  5 +++++
 remoting/webapp/crd/js/host_session.js    | 13 +++++++------
 5 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/remoting/resources/remoting_strings.grd b/remoting/resources/remoting_strings.grd
index 374cad28a32da..afc2a5008bb3e 100644
--- a/remoting/resources/remoting_strings.grd
+++ b/remoting/resources/remoting_strings.grd
@@ -870,7 +870,10 @@ For information about privacy, please see the Google Privacy Policy (http://goo.
         To begin sharing your desktop, give the access code below to the person who will be assisting you.
       </message>
       <message desc="Instructions shown below the access code when it is ready to be conveyed to the client." name="IDS_INSTRUCTIONS_SHARE_BELOW">
-        Once they enter the code your sharing session will begin.
+        Once they enter the code, you will be prompted to accept the connection and begin the sharing session.
+      </message>
+      <message desc="Instructions shown when the local user must accept or reject the incoming connection request."  name="IDS_INSTRUCTIONS_SHARE_PROMPT">
+        Please select '<ph name="SHARE">$1<ex>Share</ex></ph>' on the connection dialog box to complete the process.
       </message>
       <message desc="An error message displayed if the user enters an invalid PIN while setting up a host." name="IDS_INVALID_PIN">
         Please enter a PIN consisting of six or more digits.
diff --git a/remoting/webapp/base/js/ui_mode.js b/remoting/webapp/base/js/ui_mode.js
index 07ad094f5a588..aa8375dd1802b 100644
--- a/remoting/webapp/base/js/ui_mode.js
+++ b/remoting/webapp/base/js/ui_mode.js
@@ -29,6 +29,7 @@ remoting.AppMode = {
     HOST: 'home.host',
       HOST_WAITING_FOR_CODE: 'home.host.waiting-for-code',
       HOST_WAITING_FOR_CONNECTION: 'home.host.waiting-for-connection',
+      HOST_WAITING_FOR_ACCEPT: 'home.host.waiting-for-accept',
       HOST_SHARED: 'home.host.shared',
       HOST_SHARE_FAILED: 'home.host.share-failed',
       HOST_SHARE_FINISHED: 'home.host.share-finished',
diff --git a/remoting/webapp/crd/html/dialog_host.html b/remoting/webapp/crd/html/dialog_host.html
index 7e054722cfd75..adc752ae5122c 100644
--- a/remoting/webapp/crd/html/dialog_host.html
+++ b/remoting/webapp/crd/html/dialog_host.html
@@ -64,4 +64,9 @@ found in the LICENSE file.
     <button id="cancel-share-button" i18n-content="CANCEL"></button>
   </div>
 
+  <div data-ui-mode="home.host.waiting-for-accept">
+    <span i18n-content="INSTRUCTIONS_SHARE_PROMPT"
+          i18n-value-name-1="SHARE_CONFIRM_DIALOG_CONFIRM" ></span>
+  </div>
+
 </div> <!-- host dialog -->
diff --git a/remoting/webapp/crd/js/host_screen.js b/remoting/webapp/crd/js/host_screen.js
index c4f2ac193792a..3cfaa267e117a 100644
--- a/remoting/webapp/crd/js/host_screen.js
+++ b/remoting/webapp/crd/js/host_screen.js
@@ -170,6 +170,11 @@ function onHostStateChanged_(state) {
       remoting.cancelShare();
     }
 
+  } else if (state == remoting.HostSession.State.CONNECTING) {
+    console.log('Host state: CONNECTING');
+    remoting.setMode(remoting.AppMode.HOST_WAITING_FOR_ACCEPT);
+    disableTimeoutCountdown_();
+
   } else if (state == remoting.HostSession.State.CONNECTED) {
     console.log('Host state: CONNECTED');
     var element = document.getElementById('host-shared-message');
diff --git a/remoting/webapp/crd/js/host_session.js b/remoting/webapp/crd/js/host_session.js
index 1736dadd82825..36de90246ad33 100644
--- a/remoting/webapp/crd/js/host_session.js
+++ b/remoting/webapp/crd/js/host_session.js
@@ -25,8 +25,8 @@ remoting.HostSession = function() {
   this.hostFacade_ = null;
 };
 
-// Note that these values are copied directly from host_script_object.h and
-// must be kept in sync.
+// Note that these values are copied directly from it2me_host.h and must be kept
+// in sync.
 /** @enum {number} */
 remoting.HostSession.State = {
   UNKNOWN: -1,
@@ -34,10 +34,11 @@ remoting.HostSession.State = {
   STARTING: 1,
   REQUESTED_ACCESS_CODE: 2,
   RECEIVED_ACCESS_CODE: 3,
-  CONNECTED: 4,
-  DISCONNECTING: 5,
-  ERROR: 6,
-  INVALID_DOMAIN_ERROR: 7
+  CONNECTING: 4,
+  CONNECTED: 5,
+  DISCONNECTING: 6,
+  ERROR: 7,
+  INVALID_DOMAIN_ERROR: 8,
 };
 
 remoting.HostSession.prototype.dispose = function() {