Commit e754da03 authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Migrate Google Docs preinstalled web app from Chrome OS JSON to C++

This CL migrates the Chrome OS JSON config for the Google Docs
preinstalled web app (located here [0]) up into the Chrome binary.

This default web app is going to be used by Chrome Windows/Mac/Linux
so this CL is deduping the offline data into one place.
A separate CL will clean up the redundant JSON config.

[0]: https://chrome-internal.googlesource.com/chromeos/overlays/chromeos-overlay/+/master/chromeos-base/chromeos-default-apps/files/web_apps/docs.json

Bug: 1104692
Change-Id: I4f713bf1dec230fe4c6f3c691d4d954ac0c5f340
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2524809
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarGlen Robertson <glenrob@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825697}
parent 3ba8d26b
......@@ -199,6 +199,18 @@ if (!is_android) {
]
output_dir = "$root_gen_dir/chrome"
}
grit("preinstalled_web_apps_resources") {
source = "preinstalled_web_apps/resources.grd"
defines = chrome_grit_defines
outputs = [
"grit/preinstalled_web_apps_resources.h",
"grit/preinstalled_web_apps_resources_map.cc",
"grit/preinstalled_web_apps_resources_map.h",
"preinstalled_web_apps_resources.pak",
]
output_dir = "$root_gen_dir/chrome"
}
}
if (is_chromeos) {
......
......@@ -19,7 +19,8 @@
},
"aohghmighlieiainnegkcijnfilokake" : {
"external_crx": "docs.crx",
"external_version": "0.0.0.6"
"external_version": "0.0.0.6",
"web_app_migration_flag": "MigrateDefaultChromeAppToWebAppsGSuite"
},
// Google Sheets
"aapocclcgogkmnckokdopfmhonfmgoek" : {
......
file://chrome/browser/web_applications/OWNERS
<?xml version="1.0" encoding="UTF-8"?>
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
<outputs>
<output filename="grit/preinstalled_web_apps_resources.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="grit/preinstalled_web_apps_resources_map.cc"
type="resource_file_map_source" />
<output filename="grit/preinstalled_web_apps_resources_map.h"
type="resource_map_header" />
<output filename="preinstalled_web_apps_resources.pak" type="data_package" />
</outputs>
<release seq="1">
<includes>
<include name="IDR_PREINSTALLED_WEB_APPS_GOOGLE_DOCS_ICON_192_PNG" file="google_docs_192.png" type="BINDATA" />
</includes>
</release>
</grit>
......@@ -30,8 +30,6 @@ source_set("web_applications") {
"pending_app_manager_impl.h",
"pending_app_registration_task.cc",
"pending_app_registration_task.h",
"preinstalled_web_apps.cc",
"preinstalled_web_apps.h",
"system_web_app_manager.cc",
"system_web_app_manager.h",
"web_app.cc",
......@@ -76,6 +74,7 @@ source_set("web_applications") {
deps = [
":web_app_group",
"//chrome/browser/web_applications/components",
"//chrome/browser/web_applications/preinstalled_web_apps",
"//chrome/common",
"//components/content_settings/core/browser",
"//components/keyed_service/content",
......@@ -207,6 +206,7 @@ source_set("web_applications_unit_tests") {
"//base/test:test_support",
"//chrome/browser",
"//chrome/browser/web_applications/components",
"//chrome/browser/web_applications/preinstalled_web_apps",
"//chrome/common",
"//chrome/test:test_support",
"//components/services/app_service/public/cpp:protocol_handling",
......@@ -257,11 +257,13 @@ source_set("web_applications_browser_tests") {
":web_applications_on_extensions",
":web_applications_on_extensions_test_support",
":web_applications_test_support",
"//build:branding_buildflags",
"//chrome/app:command_ids",
"//chrome/browser/apps/app_service:test_support",
"//chrome/browser/extensions:test_support",
"//chrome/browser/web_applications/components",
"//chrome/browser/web_applications/extensions",
"//chrome/browser/web_applications/preinstalled_web_apps",
"//chrome/test:test_support",
"//chrome/test:test_support_ui",
"//components/permissions:permissions",
......
......@@ -35,7 +35,7 @@
#include "chrome/browser/web_applications/components/web_app_install_utils.h"
#include "chrome/browser/web_applications/extension_status_utils.h"
#include "chrome/browser/web_applications/external_web_app_utils.h"
#include "chrome/browser/web_applications/preinstalled_web_apps.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/preinstalled_web_apps.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
......
......@@ -9,11 +9,14 @@
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/test/bind.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/components/external_app_install_features.h"
#include "chrome/browser/web_applications/components/os_integration_manager.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/preinstalled_web_apps.h"
#include "chrome/browser/web_applications/test/test_file_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/test/base/in_process_browser_test.h"
......@@ -481,4 +484,33 @@ IN_PROC_BROWSER_TEST_F(ExternalWebAppManagerBrowserTest,
#endif // defined(OS_CHROMEOS)
// Icon resourcs are only available on Chrome branded builds.
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
IN_PROC_BROWSER_TEST_F(ExternalWebAppManagerBrowserTest, PreinstalledWebApps) {
base::AutoReset<bool> scope =
SetExternalAppInstallFeatureAlwaysEnabledForTesting();
constexpr std::array<const char*, 1> kExpectedInstallUrls = {
"https://docs.google.com/document/installwebapp?usp=chrome_default",
};
base::RunLoop run_loop;
WebAppProvider::Get(browser()->profile())
->external_web_app_manager_for_testing()
.LoadAndSynchronizeForTesting(base::BindLambdaForTesting(
[&](std::map<GURL, InstallResultCode> install_results,
std::map<GURL, bool> uninstall_results) {
EXPECT_EQ(install_results.size(), kExpectedInstallUrls.size());
for (const char* install_url : kExpectedInstallUrls) {
EXPECT_TRUE(base::Contains(install_results, GURL(install_url)))
<< install_url;
}
EXPECT_EQ(uninstall_results.size(), 0u);
run_loop.Quit();
}));
run_loop.Run();
}
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
} // namespace web_app
......@@ -22,7 +22,7 @@
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "chrome/browser/web_applications/components/external_app_install_features.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/preinstalled_web_apps.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/preinstalled_web_apps.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_profile.h"
......@@ -174,6 +174,8 @@ class ExternalWebAppManagerTest : public testing::Test {
base::HistogramTester histograms_;
ScopedTestingPreinstalledAppData preinstalled_web_app_override_;
private:
#if defined(OS_CHROMEOS)
chromeos::FakeChromeUserManager* user_manager() {
......@@ -187,7 +189,6 @@ class ExternalWebAppManagerTest : public testing::Test {
// To support context of browser threads.
content::BrowserTaskEnvironment task_environment_;
};
TEST_F(ExternalWebAppManagerTest, ReplacementExtensionBlockedByPolicy) {
......@@ -197,14 +198,16 @@ TEST_F(ExternalWebAppManagerTest, ReplacementExtensionBlockedByPolicy) {
sync_preferences::TestingPrefServiceSyncable* prefs =
test_profile->GetTestingPrefService();
ScopedTestingPreinstalledAppData scoped_preinstalled_apps;
GURL install_url("https://test.app");
constexpr char kExtensionId[] = "abcdefghijklmnopabcdefghijklmnop";
ExternalInstallOptions options(install_url, DisplayMode::kBrowser,
ExternalInstallSource::kExternalDefault);
options.user_type_allowlist = {"unmanaged"};
options.uninstall_and_replace = {kExtensionId};
scoped_preinstalled_apps.apps.push_back(std::move(options));
options.only_use_app_info_factory = true;
options.app_info_factory = base::BindRepeating(
[]() { return std::make_unique<WebApplicationInfo>(); });
preinstalled_web_app_override_.apps.push_back(std::move(options));
auto expect_present = [&]() {
std::vector<ExternalInstallOptions> options_list =
......
......@@ -6,6 +6,7 @@
#include "base/json/json_reader.h"
#include "base/path_service.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
......@@ -20,7 +21,7 @@
#include "chrome/browser/web_applications/components/os_integration_manager.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/external_web_app_manager.h"
#include "chrome/browser/web_applications/preinstalled_web_apps.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/preinstalled_web_apps.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test.h"
......@@ -169,8 +170,10 @@ class ExternalWebAppMigrationBrowserTest : public InProcessBrowserTest {
[&](std::map<GURL, InstallResultCode> install_results,
std::map<GURL, bool> uninstall_results) {
if (expect_install) {
EXPECT_EQ(install_results.at(GetWebAppUrl()),
InstallResultCode::kSuccessNewInstall);
InstallResultCode result = install_results.at(GetWebAppUrl());
EXPECT_TRUE(result == InstallResultCode::kSuccessNewInstall ||
result ==
InstallResultCode::kSuccessOfflineOnlyInstall);
} else {
EXPECT_EQ(install_results.find(GetWebAppUrl()),
install_results.end());
......@@ -429,6 +432,13 @@ IN_PROC_BROWSER_TEST_F(ExternalWebAppMigrationBrowserTest,
options.gate_on_feature = kMigrationFlag;
options.user_type_allowlist = {"unmanaged"};
options.uninstall_and_replace.push_back(kExtensionId);
options.only_use_app_info_factory = true;
options.app_info_factory = base::BindLambdaForTesting([&]() {
auto info = std::make_unique<WebApplicationInfo>();
info->start_url = GetWebAppUrl();
info->title = base::UTF8ToUTF16("Test app");
return info;
});
preinstalled_apps.apps.push_back(std::move(options));
EXPECT_EQ(1u, GetPreinstalledWebApps().size());
// Set up pre-migration state.
......
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("preinstalled_web_apps") {
sources = [
"google_docs.cc",
"google_docs.h",
"preinstalled_web_app_utils.cc",
"preinstalled_web_app_utils.h",
"preinstalled_web_apps.cc",
"preinstalled_web_apps.h",
]
deps = [
"//build:branding_buildflags",
"//chrome/browser/resources:preinstalled_web_apps_resources",
"//chrome/browser/web_applications/components",
"//chrome/common",
]
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// 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 "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/preinstalled_web_app_utils.h"
#include "chrome/common/web_application_info.h"
#include "chrome/grit/preinstalled_web_apps_resources.h"
namespace web_app {
ExternalInstallOptions GetConfigForGoogleDocs() {
ExternalInstallOptions options(
/*install_url=*/GURL(
"https://docs.google.com/document/installwebapp?usp=chrome_default"),
/*user_display_mode=*/DisplayMode::kBrowser,
/*install_source=*/ExternalInstallSource::kExternalDefault);
options.user_type_allowlist = {"unmanaged", "managed", "child"};
options.gate_on_feature = "MigrateDefaultChromeAppToWebAppsGSuite";
options.uninstall_and_replace.push_back("aohghmighlieiainnegkcijnfilokake");
options.load_and_await_service_worker_registration = false;
#if !defined(OS_CHROMEOS)
options.only_use_app_info_factory = true;
#endif // !defined(OS_CHROMEOS)
options.app_info_factory = base::BindRepeating([]() {
auto info = std::make_unique<WebApplicationInfo>();
info->title = base::UTF8ToUTF16("Docs");
info->start_url =
GURL("https://docs.google.com/document/?usp=installed_webapp");
info->scope = GURL("https://docs.google.com/document/");
info->display_mode = DisplayMode::kBrowser;
info->icon_bitmaps_any =
LoadBundledIcons({IDR_PREINSTALLED_WEB_APPS_GOOGLE_DOCS_ICON_192_PNG});
return info;
});
return options;
}
} // namespace web_app
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_GOOGLE_DOCS_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_GOOGLE_DOCS_H_
#include "chrome/browser/web_applications/components/external_install_options.h"
namespace web_app {
ExternalInstallOptions GetConfigForGoogleDocs();
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_GOOGLE_DOCS_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// 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/preinstalled_web_app_utils.h"
#include "ui/base/resource/resource_bundle.h"
namespace web_app {
std::map<SquareSizePx, SkBitmap> LoadBundledIcons(
const std::initializer_list<int>& icon_resource_ids) {
std::map<SquareSizePx, SkBitmap> results;
for (int id : icon_resource_ids) {
const gfx::Image& image =
ui::ResourceBundle::GetSharedInstance().GetImageNamed(id);
DCHECK_EQ(image.Width(), image.Height());
results[image.Width()] = image.AsBitmap();
}
return results;
}
} // namespace web_app
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_PREINSTALLED_WEB_APP_UTILS_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_PREINSTALLED_WEB_APP_UTILS_H_
#include "chrome/common/web_application_info.h"
namespace web_app {
std::map<SquareSizePx, SkBitmap> LoadBundledIcons(
const std::initializer_list<int>& icon_resource_ids);
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_PREINSTALLED_WEB_APP_UTILS_H_
......@@ -2,11 +2,13 @@
// 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.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/preinstalled_web_apps.h"
#include "base/feature_list.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/web_applications/components/external_app_install_features.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/preinstalled_web_apps/google_docs.h"
namespace web_app {
namespace {
......@@ -18,9 +20,21 @@ std::vector<ExternalInstallOptions> GetPreinstalledAppData() {
if (g_preinstalled_app_data_for_testing)
return *g_preinstalled_app_data_for_testing;
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING)
return {};
#endif
// TODO(crbug.com/1104692): Replace these C++ configs with JSON configs like
// those seen in: chrome/test/data/web_app_default_apps/good_json
// This requires:
// - Mimicking the directory packaging used by
// chrome/browser/resources/default_apps.
// - Hooking up a second JSON config load to ExternalWebAppManager.
// - Validating everything works on all OSs (Mac bundles things differently).
// - Ensure that these resources are correctly installed by our Chrome
// installers on every desktop platform.
return {
// TODO(devlin): Add the web apps that should come preinstalled, gated by
// OS.
GetConfigForGoogleDocs(),
};
}
......@@ -42,6 +56,13 @@ std::vector<ExternalInstallOptions> GetPreinstalledWebApps() {
for (ExternalInstallOptions& app_data : GetPreinstalledAppData()) {
DCHECK_EQ(app_data.install_source, ExternalInstallSource::kExternalDefault);
#if !defined(OS_CHROMEOS)
// Non-Chrome OS platforms are not permitted to fetch the web app install
// URLs during start up.
DCHECK(app_data.only_use_app_info_factory);
DCHECK(app_data.app_info_factory);
#endif // defined(OS_CHROMEOS)
// Preinstalled web apps should not have OS shortcuts of any kind.
app_data.add_to_applications_menu = false;
app_data.add_to_desktop = false;
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_H_
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_PREINSTALLED_WEB_APPS_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_PREINSTALLED_WEB_APPS_H_
#include <vector>
......@@ -29,4 +29,4 @@ std::vector<ExternalInstallOptions> GetPreinstalledWebApps();
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_H_
#endif // CHROME_BROWSER_WEB_APPLICATIONS_PREINSTALLED_WEB_APPS_PREINSTALLED_WEB_APPS_H_
......@@ -164,6 +164,11 @@ template("chrome_extra_paks") {
"//content/browser/devtools:devtools_resources",
"//headless:resources",
]
if (is_chrome_branded) {
sources +=
[ "$root_gen_dir/chrome/preinstalled_web_apps_resources.pak" ]
deps += [ "//chrome/browser/resources:preinstalled_web_apps_resources" ]
}
}
if (is_chromeos) {
sources += [
......
......@@ -156,6 +156,9 @@
"chrome/browser/resources/new_tab_page/new_tab_page_resources.grd": {
"includes": [1680],
},
"chrome/browser/resources/preinstalled_web_apps/resources.grd": {
"includes": [1710],
},
"<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/print_preview/print_preview_resources.grd": {
"META": {"sizes": {"includes": [500],}},
"includes": [1720],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment