Commit 0a25657e authored by Samuel Huang's avatar Samuel Huang Committed by Commit Bot

[DevUI DFM] Add helpers to load native resources in "dev_ui_resources.pak".

This CL adds helper functions to load DevUI DFM native resources.
* Add enum chrome::FILE_DEV_UI_RESOURCES_PACK to specify path for
  "dev_ui_resources.pak" on Android.
* Add LoadAndroidDevUiPackFile().
  * Adds another {file descriptor, memory mapped file regions} global
    variable in resource_bundle_android.h. All these will be cleaned up
    in the future.
* Add LoadDevUiResources() (in new file) as the main function to call
  to load DevUI DFM resources (hidden behind DFMIFY_DEV_UI).
  * There's no need for a function to return the file descriptor of
    "dev_ui_resources.pak", because we do not intend to forward it to
    child processes.

Bug: 927131
Change-Id: I0c4e42e33b959d0a022f1287748573ebaf79c685
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769218Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691672}
parent 9eccfd83
...@@ -35,6 +35,7 @@ import("//ui/base/ui_features.gni") ...@@ -35,6 +35,7 @@ import("//ui/base/ui_features.gni")
# produces a conflict for the "grit" template so we have to only include one. # produces a conflict for the "grit" template so we have to only include one.
if (is_android) { if (is_android) {
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
import("//chrome/android/features/dev_ui/dev_ui_module.gni")
} else { } else {
import("//tools/grit/grit_rule.gni") import("//tools/grit/grit_rule.gni")
} }
...@@ -2380,6 +2381,8 @@ jumbo_split_static_library("browser") { ...@@ -2380,6 +2381,8 @@ jumbo_split_static_library("browser") {
"android/devtools_manager_delegate_android.h", "android/devtools_manager_delegate_android.h",
"android/devtools_server.cc", "android/devtools_server.cc",
"android/devtools_server.h", "android/devtools_server.h",
"android/dfm_resource_bundle_helper.cc",
"android/dfm_resource_bundle_helper.h",
"android/digital_asset_links/digital_asset_links_handler.cc", "android/digital_asset_links/digital_asset_links_handler.cc",
"android/digital_asset_links/digital_asset_links_handler.h", "android/digital_asset_links/digital_asset_links_handler.h",
"android/document/document_web_contents_delegate.cc", "android/document/document_web_contents_delegate.cc",
...@@ -2884,6 +2887,7 @@ jumbo_split_static_library("browser") { ...@@ -2884,6 +2887,7 @@ jumbo_split_static_library("browser") {
"translate/android/translate_bridge.cc", "translate/android/translate_bridge.cc",
] ]
public_deps += [ public_deps += [
"//chrome/android/features/dev_ui:buildflags",
"//components/image_fetcher/core", "//components/image_fetcher/core",
"//components/ntp_snippets", "//components/ntp_snippets",
] ]
......
...@@ -3,6 +3,7 @@ include_rules = [ ...@@ -3,6 +3,7 @@ include_rules = [
"+cc/paint", "+cc/paint",
"+chrome/android/chrome_jni_headers", "+chrome/android/chrome_jni_headers",
"+chrome/android/features/autofill_assistant/jni_headers", "+chrome/android/features/autofill_assistant/jni_headers",
"+chrome/android/features/dev_ui",
"+chrome/android/public/profiles/jni_headers", "+chrome/android/public/profiles/jni_headers",
"+chrome/app", "+chrome/app",
"+chrome/chrome_watcher", "+chrome/chrome_watcher",
......
// Copyright 2019 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/android/dfm_resource_bundle_helper.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/common/chrome_paths.h"
#include "ui/base/resource/resource_bundle_android.h"
namespace android {
#if BUILDFLAG(DFMIFY_DEV_UI)
void LoadDevUiResources() {
base::FilePath path_on_disk;
base::PathService::Get(chrome::FILE_DEV_UI_RESOURCES_PACK, &path_on_disk);
ui::LoadAndroidDevUiPackFile("assets/dev_ui_resources.pak", path_on_disk);
}
#endif // BUILDFLAG(DFMIFY_DEV_UI)
} // namespace android
// Copyright 2019 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_ANDROID_DFM_RESOURCE_BUNDLE_HELPER_H_
#define CHROME_BROWSER_ANDROID_DFM_RESOURCE_BUNDLE_HELPER_H_
#include "chrome/android/features/dev_ui/buildflags.h"
namespace android {
#if BUILDFLAG(DFMIFY_DEV_UI)
// Loads the resources for DevUI pages. Performs file I/O, and should be called
// on a worker thread.
void LoadDevUiResources();
#endif // BUILDFLAG(DFMIFY_DEV_UI)
} // namespace android
#endif // CHROME_BROWSER_ANDROID_DFM_RESOURCE_BUNDLE_HELPER_H_
...@@ -383,7 +383,8 @@ bool PathProvider(int key, base::FilePath* result) { ...@@ -383,7 +383,8 @@ bool PathProvider(int key, base::FilePath* result) {
.AppendASCII(base::GetNativeLibraryName(kWidevineCdmLibraryName)); .AppendASCII(base::GetNativeLibraryName(kWidevineCdmLibraryName));
break; break;
#endif // BUILDFLAG(ENABLE_WIDEVINE) && BUILDFLAG(ENABLE_LIBRARY_CDMS) #endif // BUILDFLAG(ENABLE_WIDEVINE) && BUILDFLAG(ENABLE_LIBRARY_CDMS)
case chrome::FILE_RESOURCES_PACK: case chrome::FILE_RESOURCES_PACK: // Falls through.
case chrome::FILE_DEV_UI_RESOURCES_PACK:
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
cur = base::mac::FrameworkBundlePath(); cur = base::mac::FrameworkBundlePath();
cur = cur.Append(FILE_PATH_LITERAL("Resources")) cur = cur.Append(FILE_PATH_LITERAL("Resources"))
...@@ -392,14 +393,21 @@ bool PathProvider(int key, base::FilePath* result) { ...@@ -392,14 +393,21 @@ bool PathProvider(int key, base::FilePath* result) {
#elif defined(OS_ANDROID) #elif defined(OS_ANDROID)
if (!base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur)) if (!base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
return false; return false;
if (key == chrome::FILE_DEV_UI_RESOURCES_PACK) {
cur = cur.Append(FILE_PATH_LITERAL("dev_ui_resources.pak"));
} else {
DCHECK_EQ(chrome::FILE_RESOURCES_PACK, key);
cur = cur.Append(FILE_PATH_LITERAL("resources.pak"));
}
#else #else
// If we're not bundled on mac or Android, resources.pak should be next // If we're not bundled on mac or Android, resources.pak should be next
// to the binary (e.g., for unit tests). // to the binary (e.g., for unit tests).
if (!base::PathService::Get(base::DIR_MODULE, &cur)) if (!base::PathService::Get(base::DIR_MODULE, &cur))
return false; return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("resources.pak")); cur = cur.Append(FILE_PATH_LITERAL("resources.pak"));
#endif
break; break;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
case chrome::DIR_CHROMEOS_WALLPAPERS: case chrome::DIR_CHROMEOS_WALLPAPERS:
if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur)) if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur))
......
...@@ -94,9 +94,13 @@ enum { ...@@ -94,9 +94,13 @@ enum {
DIR_PNACL_COMPONENT, // Full path to the latest PNaCl version DIR_PNACL_COMPONENT, // Full path to the latest PNaCl version
// (subdir of DIR_PNACL_BASE). // (subdir of DIR_PNACL_BASE).
FILE_WIDEVINE_CDM, // Full path to the Widevine CDM. FILE_WIDEVINE_CDM, // Full path to the Widevine CDM.
FILE_RESOURCES_PACK, // Full path to the .pak file containing FILE_RESOURCES_PACK, // Full path to the .pak file containing binary data.
// binary data (e.g., html files and images // This includes data for internal pages (e.g., html
// used by internal pages). // files and images), unless these resources are
// purposefully split into a separate file.
FILE_DEV_UI_RESOURCES_PACK, // Full path to the .pak file containing
// binary data for internal pages (e.g., html
// files and images).
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
DIR_CHROMEOS_WALLPAPERS, // Directory where downloaded chromeos DIR_CHROMEOS_WALLPAPERS, // Directory where downloaded chromeos
// wallpapers reside. // wallpapers reside.
......
...@@ -25,10 +25,12 @@ bool g_load_secondary_locale_paks = false; ...@@ -25,10 +25,12 @@ bool g_load_secondary_locale_paks = false;
// ResourceBundle singleton never closes the handles. // ResourceBundle singleton never closes the handles.
int g_chrome_100_percent_fd = -1; int g_chrome_100_percent_fd = -1;
int g_resources_pack_fd = -1; int g_resources_pack_fd = -1;
int g_dev_ui_resources_pack_fd = -1;
int g_locale_pack_fd = -1; int g_locale_pack_fd = -1;
int g_secondary_locale_pack_fd = -1; int g_secondary_locale_pack_fd = -1;
base::MemoryMappedFile::Region g_chrome_100_percent_region; base::MemoryMappedFile::Region g_chrome_100_percent_region;
base::MemoryMappedFile::Region g_resources_pack_region; base::MemoryMappedFile::Region g_resources_pack_region;
base::MemoryMappedFile::Region g_dev_ui_resources_pack_region;
base::MemoryMappedFile::Region g_locale_pack_region; base::MemoryMappedFile::Region g_locale_pack_region;
base::MemoryMappedFile::Region g_secondary_locale_pack_region; base::MemoryMappedFile::Region g_secondary_locale_pack_region;
...@@ -177,6 +179,19 @@ void LoadMainAndroidPackFile(const char* path_within_apk, ...@@ -177,6 +179,19 @@ void LoadMainAndroidPackFile(const char* path_within_apk,
} }
} }
void LoadAndroidDevUiPackFile(const char* path_within_apk,
const base::FilePath& disk_file_path) {
if (LoadFromApkOrFile(path_within_apk, &disk_file_path,
&g_dev_ui_resources_pack_fd,
&g_dev_ui_resources_pack_region)) {
ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion(
base::File(g_dev_ui_resources_pack_fd), g_dev_ui_resources_pack_region,
SCALE_FACTOR_NONE);
} else {
NOTREACHED() << "Failed to load DevUI resources.";
}
}
int GetMainAndroidPackFd(base::MemoryMappedFile::Region* out_region) { int GetMainAndroidPackFd(base::MemoryMappedFile::Region* out_region) {
DCHECK_GE(g_resources_pack_fd, 0); DCHECK_GE(g_resources_pack_fd, 0);
*out_region = g_resources_pack_region; *out_region = g_resources_pack_region;
......
...@@ -14,11 +14,17 @@ ...@@ -14,11 +14,17 @@
namespace ui { namespace ui {
// Loads "resources.apk" from the .apk. Falls back to loading from disk, which // Loads "resources.apk" from the .apk. Falls back to loading from disk, which
// is necessary for tests. Returns true if it succeeds, false otherwise. // is necessary for tests.
UI_BASE_EXPORT void LoadMainAndroidPackFile( UI_BASE_EXPORT void LoadMainAndroidPackFile(
const char* path_within_apk, const char* path_within_apk,
const base::FilePath& disk_file_path); const base::FilePath& disk_file_path);
// Loads "dev_ui_resources.apk" from the .apk, for the DevUI DFM. Falls back to
// loading from disk.
UI_BASE_EXPORT void LoadAndroidDevUiPackFile(
const char* path_within_apk,
const base::FilePath& disk_file_path);
// Returns the file descriptor and region for resources.pak. // Returns the file descriptor and region for resources.pak.
UI_BASE_EXPORT int GetMainAndroidPackFd( UI_BASE_EXPORT int GetMainAndroidPackFd(
base::MemoryMappedFile::Region* out_region); base::MemoryMappedFile::Region* out_region);
......
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