Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2196)

Unified Diff: chrome/common/extensions/extension.cc

Issue 545068: Allow extensions to add, remove, or change their page action popup. (Closed)
Patch Set: Rebase, to run trybots with test data in place. Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index f6de4ab2f7f4af0f9817959fb62aa0866102328c..4b2992d9eb85df2e351e04b697209811b6d7319e 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -436,36 +436,55 @@ ExtensionAction* Extension::LoadExtensionActionHelper(
result->SetTitle(ExtensionAction::kDefaultTabId, title);
// Read the action's |popup| (optional).
- DictionaryValue* popup = NULL;
- std::string url_str;
- if (extension_action->HasKey(keys::kPageActionPopup) &&
- !extension_action->GetDictionary(keys::kPageActionPopup, &popup) &&
- !extension_action->GetString(keys::kPageActionPopup, &url_str)) {
- *error = errors::kInvalidPageActionPopup;
- return NULL;
- }
- if (popup) {
- // TODO(EXTENSIONS_DEPRECATED): popup is a string only
- if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) {
+ const wchar_t* popup_key = NULL;
+ if (extension_action->HasKey(keys::kPageActionDefaultPopup))
+ popup_key = keys::kPageActionDefaultPopup;
+
+ // For backward compatibility, alias old key "popup" to new
+ // key "default_popup".
+ if (extension_action->HasKey(keys::kPageActionPopup)) {
+ if (popup_key) {
*error = ExtensionErrorUtils::FormatErrorMessage(
- errors::kInvalidPageActionPopupPath, "<missing>");
+ errors::kInvalidPageActionOldAndNewKeys,
+ WideToASCII(keys::kPageActionDefaultPopup),
+ WideToASCII(keys::kPageActionPopup));
return NULL;
}
- GURL url = GetResourceURL(url_str);
- if (!url.is_valid()) {
- *error = ExtensionErrorUtils::FormatErrorMessage(
- errors::kInvalidPageActionPopupPath, url_str);
+ popup_key = keys::kPageActionPopup;
+ }
+
+ if (popup_key) {
+ DictionaryValue* popup = NULL;
+ std::string url_str;
+
+ if (extension_action->GetString(popup_key, &url_str)) {
+ // On success, |url_str| is set. Nothing else to do.
+ } else if (extension_action->GetDictionary(popup_key, &popup)) {
+ // TODO(EXTENSIONS_DEPRECATED): popup is now a string only.
+ // Support the old dictionary format for backward compatibility.
+ if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ errors::kInvalidPageActionPopupPath, "<missing>");
+ return NULL;
+ }
+ } else {
+ *error = errors::kInvalidPageActionPopup;
return NULL;
}
- result->SetPopupUrl(ExtensionAction::kDefaultTabId, url);
- } else if (!url_str.empty()) {
- GURL url = GetResourceURL(url_str);
- if (!url.is_valid()) {
- *error = ExtensionErrorUtils::FormatErrorMessage(
- errors::kInvalidPageActionPopupPath, url_str);
- return NULL;
+
+ if (!url_str.empty()) {
+ // An empty string is treated as having no popup.
+ GURL url = GetResourceURL(url_str);
+ if (!url.is_valid()) {
+ *error = ExtensionErrorUtils::FormatErrorMessage(
+ errors::kInvalidPageActionPopupPath, url_str);
+ return NULL;
+ }
+ result->SetPopupUrl(ExtensionAction::kDefaultTabId, url);
+ } else {
+ DCHECK(!result->HasPopup(ExtensionAction::kDefaultTabId))
+ << "Shouldn't be posible for the popup to be set.";
}
- result->SetPopupUrl(ExtensionAction::kDefaultTabId, url);
}
return result.release();
« no previous file with comments | « chrome/common/extensions/docs/static/pageAction.html ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698