File: web_kiosk_app_data.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 (107 lines) | stat: -rw-r--r-- 3,526 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
// Copyright 2019 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_ASH_APP_MODE_WEB_APP_WEB_KIOSK_APP_DATA_H_
#define CHROME_BROWSER_ASH_APP_MODE_WEB_APP_WEB_KIOSK_APP_DATA_H_

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

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "chrome/browser/ash/app_mode/kiosk_app_data_base.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "components/account_id/account_id.h"
#include "ui/gfx/image/image_skia.h"
#include "url/gurl.h"

namespace web_app {
struct WebAppInstallInfo;
}  // namespace web_app

namespace ash {

class KioskAppDataDelegate;

class WebKioskAppData : public KioskAppDataBase {
 public:
  // Size of a kiosk web app icon in pixels.
  static constexpr int kIconSize = 128;

  enum class Status {
    kInit,       // Data initialized with app id.
    kLoading,    // Loading data from cache or web store.
    kLoaded,     // Data load finished.
    kInstalled,  // Icon and launch url are fetched and app can be run
                 // without them.
  };

  WebKioskAppData(KioskAppDataDelegate& delegate,
                  const std::string& app_id,
                  const AccountId& account_id,
                  const GURL url,
                  const std::string& title,
                  const GURL icon_url);
  WebKioskAppData(const WebKioskAppData&) = delete;
  WebKioskAppData& operator=(const WebKioskAppData&) = delete;
  ~WebKioskAppData() override;

  // Loads the locally cached data. Returns true on success.
  bool LoadFromCache();

  // Updates `icon_` from either `KioskAppDataBase::icon_path_` or `icon_url_`.
  void LoadIcon();

  // Get a proper URL to launch according to the app status.
  GURL GetLaunchableUrl() const;

  // Updates `status_`. Based on `notify`, we will notify `delegate_` about data
  // update.
  void SetStatus(Status status, bool notify = true);

  void UpdateFromWebAppInfo(const web_app::WebAppInstallInfo& app_info);

  void UpdateAppInfo(const std::string& title,
                     const GURL& start_url,
                     const web_app::IconBitmaps& icon_bitmaps);

  void SetOnLoadedCallbackForTesting(base::OnceClosure callback);

  Status status() const { return status_; }
  const GURL& install_url() const { return install_url_; }
  const GURL& launch_url() const { return launch_url_; }

 private:
  class IconFetcher;
  void OnDidDownloadIcon(const SkBitmap& icon);
  void OnIconLoadDone(std::optional<gfx::ImageSkia> icon);

  bool LoadLaunchUrlFromDictionary(const base::Value::Dict& dict);

  // Returns the icon url of the icon that was being provided during previous
  // session.
  GURL GetLastIconUrl(const base::Value::Dict& dict) const;

  const raw_ref<KioskAppDataDelegate> delegate_;
  Status status_;
  const GURL install_url_;  // installation url.
  GURL launch_url_;         // app launch url.

  // Url for loading the app icon in case the app has not been installed earlier
  // and a user opened the App menu in the login screen.
  GURL icon_url_;
  // Used to download icon from `icon_url_`.
  std::unique_ptr<IconFetcher> icon_fetcher_;

  base::OnceClosure on_loaded_closure_for_testing_;

  base::WeakPtrFactory<WebKioskAppData> weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_APP_MODE_WEB_APP_WEB_KIOSK_APP_DATA_H_