Commit 72ecaf0c authored by Ben Wells's avatar Ben Wells Committed by Commit Bot

Update chrome://apps for bookmark apps that aren't locally installed.

When bookmark apps aren't locally installed, they should be dimmed out
and they should have the launch type, app info and create shortcuts
menus removed.

This change also cleans up the logic that shows these menus and moved
it to C++ where it is easier to reason about.

Bug: 874841
Change-Id: Ia6af16a383c6f4434ac9da9e49882186c2c20015
Reviewed-on: https://chromium-review.googlesource.com/1195124Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Commit-Queue: Ben Wells <benwells@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587920}
parent 2364c68c
...@@ -80,13 +80,11 @@ cr.define('ntp', function() { ...@@ -80,13 +80,11 @@ cr.define('ntp', function() {
this.uninstall_.addEventListener( this.uninstall_.addEventListener(
'activate', this.onUninstall_.bind(this)); 'activate', this.onUninstall_.bind(this));
if (!cr.isChromeOS) { this.createShortcutSeparator_ =
this.createShortcutSeparator_ = menu.appendChild(cr.ui.MenuItem.createSeparator());
menu.appendChild(cr.ui.MenuItem.createSeparator()); this.createShortcut_ = this.appendMenuItem_('appcreateshortcut');
this.createShortcut_ = this.appendMenuItem_('appcreateshortcut'); this.createShortcut_.addEventListener(
this.createShortcut_.addEventListener( 'activate', this.onCreateShortcut_.bind(this));
'activate', this.onCreateShortcut_.bind(this));
}
document.body.appendChild(menu); document.body.appendChild(menu);
}, },
...@@ -143,11 +141,11 @@ cr.define('ntp', function() { ...@@ -143,11 +141,11 @@ cr.define('ntp', function() {
launchTypeButton.disabled = false; launchTypeButton.disabled = false;
launchTypeButton.checked = app.appData.launch_type == id; launchTypeButton.checked = app.appData.launch_type == id;
// There are three cases when a launch type is hidden: // There are three cases when a launch type is hidden:
// 1. packaged apps hide all launch types // 1. if the launch type can't be changed.
// 2. canHostedAppsOpenInWindows is false and type is launchTypeWindow // 2. canHostedAppsOpenInWindows is false and type is launchTypeWindow
// 3. enableNewBookmarkApps is true and type is anything except // 3. enableNewBookmarkApps is true and type is anything except
// launchTypeWindow // launchTypeWindow
launchTypeButton.hidden = app.appData.packagedApp || launchTypeButton.hidden = !app.appData.mayChangeLaunchType ||
(!loadTimeData.getBoolean('canHostedAppsOpenInWindows') && (!loadTimeData.getBoolean('canHostedAppsOpenInWindows') &&
launchTypeButton == launchTypeWindow) || launchTypeButton == launchTypeWindow) ||
(loadTimeData.getBoolean('enableNewBookmarkApps') && (loadTimeData.getBoolean('enableNewBookmarkApps') &&
...@@ -157,20 +155,16 @@ cr.define('ntp', function() { ...@@ -157,20 +155,16 @@ cr.define('ntp', function() {
}); });
this.launchTypeMenuSeparator_.hidden = this.launchTypeMenuSeparator_.hidden =
app.appData.packagedApp || !hasLaunchType; !app.appData.mayChangeLaunchType || !hasLaunchType;
this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled; this.options_.disabled = !app.appData.optionsUrl || !app.appData.enabled;
if (this.details_) if (this.details_)
this.details_.disabled = !app.appData.detailsUrl; this.details_.disabled = !app.appData.detailsUrl;
this.uninstall_.disabled = !app.appData.mayDisable; this.uninstall_.disabled = !app.appData.mayDisable;
this.appinfo_.hidden = !app.appData.isLocallyInstalled;
if (cr.isMac) { this.createShortcutSeparator_.hidden = this.createShortcut_.hidden =
// On Windows and Linux, these should always be visible. On ChromeOS, !app.appData.mayCreateShortcuts;
// they are never created. On Mac, shortcuts can only be created for
// new-style packaged apps, so hide the menu item.
this.createShortcutSeparator_.hidden = this.createShortcut_.hidden =
!app.appData.packagedApp;
}
}, },
/** @private */ /** @private */
...@@ -345,7 +339,7 @@ cr.define('ntp', function() { ...@@ -345,7 +339,7 @@ cr.define('ntp', function() {
setIcon: function() { setIcon: function() {
var src = this.useSmallIcon_ ? this.appData_.icon_small : var src = this.useSmallIcon_ ? this.appData_.icon_small :
this.appData_.icon_big; this.appData_.icon_big;
if (!this.appData_.enabled || if (!this.appData_.enabled || !this.appData_.isLocallyInstalled ||
(!this.appData_.offlineEnabled && !navigator.onLine)) { (!this.appData_.offlineEnabled && !navigator.onLine)) {
src += '?grayscale=true'; src += '?grayscale=true';
} }
......
...@@ -26,11 +26,14 @@ ...@@ -26,11 +26,14 @@
* id: string, * id: string,
* is_component: boolean, * is_component: boolean,
* is_webstore: boolean, * is_webstore: boolean,
* isLocallyInstalled: boolean,
* kioskEnabled: boolean, * kioskEnabled: boolean,
* kioskMode: boolean, * kioskMode: boolean,
* kioskOnly: boolean, * kioskOnly: boolean,
* launch_container: number, * launch_container: number,
* launch_type: number, * launch_type: number,
* mayChangeLaunchType: boolean,
* mayCreateShortcuts: boolean,
* mayDisable: boolean, * mayDisable: boolean,
* name: string, * name: string,
* offlineEnabled: boolean, * offlineEnabled: boolean,
......
...@@ -20,11 +20,13 @@ ...@@ -20,11 +20,13 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_ui_util.h" #include "chrome/browser/extensions/extension_ui_util.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/launch_util.h" #include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -41,6 +43,7 @@ ...@@ -41,6 +43,7 @@
#include "chrome/browser/ui/webui/extensions/extension_basic_info.h" #include "chrome/browser/ui/webui/extensions/extension_basic_info.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_util.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_constants.h"
...@@ -150,6 +153,22 @@ void AppLauncherHandler::CreateAppInfo(const Extension* extension, ...@@ -150,6 +153,22 @@ void AppLauncherHandler::CreateAppInfo(const Extension* extension,
service->profile())->management_policy()->UserMayModifySettings( service->profile())->management_policy()->UserMayModifySettings(
extension, NULL)); extension, NULL));
bool is_locally_installed =
!extension->is_hosted_app() ||
BookmarkAppIsLocallyInstalled(service->profile(), extension);
value->SetBoolean("mayChangeLaunchType",
!extension->is_platform_app() && is_locally_installed);
#if defined(OS_MACOSX)
// On Mac, only packaged apps can have shortcuts created.
value->SetBoolean("mayCreateShortcuts", extension->is_platform_app());
#else
// On other platforms, any locally installed app can have shortcuts created.
value->SetBoolean("mayCreateShortcuts", is_locally_installed);
#endif
value->SetBoolean("isLocallyInstalled", is_locally_installed);
auto icon_size = extension_misc::EXTENSION_ICON_LARGE; auto icon_size = extension_misc::EXTENSION_ICON_LARGE;
auto match_type = ExtensionIconSet::MATCH_BIGGER; auto match_type = ExtensionIconSet::MATCH_BIGGER;
bool has_non_default_large_icon = bool has_non_default_large_icon =
......
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