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

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

Issue 450383003: Hangout remote desktop part II - background.html and AppLauncher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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/background/app_launcher.js
diff --git a/remoting/webapp/background/app_launcher.js b/remoting/webapp/background/app_launcher.js
new file mode 100644
index 0000000000000000000000000000000000000000..a6159dc76fbfe252732f5381e3456e0778152fc3
--- /dev/null
+++ b/remoting/webapp/background/app_launcher.js
@@ -0,0 +1,135 @@
+// 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
+ * AppLauncher is an interface for app launching closing implementations.
+ * It nows the client code to launch and close the app without knowing the
+ * implementation difference between launching a v1 app and a v2 app.
Jamie 2014/08/12 02:24:56 Can you clean up this comment? Specifically, I don
kelvinp 2014/08/12 18:22:44 Done.
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/** @interface */
+remoting.AppLauncher = function() {};
+
+/**
+ * @param {Object=} opt_launchArgs
+ * @return {Promise}
Jamie 2014/08/12 02:24:56 The methods of this interface need descriptions, o
Jamie 2014/08/12 02:24:56 Make it clear that when the Promise resolves, it w
kelvinp 2014/08/12 18:22:44 Done.
+ */
+remoting.AppLauncher.prototype.launch = function(opt_launchArgs) { };
Jamie 2014/08/12 02:24:56 Nit: No space between braces.
kelvinp 2014/08/12 18:22:44 Done.
+
+/**
+ * @param {string} id The id of the tab/window to close.
+ * @return {Promise}
+ */
+remoting.AppLauncher.prototype.close = function(id) {};
+
+/**
+ * @param {string} url
+ * @param {Object.<string>=} opt_params
+ * @return {string}
+ */
+remoting.AppLauncher.urlJoin = function(url, opt_params) {
Jamie 2014/08/12 02:24:56 Interfaces should not have concrete methods, and i
kelvinp 2014/08/12 18:22:44 Moved to base.js
+ if (!opt_params) {
+ return url;
+ }
+ var queryParameters = [];
+ for (var key in opt_params) {
+ queryParameters.push(encodeURIComponent(key) + "=" +
+ encodeURIComponent(opt_params[key]));
+ }
+ return url + '?' + queryParameters.join('&');
+};
+
+/**
+ * @constructor
+ * @implements {remoting.AppLauncher}
+ */
+remoting.V1AppLauncher = function() {};
+
+remoting.V1AppLauncher.prototype.launch = function(opt_launchArgs) {
+ var url = remoting.AppLauncher.urlJoin('main.html', opt_launchArgs);
+
+ /**
+ * @param {function(*=):void} resolve
+ * @param {function(*=):void} reject
+ */
+ return new Promise(function(resolve, reject) {
+ chrome.tabs.create({ url: url, selected: true},
Jamie 2014/08/12 02:24:56 Nit: No space after '{' (or add one after 'true').
kelvinp 2014/08/12 18:22:44 Done.
+ /** @param {chrome.Tab} tab The created tab. */
+ function(tab) {
+ if (!tab) {
+ reject(chrome.runtime.lastError);
Jamie 2014/08/12 02:24:56 Is it better to use new Error to get a stack trace
+ } else {
+ resolve(tab.id);
+ }
+ });
+ });
+};
+
+remoting.V1AppLauncher.prototype.close = function(id) {
+ /**
+ * @param {function(*=):void} resolve
+ * @param {function(*=):void} reject
+ */
+ return new Promise(function(resolve, reject) {
+ /** @param {chrome.Tab} tab The retrieved tab. */
+ chrome.tabs.get(id, function(tab) {
+ if (!tab) {
+ reject(chrome.runtime.lastError.message);
Jamie 2014/08/12 02:24:56 Why .message here but not in launch?
kelvinp 2014/08/12 18:22:44 Good catch. Typo in launch
+ } else {
+ chrome.tabs.remove(tab.id, function(){
Jamie 2014/08/12 02:24:56 Do you need the wrapper function?
kelvinp 2014/08/12 18:22:44 Done.
+ resolve();
+ });
+ }
+ });
+ });
+};
+
+
+/**
+ * @constructor
+ * @implements {remoting.AppLauncher}
+ */
+remoting.V2AppLauncher = function() {};
+
+remoting.V2AppLauncher.nextWindowId_ = 0;
Jamie 2014/08/12 02:24:56 @type and @private annotations, please.
+
+remoting.V2AppLauncher.prototype.launch = function(opt_launchArgs) {
+ var url = remoting.AppLauncher.urlJoin('main.html', opt_launchArgs);
+
+ /**
+ * @param {function(*=):void} resolve
+ * @param {function(*=):void} reject
+ */
+ return new Promise(function(resolve, reject) {
+ chrome.app.window.create(url, {
+ 'width': 800,
+ 'height': 600,
+ 'frame': 'none',
+ 'id': "hangout" + remoting.V2AppLauncher.nextWindowId_++
Jamie 2014/08/12 02:24:56 I think the id would be better managed by the call
kelvinp 2014/08/12 18:22:44 You are right. Prefix removed.
+ },
+ /** @param {AppWindow} appWindow */
+ function(appWindow) {
+ if (!appWindow) {
+ reject(chrome.runtime.lastError.message);
+ } else {
+ resolve(appWindow.id);
+ }
+ });
+ });
+};
+
+remoting.V2AppLauncher.prototype.close = function(id) {
+ var appWindow = chrome.app.window.get(id);
+ if (!appWindow) {
+ return Promise.reject(chrome.runtime.lastError.message);
+ }
+ appWindow.close();
+ return Promise.resolve();
+};

Powered by Google App Engine
This is Rietveld 408576698