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

Unified Diff: ui/base/resource/resource_bundle.h

Issue 10270023: Add new ResourceBundle::Delegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/base/resource/resource_bundle.h
===================================================================
--- ui/base/resource/resource_bundle.h (revision 133962)
+++ ui/base/resource/resource_bundle.h (working copy)
@@ -19,6 +19,8 @@
#include "base/string16.h"
#include "base/string_piece.h"
#include "ui/base/ui_export.h"
+#include "ui/gfx/font.h"
+#include "ui/gfx/image/image.h"
#include "ui/gfx/native_widget_types.h"
class SkBitmap;
@@ -28,11 +30,6 @@
class RefCountedStaticMemory;
}
-namespace gfx {
-class Font;
-class Image;
-}
-
namespace ui {
class ResourceHandle;
@@ -63,12 +60,59 @@
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.
+ virtual scoped_ptr<gfx::Image> GetImageNamed(int resource_id) = 0;
+
+ // Return an image resource or NULL to attempt retrieval of the default
+ // resource.
+ virtual scoped_ptr<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.
+ virtual scoped_ptr<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,12 +127,14 @@
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
- // main module. This method is not thread safe! You should call it
- // immediately after calling InitSharedInstance.
+ // Registers additional data pack files with the global ResourceBundle. This
tony 2012/05/01 15:56:48 Nit: Remove the word global since this operates on
Marshall 2012/05/01 17:29:41 Done.
+ // method is intended for use by ResourceBundle consumers and adds the data
+ // pack to the ResourceBundle without calling the ResourceBundle delegate.
+ // These files will be seached in the order added when looking for resources.
+ // This method is not thread safe and should be called immediately after
+ // calling the appropriate InitSharedInstance*() method.
void AddDataPack(const FilePath& path);
// Changes the locale for an already-initialized ResourceBundle, returning 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,13 @@
// Load the main resources.
void LoadCommonResources();
+ // Registers additional data pack files with the global ResourceBundle. This
tony 2012/05/01 15:56:48 Nit: Remove global here too?
Marshall 2012/05/01 17:29:41 Done.
+ // method is intended for use when ResourceBundle loads pack files internally
+ // and will give the delegate an opportunity to modify or cancel the load.
+ // This method is not thread safe and should only be called from the platform
+ // LoadCommonResources() implementation.
+ void AddCommonDataPack(const std::string& pack_name, const FilePath& path);
+
// 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 +229,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 +242,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_;

Powered by Google App Engine
This is Rietveld 408576698