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

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: Rebase 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
« no previous file with comments | « remoting/webapp/crd/js/activation_handler.js ('k') | remoting/webapp/crd/js/background.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9257d3dbfd47eee89046d073ce52462174963082..4bf03c74f8e8f16f1af22a11a626f25142752644 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,22 @@ 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) {
+ this.close(id).then(function() {
+ // Not using the launch() method because we want to launch a new window with
+ // the same id, such that the size and positioning of the original window
+ // can be preserved.
+ return chrome.app.window.create(APP_MAIN_URL, {'id' : id, 'frame': 'none'});
+ });
+};
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
@@ -114,7 +124,7 @@ remoting.V2AppLauncher.prototype.launch = function(opt_launchArgs) {
'width': 800,
'height': 600,
'frame': 'none',
- 'id': String(remoting.V2AppLauncher.nextWindowId_++),
+ 'id': String(getNextWindowId()),
'state': state
},
/** @param {AppWindow=} appWindow */
@@ -131,10 +141,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;
+}
+
+})();
« no previous file with comments | « remoting/webapp/crd/js/activation_handler.js ('k') | remoting/webapp/crd/js/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698