| OLD | NEW | 
|    1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2011 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 "ui/base/resource/resource_bundle.h" |    5 #include "ui/base/resource/resource_bundle.h" | 
|    6  |    6  | 
|    7 #import <AppKit/AppKit.h> |    7 #import <AppKit/AppKit.h> | 
|    8  |    8  | 
|    9 #include "base/basictypes.h" |    9 #include "base/basictypes.h" | 
|   10 #include "base/file_path.h" |   10 #include "base/file_path.h" | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
|   39 } |   39 } | 
|   40  |   40  | 
|   41 }  // namespace |   41 }  // namespace | 
|   42  |   42  | 
|   43 // static |   43 // static | 
|   44 FilePath ResourceBundle::GetResourcesFilePath() { |   44 FilePath ResourceBundle::GetResourcesFilePath() { | 
|   45   return GetResourcesPakFilePath(@"chrome", nil); |   45   return GetResourcesPakFilePath(@"chrome", nil); | 
|   46 } |   46 } | 
|   47  |   47  | 
|   48 // static |   48 // static | 
 |   49 FilePath ResourceBundle::GetLargeIconResourcesFilePath() { | 
 |   50   return GetResourcesPakFilePath(@"theme_resources_large", nil); | 
 |   51 } | 
 |   52  | 
 |   53 // static | 
|   49 FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) { |   54 FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) { | 
|   50   NSString* mac_locale = base::SysUTF8ToNSString(app_locale); |   55   NSString* mac_locale = base::SysUTF8ToNSString(app_locale); | 
|   51  |   56  | 
|   52   // Mac OS X uses "_" instead of "-", so swap to get a Mac-style value. |   57   // Mac OS X uses "_" instead of "-", so swap to get a Mac-style value. | 
|   53   mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" |   58   mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" | 
|   54                                                      withString:@"_"]; |   59                                                      withString:@"_"]; | 
|   55  |   60  | 
|   56   // On disk, the "en_US" resources are just "en" (http://crbug.com/25578). |   61   // On disk, the "en_US" resources are just "en" (http://crbug.com/25578). | 
|   57   if ([mac_locale isEqual:@"en_US"]) |   62   if ([mac_locale isEqual:@"en_US"]) | 
|   58     mac_locale = @"en"; |   63     mac_locale = @"en"; | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|   82  |   87  | 
|   83   // Create a data object from the raw bytes. |   88   // Create a data object from the raw bytes. | 
|   84   scoped_nsobject<NSData> ns_data([[NSData alloc] initWithBytes:data->front() |   89   scoped_nsobject<NSData> ns_data([[NSData alloc] initWithBytes:data->front() | 
|   85                                                          length:data->size()]); |   90                                                          length:data->size()]); | 
|   86  |   91  | 
|   87   // Create the image from the data. The gfx::Image will take ownership of this. |   92   // Create the image from the data. The gfx::Image will take ownership of this. | 
|   88   scoped_nsobject<NSImage> ns_image([[NSImage alloc] initWithData:ns_data]); |   93   scoped_nsobject<NSImage> ns_image([[NSImage alloc] initWithData:ns_data]); | 
|   89  |   94  | 
|   90   // Cache the converted image. |   95   // Cache the converted image. | 
|   91   if (ns_image.get()) { |   96   if (ns_image.get()) { | 
 |   97     // Load a high resolution version of the icon if available. | 
 |   98     if (large_icon_resources_data_) { | 
 |   99       scoped_refptr<RefCountedStaticMemory> large_data( | 
 |  100           LoadResourceBytes(large_icon_resources_data_, resource_id)); | 
 |  101       if (large_data.get()) { | 
 |  102         scoped_nsobject<NSData> ns_large_data( | 
 |  103             [[NSData alloc] initWithBytes:large_data->front() | 
 |  104                                    length:large_data->size()]); | 
 |  105         NSImageRep* image_rep = | 
 |  106             [NSBitmapImageRep imageRepWithData:ns_large_data]; | 
 |  107         if (image_rep) | 
 |  108           [ns_image addRepresentation:image_rep]; | 
 |  109       } | 
 |  110     } | 
 |  111  | 
|   92     base::AutoLock lock(*lock_); |  112     base::AutoLock lock(*lock_); | 
|   93  |  113  | 
|   94     // Another thread raced the load and has already cached the image. |  114     // Another thread raced the load and has already cached the image. | 
|   95     if (images_.count(resource_id)) { |  115     if (images_.count(resource_id)) { | 
|   96       return *images_[resource_id]; |  116       return *images_[resource_id]; | 
|   97     } |  117     } | 
|   98  |  118  | 
|   99     gfx::Image* image = new gfx::Image(ns_image.release()); |  119     gfx::Image* image = new gfx::Image(ns_image.release()); | 
|  100     images_[resource_id] = image; |  120     images_[resource_id] = image; | 
|  101     return *image; |  121     return *image; | 
|  102   } |  122   } | 
|  103  |  123  | 
|  104   LOG(WARNING) << "Unable to load image with id " << resource_id; |  124   LOG(WARNING) << "Unable to load image with id " << resource_id; | 
|  105   NOTREACHED();  // Want to assert in debug mode. |  125   NOTREACHED();  // Want to assert in debug mode. | 
|  106   return *GetEmptyImage(); |  126   return *GetEmptyImage(); | 
|  107 } |  127 } | 
|  108  |  128  | 
|  109 }  // namespace ui |  129 }  // namespace ui | 
| OLD | NEW |