diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-28 21:09:56 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-28 21:09:56 +0000 |
commit | ba69a7db718bd6815e154b36cead5d0e25d9e45e (patch) | |
tree | 57a415ee022130e50bd27e8346fc02f6d2a238cc /chrome/common | |
parent | d55aaa139da94452ebd6812bfa9241ba050978d9 (diff) | |
download | chromium_src-ba69a7db718bd6815e154b36cead5d0e25d9e45e.zip chromium_src-ba69a7db718bd6815e154b36cead5d0e25d9e45e.tar.gz chromium_src-ba69a7db718bd6815e154b36cead5d0e25d9e45e.tar.bz2 |
Moving ContextualAction class to common/extensions and in the process renaming it ExtensionAction.
No code change.
BUG=None
TEST=Page actions and browser actions should work as before (no change)
Review URL: http://codereview.chromium.org/242035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27406 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/extensions/extension.cc | 28 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 20 | ||||
-rw-r--r-- | chrome/common/extensions/extension_action.cc (renamed from chrome/common/page_action.cc) | 6 | ||||
-rw-r--r-- | chrome/common/extensions/extension_action.h (renamed from chrome/common/page_action.h) | 38 | ||||
-rw-r--r-- | chrome/common/extensions/extension_unittest.cc | 62 |
5 files changed, 77 insertions, 77 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index d68e91f..8aaefa4 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -149,13 +149,13 @@ GURL Extension::GetResourceURL(const GURL& extension_url, return ret_val; } -const ContextualAction* Extension::GetContextualAction( - std::string id, ContextualAction::ContextualActionType action_type) const { - if (action_type == ContextualAction::BROWSER_ACTION) { +const ExtensionAction* Extension::GetExtensionAction( + std::string id, ExtensionAction::ExtensionActionType action_type) const { + if (action_type == ExtensionAction::BROWSER_ACTION) { DCHECK(id.empty()); // Multiple browser actions are not allowed. return browser_action_.get(); } else { - ContextualActionMap::const_iterator it = page_actions_.find(id); + ExtensionActionMap::const_iterator it = page_actions_.find(id); if (it == page_actions_.end()) return NULL; @@ -313,10 +313,10 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, // Helper method that loads a PageAction or BrowserAction object from a // dictionary in the page_actions list or browser_action key of the manifest. -ContextualAction* Extension::LoadContextualActionHelper( +ExtensionAction* Extension::LoadExtensionActionHelper( const DictionaryValue* page_action, int definition_index, - std::string* error, ContextualAction::ContextualActionType action_type) { - scoped_ptr<ContextualAction> result(new ContextualAction()); + std::string* error, ExtensionAction::ExtensionActionType action_type) { + scoped_ptr<ExtensionAction> result(new ExtensionAction()); result->set_extension_id(id()); result->set_type(action_type); @@ -345,7 +345,7 @@ ContextualAction* Extension::LoadContextualActionHelper( ++icon_count; } - if (action_type == ContextualAction::BROWSER_ACTION) { + if (action_type == ExtensionAction::BROWSER_ACTION) { result->set_id(""); // Not needed (only 1 browser action per extension). } else { // Read the page action |id|. @@ -933,9 +933,9 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, return false; } - ContextualAction* contextual_action = - LoadContextualActionHelper(page_action_value, i, error, - ContextualAction::PAGE_ACTION); + ExtensionAction* contextual_action = + LoadExtensionActionHelper(page_action_value, i, error, + ExtensionAction::PAGE_ACTION); if (!contextual_action) return false; // Failed to parse page action definition. page_actions_[contextual_action->id()] = contextual_action; @@ -951,8 +951,8 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, } browser_action_.reset( - LoadContextualActionHelper(browser_action_value, 0, error, - ContextualAction::BROWSER_ACTION)); + LoadExtensionActionHelper(browser_action_value, 0, error, + ExtensionAction::BROWSER_ACTION)); if (!browser_action_.get()) return false; // Failed to parse browser action definition. } @@ -1060,7 +1060,7 @@ std::set<FilePath> Extension::GetBrowserImages() { } // page action icons - for (ContextualActionMap::const_iterator it = page_actions().begin(); + for (ExtensionActionMap::const_iterator it = page_actions().begin(); it != page_actions().end(); ++it) { const std::vector<std::string>& icon_paths = it->second->icon_paths(); for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 6c085ab..af16698 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -15,10 +15,10 @@ #include "base/values.h" #include "base/version.h" #include "chrome/browser/extensions/user_script_master.h" +#include "chrome/common/extensions/extension_action.h" #include "chrome/common/extensions/extension_message_bundle.h" #include "chrome/common/extensions/user_script.h" #include "chrome/common/extensions/url_pattern.h" -#include "chrome/common/page_action.h" #include "googleurl/src/gurl.h" // Represents a Chrome extension. @@ -194,8 +194,8 @@ class Extension { const std::string& public_key() const { return public_key_; } const std::string& description() const { return description_; } const UserScriptList& content_scripts() const { return content_scripts_; } - const ContextualActionMap& page_actions() const { return page_actions_; } - ContextualAction* browser_action() const { return browser_action_.get(); } + const ExtensionActionMap& page_actions() const { return page_actions_; } + ExtensionAction* browser_action() const { return browser_action_.get(); } const std::vector<PrivacyBlacklistInfo>& privacy_blacklists() const { return privacy_blacklists_; } @@ -227,8 +227,8 @@ class Extension { const std::map<int, std::string>& icons() { return icons_; } // Retrieves a page action or browser action by |id|. - const ContextualAction* GetContextualAction( - std::string id, ContextualAction::ContextualActionType action_type) const; + const ExtensionAction* GetExtensionAction( + std::string id, ExtensionAction::ExtensionActionType action_type) const; // Returns the origin of this extension. This function takes a |registry_path| // so that the registry location can be overwritten during testing. @@ -293,13 +293,13 @@ class Extension { std::string* error, UserScript* result); - // Helper method that loads a ContextualAction object from a + // Helper method that loads a ExtensionAction object from a // dictionary in the page_action or browser_action section of the manifest. - ContextualAction* LoadContextualActionHelper( + ExtensionAction* LoadExtensionActionHelper( const DictionaryValue* contextual_action, int definition_index, std::string* error, - ContextualAction::ContextualActionType action_type); + ExtensionAction::ExtensionActionType action_type); // Figures out if a source contains keys not associated with themes - we // don't want to allow scripts and such to be bundled with themes. @@ -335,10 +335,10 @@ class Extension { UserScriptList content_scripts_; // A list of page actions. - ContextualActionMap page_actions_; + ExtensionActionMap page_actions_; // The extension's browser action, if any. - scoped_ptr<ContextualAction> browser_action_; + scoped_ptr<ExtensionAction> browser_action_; // Optional list of privacy blacklistrom. std::vector<PrivacyBlacklistInfo> privacy_blacklists_; diff --git a/chrome/common/page_action.cc b/chrome/common/extensions/extension_action.cc index f2b6f24..2d3291e 100644 --- a/chrome/common/page_action.cc +++ b/chrome/common/extensions/extension_action.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/common/page_action.h" +#include "chrome/common/extensions/extension_action.h" -ContextualAction::ContextualAction() +ExtensionAction::ExtensionAction() : type_(PAGE_ACTION) { } -ContextualAction::~ContextualAction() { +ExtensionAction::~ExtensionAction() { } diff --git a/chrome/common/page_action.h b/chrome/common/extensions/extension_action.h index 8594ace..445f98e 100644 --- a/chrome/common/page_action.h +++ b/chrome/common/extensions/extension_action.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_COMMON_PAGE_ACTION_H_ -#define CHROME_COMMON_PAGE_ACTION_H_ +#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ +#define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ #include <map> #include <string> @@ -11,21 +11,21 @@ #include "base/basictypes.h" -class ContextualAction { +class ExtensionAction { public: - ContextualAction(); - virtual ~ContextualAction(); + ExtensionAction(); + virtual ~ExtensionAction(); typedef enum { PAGE_ACTION = 0, BROWSER_ACTION = 1, - } ContextualActionType; + } ExtensionActionType; std::string id() const { return id_; } void set_id(const std::string& id) { id_ = id; } - ContextualActionType type() const { return type_; } - void set_type(ContextualActionType type) { type_ = type; } + ExtensionActionType type() const { return type_; } + void set_type(ExtensionActionType type) { type_ = type; } std::string extension_id() const { return extension_id_; } void set_extension_id(const std::string& extension_id) { @@ -41,31 +41,31 @@ class ContextualAction { } private: - // The id for the ContextualAction, for example: "RssPageAction". + // The id for the ExtensionAction, for example: "RssPageAction". // For BrowserActions this is blank. std::string id_; - // The type of the ContextualAction, either PageAction or BrowserAction. - ContextualActionType type_; + // The type of the ExtensionAction, either PageAction or BrowserAction. + ExtensionActionType type_; - // The id for the extension this ContextualAction belongs to (as defined in + // The id for the extension this ExtensionAction belongs to (as defined in // the extension manifest). std::string extension_id_; - // The name of the ContextualAction. + // The name of the ExtensionAction. std::string name_; // The paths to the icons that this PageIcon can show. std::vector<std::string> icon_paths_; }; -typedef std::map<std::string, ContextualAction*> ContextualActionMap; +typedef std::map<std::string, ExtensionAction*> ExtensionActionMap; // This class keeps track of what values each tab uses to override the default -// values of the ContextualAction. -class ContextualActionState { +// values of the ExtensionAction. +class ExtensionActionState { public: - ContextualActionState(std::string title, int icon_index) + ExtensionActionState(std::string title, int icon_index) : title_(title), icon_index_(icon_index) { } @@ -79,7 +79,7 @@ class ContextualActionState { // The icon to use. int icon_index_; - DISALLOW_COPY_AND_ASSIGN(ContextualActionState); + DISALLOW_COPY_AND_ASSIGN(ExtensionActionState); }; -#endif // CHROME_COMMON_PAGE_ACTION_H_ +#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc index 6348315..249c719 100644 --- a/chrome/common/extensions/extension_unittest.cc +++ b/chrome/common/extensions/extension_unittest.cc @@ -279,24 +279,24 @@ TEST(ExtensionTest, GetResourceURLAndPath) { TEST(ExtensionTest, LoadPageActionHelper) { Extension extension; std::string error_msg; - scoped_ptr<ContextualAction> action; + scoped_ptr<ExtensionAction> action; DictionaryValue input; // First try with an empty dictionary. We should get nothing back. - ASSERT_EQ(NULL, extension.LoadContextualActionHelper( - &input, 0, &error_msg, ContextualAction::PAGE_ACTION)); + ASSERT_EQ(NULL, extension.LoadExtensionActionHelper( + &input, 0, &error_msg, ExtensionAction::PAGE_ACTION)); ASSERT_STRNE("", error_msg.c_str()); error_msg = ""; // Now try the same, but as a browser action. Ensure same results. - ASSERT_EQ(NULL, extension.LoadContextualActionHelper( - &input, 0, &error_msg, ContextualAction::BROWSER_ACTION)); + ASSERT_EQ(NULL, extension.LoadExtensionActionHelper( + &input, 0, &error_msg, ExtensionAction::BROWSER_ACTION)); ASSERT_STRNE("", error_msg.c_str()); error_msg = ""; // Now setup some values to use in the page action. - const std::string id("MyContextualActionId"); - const std::string name("MyContextualActionName"); + const std::string id("MyExtensionActionId"); + const std::string name("MyExtensionActionName"); std::string img1("image1.png"); std::string img2("image2.png"); @@ -309,8 +309,8 @@ TEST(ExtensionTest, LoadPageActionHelper) { input.Set(keys::kPageActionIcons, icons); // Parse as page action and read back the values from the object. - action.reset(extension.LoadContextualActionHelper( - &input, 0, &error_msg, ContextualAction::PAGE_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + &input, 0, &error_msg, ExtensionAction::PAGE_ACTION)); ASSERT_TRUE(NULL != action.get()); ASSERT_STREQ("", error_msg.c_str()); ASSERT_STREQ(id.c_str(), action->id().c_str()); @@ -318,11 +318,11 @@ TEST(ExtensionTest, LoadPageActionHelper) { ASSERT_EQ(2u, action->icon_paths().size()); ASSERT_STREQ(img1.c_str(), action->icon_paths()[0].c_str()); ASSERT_STREQ(img2.c_str(), action->icon_paths()[1].c_str()); - ASSERT_EQ(ContextualAction::PAGE_ACTION, action->type()); + ASSERT_EQ(ExtensionAction::PAGE_ACTION, action->type()); // Now try the same, but as a browser action. - action.reset(extension.LoadContextualActionHelper( - &input, 0, &error_msg, ContextualAction::BROWSER_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + &input, 0, &error_msg, ExtensionAction::BROWSER_ACTION)); ASSERT_TRUE(NULL != action.get()); ASSERT_STREQ("", error_msg.c_str()); // Browser actions don't have an id, page actions do. @@ -331,23 +331,23 @@ TEST(ExtensionTest, LoadPageActionHelper) { ASSERT_EQ(2u, action->icon_paths().size()); ASSERT_STREQ(img1.c_str(), action->icon_paths()[0].c_str()); ASSERT_STREQ(img2.c_str(), action->icon_paths()[1].c_str()); - ASSERT_EQ(ContextualAction::BROWSER_ACTION, action->type()); + ASSERT_EQ(ExtensionAction::BROWSER_ACTION, action->type()); // Explicitly set the same type and parse again. input.SetString(keys::kType, values::kPageActionTypeTab); - action.reset(extension.LoadContextualActionHelper( - &input, 0, &error_msg, ContextualAction::BROWSER_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + &input, 0, &error_msg, ExtensionAction::BROWSER_ACTION)); ASSERT_TRUE(NULL != action.get()); ASSERT_STREQ("", error_msg.c_str()); - ASSERT_EQ(ContextualAction::BROWSER_ACTION, action->type()); + ASSERT_EQ(ExtensionAction::BROWSER_ACTION, action->type()); // Explicitly set the PAGE_ACTION type and parse again. input.SetString(keys::kType, values::kPageActionTypePermanent); - action.reset(extension.LoadContextualActionHelper( - &input, 0, &error_msg, ContextualAction::PAGE_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + &input, 0, &error_msg, ExtensionAction::PAGE_ACTION)); ASSERT_TRUE(NULL != action.get()); ASSERT_STREQ("", error_msg.c_str()); - ASSERT_EQ(ContextualAction::PAGE_ACTION, action->type()); + ASSERT_EQ(ExtensionAction::PAGE_ACTION, action->type()); // Make a deep copy of the input and remove one key at a time and see if we // get the right error. @@ -356,8 +356,8 @@ TEST(ExtensionTest, LoadPageActionHelper) { // First remove id key. copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); copy->Remove(keys::kPageActionId, NULL); - action.reset(extension.LoadContextualActionHelper( - copy.get(), 0, &error_msg, ContextualAction::PAGE_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + copy.get(), 0, &error_msg, ExtensionAction::PAGE_ACTION)); ASSERT_TRUE(NULL == action.get()); ASSERT_TRUE(MatchPattern(error_msg.c_str(), errors::kInvalidPageActionId)); @@ -366,8 +366,8 @@ TEST(ExtensionTest, LoadPageActionHelper) { // Same test (id key), but with browser action. copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); copy->Remove(keys::kPageActionId, NULL); - action.reset(extension.LoadContextualActionHelper( - copy.get(), 0, &error_msg, ContextualAction::BROWSER_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + copy.get(), 0, &error_msg, ExtensionAction::BROWSER_ACTION)); // Having no id is valid for browser actions. ASSERT_TRUE(NULL != action.get()); ASSERT_STREQ("", error_msg.c_str()); @@ -376,8 +376,8 @@ TEST(ExtensionTest, LoadPageActionHelper) { // Then remove the name key. copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); copy->Remove(keys::kName, NULL); - action.reset(extension.LoadContextualActionHelper( - copy.get(), 0, &error_msg, ContextualAction::PAGE_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + copy.get(), 0, &error_msg, ExtensionAction::PAGE_ACTION)); ASSERT_TRUE(NULL == action.get()); ASSERT_TRUE(MatchPattern(error_msg.c_str(), errors::kInvalidName)); @@ -386,8 +386,8 @@ TEST(ExtensionTest, LoadPageActionHelper) { // Same test (name key), but with browser action. copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); copy->Remove(keys::kName, NULL); - action.reset(extension.LoadContextualActionHelper( - copy.get(), 0, &error_msg, ContextualAction::BROWSER_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + copy.get(), 0, &error_msg, ExtensionAction::BROWSER_ACTION)); ASSERT_TRUE(NULL == action.get()); ASSERT_TRUE(MatchPattern(error_msg.c_str(), errors::kInvalidName)); @@ -396,8 +396,8 @@ TEST(ExtensionTest, LoadPageActionHelper) { // Then remove the icon paths key. copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); copy->Remove(keys::kPageActionIcons, NULL); - action.reset(extension.LoadContextualActionHelper( - copy.get(), 0, &error_msg, ContextualAction::PAGE_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + copy.get(), 0, &error_msg, ExtensionAction::PAGE_ACTION)); ASSERT_TRUE(NULL == action.get()); ASSERT_TRUE(MatchPattern(error_msg.c_str(), errors::kInvalidPageActionIconPaths)); @@ -406,8 +406,8 @@ TEST(ExtensionTest, LoadPageActionHelper) { // Same test (name key), but with browser action. copy.reset(static_cast<DictionaryValue*>(input.DeepCopy())); copy->Remove(keys::kPageActionIcons, NULL); - action.reset(extension.LoadContextualActionHelper( - copy.get(), 0, &error_msg, ContextualAction::BROWSER_ACTION)); + action.reset(extension.LoadExtensionActionHelper( + copy.get(), 0, &error_msg, ExtensionAction::BROWSER_ACTION)); ASSERT_TRUE(NULL == action.get()); ASSERT_TRUE(MatchPattern(error_msg.c_str(), errors::kInvalidPageActionIconPaths)); |