diff options
author | hayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-03 05:25:11 +0000 |
---|---|---|
committer | hayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-03 05:25:11 +0000 |
commit | 32caba271be320eaba3ef4cee0a5806de0b2cbca (patch) | |
tree | 0ecbe2fdd97e243a20fe009144e3ee1746744a91 /app/resource_bundle_mac.mm | |
parent | 717fcd89505d0e318b052c24a60fb1b64a6de480 (diff) | |
download | chromium_src-32caba271be320eaba3ef4cee0a5806de0b2cbca.zip chromium_src-32caba271be320eaba3ef4cee0a5806de0b2cbca.tar.gz chromium_src-32caba271be320eaba3ef4cee0a5806de0b2cbca.tar.bz2 |
Share code between Mac and Linux in ResourceBundle.
BUG=25891
TEST=None
Review URL: http://codereview.chromium.org/442002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33668 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/resource_bundle_mac.mm')
-rw-r--r-- | app/resource_bundle_mac.mm | 93 |
1 files changed, 11 insertions, 82 deletions
diff --git a/app/resource_bundle_mac.mm b/app/resource_bundle_mac.mm index 547c84b..94ef31a 100644 --- a/app/resource_bundle_mac.mm +++ b/app/resource_bundle_mac.mm @@ -6,104 +6,33 @@ #import <Foundation/Foundation.h> -#include "app/gfx/font.h" -#include "app/l10n_util.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/mac_util.h" -#include "base/path_service.h" -#include "base/string_piece.h" -#include "base/string_util.h" #include "skia/ext/skia_utils_mac.h" -ResourceBundle::~ResourceBundle() { - FreeImages(); - - delete locale_resources_data_; - locale_resources_data_ = NULL; - delete resources_data_; - resources_data_ = NULL; -} - namespace { -base::DataPack *LoadResourceDataPack(NSString *name) { - base::DataPack *resource_pack = NULL; - +FilePath GetResourcesPakFilePath(NSString* name) { NSString *resource_path = [mac_util::MainAppBundle() 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); - if (!success) { - delete resource_pack; - resource_pack = NULL; - } - } - - return resource_pack; + if (!resource_path) + return FilePath(); + return FilePath([resource_path fileSystemRepresentation]); } } // namespace -void ResourceBundle::LoadResources(const std::wstring& pref_locale) { - DLOG_IF(WARNING, pref_locale.size() != 0) - << "ignoring requested locale in favor 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"; -} - // static -RefCountedStaticMemory* ResourceBundle::LoadResourceBytes( - DataHandle module, int resource_id) { - DCHECK(module); - return module->GetStaticMemory(resource_id); -} - -base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) { - DCHECK(resources_data_); - base::StringPiece data; - if (!resources_data_->GetStringPiece(resource_id, &data)) { - if (!locale_resources_data_->GetStringPiece(resource_id, &data)) { - return base::StringPiece(); - } - } - return data; +FilePath ResourceBundle::GetResourcesFilePath() { + return GetResourcesPakFilePath(@"chrome"); } -string16 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 string16(); - } - - base::StringPiece data; - if (!locale_resources_data_->GetStringPiece(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 string16(); - } - } - - // Data pack encodes strings as UTF16. - string16 msg(reinterpret_cast<const char16*>(data.data()), - data.length() / 2); - return msg; +// static +FilePath ResourceBundle::GetLocaleFilePath(const std::wstring& pref_locale) { + DLOG_IF(WARNING, !pref_locale.empty()) + << "ignoring requested locale in favor of NSBundle's selection"; + return GetResourcesPakFilePath(@"locale"); } NSImage* ResourceBundle::GetNSImageNamed(int resource_id) { |