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

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: Address CR Feedbacks 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..78afd7eace0828a98962bc48a2626d85609f2592
--- /dev/null
+++ b/remoting/webapp/background/app_launcher.js
@@ -0,0 +1,132 @@
+// 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 that allows the client code to launch and close
+ * the app without knowing the implementation difference between a v1 app and
+ * a v2 app.
+ *
+ * To launch an app:
+ * var appLauncher = new remoting.V1AppLauncher();
+ * var appId = "";
+ * appLauncher.launch({arg1:'someValue'}).then(function(id){
+ * appId = id;
+ * });
+ *
+ * To close an app:
+ * appLauncher.close(appId);
Jamie 2014/08/12 20:42:54 Nit: Code samples stand out better if they're inde
kelvinp 2014/08/12 21:42:42 Done.
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/** @interface */
+remoting.AppLauncher = function() {};
+
+/**
+ * @param {Object=} opt_launchArgs
+ * @return {Promise} The promise will resolve when the app is launched. It will
+ * provide the caller with the appId (which is either the id of the hosting tab
+ * or window). The caller can use the appId to close the app.
+ */
+remoting.AppLauncher.prototype.launch = function(opt_launchArgs) { };
+
+/**
+ * @param {string} id The id of the app to close.
+ * @return {Promise} The promise will resolve when the app is closed.
+ */
+remoting.AppLauncher.prototype.close = function(id) {};
+
+/**
+ * @constructor
+ * @implements {remoting.AppLauncher}
+ */
+remoting.V1AppLauncher = function() {};
+
+remoting.V1AppLauncher.prototype.launch = function(opt_launchArgs) {
+ var url = base.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 },
+ /** @param {chrome.Tab} tab The created tab. */
+ function(tab) {
+ if (!tab) {
+ reject(new Error(chrome.runtime.lastError.message));
+ } 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(new Error(chrome.runtime.lastError.message));
+ } else {
+ chrome.tabs.remove(tab.id, resolve);
+ }
+ });
+ });
+};
+
+
+/**
+ * @constructor
+ * @implements {remoting.AppLauncher}
+ */
+remoting.V2AppLauncher = function() {};
+
+/**
+ * @type {number}
+ * @private
+ */
+remoting.V2AppLauncher.nextWindowId_ = 0;
+
+remoting.V2AppLauncher.prototype.launch = function(opt_launchArgs) {
+ var url = base.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': String(remoting.V2AppLauncher.nextWindowId_++)
+ },
+ /** @param {AppWindow} appWindow */
+ function(appWindow) {
+ if (!appWindow) {
+ reject(new Error(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(new Error(chrome.runtime.lastError.message));
+ }
+ appWindow.close();
+ return Promise.resolve();
+};

Powered by Google App Engine
This is Rietveld 408576698