| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 22 matching lines...) Expand all Loading... |
| 33 ofType:@"pak" | 33 ofType:@"pak" |
| 34 inDirectory:@"" | 34 inDirectory:@"" |
| 35 forLocalization:mac_locale]; | 35 forLocalization:mac_locale]; |
| 36 } else { | 36 } else { |
| 37 resource_path = [base::mac::FrameworkBundle() pathForResource:name | 37 resource_path = [base::mac::FrameworkBundle() pathForResource:name |
| 38 ofType:@"pak"]; | 38 ofType:@"pak"]; |
| 39 } | 39 } |
| 40 | 40 |
| 41 if (!resource_path) { | 41 if (!resource_path) { |
| 42 // Return just the name of the pack file. | 42 // Return just the name of the pack file. |
| 43 return FilePath(base::SysNSStringToUTF8(name) + ".pak"); | 43 return base::FilePath(base::SysNSStringToUTF8(name) + ".pak"); |
| 44 } | 44 } |
| 45 | 45 |
| 46 return FilePath([resource_path fileSystemRepresentation]); | 46 return base::FilePath([resource_path fileSystemRepresentation]); |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 void ResourceBundle::LoadCommonResources() { | 51 void ResourceBundle::LoadCommonResources() { |
| 52 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome", nil), | 52 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome", nil), |
| 53 SCALE_FACTOR_NONE); | 53 SCALE_FACTOR_NONE); |
| 54 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_100_percent", | 54 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_100_percent", |
| 55 nil), SCALE_FACTOR_100P); | 55 nil), SCALE_FACTOR_100P); |
| 56 AddDataPackFromPath(GetResourcesPakFilePath(@"webkit_resources_100_percent", | 56 AddDataPackFromPath(GetResourcesPakFilePath(@"webkit_resources_100_percent", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 71 NSString* mac_locale = base::SysUTF8ToNSString(app_locale); | 71 NSString* mac_locale = base::SysUTF8ToNSString(app_locale); |
| 72 | 72 |
| 73 // Mac OS X uses "_" instead of "-", so swap to get a Mac-style value. | 73 // Mac OS X uses "_" instead of "-", so swap to get a Mac-style value. |
| 74 mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" | 74 mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" |
| 75 withString:@"_"]; | 75 withString:@"_"]; |
| 76 | 76 |
| 77 // On disk, the "en_US" resources are just "en" (http://crbug.com/25578). | 77 // On disk, the "en_US" resources are just "en" (http://crbug.com/25578). |
| 78 if ([mac_locale isEqual:@"en_US"]) | 78 if ([mac_locale isEqual:@"en_US"]) |
| 79 mac_locale = @"en"; | 79 mac_locale = @"en"; |
| 80 | 80 |
| 81 FilePath locale_file_path = GetResourcesPakFilePath(@"locale", mac_locale); | 81 base::FilePath locale_file_path = |
| 82 GetResourcesPakFilePath(@"locale", mac_locale); |
| 82 | 83 |
| 83 if (delegate_) { | 84 if (delegate_) { |
| 84 locale_file_path = | 85 locale_file_path = |
| 85 delegate_->GetPathForLocalePack(locale_file_path, app_locale); | 86 delegate_->GetPathForLocalePack(locale_file_path, app_locale); |
| 86 } | 87 } |
| 87 | 88 |
| 88 // Don't try to load empty values or values that are not absolute paths. | 89 // Don't try to load empty values or values that are not absolute paths. |
| 89 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) | 90 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) |
| 90 return FilePath(); | 91 return base::FilePath(); |
| 91 | 92 |
| 92 if (test_file_exists && !file_util::PathExists(locale_file_path)) | 93 if (test_file_exists && !file_util::PathExists(locale_file_path)) |
| 93 return FilePath(); | 94 return base::FilePath(); |
| 94 | 95 |
| 95 return locale_file_path; | 96 return locale_file_path; |
| 96 } | 97 } |
| 97 | 98 |
| 98 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { | 99 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { |
| 99 // Flipped images are not used on Mac. | 100 // Flipped images are not used on Mac. |
| 100 DCHECK_EQ(rtl, RTL_DISABLED); | 101 DCHECK_EQ(rtl, RTL_DISABLED); |
| 101 | 102 |
| 102 // Check to see if the image is already in the cache. | 103 // Check to see if the image is already in the cache. |
| 103 { | 104 { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 151 |
| 151 // Another thread raced the load and has already cached the image. | 152 // Another thread raced the load and has already cached the image. |
| 152 if (images_.count(resource_id)) | 153 if (images_.count(resource_id)) |
| 153 return images_[resource_id]; | 154 return images_[resource_id]; |
| 154 | 155 |
| 155 images_[resource_id] = image; | 156 images_[resource_id] = image; |
| 156 return images_[resource_id]; | 157 return images_[resource_id]; |
| 157 } | 158 } |
| 158 | 159 |
| 159 } // namespace ui | 160 } // namespace ui |
| OLD | NEW |