File: app_install_dialog.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 (97 lines) | stat: -rw-r--r-- 3,631 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
// Copyright 2023 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_WEBUI_ASH_APP_INSTALL_APP_INSTALL_DIALOG_H_
#define CHROME_BROWSER_UI_WEBUI_ASH_APP_INSTALL_APP_INSTALL_DIALOG_H_

#include <optional>

#include "chrome/browser/apps/almanac_api_client/almanac_icon_cache.h"
#include "chrome/browser/apps/app_service/app_install/app_install_types.h"
#include "chrome/browser/ui/webui/ash/app_install/app_install.mojom.h"
#include "chrome/browser/ui/webui/ash/app_install/app_install_dialog_args.h"
#include "chrome/browser/ui/webui/ash/app_install/app_install_ui.h"
#include "chrome/browser/ui/webui/ash/system_web_dialog/system_web_dialog_delegate.h"
#include "components/services/app_service/public/cpp/icon_types.h"
#include "components/services/app_service/public/cpp/package_id.h"
#include "ui/views/native_window_tracker.h"

namespace apps {
class AlmanacAppIconLoader;
}

namespace ash::app_install {

inline constexpr int kIconSize = 32;

// Defines the web dialog used for installing an app.
class AppInstallDialog : public SystemWebDialogDelegate {
 public:
  // Creates and returns a new dialog for installing an app.
  static base::WeakPtr<AppInstallDialog> CreateDialog();

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

  // Displays the dialog with app info.
  void ShowApp(
      Profile* profile,
      gfx::NativeWindow parent,
      apps::PackageId package_id,
      std::string app_name,
      GURL app_url,
      std::string app_description,
      std::optional<apps::AppInstallIcon> icon,
      std::vector<mojom::ScreenshotPtr> screenshots,
      base::OnceCallback<void(bool accepted)> dialog_accepted_callback);

  // Displays the dialog with an error message that the app can't be found.
  void ShowNoAppError(gfx::NativeWindow parent);

  // Displays the dialog with an error message that the connection failed.
  void ShowConnectionError(gfx::NativeWindow parent,
                           base::OnceClosure try_again_callback);

  // Callers must call one of SetInstallSucceeded or SetInstallFailed once the
  // install has finished, passing in the app_id if the installation succeeded
  // or a callback to retry the install if it failed.
  void SetInstallSucceeded();
  void SetInstallFailed(base::OnceCallback<void(bool accepted)> retry_callback);

  // There are some cases where we may have created the dialog, but then never
  // shown it. We need to clean up the dialog in that case.
  void CleanUpDialogIfNotShown();

  // SystemWebDialogDelegate:
  void OnDialogShown(content::WebUI* webui) override;
  bool ShouldShowCloseButton() const override;
  void GetDialogSize(gfx::Size* size) const override;

 private:
  AppInstallDialog();
  ~AppInstallDialog() override;

  void OnAppIconLoaded(apps::IconValuePtr icon_value);

  void Show(gfx::NativeWindow parent, AppInstallDialogArgs dialog_args);

  base::WeakPtr<AppInstallDialog> GetWeakPtr();

  std::optional<AppInstallDialogArgs> dialog_args_;
  int dialog_height_ = 0;
  raw_ptr<AppInstallDialogUI> dialog_ui_ = nullptr;

  // Temporary variables for ShowApp().
  base::WeakPtr<Profile> profile_;
  gfx::NativeWindow parent_;
  std::unique_ptr<views::NativeWindowTracker> parent_window_tracker_;
  AppInfoArgs app_info_args_;
  std::unique_ptr<apps::AlmanacAppIconLoader> icon_loader_;

  base::WeakPtrFactory<AppInstallDialog> weak_factory_{this};
};

}  // namespace ash::app_install

#endif  // CHROME_BROWSER_UI_WEBUI_ASH_APP_INSTALL_APP_INSTALL_DIALOG_H_