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

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 134688)
+++ 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,60 @@
RTL_DISABLED,
};
- // Initialize the ResourceBundle for this process. Returns the language
- // selected.
+ class Delegate {
tony 2012/05/02 20:41:20 Are delegates expected to deal with thread safety
Marshall 2012/05/03 19:10:54 Yes, the delegate will need to deal with thread sa
+ 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,
+ float scale_factor) = 0;
tony 2012/05/02 20:41:20 I would keep pack_name as a FilePath. What if we
Marshall 2012/05/03 19:10:54 Done.
+
+ // 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;
tony 2012/05/02 20:41:20 I would just return a FilePath (empty to cancel th
Marshall 2012/05/03 19:10:54 Done.
+
+ // 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,14 +128,18 @@
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);
tony 2012/05/02 20:41:20 Does this need to be public?
Marshall 2012/05/03 19:10:54 It's used by l10n_util.cc currently.
- // Registers additional data pack files with the global ResourceBundle. When
- // looking for a DataResource, we will search these files after searching the
- // main module. |scale_factor| is the scale of images in this resource pak
- // relative to the images in the 1x resource pak. This method is not thread
- // safe! You should call it immediately after calling InitSharedInstance.
- void AddDataPack(const FilePath& path, float scale_factor);
+ // Registers additional data pack files with the ResourceBundle. When looking
+ // for a DataResource, we will search these files after searching the main
+ // module. |pack_name| is the name of the pack file (minus the extension)
+ // that will be passed to the delegate. |scale_factor| is the scale of images
+ // in this resource pak relative to the images in the 1x resource pak. This
+ // method is not thread safe! You should call it immediately after calling
+ // InitSharedInstance.
+ void AddDataPack(const std::string& pack_name,
tony 2012/05/02 20:41:20 I would leave this interface unchanged and and spl
Marshall 2012/05/03 19:10:54 Done.
+ const FilePath& path,
+ float scale_factor);
// Changes the locale for an already-initialized ResourceBundle, returning the
// name of the newly-loaded locale. Future calls to get strings will return
@@ -149,10 +198,19 @@
void OverrideLocalePakForTest(const FilePath& pak_path);
private:
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForResourcePack);
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForLocalePack);
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetImageNamed);
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetNativeImageNamed);
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateLoadDataResourceBytes);
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetRawDataResource);
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetLocalizedString);
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetFont);
FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LoadDataResourceBytes);
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LocaleDataPakExists);
// Ctor/dtor are private, since we're a singleton.
- ResourceBundle();
+ explicit ResourceBundle(Delegate* delegate);
~ResourceBundle();
// Free skia_images_.
@@ -177,7 +235,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
@@ -190,6 +248,9 @@
const FilePath& GetOverriddenPakPath();
+ // This pointer is guaranteed to outlive the ResourceBundle instance.
tony 2012/05/02 20:41:20 I would add that it can be NULL.
Marshall 2012/05/03 19:10:54 Done.
+ 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