From 06ce0d64c62f455a2d901f2c9087895d5b3a9c9e Mon Sep 17 00:00:00 2001 From: "kelvinp@chromium.org" Date: Fri, 8 Aug 2014 23:24:39 +0000 Subject: [PATCH] Hangout remote desktop part I - It2Me mode This CL enables the user to launch the chrome remote desktop app directly into an immersive it2me helper session. In the immersive session, the app will 1. hide the home screen 2. create an hrd_helper_session object to communicate with the it2me_background service. Review URL: https://codereview.chromium.org/439923002 Cr-Commit-Position: refs/heads/master@{#288466} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288466 0039d316-1c4b-4281-b951-d872f2087c98 --- remoting/remoting_webapp_files.gypi | 1 + remoting/webapp/client_screen.js | 13 ++++- remoting/webapp/hangout_session.js | 72 ++++++++++++++++++++++++ remoting/webapp/html/template_main.html | 2 +- remoting/webapp/js_proto/chrome_proto.js | 6 ++ remoting/webapp/main.css | 6 +- remoting/webapp/remoting.js | 10 ++++ 7 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 remoting/webapp/hangout_session.js diff --git a/remoting/remoting_webapp_files.gypi b/remoting/remoting_webapp_files.gypi index 070f89900c26b9..93b74bb18be896 100644 --- a/remoting/remoting_webapp_files.gypi +++ b/remoting/remoting_webapp_files.gypi @@ -46,6 +46,7 @@ 'webapp/client_screen.js', 'webapp/client_session.js', 'webapp/clipboard.js', + 'webapp/hangout_session.js', 'webapp/media_source_renderer.js', 'webapp/session_connector.js', 'webapp/smart_reconnector.js', diff --git a/remoting/webapp/client_screen.js b/remoting/webapp/client_screen.js index cb54aa358610d9..f1f0bac225af4c 100644 --- a/remoting/webapp/client_screen.js +++ b/remoting/webapp/client_screen.js @@ -55,7 +55,7 @@ remoting.onVisibilityChanged = function() { remoting.clientSession.pauseVideo( ('hidden' in document) ? document.hidden : document.webkitHidden); } -} +}; /** * Disconnect the remoting client. @@ -89,6 +89,9 @@ function onClientStateChange_(state) { if (remoting.clientSession.getMode() == remoting.ClientSession.Mode.IT2ME) { remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME); + remoting.hangoutSessionEvents.raiseEvent( + remoting.hangoutSessionEvents.sessionStateChanged, + remoting.ClientSession.State.CLOSED); } else { remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); } @@ -133,6 +136,10 @@ function showConnectError_(errorTag) { : remoting.connector.getConnectionMode(); if (mode == remoting.ClientSession.Mode.IT2ME) { remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); + remoting.hangoutSessionEvents.raiseEvent( + remoting.hangoutSessionEvents.sessionStateChanged, + remoting.ClientSession.State.FAILED + ); } else { remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); } @@ -317,6 +324,10 @@ remoting.onConnected = function(clientSession) { remoting.toolbar.preview(); remoting.clipboard.startSession(); updateStatistics_(); + remoting.hangoutSessionEvents.raiseEvent( + remoting.hangoutSessionEvents.sessionStateChanged, + remoting.ClientSession.State.CONNECTED + ); if (remoting.connector.pairingRequested) { /** * @param {string} clientId diff --git a/remoting/webapp/hangout_session.js b/remoting/webapp/hangout_session.js new file mode 100644 index 00000000000000..7f11ee308ed625 --- /dev/null +++ b/remoting/webapp/hangout_session.js @@ -0,0 +1,72 @@ +// Copyright 2014 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. + +/** + * @fileoverview + * Class to communicate with the background scripts via chrome runtime + * messages to + * 1. Forward session state notifications + * 2. Closes the window when the session terminates + */ + +'use strict'; + +/** @suppress {duplicate} */ +var remoting = remoting || {}; + +/** + * @constructor + */ +remoting.HangoutSession = function() { + /** + * @private + * @type {chrome.extension.Port} + */ + this.port_ = null; +}; + +remoting.HangoutSession.prototype.init = function() { + this.port_ = chrome.runtime.connect({name: 'it2me.helper.webapp'}); + + remoting.hangoutSessionEvents.addEventListener( + remoting.hangoutSessionEvents.sessionStateChanged, + this.onSessionStateChanged_.bind(this)); +}; + +/** + * @param {remoting.ClientSession.State} state + */ +remoting.HangoutSession.prototype.onSessionStateChanged_ = function(state) { + var State = remoting.ClientSession.State; + try { + this.port_.postMessage({method: 'sessionStateChanged', state: state}); + } catch (e) { + // postMessage will throw an exception if the port is disconnected. + // We can safely ignore this exception. + } finally { + if (state === State.FAILED || state === State.CLOSED) { + // close the current window + if (remoting.isAppsV2) { + chrome.app.window.current().close(); + } else { + window.close(); + } + } + } +}; + + +/** + * remoting.clientSession does not exist until the session is connected. + * hangoutSessionEvents serves as a global event source to plumb session + * state changes until we cleanup clientSession and sessionConnector. + * @type {base.EventSource} + */ +remoting.hangoutSessionEvents = new base.EventSource(); + +/** @type {string} */ +remoting.hangoutSessionEvents.sessionStateChanged = "sessionStateChanged"; + +remoting.hangoutSessionEvents.defineEvents( + [remoting.hangoutSessionEvents.sessionStateChanged]); \ No newline at end of file diff --git a/remoting/webapp/html/template_main.html b/remoting/webapp/html/template_main.html index e49551dc4f182c..f0a29de61431d6 100644 --- a/remoting/webapp/html/template_main.html +++ b/remoting/webapp/html/template_main.html @@ -38,7 +38,7 @@
-