Commit 81b9425c authored by kelvinp's avatar kelvinp Committed by Commit bot

Fix CRD opens a window every time it's clicked in the launcher

Cause:
This is a regression of the HRD change, in which we pass in an unique
ID everytime when we create an app window.  This causes a new window
to be created whenever the user clicks on the app icon in the app
launcher.

Fix:
Only create a new app window when:
1. There are no existing windows or
2. The user clicks on the New Window context menu

BUG=448128

Review URL: https://codereview.chromium.org/844503007

Cr-Commit-Position: refs/heads/master@{#311545}
parent ee20aa9a
...@@ -7,33 +7,58 @@ var remoting = remoting || {}; ...@@ -7,33 +7,58 @@ var remoting = remoting || {};
(function(){ (function(){
/** @param {remoting.AppLauncher} appLauncher */ /**
function initializeAppV2(appLauncher) { * A class that handles application activation.
/** @type {string} */ *
var kNewWindowId = 'new-window'; * @param {remoting.AppLauncher} appLauncher
* @constructor
/** @param {OnClickData} info */ */
function onContextMenu(info) { function ActivationHandler(appLauncher) {
if (info.menuItemId == kNewWindowId) { /**
appLauncher.launch(); * @type {remoting.AppLauncher}
} * @private
} */
this.appLauncher_ = appLauncher;
function initializeContextMenu() {
chrome.contextMenus.create({ chrome.contextMenus.create({
id: kNewWindowId, id: ActivationHandler.NEW_WINDOW_MENU_ID_,
contexts: ['launcher'], contexts: ['launcher'],
title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW') title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW')
}); });
chrome.contextMenus.onClicked.addListener(onContextMenu);
}
initializeContextMenu(); chrome.contextMenus.onClicked.addListener(this.onContextMenu_.bind(this));
chrome.app.runtime.onLaunched.addListener( chrome.app.runtime.onLaunched.addListener(this.onLaunched_.bind(this));
appLauncher.launch.bind(appLauncher)
);
} }
/** @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 * The background service is responsible for listening to incoming connection
* requests from Hangouts and the webapp. * requests from Hangouts and the webapp.
...@@ -61,8 +86,7 @@ function initializeBackgroundService(appLauncher) { ...@@ -61,8 +86,7 @@ function initializeBackgroundService(appLauncher) {
function main() { function main() {
if (base.isAppsV2()) { if (base.isAppsV2()) {
var appLauncher = new remoting.V2AppLauncher(); new ActivationHandler(new remoting.V2AppLauncher());
initializeAppV2(appLauncher);
} }
} }
......
...@@ -41,7 +41,11 @@ chrome.app.window = { ...@@ -41,7 +41,11 @@ chrome.app.window = {
* @param {string} id * @param {string} id
* @param {function()=} opt_callback * @param {function()=} opt_callback
*/ */
get: function(id, opt_callback) {} get: function(id, opt_callback) {},
/**
* @return {Array.<AppWindow>}
*/
getAll: function() {}
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment