File: arc_app_window_info.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (141 lines) | stat: -rw-r--r-- 4,044 bytes parent folder | download | duplicates (3)
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_;
}