File: web_app_browser_controller.h

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 (196 lines) | stat: -rw-r--r-- 7,712 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// 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_UI_WEB_APPLICATIONS_WEB_APP_BROWSER_CONTROLLER_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_BROWSER_CONTROLLER_H_

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

#include "base/callback_list.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/web_applications/tabbed_mode_scope_matcher.h"
#include "chrome/browser/web_applications/web_app_icon_manager.h"
#include "chrome/browser/web_applications/web_app_install_manager.h"
#include "chrome/browser/web_applications/web_app_install_manager_observer.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "components/services/app_service/public/cpp/icon_types.h"
#include "components/webapps/common/web_app_id.h"
#include "third_party/re2/src/re2/set.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/models/image_model.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "components/content_relationship_verification/digital_asset_links_handler.h"  // nogncheck
#endif

class Browser;
class SkBitmap;

#if BUILDFLAG(IS_CHROMEOS)
namespace ash {
class SystemWebAppDelegate;
}
#endif  // BUILDFLAG(IS_CHROMEOS)

namespace content_relationship_verification {
class DigitalAssetLinksHandler;
}

namespace web_app {

class WebAppRegistrar;
class WebAppProvider;

// Class to encapsulate logic to control the browser UI for
// web apps.
// App information is obtained from the WebAppRegistrar.
// Icon information is obtained from the WebAppIconManager.
// Note: Much of the functionality in HostedAppBrowserController
// will move to this class.
class WebAppBrowserController : public AppBrowserController,
                                public WebAppInstallManagerObserver {
 public:
  WebAppBrowserController(WebAppProvider& provider,
                          Browser* browser,
                          webapps::AppId app_id,
#if BUILDFLAG(IS_CHROMEOS)
                          const ash::SystemWebAppDelegate* system_app,
#endif  // BUILDFLAG(IS_CHROMEOS)
                          bool has_tab_strip);
  WebAppBrowserController(const WebAppBrowserController&) = delete;
  WebAppBrowserController& operator=(const WebAppBrowserController&) = delete;
  ~WebAppBrowserController() override;

  // AppBrowserController:
  using HomeTabCallbackList = base::OnceCallbackList<void()>;
  bool HasMinimalUiButtons() const override;
  gfx::ImageSkia GetHomeTabIcon() const;
  gfx::ImageSkia GetFallbackHomeTabIcon() const;
  ui::ImageModel GetWindowAppIcon() const override;
  ui::ImageModel GetWindowIcon() const override;
  std::optional<SkColor> GetThemeColor() const override;
  std::optional<SkColor> GetBackgroundColor() const override;
  std::u16string GetTitle() const override;
  std::u16string GetAppShortName() const override;
  std::u16string GetFormattedUrlOrigin() const override;
  GURL GetAppStartUrl() const override;
  GURL GetAppNewTabUrl() const override;
  bool ShouldHideNewTabButton() const override;
  bool IsUrlInHomeTabScope(const GURL& url) const override;
  bool ShouldShowAppIconOnTab(int index) const override;
  bool IsUrlInAppScope(const GURL& url) const override;
  WebAppBrowserController* AsWebAppBrowserController() override;
  bool CanUserUninstall() const override;
  void Uninstall(
      webapps::WebappUninstallSource webapp_uninstall_source) override;
  bool IsInstalled() const override;
  bool IsHostedApp() const override;
  std::unique_ptr<TabMenuModelFactory> GetTabMenuModelFactory() const override;
  bool AppUsesWindowControlsOverlay() const override;
  bool AppUsesTabbed() const override;
  bool IsWindowControlsOverlayEnabled() const override;
  void ToggleWindowControlsOverlayEnabled(
      base::OnceClosure on_complete) override;
  bool AppUsesBorderlessMode() const override;
  bool IsIsolatedWebApp() const override;
  void SetIsolatedWebAppTrueForTesting() override;
  gfx::Rect GetDefaultBounds() const override;
  bool HasReloadButton() const override;
#if BUILDFLAG(IS_CHROMEOS)
  const ash::SystemWebAppDelegate* system_app() const override;
  bool ShouldShowCustomTabBar() const override;
#else
  bool HasProfileMenuButton() const override;
  bool IsProfileMenuButtonVisible() const override;
#endif  // BUILDFLAG(IS_CHROMEOS)

#if BUILDFLAG(IS_MAC)
  bool AlwaysShowToolbarInFullscreen() const override;
  void ToggleAlwaysShowToolbarInFullscreen() override;
#endif

  // WebAppInstallManagerObserver:
  void OnWebAppUninstalled(
      const webapps::AppId& app_id,
      webapps::WebappUninstallSource uninstall_source) override;
  void OnWebAppManifestUpdated(const webapps::AppId& app_id) override;
  void OnWebAppInstallManagerDestroyed() override;

  base::CallbackListSubscription AddHomeTabIconLoadCallbackForTesting(
      const base::OnceClosure callback);
  static void SetIconLoadCallbackForTesting(base::OnceClosure callback);
  static void SetManifestUpdateAppliedCallbackForTesting(
      base::OnceClosure callback);

 protected:
  // AppBrowserController:
  void OnTabInserted(content::WebContents* contents) override;
  void OnTabRemoved(content::WebContents* contents) override;

 private:
  mutable HomeTabCallbackList home_tab_callback_list_;
  const WebAppRegistrar& registrar() const;
  const WebAppInstallManager& install_manager() const;

  // Helper function to call AppServiceProxy to load icon.
  void LoadAppIcon(bool allow_placeholder_icon) const;

  // Invoked when the icon is loaded.
  void OnLoadIcon(apps::IconValuePtr icon_value);

  void OnReadHomeTabIcon(SkBitmap home_tab_icon_bitmap) const;
  void OnReadIcon(IconPurpose purpose, SkBitmap bitmap);
  void PerformDigitalAssetLinkVerification(Browser* browser);

#if BUILDFLAG(IS_CHROMEOS)
  void CheckDigitalAssetLinkRelationshipForAndroidApp(
      const std::string& package_name,
      const std::string& fingerprint);
  void OnRelationshipCheckComplete(
      content_relationship_verification::RelationshipCheckResult result);
#endif  // BUILDFLAG(IS_CHROMEOS)

  // Helper function to return the resolved background color from the manifest
  // given the current state of dark/light mode.
  std::optional<SkColor> GetResolvedManifestBackgroundColor() const;

  const raw_ref<WebAppProvider> provider_;

  // Save the display mode at time of launch. The web app display mode may
  // change with manifest updates but the app window should continue using
  // whatever it was launched with.
  DisplayMode effective_display_mode_ = DisplayMode::kUndefined;
  bool is_isolated_web_app_for_testing_ = false;

#if BUILDFLAG(IS_CHROMEOS)
  const raw_ptr<const ash::SystemWebAppDelegate> system_app_;
#endif  // BUILDFLAG(IS_CHROMEOS)
  mutable std::optional<ui::ImageModel> app_icon_;

#if BUILDFLAG(IS_CHROMEOS)
  // The result of digital asset link verification of the web app.
  // Only used for web-only TWAs installed through the Play Store.
  std::optional<bool> is_verified_;

  std::unique_ptr<content_relationship_verification::DigitalAssetLinksHandler>
      asset_link_handler_;
#endif  // BUILDFLAG(IS_CHROMEOS)

  base::ScopedObservation<WebAppInstallManager, WebAppInstallManagerObserver>
      install_manager_observation_{this};

  mutable base::WeakPtrFactory<WebAppBrowserController> weak_ptr_factory_{this};
};

}  // namespace web_app

#endif  // CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_BROWSER_CONTROLLER_H_