diff options
author | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-30 00:01:18 +0000 |
---|---|---|
committer | yoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-30 00:01:18 +0000 |
commit | ce613ba0d5d3bc17cd55d582d4c3ad4667bee57e (patch) | |
tree | cb6ba45b8d889ed57152884222586dd4ff47bb72 /chrome/common/extensions/api/extension_action | |
parent | a9d2b465d3985155361fbe92cd4e239050b96f05 (diff) | |
download | chromium_src-ce613ba0d5d3bc17cd55d582d4c3ad4667bee57e.zip chromium_src-ce613ba0d5d3bc17cd55d582d4c3ad4667bee57e.tar.gz chromium_src-ce613ba0d5d3bc17cd55d582d4c3ad4667bee57e.tar.bz2 |
Change ManifestHandler interface to always (implicitly) pass the entire manifest to handlers.
This makes it possible to support multi-key handlers using the same interface.
Fixes a bug with default behavior for manifest handlers; previously, HasNoKey would be called even for inappropriate extension types.
BUG=159265
Review URL: https://chromiumcodereview.appspot.com/12084034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179470 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/api/extension_action')
5 files changed, 22 insertions, 20 deletions
diff --git a/chrome/common/extensions/api/extension_action/browser_action_handler.cc b/chrome/common/extensions/api/extension_action/browser_action_handler.cc index 45ec188..b5ab1db 100644 --- a/chrome/common/extensions/api/extension_action/browser_action_handler.cc +++ b/chrome/common/extensions/api/extension_action/browser_action_handler.cc @@ -11,6 +11,7 @@ #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_manifest_constants.h" #include "chrome/common/extensions/feature_switch.h" +#include "chrome/common/extensions/manifest.h" #include "chrome/common/extensions/manifest_handler_helpers.h" namespace extensions { @@ -21,11 +22,11 @@ BrowserActionHandler::BrowserActionHandler() { BrowserActionHandler::~BrowserActionHandler() { } -bool BrowserActionHandler::Parse(const base::Value* value, - Extension* extension, +bool BrowserActionHandler::Parse(Extension* extension, string16* error) { const DictionaryValue* dict = NULL; - if (!value->GetAsDictionary(&dict)) { + if (!extension->manifest()->GetDictionary( + extension_manifest_keys::kBrowserAction, &dict)) { *error = ASCIIToUTF16(extension_manifest_errors::kInvalidBrowserAction); return false; } diff --git a/chrome/common/extensions/api/extension_action/browser_action_handler.h b/chrome/common/extensions/api/extension_action/browser_action_handler.h index e979445..e204a22 100644 --- a/chrome/common/extensions/api/extension_action/browser_action_handler.h +++ b/chrome/common/extensions/api/extension_action/browser_action_handler.h @@ -19,9 +19,7 @@ class BrowserActionHandler : public ManifestHandler { BrowserActionHandler(); virtual ~BrowserActionHandler(); - virtual bool Parse(const base::Value* value, - Extension* extension, - string16* error) OVERRIDE; + virtual bool Parse(Extension* extension, string16* error) OVERRIDE; }; } // namespace extensions diff --git a/chrome/common/extensions/api/extension_action/script_badge_handler.cc b/chrome/common/extensions/api/extension_action/script_badge_handler.cc index f68d4a8..17f1c10 100644 --- a/chrome/common/extensions/api/extension_action/script_badge_handler.cc +++ b/chrome/common/extensions/api/extension_action/script_badge_handler.cc @@ -11,6 +11,7 @@ #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_manifest_constants.h" #include "chrome/common/extensions/feature_switch.h" +#include "chrome/common/extensions/manifest.h" #include "chrome/common/extensions/manifest_handler_helpers.h" namespace errors = extension_manifest_errors; @@ -23,11 +24,16 @@ ScriptBadgeHandler::ScriptBadgeHandler() { ScriptBadgeHandler::~ScriptBadgeHandler() { } -bool ScriptBadgeHandler::Parse(const base::Value* value, - Extension* extension, - string16* error) { +bool ScriptBadgeHandler::Parse(Extension* extension, string16* error) { scoped_ptr<ActionInfo> action_info(new ActionInfo); + // Provide a default script badge if one isn't declared in the manifest. + if (!extension->manifest()->HasKey(extension_manifest_keys::kScriptBadge)) { + SetActionInfoDefaults(extension, action_info.get()); + ActionInfo::SetScriptBadgeInfo(extension, action_info.release()); + return true; + } + // So as to not confuse developers if they specify a script badge section // in the manifest, show a warning if the script badge declaration isn't // going to have any effect. @@ -38,8 +44,9 @@ bool ScriptBadgeHandler::Parse(const base::Value* value, } const DictionaryValue* dict = NULL; - if (!value->GetAsDictionary(&dict)) { - *error = ASCIIToUTF16(extension_manifest_errors::kInvalidScriptBadge); + if (!extension->manifest()->GetDictionary( + extension_manifest_keys::kScriptBadge, &dict)) { + *error = ASCIIToUTF16(errors::kInvalidScriptBadge); return false; } @@ -72,11 +79,8 @@ bool ScriptBadgeHandler::Parse(const base::Value* value, return true; } -bool ScriptBadgeHandler::HasNoKey(Extension* extension, string16* error) { - scoped_ptr<ActionInfo> action_info(new ActionInfo); - SetActionInfoDefaults(extension, action_info.get()); - ActionInfo::SetScriptBadgeInfo(extension, action_info.release()); - return true; +bool ScriptBadgeHandler::AlwaysParseForType(Extension::Type type) { + return type == Extension::TYPE_EXTENSION; } void ScriptBadgeHandler::SetActionInfoDefaults(const Extension* extension, diff --git a/chrome/common/extensions/api/extension_action/script_badge_handler.h b/chrome/common/extensions/api/extension_action/script_badge_handler.h index 2691d62..90faf9a 100644 --- a/chrome/common/extensions/api/extension_action/script_badge_handler.h +++ b/chrome/common/extensions/api/extension_action/script_badge_handler.h @@ -19,11 +19,9 @@ class ScriptBadgeHandler : public ManifestHandler { ScriptBadgeHandler(); virtual ~ScriptBadgeHandler(); - virtual bool Parse(const base::Value* value, - Extension* extension, - string16* error) OVERRIDE; + virtual bool Parse(Extension* extension, string16* error) OVERRIDE; + virtual bool AlwaysParseForType(Extension::Type type) OVERRIDE; - virtual bool HasNoKey(Extension* extension, string16* error) OVERRIDE; private: // Sets the fields of ActionInfo to the default values, matching the parent // extension's title and icons. Performed whether or not the script_badge key diff --git a/chrome/common/extensions/api/extension_action/script_badge_manifest_unittest.cc b/chrome/common/extensions/api/extension_action/script_badge_manifest_unittest.cc index 98b5f17..2133579 100644 --- a/chrome/common/extensions/api/extension_action/script_badge_manifest_unittest.cc +++ b/chrome/common/extensions/api/extension_action/script_badge_manifest_unittest.cc @@ -8,6 +8,7 @@ #include "chrome/common/extensions/extension_constants.h" #include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/extension_manifest_constants.h" +#include "chrome/common/extensions/feature_switch.h" #include "chrome/common/extensions/manifest_handler.h" #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" #include "testing/gmock/include/gmock/gmock.h" |