OLD | NEW |
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 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // false to attempt retrieval of the default string. | 108 // false to attempt retrieval of the default string. |
109 virtual bool GetLocalizedString(int message_id, base::string16* value) = 0; | 109 virtual bool GetLocalizedString(int message_id, base::string16* value) = 0; |
110 | 110 |
111 // Returns a font or NULL to attempt retrieval of the default resource. | 111 // Returns a font or NULL to attempt retrieval of the default resource. |
112 virtual scoped_ptr<gfx::Font> GetFont(FontStyle style) = 0; | 112 virtual scoped_ptr<gfx::Font> GetFont(FontStyle style) = 0; |
113 | 113 |
114 protected: | 114 protected: |
115 virtual ~Delegate() {} | 115 virtual ~Delegate() {} |
116 }; | 116 }; |
117 | 117 |
| 118 struct UI_BASE_EXPORT InitParams { |
| 119 InitParams(); |
| 120 ~InitParams(); |
| 121 |
| 122 base::FilePath main_pak_path; |
| 123 base::FilePath scaled_1x_pak_path; |
| 124 base::FilePath scaled_2x_pak_path; |
| 125 std::string pref_locale; |
| 126 Delegate* delegate; |
| 127 }; |
| 128 |
118 // Initialize the ResourceBundle for this process. Does not take ownership of | 129 // Initialize the ResourceBundle for this process. Does not take ownership of |
119 // the |delegate| value. Returns the language selected. | 130 // the |delegate| value. Returns the language selected. |
120 // NOTE: Mac ignores this and always loads up resources for the language | 131 // NOTE: Mac ignores this and always loads up resources for the language |
121 // defined by the Cocoa UI (i.e., NSBundle does the language work). | 132 // defined by the Cocoa UI (i.e., NSBundle does the language work). |
122 // | 133 // |
123 // TODO(sergeyu): This method also loads common resources (i.e. chrome.pak). | 134 // TODO(sergeyu): This method also loads common resources (i.e. chrome.pak). |
124 // There is no way to specify which resource files are loaded, i.e. names of | 135 // There is no way to specify which resource files are loaded, i.e. names of |
125 // the files are hardcoded in ResourceBundle. Fix it to allow to specify which | 136 // the files are hardcoded in ResourceBundle. Fix it to allow to specify which |
126 // files are loaded (e.g. add a new method in Delegate). | 137 // files are loaded (e.g. add a new method in Delegate). |
127 static std::string InitSharedInstanceWithLocale( | 138 static std::string InitSharedInstanceWithLocale( |
128 const std::string& pref_locale, Delegate* delegate); | 139 const std::string& pref_locale, |
| 140 Delegate* delegate); |
129 | 141 |
130 // Same as InitSharedInstanceWithLocale(), but loads only localized resources, | 142 // Same as InitSharedInstanceWithLocale(), but loads only localized resources, |
131 // without default resource packs. | 143 // without default resource packs. |
132 static std::string InitSharedInstanceLocaleOnly( | 144 static std::string InitSharedInstanceLocaleOnly( |
133 const std::string& pref_locale, Delegate* delegate); | 145 const std::string& pref_locale, |
| 146 Delegate* delegate); |
134 | 147 |
135 // Initialize the ResourceBundle using the given file region. If |region| is | 148 // Initialize the ResourceBundle using the given file region. If |region| is |
136 // MemoryMappedFile::Region::kWholeFile, the entire |pak_file| is used. | 149 // MemoryMappedFile::Region::kWholeFile, the entire |pak_file| is used. |
137 // |should_load_common_resources| controls whether or not LoadCommonResources | 150 // |should_load_common_resources| controls whether or not LoadCommonResources |
138 // is called. | 151 // is called. |
139 // This allows the use of this function in a sandbox without local file | 152 // This allows the use of this function in a sandbox without local file |
140 // access (as on Android). | 153 // access (as on Android). |
141 static void InitSharedInstanceWithPakFileRegion( | 154 static void InitSharedInstanceWithPakFileRegion( |
142 base::File pak_file, | 155 base::File pak_file, |
143 const base::MemoryMappedFile::Region& region, | 156 const base::MemoryMappedFile::Region& region, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 // Ctor/dtor are private, since we're a singleton. | 309 // Ctor/dtor are private, since we're a singleton. |
297 explicit ResourceBundle(Delegate* delegate); | 310 explicit ResourceBundle(Delegate* delegate); |
298 ~ResourceBundle(); | 311 ~ResourceBundle(); |
299 | 312 |
300 // Shared initialization. | 313 // Shared initialization. |
301 static void InitSharedInstance(Delegate* delegate); | 314 static void InitSharedInstance(Delegate* delegate); |
302 | 315 |
303 // Free skia_images_. | 316 // Free skia_images_. |
304 void FreeImages(); | 317 void FreeImages(); |
305 | 318 |
306 // Load the main resources. | |
307 void LoadCommonResources(); | |
308 | |
309 // Implementation for AddDataPackFromPath and AddOptionalDataPackFromPath, if | 319 // Implementation for AddDataPackFromPath and AddOptionalDataPackFromPath, if |
310 // the pack is not |optional| logs an error on failure to load. | 320 // the pack is not |optional| logs an error on failure to load. |
311 void AddDataPackFromPathInternal(const base::FilePath& path, | 321 void AddDataPackFromPathInternal(const base::FilePath& path, |
312 ScaleFactor scale_factor, | 322 ScaleFactor scale_factor, |
313 bool optional); | 323 bool optional); |
314 | 324 |
315 // Inserts |data_pack| to |data_pack_| and updates |max_scale_factor_| | 325 // Inserts |data_pack| to |data_pack_| and updates |max_scale_factor_| |
316 // accordingly. | 326 // accordingly. |
317 void AddDataPack(DataPack* data_pack); | 327 void AddDataPack(DataPack* data_pack); |
318 | 328 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 431 |
422 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); | 432 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); |
423 }; | 433 }; |
424 | 434 |
425 } // namespace ui | 435 } // namespace ui |
426 | 436 |
427 // TODO(beng): Someday, maybe, get rid of this. | 437 // TODO(beng): Someday, maybe, get rid of this. |
428 using ui::ResourceBundle; | 438 using ui::ResourceBundle; |
429 | 439 |
430 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 440 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
OLD | NEW |