From 2d8d923da42df61e9d65942945456d4b9304ef8e Mon Sep 17 00:00:00 2001 From: "erikkay@chromium.org" Date: Fri, 2 Oct 2009 20:19:20 +0000 Subject: Add simple popup support to browser actions. This will create a popup HTML window that extends below a browser action button when the browser is clicked. When it loses focus, it is automatically dismissed. BUG=23596 TEST=none Review URL: http://codereview.chromium.org/258011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27889 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/common/extensions/extension.cc | 31 +++++++++++++++++++++++++ chrome/common/extensions/extension_action.h | 11 +++++++++ chrome/common/extensions/extension_constants.cc | 9 +++++++ chrome/common/extensions/extension_constants.h | 6 +++++ 4 files changed, 57 insertions(+) (limited to 'chrome/common/extensions') diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 9760efe..2ac504e 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -372,6 +372,37 @@ ExtensionAction* Extension::LoadExtensionActionHelper( } result->set_name(name); + // Read the action's |popup| (optional). + DictionaryValue* popup = NULL; + if (page_action->HasKey(keys::kPageActionPopup) && + !page_action->GetDictionary(keys::kPageActionPopup, &popup)) { + *error = errors::kInvalidPageActionPopup; + return NULL; + } + if (popup) { + std::string url_str; + if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) { + *error = ExtensionErrorUtils::FormatErrorMessage( + errors::kInvalidPageActionPopupPath, ""); + return NULL; + } + GURL url = GetResourceURL(url_str); + if (!url.is_valid()) { + *error = ExtensionErrorUtils::FormatErrorMessage( + errors::kInvalidPageActionPopupPath, url_str); + return NULL; + } + result->set_popup_url(url); + + int height; + if (!popup->GetInteger(keys::kPageActionPopupHeight, &height)) { + *error = ExtensionErrorUtils::FormatErrorMessage( + errors::kInvalidPageActionPopupHeight, ""); + return NULL; + } + result->set_popup_height(height); + } + return result.release(); } diff --git a/chrome/common/extensions/extension_action.h b/chrome/common/extensions/extension_action.h index f091487..630671c 100644 --- a/chrome/common/extensions/extension_action.h +++ b/chrome/common/extensions/extension_action.h @@ -10,6 +10,7 @@ #include #include "base/basictypes.h" +#include "googleurl/src/gurl.h" class ExtensionAction { public: @@ -42,6 +43,12 @@ class ExtensionAction { icon_paths_.push_back(icon_path); } + const GURL& popup_url() const { return popup_url_; } + void set_popup_url(const GURL& url) { popup_url_ = url; } + + const int popup_height() const { return popup_height_; } + void set_popup_height(int height) { popup_height_ = height; } + private: static int next_command_id_; @@ -65,6 +72,10 @@ class ExtensionAction { // An integer for use with the browser's command system. These should always // be in the range [IDC_BROWSER_ACTION_FIRST, IDC_BROWSER_ACTION_LAST]. int command_id_; + + // If the action has a popup, it has a URL and a height. + GURL popup_url_; + int popup_height_; }; typedef std::map ExtensionActionMap; diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc index 8281d42..228197b 100644 --- a/chrome/common/extensions/extension_constants.cc +++ b/chrome/common/extensions/extension_constants.cc @@ -20,6 +20,9 @@ const wchar_t* kName = L"name"; const wchar_t* kPageActionId = L"id"; const wchar_t* kPageActions = L"page_actions"; const wchar_t* kPageActionIcons = L"icons"; +const wchar_t* kPageActionPopup = L"popup"; +const wchar_t* kPageActionPopupHeight = L"height"; +const wchar_t* kPageActionPopupPath = L"path"; const wchar_t* kPermissions = L"permissions"; const wchar_t* kPlugins = L"plugins"; const wchar_t* kPluginsPath = L"path"; @@ -99,6 +102,12 @@ const char* kInvalidPageActionIconPaths = "Required value 'page_actions[*].icons' is missing or invalid."; const char* kInvalidPageActionId = "Required value 'id' is missing or invalid."; +const char* kInvalidPageActionPopup = + "Invalid type for page action popup."; +const char* kInvalidPageActionPopupHeight = + "Invalid value for page action popup height [*]."; +const char* kInvalidPageActionPopupPath = + "Invalid value for page action popup path [*]."; const char* kInvalidPageActionTypeValue = "Invalid value for 'page_actions[*].type', expected 'tab' or 'permanent'."; const char* kInvalidPermissions = diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h index 8b321b6..125a47f 100644 --- a/chrome/common/extensions/extension_constants.h +++ b/chrome/common/extensions/extension_constants.h @@ -21,6 +21,9 @@ namespace extension_manifest_keys { extern const wchar_t* kPageActionId; extern const wchar_t* kPageActions; extern const wchar_t* kPageActionIcons; + extern const wchar_t* kPageActionPopup; + extern const wchar_t* kPageActionPopupHeight; + extern const wchar_t* kPageActionPopupPath; extern const wchar_t* kPermissions; extern const wchar_t* kPlugins; extern const wchar_t* kPluginsPath; @@ -87,6 +90,9 @@ namespace extension_manifest_errors { extern const char* kInvalidPageActionIconPath; extern const char* kInvalidPageActionIconPaths; extern const char* kInvalidPageActionId; + extern const char* kInvalidPageActionPopup; + extern const char* kInvalidPageActionPopupHeight; + extern const char* kInvalidPageActionPopupPath; extern const char* kInvalidPageActionTypeValue; extern const char* kInvalidPermissions; extern const char* kInvalidPermission; -- cgit v1.1