Commit c586ca3f authored by nancylingwang@google.com's avatar nancylingwang@google.com Committed by Commit Bot

Modify ARC mojom for ARC adaptive icons.

Design doc: go/appservice-adaptive-icon

The related ARC icon interfaces are modified/added to use the new
structure RawIconPngData, and call AppService interfaces to
decode/encode the icon.

The ARC side CL number is 12024464, which has use the new
OnTaskDescriptionUpdated interface. And we can't call both the new and
old task update interfaces, that could cause updating twice for the icon
on the windows, so we have to select 1(the new one) to use in the code.

Once the ARC side CL is submitted, the change on the Chromium side will
be change to use the new interface as soon as possible.

TODO: Add some test cases for adaptive icons and implement the new
interfaces for FakeAppInstance.

Note: Below 2 files will be deleted soon. They are modified to pass the
build:
chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h
chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc

BUG=1083331

Change-Id: I8daaa1643dd20c6038d685863c8f6e71c3948c7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2251600Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarLong Cheng <lgcheng@google.com>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786071}
parent 863b4aad
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_install_utils.h" #include "chrome/browser/web_applications/components/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h" #include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "services/data_decoder/public/cpp/decode_image.h" #include "services/data_decoder/public/cpp/decode_image.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom.h" #include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
...@@ -33,7 +34,7 @@ namespace chromeos { ...@@ -33,7 +34,7 @@ namespace chromeos {
// static // static
void ApkWebAppInstaller::Install(Profile* profile, void ApkWebAppInstaller::Install(Profile* profile,
arc::mojom::WebAppInfoPtr web_app_info, arc::mojom::WebAppInfoPtr web_app_info,
const std::vector<uint8_t>& icon_png_data, arc::mojom::RawIconPngDataPtr icon,
InstallFinishCallback callback, InstallFinishCallback callback,
base::WeakPtr<Owner> weak_owner) { base::WeakPtr<Owner> weak_owner) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
...@@ -44,7 +45,7 @@ void ApkWebAppInstaller::Install(Profile* profile, ...@@ -44,7 +45,7 @@ void ApkWebAppInstaller::Install(Profile* profile,
// CompleteInstallation(). // CompleteInstallation().
auto* installer = auto* installer =
new ApkWebAppInstaller(profile, std::move(callback), weak_owner); new ApkWebAppInstaller(profile, std::move(callback), weak_owner);
installer->Start(std::move(web_app_info), icon_png_data); installer->Start(std::move(web_app_info), std::move(icon));
} }
ApkWebAppInstaller::ApkWebAppInstaller(Profile* profile, ApkWebAppInstaller::ApkWebAppInstaller(Profile* profile,
...@@ -59,7 +60,7 @@ ApkWebAppInstaller::ApkWebAppInstaller(Profile* profile, ...@@ -59,7 +60,7 @@ ApkWebAppInstaller::ApkWebAppInstaller(Profile* profile,
ApkWebAppInstaller::~ApkWebAppInstaller() = default; ApkWebAppInstaller::~ApkWebAppInstaller() = default;
void ApkWebAppInstaller::Start(arc::mojom::WebAppInfoPtr web_app_info, void ApkWebAppInstaller::Start(arc::mojom::WebAppInfoPtr web_app_info,
const std::vector<uint8_t>& icon_png_data) { arc::mojom::RawIconPngDataPtr icon) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!weak_owner_.get()) { if (!weak_owner_.get()) {
CompleteInstallation(web_app::AppId(), CompleteInstallation(web_app::AppId(),
...@@ -69,7 +70,8 @@ void ApkWebAppInstaller::Start(arc::mojom::WebAppInfoPtr web_app_info, ...@@ -69,7 +70,8 @@ void ApkWebAppInstaller::Start(arc::mojom::WebAppInfoPtr web_app_info,
// We can't install without |web_app_info| or |icon_png_data|. They may be // We can't install without |web_app_info| or |icon_png_data|. They may be
// null if there was an error generating the data. // null if there was an error generating the data.
if (web_app_info.is_null() || icon_png_data.empty()) { if (web_app_info.is_null() || !icon || !icon->icon_png_data ||
!icon->icon_png_data.has_value() || icon->icon_png_data->empty()) {
LOG(ERROR) << "Insufficient data to install a web app"; LOG(ERROR) << "Insufficient data to install a web app";
CompleteInstallation(web_app::AppId(), CompleteInstallation(web_app::AppId(),
web_app::InstallResultCode::kApkWebAppInstallFailed); web_app::InstallResultCode::kApkWebAppInstallFailed);
...@@ -100,7 +102,8 @@ void ApkWebAppInstaller::Start(arc::mojom::WebAppInfoPtr web_app_info, ...@@ -100,7 +102,8 @@ void ApkWebAppInstaller::Start(arc::mojom::WebAppInfoPtr web_app_info,
// Decode the image in a sandboxed process off the main thread. // Decode the image in a sandboxed process off the main thread.
// base::Unretained is safe because this object owns itself. // base::Unretained is safe because this object owns itself.
data_decoder::DecodeImageIsolated( data_decoder::DecodeImageIsolated(
icon_png_data, data_decoder::mojom::ImageCodec::DEFAULT, std::move(icon->icon_png_data.value()),
data_decoder::mojom::ImageCodec::DEFAULT,
/*shrink_to_fit=*/false, data_decoder::kDefaultMaxSizeInBytes, /*shrink_to_fit=*/false, data_decoder::kDefaultMaxSizeInBytes,
/*desired_image_frame_size=*/gfx::Size(), /*desired_image_frame_size=*/gfx::Size(),
base::BindOnce(&ApkWebAppInstaller::OnImageDecoded, base::BindOnce(&ApkWebAppInstaller::OnImageDecoded,
......
...@@ -46,7 +46,7 @@ class ApkWebAppInstaller { ...@@ -46,7 +46,7 @@ class ApkWebAppInstaller {
// or an empty id if not. // or an empty id if not.
static void Install(Profile* profile, static void Install(Profile* profile,
arc::mojom::WebAppInfoPtr web_app_info, arc::mojom::WebAppInfoPtr web_app_info,
const std::vector<uint8_t>& icon_png_data, arc::mojom::RawIconPngDataPtr icon,
InstallFinishCallback callback, InstallFinishCallback callback,
base::WeakPtr<Owner> weak_owner); base::WeakPtr<Owner> weak_owner);
...@@ -59,7 +59,7 @@ class ApkWebAppInstaller { ...@@ -59,7 +59,7 @@ class ApkWebAppInstaller {
// Starts the installation flow by decoding icon data. // Starts the installation flow by decoding icon data.
void Start(arc::mojom::WebAppInfoPtr web_app_info, void Start(arc::mojom::WebAppInfoPtr web_app_info,
const std::vector<uint8_t>& icon_png_data); arc::mojom::RawIconPngDataPtr icon);
// Calls |callback_| with |id|, and deletes this object. Virtual for testing. // Calls |callback_| with |id|, and deletes this object. Virtual for testing.
virtual void CompleteInstallation(const web_app::AppId& id, virtual void CompleteInstallation(const web_app::AppId& id,
......
...@@ -29,14 +29,17 @@ arc::mojom::WebAppInfoPtr GetWebAppInfo() { ...@@ -29,14 +29,17 @@ arc::mojom::WebAppInfoPtr GetWebAppInfo() {
constexpr int kGeneratedIconSize = 128; constexpr int kGeneratedIconSize = 128;
const std::vector<uint8_t> GetIconBytes() { arc::mojom::RawIconPngDataPtr GetIconBytes() {
auto fake_app_instance = auto fake_app_instance =
std::make_unique<arc::FakeAppInstance>(/*app_host=*/nullptr); std::make_unique<arc::FakeAppInstance>(/*app_host=*/nullptr);
std::string png_data_as_string; std::string png_data_as_string;
EXPECT_TRUE(fake_app_instance->GenerateIconResponse( EXPECT_TRUE(fake_app_instance->GenerateIconResponse(
kGeneratedIconSize, /*app_icon=*/true, &png_data_as_string)); kGeneratedIconSize, /*app_icon=*/true, &png_data_as_string));
return std::vector<uint8_t>(png_data_as_string.begin(), arc::mojom::RawIconPngDataPtr icon = arc::mojom::RawIconPngData::New();
png_data_as_string.end()); icon->is_adaptive_icon = false;
icon->icon_png_data = std::vector<uint8_t>(png_data_as_string.begin(),
png_data_as_string.end());
return icon;
} }
} // namespace } // namespace
......
...@@ -443,8 +443,11 @@ void ApkWebAppService::OnDidGetWebAppIcon( ...@@ -443,8 +443,11 @@ void ApkWebAppService::OnDidGetWebAppIcon(
const std::string& package_name, const std::string& package_name,
arc::mojom::WebAppInfoPtr web_app_info, arc::mojom::WebAppInfoPtr web_app_info,
const std::vector<uint8_t>& icon_png_data) { const std::vector<uint8_t>& icon_png_data) {
arc::mojom::RawIconPngDataPtr icon = arc::mojom::RawIconPngData::New();
icon->is_adaptive_icon = false;
icon->icon_png_data = std::vector<uint8_t>(icon_png_data);
ApkWebAppInstaller::Install( ApkWebAppInstaller::Install(
profile_, std::move(web_app_info), icon_png_data, profile_, std::move(web_app_info), std::move(icon),
base::BindOnce(&ApkWebAppService::OnDidFinishInstall, base::BindOnce(&ApkWebAppService::OnDidFinishInstall,
weak_ptr_factory_.GetWeakPtr(), package_name), weak_ptr_factory_.GetWeakPtr(), package_name),
weak_ptr_factory_.GetWeakPtr()); weak_ptr_factory_.GetWeakPtr());
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "chrome/browser/ui/app_list/arc/arc_package_syncable_service.h" #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service.h"
#include "chrome/browser/ui/app_list/arc/arc_pai_starter.h" #include "chrome/browser/ui/app_list/arc/arc_pai_starter.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
...@@ -121,16 +122,17 @@ class NotificationsEnabledDeferred { ...@@ -121,16 +122,17 @@ class NotificationsEnabledDeferred {
PrefService* const prefs_; PrefService* const prefs_;
}; };
bool InstallIconFromFileThread(const base::FilePath& icon_path, bool WriteIconFile(const base::FilePath& icon_path,
const std::vector<uint8_t>& content_png) { const std::vector<uint8_t>& icon_png_data) {
DCHECK(!content_png.empty()); if (icon_png_data.empty())
return false;
base::CreateDirectory(icon_path.DirName()); base::CreateDirectory(icon_path.DirName());
int wrote = int wrote = base::WriteFile(icon_path,
base::WriteFile(icon_path, reinterpret_cast<const char*>(&content_png[0]), reinterpret_cast<const char*>(&icon_png_data[0]),
content_png.size()); icon_png_data.size());
if (wrote != static_cast<int>(content_png.size())) { if (wrote != static_cast<int>(icon_png_data.size())) {
VLOG(2) << "Failed to write ARC icon file: " << icon_path.MaybeAsASCII() VLOG(2) << "Failed to write ARC icon file: " << icon_path.MaybeAsASCII()
<< "."; << ".";
if (!base::DeleteFile(icon_path)) { if (!base::DeleteFile(icon_path)) {
...@@ -139,6 +141,33 @@ bool InstallIconFromFileThread(const base::FilePath& icon_path, ...@@ -139,6 +141,33 @@ bool InstallIconFromFileThread(const base::FilePath& icon_path,
} }
return false; return false;
} }
return true;
}
bool InstallIconFromFileThread(const base::FilePath& icon_path,
const base::FilePath& foreground_icon_path,
const base::FilePath& background_icon_path,
arc::mojom::RawIconPngDataPtr icon) {
const std::vector<uint8_t>& icon_png_data = icon->icon_png_data.value();
DCHECK(!icon_png_data.empty());
if (!WriteIconFile(icon_path, icon_png_data))
return false;
if (!base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon) ||
!icon->is_adaptive_icon) {
return true;
}
if (!WriteIconFile(foreground_icon_path,
icon->foreground_icon_png_data.value())) {
return false;
}
if (!WriteIconFile(background_icon_path,
icon->background_icon_png_data.value())) {
return false;
}
return true; return true;
} }
...@@ -1598,7 +1627,29 @@ void ArcAppListPrefs::OnIcon(const std::string& app_id, ...@@ -1598,7 +1627,29 @@ void ArcAppListPrefs::OnIcon(const std::string& app_id,
return; return;
} }
InstallIcon(app_id, descriptor, icon_png_data); arc::mojom::RawIconPngDataPtr icon = arc::mojom::RawIconPngData::New();
icon->is_adaptive_icon = false;
icon->icon_png_data =
std::vector<uint8_t>(icon_png_data.begin(), icon_png_data.end());
InstallIcon(app_id, descriptor, std::move(icon));
}
void ArcAppListPrefs::OnIconLoaded(const std::string& app_id,
const ArcAppIconDescriptor& descriptor,
arc::mojom::RawIconPngDataPtr icon) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (icon->icon_png_data->empty()) {
LOG(WARNING) << "Cannot fetch icon for " << app_id;
return;
}
if (!IsRegistered(app_id)) {
VLOG(2) << "Request to update icon for non-registered app: " << app_id;
return;
}
InstallIcon(app_id, descriptor, std::move(icon));
} }
void ArcAppListPrefs::OnTaskCreated(int32_t task_id, void ArcAppListPrefs::OnTaskCreated(int32_t task_id,
...@@ -1619,8 +1670,20 @@ void ArcAppListPrefs::OnTaskDescriptionUpdated( ...@@ -1619,8 +1670,20 @@ void ArcAppListPrefs::OnTaskDescriptionUpdated(
int32_t task_id, int32_t task_id,
const std::string& label, const std::string& label,
const std::vector<uint8_t>& icon_png_data) { const std::vector<uint8_t>& icon_png_data) {
arc::mojom::RawIconPngDataPtr icon = arc::mojom::RawIconPngData::New();
icon->is_adaptive_icon = false;
icon->icon_png_data =
std::vector<uint8_t>(icon_png_data.begin(), icon_png_data.end());
for (auto& observer : observer_list_)
observer.OnTaskDescriptionChanged(task_id, label, *icon);
}
void ArcAppListPrefs::OnTaskDescriptionChanged(
int32_t task_id,
const std::string& label,
arc::mojom::RawIconPngDataPtr icon) {
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnTaskDescriptionUpdated(task_id, label, icon_png_data); observer.OnTaskDescriptionChanged(task_id, label, *icon);
} }
void ArcAppListPrefs::OnTaskDestroyed(int32_t task_id) { void ArcAppListPrefs::OnTaskDestroyed(int32_t task_id) {
...@@ -1775,11 +1838,17 @@ base::Time ArcAppListPrefs::GetInstallTime(const std::string& app_id) const { ...@@ -1775,11 +1838,17 @@ base::Time ArcAppListPrefs::GetInstallTime(const std::string& app_id) const {
void ArcAppListPrefs::InstallIcon(const std::string& app_id, void ArcAppListPrefs::InstallIcon(const std::string& app_id,
const ArcAppIconDescriptor& descriptor, const ArcAppIconDescriptor& descriptor,
const std::vector<uint8_t>& content_png) { arc::mojom::RawIconPngDataPtr icon) {
const base::FilePath icon_path = GetIconPath(app_id, descriptor); const base::FilePath icon_path = GetIconPath(app_id, descriptor);
const base::FilePath foreground_icon_path =
GetForegroundIconPath(app_id, descriptor);
const base::FilePath background_icon_path =
GetBackgroundIconPath(app_id, descriptor);
base::PostTaskAndReplyWithResult( base::PostTaskAndReplyWithResult(
file_task_runner_.get(), FROM_HERE, file_task_runner_.get(), FROM_HERE,
base::BindOnce(&InstallIconFromFileThread, icon_path, content_png), base::BindOnce(&InstallIconFromFileThread, icon_path,
foreground_icon_path, background_icon_path,
std::move(icon)),
base::BindOnce(&ArcAppListPrefs::OnIconInstalled, base::BindOnce(&ArcAppListPrefs::OnIconInstalled,
weak_ptr_factory_.GetWeakPtr(), app_id, descriptor)); weak_ptr_factory_.GetWeakPtr(), app_id, descriptor));
} }
......
...@@ -180,10 +180,10 @@ class ArcAppListPrefs : public KeyedService, ...@@ -180,10 +180,10 @@ class ArcAppListPrefs : public KeyedService,
const std::string& activity, const std::string& activity,
const std::string& intent) {} const std::string& intent) {}
// Notifies that task description has been updated. // Notifies that task description has been updated.
virtual void OnTaskDescriptionUpdated( virtual void OnTaskDescriptionChanged(
int32_t task_id, int32_t task_id,
const std::string& label, const std::string& label,
const std::vector<uint8_t>& icon_png_data) {} const arc::mojom::RawIconPngData& icon) {}
// Notifies that task has been destroyed. // Notifies that task has been destroyed.
virtual void OnTaskDestroyed(int32_t task_id) {} virtual void OnTaskDestroyed(int32_t task_id) {}
// Notifies that task has been activated and moved to the front. // Notifies that task has been activated and moved to the front.
...@@ -389,15 +389,23 @@ class ArcAppListPrefs : public KeyedService, ...@@ -389,15 +389,23 @@ class ArcAppListPrefs : public KeyedService,
void OnIcon(const std::string& app_id, void OnIcon(const std::string& app_id,
const ArcAppIconDescriptor& descriptor, const ArcAppIconDescriptor& descriptor,
const std::vector<uint8_t>& icon_png_data); const std::vector<uint8_t>& icon_png_data);
void OnIconLoaded(const std::string& app_id,
const ArcAppIconDescriptor& descriptor,
arc::mojom::RawIconPngDataPtr icon);
void OnTaskCreated(int32_t task_id, void OnTaskCreated(int32_t task_id,
const std::string& package_name, const std::string& package_name,
const std::string& activity, const std::string& activity,
const base::Optional<std::string>& name, const base::Optional<std::string>& name,
const base::Optional<std::string>& intent) override; const base::Optional<std::string>& intent) override;
// This interface is deprecated and will soon be replaced by
// OnTaskDescriptionChanged().
void OnTaskDescriptionUpdated( void OnTaskDescriptionUpdated(
int32_t task_id, int32_t task_id,
const std::string& label, const std::string& label,
const std::vector<uint8_t>& icon_png_data) override; const std::vector<uint8_t>& icon_png_data) override;
void OnTaskDescriptionChanged(int32_t task_id,
const std::string& label,
arc::mojom::RawIconPngDataPtr icon) override;
void OnTaskDestroyed(int32_t task_id) override; void OnTaskDestroyed(int32_t task_id) override;
void OnTaskSetActive(int32_t task_id) override; void OnTaskSetActive(int32_t task_id) override;
void OnNotificationsEnabledChanged(const std::string& package_name, void OnNotificationsEnabledChanged(const std::string& package_name,
...@@ -463,7 +471,7 @@ class ArcAppListPrefs : public KeyedService, ...@@ -463,7 +471,7 @@ class ArcAppListPrefs : public KeyedService,
// directory. // directory.
void InstallIcon(const std::string& app_id, void InstallIcon(const std::string& app_id,
const ArcAppIconDescriptor& descriptor, const ArcAppIconDescriptor& descriptor,
const std::vector<uint8_t>& contentPng); arc::mojom::RawIconPngDataPtr icon);
void OnIconInstalled(const std::string& app_id, void OnIconInstalled(const std::string& app_id,
const ArcAppIconDescriptor& descriptor, const ArcAppIconDescriptor& descriptor,
bool install_succeed); bool install_succeed);
......
...@@ -37,7 +37,7 @@ class MockArcAppListPrefsObserver : public ArcAppListPrefs::Observer { ...@@ -37,7 +37,7 @@ class MockArcAppListPrefsObserver : public ArcAppListPrefs::Observer {
MOCK_METHOD3(OnTaskDescriptionUpdated, MOCK_METHOD3(OnTaskDescriptionUpdated,
void(int32_t task_id, void(int32_t task_id,
const std::string& label, const std::string& label,
const std::vector<uint8_t>& icon_png_data)); const arc::mojom::RawIconPngDataPtr& icon));
MOCK_METHOD1(OnTaskDestroyed, void(int32_t task_id)); MOCK_METHOD1(OnTaskDestroyed, void(int32_t task_id));
MOCK_METHOD1(OnTaskSetActive, void(int32_t task_id)); MOCK_METHOD1(OnTaskSetActive, void(int32_t task_id));
MOCK_METHOD2(OnNotificationsEnabledChanged, MOCK_METHOD2(OnNotificationsEnabledChanged,
......
...@@ -29,11 +29,16 @@ ...@@ -29,11 +29,16 @@
#include "chrome/browser/ui/ash/launcher/arc_app_window_info.h" #include "chrome/browser/ui/ash/launcher/arc_app_window_info.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_helper.h" #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_helper.h"
#include "chrome/common/chrome_features.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace {
constexpr int kArcAppWindowIconSize = extension_misc::EXTENSION_ICON_MEDIUM;
} // namespace
AppServiceAppWindowArcTracker::AppServiceAppWindowArcTracker( AppServiceAppWindowArcTracker::AppServiceAppWindowArcTracker(
AppServiceAppWindowLauncherController* app_service_controller) AppServiceAppWindowLauncherController* app_service_controller)
: observed_profile_(app_service_controller->owner()->profile()), : observed_profile_(app_service_controller->owner()->profile()),
...@@ -151,18 +156,27 @@ void AppServiceAppWindowArcTracker::OnTaskCreated( ...@@ -151,18 +156,27 @@ void AppServiceAppWindowArcTracker::OnTaskCreated(
arc_window_candidates_.erase(window); arc_window_candidates_.erase(window);
} }
void AppServiceAppWindowArcTracker::OnTaskDescriptionUpdated( void AppServiceAppWindowArcTracker::OnTaskDescriptionChanged(
int32_t task_id, int32_t task_id,
const std::string& label, const std::string& label,
const std::vector<uint8_t>& icon_png_data) { const arc::mojom::RawIconPngData& icon) {
auto it = task_id_to_arc_app_window_info_.find(task_id); auto it = task_id_to_arc_app_window_info_.find(task_id);
if (it == task_id_to_arc_app_window_info_.end()) if (it == task_id_to_arc_app_window_info_.end())
return; return;
apps::CompressedDataToImageSkiaCallback( if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
base::BindOnce(&AppServiceAppWindowArcTracker::SetDescription, apps::ArcRawIconPngDataToImageSkia(
weak_ptr_factory_.GetWeakPtr(), task_id, label)) icon.Clone(), kArcAppWindowIconSize,
.Run(std::move(icon_png_data)); base::BindOnce(&AppServiceAppWindowArcTracker::OnIconLoaded,
weak_ptr_factory_.GetWeakPtr(), task_id, label));
} else {
if (icon.icon_png_data.has_value()) {
apps::CompressedDataToImageSkiaCallback(
base::BindOnce(&AppServiceAppWindowArcTracker::SetDescription,
weak_ptr_factory_.GetWeakPtr(), task_id, label))
.Run(icon.icon_png_data.value());
}
}
} }
void AppServiceAppWindowArcTracker::OnTaskDestroyed(int task_id) { void AppServiceAppWindowArcTracker::OnTaskDestroyed(int task_id) {
...@@ -469,3 +483,10 @@ void AppServiceAppWindowArcTracker::SetDescription(int32_t task_id, ...@@ -469,3 +483,10 @@ void AppServiceAppWindowArcTracker::SetDescription(int32_t task_id,
if (app_window) if (app_window)
app_window->SetDescription(title, icon); app_window->SetDescription(title, icon);
} }
void AppServiceAppWindowArcTracker::OnIconLoaded(int32_t task_id,
const std::string& title,
const gfx::ImageSkia& icon) {
gfx::ImageSkia image = icon;
SetDescription(task_id, title, image);
}
...@@ -70,10 +70,10 @@ class AppServiceAppWindowArcTracker : public ArcAppListPrefs::Observer, ...@@ -70,10 +70,10 @@ class AppServiceAppWindowArcTracker : public ArcAppListPrefs::Observer,
const std::string& package_name, const std::string& package_name,
const std::string& activity, const std::string& activity,
const std::string& intent) override; const std::string& intent) override;
void OnTaskDescriptionUpdated( void OnTaskDescriptionChanged(
int32_t task_id, int32_t task_id,
const std::string& label, const std::string& label,
const std::vector<uint8_t>& icon_png_data) override; const arc::mojom::RawIconPngData& icon) override;
void OnTaskDestroyed(int task_id) override; void OnTaskDestroyed(int task_id) override;
void OnTaskSetActive(int32_t task_id) override; void OnTaskSetActive(int32_t task_id) override;
...@@ -121,7 +121,15 @@ class AppServiceAppWindowArcTracker : public ArcAppListPrefs::Observer, ...@@ -121,7 +121,15 @@ class AppServiceAppWindowArcTracker : public ArcAppListPrefs::Observer,
std::vector<int> GetTaskIdsForApp(const std::string& arc_app_id) const; std::vector<int> GetTaskIdsForApp(const std::string& arc_app_id) const;
// Invoked when the compressed data is converted to an ImageSkia.
void OnIconLoaded(int32_t task_id,
const std::string& title,
const gfx::ImageSkia& icon);
// Sets the window title and icon. // Sets the window title and icon.
// TODO(crbug.com/1083331): This function can be deleted when the flag
// kAppServiceAdaptiveIcon is deleted, and use OnIconLoaded to replace this
// function.
void SetDescription(int32_t task_id, void SetDescription(int32_t task_id,
const std::string& title, const std::string& title,
gfx::ImageSkia icon); gfx::ImageSkia icon);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#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/multi_user/multi_user_window_manager_helper.h" #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_helper.h"
#include "chrome/common/chrome_features.h"
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
#include "components/arc/session/arc_bridge_service.h" #include "components/arc/session/arc_bridge_service.h"
...@@ -35,6 +36,10 @@ ...@@ -35,6 +36,10 @@
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace {
constexpr int kArcAppWindowIconSize = extension_misc::EXTENSION_ICON_MEDIUM;
} // namespace
// The information about the arc application window which has to be kept // The information about the arc application window which has to be kept
// even when its AppWindow is not present. // even when its AppWindow is not present.
class ArcAppWindowLauncherController::AppWindowInfo { class ArcAppWindowLauncherController::AppWindowInfo {
...@@ -305,18 +310,27 @@ void ArcAppWindowLauncherController::OnTaskCreated( ...@@ -305,18 +310,27 @@ void ArcAppWindowLauncherController::OnTaskCreated(
AttachControllerToTask(task_id, *task_id_to_app_window_info_[task_id]); AttachControllerToTask(task_id, *task_id_to_app_window_info_[task_id]);
} }
void ArcAppWindowLauncherController::OnTaskDescriptionUpdated( void ArcAppWindowLauncherController::OnTaskDescriptionChanged(
int32_t task_id, int32_t task_id,
const std::string& label, const std::string& label,
const std::vector<uint8_t>& icon_png_data) { const arc::mojom::RawIconPngData& icon) {
AppWindowInfo* info = GetAppWindowInfoForTask(task_id); AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
if (!info) if (!info)
return; return;
apps::CompressedDataToImageSkiaCallback( if (base::FeatureList::IsEnabled(features::kAppServiceAdaptiveIcon)) {
base::BindOnce(&ArcAppWindowLauncherController::SetDescription, apps::ArcRawIconPngDataToImageSkia(
weak_ptr_factory_.GetWeakPtr(), task_id, label)) icon.Clone(), kArcAppWindowIconSize,
.Run(std::move(icon_png_data)); base::BindOnce(&ArcAppWindowLauncherController::OnIconLoaded,
weak_ptr_factory_.GetWeakPtr(), task_id, label));
} else {
if (icon.icon_png_data && icon.icon_png_data.has_value()) {
apps::CompressedDataToImageSkiaCallback(
base::BindOnce(&ArcAppWindowLauncherController::SetDescription,
weak_ptr_factory_.GetWeakPtr(), task_id, label))
.Run(icon.icon_png_data.value());
}
}
} }
void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) {
...@@ -558,3 +572,10 @@ void ArcAppWindowLauncherController::SetDescription(int32_t task_id, ...@@ -558,3 +572,10 @@ void ArcAppWindowLauncherController::SetDescription(int32_t task_id,
info->app_window()->SetDescription(title, icon); info->app_window()->SetDescription(title, icon);
} }
} }
void ArcAppWindowLauncherController::OnIconLoaded(int32_t task_id,
const std::string& title,
const gfx::ImageSkia& icon) {
gfx::ImageSkia image = icon;
SetDescription(task_id, title, image);
}
...@@ -68,10 +68,10 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController, ...@@ -68,10 +68,10 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController,
const std::string& package_name, const std::string& package_name,
const std::string& activity, const std::string& activity,
const std::string& intent) override; const std::string& intent) override;
void OnTaskDescriptionUpdated( void OnTaskDescriptionChanged(
int32_t task_id, int32_t task_id,
const std::string& label, const std::string& label,
const std::vector<uint8_t>& icon_png_data) override; const arc::mojom::RawIconPngData& icon) override;
void OnTaskDestroyed(int task_id) override; void OnTaskDestroyed(int task_id) override;
void OnTaskSetActive(int32_t task_id) override; void OnTaskSetActive(int32_t task_id) override;
...@@ -119,6 +119,10 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController, ...@@ -119,6 +119,10 @@ class ArcAppWindowLauncherController : public AppWindowLauncherController,
void OnArcOptInManagementCheckStarted() override; void OnArcOptInManagementCheckStarted() override;
void OnArcSessionStopped(arc::ArcStopReason stop_reason) override; void OnArcSessionStopped(arc::ArcStopReason stop_reason) override;
void OnIconLoaded(int32_t task_id,
const std::string& title,
const gfx::ImageSkia& icon);
// Sets the window title and icon. // Sets the window title and icon.
void SetDescription(int32_t task_id, void SetDescription(int32_t task_id,
const std::string& title, const std::string& title,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// Next MinVersion: 46 // Next MinVersion: 47
module arc.mojom; module arc.mojom;
...@@ -112,6 +112,7 @@ struct AppDiscoveryResult { ...@@ -112,6 +112,7 @@ struct AppDiscoveryResult {
float review_score; float review_score;
array<uint8> icon_png_data; array<uint8> icon_png_data;
[MinVersion=22] string? package_name; [MinVersion=22] string? package_name;
[MinVersion=46] RawIconPngData? icon;
}; };
// Describes the status of an app discovery request, including completed // Describes the status of an app discovery request, including completed
...@@ -172,10 +173,13 @@ struct AppDataResult { ...@@ -172,10 +173,13 @@ struct AppDataResult {
// Text information for the result. // Text information for the result.
string text@3; string text@3;
// Icon information in png format. It could be null if not provided. Decoded // Icon information in png format. It could be null if not provided. Decoded
// in the utility process. // in the utility process. This will be replaced by |icon|.
array<uint8>? icon_png_data@2; array<uint8>? icon_png_data@2;
// Type of this app data search result. // Type of this app data search result.
[MinVersion=28] AppDataResultType type@4; [MinVersion=28] AppDataResultType type@4;
// Icon information in png format. It could be null if not provided. Decoded
// in the utility process.
[MinVersion=46] RawIconPngData? icon@5;
}; };
// Describes the status of an app data search request, including completed // Describes the status of an app data search request, including completed
...@@ -261,7 +265,8 @@ struct AppShortcutItem { ...@@ -261,7 +265,8 @@ struct AppShortcutItem {
// The short description of this shortcut. // The short description of this shortcut.
string short_label; string short_label;
// The icon for this shortcut, decoded in the utility process. // The icon for this shortcut, decoded in the utility process. This will be
// replaced by |icon|.
array<uint8> icon_png; array<uint8> icon_png;
// The package name of the publisher app. // The package name of the publisher app.
...@@ -272,6 +277,9 @@ struct AppShortcutItem { ...@@ -272,6 +277,9 @@ struct AppShortcutItem {
// "Rank" of a shortcut, which is a non-negative, sequential value. // "Rank" of a shortcut, which is a non-negative, sequential value.
[MinVersion=32] int32 rank; [MinVersion=32] int32 rank;
// The icon for this shortcut, decoded in the utility process.
[MinVersion=46] RawIconPngData? icon;
}; };
[Extensible] [Extensible]
...@@ -298,7 +306,7 @@ enum PaiFlowState { ...@@ -298,7 +306,7 @@ enum PaiFlowState {
TIMEOUT = 9, TIMEOUT = 9,
}; };
// Next method ID: 18 // Next method ID: 19
// Deprecated method IDs: 1 // Deprecated method IDs: 1
interface AppHost { interface AppHost {
// Sends newly added ARC app to Chrome. This message is sent when ARC receives // Sends newly added ARC app to Chrome. This message is sent when ARC receives
...@@ -338,11 +346,16 @@ interface AppHost { ...@@ -338,11 +346,16 @@ interface AppHost {
[MinVersion=13] string? name@3, [MinVersion=13] string? name@3,
[MinVersion=15] string? intent@4); [MinVersion=15] string? intent@4);
// Sends task label and icon. // Sends task label and icon. This is deprecated and will soon be replaced by
// OnTaskDescriptionChanged().
[MinVersion=19] OnTaskDescriptionUpdated@17(int32 task_id, [MinVersion=19] OnTaskDescriptionUpdated@17(int32 task_id,
string label, string label,
array<uint8> icon_png_data); array<uint8> icon_png_data);
// Sends task label and icon.
[MinVersion=46] OnTaskDescriptionChanged@18(
int32 task_id, string label, RawIconPngData icon);
// Notifies that task has been destroyed. // Notifies that task has been destroyed.
[MinVersion=4] OnTaskDestroyed@5(int32 task_id); [MinVersion=4] OnTaskDestroyed@5(int32 task_id);
...@@ -373,7 +386,7 @@ interface AppHost { ...@@ -373,7 +386,7 @@ interface AppHost {
}; };
// TODO(lhchavez): Migrate all request/response messages to Mojo. // TODO(lhchavez): Migrate all request/response messages to Mojo.
// Next method ID: 35 // Next method ID: 38
// Deprecated method IDs: 2, 3, 13 // Deprecated method IDs: 2, 3, 13
interface AppInstance { interface AppInstance {
// DEPRECATED: Please use Init@21 instead. // DEPRECATED: Please use Init@21 instead.
...@@ -416,28 +429,51 @@ interface AppInstance { ...@@ -416,28 +429,51 @@ interface AppInstance {
// string. See Intent.toUri(). // string. See Intent.toUri().
[MinVersion=23] LaunchIntent@19(string intent_uri, int64 display_id); [MinVersion=23] LaunchIntent@19(string intent_uri, int64 display_id);
// Sends a request for the ARC shortcut icon of a given resource id and // Sends a request for the ARC icon of a given resource id and
// |pixel_size|. // |pixel_size|. This is deprecated and will soon be replaced by GetAppIcon().
[MinVersion=36] RequestAppIcon@27(string package_name, [MinVersion=36] RequestAppIcon@27(string package_name,
string activity, string activity,
int32 pixel_size) => int32 pixel_size) =>
(array<uint8> icon_png_data); (array<uint8> icon_png_data);
// Sends a request for the ARC shortcut icon of a given resource id and // Sends a request for the ARC icon of a given resource id and
// |pixel_size|. // |pixel_size|.
[MinVersion=46] GetAppIcon@35(string package_name,
string activity, int32 pixel_size) =>
(RawIconPngData icon);
// Sends a request for the ARC shortcut icon of a given resource id and
// |pixel_size|. This is deprecated and will soon be replaced by
// GetAppShortcutIcon().
[MinVersion=36] RequestShortcutIcon@28(string icon_resource_id, [MinVersion=36] RequestShortcutIcon@28(string icon_resource_id,
int32 pixel_size) => int32 pixel_size) =>
(array<uint8> icon_png_data); (array<uint8> icon_png_data);
// Sends a request for the ARC shortcut icon of a given resource id and
// |pixel_size|.
[MinVersion=46] GetAppShortcutIcon@36(string icon_resource_id,
int32 pixel_size) =>
(RawIconPngData icon);
// Sends a request for the ARC icon for a given |package_name| and // Sends a request for the ARC icon for a given |package_name| and
// |pixel_size|. If |normalize| is true, the icon will be normalized per // |pixel_size|. If |normalize| is true, the icon will be normalized per
// Android's icon guidelines, otherwise, the raw unnormalized icon is // Android's icon guidelines, otherwise, the raw unnormalized icon is
// returned. Returns an empty array if an error occurred. // returned. Returns an empty array if an error occurred. This is deprecated
// and will soon be replaced by GetPackageIcon().
[MinVersion=38] RequestPackageIcon@30(string package_name, [MinVersion=38] RequestPackageIcon@30(string package_name,
int32 pixel_size, int32 pixel_size,
bool normalize) => bool normalize) =>
(array<uint8> icon_png_data); (array<uint8> icon_png_data);
// Sends a request for the ARC icon for a given |package_name| and
// |pixel_size|. If |normalize| is true, the icon will be normalized per
// Android's icon guidelines, otherwise, the raw unnormalized icon is
// returned. Returns an empty array if an error occurred.
[MinVersion=46] GetPackageIcon@37(string package_name,
int32 pixel_size,
bool normalize) =>
(RawIconPngData icon);
// Removes cached shortcut icon with the given resource id. // Removes cached shortcut icon with the given resource id.
[MinVersion=9] RemoveCachedIcon@14(string icon_resource_id); [MinVersion=9] RemoveCachedIcon@14(string icon_resource_id);
......
...@@ -93,6 +93,13 @@ void FakeAppInstance::RequestAppIcon(const std::string& package_name, ...@@ -93,6 +93,13 @@ void FakeAppInstance::RequestAppIcon(const std::string& package_name,
} }
} }
void FakeAppInstance::GetAppIcon(const std::string& package_name,
const std::string& activity,
int dimension,
GetAppIconCallback callback) {
// TODO(crbug.com/1083331): Implement for the new fake icon interface.
}
void FakeAppInstance::SendRefreshAppList( void FakeAppInstance::SendRefreshAppList(
const std::vector<mojom::AppInfo>& apps) { const std::vector<mojom::AppInfo>& apps) {
std::vector<mojom::AppInfoPtr> v; std::vector<mojom::AppInfoPtr> v;
...@@ -520,6 +527,12 @@ void FakeAppInstance::RequestShortcutIcon( ...@@ -520,6 +527,12 @@ void FakeAppInstance::RequestShortcutIcon(
} }
} }
void FakeAppInstance::GetAppShortcutIcon(const std::string& icon_resource_id,
int dimension,
GetAppShortcutIconCallback callback) {
// TODO(crbug.com/1083331): Implement for the new fake icon interface.
}
void FakeAppInstance::RequestPackageIcon(const std::string& package_name, void FakeAppInstance::RequestPackageIcon(const std::string& package_name,
int dimension, int dimension,
bool normalize, bool normalize,
...@@ -531,6 +544,13 @@ void FakeAppInstance::RequestPackageIcon(const std::string& package_name, ...@@ -531,6 +544,13 @@ void FakeAppInstance::RequestPackageIcon(const std::string& package_name,
png_data_as_string.end())); png_data_as_string.end()));
} }
void FakeAppInstance::GetPackageIcon(const std::string& package_name,
int dimension,
bool normalize,
GetPackageIconCallback callback) {
// TODO(crbug.com/1083331): Implement for the new fake icon interface.
}
void FakeAppInstance::RemoveCachedIcon(const std::string& icon_resource_id) {} void FakeAppInstance::RemoveCachedIcon(const std::string& icon_resource_id) {}
void FakeAppInstance::SetAppReinstallCandidates( void FakeAppInstance::SetAppReinstallCandidates(
......
...@@ -103,6 +103,10 @@ class FakeAppInstance : public mojom::AppInstance { ...@@ -103,6 +103,10 @@ class FakeAppInstance : public mojom::AppInstance {
const std::string& activity, const std::string& activity,
int dimension, int dimension,
RequestAppIconCallback callback) override; RequestAppIconCallback callback) override;
void GetAppIcon(const std::string& package_name,
const std::string& activity,
int dimension,
GetAppIconCallback callback) override;
void LaunchIntentDeprecated( void LaunchIntentDeprecated(
const std::string& intent_uri, const std::string& intent_uri,
const base::Optional<gfx::Rect>& dimension_on_screen) override; const base::Optional<gfx::Rect>& dimension_on_screen) override;
...@@ -110,10 +114,17 @@ class FakeAppInstance : public mojom::AppInstance { ...@@ -110,10 +114,17 @@ class FakeAppInstance : public mojom::AppInstance {
void RequestShortcutIcon(const std::string& icon_resource_id, void RequestShortcutIcon(const std::string& icon_resource_id,
int dimension, int dimension,
RequestShortcutIconCallback callback) override; RequestShortcutIconCallback callback) override;
void GetAppShortcutIcon(const std::string& icon_resource_id,
int dimension,
GetAppShortcutIconCallback callback) override;
void RequestPackageIcon(const std::string& package_name, void RequestPackageIcon(const std::string& package_name,
int dimension, int dimension,
bool normalize, bool normalize,
RequestPackageIconCallback callback) override; RequestPackageIconCallback callback) override;
void GetPackageIcon(const std::string& package_name,
int dimension,
bool normalize,
GetPackageIconCallback callback) override;
void RemoveCachedIcon(const std::string& icon_resource_id) override; void RemoveCachedIcon(const std::string& icon_resource_id) override;
void CanHandleResolutionDeprecated( void CanHandleResolutionDeprecated(
const std::string& package_name, const std::string& package_name,
......
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