diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/chrome_dll_main.cc | 6 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 2 | ||||
-rw-r--r-- | chrome/chrome.xcodeproj/project.pbxproj | 36 | ||||
-rw-r--r-- | chrome/common/l10n_util.cc | 15 | ||||
-rw-r--r-- | chrome/common/resource_bundle.h | 11 | ||||
-rw-r--r-- | chrome/common/resource_bundle_mac.mm | 119 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.cc | 38 | ||||
-rwxr-xr-x | chrome/tools/mac_copy_grit_resources.sh | 37 | ||||
-rwxr-xr-x | chrome/tools/mac_repack_grit_resources.sh | 34 |
9 files changed, 232 insertions, 66 deletions
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc index 3a94bb5..daf5244 100644 --- a/chrome/app/chrome_dll_main.cc +++ b/chrome/app/chrome_dll_main.cc @@ -169,13 +169,10 @@ void EnableHeapProfiler(const CommandLine& parsed_command_line) { } void CommonSubprocessInit() { -#if defined(OS_WIN) || defined(OS_LINUX) // Initialize ResourceBundle which handles files loaded from external // sources. The language should have been passed in to us from the // browser process as a command line flag. - // TODO(port-mac): enable when we figure out resource bundle issues ResourceBundle::InitSharedInstance(std::wstring()); -#endif #if defined(OS_WIN) // HACK: Let Windows know that we have started. This is needed to suppress @@ -330,10 +327,7 @@ int ChromeMain(int argc, const char** argv) { } if (!process_type.empty()) { -#if defined(OS_WIN) || defined(OS_LINUX) - // TODO(port-mac): enable when we figure out resource bundle issues ResourceBundle::CleanupSharedInstance(); -#endif } #if defined(OS_WIN) diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 88c5978..0693cd1 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -306,7 +306,6 @@ int BrowserMain(const MainFunctionParams& parameters) { parent_local_state.GetString(prefs::kApplicationLocale)); } -#if defined(OS_WIN) || defined(OS_LINUX) // If we're running tests (ui_task is non-null), then the ResourceBundle // has already been initialized. if (!parameters.ui_task) { @@ -315,7 +314,6 @@ int BrowserMain(const MainFunctionParams& parameters) { // We only load the theme dll in the browser process. ResourceBundle::GetSharedInstance().LoadThemeResources(); } -#endif // defined(OS_WIN) || defined(OS_LINUX) if (!parsed_command_line.HasSwitch(switches::kNoErrorDialogs)) { // Display a warning if the user is running windows 2000. diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj index 9550646..15414bb 100644 --- a/chrome/chrome.xcodeproj/project.pbxproj +++ b/chrome/chrome.xcodeproj/project.pbxproj @@ -673,6 +673,8 @@ EEA5B4CB2EB282403BDE41D7 /* tab_contents.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6CCB9E40F1EC32700106F0D /* tab_contents.cc */; }; F081CEE97F8C75FEAF3D0FD2 /* jstemplate_builder.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BFBC70E9D4C9F009A6919 /* jstemplate_builder.cc */; }; F4143C8C0F4B1D43008C8F73 /* renderer.sb in Resources */ = {isa = PBXBuildFile; fileRef = F4143C8B0F4B1D07008C8F73 /* renderer.sb */; }; + F41444200F55A81C008C8F73 /* resource_bundle.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BFBF40E9D4C9F009A6919 /* resource_bundle.cc */; }; + F414442D0F55AABD008C8F73 /* resource_bundle_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = F41444270F55AA97008C8F73 /* resource_bundle_mac.mm */; }; F47CA1280F44AE0E00FFFAFB /* libnet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D7B004E0E9D5464009A6919 /* libnet.a */; }; F47CA1290F44AE2800FFFAFB /* libglue.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 826850180F2FC82E009F6555 /* libglue.a */; }; F47CA12A0F44AE3500FFFAFB /* libwtf.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 826850240F2FC82E009F6555 /* libwtf.a */; }; @@ -2945,6 +2947,7 @@ EA72CF50C0AB4492A644C703 /* url_fetcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = url_fetcher.h; sourceTree = "<group>"; }; F174BA4A5FF6B3DFC64105AD /* transport_dib_mac.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = transport_dib_mac.cc; sourceTree = "<group>"; }; F4143C8B0F4B1D07008C8F73 /* renderer.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = renderer.sb; sourceTree = "<group>"; }; + F41444270F55AA97008C8F73 /* resource_bundle_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = resource_bundle_mac.mm; sourceTree = "<group>"; }; F60D7722C1302E1EC789B67A /* ssl_host_state.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ssl_host_state.cc; path = ssl/ssl_host_state.cc; sourceTree = "<group>"; }; /* End PBXFileReference section */ @@ -3973,6 +3976,7 @@ 4D7BFBF30E9D4C9F009A6919 /* render_messages_internal.h */, 4D7BFBF40E9D4C9F009A6919 /* resource_bundle.cc */, 4D7BFBF50E9D4C9F009A6919 /* resource_bundle.h */, + F41444270F55AA97008C8F73 /* resource_bundle_mac.mm */, 4D7BFBF60E9D4C9F009A6919 /* resource_dispatcher.cc */, 4D7BFBF70E9D4C9F009A6919 /* resource_dispatcher.h */, 4D7BFBF80E9D4C9F009A6919 /* resource_dispatcher_unittest.cc */, @@ -4961,6 +4965,8 @@ buildConfigurationList = E45060E90EE87B86003BE099 /* Build configuration list for PBXNativeTarget "app" */; buildPhases = ( E45060E00EE87B86003BE099 /* Resources */, + F414470B0F562CC8008C8F73 /* Repack GRIT Resources */, + F41447180F56345B008C8F73 /* Copy GRIT Resources */, E45060E10EE87B86003BE099 /* Sources */, E45060E20EE87B86003BE099 /* Frameworks */, 4DCEA14B0EF0BC0E00682526 /* Strip If Needed */, @@ -5603,6 +5609,34 @@ shellScript = "set -ex\nRUNNABLE_PRODUCT=$(echo \"${PRODUCT_NAME}\" | sed -e s/^run_//)\nexec \"${BUILT_PRODUCTS_DIR}/${RUNNABLE_PRODUCT}\"\n"; showEnvVarsInLog = 0; }; + F414470B0F562CC8008C8F73 /* Repack GRIT Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Repack GRIT Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "set -ex\nexec \"${PROJECT_FILE_PATH}/../tools/mac_repack_grit_resources.sh\" \"${@}\""; + }; + F41447180F56345B008C8F73 /* Copy GRIT Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Copy GRIT Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "set -ex\nexec \"${PROJECT_FILE_PATH}/../tools/mac_copy_grit_resources.sh\" \"${@}\""; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -5980,6 +6014,8 @@ E45076850F1530CD003BE099 /* pref_service.cc in Sources */, B562E2F80F05843C00FB1A4F /* property_bag.cc in Sources */, E45076A90F153619003BE099 /* resource_dispatcher.cc in Sources */, + F41444200F55A81C008C8F73 /* resource_bundle.cc in Sources */, + F414442D0F55AABD008C8F73 /* resource_bundle_mac.mm in Sources */, E43A78750F17A95400ABD5D1 /* sandbox_init_wrapper.cc in Sources */, E40CC5FE0F2E35A800708647 /* security_filter_peer.cc in Sources */, 4D7BFC7F0E9D4D2E009A6919 /* slide_animation.cc in Sources */, diff --git a/chrome/common/l10n_util.cc b/chrome/common/l10n_util.cc index 9fcee980..ac2e257 100644 --- a/chrome/common/l10n_util.cc +++ b/chrome/common/l10n_util.cc @@ -18,10 +18,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/gfx/chrome_canvas.h" -#if defined(OS_WIN) || defined(OS_LINUX) -// TODO(port): re-enable. #include "chrome/common/resource_bundle.h" -#endif #if defined(OS_WIN) #include "chrome/views/view.h" #endif // defined(OS_WIN) @@ -285,14 +282,8 @@ std::wstring GetLocalName(const std::wstring& locale_code_wstr, } std::wstring GetString(int message_id) { -#if defined(OS_WIN) || defined(OS_LINUX) ResourceBundle &rb = ResourceBundle::GetSharedInstance(); return rb.GetLocalizedString(message_id); -#else - NOTIMPLEMENTED(); // TODO(port): Real implementation of GetString. - // Return something non-empty so callers don't freak out. - return L"true"; -#endif } static std::wstring GetStringF(int message_id, @@ -301,16 +292,10 @@ static std::wstring GetStringF(int message_id, const std::wstring& c, const std::wstring& d, std::vector<size_t>* offsets) { -#if defined(OS_WIN) || defined(OS_LINUX) -// TODO(port): re-enable. const std::wstring& format_string = GetString(message_id); std::wstring formatted = ReplaceStringPlaceholders(format_string, a, b, c, d, offsets); return formatted; -#else - NOTIMPLEMENTED(); - return L"GetStringF NOTIMPLEMENTED"; -#endif // defined(OS_WIN) } std::wstring GetStringF(int message_id, diff --git a/chrome/common/resource_bundle.h b/chrome/common/resource_bundle.h index 983f34b..ac62d9b 100644 --- a/chrome/common/resource_bundle.h +++ b/chrome/common/resource_bundle.h @@ -19,10 +19,12 @@ #include "base/lock.h" #include "base/scoped_ptr.h" -#if defined(OS_LINUX) +#if defined(OS_LINUX) || defined(OS_MACOSX) namespace base { class DataPack; }; +#endif +#if defined(OS_LINUX) typedef struct _GdkPixbuf GdkPixbuf; #endif class ChromeFont; @@ -48,6 +50,8 @@ class ResourceBundle { }; // Initialize the ResourceBundle for this process. + // NOTE: Mac ignores this and always loads up resources for the language + // defined by the Cocoa UI (ie-NSBundle does the langange work). static void InitSharedInstance(const std::wstring& pref_locale); // Delete the ResourceBundle for this process if it exists. @@ -120,12 +124,9 @@ class ResourceBundle { #if defined(OS_WIN) // Windows stores resources in DLLs, which are managed by HINSTANCE. typedef HINSTANCE DataHandle; -#elif defined(OS_LINUX) +#elif defined(OS_LINUX) || defined(OS_MACOSX) // Linux uses base::DataPack. typedef base::DataPack* DataHandle; -#elif defined(OS_MACOSX) - // TODO(port): Implement resource loading on OS X. - typedef void* DataHandle; #endif // Ctor/dtor are private, since we're a singleton. diff --git a/chrome/common/resource_bundle_mac.mm b/chrome/common/resource_bundle_mac.mm new file mode 100644 index 0000000..a1d152f --- /dev/null +++ b/chrome/common/resource_bundle_mac.mm @@ -0,0 +1,119 @@ +// Copyright (c) 2006-2008 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/common/resource_bundle.h" + +#include <Cocoa/Cocoa.h> + +#include "base/base_paths.h" +#include "base/data_pack.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "base/path_service.h" +#include "base/string_piece.h" +#include "base/string_util.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/gfx/chrome_font.h" +#include "chrome/common/l10n_util.h" + +ResourceBundle::~ResourceBundle() { + FreeImages(); + + delete locale_resources_data_; + locale_resources_data_ = NULL; + delete theme_data_; + theme_data_ = NULL; + delete resources_data_; + resources_data_ = NULL; +} + +namespace { + +base::DataPack *LoadResourceDataPack(NSString *name) { + base::DataPack *resource_pack = NULL; + + NSString *resource_path = [[NSBundle mainBundle] pathForResource:name + ofType:@"pak"]; + if (resource_path) { + FilePath resources_pak_path([resource_path fileSystemRepresentation]); + resource_pack = new base::DataPack; + bool success = resource_pack->Load(resources_pak_path); + DCHECK(success) << "failed to load chrome.pak"; + if (!success) { + delete resource_pack; + resource_pack = NULL; + } + } + + return resource_pack; +} + +} // namespace + +void ResourceBundle::LoadResources(const std::wstring& pref_locale) { + DCHECK(pref_locale.size() == 0) + << "ignoring requested locale in favore of NSBundle's selection"; + + DCHECK(resources_data_ == NULL) << "resource data already loaded!"; + resources_data_ = LoadResourceDataPack(@"chrome"); + DCHECK(resources_data_) << "failed to load chrome.pak"; + + DCHECK(locale_resources_data_ == NULL) << "locale data already loaded!"; + locale_resources_data_ = LoadResourceDataPack(@"locale"); + DCHECK(locale_resources_data_) << "failed to load locale.pak"; +} + +void ResourceBundle::LoadThemeResources() { + DCHECK(theme_data_ == NULL) << "theme data already loaded!"; + theme_data_ = LoadResourceDataPack(@"theme"); + DCHECK(theme_data_) << "failed to load theme.pak"; +} + +/* static */ +bool ResourceBundle::LoadResourceBytes(DataHandle module, int resource_id, + std::vector<unsigned char>* bytes) { + DCHECK(module); + StringPiece data; + if (!module->Get(resource_id, &data)) + return false; + + bytes->resize(data.length()); + memcpy(&(bytes->front()), data.data(), data.length()); + + return true; +} + +StringPiece ResourceBundle::GetRawDataResource(int resource_id) { + DCHECK(resources_data_); + StringPiece data; + if (!resources_data_->Get(resource_id, &data)) + return StringPiece(); + return data; +} + +std::wstring ResourceBundle::GetLocalizedString(int message_id) { + // If for some reason we were unable to load a resource dll, return an empty + // string (better than crashing). + if (!locale_resources_data_) { + LOG(WARNING) << "locale resources are not loaded"; + return std::wstring(); + } + + StringPiece data; + if (!locale_resources_data_->Get(message_id, &data)) { + // Fall back on the main data pack (shouldn't be any strings here except in + // unittests). + data = GetRawDataResource(message_id); + if (data.empty()) { + NOTREACHED() << "unable to find resource: " << message_id; + return std::wstring(); + } + } + + // Data pack encodes strings as UTF16. + string16 msg(reinterpret_cast<const char16*>(data.data()), + data.length() / 2); + return UTF16ToWide(msg); +} diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc index 47789bb..d2e293d 100644 --- a/chrome/common/temp_scaffolding_stubs.cc +++ b/chrome/common/temp_scaffolding_stubs.cc @@ -41,7 +41,6 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_service.h" #include "chrome/common/process_watcher.h" -#include "chrome/common/resource_bundle.h" #include "net/url_request/url_request_context.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webkit_glue.h" @@ -266,43 +265,6 @@ void RunBeforeUnloadDialog(WebContents* web_contents, void RunRepostFormWarningDialog(NavigationController*) { } -#if defined(OS_MACOSX) -ResourceBundle* ResourceBundle::g_shared_instance_ = NULL; - -// GetBitmapNamed() will leak, but there's no way around it for stubs. -SkBitmap* ResourceBundle::GetBitmapNamed(int) { - NOTIMPLEMENTED(); - return new SkBitmap(); -} -ResourceBundle::ResourceBundle() { } -ResourceBundle& ResourceBundle::GetSharedInstance() { - NOTIMPLEMENTED(); - if (!g_shared_instance_) - g_shared_instance_ = new ResourceBundle; - return *g_shared_instance_; -} - -StringPiece ResourceBundle::GetRawDataResource(int resource_id) { - NOTIMPLEMENTED(); - return StringPiece(); -} - -std::string ResourceBundle::GetDataResource(int resource_id) { - NOTIMPLEMENTED(); - return ""; -} - -void ResourceBundle::CleanupSharedInstance() { - NOTIMPLEMENTED(); -} - -bool ResourceBundle::LoadImageResourceBytes(int resource_id, - std::vector<unsigned char>* bytes) { - NOTIMPLEMENTED(); - return false; -} -#endif - LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, URLRequest* request, MessageLoop* ui_loop) { diff --git a/chrome/tools/mac_copy_grit_resources.sh b/chrome/tools/mac_copy_grit_resources.sh new file mode 100755 index 0000000..936e221 --- /dev/null +++ b/chrome/tools/mac_copy_grit_resources.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +# Copyright (c) 2009 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. + +set -ex +GENERATED_DIR="${CONFIGURATION_TEMP_DIR}/generated" +REPACKED_DIR="${GENERATED_DIR}/grit_repacked" +APP_RESOURCES_ROOT_DIR="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +mkdir -p "${APP_RESOURCES_ROOT_DIR}" + + +if [ "${APP_RESOURCES_ROOT_DIR}/chrome.pak" -ot \ + "${REPACKED_DIR}/chrome.pak" ] +then + cp -f "${REPACKED_DIR}/chrome.pak" \ + "${APP_RESOURCES_ROOT_DIR}/chrome.pak" +fi + +if [ "${APP_RESOURCES_ROOT_DIR}/theme.pak" -ot \ + "${REPACKED_DIR}/theme.pak" ] +then + cp -f "${REPACKED_DIR}/theme.pak" \ + "${APP_RESOURCES_ROOT_DIR}/theme.pak" +fi + +# TODO: this should loop though all the languages and copy them to the +# right folder (note the name change) + +if [ "${APP_RESOURCES_ROOT_DIR}/locale.pak" -ot \ + "${REPACKED_DIR}/locale_en-US.pak" ] +then + mkdir -p "${APP_RESOURCES_ROOT_DIR}/English.lproj" + cp -f "${REPACKED_DIR}/locale_en-US.pak" \ + "${APP_RESOURCES_ROOT_DIR}/English.lproj/locale.pak" +fi diff --git a/chrome/tools/mac_repack_grit_resources.sh b/chrome/tools/mac_repack_grit_resources.sh new file mode 100755 index 0000000..1fc3596 --- /dev/null +++ b/chrome/tools/mac_repack_grit_resources.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# Copyright (c) 2009 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. + +set -ex +GENERATED_DIR="${CONFIGURATION_TEMP_DIR}/generated" +GRIT_DIR="${GENERATED_DIR}/grit" +REPACKED_DIR="${GENERATED_DIR}/grit_repacked" +mkdir -p "${REPACKED_DIR}" + +# TODO: these need dependency checks + +python "${PROJECT_DIR}/../tools/data_pack/repack.py" \ + "${REPACKED_DIR}/chrome.pak" \ + "${GRIT_DIR}/browser_resources.pak" \ + "${GRIT_DIR}/debugger_resources.pak" \ + "${GRIT_DIR}/common_resources.pak" \ + "${GRIT_DIR}/renderer_resources.pak" + +# Need two to repack, but linux avoids that by directly invoking the module, so +# we just cp instead. +cp -f "${GRIT_DIR}/theme_resources.pak" "${REPACKED_DIR}/theme.pak" + + +# TODO: we when these are built for each language, we need to loop over +# the languages and do the repack on all of them. + +python "${PROJECT_DIR}/../tools/data_pack/repack.py" \ + "${REPACKED_DIR}/locale_en-US.pak" \ + "${GRIT_DIR}/generated_resources_en-US.pak" \ + "${GRIT_DIR}/chromium_strings_en-US.pak" \ + "${GRIT_DIR}/locale_settings_en-US.pak" |