Use the same pak files for the Alloy and Chrome runtimes (see issue #2969)

Chrome currently uses chrome_100_percent.pak, chrome_200_percent.pak,
resources.pak and locales/<locale>.pak files. This change adds CEF
resources to those existing pak files and updates the Alloy runtime to
use them instead of the previous CEF-specific pak files (cef.pak,
cef_100_percent.pak, cef_200_percent.pak, cef_extensions.pak,
devtools_resources.pak) which are no longer generated.

The addition of Chrome resources results in an ~16% (~4.1MB) increase in total
combined pak file size vs. the previous CEF-specific pak files. While a size
increase is not ideal for the Alloy runtime, it seems preferable to the
alternative of distributing separate (and partially duplicated) pak files for
each runtime, which would have added ~9.8MB to the total binary distribution
size.
This commit is contained in:
Marshall Greenblatt
2021-02-28 15:23:42 -05:00
parent a6a8c0e845
commit 8424f166cc
13 changed files with 160 additions and 518 deletions

View File

@@ -21,6 +21,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "components/url_formatter/url_fixer.h"
#include "url/url_constants.h"
#if defined(TOOLKIT_VIEWS)
@@ -435,13 +436,24 @@ bool ChromeBrowserHostImpl::Navigate(const content::OpenURLParams& params) {
}
if (browser_) {
// Fix common problems with user-typed text. Among other things, this:
// - Converts absolute file paths to "file://" URLs.
// - Normalizes "about:" and "chrome:" to "chrome://" URLs.
// - Adds the "http://" scheme if none was specified.
GURL gurl = url_formatter::FixupURL(params.url.possibly_invalid_spec(),
std::string());
if (!gurl.is_valid()) {
LOG(ERROR) << "Invalid URL: " << params.url.possibly_invalid_spec();
return false;
}
// This is generally equivalent to calling Browser::OpenURL, except:
// 1. It doesn't trigger a call to CefRequestHandler::OnOpenURLFromTab, and
// 2. It navigates in this CefBrowserHost's WebContents instead of
// (a) creating a new WebContents, or (b) using the Browser's active
// WebContents (which may not be the same), and
// 3. There is no risk of triggering chrome's popup blocker.
NavigateParams nav_params(browser_, params.url, params.transition);
NavigateParams nav_params(browser_, gurl, params.transition);
nav_params.FillNavigateParamsFromOpenURLParams(params);
// Always navigate in the current tab.

View File

@@ -35,7 +35,6 @@
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
#include "chrome/browser/ui/webui/theme_source.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chrome_unscaled_resources.h"
#include "content/browser/renderer_host/debug_urls.h"
#include "content/browser/webui/content_web_ui_controller_factory.h"
#include "content/public/browser/browser_url_handler.h"
@@ -354,17 +353,9 @@ bool OnExtensionsSupportUI(std::string* mime_type, std::string* output) {
}
bool OnLicenseUI(std::string* mime_type, std::string* output) {
// TODO(chrome): Currently, CEF-specific resources for the Alloy runtime come
// from cef/libcef/resources/cef_resources.grd via cef.pak and CEF-specific
// resources for the Chrome runtime come from
// chrome/app/theme/chrome_unscaled_resources.grd via chrome_100_percent.pak.
// It would be better to have a single pak file (and single ID value) for
// CEF-specific resources and share the same *.pak files as Chrome for the
// other resources.
std::string piece =
ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(
cef::IsChromeRuntimeEnabled() ? IDR_CHROME_CEF_LICENSE_TXT
: IDR_CEF_LICENSE_TXT);
IDR_CEF_LICENSE_TXT);
if (piece.empty()) {
NOTREACHED() << "Failed to load license txt resource.";
return false;

View File

@@ -486,9 +486,8 @@ AlloyMainDelegate::GetWebWorkerTaskRunner() {
void AlloyMainDelegate::InitializeResourceBundle() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
base::FilePath cef_pak_file, cef_100_percent_pak_file,
cef_200_percent_pak_file, cef_extensions_pak_file, devtools_pak_file,
locales_dir;
base::FilePath resources_pak_file, chrome_100_percent_pak_file,
chrome_200_percent_pak_file, locales_dir;
base::FilePath resources_dir;
if (command_line->HasSwitch(switches::kResourcesDirPath)) {
@@ -503,15 +502,12 @@ void AlloyMainDelegate::InitializeResourceBundle() {
if (!resource_bundle_delegate_.pack_loading_disabled()) {
if (!resources_dir.empty()) {
CHECK(resources_dir.IsAbsolute());
cef_pak_file = resources_dir.Append(FILE_PATH_LITERAL("cef.pak"));
cef_100_percent_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("cef_100_percent.pak"));
cef_200_percent_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("cef_200_percent.pak"));
cef_extensions_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("cef_extensions.pak"));
devtools_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("devtools_resources.pak"));
resources_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("resources.pak"));
chrome_100_percent_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("chrome_100_percent.pak"));
chrome_200_percent_pak_file =
resources_dir.Append(FILE_PATH_LITERAL("chrome_200_percent.pak"));
}
if (command_line->HasSwitch(switches::kLocalesDirPath))
@@ -539,54 +535,36 @@ void AlloyMainDelegate::InitializeResourceBundle() {
resource_bundle_delegate_.set_allow_pack_file_load(true);
if (base::PathExists(cef_pak_file)) {
resource_bundle.AddDataPackFromPath(cef_pak_file, ui::SCALE_FACTOR_NONE);
if (base::PathExists(resources_pak_file)) {
resource_bundle.AddDataPackFromPath(resources_pak_file,
ui::SCALE_FACTOR_NONE);
} else {
LOG(ERROR) << "Could not load cef.pak";
LOG(ERROR) << "Could not load resources.pak";
}
// On OS X and Linux/Aura always load the 1x data pack first as the 2x data
// pack contains both 1x and 2x images.
const bool load_100_percent =
#if defined(OS_WIN)
resource_util::IsScaleFactorSupported(ui::SCALE_FACTOR_100P);
#else
true;
#endif
if (load_100_percent) {
if (base::PathExists(cef_100_percent_pak_file)) {
resource_bundle.AddDataPackFromPath(cef_100_percent_pak_file,
// Always load the 1x data pack first as the 2x data pack contains both 1x
// and 2x images. The 1x data pack only has 1x images, thus passes in an
// accurate scale factor to gfx::ImageSkia::AddRepresentation.
if (resource_util::IsScaleFactorSupported(ui::SCALE_FACTOR_100P)) {
if (base::PathExists(chrome_100_percent_pak_file)) {
resource_bundle.AddDataPackFromPath(chrome_100_percent_pak_file,
ui::SCALE_FACTOR_100P);
} else {
LOG(ERROR) << "Could not load cef_100_percent.pak";
LOG(ERROR) << "Could not load chrome_100_percent.pak";
}
}
if (resource_util::IsScaleFactorSupported(ui::SCALE_FACTOR_200P)) {
if (base::PathExists(cef_200_percent_pak_file)) {
resource_bundle.AddDataPackFromPath(cef_200_percent_pak_file,
if (base::PathExists(chrome_200_percent_pak_file)) {
resource_bundle.AddDataPackFromPath(chrome_200_percent_pak_file,
ui::SCALE_FACTOR_200P);
} else {
LOG(ERROR) << "Could not load cef_200_percent.pak";
LOG(ERROR) << "Could not load chrome_200_percent.pak";
}
}
if (extensions::ExtensionsEnabled() ||
!command_line->HasSwitch(switches::kDisablePlugins)) {
if (base::PathExists(cef_extensions_pak_file)) {
resource_bundle.AddDataPackFromPath(cef_extensions_pak_file,
ui::SCALE_FACTOR_NONE);
} else {
LOG(ERROR) << "Could not load cef_extensions.pak";
}
}
if (base::PathExists(devtools_pak_file)) {
resource_bundle.AddDataPackFromPath(devtools_pak_file,
ui::SCALE_FACTOR_NONE);
}
// Skip the default pak file loading that would otherwise occur in
// ResourceBundle::LoadChromeResources().
resource_bundle_delegate_.set_allow_pack_file_load(false);
}
}