| Index: remoting/webapp/crd/js/background.js
|
| diff --git a/remoting/webapp/crd/js/background.js b/remoting/webapp/crd/js/background.js
|
| index fd2e41de623798d6bcdf503e9266d0f72ceb3bc4..96f2833d9545d0327eb88738f14d7436660fe77d 100644
|
| --- a/remoting/webapp/crd/js/background.js
|
| +++ b/remoting/webapp/crd/js/background.js
|
| @@ -9,45 +9,71 @@ var remoting = remoting || {};
|
|
|
| 'use strict';
|
|
|
| +var ENABLE_HANGOUT_REMOTE_ASSISTANCE = true;
|
| +
|
| /**
|
| - * The background service is responsible for listening to incoming connection
|
| - * requests from Hangouts and the webapp.
|
| - *
|
| - * @param {remoting.AppLauncher} appLauncher
|
| + * @constructor
|
| */
|
| -function initializeBackgroundService(appLauncher) {
|
| - function initializeIt2MeService() {
|
| - /** @type {remoting.It2MeService} */
|
| - remoting.it2meService = new remoting.It2MeService(appLauncher);
|
| - remoting.it2meService.init();
|
| - }
|
| +var BackgroundPage = function() {
|
| + /** @private {remoting.AppLauncher} */
|
| + this.appLauncher_ = null;
|
| + /** @private {remoting.ActivationHandler} */
|
| + this.activationHandler_ = null;
|
| + /** @private {remoting.It2MeService} */
|
| + this.it2meService_ = null;
|
| + /** @private {base.Disposables} */
|
| + this.disposables_ = null;
|
|
|
| - chrome.runtime.onSuspend.addListener(function() {
|
| - base.debug.assert(remoting.it2meService != null);
|
| - remoting.it2meService.dispose();
|
| - remoting.it2meService = null;
|
| - });
|
| + this.preInit_();
|
| + this.onResumed_();
|
|
|
| - remoting.settings = new remoting.Settings();
|
| + chrome.runtime.onSuspendCanceled.addListener(this.onResumed_.bind(this));
|
| + chrome.runtime.onSuspend.addListener(this.onSuspended_.bind(this));
|
| +};
|
|
|
| - chrome.runtime.onSuspendCanceled.addListener(initializeIt2MeService);
|
| - initializeIt2MeService();
|
| -}
|
| +/**
|
| + * Initialize members and globals that are valid throughout the entire lifetime
|
| + * of the background page.
|
| + *
|
| + * @private
|
| + */
|
| +BackgroundPage.prototype.preInit_ = function() {
|
| + remoting.settings = new remoting.Settings();
|
| + if (base.isAppsV2()) {
|
| + remoting.identity = new remoting.Identity();
|
| + } else {
|
| + remoting.oauth2 = new remoting.OAuth2();
|
| + var oauth2 = /** @type {*} */ (remoting.oauth2);
|
| + remoting.identity = /** @type {remoting.Identity} */ (oauth2);
|
| + }
|
|
|
| -function main() {
|
| if (base.isAppsV2()) {
|
| - new remoting.ActivationHandler(base.Ipc.getInstance(),
|
| - new remoting.V2AppLauncher());
|
| + this.appLauncher_ = new remoting.V2AppLauncher();
|
| + this.activationHandler_ = new remoting.ActivationHandler(
|
| + base.Ipc.getInstance(), this.appLauncher_);
|
| + } else {
|
| + this.appLauncher_ = new remoting.V1AppLauncher();
|
| }
|
| -}
|
| +};
|
| +
|
| +/** @private */
|
| +BackgroundPage.prototype.onResumed_ = function() {
|
| + if (ENABLE_HANGOUT_REMOTE_ASSISTANCE) {
|
| + this.it2meService_ = new remoting.It2MeService(this.appLauncher_);
|
| + this.it2meService_.init();
|
| + this.disposables_ = new base.Disposables(this.it2meService_);
|
| + }
|
| +};
|
|
|
| -remoting.enableHangoutsRemoteAssistance = function() {
|
| - /** @type {remoting.AppLauncher} */
|
| - var appLauncher = base.isAppsV2() ? new remoting.V1AppLauncher():
|
| - new remoting.V2AppLauncher();
|
| - initializeBackgroundService(appLauncher);
|
| +/** @private */
|
| +BackgroundPage.prototype.onSuspended_ = function() {
|
| + this.it2meService_ = null;
|
| + base.dispose(this.disposables_);
|
| + this.disposables_ = null;
|
| };
|
|
|
| -window.addEventListener('load', main, false);
|
| +window.addEventListener('load', function() {
|
| + remoting.backgroundPage = new BackgroundPage();
|
| +}, false);
|
|
|
| }());
|
|
|