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 @@
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
#include "base/android/locale_utils.h"
#include "base/android/path_service.h"
#include "base/android/path_utils.h"
namespace base {
......@@ -18,6 +19,7 @@ namespace android {
static RegistrationMethod kBaseRegisteredMethods[] = {
{ "BuildInfo", base::android::BuildInfo::RegisterBindings },
{ "LocaleUtils", base::android::RegisterLocaleUtils },
{ "PathService", base::android::RegisterPathService },
{ "PathUtils", base::android::RegisterPathUtils },
{ "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 @@
'sources': [
'android/java/src/org/chromium/base/BuildInfo.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/SystemMessageHandler.java',
],
......
......@@ -41,6 +41,8 @@
'android/jni_string.h',
'android/locale_utils.cc',
'android/locale_utils.h',
'android/path_service.cc',
'android/path_service.h',
'android/path_utils.cc',
'android/path_utils.h',
'at_exit.cc',
......
......@@ -13,6 +13,7 @@
#include "base/version.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths_internal.h"
#include "ui/base/ui_base_paths.h"
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
......@@ -312,11 +313,15 @@ bool PathProvider(int key, FilePath* result) {
.Append(FILE_PATH_LITERAL("resources.pak"));
break;
}
// If we're not bundled on mac, resources.pak should be next to the
// binary (e.g., for unit tests).
#endif
#elif defined(OS_ANDROID)
if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
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))
return false;
#endif
cur = cur.Append(FILE_PATH_LITERAL("resources.pak"));
break;
case chrome::DIR_RESOURCES_EXTENSION:
......
......@@ -201,12 +201,7 @@ FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale,
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);
#endif
if (!locale_file_path.empty())
locale_file_path = locale_file_path.AppendASCII(app_locale + ".pak");
......
......@@ -11,31 +11,19 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "base/stringprintf.h"
#include "ui/base/ui_base_paths.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 {
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);
AddDataPackFromPath(GetResourcesPakFilePath(
"theme_resources_100_percent.pak"),
AddDataPackFromPath(path.AppendASCII("theme_resources_100_percent.pak"),
SCALE_FACTOR_100P);
AddDataPackFromPath(GetResourcesPakFilePath(
"ui_resources_100_percent.pak"),
AddDataPackFromPath(path.AppendASCII("ui_resources_100_percent.pak"),
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
// found in the LICENSE file.
......@@ -10,6 +10,10 @@
#include "base/logging.h"
#include "base/path_service.h"
#if defined(OS_ANDROID)
#include "base/android/path_utils.h"
#endif
namespace ui {
bool PathProvider(int key, FilePath* result) {
......@@ -27,6 +31,9 @@ bool PathProvider(int key, FilePath* result) {
// App dir.
cur = cur.DirName();
cur = cur.Append(FILE_PATH_LITERAL("Resources"));
#elif defined(OS_ANDROID)
if (!PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &cur))
return false;
#else
cur = cur.Append(FILE_PATH_LITERAL("locales"));
#endif
......@@ -44,6 +51,13 @@ bool PathProvider(int key, FilePath* result) {
if (!file_util::PathExists(cur)) // we don't want to create this
return false;
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:
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
// found in the LICENSE file.
#ifndef UI_BASE_UI_BASE_PATHS_H_
#define UI_BASE_UI_BASE_PATHS_H_
#include "build/build_config.h"
#include "ui/base/ui_export.h"
// This file declares path keys for the app module. These can be used with
......@@ -17,9 +18,13 @@ enum {
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.
#if defined(OS_ANDROID)
DIR_RESOURCE_PAKS_ANDROID,
#endif
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