Commit ba01253a authored by nancy's avatar nancy Committed by Commit Bot

Add AppServiceAppWindowLauncherItemController.

Add AppServiceAppWindowLauncherItemController to handle the special
cases for Chrome apps, e.g. OnWindowTitleChanged, GetAppMenuItems,
which is the current implementation in
//src/chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_controller.cc
https://cs.chromium.org/chromium/src/chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_controller.cc?sq=package:chromium&dr=CSs&g=0

BUG=1011235

Change-Id: I24052b7df167011ea5b042082950adae3026e5dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1942892Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722603}
parent 5fbf5a6e
...@@ -3738,6 +3738,8 @@ jumbo_static_library("ui") { ...@@ -3738,6 +3738,8 @@ jumbo_static_library("ui") {
"ash/launcher/app_service_app_window_crostini_tracker.h", "ash/launcher/app_service_app_window_crostini_tracker.h",
"ash/launcher/app_service_app_window_launcher_controller.cc", "ash/launcher/app_service_app_window_launcher_controller.cc",
"ash/launcher/app_service_app_window_launcher_controller.h", "ash/launcher/app_service_app_window_launcher_controller.h",
"ash/launcher/app_service_app_window_launcher_item_controller.cc",
"ash/launcher/app_service_app_window_launcher_item_controller.h",
"ash/launcher/app_service_instance_registry_helper.cc", "ash/launcher/app_service_instance_registry_helper.cc",
"ash/launcher/app_service_instance_registry_helper.h", "ash/launcher/app_service_instance_registry_helper.h",
"ash/launcher/app_window_base.cc", "ash/launcher/app_window_base.cc",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/browser/chromeos/plugin_vm/plugin_vm_util.h" #include "chrome/browser/chromeos/plugin_vm/plugin_vm_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/launcher/app_service_app_window_crostini_tracker.h" #include "chrome/browser/ui/ash/launcher/app_service_app_window_crostini_tracker.h"
#include "chrome/browser/ui/ash/launcher/app_service_app_window_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/app_window_base.h" #include "chrome/browser/ui/ash/launcher/app_window_base.h"
#include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
...@@ -304,7 +305,7 @@ void AppServiceAppWindowLauncherController::AddToShelf( ...@@ -304,7 +305,7 @@ void AppServiceAppWindowLauncherController::AddToShelf(
owner()->shelf_model()->GetAppWindowLauncherItemController(shelf_id); owner()->shelf_model()->GetAppWindowLauncherItemController(shelf_id);
if (item_controller == nullptr) { if (item_controller == nullptr) {
auto controller = auto controller =
std::make_unique<AppWindowLauncherItemController>(shelf_id); std::make_unique<AppServiceAppWindowLauncherItemController>(shelf_id);
item_controller = controller.get(); item_controller = controller.get();
if (!owner()->GetItem(shelf_id)) { if (!owner()->GetItem(shelf_id)) {
owner()->CreateAppLauncherItem(std::move(controller), owner()->CreateAppLauncherItem(std::move(controller),
......
// Copyright 2019 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/app_service_app_window_launcher_item_controller.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h"
#include "components/favicon/content/content_favicon_driver.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/app_window/native_app_window.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/gfx/image/image.h"
AppServiceAppWindowLauncherItemController::
AppServiceAppWindowLauncherItemController(const ash::ShelfID& shelf_id)
: AppWindowLauncherItemController(shelf_id) {}
AppServiceAppWindowLauncherItemController::
~AppServiceAppWindowLauncherItemController() {}
ash::ShelfItemDelegate::AppMenuItems
AppServiceAppWindowLauncherItemController::GetAppMenuItems(int event_flags) {
if (!IsChromeApp())
return GetAppMenuItems(event_flags);
AppMenuItems items;
extensions::AppWindowRegistry* const app_window_registry =
extensions::AppWindowRegistry::Get(
ChromeLauncherController::instance()->profile());
for (const ui::BaseWindow* window : windows()) {
extensions::AppWindow* const app_window =
app_window_registry->GetAppWindowForNativeWindow(
window->GetNativeWindow());
DCHECK(app_window);
// Use the app's web contents favicon, or the app window's icon.
favicon::FaviconDriver* const favicon_driver =
favicon::ContentFaviconDriver::FromWebContents(
app_window->web_contents());
DCHECK(favicon_driver);
gfx::ImageSkia image = favicon_driver->GetFavicon().AsImageSkia();
if (image.isNull()) {
const gfx::ImageSkia* app_icon = nullptr;
if (app_window->GetNativeWindow()) {
app_icon = app_window->GetNativeWindow()->GetProperty(
aura::client::kAppIconKey);
}
if (app_icon && !app_icon->isNull())
image = *app_icon;
}
items.push_back({app_window->GetTitle(), image});
}
return items;
}
void AppServiceAppWindowLauncherItemController::OnWindowTitleChanged(
aura::Window* window) {
if (!IsChromeApp())
return;
// For Chrome apps,Use the window title (if set) to differentiate
// show_in_shelf window shelf items instead of the default behavior of using
// the app name.
ui::BaseWindow* const base_window = GetAppWindow(window);
extensions::AppWindowRegistry* const app_window_registry =
extensions::AppWindowRegistry::Get(
ChromeLauncherController::instance()->profile());
extensions::AppWindow* const app_window =
app_window_registry->GetAppWindowForNativeWindow(
base_window->GetNativeWindow());
// Use the window title (if set) to differentiate show_in_shelf window shelf
// items instead of the default behavior of using the app name.
if (app_window->show_in_shelf()) {
const base::string16 title = window->GetTitle();
if (!title.empty())
ChromeLauncherController::instance()->SetItemTitle(shelf_id(), title);
}
}
bool AppServiceAppWindowLauncherItemController::IsChromeApp() {
Profile* const profile = ChromeLauncherController::instance()->profile();
apps::AppServiceProxy* const proxy =
apps::AppServiceProxyFactory::GetForProfile(profile);
DCHECK(proxy);
return proxy->AppRegistryCache().GetAppType(shelf_id().app_id) ==
apps::mojom::AppType::kExtension;
}
// Copyright 2019 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_APP_SERVICE_APP_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_
#define CHROME_BROWSER_UI_ASH_LAUNCHER_APP_SERVICE_APP_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_
#include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
// Shelf item delegate for extension app windows.
class AppServiceAppWindowLauncherItemController
: public AppWindowLauncherItemController {
public:
explicit AppServiceAppWindowLauncherItemController(
const ash::ShelfID& shelf_id);
~AppServiceAppWindowLauncherItemController() override;
AppServiceAppWindowLauncherItemController(
const AppServiceAppWindowLauncherItemController&) = delete;
AppServiceAppWindowLauncherItemController& operator=(
const AppServiceAppWindowLauncherItemController&) = delete;
// aura::WindowObserver overrides:
void OnWindowTitleChanged(aura::Window* window) override;
// AppWindowLauncherItemController:
AppMenuItems GetAppMenuItems(int event_flags) override;
private:
bool IsChromeApp();
};
#endif // CHROME_BROWSER_UI_ASH_LAUNCHER_APP_SERVICE_APP_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_
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