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

Side by Side Diff: ui/base/resource/resource_bundle.h

Issue 10686005: Add methods to add DataPack from open files (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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
« no previous file with comments | « ui/base/resource/data_pack_unittest.cc ('k') | ui/base/resource/resource_bundle.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ 5 #ifndef UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_
6 #define UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ 6 #define UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_
7 #pragma once 7 #pragma once
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
11 #include <map> 11 #include <map>
12 #include <string> 12 #include <string>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/scoped_vector.h" 18 #include "base/memory/scoped_vector.h"
19 #include "base/platform_file.h"
19 #include "base/string16.h" 20 #include "base/string16.h"
20 #include "base/string_piece.h" 21 #include "base/string_piece.h"
21 #include "ui/base/layout.h" 22 #include "ui/base/layout.h"
22 #include "ui/base/ui_export.h" 23 #include "ui/base/ui_export.h"
23 #include "ui/gfx/font.h" 24 #include "ui/gfx/font.h"
24 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
25 #include "ui/gfx/native_widget_types.h" 26 #include "ui/gfx/native_widget_types.h"
26 27
27 class SkBitmap; 28 class SkBitmap;
28 29
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 virtual ~Delegate() {} 112 virtual ~Delegate() {}
112 }; 113 };
113 114
114 // Initialize the ResourceBundle for this process. Does not take ownership of 115 // Initialize the ResourceBundle for this process. Does not take ownership of
115 // the |delegate| value. Returns the language selected. 116 // the |delegate| value. Returns the language selected.
116 // NOTE: Mac ignores this and always loads up resources for the language 117 // NOTE: Mac ignores this and always loads up resources for the language
117 // defined by the Cocoa UI (i.e., NSBundle does the language work). 118 // defined by the Cocoa UI (i.e., NSBundle does the language work).
118 static std::string InitSharedInstanceWithLocale( 119 static std::string InitSharedInstanceWithLocale(
119 const std::string& pref_locale, Delegate* delegate); 120 const std::string& pref_locale, Delegate* delegate);
120 121
122 // Initialize the ResourceBundle using given file. The second argument
123 // controls whether or not ResourceBundle::LoadCommonResources is called.
124 // This allows the use of this function in a sandbox without local file
125 // access (as on Android).
126 static void InitSharedInstanceWithPakFile(
127 base::PlatformFile file, bool should_load_common_resources);
128
121 // Initialize the ResourceBundle using given data pack path for testing. 129 // Initialize the ResourceBundle using given data pack path for testing.
122 static void InitSharedInstanceWithPakFile(const FilePath& path); 130 static void InitSharedInstanceWithPakPath(const FilePath& path);
123 131
124 // Delete the ResourceBundle for this process if it exists. 132 // Delete the ResourceBundle for this process if it exists.
125 static void CleanupSharedInstance(); 133 static void CleanupSharedInstance();
126 134
127 // Returns true after the global resource loader instance has been created. 135 // Returns true after the global resource loader instance has been created.
128 static bool HasSharedInstance(); 136 static bool HasSharedInstance();
129 137
130 // Return the global resource loader instance. 138 // Return the global resource loader instance.
131 static ResourceBundle& GetSharedInstance(); 139 static ResourceBundle& GetSharedInstance();
132 140
133 // Check if the .pak for the given locale exists. 141 // Check if the .pak for the given locale exists.
134 bool LocaleDataPakExists(const std::string& locale); 142 bool LocaleDataPakExists(const std::string& locale);
135 143
136 // Registers additional data pack files with this ResourceBundle. When 144 // Registers additional data pack files with this ResourceBundle. When
137 // looking for a DataResource, we will search these files after searching the 145 // looking for a DataResource, we will search these files after searching the
138 // main module. |path| should be the complete path to the pack file if known 146 // main module. |path| should be the complete path to the pack file if known
139 // or just the pack file name otherwise (the delegate may optionally override 147 // or just the pack file name otherwise (the delegate may optionally override
140 // this value). |scale_factor| is the scale of images in this resource pak 148 // this value). |scale_factor| is the scale of images in this resource pak
141 // relative to the images in the 1x resource pak. This method is not thread 149 // relative to the images in the 1x resource pak. This method is not thread
142 // safe! You should call it immediately after calling InitSharedInstance. 150 // safe! You should call it immediately after calling InitSharedInstance.
143 void AddDataPack(const FilePath& path, ScaleFactor scale_factor); 151 void AddDataPackFromPath(const FilePath& path, ScaleFactor scale_factor);
152
153 // Same as above but using an already open file.
154 void AddDataPackFromFile(base::PlatformFile file, ScaleFactor scale_factor);
144 155
145 // Changes the locale for an already-initialized ResourceBundle, returning the 156 // Changes the locale for an already-initialized ResourceBundle, returning the
146 // name of the newly-loaded locale. Future calls to get strings will return 157 // name of the newly-loaded locale. Future calls to get strings will return
147 // the strings for this new locale. This has no effect on existing or future 158 // the strings for this new locale. This has no effect on existing or future
148 // image resources. |locale_resources_data_| is protected by a lock for the 159 // image resources. |locale_resources_data_| is protected by a lock for the
149 // duration of the swap, as GetLocalizedString() may be concurrently invoked 160 // duration of the swap, as GetLocalizedString() may be concurrently invoked
150 // on another thread. 161 // on another thread.
151 std::string ReloadLocaleResources(const std::string& pref_locale); 162 std::string ReloadLocaleResources(const std::string& pref_locale);
152 163
153 // Gets the bitmap with the specified resource_id from the current module 164 // Gets the bitmap with the specified resource_id from the current module
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 const gfx::Font& GetFont(FontStyle style); 217 const gfx::Font& GetFont(FontStyle style);
207 218
208 // Resets and reloads the cached fonts. This is useful when the fonts of the 219 // Resets and reloads the cached fonts. This is useful when the fonts of the
209 // system have changed, for example, when the locale has changed. 220 // system have changed, for example, when the locale has changed.
210 void ReloadFonts(); 221 void ReloadFonts();
211 222
212 // Overrides the path to the pak file from which the locale resources will be 223 // Overrides the path to the pak file from which the locale resources will be
213 // loaded. Pass an empty path to undo. 224 // loaded. Pass an empty path to undo.
214 void OverrideLocalePakForTest(const FilePath& pak_path); 225 void OverrideLocalePakForTest(const FilePath& pak_path);
215 226
227 // Returns the full pathname of the locale file to load. May return an empty
228 // string if no locale data files are found and |test_file_exists| is true.
229 // Used on Android to load the local file in the browser process and pass it
230 // to the sandboxed renderer process.
231 FilePath GetLocaleFilePath(const std::string& app_locale,
232 bool test_file_exists);
233
216 private: 234 private:
217 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForResourcePack); 235 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForResourcePack);
218 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForLocalePack); 236 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForLocalePack);
219 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetImageNamed); 237 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetImageNamed);
220 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetNativeImageNamed); 238 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetNativeImageNamed);
221 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateLoadDataResourceBytes); 239 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateLoadDataResourceBytes);
222 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetRawDataResource); 240 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetRawDataResource);
223 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetLocalizedString); 241 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetLocalizedString);
224 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetFont); 242 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetFont);
225 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, GetRawDataResource); 243 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, GetRawDataResource);
(...skipping 18 matching lines...) Expand all
244 // resource pack is loaded. 262 // resource pack is loaded.
245 void LoadTestResources(const FilePath& path, const FilePath& locale_path); 263 void LoadTestResources(const FilePath& path, const FilePath& locale_path);
246 264
247 // Unload the locale specific strings and prepares to load new ones. See 265 // Unload the locale specific strings and prepares to load new ones. See
248 // comments for ReloadLocaleResources(). 266 // comments for ReloadLocaleResources().
249 void UnloadLocaleResources(); 267 void UnloadLocaleResources();
250 268
251 // Initialize all the gfx::Font members if they haven't yet been initialized. 269 // Initialize all the gfx::Font members if they haven't yet been initialized.
252 void LoadFontsIfNecessary(); 270 void LoadFontsIfNecessary();
253 271
254 // Returns the full pathname of the locale file to load. May return an empty
255 // string if no locale data files are found.
256 FilePath GetLocaleFilePath(const std::string& app_locale);
257
258 // Creates and returns a new SkBitmap given the data file to look in and the 272 // Creates and returns a new SkBitmap given the data file to look in and the
259 // resource id. It's up to the caller to free the returned bitmap when 273 // resource id. It's up to the caller to free the returned bitmap when
260 // done. 274 // done.
261 SkBitmap* LoadBitmap(const ResourceHandle& dll_inst, int resource_id); 275 SkBitmap* LoadBitmap(const ResourceHandle& dll_inst, int resource_id);
262 276
263 // Returns an empty image for when a resource cannot be loaded. This is a 277 // Returns an empty image for when a resource cannot be loaded. This is a
264 // bright red bitmap. 278 // bright red bitmap.
265 gfx::Image& GetEmptyImage(); 279 gfx::Image& GetEmptyImage();
266 280
267 const FilePath& GetOverriddenPakPath(); 281 const FilePath& GetOverriddenPakPath();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 317
304 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); 318 DISALLOW_COPY_AND_ASSIGN(ResourceBundle);
305 }; 319 };
306 320
307 } // namespace ui 321 } // namespace ui
308 322
309 // TODO(beng): Someday, maybe, get rid of this. 323 // TODO(beng): Someday, maybe, get rid of this.
310 using ui::ResourceBundle; 324 using ui::ResourceBundle;
311 325
312 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ 326 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_
OLDNEW
« no previous file with comments | « ui/base/resource/data_pack_unittest.cc ('k') | ui/base/resource/resource_bundle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698