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" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/mac/bundle_locations.h" | 12 #include "base/mac/bundle_locations.h" |
13 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
15 #include "base/memory/scoped_nsobject.h" | 15 #include "base/memory/scoped_nsobject.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
18 #include "ui/base/resource/resource_handle.h" | 18 #include "ui/base/resource/resource_handle.h" |
19 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) { | 25 base::FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) { |
26 NSString *resource_path; | 26 NSString *resource_path; |
27 // Some of the helper processes need to be able to fetch resources | 27 // Some of the helper processes need to be able to fetch resources |
28 // (chrome_main.cc: SubprocessNeedsResourceBundle()). Fetch the same locale | 28 // (chrome_main.cc: SubprocessNeedsResourceBundle()). Fetch the same locale |
29 // as the already-running browser instead of using what NSBundle might pick | 29 // as the already-running browser instead of using what NSBundle might pick |
30 // based on values at helper launch time. | 30 // based on values at helper launch time. |
31 if ([mac_locale length]) { | 31 if ([mac_locale length]) { |
32 resource_path = [base::mac::FrameworkBundle() pathForResource:name | 32 resource_path = [base::mac::FrameworkBundle() pathForResource:name |
33 ofType:@"pak" | 33 ofType:@"pak" |
34 inDirectory:@"" | 34 inDirectory:@"" |
35 forLocalization:mac_locale]; | 35 forLocalization:mac_locale]; |
(...skipping 23 matching lines...) Expand all Loading... |
59 // On Mac we load 1x and 2x resources and we let the UI framework decide | 59 // On Mac we load 1x and 2x resources and we let the UI framework decide |
60 // which one to use. | 60 // which one to use. |
61 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) { | 61 if (IsScaleFactorSupported(SCALE_FACTOR_200P)) { |
62 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_200_percent", | 62 AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_200_percent", |
63 nil), SCALE_FACTOR_200P); | 63 nil), SCALE_FACTOR_200P); |
64 AddDataPackFromPath(GetResourcesPakFilePath(@"webkit_resources_200_percent", | 64 AddDataPackFromPath(GetResourcesPakFilePath(@"webkit_resources_200_percent", |
65 nil), SCALE_FACTOR_200P); | 65 nil), SCALE_FACTOR_200P); |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, | 69 base::FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale, |
70 bool test_file_exists) { | 70 bool test_file_exists) { |
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 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 // Another thread raced the load and has already cached the image. | 152 // Another thread raced the load and has already cached the image. |
153 if (images_.count(resource_id)) | 153 if (images_.count(resource_id)) |
154 return images_[resource_id]; | 154 return images_[resource_id]; |
155 | 155 |
156 images_[resource_id] = image; | 156 images_[resource_id] = image; |
157 return images_[resource_id]; | 157 return images_[resource_id]; |
158 } | 158 } |
159 | 159 |
160 } // namespace ui | 160 } // namespace ui |
OLD | NEW |