summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-04 20:27:04 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-04 20:27:04 +0000
commit07c00d99969c6584079c78a2e31cb0d5ad5beda7 (patch)
tree84243fe741c02a76214c76cf5bfa2bb0fe93f670 /chrome/browser/extensions
parent1b1e520d728ae8f53b944322fcfddab929aad70f (diff)
downloadchromium_src-07c00d99969c6584079c78a2e31cb0d5ad5beda7.zip
chromium_src-07c00d99969c6584079c78a2e31cb0d5ad5beda7.tar.gz
chromium_src-07c00d99969c6584079c78a2e31cb0d5ad5beda7.tar.bz2
Add trivial theming support in extensions.
NOTE: This is not final API. It *will* change. It's purely for testing purposes. Review URL: http://codereview.chromium.org/40042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10913 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/extension.cc39
-rw-r--r--chrome/browser/extensions/extension.h19
2 files changed, 55 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc
index 918268f..44635c5 100644
--- a/chrome/browser/extensions/extension.cc
+++ b/chrome/browser/extensions/extension.cc
@@ -9,6 +9,7 @@
#include "base/string_util.h"
#include "net/base/net_util.h"
#include "chrome/common/extensions/user_script.h"
+#include "chrome/common/resource_bundle.h"
#include "chrome/common/url_constants.h"
const char Extension::kManifestFilename[] = "manifest.json";
@@ -24,6 +25,7 @@ const wchar_t* Extension::kRunAtKey = L"run_at";
const wchar_t* Extension::kVersionKey = L"version";
const wchar_t* Extension::kZipHashKey = L"zip_hash";
const wchar_t* Extension::kPluginsDirKey = L"plugins_dir";
+const wchar_t* Extension::kThemeKey = L"theme";
const char* Extension::kRunAtDocumentStartValue = "document_start";
const char* Extension::kRunAtDocumentEndValue = "document_end";
@@ -71,6 +73,19 @@ const char* Extension::kInvalidPluginsDirError =
const size_t Extension::kIdSize = 20; // SHA1 (160 bits) == 20 bytes
+Extension::Extension(const Extension& rhs) :
+ path_(rhs.path_),
+ extension_url_(rhs.extension_url_),
+ id_(rhs.id_),
+ version_(new Version(*rhs.version_)),
+ name_(rhs.name_),
+ description_(rhs.description_),
+ content_scripts_(rhs.content_scripts_),
+ plugins_dir_(rhs.plugins_dir_),
+ zip_hash_(rhs.zip_hash_),
+ theme_paths_(rhs.theme_paths_) {
+}
+
const std::string Extension::VersionString() const {
return version_->GetString();
}
@@ -87,6 +102,14 @@ GURL Extension::GetResourceURL(const GURL& extension_url,
return ret_val;
}
+FilePath Extension::GetThemeResourcePath(const int resource_id) {
+ std::wstring id = IntToWString(resource_id);
+ std::string path = theme_paths_[id];
+ if (path.size())
+ return path_.AppendASCII(path.c_str());
+ return FilePath();
+}
+
// static
FilePath Extension::GetResourcePath(const FilePath& extension_path,
const std::string& relative_path) {
@@ -237,6 +260,22 @@ bool Extension::InitFromValue(const DictionaryValue& source,
plugins_dir_ = path_.AppendASCII(plugins_dir);
}
+ if (source.HasKey(kThemeKey)) {
+ DictionaryValue* dict_value;
+ if (source.GetDictionary(kThemeKey, &dict_value)) {
+ DictionaryValue::key_iterator iter = dict_value->begin_keys();
+ while (iter != dict_value->end_keys()) {
+ std::string val;
+ if (dict_value->GetString(*iter, &val)) {
+ std::wstring id = *iter;
+ theme_paths_[id] = val;
+ }
+ ++iter;
+ }
+ ResourceBundle::GetSharedInstance().SetThemeExtension(*this);
+ }
+ }
+
// Initialize content scripts (optional).
if (source.HasKey(kContentScriptsKey)) {
ListValue* list_value;
diff --git a/chrome/browser/extensions/extension.h b/chrome/browser/extensions/extension.h
index 095e7bd..5ca86d3 100644
--- a/chrome/browser/extensions/extension.h
+++ b/chrome/browser/extensions/extension.h
@@ -21,6 +21,7 @@ class Extension {
public:
Extension() {}
explicit Extension(const FilePath& path);
+ explicit Extension(const Extension& path);
// The format for extension manifests that this code understands.
static const unsigned int kExpectedFormatVersion = 1;
@@ -40,6 +41,7 @@ class Extension {
static const wchar_t* kVersionKey;
static const wchar_t* kZipHashKey;
static const wchar_t* kPluginsDirKey;
+ static const wchar_t* kThemeKey;
// Some values expected in manifests.
static const char* kRunAtDocumentStartValue;
@@ -67,7 +69,7 @@ class Extension {
// The number of bytes in a legal id.
static const size_t kIdSize;
- // Creates an absolute url to a resource inside an extension. The
+ // Returns an absolute url to a resource inside of an extension. The
// |extension_url| argument should be the url() from an Extension object. The
// |relative_path| can be untrusted user input. The returned URL will either
// be invalid() or a child of |extension_url|.
@@ -75,7 +77,7 @@ class Extension {
static GURL GetResourceURL(const GURL& extension_url,
const std::string& relative_path);
- // Creates an absolute path to a resource inside an extension. The
+ // Returns an absolute path to a resource inside of an extension. The
// |extension_path| argument should be the path() from an Extension object.
// The |relative_path| can be untrusted user input. The returned path will
// either be empty or a child of extension_path.
@@ -83,6 +85,13 @@ class Extension {
static FilePath GetResourcePath(const FilePath& extension_path,
const std::string& relative_path);
+ // Returns an absolute path to a resource inside of an extension if the
+ // extension has a theme defined with the given |resource_id|. Otherwise
+ // the path will be empty. Note that this method is not static as it is
+ // only intended to be called on an extension which has registered itself
+ // as providing a theme.
+ FilePath GetThemeResourcePath(const int resource_id);
+
// The path to the folder the extension is stored in.
const FilePath& path() const { return path_; }
@@ -152,7 +161,11 @@ class Extension {
// will not have this key.
std::string zip_hash_;
- DISALLOW_COPY_AND_ASSIGN(Extension);
+ // A map of resource id's to relative file paths.
+ std::map<const std::wstring, std::string> theme_paths_;
+
+ // We implement copy, but not assign.
+ void operator=(const Extension&);
};
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_H_