Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * Class to communicate with the background scripts via chrome runtime | |
| 8 * messages to | |
| 9 * 1. Forward session state notifications | |
| 10 * 2. Closes the window when the session terminates | |
| 11 */ | |
| 12 | |
| 13 'use strict'; | |
| 14 | |
| 15 /** @suppress {duplicate} */ | |
| 16 var remoting = remoting || {}; | |
| 17 | |
| 18 /** | |
| 19 * @constructor | |
| 20 */ | |
| 21 remoting.HangoutSession = function() { | |
| 22 /** | |
| 23 * @private | |
| 24 * @type {chrome.extension.Port} | |
| 25 */ | |
| 26 this.port_ = null; | |
| 27 }; | |
| 28 | |
| 29 remoting.HangoutSession.prototype.init = function() { | |
| 30 this.port_ = chrome.runtime.connect({name: 'it2me.helper.webapp'}); | |
| 31 | |
| 32 remoting.hangoutSessionEvents.addEventListener( | |
| 33 remoting.hangoutSessionEvents.sessionStateChanged, | |
| 34 this.onSessionStateChanged_.bind(this)); | |
| 35 }; | |
| 36 | |
| 37 /** | |
| 38 * @param {remoting.ClientSession.State} state | |
| 39 */ | |
| 40 remoting.HangoutSession.prototype.onSessionStateChanged_ = function(state) { | |
| 41 var State = remoting.ClientSession.State; | |
| 42 try { | |
| 43 this.port_.postMessage({method: 'sessionStateChanged', state: state}); | |
| 44 } catch (e) { | |
| 45 // postMessage will throw an exception if the port is disconnected. | |
| 46 // We can safely ignore this exception. | |
| 47 } finally { | |
| 48 if (state === State.FAILED || state === State.CLOSED) { | |
| 49 // close the current window | |
| 50 if (remoting.isAppsV2) { | |
| 51 chrome.app.window.current().close(); | |
| 52 } else { | |
| 53 window.close(); | |
| 54 } | |
| 55 } | |
| 56 } | |
| 57 }; | |
| 58 | |
| 59 | |
| 60 | |
|
Jamie
2014/08/08 01:24:12
Three blank lines is overkill :) I suggest two, si
kelvinp
2014/08/08 18:58:50
Done.
| |
| 61 /** | |
| 62 * remoting.clientSession does not exist until the session is connected. | |
| 63 * hangoutSessionEvents serves as a global event source to plumb session | |
| 64 * state changes until we cleanup clientSession and sessionConnector. | |
| 65 * @type {base.EventSource} | |
| 66 */ | |
| 67 remoting.hangoutSessionEvents = new base.EventSource(); | |
| 68 | |
| 69 /** @type {string} */ | |
| 70 remoting.hangoutSessionEvents.sessionStateChanged = "sessionStateChanged"; | |
| 71 | |
| 72 remoting.hangoutSessionEvents.defineEvents( | |
| 73 [remoting.hangoutSessionEvents.sessionStateChanged]); | |
| OLD | NEW |