OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/resource_bundle.h" | 5 #include "app/resource_bundle.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include "app/gfx/font.h" | 9 #include "app/gfx/font.h" |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/data_pack.h" | 12 #include "base/data_pack.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/mac_util.h" | 16 #include "base/mac_util.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "skia/ext/skia_utils_mac.h" | 20 #include "skia/ext/skia_utils_mac.h" |
21 | 21 |
22 ResourceBundle::~ResourceBundle() { | 22 ResourceBundle::~ResourceBundle() { |
23 FreeImages(); | 23 FreeImages(); |
24 | 24 |
25 delete locale_resources_data_; | 25 delete locale_resources_data_; |
26 locale_resources_data_ = NULL; | 26 locale_resources_data_ = NULL; |
27 delete resources_data_; | 27 delete resources_data_; |
28 resources_data_ = NULL; | 28 resources_data_ = NULL; |
29 theme_data_ = NULL; | |
30 } | 29 } |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 base::DataPack *LoadResourceDataPack(NSString *name) { | 33 base::DataPack *LoadResourceDataPack(NSString *name) { |
35 base::DataPack *resource_pack = NULL; | 34 base::DataPack *resource_pack = NULL; |
36 | 35 |
37 NSString *resource_path = [mac_util::MainAppBundle() pathForResource:name | 36 NSString *resource_path = [mac_util::MainAppBundle() pathForResource:name |
38 ofType:@"pak"]; | 37 ofType:@"pak"]; |
39 if (resource_path) { | 38 if (resource_path) { |
(...skipping 17 matching lines...) Expand all Loading... |
57 | 56 |
58 DCHECK(resources_data_ == NULL) << "resource data already loaded!"; | 57 DCHECK(resources_data_ == NULL) << "resource data already loaded!"; |
59 resources_data_ = LoadResourceDataPack(@"chrome"); | 58 resources_data_ = LoadResourceDataPack(@"chrome"); |
60 DCHECK(resources_data_) << "failed to load chrome.pak"; | 59 DCHECK(resources_data_) << "failed to load chrome.pak"; |
61 | 60 |
62 DCHECK(locale_resources_data_ == NULL) << "locale data already loaded!"; | 61 DCHECK(locale_resources_data_ == NULL) << "locale data already loaded!"; |
63 locale_resources_data_ = LoadResourceDataPack(@"locale"); | 62 locale_resources_data_ = LoadResourceDataPack(@"locale"); |
64 DCHECK(locale_resources_data_) << "failed to load locale.pak"; | 63 DCHECK(locale_resources_data_) << "failed to load locale.pak"; |
65 } | 64 } |
66 | 65 |
67 void ResourceBundle::LoadThemeResources() { | |
68 // The data has been merged with chrome.pak so just set the pointer to be | |
69 // the same file. | |
70 DCHECK(resources_data_); | |
71 theme_data_ = resources_data_; | |
72 } | |
73 | |
74 // static | 66 // static |
75 RefCountedStaticMemory* ResourceBundle::LoadResourceBytes( | 67 RefCountedStaticMemory* ResourceBundle::LoadResourceBytes( |
76 DataHandle module, int resource_id) { | 68 DataHandle module, int resource_id) { |
77 DCHECK(module); | 69 DCHECK(module); |
78 return module->GetStaticMemory(resource_id); | 70 return module->GetStaticMemory(resource_id); |
79 } | 71 } |
80 | 72 |
81 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) { | 73 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) { |
82 DCHECK(resources_data_); | 74 DCHECK(resources_data_); |
83 base::StringPiece data; | 75 base::StringPiece data; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 NSImage* ResourceBundle::GetNSImageNamed(int resource_id) { | 109 NSImage* ResourceBundle::GetNSImageNamed(int resource_id) { |
118 // Currently this doesn't make a cache holding these as NSImages because | 110 // Currently this doesn't make a cache holding these as NSImages because |
119 // GetBitmapNamed has a cache, and we don't want to double cache. | 111 // GetBitmapNamed has a cache, and we don't want to double cache. |
120 SkBitmap* bitmap = GetBitmapNamed(resource_id); | 112 SkBitmap* bitmap = GetBitmapNamed(resource_id); |
121 if (!bitmap) | 113 if (!bitmap) |
122 return nil; | 114 return nil; |
123 | 115 |
124 NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap); | 116 NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap); |
125 return nsimage; | 117 return nsimage; |
126 } | 118 } |
OLD | NEW |