Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/resource/resource_bundle_android.h" | |
| 6 | |
| 7 #include "base/android/apk_assets.h" | |
| 8 #include "base/android/jni_android.h" | |
| 9 #include "base/android/jni_string.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "jni/ResourceBundle_jni.h" | |
| 5 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 6 | 13 |
| 7 #include <string> | 14 namespace { |
| 8 | 15 // It is okay to cache and share these file descriptors since the |
| 9 #include "base/android/jni_android.h" | 16 // ResourceBundle singleton never closes the handles. |
| 10 #include "base/android/jni_string.h" | 17 int g_chrome_100_percent_fd = -1; |
| 11 #include "base/files/file_path.h" | 18 int g_resources_pack_fd = -1; |
| 12 #include "base/files/file_util.h" | 19 base::MemoryMappedFile::Region g_chrome_100_percent_region; |
| 13 #include "base/logging.h" | 20 base::MemoryMappedFile::Region g_resources_pack_region; |
|
sadrul
2015/06/22 20:35:03
Does this add a couple of new static initializers?
agrieve
2015/06/22 23:53:33
It would have a couple of weeks ago, but after get
| |
| 14 #include "base/path_service.h" | 21 } |
| 15 #include "base/strings/stringprintf.h" | |
| 16 #include "jni/ResourceBundle_jni.h" | |
| 17 #include "ui/base/resource/resource_handle.h" | |
| 18 #include "ui/base/ui_base_paths.h" | |
| 19 | 22 |
| 20 namespace ui { | 23 namespace ui { |
| 21 | 24 |
| 22 void ResourceBundle::LoadCommonResources() { | 25 void ResourceBundle::LoadCommonResources() { |
| 23 base::FilePath path; | 26 DCHECK_EQ(g_chrome_100_percent_fd, -1); |
| 24 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &path); | 27 g_chrome_100_percent_fd = base::android::OpenApkAsset( |
| 25 AddDataPackFromPath(path.AppendASCII("chrome_100_percent.pak"), | 28 "assets/chrome_100_percent.pak", &g_chrome_100_percent_region); |
| 26 SCALE_FACTOR_100P); | 29 DCHECK_GE(g_chrome_100_percent_fd, 0); |
| 30 AddDataPackFromFileRegion(base::File(g_chrome_100_percent_fd), | |
| 31 g_chrome_100_percent_region, SCALE_FACTOR_100P); | |
| 27 } | 32 } |
| 28 | 33 |
| 29 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { | 34 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { |
| 30 // Flipped image is not used on Android. | 35 // Flipped image is not used on Android. |
| 31 DCHECK_EQ(rtl, RTL_DISABLED); | 36 DCHECK_EQ(rtl, RTL_DISABLED); |
| 32 return GetImageNamed(resource_id); | 37 return GetImageNamed(resource_id); |
| 33 } | 38 } |
| 34 | 39 |
| 40 void LoadMainAndroidPackFile() { | |
| 41 DCHECK_EQ(g_resources_pack_fd, -1); | |
| 42 g_resources_pack_fd = base::android::OpenApkAsset("assets/resources.pak", | |
| 43 &g_resources_pack_region); | |
| 44 DCHECK_GE(g_resources_pack_fd, 0); | |
| 45 ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( | |
| 46 base::File(g_resources_pack_fd), g_resources_pack_region, | |
| 47 SCALE_FACTOR_NONE); | |
| 48 } | |
| 49 | |
| 50 int GetMainAndroidPackFd(base::MemoryMappedFile::Region* out_region) { | |
| 51 DCHECK_GE(g_resources_pack_fd, 0); | |
| 52 *out_region = g_resources_pack_region; | |
| 53 return g_resources_pack_fd; | |
| 54 } | |
| 55 | |
| 56 int GetCommonResourcesPackFd(base::MemoryMappedFile::Region* out_region) { | |
| 57 DCHECK_GE(g_chrome_100_percent_fd, 0); | |
| 58 *out_region = g_chrome_100_percent_region; | |
| 59 return g_chrome_100_percent_fd; | |
| 60 } | |
| 61 | |
| 35 bool AssetContainedInApk(const std::string& filename) { | 62 bool AssetContainedInApk(const std::string& filename) { |
| 36 JNIEnv* env = base::android::AttachCurrentThread(); | 63 JNIEnv* env = base::android::AttachCurrentThread(); |
| 37 return Java_ResourceBundle_assetContainedInApk( | 64 return Java_ResourceBundle_assetContainedInApk( |
| 38 env, | 65 env, |
| 39 base::android::GetApplicationContext(), | 66 base::android::GetApplicationContext(), |
| 40 base::android::ConvertUTF8ToJavaString(env, filename).obj()); | 67 base::android::ConvertUTF8ToJavaString(env, filename).obj()); |
| 41 } | 68 } |
| 42 | 69 |
| 43 bool RegisterResourceBundleAndroid(JNIEnv* env) { | 70 bool RegisterResourceBundleAndroid(JNIEnv* env) { |
| 44 return RegisterNativesImpl(env); | 71 return RegisterNativesImpl(env); |
| 45 } | 72 } |
| 46 | 73 |
| 47 } | 74 } |
| OLD | NEW |