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 /** @type {base.EventSource} */ | |
| 33 var HangoutSessionEvents = remoting.HangoutSessionEvents; | |
|
Jamie
2014/08/07 23:12:35
No need for this assignment.
kelvinp
2014/08/08 01:14:22
Done.
| |
| 34 HangoutSessionEvents.addEventListener( | |
| 35 remoting.HangoutSessionEvents.sessionStateChanged, | |
| 36 this.onSessionStateChanged_.bind(this)); | |
| 37 }; | |
| 38 | |
| 39 /** | |
| 40 * @param {remoting.HangoutSessionEvents.SessionStates} state | |
| 41 */ | |
| 42 remoting.HangoutSession.prototype.onSessionStateChanged_ = function(state) { | |
| 43 var State = remoting.HangoutSessionEvents.SessionStates; | |
| 44 try { | |
| 45 this.port_.postMessage({method: 'sessionStateChanged', state: state}); | |
| 46 } catch (e) { | |
| 47 // postMessage will throw an exception if the port is disconnected. | |
| 48 // We can safely ignore this exception. | |
| 49 } finally { | |
| 50 if (state === State.ERROR || state === State.CLOSED) { | |
| 51 // close the current window | |
| 52 if (remoting.isAppsV2) { | |
| 53 chrome.app.window.current().close(); | |
| 54 } else { | |
| 55 window.close(); | |
| 56 } | |
| 57 } | |
| 58 } | |
| 59 }; | |
| OLD | NEW |