File: shelf_controller_helper.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (133 lines) | stat: -rw-r--r-- 5,246 bytes parent folder | download | duplicates (5)
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
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_ASH_SHELF_SHELF_CONTROLLER_HELPER_H_
#define CHROME_BROWSER_UI_ASH_SHELF_SHELF_CONTROLLER_HELPER_H_

#include <memory>
#include <optional>
#include <string>

#include "ash/public/cpp/shelf_types.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"

class ArcAppListPrefs;
class ExtensionEnableFlow;
class Profile;

namespace apps {
enum class PromiseStatus;
}

namespace content {
class WebContents;
}

// Assists ChromeShelfController with ExtensionService interaction.
class ShelfControllerHelper : public ExtensionEnableFlowDelegate {
 public:
  explicit ShelfControllerHelper(Profile* profile);

  ShelfControllerHelper(const ShelfControllerHelper&) = delete;
  ShelfControllerHelper& operator=(const ShelfControllerHelper&) = delete;

  ~ShelfControllerHelper() override;

  // Get the item label that should be shown for the specified promise app
  // status.
  static std::u16string GetLabelForPromiseStatus(apps::PromiseStatus status);

  // Get the accessible label that should be announced by the screenreader for
  // the specified promise app name and status.
  static std::u16string GetAccessibleLabelForPromiseStatus(
      std::optional<std::string> app_name,
      apps::PromiseStatus status);

  // Helper function to return the title associated with |app_id|.
  // Returns an empty title if no matching extension can be found.
  static std::u16string GetAppTitle(Profile* profile,
                                    const std::string& app_id);

  // Helper function to return the package id associated with |app_id|.
  // Returns an empty string if no matching extension can be found.
  static std::string GetAppPackageId(Profile* profile,
                                     const std::string& app_id);

  // Helper function to return the app status associated with |app_id|. if the
  // app is blocked, return AppStatus::kBlocked. Otherwise, if the app is
  // paused, return AppStatus::kPaused. Otherwise, return AppStatus::kReady.
  static ash::AppStatus GetAppStatus(Profile* profile,
                                     const std::string& app_id);

  // Returns whether the app with `app_id` was installed by default.
  static bool IsAppDefaultInstalled(Profile* profile,
                                    const std::string& app_id);

  // Returns the app id of the specified tab, or an empty string if there is
  // no app. All known profiles will be queried for this.
  virtual std::string GetAppID(content::WebContents* tab);

  // Get the accessible label that should be announced by the screenreader for
  // the specified promise shelf item.
  static std::u16string GetPromiseAppAccessibleName(
      Profile* profile,
      const std::string& package_id);

  // Retrieve the label for a registered promise app. If there isn't a promise
  // app with the specified package ID, return an empty string.
  static std::u16string GetPromiseAppTitle(
      Profile* profile,
      const std::string& string_package_id);

  // Retrieve the installation progress value for a registered promise app. If
  // there isn't a promise app with the specified package ID, return -1.
  static float GetPromiseAppProgress(Profile* profile,
                                     const std::string& string_package_id);

  // Check whether this item is a registered promise app.
  static bool IsPromiseApp(Profile* profile, const std::string& id);

  // Convert promise status into general app status.
  static ash::AppStatus ConvertPromiseStatusToAppStatus(
      apps::PromiseStatus promise_status);

  // Returns true if |id| is valid for the currently active profile.
  // Used during restore to ignore no longer valid extensions.
  // Note that already running applications are ignored by the restore process.
  virtual bool IsValidIDForCurrentUser(const std::string& app_id) const;

  void LaunchApp(const ash::ShelfID& id,
                 ash::ShelfLaunchSource source,
                 int event_flags,
                 int64_t display_id,
                 bool new_window);

  virtual ArcAppListPrefs* GetArcAppListPrefs() const;

  Profile* profile() { return profile_; }
  const Profile* profile() const { return profile_; }
  void set_profile(Profile* profile) { profile_ = profile; }

  bool IsValidPromisePackageIdFromAppService(
      const std::string& promise_package_id) const;

 private:
  // ExtensionEnableFlowDelegate:
  void ExtensionEnableFlowFinished() override;
  void ExtensionEnableFlowAborted(bool user_initiated) override;

  // Returns true if |id| is a valid ARC app for the currently active profile.
  bool IsValidIDForArcApp(const std::string& app_id) const;

  // Returns true if |id| is a valid app from AppService. ARC app is not
  // handled by this method.
  bool IsValidIDFromAppService(const std::string& app_id) const;

  // The currently active profile for the usage of |GetAppID|.
  raw_ptr<Profile, DanglingUntriaged> profile_;
  std::unique_ptr<ExtensionEnableFlow> extension_enable_flow_;
};

#endif  // CHROME_BROWSER_UI_ASH_SHELF_SHELF_CONTROLLER_HELPER_H_