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.
7 * This class implements the functionality that is specific to application
8 * remoting ("AppRemoting" or AR).
13 /** @suppress {duplicate} */
14 var remoting
= remoting
|| {};
17 * Parameters for the remoting.AppRemoting constructor.
19 * appId: The application ID. If this is not specified than the app id will
20 * be extracted from the app's manifest.
22 * appCapabilites: Array of application capabilites.
24 * licenseManager: Licence manager for this application.
27 * appId: (string|undefined),
28 * appCapabilities: (Array<string>|undefined),
29 * licenseManager: (remoting.LicenseManager|undefined)
32 remoting
.AppRemotingParams
;
35 * @param {remoting.AppRemotingParams} args
37 * @implements {remoting.ApplicationInterface}
38 * @extends {remoting.Application}
40 remoting
.AppRemoting = function(args
) {
41 base
.inherits(this, remoting
.Application
);
44 // Save recent errors for inclusion in user feedback.
45 remoting
.ConsoleWrapper
.getInstance().activate(
47 remoting
.ConsoleWrapper
.LogType
.ERROR
,
48 remoting
.ConsoleWrapper
.LogType
.ASSERT
);
50 /** @private {remoting.Activity} */
51 this.activity_
= null;
53 /** @private {string} */
54 this.appId_
= (args
.appId
) ? args
.appId
: chrome
.runtime
.id
;
57 this.licenseManager_
= (args
.licenseManager
) ?
59 new remoting
.GaiaLicenseManager();
62 this.appCapabilities_
= (args
.appCapabilities
) ? args
.appCapabilities
: [];
64 // This prefix must be added to message window paths so that the HTML
65 // files can be found in the shared module.
66 // TODO(garykac) Add support for dev/prod shared modules.
67 remoting
.MessageWindow
.htmlFilePrefix
=
68 "_modules/koejkfhmphamcgafjmkellhnekdkopod/";
72 * @return {string} Application Id.
73 * @override {remoting.ApplicationInterface}
75 remoting
.AppRemoting
.prototype.getApplicationId = function() {
80 * @return {string} Application product name to be used in UI.
81 * @override {remoting.ApplicationInterface}
83 remoting
.AppRemoting
.prototype.getApplicationName = function() {
84 var manifest
= chrome
.runtime
.getManifest();
88 remoting
.AppRemoting
.prototype.getActivity = function() {
89 return this.activity_
;
93 * @param {!remoting.Error} error The failure reason.
94 * @override {remoting.ApplicationInterface}
96 remoting
.AppRemoting
.prototype.signInFailed_ = function(error
) {
97 remoting
.MessageWindow
.showErrorMessage(
98 this.getApplicationName(),
99 chrome
.i18n
.getMessage(error
.getTag()));
103 * @override {remoting.ApplicationInterface}
105 remoting
.AppRemoting
.prototype.initApplication_ = function() {
106 remoting
.messageWindowManager
= new remoting
.MessageWindowManager(
107 /** @type {base.WindowMessageDispatcher} */
108 (this.windowMessageDispatcher_
));
112 * @param {string} token An OAuth access token.
113 * @override {remoting.ApplicationInterface}
115 remoting
.AppRemoting
.prototype.startApplication_ = function(token
) {
116 var windowShape
= new remoting
.WindowShape();
117 windowShape
.updateClientWindowShape();
120 this.licenseManager_
.getSubscriptionToken(token
).then(
121 function(/** string*/ subscriptionToken
) {
122 that
.activity_
= new remoting
.AppRemotingActivity(
123 that
.appCapabilities_
, that
, windowShape
, subscriptionToken
,
124 /** @type {base.WindowMessageDispatcher} */
125 (that
.windowMessageDispatcher_
));
126 that
.activity_
.start();
131 * @override {remoting.ApplicationInterface}
133 remoting
.AppRemoting
.prototype.exitApplication_ = function() {
134 if (this.activity_
) {
135 this.activity_
.stop();
136 this.activity_
.dispose();
137 this.activity_
= null;
139 this.closeMainWindow_();