diff options
author | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 20:26:05 +0000 |
---|---|---|
committer | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-28 20:26:05 +0000 |
commit | 86c008e8a7da9c00c5a676eb201ba5d0c976748e (patch) | |
tree | 8e58aeeab8564a396ccf67807d5bddfcdaa05807 /chrome/common/extensions | |
parent | 5ec8d59c7e79d1a7aae4137051ffc184ec51096c (diff) | |
download | chromium_src-86c008e8a7da9c00c5a676eb201ba5d0c976748e.zip chromium_src-86c008e8a7da9c00c5a676eb201ba5d0c976748e.tar.gz chromium_src-86c008e8a7da9c00c5a676eb201ba5d0c976748e.tar.bz2 |
override chrome:// URLs via extensions.
Overrides are declared in an extension's manifest. The last one installed
wins. However, we keep a list of those installed per page so that priority
is preserved and so that uninstall will revert to a previous state.
Review URL: http://codereview.chromium.org/174277
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24791 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions')
-rw-r--r-- | chrome/common/extensions/extension.cc | 31 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 9 | ||||
-rw-r--r-- | chrome/common/extensions/extension_constants.cc | 3 | ||||
-rw-r--r-- | chrome/common/extensions/extension_constants.h | 2 |
4 files changed, 45 insertions, 0 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index c826c07..3f3c8539 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -998,6 +998,37 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, set_default_locale(default_locale); } + // Chrome URL overrides (optional) + if (source.HasKey(keys::kChromeURLOverrides)) { + DictionaryValue* overrides; + if (!source.GetDictionary(keys::kChromeURLOverrides, &overrides)) { + *error = errors::kInvalidChromeURLOverrides; + return false; + } + // Validate that the overrides are all strings + DictionaryValue::key_iterator iter = overrides->begin_keys(); + while (iter != overrides->end_keys()) { + // For now, only allow the new tab page. Others will work when we remove + // this check, but let's keep it simple for now. + // TODO(erikkay) enable other pages as well + if (WideToUTF8(*iter) != chrome::kChromeUINewTabHost) { + *error = errors::kInvalidChromeURLOverrides; + return false; + } + std::string val; + if (!overrides->GetString(*iter, &val)) { + *error = errors::kInvalidChromeURLOverrides; + return false; + } + // Replace the entry with a fully qualified chrome-extension:// URL. + GURL url = GetResourceURL(val); + overrides->SetString(*iter, url.spec()); + ++iter; + } + chrome_url_overrides_.reset( + static_cast<DictionaryValue*>(overrides->DeepCopy())); + } + return true; } diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 6e7215f..e8cdd10 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -262,6 +262,11 @@ class Extension { default_locale_ = default_locale; } + // Chrome URL overrides (see ExtensionOverrideUI). + DictionaryValue* GetChromeURLOverrides() const { + return chrome_url_overrides_.get(); + } + // Runtime data: // Put dynamic data about the state of a running extension below. @@ -382,6 +387,10 @@ class Extension { // Default locale, used for fallback. std::string default_locale_; + // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs + // which override the handling of those URLs. + scoped_ptr<DictionaryValue> chrome_url_overrides_; + // Runtime data: // True if the background page is ready. diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc index d887678..d72fbcf 100644 --- a/chrome/common/extensions/extension_constants.cc +++ b/chrome/common/extensions/extension_constants.cc @@ -7,6 +7,7 @@ namespace extension_manifest_keys { const wchar_t* kBackground = L"background_page"; +const wchar_t* kChromeURLOverrides = L"chrome_url_overrides"; const wchar_t* kContentScripts = L"content_scripts"; const wchar_t* kCss = L"css"; const wchar_t* kDefaultLocale = L"default_locale"; @@ -52,6 +53,8 @@ const char* kPageActionTypePermanent = "permanent"; // printf because we want to unit test them and scanf is hard to make // cross-platform. namespace extension_manifest_errors { +const char* kInvalidChromeURLOverrides = + "Invalid value for 'chrome_url_overrides'."; const char* kInvalidContentScript = "Invalid value for 'content_scripts[*]'."; const char* kInvalidContentScriptsList = diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h index b808665..09429a2 100644 --- a/chrome/common/extensions/extension_constants.h +++ b/chrome/common/extensions/extension_constants.h @@ -8,6 +8,7 @@ // Keys used in JSON representation of extensions. namespace extension_manifest_keys { extern const wchar_t* kBackground; + extern const wchar_t* kChromeURLOverrides; extern const wchar_t* kContentScripts; extern const wchar_t* kCss; extern const wchar_t* kDefaultLocale; @@ -51,6 +52,7 @@ namespace extension_manifest_values { // Error messages returned from Extension::InitFromValue(). namespace extension_manifest_errors { + extern const char* kInvalidChromeURLOverrides; extern const char* kInvalidContentScript; extern const char* kInvalidContentScriptsList; extern const char* kInvalidCss; |