Index: remoting/webapp/hrd_helper_session.js |
diff --git a/remoting/webapp/hrd_helper_session.js b/remoting/webapp/hrd_helper_session.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1e1f0e847354d5ed36c98ef4c13d084e2fba3c98 |
--- /dev/null |
+++ b/remoting/webapp/hrd_helper_session.js |
@@ -0,0 +1,52 @@ |
+// 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 it2me background service via chrome runtime |
+ * messages. |
Jamie
2014/08/05 21:15:14
To do what? AFAICT, this class does two things:
1
kelvinp
2014/08/07 18:03:25
Done.
|
+ */ |
+ |
+'use strict'; |
+ |
+/** @suppress {duplicate} */ |
+var remoting = remoting || {}; |
+ |
+/** |
+ * @constructor |
+ */ |
+remoting.HRDHelperSession = function() { |
Jamie
2014/08/05 21:15:14
Can you come up with something more descriptive th
kelvinp
2014/08/07 18:03:25
Done.
|
+ /** @type {chrome.extension.Port} */ |
Jamie
2014/08/05 21:15:14
Add @private?
kelvinp
2014/08/07 18:03:25
Done.
|
+ this.port_ = null; |
+ this.onSessionStateChangedHandler_ = this.onSessionStateChanged_.bind(this); |
Jamie
2014/08/05 21:15:13
You only use this in one place, so there's no need
kelvinp
2014/08/07 18:03:25
Done.
|
+}; |
+ |
+remoting.HRDHelperSession.prototype.init = function() { |
+ this.port_ = chrome.runtime.connect({name: 'it2me.helper.webapp'}); |
Jamie
2014/08/05 21:15:13
Are you missing an extension id here? Without one,
kelvinp
2014/08/07 18:03:25
This is intended. According to the documentation,
|
+ |
+ /** @type {base.EventSource} */ |
+ var hrdSessionEvents = remoting.hrdSessionEvents; |
+ hrdSessionEvents.addEventListener('sessionStateChanged', |
+ this.onSessionStateChangedHandler_); |
+}; |
+ |
+/** |
+ * @param {remoting.hrdSessionEvents.SessionStates} state |
+ */ |
+remoting.HRDHelperSession.prototype.onSessionStateChanged_ = function(state) { |
+ var State = remoting.hrdSessionEvents.SessionStates; |
+ try { |
+ this.port_.postMessage({method: 'sessionStateChanged', state: state}); |
+ } catch (e) { |
Jamie
2014/08/05 21:15:13
This ignores any errors. Is that what you want? If
kelvinp
2014/08/07 18:03:25
Done.
|
+ } finally { |
+ if (state === State.ERROR || state === State.CLOSED) { |
+ // close the current window |
+ if (remoting.isAppsV2) { |
+ chrome.app.window.current().close(); |
+ } else { |
+ window.close(); |
+ } |
+ } |
+ } |
+}; |