From ba69a7db718bd6815e154b36cead5d0e25d9e45e Mon Sep 17 00:00:00 2001 From: "finnur@chromium.org" Date: Mon, 28 Sep 2009 21:09:56 +0000 Subject: 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 --- chrome/common/extensions/extension.cc | 28 ++++----- chrome/common/extensions/extension.h | 20 +++--- chrome/common/extensions/extension_action.cc | 12 ++++ chrome/common/extensions/extension_action.h | 85 ++++++++++++++++++++++++++ chrome/common/extensions/extension_unittest.cc | 62 +++++++++---------- chrome/common/page_action.cc | 12 ---- chrome/common/page_action.h | 85 -------------------------- 7 files changed, 152 insertions(+), 152 deletions(-) create mode 100644 chrome/common/extensions/extension_action.cc create mode 100644 chrome/common/extensions/extension_action.h delete mode 100644 chrome/common/page_action.cc delete mode 100644 chrome/common/page_action.h (limited to 'chrome/common') 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 result(new ContextualAction()); + std::string* error, ExtensionAction::ExtensionActionType action_type) { + scoped_ptr 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 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& icon_paths = it->second->icon_paths(); for (std::vector::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& privacy_blacklists() const { return privacy_blacklists_; } @@ -227,8 +227,8 @@ class Extension { const std::map& 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 browser_action_; + scoped_ptr browser_action_; // Optional list of privacy blacklistrom. std::vector privacy_blacklists_; diff --git a/chrome/common/extensions/extension_action.cc b/chrome/common/extensions/extension_action.cc new file mode 100644 index 0000000..2d3291e --- /dev/null +++ b/chrome/common/extensions/extension_action.cc @@ -0,0 +1,12 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/extensions/extension_action.h" + +ExtensionAction::ExtensionAction() + : type_(PAGE_ACTION) { +} + +ExtensionAction::~ExtensionAction() { +} diff --git a/chrome/common/extensions/extension_action.h b/chrome/common/extensions/extension_action.h new file mode 100644 index 0000000..445f98e --- /dev/null +++ b/chrome/common/extensions/extension_action.h @@ -0,0 +1,85 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ +#define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ + +#include +#include +#include + +#include "base/basictypes.h" + +class ExtensionAction { + public: + ExtensionAction(); + virtual ~ExtensionAction(); + + typedef enum { + PAGE_ACTION = 0, + BROWSER_ACTION = 1, + } ExtensionActionType; + + std::string id() const { return id_; } + void set_id(const std::string& id) { id_ = id; } + + 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) { + extension_id_ = extension_id; + } + + std::string name() const { return name_; } + void set_name(const std::string& name) { name_ = name; } + + const std::vector& icon_paths() const { return icon_paths_; } + void AddIconPath(const std::string& icon_path) { + icon_paths_.push_back(icon_path); + } + + private: + // The id for the ExtensionAction, for example: "RssPageAction". + // For BrowserActions this is blank. + std::string id_; + + // The type of the ExtensionAction, either PageAction or BrowserAction. + ExtensionActionType type_; + + // The id for the extension this ExtensionAction belongs to (as defined in + // the extension manifest). + std::string extension_id_; + + // The name of the ExtensionAction. + std::string name_; + + // The paths to the icons that this PageIcon can show. + std::vector icon_paths_; +}; + +typedef std::map ExtensionActionMap; + +// This class keeps track of what values each tab uses to override the default +// values of the ExtensionAction. +class ExtensionActionState { + public: + ExtensionActionState(std::string title, int icon_index) + : title_(title), icon_index_(icon_index) { + } + + std::string title() const { return title_; } + int icon_index() const { return icon_index_; } + + private: + // The title to use. + std::string title_; + + // The icon to use. + int icon_index_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionActionState); +}; + +#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 action; + scoped_ptr 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(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(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(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(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(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(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)); diff --git a/chrome/common/page_action.cc b/chrome/common/page_action.cc deleted file mode 100644 index f2b6f24..0000000 --- a/chrome/common/page_action.cc +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// 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" - -ContextualAction::ContextualAction() - : type_(PAGE_ACTION) { -} - -ContextualAction::~ContextualAction() { -} diff --git a/chrome/common/page_action.h b/chrome/common/page_action.h deleted file mode 100644 index 8594ace..0000000 --- a/chrome/common/page_action.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// 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_ - -#include -#include -#include - -#include "base/basictypes.h" - -class ContextualAction { - public: - ContextualAction(); - virtual ~ContextualAction(); - - typedef enum { - PAGE_ACTION = 0, - BROWSER_ACTION = 1, - } ContextualActionType; - - 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; } - - std::string extension_id() const { return extension_id_; } - void set_extension_id(const std::string& extension_id) { - extension_id_ = extension_id; - } - - std::string name() const { return name_; } - void set_name(const std::string& name) { name_ = name; } - - const std::vector& icon_paths() const { return icon_paths_; } - void AddIconPath(const std::string& icon_path) { - icon_paths_.push_back(icon_path); - } - - private: - // The id for the ContextualAction, for example: "RssPageAction". - // For BrowserActions this is blank. - std::string id_; - - // The type of the ContextualAction, either PageAction or BrowserAction. - ContextualActionType type_; - - // The id for the extension this ContextualAction belongs to (as defined in - // the extension manifest). - std::string extension_id_; - - // The name of the ContextualAction. - std::string name_; - - // The paths to the icons that this PageIcon can show. - std::vector icon_paths_; -}; - -typedef std::map ContextualActionMap; - -// This class keeps track of what values each tab uses to override the default -// values of the ContextualAction. -class ContextualActionState { - public: - ContextualActionState(std::string title, int icon_index) - : title_(title), icon_index_(icon_index) { - } - - std::string title() const { return title_; } - int icon_index() const { return icon_index_; } - - private: - // The title to use. - std::string title_; - - // The icon to use. - int icon_index_; - - DISALLOW_COPY_AND_ASSIGN(ContextualActionState); -}; - -#endif // CHROME_COMMON_PAGE_ACTION_H_ -- cgit v1.1