Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Unified Diff: remoting/webapp/crd/js/app_launcher.js

Issue 868203002: Handle authentication failures in the v2 app by restarting the app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/crd/js/app_launcher.js
diff --git a/remoting/webapp/crd/js/app_launcher.js b/remoting/webapp/crd/js/app_launcher.js
index 29589dfc45f6f8d9ba358d02e4d37b5a6cf75be5..80aefe77b4e063f752c5eca07e9d1052016b9916 100644
--- a/remoting/webapp/crd/js/app_launcher.js
+++ b/remoting/webapp/crd/js/app_launcher.js
@@ -19,11 +19,13 @@
* appLauncher.close(appId);
*/
-'use strict';
-
/** @suppress {duplicate} */
var remoting = remoting || {};
+(function() {
+
+'use strict';
+
/** @interface */
remoting.AppLauncher = function() {};
@@ -91,14 +93,21 @@ remoting.V1AppLauncher.prototype.close = function(id) {
*/
remoting.V2AppLauncher = function() {};
+var APP_MAIN_URL = 'main.html';
+
/**
- * @type {number}
- * @private
+ * @param {string} id
*/
-remoting.V2AppLauncher.nextWindowId_ = 0;
+remoting.V2AppLauncher.prototype.restart = function(id) {
+ base.debug.assert(base.isBackgroundPage(),
+ 'restart() can only be called from the background page');
Jamie 2015/01/23 23:33:26 It would be better if this code file was simply no
kelvinp 2015/01/28 00:26:45 Done.
+ this.close(id).then(function() {
+ return chrome.app.window.create(APP_MAIN_URL, {'id' : id, 'frame': 'none'});
Jamie 2015/01/23 23:33:26 Please add a comment explaining why we're not re-u
kelvinp 2015/01/28 00:26:45 Done.
+ });
+};
remoting.V2AppLauncher.prototype.launch = function(opt_launchArgs) {
- var url = base.urlJoin('main.html', opt_launchArgs);
+ var url = base.urlJoin(APP_MAIN_URL, opt_launchArgs);
/**
* @param {function(*=):void} resolve
@@ -109,7 +118,7 @@ remoting.V2AppLauncher.prototype.launch = function(opt_launchArgs) {
'width': 800,
'height': 600,
'frame': 'none',
- 'id': String(remoting.V2AppLauncher.nextWindowId_++)
+ 'id': String(getNextWindowId())
},
/** @param {AppWindow=} appWindow */
function(appWindow) {
@@ -123,10 +132,35 @@ remoting.V2AppLauncher.prototype.launch = function(opt_launchArgs) {
};
remoting.V2AppLauncher.prototype.close = function(id) {
- var appWindow = chrome.app.window.get(id);
- if (!appWindow) {
- return Promise.reject(new Error(chrome.runtime.lastError.message));
- }
- appWindow.close();
- return Promise.resolve();
+ /**
+ * @param {function(*=):void} resolve
+ * @param {function(*=):void} reject
+ */
+ return new Promise(function(resolve, reject) {
+ var appWindow = chrome.app.window.get(id);
+ if (!appWindow) {
+ return Promise.reject(new Error(chrome.runtime.lastError.message));
+ }
+ appWindow.onClosed.addListener(resolve);
+ appWindow.close();
+ });
};
+
+/**
+ * @return {number} the next available window id.
+ */
+function getNextWindowId() {
+ var appWindows = chrome.app.window.getAll();
+ var lastId = /** @type(number) */ (0);
+ appWindows.forEach(function(appWindow) {
+ base.debug.assert(Number.isInteger(appWindow.id),
+ "Window Id should be an integer");
+ var id = parseInt(appWindow.id, 10);
+ if (lastId <= id) {
+ lastId = id;
+ }
+ });
+ return ++lastId;
+}
+
+})();

Powered by Google App Engine
This is Rietveld 408576698