Commit f152b67b authored by benm@chromium.org's avatar benm@chromium.org

Android requires some extra functionality to set the path to it's resource pak...

Android requires some extra functionality to set the path to it's resource pak files and native libraries.
    
This patch adds a new value to the PathService to implement the resource pak override and update the places that load pak files to take advantage of it.
    
Also adds a function for embedders to set the path to native libraries.


Review URL: https://chromiumcodereview.appspot.com/10802065

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149842 0039d316-1c4b-4281-b951-d872f2087c98
parent a94ba89a
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_registrar.h" #include "base/android/jni_registrar.h"
#include "base/android/locale_utils.h" #include "base/android/locale_utils.h"
#include "base/android/path_service.h"
#include "base/android/path_utils.h" #include "base/android/path_utils.h"
namespace base { namespace base {
...@@ -18,6 +19,7 @@ namespace android { ...@@ -18,6 +19,7 @@ namespace android {
static RegistrationMethod kBaseRegisteredMethods[] = { static RegistrationMethod kBaseRegisteredMethods[] = {
{ "BuildInfo", base::android::BuildInfo::RegisterBindings }, { "BuildInfo", base::android::BuildInfo::RegisterBindings },
{ "LocaleUtils", base::android::RegisterLocaleUtils }, { "LocaleUtils", base::android::RegisterLocaleUtils },
{ "PathService", base::android::RegisterPathService },
{ "PathUtils", base::android::RegisterPathUtils }, { "PathUtils", base::android::RegisterPathUtils },
{ "SystemMessageHandler", base::MessagePumpForUI::RegisterBindings }, { "SystemMessageHandler", base::MessagePumpForUI::RegisterBindings },
}; };
......
// Copyright (c) 2012 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.
package org.chromium.base;
/**
* This class provides java side access to the native PathService.
*/
@JNINamespace("base::android")
public abstract class PathService {
// Must match the value of DIR_MODULE in base/base_paths.h!
public static final int DIR_MODULE = 3;
// Prevent instantiation.
private PathService() {}
public static void override(int what, String path) {
nativeOverride(what, path);
}
private static native void nativeOverride(int what, String path);
}
// Copyright (c) 2012 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 "base/android/path_service.h"
#include "base/file_path.h"
#include "base/path_service.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "jni/PathService_jni.h"
namespace base {
namespace android {
void Override(JNIEnv* env, jclass clazz, jint what, jstring path) {
FilePath file_path(ConvertJavaStringToUTF8(env, path));
PathService::Override(what, file_path);
}
bool RegisterPathService(JNIEnv* env) {
return RegisterNativesImpl(env);
}
} // namespace android
} // namespace base
// Copyright (c) 2012 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 BASE_ANDROID_PATH_SERVICE_H_
#define BASE_ANDROID_PATH_SERVICE_H_
#include <jni.h>
namespace base {
namespace android {
bool RegisterPathService(JNIEnv* env);
} // namespace android
} // namespace base
#endif // BASE_ANDROID_PATH_SERVICE_H_
...@@ -920,6 +920,7 @@ ...@@ -920,6 +920,7 @@
'sources': [ 'sources': [
'android/java/src/org/chromium/base/BuildInfo.java', 'android/java/src/org/chromium/base/BuildInfo.java',
'android/java/src/org/chromium/base/LocaleUtils.java', 'android/java/src/org/chromium/base/LocaleUtils.java',
'android/java/src/org/chromium/base/PathService.java',
'android/java/src/org/chromium/base/PathUtils.java', 'android/java/src/org/chromium/base/PathUtils.java',
'android/java/src/org/chromium/base/SystemMessageHandler.java', 'android/java/src/org/chromium/base/SystemMessageHandler.java',
], ],
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
'android/jni_string.h', 'android/jni_string.h',
'android/locale_utils.cc', 'android/locale_utils.cc',
'android/locale_utils.h', 'android/locale_utils.h',
'android/path_service.cc',
'android/path_service.h',
'android/path_utils.cc', 'android/path_utils.cc',
'android/path_utils.h', 'android/path_utils.h',
'at_exit.cc', 'at_exit.cc',
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/version.h" #include "base/version.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h" #include "chrome/common/chrome_paths_internal.h"
#include "ui/base/ui_base_paths.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
...@@ -312,11 +313,15 @@ bool PathProvider(int key, FilePath* result) { ...@@ -312,11 +313,15 @@ bool PathProvider(int key, FilePath* result) {
.Append(FILE_PATH_LITERAL("resources.pak")); .Append(FILE_PATH_LITERAL("resources.pak"));
break; break;
} }
// If we're not bundled on mac, resources.pak should be next to the #elif defined(OS_ANDROID)
// binary (e.g., for unit tests). if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
#endif return false;
#else
// If we're not bundled on mac or Android, resources.pak should be next
// to the binary (e.g., for unit tests).
if (!PathService::Get(base::DIR_MODULE, &cur)) if (!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"));
break; break;
case chrome::DIR_RESOURCES_EXTENSION: case chrome::DIR_RESOURCES_EXTENSION:
......
...@@ -201,12 +201,7 @@ FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, ...@@ -201,12 +201,7 @@ FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale,
FilePath locale_file_path; FilePath locale_file_path;
#if defined(OS_ANDROID)
PathService::Get(base::DIR_ANDROID_APP_DATA, &locale_file_path);
locale_file_path = locale_file_path.Append(FILE_PATH_LITERAL("paks"));
#else
PathService::Get(ui::DIR_LOCALES, &locale_file_path); PathService::Get(ui::DIR_LOCALES, &locale_file_path);
#endif
if (!locale_file_path.empty()) if (!locale_file_path.empty())
locale_file_path = locale_file_path.AppendASCII(app_locale + ".pak"); locale_file_path = locale_file_path.AppendASCII(app_locale + ".pak");
......
...@@ -11,31 +11,19 @@ ...@@ -11,31 +11,19 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "ui/base/ui_base_paths.h"
#include "ui/base/resource/resource_handle.h" #include "ui/base/resource/resource_handle.h"
namespace {
FilePath GetResourcesPakFilePath(const std::string& pak_name) {
FilePath path;
if (PathService::Get(base::DIR_ANDROID_APP_DATA, &path))
return path.AppendASCII("paks").AppendASCII(pak_name.c_str());
// Return just the name of the pack file.
return FilePath(pak_name.c_str());
}
} // namespace
namespace ui { namespace ui {
void ResourceBundle::LoadCommonResources() { void ResourceBundle::LoadCommonResources() {
AddDataPackFromPath(GetResourcesPakFilePath("chrome.pak"), FilePath path;
PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &path);
AddDataPackFromPath(path.AppendASCII("chrome.pak"),
SCALE_FACTOR_100P); SCALE_FACTOR_100P);
AddDataPackFromPath(GetResourcesPakFilePath( AddDataPackFromPath(path.AppendASCII("theme_resources_100_percent.pak"),
"theme_resources_100_percent.pak"),
SCALE_FACTOR_100P); SCALE_FACTOR_100P);
AddDataPackFromPath(GetResourcesPakFilePath( AddDataPackFromPath(path.AppendASCII("ui_resources_100_percent.pak"),
"ui_resources_100_percent.pak"),
SCALE_FACTOR_100P); SCALE_FACTOR_100P);
} }
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#if defined(OS_ANDROID)
#include "base/android/path_utils.h"
#endif
namespace ui { namespace ui {
bool PathProvider(int key, FilePath* result) { bool PathProvider(int key, FilePath* result) {
...@@ -27,6 +31,9 @@ bool PathProvider(int key, FilePath* result) { ...@@ -27,6 +31,9 @@ bool PathProvider(int key, FilePath* result) {
// App dir. // App dir.
cur = cur.DirName(); cur = cur.DirName();
cur = cur.Append(FILE_PATH_LITERAL("Resources")); cur = cur.Append(FILE_PATH_LITERAL("Resources"));
#elif defined(OS_ANDROID)
if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
return false;
#else #else
cur = cur.Append(FILE_PATH_LITERAL("locales")); cur = cur.Append(FILE_PATH_LITERAL("locales"));
#endif #endif
...@@ -44,6 +51,13 @@ bool PathProvider(int key, FilePath* result) { ...@@ -44,6 +51,13 @@ bool PathProvider(int key, FilePath* result) {
if (!file_util::PathExists(cur)) // we don't want to create this if (!file_util::PathExists(cur)) // we don't want to create this
return false; return false;
break; break;
#if defined(OS_ANDROID)
case ui::DIR_RESOURCE_PAKS_ANDROID:
if (!PathService::Get(base::DIR_ANDROID_APP_DATA, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("paks"));
break;
#endif
default: default:
return false; return false;
} }
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef UI_BASE_UI_BASE_PATHS_H_ #ifndef UI_BASE_UI_BASE_PATHS_H_
#define UI_BASE_UI_BASE_PATHS_H_ #define UI_BASE_UI_BASE_PATHS_H_
#include "build/build_config.h"
#include "ui/base/ui_export.h" #include "ui/base/ui_export.h"
// This file declares path keys for the app module. These can be used with // This file declares path keys for the app module. These can be used with
...@@ -17,9 +18,13 @@ enum { ...@@ -17,9 +18,13 @@ enum {
DIR_LOCALES, // Directory where locale resources are stored. DIR_LOCALES, // Directory where locale resources are stored.
// Valid only in development environment; TODO(darin): move these // Valid only in development environment; TODO(darin): move this
DIR_TEST_DATA, // Directory where unit test data resides. DIR_TEST_DATA, // Directory where unit test data resides.
#if defined(OS_ANDROID)
DIR_RESOURCE_PAKS_ANDROID,
#endif
PATH_END PATH_END
}; };
......
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