Chromium Code Reviews| Index: ui/base/resource/resource_bundle.h |
| =================================================================== |
| --- ui/base/resource/resource_bundle.h (revision 133962) |
| +++ ui/base/resource/resource_bundle.h (working copy) |
| @@ -63,12 +63,58 @@ |
| RTL_DISABLED, |
| }; |
| - // Initialize the ResourceBundle for this process. Returns the language |
| - // selected. |
| + class Delegate { |
| + public: |
| + // Retrieve the full path for the specified |pack_name|. |pack_path| will |
| + // initially contain the default path for the pack file. Change it in this |
| + // callback if a different path is desired. Return true to continue loading |
| + // the pack file or false to cancel the load. |
| + virtual bool GetPathForResourcePack(const std::string& pack_name, |
| + FilePath* pack_path) = 0; |
| + |
| + // Retrieve the full path for the specified |locale|. |pack_path| will |
| + // initially contain the default path for the pack file. Change it in this |
| + // callback if a different path is desired. Return true to continue loading |
| + // the pack file or false to cancel the load. |
| + virtual bool GetPathForLocalePack(const std::string& locale, |
| + FilePath* pack_path) = 0; |
| + |
| + // Return an image resource or NULL to attempt retrieval of the default |
| + // resource. The returned value will be owned by ResourceBundle. |
| + virtual gfx::Image* GetImageNamed(int resource_id) = 0; |
|
sail
2012/04/30 21:14:43
can you have this return a scoped_ptr. Then you ca
Marshall
2012/04/30 21:50:10
Done.
|
| + |
| + // Return an image resource or NULL to attempt retrieval of the default |
| + // resource. The returned value will be owned by ResourceBundle. |
| + virtual gfx::Image* GetNativeImageNamed(int resource_id, ImageRTL rtl) = 0; |
| + |
| + // Return a static memory resource or NULL to attempt retrieval of the |
| + // default resource. |
| + virtual base::RefCountedStaticMemory* LoadDataResourceBytes( |
| + int resource_id) = 0; |
| + |
| + // Retrieve a raw data resource. Return true if a resource was provided or |
| + // false to attempt retrieval of the default resource. |
| + virtual bool GetRawDataResource(int resource_id, |
| + base::StringPiece* value) = 0; |
| + |
| + // Retrieve a localized string. Return true if a string was provided or |
| + // false to attempt retrieval of the default string. |
| + virtual bool GetLocalizedString(int message_id, string16* value) = 0; |
| + |
| + // Return a font resource or NULL to attempt retrieval of the default |
| + // resource. The returned value will be owned by ResourceBundle. |
| + virtual gfx::Font* GetFont(FontStyle style) = 0; |
| + |
| + protected: |
| + virtual ~Delegate() {} |
| + }; |
| + |
| + // Initialize the ResourceBundle for this process. Does not take ownership of |
| + // the |delegate| value. Returns the language selected. |
| // NOTE: Mac ignores this and always loads up resources for the language |
| // defined by the Cocoa UI (i.e., NSBundle does the language work). |
| static std::string InitSharedInstanceWithLocale( |
| - const std::string& pref_locale); |
| + const std::string& pref_locale, Delegate* delegate); |
| // Initialize the ResourceBundle using given data pack path for testing. |
| static void InitSharedInstanceWithPakFile(const FilePath& path); |
| @@ -83,7 +129,7 @@ |
| static ResourceBundle& GetSharedInstance(); |
| // Check if the .pak for the given locale exists. |
| - static bool LocaleDataPakExists(const std::string& locale); |
| + bool LocaleDataPakExists(const std::string& locale); |
| // Registers additional data pack files with the global ResourceBundle. When |
| // looking for a DataResource, we will search these files after searching the |
| @@ -151,7 +197,7 @@ |
| FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LoadDataResourceBytes); |
| // Ctor/dtor are private, since we're a singleton. |
| - ResourceBundle(); |
| + explicit ResourceBundle(Delegate* delegate); |
| ~ResourceBundle(); |
| // Free skia_images_. |
| @@ -160,6 +206,10 @@ |
| // Load the main resources. |
| void LoadCommonResources(); |
| + // Add a common data pack to the ResourceBundle. Gives the delegate an |
| + // opportunity to modify the load. |
| + void AddCommonDataPack(const std::string& pack_name, const FilePath& path); |
|
sail
2012/04/30 21:14:43
do you really need AddDataPack and AddCommonDataPa
Marshall
2012/04/30 21:50:10
I think both are needed. AddDataPack() is used ext
sail
2012/04/30 22:33:26
But why does external vs internal matter? Why woul
Marshall
2012/05/01 17:29:41
Removed the additional method.
|
| + |
| // Try to load the locale specific strings from an external data module. |
| // Returns the locale that is loaded. |
| std::string LoadLocaleResources(const std::string& pref_locale); |
| @@ -176,7 +226,7 @@ |
| // Returns the full pathname of the locale file to load. May return an empty |
| // string if no locale data files are found. |
| - static FilePath GetLocaleFilePath(const std::string& app_locale); |
| + FilePath GetLocaleFilePath(const std::string& app_locale); |
| // Creates and returns a new SkBitmap given the data file to look in and the |
| // resource id. It's up to the caller to free the returned bitmap when |
| @@ -189,6 +239,9 @@ |
| const FilePath& GetOverriddenPakPath(); |
| + // This pointer is guaranteed to outlive the ResourceBundle instance. |
| + Delegate* delegate_; |
| + |
| // Protects |images_| and font-related members. |
| scoped_ptr<base::Lock> images_and_fonts_lock_; |