| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "app/resource_bundle.h" | 5 #include "app/resource_bundle.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 | 8 |
| 9 #include "app/app_paths.h" | 9 #include "app/app_paths.h" |
| 10 #include "app/gfx/font.h" | 10 #include "app/gfx/font.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 } // end anonymous namespace | 30 } // end anonymous namespace |
| 31 | 31 |
| 32 ResourceBundle::~ResourceBundle() { | 32 ResourceBundle::~ResourceBundle() { |
| 33 FreeImages(); | 33 FreeImages(); |
| 34 | 34 |
| 35 if (locale_resources_data_) { | 35 if (locale_resources_data_) { |
| 36 BOOL rv = FreeLibrary(locale_resources_data_); | 36 BOOL rv = FreeLibrary(locale_resources_data_); |
| 37 DCHECK(rv); | 37 DCHECK(rv); |
| 38 } | 38 } |
| 39 if (theme_data_) { | |
| 40 BOOL rv = FreeLibrary(theme_data_); | |
| 41 DCHECK(rv); | |
| 42 } | |
| 43 } | 39 } |
| 44 | 40 |
| 45 void ResourceBundle::LoadResources(const std::wstring& pref_locale) { | 41 void ResourceBundle::LoadResources(const std::wstring& pref_locale) { |
| 46 // As a convenience, set resources_data_ to the current module. | 42 // As a convenience, set resources_data_ to the current module. |
| 47 resources_data_ = _AtlBaseModule.GetModuleInstance(); | 43 resources_data_ = _AtlBaseModule.GetModuleInstance(); |
| 48 | 44 |
| 49 DCHECK(NULL == locale_resources_data_) << "locale dll already loaded"; | 45 DCHECK(NULL == locale_resources_data_) << "locale dll already loaded"; |
| 50 const FilePath& locale_path = GetLocaleFilePath(pref_locale); | 46 const FilePath& locale_path = GetLocaleFilePath(pref_locale); |
| 51 if (locale_path.value().empty()) { | 47 if (locale_path.value().empty()) { |
| 52 // It's possible that there are no locale dlls found, in which case we just | 48 // It's possible that there are no locale dlls found, in which case we just |
| (...skipping 13 matching lines...) Expand all Loading... |
| 66 FilePath locale_path; | 62 FilePath locale_path; |
| 67 PathService::Get(app::DIR_LOCALES, &locale_path); | 63 PathService::Get(app::DIR_LOCALES, &locale_path); |
| 68 | 64 |
| 69 const std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); | 65 const std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); |
| 70 if (app_locale.empty()) | 66 if (app_locale.empty()) |
| 71 return FilePath(); | 67 return FilePath(); |
| 72 | 68 |
| 73 return locale_path.AppendASCII(app_locale + ".dll"); | 69 return locale_path.AppendASCII(app_locale + ".dll"); |
| 74 } | 70 } |
| 75 | 71 |
| 76 void ResourceBundle::LoadThemeResources() { | |
| 77 DCHECK(NULL == theme_data_) << "theme dll already loaded"; | |
| 78 FilePath theme_data_path; | |
| 79 PathService::Get(app::DIR_THEMES, &theme_data_path); | |
| 80 theme_data_path = theme_data_path.AppendASCII("default.dll"); | |
| 81 | |
| 82 // The dll should only have resources, not executable code. | |
| 83 theme_data_ = LoadLibraryEx(theme_data_path.value().c_str(), NULL, | |
| 84 GetDataDllLoadFlags()); | |
| 85 DCHECK(theme_data_ != NULL) << "unable to load " << theme_data_path.value(); | |
| 86 } | |
| 87 | |
| 88 // static | 72 // static |
| 89 RefCountedStaticMemory* ResourceBundle::LoadResourceBytes( | 73 RefCountedStaticMemory* ResourceBundle::LoadResourceBytes( |
| 90 DataHandle module, int resource_id) { | 74 DataHandle module, int resource_id) { |
| 91 void* data_ptr; | 75 void* data_ptr; |
| 92 size_t data_size; | 76 size_t data_size; |
| 93 if (base::GetDataResourceFromModule(module, resource_id, &data_ptr, | 77 if (base::GetDataResourceFromModule(module, resource_id, &data_ptr, |
| 94 &data_size)) { | 78 &data_size)) { |
| 95 return new RefCountedStaticMemory( | 79 return new RefCountedStaticMemory( |
| 96 reinterpret_cast<const unsigned char*>(data_ptr), data_size); | 80 reinterpret_cast<const unsigned char*>(data_ptr), data_size); |
| 97 } else { | 81 } else { |
| 98 return NULL; | 82 return NULL; |
| 99 } | 83 } |
| 100 } | 84 } |
| 101 | 85 |
| 102 HICON ResourceBundle::LoadThemeIcon(int icon_id) { | 86 HICON ResourceBundle::LoadThemeIcon(int icon_id) { |
| 103 return ::LoadIcon(theme_data_, MAKEINTRESOURCE(icon_id)); | 87 return ::LoadIcon(resources_data_, MAKEINTRESOURCE(icon_id)); |
| 104 } | 88 } |
| 105 | 89 |
| 106 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) { | 90 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) { |
| 107 void* data_ptr; | 91 void* data_ptr; |
| 108 size_t data_size; | 92 size_t data_size; |
| 109 if (base::GetDataResourceFromModule(_AtlBaseModule.GetModuleInstance(), | 93 if (base::GetDataResourceFromModule(_AtlBaseModule.GetModuleInstance(), |
| 110 resource_id, | 94 resource_id, |
| 111 &data_ptr, | 95 &data_ptr, |
| 112 &data_size)) { | 96 &data_size)) { |
| 113 return base::StringPiece(static_cast<const char*>(data_ptr), data_size); | 97 return base::StringPiece(static_cast<const char*>(data_ptr), data_size); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 message_id); | 133 message_id); |
| 150 if (!image) { | 134 if (!image) { |
| 151 StackTrace().PrintBacktrace(); // See http://crbug.com/21925. | 135 StackTrace().PrintBacktrace(); // See http://crbug.com/21925. |
| 152 NOTREACHED() << "unable to find resource: " << message_id; | 136 NOTREACHED() << "unable to find resource: " << message_id; |
| 153 return std::wstring(); | 137 return std::wstring(); |
| 154 } | 138 } |
| 155 } | 139 } |
| 156 // Copy into a string16 and return. | 140 // Copy into a string16 and return. |
| 157 return string16(image->achString, image->nLength); | 141 return string16(image->achString, image->nLength); |
| 158 } | 142 } |
| OLD | NEW |