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
|
// Copyright 2021 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/eche_app_info.h"
#include <memory>
#include "ash/constants/ash_features.h"
#include "ash/webui/eche_app_ui/url_constants.h"
#include "ash/webui/grit/ash_eche_bundle_resources.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ash/system_web_apps/apps/system_web_app_install_utils.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/grit/generated_resources.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/display/screen.h"
namespace {
constexpr float kDefaultAspectRatio = 16.0 / 9.0f;
constexpr gfx::Size kMinimumEcheSize(240, 240);
} // namespace
EcheSystemAppDelegate::EcheSystemAppDelegate(Profile* profile)
: ash::SystemWebAppDelegate(ash::SystemWebAppType::ECHE,
"Eche",
GURL("chrome://eche-app"),
profile) {}
std::unique_ptr<web_app::WebAppInstallInfo>
EcheSystemAppDelegate::GetWebAppInfo() const {
GURL start_url = GURL(ash::eche_app::kChromeUIEcheAppURL);
auto info =
web_app::CreateSystemWebAppInstallInfoWithStartUrlAsIdentity(start_url);
info->scope = GURL(ash::eche_app::kChromeUIEcheAppURL);
info->title = l10n_util::GetStringUTF16(IDS_ECHE_APP_NAME);
web_app::CreateIconInfoForSystemWebApp(
info->start_url(),
{{"app_icon_256.png", 256, IDR_ASH_ECHE_APP_ICON_256_PNG}}, *info);
info->theme_color = 0xFFFFFFFF;
info->background_color = 0xFFFFFFFF;
info->display_mode = blink::mojom::DisplayMode::kMinimalUi;
info->user_display_mode = web_app::mojom::UserDisplayMode::kStandalone;
return info;
}
bool EcheSystemAppDelegate::ShouldCaptureNavigations() const {
return true;
}
bool EcheSystemAppDelegate::ShouldShowInLauncher() const {
return false;
}
bool EcheSystemAppDelegate::ShouldShowInSearchAndShelf() const {
return false;
}
bool EcheSystemAppDelegate::ShouldAllowResize() const {
return false;
}
bool EcheSystemAppDelegate::ShouldAllowMaximize() const {
return false;
}
bool EcheSystemAppDelegate::ShouldAllowFullscreen() const {
return false;
}
bool EcheSystemAppDelegate::ShouldHaveReloadButtonInMinimalUi() const {
return false;
}
bool EcheSystemAppDelegate::ShouldAllowScriptsToCloseWindows() const {
// For debug purposes, we do not allow closing windows via script under the
// debug mode.
return !base::FeatureList::IsEnabled(ash::features::kEcheSWADebugMode);
}
gfx::Rect EcheSystemAppDelegate::GetDefaultBounds(ash::BrowserDelegate*) const {
// Ensures the Eche bounds is always 16:9 portrait aspect ratio and not more
// than half of the windows.
gfx::Rect bounds =
display::Screen::GetScreen()->GetDisplayForNewWindows().work_area();
const float bounds_aspect_ratio =
static_cast<float>(bounds.width()) / bounds.height();
const bool is_landscape = (bounds_aspect_ratio >= 1);
auto new_width = is_landscape ? (bounds.height() / 2) : bounds.width() / 2;
if (kMinimumEcheSize.width() > new_width) {
new_width = kMinimumEcheSize.width();
}
bounds.ClampToCenteredSize(
gfx::Size(new_width, new_width * kDefaultAspectRatio));
return bounds;
}
bool EcheSystemAppDelegate::IsAppEnabled() const {
return base::FeatureList::IsEnabled(ash::features::kEcheSWA);
}
|