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

Side by Side Diff: app/resource_bundle_mac.mm

Issue 6263008: Move ResourceBundle, DataPack to ui/base (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app/resource_bundle_linux.cc ('k') | app/resource_bundle_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "app/resource_bundle.h"
6
7 #import <Foundation/Foundation.h>
8
9 #include "base/basictypes.h"
10 #include "base/file_path.h"
11 #include "base/mac/mac_util.h"
12 #include "base/sys_string_conversions.h"
13 #include "skia/ext/skia_utils_mac.h"
14
15 namespace {
16
17 FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) {
18 NSString *resource_path;
19 // Some of the helper processes need to be able to fetch resources
20 // (chrome_main.cc: SubprocessNeedsResourceBundle()). Fetch the same locale
21 // as the already-running browser instead of using what NSBundle might pick
22 // based on values at helper launch time.
23 if ([mac_locale length]) {
24 resource_path = [base::mac::MainAppBundle() pathForResource:name
25 ofType:@"pak"
26 inDirectory:@""
27 forLocalization:mac_locale];
28 } else {
29 resource_path = [base::mac::MainAppBundle() pathForResource:name
30 ofType:@"pak"];
31 }
32 if (!resource_path)
33 return FilePath();
34 return FilePath([resource_path fileSystemRepresentation]);
35 }
36
37 } // namespace
38
39 // static
40 FilePath ResourceBundle::GetResourcesFilePath() {
41 return GetResourcesPakFilePath(@"chrome", nil);
42 }
43
44 // static
45 FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) {
46 NSString* mac_locale = base::SysUTF8ToNSString(app_locale);
47
48 // Mac OS X uses "_" instead of "-", so swap to get a Mac-style value.
49 mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-"
50 withString:@"_"];
51
52 // On disk, the "en_US" resources are just "en" (http://crbug.com/25578).
53 if ([mac_locale isEqual:@"en_US"])
54 mac_locale = @"en";
55
56 return GetResourcesPakFilePath(@"locale", mac_locale);
57 }
58
59 NSImage* ResourceBundle::GetNSImageNamed(int resource_id) {
60 // Currently this doesn't make a cache holding these as NSImages because
61 // GetBitmapNamed has a cache, and we don't want to double cache.
62 SkBitmap* bitmap = GetBitmapNamed(resource_id);
63 if (!bitmap)
64 return nil;
65
66 NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap);
67 return nsimage;
68 }
OLDNEW
« no previous file with comments | « app/resource_bundle_linux.cc ('k') | app/resource_bundle_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698