OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/mac/bundle_locations.h" | 13 #include "base/mac/bundle_locations.h" |
14 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
16 #include "base/memory/scoped_nsobject.h" | 16 #include "base/memory/scoped_nsobject.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/sys_string_conversions.h" | 18 #include "base/sys_string_conversions.h" |
19 #include "ui/base/resource/resource_handle.h" | 19 #include "ui/base/resource/resource_handle.h" |
20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
21 | 21 |
22 namespace ui { | 22 namespace ui { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) { | 26 base::FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) { |
27 NSString *resource_path; | 27 NSString *resource_path; |
28 if ([mac_locale length]) { | 28 if ([mac_locale length]) { |
29 resource_path = [base::mac::FrameworkBundle() pathForResource:name | 29 resource_path = [base::mac::FrameworkBundle() pathForResource:name |
30 ofType:@"pak" | 30 ofType:@"pak" |
31 inDirectory:@"" | 31 inDirectory:@"" |
32 forLocalization:mac_locale]; | 32 forLocalization:mac_locale]; |
33 } else { | 33 } else { |
34 resource_path = [base::mac::FrameworkBundle() pathForResource:name | 34 resource_path = [base::mac::FrameworkBundle() pathForResource:name |
35 ofType:@"pak"]; | 35 ofType:@"pak"]; |
36 } | 36 } |
(...skipping 14 matching lines...) Expand all Loading... |
51 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_100_percent", nil), | 51 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_100_percent", nil), |
52 SCALE_FACTOR_100P); | 52 SCALE_FACTOR_100P); |
53 } | 53 } |
54 | 54 |
55 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) { | 55 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) { |
56 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_200_percent", nil), | 56 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_200_percent", nil), |
57 SCALE_FACTOR_200P); | 57 SCALE_FACTOR_200P); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, | 61 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, |
62 bool test_file_exists) { | 62 bool test_file_exists) { |
63 NSString* mac_locale = base::SysUTF8ToNSString(app_locale); | 63 NSString* mac_locale = base::SysUTF8ToNSString(app_locale); |
64 | 64 |
65 // iOS uses "_" instead of "-", so swap to get a iOS-style value. | 65 // iOS uses "_" instead of "-", so swap to get a iOS-style value. |
66 mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" | 66 mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-" |
67 withString:@"_"]; | 67 withString:@"_"]; |
68 | 68 |
69 // On disk, the "en_US" resources are just "en" (http://crbug.com/25578). | 69 // On disk, the "en_US" resources are just "en" (http://crbug.com/25578). |
70 if ([mac_locale isEqual:@"en_US"]) | 70 if ([mac_locale isEqual:@"en_US"]) |
71 mac_locale = @"en"; | 71 mac_locale = @"en"; |
72 | 72 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 // Another thread raced the load and has already cached the image. | 180 // Another thread raced the load and has already cached the image. |
181 if (images_.count(resource_id)) | 181 if (images_.count(resource_id)) |
182 return images_[resource_id]; | 182 return images_[resource_id]; |
183 | 183 |
184 images_[resource_id] = image; | 184 images_[resource_id] = image; |
185 return images_[resource_id]; | 185 return images_[resource_id]; |
186 } | 186 } |
187 | 187 |
188 } // namespace ui | 188 } // namespace ui |
OLD | NEW |