Commit 927308a4 authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Add shelf item for lacros canary browser shortcut

Add a new ShelfItemType for TYPE_LACROS_BROWSER, following the pattern
of TYPE_BROWSER_SHORTCUT. Wire it to its own ShelfItemDelegate in
//chrome/browser/ui/ash. For now, the icon does nothing when clicked.
We need to wire it to upstart to actually start the browser.

Bug: 1072472
Test: manually deploy to device, two browser icons appear

Change-Id: I12578745f627df4452fcd99fe41716eedfb834d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2155991
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762044}
parent 38d898c5
...@@ -20,6 +20,7 @@ static ShelfModel* g_shelf_model = nullptr; ...@@ -20,6 +20,7 @@ static ShelfModel* g_shelf_model = nullptr;
int ShelfItemTypeToWeight(ShelfItemType type) { int ShelfItemTypeToWeight(ShelfItemType type) {
switch (type) { switch (type) {
case TYPE_BROWSER_SHORTCUT: case TYPE_BROWSER_SHORTCUT:
case TYPE_LACROS_BROWSER:
case TYPE_PINNED_APP: case TYPE_PINNED_APP:
return 1; return 1;
case TYPE_APP: case TYPE_APP:
......
...@@ -18,13 +18,15 @@ constexpr char kDelimiter[] = "|"; ...@@ -18,13 +18,15 @@ constexpr char kDelimiter[] = "|";
bool IsValidShelfItemType(int64_t type) { bool IsValidShelfItemType(int64_t type) {
return type == TYPE_PINNED_APP || type == TYPE_BROWSER_SHORTCUT || return type == TYPE_PINNED_APP || type == TYPE_BROWSER_SHORTCUT ||
type == TYPE_APP || type == TYPE_DIALOG || type == TYPE_UNDEFINED; type == TYPE_LACROS_BROWSER || type == TYPE_APP ||
type == TYPE_DIALOG || type == TYPE_UNDEFINED;
} }
bool IsPinnedShelfItemType(ShelfItemType type) { bool IsPinnedShelfItemType(ShelfItemType type) {
switch (type) { switch (type) {
case TYPE_PINNED_APP: case TYPE_PINNED_APP:
case TYPE_BROWSER_SHORTCUT: case TYPE_BROWSER_SHORTCUT:
case TYPE_LACROS_BROWSER:
return true; return true;
case TYPE_APP: case TYPE_APP:
case TYPE_DIALOG: case TYPE_DIALOG:
......
...@@ -146,6 +146,10 @@ enum ShelfItemType { ...@@ -146,6 +146,10 @@ enum ShelfItemType {
// The browser shortcut button, the browser may be running or not. // The browser shortcut button, the browser may be running or not.
TYPE_BROWSER_SHORTCUT, TYPE_BROWSER_SHORTCUT,
// Represents the lacros "linux-chrome" browser. The browser may or may not
// be running.
TYPE_LACROS_BROWSER,
// Represents an unpinned running app window. Supports these app types: // Represents an unpinned running app window. Supports these app types:
// - Extension "V1" (legacy packaged and hosted) apps, // - Extension "V1" (legacy packaged and hosted) apps,
// - Extension "V2" (platform) apps, // - Extension "V2" (platform) apps,
......
...@@ -228,6 +228,7 @@ bool ShelfButtonIsInDrag(const ShelfItemType item_type, ...@@ -228,6 +228,7 @@ bool ShelfButtonIsInDrag(const ShelfItemType item_type,
switch (item_type) { switch (item_type) {
case TYPE_PINNED_APP: case TYPE_PINNED_APP:
case TYPE_BROWSER_SHORTCUT: case TYPE_BROWSER_SHORTCUT:
case TYPE_LACROS_BROWSER:
case TYPE_APP: case TYPE_APP:
return static_cast<const ShelfAppButton*>(item_view)->state() & return static_cast<const ShelfAppButton*>(item_view)->state() &
ShelfAppButton::STATE_DRAGGING; ShelfAppButton::STATE_DRAGGING;
...@@ -674,6 +675,7 @@ void ShelfView::ButtonPressed(views::Button* sender, ...@@ -674,6 +675,7 @@ void ShelfView::ButtonPressed(views::Button* sender,
switch (model_->items()[last_pressed_index_].type) { switch (model_->items()[last_pressed_index_].type) {
case TYPE_PINNED_APP: case TYPE_PINNED_APP:
case TYPE_BROWSER_SHORTCUT: case TYPE_BROWSER_SHORTCUT:
case TYPE_LACROS_BROWSER:
case TYPE_APP: case TYPE_APP:
Shell::Get()->metrics()->RecordUserMetricsAction( Shell::Get()->metrics()->RecordUserMetricsAction(
UMA_LAUNCHER_CLICK_ON_APP); UMA_LAUNCHER_CLICK_ON_APP);
...@@ -968,6 +970,7 @@ views::View* ShelfView::CreateViewForItem(const ShelfItem& item) { ...@@ -968,6 +970,7 @@ views::View* ShelfView::CreateViewForItem(const ShelfItem& item) {
switch (item.type) { switch (item.type) {
case TYPE_PINNED_APP: case TYPE_PINNED_APP:
case TYPE_BROWSER_SHORTCUT: case TYPE_BROWSER_SHORTCUT:
case TYPE_LACROS_BROWSER:
case TYPE_APP: case TYPE_APP:
case TYPE_DIALOG: { case TYPE_DIALOG: {
ShelfAppButton* button = new ShelfAppButton( ShelfAppButton* button = new ShelfAppButton(
...@@ -1878,6 +1881,7 @@ void ShelfView::ShelfItemChanged(int model_index, const ShelfItem& old_item) { ...@@ -1878,6 +1881,7 @@ void ShelfView::ShelfItemChanged(int model_index, const ShelfItem& old_item) {
switch (item.type) { switch (item.type) {
case TYPE_PINNED_APP: case TYPE_PINNED_APP:
case TYPE_BROWSER_SHORTCUT: case TYPE_BROWSER_SHORTCUT:
case TYPE_LACROS_BROWSER:
case TYPE_APP: case TYPE_APP:
case TYPE_DIALOG: { case TYPE_DIALOG: {
CHECK_EQ(ShelfAppButton::kViewClassName, view->GetClassName()); CHECK_EQ(ShelfAppButton::kViewClassName, view->GetClassName());
......
...@@ -269,6 +269,7 @@ api::autotest_private::ShelfItemType GetShelfItemType(ash::ShelfItemType type) { ...@@ -269,6 +269,7 @@ api::autotest_private::ShelfItemType GetShelfItemType(ash::ShelfItemType type) {
SHELF_ITEM_TYPE_BROWSERSHORTCUT; SHELF_ITEM_TYPE_BROWSERSHORTCUT;
case ash::TYPE_DIALOG: case ash::TYPE_DIALOG:
return api::autotest_private::ShelfItemType::SHELF_ITEM_TYPE_DIALOG; return api::autotest_private::ShelfItemType::SHELF_ITEM_TYPE_DIALOG;
case ash::TYPE_LACROS_BROWSER: // TODO(jamescook): Add autotest support.
case ash::TYPE_UNDEFINED: case ash::TYPE_UNDEFINED:
return api::autotest_private::ShelfItemType::SHELF_ITEM_TYPE_NONE; return api::autotest_private::ShelfItemType::SHELF_ITEM_TYPE_NONE;
} }
......
...@@ -1633,6 +1633,8 @@ jumbo_static_library("ui") { ...@@ -1633,6 +1633,8 @@ jumbo_static_library("ui") {
"ash/launcher/extension_shelf_context_menu.h", "ash/launcher/extension_shelf_context_menu.h",
"ash/launcher/extension_uninstaller.cc", "ash/launcher/extension_uninstaller.cc",
"ash/launcher/extension_uninstaller.h", "ash/launcher/extension_uninstaller.h",
"ash/launcher/lacros_browser_shelf_item_delegate.cc",
"ash/launcher/lacros_browser_shelf_item_delegate.h",
"ash/launcher/launcher_app_updater.cc", "ash/launcher/launcher_app_updater.cc",
"ash/launcher/launcher_app_updater.h", "ash/launcher/launcher_app_updater.h",
"ash/launcher/launcher_controller_helper.cc", "ash/launcher/launcher_controller_helper.cc",
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
#include "chrome/browser/ui/ash/launcher/crostini_app_window_shelf_controller.h" #include "chrome/browser/ui/ash/launcher/crostini_app_window_shelf_controller.h"
#include "chrome/browser/ui/ash/launcher/internal_app_window_shelf_controller.h" #include "chrome/browser/ui/ash/launcher/internal_app_window_shelf_controller.h"
#include "chrome/browser/ui/ash/launcher/lacros_browser_shelf_item_delegate.h"
#include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
#include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h"
#include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_controller.h"
...@@ -81,6 +82,7 @@ ...@@ -81,6 +82,7 @@
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h" #include "chrome/grit/theme_resources.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h" #include "chrome/services/app_service/public/mojom/types.mojom.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/strings/grit/chromeos_strings.h" #include "chromeos/strings/grit/chromeos_strings.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/arc/arc_prefs.h" #include "components/arc/arc_prefs.h"
...@@ -93,6 +95,7 @@ ...@@ -93,6 +95,7 @@
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/management_policy.h" #include "extensions/browser/management_policy.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -104,6 +107,7 @@ ...@@ -104,6 +107,7 @@
using extension_misc::kChromeAppId; using extension_misc::kChromeAppId;
using extension_misc::kGmailAppId; using extension_misc::kGmailAppId;
using extension_misc::kLacrosAppId;
namespace { namespace {
...@@ -333,6 +337,8 @@ ChromeLauncherController::~ChromeLauncherController() { ...@@ -333,6 +337,8 @@ ChromeLauncherController::~ChromeLauncherController() {
void ChromeLauncherController::Init() { void ChromeLauncherController::Init() {
CreateBrowserShortcutLauncherItem(); CreateBrowserShortcutLauncherItem();
if (chromeos::features::IsLacrosSideBySideEnabled())
CreateLacrosBrowserShortcut();
UpdateAppLaunchersFromSync(); UpdateAppLaunchersFromSync();
} }
...@@ -1214,6 +1220,25 @@ void ChromeLauncherController::CreateBrowserShortcutLauncherItem() { ...@@ -1214,6 +1220,25 @@ void ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
item_controller->UpdateBrowserItemState(); item_controller->UpdateBrowserItemState();
} }
void ChromeLauncherController::CreateLacrosBrowserShortcut() {
// See CreateBrowserShortcutLauncherItem().
ScopedPinSyncDisabler scoped_pin_sync_disabler = GetScopedPinSyncDisabler();
ash::ShelfItem shortcut;
shortcut.type = ash::TYPE_LACROS_BROWSER;
shortcut.id = ash::ShelfID(kLacrosAppId);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
// TODO(jamescook): Custom icon.
shortcut.image = *rb.GetImageSkiaNamed(IDR_CHROME_APP_ICON_192);
// TODO(jamescook): Real name.
shortcut.title = base::ASCIIToUTF16("LaCrOS");
// Set the delegate first to avoid constructing another one in ShelfItemAdded.
model_->SetShelfItemDelegate(
shortcut.id, std::make_unique<LacrosBrowserShelfItemDelegate>());
// Add the item towards the start of the shelf, it will be ordered by weight.
model_->AddAt(1, shortcut);
}
int ChromeLauncherController::FindInsertionPoint() { int ChromeLauncherController::FindInsertionPoint() {
for (int i = model_->item_count() - 1; i > 0; --i) { for (int i = model_->item_count() - 1; i > 0; --i) {
if (ItemTypeIsPinned(model_->items()[i])) if (ItemTypeIsPinned(model_->items()[i]))
......
...@@ -352,6 +352,9 @@ class ChromeLauncherController ...@@ -352,6 +352,9 @@ class ChromeLauncherController
// Create the Chrome browser shortcut ShelfItem. // Create the Chrome browser shortcut ShelfItem.
void CreateBrowserShortcutLauncherItem(); void CreateBrowserShortcutLauncherItem();
// Creates the Lacros browser shortcut ShelfItem.
void CreateLacrosBrowserShortcut();
// Finds the index of where to insert the next item. // Finds the index of where to insert the next item.
int FindInsertionPoint(); int FindInsertionPoint();
......
// Copyright 2020 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.
#include "chrome/browser/ui/ash/launcher/lacros_browser_shelf_item_delegate.h"
#include "ash/public/cpp/shelf_types.h"
#include "base/logging.h"
#include "extensions/common/constants.h"
LacrosBrowserShelfItemDelegate::LacrosBrowserShelfItemDelegate()
: ash::ShelfItemDelegate(ash::ShelfID(extension_misc::kLacrosAppId)) {}
LacrosBrowserShelfItemDelegate::~LacrosBrowserShelfItemDelegate() = default;
void LacrosBrowserShelfItemDelegate::ItemSelected(
std::unique_ptr<ui::Event> event,
int64_t display_id,
ash::ShelfLaunchSource source,
ItemSelectedCallback callback) {
// TODO(lacros): Handle window activation, window minimize, and spawning a
// menu with a list of browser windows.
NOTIMPLEMENTED() << "Launch lacros-chrome via upstart";
std::move(callback).Run(ash::SHELF_ACTION_NEW_WINDOW_CREATED, {});
}
void LacrosBrowserShelfItemDelegate::ExecuteCommand(bool from_context_menu,
int64_t command_id,
int32_t event_flags,
int64_t display_id) {
if (from_context_menu && ExecuteContextMenuCommand(command_id, event_flags))
return;
// TODO(lacros): Handle custom context menu commands.
}
void LacrosBrowserShelfItemDelegate::Close() {
// TODO(lacros): Close all browser windows.
}
// Copyright 2020 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.
#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_LACROS_BROWSER_SHELF_ITEM_DELEGATE_H_
#define CHROME_BROWSER_UI_ASH_LAUNCHER_LACROS_BROWSER_SHELF_ITEM_DELEGATE_H_
#include "ash/public/cpp/shelf_item_delegate.h"
// Shelf item delegate for the lacros-chrome browser shortcut; only one such
// item should exist.
class LacrosBrowserShelfItemDelegate : public ash::ShelfItemDelegate {
public:
LacrosBrowserShelfItemDelegate();
LacrosBrowserShelfItemDelegate(const LacrosBrowserShelfItemDelegate&) =
delete;
LacrosBrowserShelfItemDelegate& operator=(
const LacrosBrowserShelfItemDelegate&) = delete;
~LacrosBrowserShelfItemDelegate() override;
// ash::ShelfItemDelegate:
void ItemSelected(std::unique_ptr<ui::Event> event,
int64_t display_id,
ash::ShelfLaunchSource source,
ItemSelectedCallback callback) override;
void ExecuteCommand(bool from_context_menu,
int64_t command_id,
int32_t event_flags,
int64_t display_id) override;
void Close() override;
};
#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_LACROS_BROWSER_SHELF_ITEM_DELEGATE_H_
...@@ -227,6 +227,12 @@ const base::Feature kVirtualKeyboardFloatingDefault{ ...@@ -227,6 +227,12 @@ const base::Feature kVirtualKeyboardFloatingDefault{
const base::Feature kInstantTethering{"InstantTethering", const base::Feature kInstantTethering{"InstantTethering",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
// See kLacrosSupport below. This feature also enables a separate icon in the
// shelf and app list representing the lacros-chrome browser, much like how
// Windows supports a side-by-side installation of Chrome canary.
const base::Feature kLacrosSideBySide{"LacrosSideBySide",
base::FEATURE_DISABLED_BY_DEFAULT};
// Enables "Linux and Chrome OS" support. Allows a Linux version of Chrome // Enables "Linux and Chrome OS" support. Allows a Linux version of Chrome
// ("lacros-chrome") to run as a Wayland client with this instance of Chrome // ("lacros-chrome") to run as a Wayland client with this instance of Chrome
// ("ash-chrome") acting as the Wayland server and window manager. // ("ash-chrome") acting as the Wayland server and window manager.
...@@ -411,6 +417,10 @@ bool IsInstantTetheringBackgroundAdvertisingSupported() { ...@@ -411,6 +417,10 @@ bool IsInstantTetheringBackgroundAdvertisingSupported() {
kInstantTetheringBackgroundAdvertisementSupport); kInstantTetheringBackgroundAdvertisementSupport);
} }
bool IsLacrosSideBySideEnabled() {
return base::FeatureList::IsEnabled(kLacrosSideBySide);
}
bool IsLacrosSupportEnabled() { bool IsLacrosSupportEnabled() {
return base::FeatureList::IsEnabled(kLacrosSupport); return base::FeatureList::IsEnabled(kLacrosSupport);
} }
......
...@@ -105,6 +105,8 @@ COMPONENT_EXPORT(CHROMEOS_CONSTANTS) ...@@ -105,6 +105,8 @@ COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const base::Feature kVirtualKeyboardFloatingDefault; extern const base::Feature kVirtualKeyboardFloatingDefault;
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const base::Feature kInstantTethering; extern const base::Feature kInstantTethering;
COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const base::Feature kLacrosSideBySide;
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const base::Feature kLacrosSupport; COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const base::Feature kLacrosSupport;
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const base::Feature kMediaApp; COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const base::Feature kMediaApp;
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
...@@ -182,6 +184,7 @@ COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsEduCoexistenceEnabled(); ...@@ -182,6 +184,7 @@ COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsEduCoexistenceEnabled();
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsImeDecoderWithSandboxEnabled(); COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsImeDecoderWithSandboxEnabled();
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
bool IsInstantTetheringBackgroundAdvertisingSupported(); bool IsInstantTetheringBackgroundAdvertisingSupported();
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsLacrosSideBySideEnabled();
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsLacrosSupportEnabled(); COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsLacrosSupportEnabled();
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsOobeScreensPriorityEnabled(); COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsOobeScreensPriorityEnabled();
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsParentalControlsSettingsEnabled(); COMPONENT_EXPORT(CHROMEOS_CONSTANTS) bool IsParentalControlsSettingsEnabled();
......
...@@ -119,6 +119,8 @@ const char kMimeHandlerPrivateTestExtensionId[] = ...@@ -119,6 +119,8 @@ const char kMimeHandlerPrivateTestExtensionId[] =
const char kCameraAppId[] = "hfhhnacclhffhdffklopdkcgdhifgngh"; const char kCameraAppId[] = "hfhhnacclhffhdffklopdkcgdhifgngh";
const char kCameraAppDevId[] = "flgnmkgjffmkephdokeeliiopbjaafpm"; const char kCameraAppDevId[] = "flgnmkgjffmkephdokeeliiopbjaafpm";
const char kChromeAppId[] = "mgndgikekgjfcpckkfioiadnlibdjbkf"; const char kChromeAppId[] = "mgndgikekgjfcpckkfioiadnlibdjbkf";
// Generated by: echo "lacros-chrome" | sha256sum | head -c32 | tr 0-9a-f a-p
const char kLacrosAppId[] = "jaimifaeiicidiikhmjedcgdimealfbh";
const char kFilesManagerAppId[] = "hhaomjibdihmijegdhdafkllkbggdgoj"; const char kFilesManagerAppId[] = "hhaomjibdihmijegdhdafkllkbggdgoj";
const char kGoogleKeepAppId[] = "hmjkmjkepdijhoojdojkdfohbdgmmhki"; const char kGoogleKeepAppId[] = "hmjkmjkepdijhoojdojkdfohbdgmmhki";
const char kYoutubeAppId[] = "blpcfgokakmgnkcojhhkbfbldkacnbeo"; const char kYoutubeAppId[] = "blpcfgokakmgnkcojhhkbfbldkacnbeo";
......
...@@ -204,6 +204,9 @@ extern const char kCameraAppDevId[]; ...@@ -204,6 +204,9 @@ extern const char kCameraAppDevId[];
// The extension id of the Chrome component application. // The extension id of the Chrome component application.
extern const char kChromeAppId[]; extern const char kChromeAppId[];
// Fake extension ID for the Lacros chrome browser application.
extern const char kLacrosAppId[];
// The extension id of the Files Manager application. // The extension id of the Files Manager application.
extern const char kFilesManagerAppId[]; extern const char kFilesManagerAppId[];
......
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