Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: ui/base/resource/resource_bundle_mac.mm

Issue 10270023: Add new ResourceBundle::Delegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/resource/resource_bundle_mac.mm
===================================================================
--- ui/base/resource/resource_bundle_mac.mm (revision 133962)
+++ ui/base/resource/resource_bundle_mac.mm (working copy)
@@ -44,17 +44,22 @@
} // namespace
void ResourceBundle::LoadCommonResources() {
- AddDataPack(GetResourcesPakFilePath(@"chrome", nil));
- AddDataPack(GetResourcesPakFilePath(@"theme_resources_standard", nil));
- AddDataPack(GetResourcesPakFilePath(@"ui_resources_standard", nil));
+ AddCommonDataPack("chrome", GetResourcesPakFilePath(@"chrome", nil));
+ AddCommonDataPack("theme_resources_standard",
+ GetResourcesPakFilePath(@"theme_resources_standard", nil));
+ AddCommonDataPack("ui_resources_standard",
+ GetResourcesPakFilePath(@"ui_resources_standard", nil));
// On Windows and ChromeOS we load either the 1x resource or the 2x resource.
// On Mac we load both and let the UI framework decide which one to use.
#if defined(ENABLE_HIDPI)
if (base::mac::IsOSLionOrLater()) {
- AddDataPack(GetResourcesPakFilePath(@"theme_resources_2x", nil));
- AddDataPack(GetResourcesPakFilePath(@"theme_resources_standard_2x", nil));
- AddDataPack(GetResourcesPakFilePath(@"ui_resources_standard_2x", nil));
+ AddCommonDataPack("theme_resources_2x",
+ GetResourcesPakFilePath(@"theme_resources_2x", nil));
+ AddCommonDataPack("theme_resources_standard_2x",
+ GetResourcesPakFilePath(@"theme_resources_standard_2x", nil));
+ AddCommonDataPack("ui_resources_standard_2x",
+ GetResourcesPakFilePath(@"ui_resources_standard_2x", nil));
}
#endif
}
@@ -71,7 +76,14 @@
if ([mac_locale isEqual:@"en_US"])
mac_locale = @"en";
- return GetResourcesPakFilePath(@"locale", mac_locale);
+ FilePath locale_file_path = GetResourcesPakFilePath(@"locale", mac_locale);
+
+ if (delegate_ &&
+ !delegate_->GetPathForLocalePack(app_locale, &locale_file_path)) {
+ return FilePath();
+ }
+
+ return locale_file_path;
}
gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
@@ -93,39 +105,47 @@
}
}
- scoped_nsobject<NSImage> ns_image;
- for (size_t i = 0; i < data_packs_.size(); ++i) {
- scoped_refptr<base::RefCountedStaticMemory> data(
- data_packs_[i]->GetStaticMemory(resource_id));
- if (!data.get())
- continue;
+ gfx::Image* image = NULL;
+ if (delegate_)
+ image = delegate_->GetNativeImageNamed(resource_id, rtl);
- scoped_nsobject<NSData> ns_data(
- [[NSData alloc] initWithBytes:data->front()
- length:data->size()]);
+ if (!image) {
+ scoped_nsobject<NSImage> ns_image;
+ for (size_t i = 0; i < data_packs_.size(); ++i) {
+ scoped_refptr<base::RefCountedStaticMemory> data(
+ data_packs_[i]->GetStaticMemory(resource_id));
+ if (!data.get())
+ continue;
+
+ scoped_nsobject<NSData> ns_data(
+ [[NSData alloc] initWithBytes:data->front()
+ length:data->size()]);
+ if (!ns_image.get()) {
+ ns_image.reset([[NSImage alloc] initWithData:ns_data]);
+ } else {
+ NSImageRep* image_rep = [NSBitmapImageRep imageRepWithData:ns_data];
+ if (image_rep)
+ [ns_image addRepresentation:image_rep];
+ }
+ }
+
if (!ns_image.get()) {
- ns_image.reset([[NSImage alloc] initWithData:ns_data]);
- } else {
- NSImageRep* image_rep = [NSBitmapImageRep imageRepWithData:ns_data];
- if (image_rep)
- [ns_image addRepresentation:image_rep];
+ LOG(WARNING) << "Unable to load image with id " << resource_id;
+ NOTREACHED(); // Want to assert in debug mode.
+ return *GetEmptyImage();
}
- }
- if (!ns_image.get()) {
- LOG(WARNING) << "Unable to load image with id " << resource_id;
- NOTREACHED(); // Want to assert in debug mode.
- return *GetEmptyImage();
+ image = new gfx::Image(ns_image.release());
}
base::AutoLock lock(*images_and_fonts_lock_);
// Another thread raced the load and has already cached the image.
if (images_.count(resource_id)) {
+ delete image;
sail 2012/04/30 21:14:43 same, should avoid this if possible
Marshall 2012/04/30 21:50:10 Done.
return *images_[resource_id];
}
- gfx::Image* image = new gfx::Image(ns_image.release());
images_[resource_id] = image;
return *image;
}

Powered by Google App Engine
This is Rietveld 408576698