summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DEPS2
-rw-r--r--base/i18n/icu_util.cc37
-rw-r--r--base/mac/foundation_util.h3
-rw-r--r--base/mac/foundation_util.mm9
4 files changed, 49 insertions, 2 deletions
diff --git a/DEPS b/DEPS
index e600536..ee8171a 100644
--- a/DEPS
+++ b/DEPS
@@ -47,7 +47,7 @@ deps = {
"/trunk/deps/third_party/WebKit@73335",
"src/third_party/icu":
- "/trunk/deps/third_party/icu42@69864",
+ "/trunk/deps/third_party/icu42@74439",
"src/third_party/hunspell":
"/trunk/deps/third_party/hunspell@65351",
diff --git a/base/i18n/icu_util.cc b/base/i18n/icu_util.cc
index d378a25..eb7a688 100644
--- a/base/i18n/icu_util.cc
+++ b/base/i18n/icu_util.cc
@@ -21,6 +21,10 @@
#include "unicode/putil.h"
#include "unicode/udata.h"
+#if defined(OS_MACOSX)
+#include "base/mac/foundation_util.h"
+#endif
+
#define ICU_UTIL_DATA_FILE 0
#define ICU_UTIL_DATA_SHARED 1
#define ICU_UTIL_DATA_STATIC 2
@@ -35,10 +39,14 @@
#endif // ICU_UTIL_DATA_IMPL
-#if defined(OS_WIN)
+#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
+#define ICU_UTIL_DATA_FILE_NAME "icudt" U_ICU_VERSION_SHORT "l.dat"
+#elif ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_SHARED
#define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat"
+#if defined(OS_WIN)
#define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt" U_ICU_VERSION_SHORT ".dll"
#endif
+#endif
namespace icu_util {
@@ -78,6 +86,7 @@ bool Initialize() {
// Mac/Linux bundle the ICU data in.
return true;
#elif (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
+#if !defined(OS_MACOSX)
// For now, expect the data file to be alongside the executable.
// This is sufficient while we work on unit tests, but will eventually
// likely live in a data directory.
@@ -90,6 +99,32 @@ bool Initialize() {
UErrorCode err = U_ZERO_ERROR;
udata_setFileAccess(UDATA_ONLY_PACKAGES, &err);
return err == U_ZERO_ERROR;
+#else
+ // If the ICU data directory is set, ICU won't actually load the data until
+ // it is needed. This can fail if the process is sandboxed at that time.
+ // Instead, Mac maps the file in and hands off the data so the sandbox won't
+ // cause any problems.
+
+ // Chrome doesn't normally shut down ICU, so the mapped data shouldn't ever
+ // be released.
+ static file_util::MemoryMappedFile mapped_file;
+ if (!mapped_file.IsValid()) {
+ // Assume it is in the MainBundle's Resources directory.
+ FilePath data_path =
+ base::mac::PathForMainAppBundleResource(CFSTR(ICU_UTIL_DATA_FILE_NAME));
+ if (data_path.empty()) {
+ LOG(ERROR) << ICU_UTIL_DATA_FILE_NAME << " not found in bundle";
+ return false;
+ }
+ if (!mapped_file.Initialize(data_path)) {
+ LOG(ERROR) << "Couldn't mmap " << data_path.value();
+ return false;
+ }
+ }
+ UErrorCode err = U_ZERO_ERROR;
+ udata_setCommonData(const_cast<uint8*>(mapped_file.data()), &err);
+ return err == U_ZERO_ERROR;
+#endif // OS check
#endif
}
diff --git a/base/mac/foundation_util.h b/base/mac/foundation_util.h
index a94cf95..a7c525a 100644
--- a/base/mac/foundation_util.h
+++ b/base/mac/foundation_util.h
@@ -45,6 +45,9 @@ bool IsBackgroundOnlyProcess();
NSBundle* MainAppBundle();
FilePath MainAppBundlePath();
+// Returns the path to a resource within the MainAppBundle.
+FilePath PathForMainAppBundleResource(CFStringRef resourceName);
+
// Set the bundle that MainAppBundle will return, overriding the default value
// (Restore the default by calling SetOverrideAppBundle(nil)).
void SetOverrideAppBundle(NSBundle* bundle);
diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm
index ad8a247..151d82f 100644
--- a/base/mac/foundation_util.mm
+++ b/base/mac/foundation_util.mm
@@ -80,6 +80,15 @@ FilePath MainAppBundlePath() {
return FilePath([[bundle bundlePath] fileSystemRepresentation]);
}
+FilePath PathForMainAppBundleResource(CFStringRef resourceName) {
+ NSBundle* bundle = MainAppBundle();
+ NSString* resourcePath = [bundle pathForResource:(NSString*)resourceName
+ ofType:nil];
+ if (!resourcePath)
+ return FilePath();
+ return FilePath([resourcePath fileSystemRepresentation]);
+}
+
void SetOverrideAppBundle(NSBundle* bundle) {
if (bundle != g_override_app_bundle) {
[g_override_app_bundle release];