Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2203)

Unified Diff: chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc

Issue 2894443002: arc: Set custom icon in shelf for ARC apps. (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc
diff --git a/chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc b/chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc
index a7ac2797ff80d7d12f06437920efc1dd30e77c5b..71c9ed2e3e8caff1ab82b5000f6399734bb0b80d 100644
--- a/chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc
+++ b/chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
+#include "chrome/browser/ui/ash/launcher/arc_app_window.h"
#include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
@@ -36,11 +37,7 @@
namespace {
-enum class FullScreenMode {
- NOT_DEFINED, // Fullscreen mode was not defined.
- ACTIVE, // Fullscreen is activated for an app.
- NON_ACTIVE, // Fullscreen was not activated for an app.
-};
+constexpr size_t kMaxIconPngSize = 64 * 1024; // 64 kb
blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom(
arc::mojom::OrientationLock orientation_lock) {
@@ -75,6 +72,25 @@ class ArcAppWindowLauncherController::AppWindowInfo {
: app_shelf_id_(app_shelf_id) {}
~AppWindowInfo() = default;
+ void SetDescription(const std::string& title,
+ const std::vector<uint8_t>& icon_data_png) {
+ if (base::IsStringUTF8(title))
+ title_ = title;
+ else
+ VLOG(1) << "Task label is not UTF-8 string.";
+ // Chrome has custom Play Store icon. Don't overwrite it.
+ if (app_shelf_id_.app_id() != arc::kPlayStoreAppId) {
+ if (icon_data_png.size() < kMaxIconPngSize)
+ icon_data_png_ = icon_data_png;
+ else
+ VLOG(1) << "Task icon size is too big " << icon_data_png.size() << ".";
+ }
+ }
+
+ void set_app_window(std::unique_ptr<ArcAppWindow> window) {
+ app_window_ = std::move(window);
+ }
+
const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; }
bool has_requested_orientation_lock() const {
@@ -100,11 +116,11 @@ class ArcAppWindowLauncherController::AppWindowInfo {
return lock_completion_behavior_;
}
- void set_app_window(std::unique_ptr<AppWindow> window) {
- app_window_ = std::move(window);
- }
+ ArcAppWindow* app_window() { return app_window_.get(); }
+
+ const std::string& title() const { return title_; }
- AppWindow* app_window() { return app_window_.get(); }
+ const std::vector<uint8_t>& icon_data_png() const { return icon_data_png_; }
private:
const arc::ArcAppShelfId app_shelf_id_;
@@ -119,132 +135,15 @@ class ArcAppWindowLauncherController::AppWindowInfo {
ScreenOrientationController::LockCompletionBehavior::None;
arc::mojom::OrientationLock requested_orientation_lock_ =
arc::mojom::OrientationLock::NONE;
- std::unique_ptr<AppWindow> app_window_;
+ // Keeps overridden window title.
+ std::string title_;
+ // Keeps overridden window icon.
+ std::vector<uint8_t> icon_data_png_;
+ std::unique_ptr<ArcAppWindow> app_window_;
DISALLOW_COPY_AND_ASSIGN(AppWindowInfo);
};
-// A ui::BaseWindow for a chromeos launcher to control ARC applications.
-class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
- public:
- AppWindow(int task_id,
- const arc::ArcAppShelfId& app_shelf_id,
- views::Widget* widget,
- ArcAppWindowLauncherController* owner)
- : task_id_(task_id),
- app_shelf_id_(app_shelf_id),
- widget_(widget),
- owner_(owner) {}
- ~AppWindow() = default;
-
- void SetController(ArcAppWindowLauncherItemController* controller) {
- DCHECK(!controller_ && controller);
- controller_ = controller;
- }
-
- void ResetController() { controller_ = nullptr; }
-
- void SetFullscreenMode(FullScreenMode mode) {
- DCHECK(mode != FullScreenMode::NOT_DEFINED);
- fullscreen_mode_ = mode;
- }
-
- FullScreenMode fullscreen_mode() const { return fullscreen_mode_; }
-
- int task_id() const { return task_id_; }
-
- const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; }
-
- const ash::ShelfID& shelf_id() const { return shelf_id_; }
-
- void set_shelf_id(const ash::ShelfID& shelf_id) { shelf_id_ = shelf_id; }
-
- views::Widget* widget() const { return widget_; }
-
- ArcAppWindowLauncherItemController* controller() { return controller_; }
-
- // ui::BaseWindow:
- bool IsActive() const override {
- return widget_->IsActive() && owner_->active_task_id_ == task_id_;
- }
-
- bool IsMaximized() const override {
- NOTREACHED();
- return false;
- }
-
- bool IsMinimized() const override {
- NOTREACHED();
- return false;
- }
-
- bool IsFullscreen() const override {
- NOTREACHED();
- return false;
- }
-
- gfx::NativeWindow GetNativeWindow() const override {
- return widget_->GetNativeWindow();
- }
-
- gfx::Rect GetRestoredBounds() const override {
- NOTREACHED();
- return gfx::Rect();
- }
-
- ui::WindowShowState GetRestoredState() const override {
- NOTREACHED();
- return ui::SHOW_STATE_NORMAL;
- }
-
- gfx::Rect GetBounds() const override {
- NOTREACHED();
- return gfx::Rect();
- }
-
- void Show() override { widget_->Show(); }
-
- void ShowInactive() override { NOTREACHED(); }
-
- void Hide() override { NOTREACHED(); }
-
- void Close() override { arc::CloseTask(task_id_); }
-
- void Activate() override { widget_->Activate(); }
-
- void Deactivate() override { NOTREACHED(); }
-
- void Maximize() override { NOTREACHED(); }
-
- void Minimize() override { widget_->Minimize(); }
-
- void Restore() override { NOTREACHED(); }
-
- void SetBounds(const gfx::Rect& bounds) override { NOTREACHED(); }
-
- void FlashFrame(bool flash) override { NOTREACHED(); }
-
- bool IsAlwaysOnTop() const override {
- NOTREACHED();
- return false;
- }
-
- void SetAlwaysOnTop(bool always_on_top) override { NOTREACHED(); }
-
- private:
- const int task_id_;
- const arc::ArcAppShelfId app_shelf_id_;
- ash::ShelfID shelf_id_;
- FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED;
- // Unowned pointers
- views::Widget* const widget_;
- ArcAppWindowLauncherController* owner_;
- ArcAppWindowLauncherItemController* controller_ = nullptr;
- // Unowned pointer, represents host ARC window.
-
- DISALLOW_COPY_AND_ASSIGN(AppWindow);
-};
-
ArcAppWindowLauncherController::ArcAppWindowLauncherController(
ChromeLauncherController* owner)
: AppWindowLauncherController(owner) {
@@ -356,8 +255,7 @@ ArcAppWindowLauncherController::GetAppWindowInfoForTask(int task_id) {
return it == task_id_to_app_window_info_.end() ? nullptr : it->second.get();
}
-ArcAppWindowLauncherController::AppWindow*
-ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) {
+ArcAppWindow* ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) {
AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
return info ? info->app_window() : nullptr;
}
@@ -398,8 +296,9 @@ void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded(
views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
DCHECK(widget);
DCHECK(!info->app_window());
- info->set_app_window(
- base::MakeUnique<AppWindow>(task_id, info->app_shelf_id(), widget, this));
+ info->set_app_window(base::MakeUnique<ArcAppWindow>(
+ task_id, info->app_shelf_id(), widget, this));
+ info->app_window()->SetDescription(info->title(), info->icon_data_png());
RegisterApp(info);
DCHECK(info->app_window()->controller());
const ash::ShelfID shelf_id(info->app_window()->shelf_id());
@@ -420,7 +319,7 @@ void ArcAppWindowLauncherController::OnAppReadyChanged(
std::vector<int> ArcAppWindowLauncherController::GetTaskIdsForApp(
const std::string& arc_app_id) const {
- // Note, AppWindow is optional part for a task and it may be not created if
+ // Note, ArcAppWindow is optional part for a task and it may be not created if
// another full screen Android app is currently active. Use
// |task_id_to_app_window_info_| that keeps currently running tasks info.
std::vector<int> task_ids;
@@ -465,6 +364,18 @@ void ArcAppWindowLauncherController::OnTaskCreated(
AttachControllerToTask(task_id, *task_id_to_app_window_info_[task_id]);
}
+void ArcAppWindowLauncherController::OnTaskDescriptionUpdated(
+ int32_t task_id,
+ const std::string& label,
+ const std::vector<uint8_t>& icon_png_data) {
+ AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
+ if (info) {
+ info->SetDescription(label, icon_png_data);
+ if (info->app_window())
+ info->app_window()->SetDescription(label, icon_png_data);
+ }
+}
+
void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) {
auto it = task_id_to_app_window_info_.find(task_id);
if (it == task_id_to_app_window_info_.end())
@@ -487,42 +398,6 @@ void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) {
task_id_to_app_window_info_.erase(it);
}
-void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) {
- if (observed_profile_ != owner()->profile()) {
- active_task_id_ = task_id;
- return;
- }
-
- AppWindow* previous_app_window = GetAppWindowForTask(active_task_id_);
- if (previous_app_window) {
- owner()->SetItemStatus(previous_app_window->shelf_id(),
- ash::STATUS_RUNNING);
- previous_app_window->SetFullscreenMode(
- previous_app_window->widget() &&
- previous_app_window->widget()->IsFullscreen()
- ? FullScreenMode::ACTIVE
- : FullScreenMode::NON_ACTIVE);
- }
-
- active_task_id_ = task_id;
-
- AppWindow* current_app_window = GetAppWindowForTask(task_id);
- if (current_app_window) {
- owner()->SetItemStatus(
- current_app_window->shelf_id(),
- current_app_window->widget() && current_app_window->IsActive()
- ? ash::STATUS_ACTIVE
- : ash::STATUS_RUNNING);
- // TODO(reveman): Figure out how to support fullscreen in interleaved
- // window mode.
- // if (new_active_app_it->second->widget()) {
- // new_active_app_it->second->widget()->SetFullscreen(
- // new_active_app_it->second->fullscreen_mode() ==
- // FullScreenMode::ACTIVE);
- // }
- }
-}
-
void ArcAppWindowLauncherController::OnTaskOrientationLockRequested(
int32_t task_id,
const arc::mojom::OrientationLock orientation_lock) {
@@ -547,25 +422,65 @@ void ArcAppWindowLauncherController::OnTaskOrientationLockRequested(
if (ash::Shell::Get()
->maximize_mode_controller()
->IsMaximizeModeWindowManagerEnabled()) {
- AppWindow* app_window = info->app_window();
+ ArcAppWindow* app_window = info->app_window();
if (app_window)
SetOrientationLockForAppWindow(app_window);
}
}
+void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) {
+ if (observed_profile_ != owner()->profile()) {
+ active_task_id_ = task_id;
+ return;
+ }
+
+ ArcAppWindow* previous_app_window = GetAppWindowForTask(active_task_id_);
+ if (previous_app_window) {
+ owner()->SetItemStatus(previous_app_window->shelf_id(),
+ ash::STATUS_RUNNING);
+ previous_app_window->SetFullscreenMode(
+ previous_app_window->widget() &&
+ previous_app_window->widget()->IsFullscreen()
+ ? ArcAppWindow::FullScreenMode::ACTIVE
+ : ArcAppWindow::FullScreenMode::NON_ACTIVE);
+ }
+
+ active_task_id_ = task_id;
+
+ ArcAppWindow* current_app_window = GetAppWindowForTask(task_id);
+ if (current_app_window) {
+ if (current_app_window->widget() && current_app_window->IsActive()) {
+ owner()->SetItemStatus(current_app_window->shelf_id(),
+ ash::STATUS_ACTIVE);
+ current_app_window->controller()->SetActiveWindow(
+ current_app_window->GetNativeWindow());
+ } else {
+ owner()->SetItemStatus(current_app_window->shelf_id(),
+ ash::STATUS_RUNNING);
+ }
+ // TODO(reveman): Figure out how to support fullscreen in interleaved
+ // window mode.
+ // if (new_active_app_it->second->widget()) {
+ // new_active_app_it->second->widget()->SetFullscreen(
+ // new_active_app_it->second->fullscreen_mode() ==
+ // ArcAppWindow::FullScreenMode::ACTIVE);
+ // }
+ }
+}
+
AppWindowLauncherItemController*
ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) {
if (!window)
return nullptr;
- AppWindow* app_window = GetAppWindowForTask(active_task_id_);
+ ArcAppWindow* app_window = GetAppWindowForTask(active_task_id_);
if (app_window &&
app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) {
return app_window->controller();
}
for (auto& it : task_id_to_app_window_info_) {
- AppWindow* app_window = it.second->app_window();
+ ArcAppWindow* app_window = it.second->app_window();
if (app_window &&
app_window->widget() ==
views::Widget::GetWidgetForNativeWindow(window)) {
@@ -587,7 +502,7 @@ void ArcAppWindowLauncherController::OnWindowActivated(
void ArcAppWindowLauncherController::OnMaximizeModeStarted() {
for (auto& it : task_id_to_app_window_info_) {
- AppWindow* app_window = it.second->app_window();
+ ArcAppWindow* app_window = it.second->app_window();
if (app_window)
SetOrientationLockForAppWindow(app_window);
}
@@ -633,7 +548,7 @@ ArcAppWindowLauncherController::AttachControllerToTask(
std::unique_ptr<ArcAppWindowLauncherItemController> controller =
base::MakeUnique<ArcAppWindowLauncherItemController>(
- app_shelf_id.ToString());
+ app_shelf_id.ToString(), owner());
ArcAppWindowLauncherItemController* item_controller = controller.get();
const ash::ShelfID shelf_id(app_shelf_id.ToString());
if (!owner()->GetItem(shelf_id)) {
@@ -650,7 +565,7 @@ ArcAppWindowLauncherController::AttachControllerToTask(
void ArcAppWindowLauncherController::RegisterApp(
AppWindowInfo* app_window_info) {
- AppWindow* app_window = app_window_info->app_window();
+ ArcAppWindow* app_window = app_window_info->app_window();
ArcAppWindowLauncherItemController* controller =
AttachControllerToTask(app_window->task_id(), *app_window_info);
DCHECK(!controller->app_id().empty());
@@ -665,19 +580,19 @@ void ArcAppWindowLauncherController::RegisterApp(
void ArcAppWindowLauncherController::UnregisterApp(
AppWindowInfo* app_window_info) {
- AppWindow* app_window = app_window_info->app_window();
+ ArcAppWindow* app_window = app_window_info->app_window();
if (!app_window)
return;
ArcAppWindowLauncherItemController* controller = app_window->controller();
if (controller)
controller->RemoveWindow(app_window);
- app_window->ResetController();
+ app_window->SetController(nullptr);
app_window_info->set_app_window(nullptr);
}
void ArcAppWindowLauncherController::SetOrientationLockForAppWindow(
- AppWindow* app_window) {
+ ArcAppWindow* app_window) {
aura::Window* window = app_window->widget()->GetNativeWindow();
if (!window)
return;

Powered by Google App Engine
This is Rietveld 408576698