blob: 13889323bfce96a9cfb3541a82cebf532cd3e096 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "app/resource_bundle.h"
#import <Foundation/Foundation.h>
#include "base/file_path.h"
#include "base/logging.h"
#include "base/mac_util.h"
#include "base/sys_string_conversions.h"
#include "skia/ext/skia_utils_mac.h"
namespace {
FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) {
NSString *resource_path;
// Some of the helper processes need to be able to fetch resources
// (chrome_dll_main.cc SubprocessNeedsResourceBundle()). Fetch the same locale
// as the already-running browser instead of using what NSBundle might pick
// based on values at helper launch time.
if ([mac_locale length]) {
resource_path = [mac_util::MainAppBundle() pathForResource:name
ofType:@"pak"
inDirectory:@""
forLocalization:mac_locale];
} else {
resource_path = [mac_util::MainAppBundle() pathForResource:name
ofType:@"pak"];
}
if (!resource_path)
return FilePath();
return FilePath([resource_path fileSystemRepresentation]);
}
} // namespace
// static
FilePath ResourceBundle::GetResourcesFilePath() {
return GetResourcesPakFilePath(@"chrome", nil);
}
// static
FilePath ResourceBundle::GetLocaleFilePath(const std::string& app_locale) {
NSString* mac_locale = base::SysUTF8ToNSString(app_locale);
// Mac OS X uses "_" instead of "-", so swap to get a Mac-style value.
mac_locale = [mac_locale stringByReplacingOccurrencesOfString:@"-"
withString:@"_"];
// On disk, the "en_US" resources are just "en" (http://crbug.com/25578).
if ([mac_locale isEqual:@"en_US"])
mac_locale = @"en";
return GetResourcesPakFilePath(@"locale", mac_locale);
}
NSImage* ResourceBundle::GetNSImageNamed(int resource_id) {
// Currently this doesn't make a cache holding these as NSImages because
// GetBitmapNamed has a cache, and we don't want to double cache.
SkBitmap* bitmap = GetBitmapNamed(resource_id);
if (!bitmap)
return nil;
NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap);
return nsimage;
}
|