File: boca_web_app_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 (191 lines) | stat: -rw-r--r-- 6,831 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
// Copyright 2024 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/ash/system_web_apps/apps/boca_web_app_info.h"

#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/webui/boca_ui/boca_app_page_handler.h"
#include "ash/webui/boca_ui/boca_ui.h"
#include "ash/webui/boca_ui/url_constants.h"
#include "ash/webui/grit/ash_boca_ui_resources.h"
#include "base/functional/bind.h"
#include "chrome/browser/ash/browser_delegate/browser_delegate.h"
#include "chrome/browser/ash/system_web_apps/apps/system_web_app_install_utils.h"
#include "chrome/browser/enterprise/util/affiliation.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/ash/components/boca/boca_app_client.h"
#include "chromeos/ash/components/boca/boca_role_util.h"
#include "chromeos/ash/components/boca/boca_session_manager.h"
#include "chromeos/ash/components/browser_context_helper/browser_context_helper.h"
#include "chromeos/ash/components/install_attributes/install_attributes.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
namespace {

inline constexpr std::string_view kDisabled = "disabled";

bool IsConsumerProfile(Profile* profile) {
  return ash::boca_util::IsConsumer(
      ash::BrowserContextHelper::Get()->GetUserByBrowserContext(profile));
}

// A clone of the method in boca_role_util.cc IsEnabled(). The difference is we
// read prefs from profile instead of from user. The previous function read from
// user to de-couple from browser profile. But user prefs are not guaranteed to
// be loaded before the check happens, so we check from profile prefs instead.
bool IsEnabled(Profile* profile) {
  // Uber switch for boca.
  if (!ash::features::IsBocaUberEnabled()) {
    return false;
  }

  if (ash::features::IsBocaEnabled()) {
    return true;
  }

  if (!profile) {
    return false;
  }

  if (!ash::InstallAttributes::IsInitialized() ||
      !enterprise_util::IsProfileAffiliated(profile)) {
    return false;
  }

  auto* prefs = profile->GetPrefs();
  if (!prefs) {
    return false;
  }

  auto setting =
      prefs->GetString(ash::prefs::kClassManagementToolsAvailabilitySetting);
  return !setting.empty() && setting != kDisabled;
}

}  // namespace

BocaSystemAppDelegate::BocaSystemAppDelegate(Profile* profile)
    : ash::SystemWebAppDelegate(ash::SystemWebAppType::BOCA,
                                "Boca",
                                GURL(ash::boca::kChromeBocaAppUntrustedURL),
                                profile) {}

std::unique_ptr<web_app::WebAppInstallInfo>
BocaSystemAppDelegate::GetWebAppInfo() const {
  GURL start_url = GURL(ash::boca::kChromeBocaAppUntrustedIndexURL);
  auto info =
      web_app::CreateSystemWebAppInstallInfoWithStartUrlAsIdentity(start_url);
  info->scope = GURL(ash::boca::kChromeBocaAppUntrustedURL);
  info->title = l10n_util::GetStringUTF16(IDS_CLASS_TOOLS_TITLE);
  web_app::CreateIconInfoForSystemWebApp(
      info->start_url(), {{"icon_256.png", 256, IDR_ASH_BOCA_UI_ICON_256_PNG}},
      *info);
  info->theme_color =
      web_app::GetDefaultBackgroundColor(/*use_dark_mode=*/false);
  info->dark_mode_theme_color =
      web_app::GetDefaultBackgroundColor(/*use_dark_mode=*/true);
  info->background_color = info->theme_color;
  info->display_mode = blink::mojom::DisplayMode::kStandalone;
  info->user_display_mode = web_app::mojom::UserDisplayMode::kStandalone;
  return info;
}

bool BocaSystemAppDelegate::ShouldCaptureNavigations() const {
  return true;
}

bool BocaSystemAppDelegate::ShouldAllowResize() const {
  return !IsConsumerProfile(profile());
}

bool BocaSystemAppDelegate::ShouldAllowMaximize() const {
  return !IsConsumerProfile(profile());
}

bool BocaSystemAppDelegate::ShouldHaveTabStrip() const {
  return IsConsumerProfile(profile());
}

bool BocaSystemAppDelegate::ShouldHideNewTabButton() const {
  return IsConsumerProfile(profile());
}

bool BocaSystemAppDelegate::ShouldHaveExtensionsContainerInToolbar() const {
  return IsConsumerProfile(profile());
}

bool BocaSystemAppDelegate::IsUrlInSystemAppScope(const GURL& url) const {
  // Consumer SWA will also host 3P content, so we override app scope checks to
  // prevent navigation outside the app.
  return IsConsumerProfile(profile());
}

bool BocaSystemAppDelegate::ShouldPinTab(GURL url) const {
  return ShouldHaveTabStrip() &&
         url == GURL(ash::boca::kChromeBocaAppUntrustedIndexURL);
}

bool BocaSystemAppDelegate::IsAppEnabled() const {
  return IsEnabled(profile());
}

bool BocaSystemAppDelegate::HasCustomTabMenuModel() const {
  return IsConsumerProfile(profile());
}

bool BocaSystemAppDelegate::ShouldShowInSearchAndShelf() const {
  return true;
}

bool BocaSystemAppDelegate::ShouldShowInLauncher() const {
  return true;
}

gfx::Size BocaSystemAppDelegate::GetMinimumWindowSize() const {
  if (!IsConsumerProfile(profile())) {
    return {400, 400};
  }
  return {500, 500};
}

std::unique_ptr<ui::SimpleMenuModel> BocaSystemAppDelegate::GetTabMenuModel(
    ui::SimpleMenuModel::Delegate* delegate) const {
  std::unique_ptr<ui::SimpleMenuModel> tab_menu =
      std::make_unique<ui::SimpleMenuModel>(delegate);
  tab_menu->AddItemWithStringId(TabStripModel::CommandReload,
                                IDS_TAB_CXMENU_RELOAD);
  tab_menu->AddItemWithStringId(TabStripModel::CommandGoBack,
                                IDS_CONTENT_CONTEXT_BACK);
  return tab_menu;
}

ash::BrowserDelegate* BocaSystemAppDelegate::LaunchAndNavigateSystemWebApp(
    Profile* profile,
    web_app::WebAppProvider* provider,
    const GURL& url,
    const apps::AppLaunchParams& params) const {
  ash::BrowserDelegate* const browser =
      ash::SystemWebAppDelegate::LaunchAndNavigateSystemWebApp(
          profile, provider, url, params);
  if (IsConsumerProfile(profile)) {
    // Notify downstream Boca components so they can prepare the app instance
    // for OnTask and restore contents from the previous session if needed.
    ash::boca::BocaAppClient::Get()->GetSessionManager()->NotifyAppReload();
  } else {
    // Always launch producer app into float mode.
    aura::Window* window = browser->GetNativeWindow();
    ash::boca::BocaAppHandler::SetFloatModeAndBoundsForWindow(
        /*is_float_mode=*/true, window, base::BindOnce([](bool result) {}));
  }
  return browser;
}