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

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

Issue 844503007: Fix CRD opens a window every time it's clicked in the launcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address CL feedback 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 | « no previous file | remoting/webapp/js_proto/chrome_proto.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/background.js
diff --git a/remoting/webapp/crd/js/background.js b/remoting/webapp/crd/js/background.js
index 03ec6ef49319f8c473001029cbadc0ea27608e03..f3d5bea5c98d5ece80db81bb4df89631552f72fc 100644
--- a/remoting/webapp/crd/js/background.js
+++ b/remoting/webapp/crd/js/background.js
@@ -7,33 +7,58 @@ var remoting = remoting || {};
(function(){
-/** @param {remoting.AppLauncher} appLauncher */
-function initializeAppV2(appLauncher) {
- /** @type {string} */
- var kNewWindowId = 'new-window';
-
- /** @param {OnClickData} info */
- function onContextMenu(info) {
- if (info.menuItemId == kNewWindowId) {
- appLauncher.launch();
- }
- }
+/**
+ * A class that handles application activation.
+ *
+ * @param {remoting.AppLauncher} appLauncher
+ * @constructor
+ */
+function ActivationHandler(appLauncher) {
+ /**
+ * @type {remoting.AppLauncher}
+ * @private
+ */
+ this.appLauncher_ = appLauncher;
- function initializeContextMenu() {
- chrome.contextMenus.create({
- id: kNewWindowId,
- contexts: ['launcher'],
- title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW')
- });
- chrome.contextMenus.onClicked.addListener(onContextMenu);
- }
+ chrome.contextMenus.create({
+ id: ActivationHandler.NEW_WINDOW_MENU_ID_,
+ contexts: ['launcher'],
+ title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW')
+ });
- initializeContextMenu();
- chrome.app.runtime.onLaunched.addListener(
- appLauncher.launch.bind(appLauncher)
- );
+ chrome.contextMenus.onClicked.addListener(this.onContextMenu_.bind(this));
+ chrome.app.runtime.onLaunched.addListener(this.onLaunched_.bind(this));
}
+/** @type {string} */
+ActivationHandler.NEW_WINDOW_MENU_ID_ = 'new-window';
+
+/**
+ * @param {OnClickData} info
+ * @private
+ */
+ActivationHandler.prototype.onContextMenu_ = function(info) {
+ if (info.menuItemId == ActivationHandler.NEW_WINDOW_MENU_ID_) {
+ this.appLauncher_.launch();
+ }
+};
+
+/**
+ * Called when the App is activated (e.g. from the Chrome App Launcher). It
+ * creates a new window if there are no existing ones. Otherwise, it will put
+ * focus on the last window created.
+ *
+ * @private
+ */
+ActivationHandler.prototype.onLaunched_ = function() {
+ var windows = chrome.app.window.getAll();
+ if (windows.length >= 1) {
+ windows[windows.length - 1].focus();
+ } else {
+ this.appLauncher_.launch();
+ }
+};
+
/**
* The background service is responsible for listening to incoming connection
* requests from Hangouts and the webapp.
@@ -61,8 +86,7 @@ function initializeBackgroundService(appLauncher) {
function main() {
if (base.isAppsV2()) {
- var appLauncher = new remoting.V2AppLauncher();
- initializeAppV2(appLauncher);
+ new ActivationHandler(new remoting.V2AppLauncher());
}
}
« no previous file with comments | « no previous file | remoting/webapp/js_proto/chrome_proto.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698