summaryrefslogtreecommitdiffstats
path: root/chrome/common/resource_bundle.h
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common/resource_bundle.h')
-rw-r--r--chrome/common/resource_bundle.h104
1 files changed, 60 insertions, 44 deletions
diff --git a/chrome/common/resource_bundle.h b/chrome/common/resource_bundle.h
index 9d7a65f..9feff10 100644
--- a/chrome/common/resource_bundle.h
+++ b/chrome/common/resource_bundle.h
@@ -5,28 +5,27 @@
#ifndef CHROME_COMMON_RESOURCE_BUNDLE_H__
#define CHROME_COMMON_RESOURCE_BUNDLE_H__
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
#include <windows.h>
+#endif
+
#include <map>
#include <string>
#include "base/basictypes.h"
+#include "base/file_path.h"
#include "base/lock.h"
#include "base/scoped_ptr.h"
-#include "chrome/common/ref_counted_util.h"
class ChromeFont;
class SkBitmap;
class StringPiece;
-////////////////////////////////////////////////////////////////////////////////
-//
-// ResourceBundle class
-//
-// ResourceBundle is a central facility to load images and other resources.
-//
-// Every resource is loaded only once
-//
-////////////////////////////////////////////////////////////////////////////////
+// ResourceBundle is a central facility to load images and other resources,
+// such as theme graphics.
+// Every resource is loaded only once.
class ResourceBundle {
public:
// An enumeration of the various font styles used throughout Chrome.
@@ -36,29 +35,29 @@ class ResourceBundle {
SmallFont,
BaseFont,
MediumFont,
- // NOTE: depending upon the locale, this may *not* result in a bold
- // font.
+ // NOTE: depending upon the locale, this may *not* result in a bold font.
MediumBoldFont,
LargeFont,
WebFont
};
- // Initialize the ResrouceBundle for this process.
+ // Initialize the ResourceBundle for this process.
static void InitSharedInstance(const std::wstring& pref_locale);
// Delete the ResourceBundle for this process if it exists.
static void CleanupSharedInstance();
- // Return the global resource loader instance;
+ // Return the global resource loader instance.
static ResourceBundle& GetSharedInstance();
- // Load the dll that contains theme resources if present.
+ // Load the data file that contains theme resources if present.
void LoadThemeResources();
// Gets the bitmap with the specified resource_id, first by looking into the
- // theme dll, than in the current dll. Returns a pointer to a shared instance
- // of the SkBitmap in the given out parameter. This shared bitmap is owned by
- // the resource bundle and should not be freed.
+ // theme data, than in the current module data if applicable.
+ // Returns a pointer to a shared instance of the SkBitmap in the given out
+ // parameter. This shared bitmap is owned by the resource bundle and should
+ // not be freed.
//
// The bitmap is assumed to exist. This function will log in release, and
// assert in debug mode if it does not. On failure, this will return a
@@ -78,23 +77,16 @@ class ResourceBundle {
bool LoadDataResourceBytes(int resource_id,
std::vector<unsigned char>* bytes);
- // Loads and returns an icon from the theme dll.
- HICON LoadThemeIcon(int icon_id);
-
// Return the contents of a file in a string given the resource id.
// This will copy the data from the resource and return it as a string.
+ // TODO(port): deprecate this and replace with GetRawDataResource to avoid
+ // needless copying.
std::string GetDataResource(int resource_id);
// Like GetDataResource(), but avoids copying the resource. Instead, it
// returns a StringPiece which points into the actual resource in the image.
StringPiece GetRawDataResource(int resource_id);
- // Loads and returns the global accelerators.
- HACCEL GetGlobalAccelerators();
-
- // Loads and returns a cursor from the app module.
- HCURSOR LoadCursor(int cursor_id);
-
// Get a localized string given a message id. Returns an empty
// string if the message_id is not found.
std::wstring GetLocalizedString(int message_id);
@@ -102,40 +94,64 @@ class ResourceBundle {
// Returns the font for the specified style.
ChromeFont GetFont(FontStyle style);
- // Creates and returns a new SkBitmap given the dll to look in and the
- // resource id. It's up to the caller to free the returned bitmap when
- // done.
- static SkBitmap* LoadBitmap(HINSTANCE dll_inst, int resource_id);
+#if defined(OS_WIN)
+ // Loads and returns an icon from the theme dll.
+ HICON LoadThemeIcon(int icon_id);
+
+ // Loads and returns the global accelerators.
+ HACCEL GetGlobalAccelerators();
+
+ // Loads and returns a cursor from the app module.
+ HCURSOR LoadCursor(int cursor_id);
+#endif // OS_WIN
private:
+ // We define a DataHandle typedef to abstract across how data is stored
+ // across platforms.
+#if defined(OS_WIN)
+ // Windows stores resources in DLLs, which are managed by HINSTANCE.
+ typedef HINSTANCE DataHandle;
+#elif defined(OS_LINUX)
+ // Linux will use base::DataPack. TODO(evanm): finish this.
+ typedef base::DataPack* DataHandle;
+#endif
+
+ // Ctor/dtor are private, since we're a singleton.
ResourceBundle();
~ResourceBundle();
- // Try to load the locale specific strings from an external DLL.
+ // Free skia_images_.
+ void FreeImages();
+
+ // Try to load the locale specific strings from an external data module.
void LoadLocaleResources(const std::wstring& pref_locale);
+ // Initialize all the ChromeFont members if they haven't yet been initialized.
void LoadFontsIfNecessary();
- // Returns the full pathname of the locale dll to load. May return an empty
- // string if no locale dlls are found.
- std::wstring GetLocaleDllPath(const std::wstring& pref_locale);
+ // Returns the full pathname of the locale file to load. May return an empty
+ // string if no locale data files are found.
+ FilePath GetLocaleFilePath(const std::wstring& pref_locale);
// Loads the raw bytes of a resource from |module| into |bytes|,
// without doing any processing or interpretation of
// the resource. Returns whether we successfully read the resource.
- bool LoadModuleResourceBytes(HINSTANCE module,
- int resource_id,
- std::vector<unsigned char>* bytes);
+ static bool LoadResourceBytes(DataHandle module,
+ int resource_id,
+ std::vector<unsigned char>* bytes);
+
+ // 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
+ // done.
+ static SkBitmap* LoadBitmap(DataHandle dll_inst, int resource_id);
// Class level lock. Used to protect internal data structures that may be
// accessed from other threads (e.g., skia_images_).
Lock lock_;
- std::wstring theme_path_;
-
- // Handle to dlls
- HINSTANCE locale_resources_dll_;
- HINSTANCE theme_dll_;
+ // Handles for data sources.
+ DataHandle locale_resources_data_;
+ DataHandle theme_data_;
// Cached images. The ResourceBundle caches all retrieved bitmaps and keeps
// ownership of the pointers.
@@ -150,7 +166,7 @@ class ResourceBundle {
scoped_ptr<ChromeFont> large_font_;
scoped_ptr<ChromeFont> web_font_;
- static ResourceBundle *g_shared_instance_;
+ static ResourceBundle* g_shared_instance_;
DISALLOW_EVIL_CONSTRUCTORS(ResourceBundle);
};