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

Side by Side Diff: app/resource_bundle_mac.mm

Issue 338027: Modify DataPacks so they can return RefCountedStaticMemory objects. (Closed)
Patch Set: Rewrite GetStaticMemory Created 11 years, 1 month 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
OLDNEW
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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 void ResourceBundle::LoadThemeResources() { 68 void ResourceBundle::LoadThemeResources() {
69 DCHECK(theme_data_ == NULL) << "theme data already loaded!"; 69 DCHECK(theme_data_ == NULL) << "theme data already loaded!";
70 theme_data_ = LoadResourceDataPack(@"theme"); 70 theme_data_ = LoadResourceDataPack(@"theme");
71 DCHECK(theme_data_) << "failed to load theme.pak"; 71 DCHECK(theme_data_) << "failed to load theme.pak";
72 } 72 }
73 73
74 // static 74 // static
75 RefCountedStaticMemory* ResourceBundle::LoadResourceBytes( 75 RefCountedStaticMemory* ResourceBundle::LoadResourceBytes(
76 DataHandle module, int resource_id) { 76 DataHandle module, int resource_id) {
77 DCHECK(module); 77 DCHECK(module);
78 base::StringPiece bytes; 78 return module->GetStaticMemory(resource_id);
79 if (!module->Get(resource_id, &bytes))
80 return NULL;
81
82 return new RefCountedStaticMemory(
83 reinterpret_cast<const unsigned char*>(bytes.data()), bytes.length());
84 } 79 }
85 80
86 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) { 81 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) {
87 DCHECK(resources_data_); 82 DCHECK(resources_data_);
88 base::StringPiece data; 83 base::StringPiece data;
89 if (!resources_data_->Get(resource_id, &data)) 84 if (!resources_data_->GetStringPiece(resource_id, &data))
90 return base::StringPiece(); 85 return base::StringPiece();
91 return data; 86 return data;
92 } 87 }
93 88
94 string16 ResourceBundle::GetLocalizedString(int message_id) { 89 string16 ResourceBundle::GetLocalizedString(int message_id) {
95 // If for some reason we were unable to load a resource dll, return an empty 90 // If for some reason we were unable to load a resource dll, return an empty
96 // string (better than crashing). 91 // string (better than crashing).
97 if (!locale_resources_data_) { 92 if (!locale_resources_data_) {
98 LOG(WARNING) << "locale resources are not loaded"; 93 LOG(WARNING) << "locale resources are not loaded";
99 return string16(); 94 return string16();
100 } 95 }
101 96
102 base::StringPiece data; 97 base::StringPiece data;
103 if (!locale_resources_data_->Get(message_id, &data)) { 98 if (!locale_resources_data_->GetStringPiece(message_id, &data)) {
104 // Fall back on the main data pack (shouldn't be any strings here except in 99 // Fall back on the main data pack (shouldn't be any strings here except in
105 // unittests). 100 // unittests).
106 data = GetRawDataResource(message_id); 101 data = GetRawDataResource(message_id);
107 if (data.empty()) { 102 if (data.empty()) {
108 NOTREACHED() << "unable to find resource: " << message_id; 103 NOTREACHED() << "unable to find resource: " << message_id;
109 return string16(); 104 return string16();
110 } 105 }
111 } 106 }
112 107
113 // Data pack encodes strings as UTF16. 108 // Data pack encodes strings as UTF16.
114 string16 msg(reinterpret_cast<const char16*>(data.data()), 109 string16 msg(reinterpret_cast<const char16*>(data.data()),
115 data.length() / 2); 110 data.length() / 2);
116 return msg; 111 return msg;
117 } 112 }
118 113
119 NSImage* ResourceBundle::GetNSImageNamed(int resource_id) { 114 NSImage* ResourceBundle::GetNSImageNamed(int resource_id) {
120 // Currently this doesn't make a cache holding these as NSImages because 115 // Currently this doesn't make a cache holding these as NSImages because
121 // GetBitmapNamed has a cache, and we don't want to double cache. 116 // GetBitmapNamed has a cache, and we don't want to double cache.
122 SkBitmap* bitmap = GetBitmapNamed(resource_id); 117 SkBitmap* bitmap = GetBitmapNamed(resource_id);
123 if (!bitmap) 118 if (!bitmap)
124 return nil; 119 return nil;
125 120
126 NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap); 121 NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap);
127 return nsimage; 122 return nsimage;
128 } 123 }
OLDNEW
« no previous file with comments | « app/resource_bundle_linux.cc ('k') | base/data_pack.h » ('j') | base/data_pack.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698