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

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: cleanup 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 a231ae53fbf328f69ff3a7715e63b2d0cf0bc90e..77e3457553df91a33bd53a8052d2b41de670094b 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
@@ -20,6 +20,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"
@@ -37,12 +38,6 @@
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.
-};
-
blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom(
arc::mojom::OrientationLock orientation_lock) {
DCHECK_NE(arc::mojom::OrientationLock::CURRENT, orientation_lock);
@@ -76,6 +71,22 @@ 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) {
+ title_ = title;
+ // Chrome has custom Play Store icon. Don't overwrite it.
+ if (app_shelf_id_.app_id() != arc::kPlayStoreAppId)
+ icon_data_png_ = icon_data_png;
+ if (app_window_)
+ app_window_->SetDescription(title_, icon_data_png_);
+ }
+
+ void SetAppWindow(std::unique_ptr<ArcAppWindow> window) {
+ app_window_ = std::move(window);
+ if (app_window_)
+ app_window_->SetDescription(title_, icon_data_png_);
msw 2017/05/18 18:26:59 Should the ArcAppWindow constructor just take a ti
khmel 2017/05/18 20:27:51 Restored to setter. However it seems adding this t
msw 2017/05/18 22:03:39 Your updated change here seems fine.
khmel 2017/05/18 22:40:02 Acknowledged.
+ }
+
const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; }
bool has_requested_orientation_lock() const {
@@ -101,11 +112,7 @@ class ArcAppWindowLauncherController::AppWindowInfo {
return lock_completion_behavior_;
}
- void set_app_window(std::unique_ptr<AppWindow> window) {
- app_window_ = std::move(window);
- }
-
- AppWindow* app_window() { return app_window_.get(); }
+ ArcAppWindow* app_window() { return app_window_.get(); }
private:
const arc::ArcAppShelfId app_shelf_id_;
@@ -120,132 +127,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) {
@@ -357,8 +247,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;
}
@@ -399,8 +288,8 @@ 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->SetAppWindow(base::MakeUnique<ArcAppWindow>(
+ task_id, info->app_shelf_id(), widget, this));
RegisterApp(info);
DCHECK(info->app_window()->controller());
const ash::ShelfID shelf_id(info->app_window()->shelf_id());
@@ -421,7 +310,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;
@@ -494,32 +383,36 @@ void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) {
return;
}
- AppWindow* previous_app_window = GetAppWindowForTask(active_task_id_);
+ 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()
- ? FullScreenMode::ACTIVE
- : FullScreenMode::NON_ACTIVE);
+ ? ArcAppWindow::FullScreenMode::ACTIVE
+ : ArcAppWindow::FullScreenMode::NON_ACTIVE);
}
active_task_id_ = task_id;
- AppWindow* current_app_window = GetAppWindowForTask(task_id);
+ ArcAppWindow* 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);
+ 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() ==
- // FullScreenMode::ACTIVE);
+ // ArcAppWindow::FullScreenMode::ACTIVE);
// }
}
}
@@ -548,25 +441,35 @@ 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::OnTaskSetDescription(
+ int32_t task_id,
+ const std::string& label,
+ const std::vector<uint8_t>& icon_png_data) {
+ AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
+ if (!info)
msw 2017/05/18 18:26:59 nit: invert conditional and nest the function call
khmel 2017/05/18 20:27:51 Done.
+ return;
+ info->SetDescription(label, icon_png_data);
+}
+
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)) {
@@ -588,7 +491,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);
}
@@ -634,7 +537,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)) {
@@ -651,7 +554,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());
@@ -666,7 +569,7 @@ 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;
@@ -674,11 +577,11 @@ void ArcAppWindowLauncherController::UnregisterApp(
if (controller)
controller->RemoveWindow(app_window);
app_window->ResetController();
- app_window_info->set_app_window(nullptr);
+ app_window_info->SetAppWindow(nullptr);
}
void ArcAppWindowLauncherController::SetOrientationLockForAppWindow(
- AppWindow* app_window) {
+ ArcAppWindow* app_window) {
ash::WmWindow* window =
ash::WmWindow::Get(app_window->widget()->GetNativeWindow());
if (!window)

Powered by Google App Engine
This is Rietveld 408576698