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
|
// Copyright 2020 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/web_applications/preinstalled_web_apps/google_docs.h"
#include <memory>
#include <string>
#include <vector>
#include "ash/constants/web_app_id_constants.h"
#include "base/functional/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom-shared.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/preinstalled_web_app_definition_utils.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/grit/preinstalled_web_apps_resources.h"
#include "components/webapps/common/web_app_id.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom-shared.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "ash/constants/ash_features.h"
#include "chrome/browser/ash/drive/file_system_util.h"
#endif // BUILDFLAG(IS_CHROMEOS)
namespace web_app {
namespace {
// clang-format off
constexpr Translation kNameTranslations[] = {
{"af", "Dokumente"},
{"am", "ሰነዶች"},
{"ar", "مستندات"},
{"hy", "Փաստաթղթեր"},
{"az", "Sənəd"},
{"eu", "Dokumentuak"},
{"be", "Дакументы"},
{"bn", "Docs"},
{"bg", "Документи"},
{"my", "Docs"},
{"ca", "Documents"},
{"zh-HK", "Google 文件"},
{"zh-CN", "Google 文档"},
{"zh-TW", "文件"},
{"hr", "Dokumenti"},
{"cs", "Dokumenty"},
{"da", "Docs"},
{"nl", "Documenten"},
{"en-AU", "Docs"},
{"en-GB", "Docs"},
{"et", "Dokumendid"},
{"fil", "Docs"},
{"fi", "Docs"},
{"fr", "Docs"},
{"fr-CA", "Documents"},
{"gl", "Documentos"},
{"ka", "Docs"},
{"de", "Dokumente"},
{"el", "Έγγραφα"},
{"gu", "Docs"},
{"iw", "Docs"},
{"hi", "Docs"},
{"hu", "Dokumentumok"},
{"is", "Skjöl"},
{"id", "Dokumen"},
{"it", "Documenti"},
{"ja", "ドキュメント"},
{"kn", "Docs"},
{"kk", "Құжаттар"},
{"km", "ឯកសារ"},
{"ko", "문서"},
{"lo", "ເອກະສານ"},
{"lv", "Dokumenti"},
{"lt", "Dokumentai"},
{"ms", "Dokumen"},
{"ml", "Docs"},
{"mr", "Docs"},
{"mn", "Docs"},
{"ne", "कागजात"},
{"no", "Dokumenter"},
{"or", "Docs"},
{"fa", "سندنگار"},
{"pl", "Dokumenty"},
{"pt-BR", "Textos"},
{"pt-PT", "Docs"},
{"pa", "Docs"},
{"ro", "Documente"},
{"ru", "Документы"},
{"sr", "Документи"},
{"si", "Docs"},
{"sk", "Dokumenty"},
{"sl", "Dokumenti"},
{"es", "Documentos"},
{"es-419", "Documentos"},
{"sw", "Hati za Google"},
{"sv", "Dokument"},
{"ta", "Docs"},
{"te", "Docs"},
{"th", "เอกสาร"},
{"tr", "Dokümanlar"},
{"uk", "Документи"},
{"ur", "Docs"},
{"vi", "Tài liệu"},
{"cy", "Docs"},
{"zu", "Amadokhumenti"},
};
// clang-format on
#if BUILDFLAG(IS_CHROMEOS)
bool IsDriveFsBulkPinningAvailable() {
return drive::util::IsDriveFsBulkPinningAvailable();
}
#endif // BUILDFLAG(IS_CHROMEOS)
} // namespace
ExternalInstallOptions GetConfigForGoogleDocs(bool is_standalone_tabbed) {
ExternalInstallOptions options(
/*install_url=*/GURL(
"https://docs.google.com/document/installwebapp?usp=chrome_default"),
/*user_display_mode=*/
is_standalone_tabbed ? mojom::UserDisplayMode::kStandalone
: mojom::UserDisplayMode::kBrowser,
/*install_source=*/ExternalInstallSource::kExternalDefault);
options.user_type_allowlist = {"unmanaged", "managed", "child"};
options.uninstall_and_replace.push_back("aohghmighlieiainnegkcijnfilokake");
options.expected_app_id = ash::kGoogleDocsAppId;
#if BUILDFLAG(IS_CHROMEOS)
if (IsDriveFsBulkPinningAvailable()) {
VLOG(1) << "DriveFsBulkPinning enabled, registering service worker";
options.load_and_await_service_worker_registration = true;
options.only_use_app_info_factory = false;
options.service_worker_registration_url = GURL("https://docs.google.com");
options.service_worker_registration_timeout = base::Minutes(10);
return options;
}
#endif // BUILDFLAG(IS_CHROMEOS)
options.load_and_await_service_worker_registration = false;
options.only_use_app_info_factory = true;
options.app_info_factory = base::BindRepeating(
[](bool is_standalone_tabbed) {
GURL start_url =
GURL("https://docs.google.com/document/?usp=installed_webapp");
// `manifest_id` must remain fixed even if start_url changes.
webapps::ManifestId manifest_id = GenerateManifestIdFromStartUrlOnly(
GURL("https://docs.google.com/document/?usp=installed_webapp"));
auto info = std::make_unique<WebAppInstallInfo>(manifest_id, start_url);
info->title =
base::UTF8ToUTF16(GetTranslatedName("Docs", kNameTranslations));
info->scope = GURL("https://docs.google.com/document/");
info->display_mode =
is_standalone_tabbed ? DisplayMode::kTabbed : DisplayMode::kBrowser;
info->icon_bitmaps.any = LoadBundledIcons(
{IDR_PREINSTALLED_WEB_APPS_GOOGLE_DOCS_ICON_192_PNG});
return info;
},
is_standalone_tabbed);
return options;
}
} // namespace web_app
|