1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
// Copyright 2020 The Chromium Authors
// 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/shelf/arc_app_window_info.h"
#include "ash/public/cpp/window_properties.h"
#include "base/strings/string_util.h"
#include "chrome/browser/ash/app_list/arc/arc_app_utils.h"
#include "chrome/browser/ash/app_list/arc/intent.h"
#include "chromeos/ash/experiences/arc/app/arc_app_constants.h"
namespace {
// Prefix in intent that specifies a logical window. Among a group of windows
// belonging to the same logical window, only one will be represented in the
// shelf and in the alt-tab menu. S. means string type.
constexpr char kLogicalWindowIntentPrefix[] =
"S.org.chromium.arc.logical_window_id=";
std::string GetLogicalWindowIdFromIntent(const std::string& launch_intent) {
auto intent = arc::Intent::Get(launch_intent);
if (!intent) {
return std::string();
}
const std::string prefix(kLogicalWindowIntentPrefix);
for (const auto& param : intent->extra_params()) {
if (base::StartsWith(param, prefix, base::CompareCase::SENSITIVE)) {
return param.substr(prefix.length());
}
}
return std::string();
}
} // namespace
ArcAppWindowInfo::ArcAppWindowInfo(const arc::ArcAppShelfId& app_shelf_id,
const std::string& launch_intent,
const std::string& package_name)
: app_shelf_id_(app_shelf_id),
launch_intent_(launch_intent),
package_name_(package_name),
logical_window_id_(GetLogicalWindowIdFromIntent(launch_intent)) {}
ArcAppWindowInfo::~ArcAppWindowInfo() = default;
void ArcAppWindowInfo::OnWindowDestroying(aura::Window* window) {
DCHECK(observed_window_.IsObservingSource(window));
observed_window_.Reset();
window_ = nullptr;
}
void ArcAppWindowInfo::SetDescription(const std::string& title,
const gfx::ImageSkia& icon) {
DCHECK(base::IsStringUTF8(title));
title_ = title;
// Chrome has custom Play Store icon. Don't overwrite it.
if (app_shelf_id_.app_id() == arc::kPlayStoreAppId) {
return;
}
icon_ = icon;
}
void ArcAppWindowInfo::set_window_hidden_from_shelf(bool hidden) {
if (window_hidden_from_shelf_ != hidden) {
window_hidden_from_shelf_ = hidden;
UpdateWindowProperties();
}
}
void ArcAppWindowInfo::UpdateWindowProperties() {
aura::Window* const win = window();
if (!win) {
return;
}
bool hidden = window_hidden_from_shelf_ || task_hidden_from_shelf_;
win->SetProperty(ash::kHideInDeskMiniViewKey, hidden);
win->SetProperty(ash::kHideInOverviewKey, hidden);
win->SetProperty(ash::kHideInShelfKey, hidden);
}
void ArcAppWindowInfo::set_window(aura::Window* window) {
if (window_ == window) {
return;
}
if (window_ && observed_window_.IsObservingSource(window_.get())) {
observed_window_.Reset();
}
window_ = window;
UpdateWindowProperties();
if (window && !observed_window_.IsObservingSource(window)) {
observed_window_.Observe(window);
}
}
aura::Window* ArcAppWindowInfo::ArcAppWindowInfo::window() {
return window_;
}
const arc::ArcAppShelfId& ArcAppWindowInfo::app_shelf_id() const {
return app_shelf_id_;
}
ash::ShelfID ArcAppWindowInfo::shelf_id() const {
return ash::ShelfID(app_shelf_id_.ToString());
}
const std::string& ArcAppWindowInfo::launch_intent() const {
return launch_intent_;
}
const std::string& ArcAppWindowInfo::package_name() const {
return package_name_;
}
const std::string& ArcAppWindowInfo::title() const {
return title_;
}
const gfx::ImageSkia& ArcAppWindowInfo::icon() const {
return icon_;
}
const std::string& ArcAppWindowInfo::logical_window_id() const {
return logical_window_id_;
}
void ArcAppWindowInfo::set_task_hidden_from_shelf() {
if (!task_hidden_from_shelf_) {
task_hidden_from_shelf_ = true;
UpdateWindowProperties();
}
}
bool ArcAppWindowInfo::task_hidden_from_shelf() const {
return task_hidden_from_shelf_;
}
|