Chromium Code Reviews| Index: chrome/common/extensions/extension.cc |
| diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc |
| index 7db7ca6aefc4ca0839a434beeac07cc7cd8badab..4dc67c60743e1b76cc6243ff987364a4d5a59ae4 100644 |
| --- a/chrome/common/extensions/extension.cc |
| +++ b/chrome/common/extensions/extension.cc |
| @@ -801,7 +801,9 @@ bool Extension::LoadGlobsHelper( |
| } |
| scoped_ptr<ExtensionAction> Extension::LoadExtensionActionHelper( |
| - const DictionaryValue* extension_action, string16* error) { |
| + const DictionaryValue* extension_action, |
| + ExtensionAction::Type action_type, |
| + string16* error) { |
| scoped_ptr<ExtensionAction> result(new ExtensionAction(id())); |
| // Page actions are hidden by default, and browser actions ignore |
| @@ -837,6 +839,10 @@ scoped_ptr<ExtensionAction> Extension::LoadExtensionActionHelper( |
| std::string default_icon; |
| // Read the page action |default_icon| (optional). |
| if (extension_action->HasKey(keys::kPageActionDefaultIcon)) { |
| + if (action_type == ExtensionAction::TYPE_SCRIPT_BADGE) { |
| + *error = ASCIIToUTF16(errors::kScriptBadgeCannotSpecifyIcon); |
|
Aaron Boodman
2012/06/16 01:50:38
Same here, I don't think we should throw an error
Jeffrey Yasskin
2012/06/18 22:16:03
Turned it into an install_warning that only develo
|
| + return scoped_ptr<ExtensionAction>(); |
| + } |
| if (!extension_action->GetString(keys::kPageActionDefaultIcon, |
| &default_icon) || |
| default_icon.empty()) { |
| @@ -2026,6 +2032,7 @@ bool Extension::LoadExtensionFeatures( |
| !LoadContentScripts(error) || |
| !LoadPageAction(error) || |
| !LoadBrowserAction(error) || |
| + !LoadScriptBadge(error) || |
| !LoadFileBrowserHandlers(error) || |
| !LoadChromeURLOverrides(error) || |
| !LoadOmnibox(error) || |
| @@ -2246,7 +2253,8 @@ bool Extension::LoadPageAction(string16* error) { |
| // If page_action_value is not NULL, then there was a valid page action. |
| if (page_action_value) { |
| - page_action_ = LoadExtensionActionHelper(page_action_value, error); |
| + page_action_ = LoadExtensionActionHelper( |
| + page_action_value, ExtensionAction::TYPE_PAGE, error); |
| if (!page_action_.get()) |
| return false; // Failed to parse page action definition. |
| declared_action_type_ = ExtensionAction::TYPE_PAGE; |
| @@ -2271,13 +2279,58 @@ bool Extension::LoadBrowserAction(string16* error) { |
| return false; |
| } |
| - browser_action_ = LoadExtensionActionHelper(browser_action_value, error); |
| + browser_action_ = LoadExtensionActionHelper( |
| + browser_action_value, ExtensionAction::TYPE_BROWSER, error); |
| if (!browser_action_.get()) |
| return false; // Failed to parse browser action definition. |
| declared_action_type_ = ExtensionAction::TYPE_BROWSER; |
| return true; |
| } |
| +bool Extension::LoadScriptBadge(string16* error) { |
| + DictionaryValue* script_badge_value = NULL; |
| + |
| + if (!switch_utils::IsActionBoxEnabled()) { |
|
Aaron Boodman
2012/06/16 01:50:38
Note: This is going to become AreScriptBadgesEnabl
not at google - send to devlin
2012/06/18 18:51:24
It's in the CQ.
Jeffrey Yasskin
2012/06/18 22:16:03
I haven't synced to this yet, but I will soon.
|
| + if (manifest_->HasKey(keys::kScriptBadge)) { |
|
Aaron Boodman
2012/06/16 01:50:38
This is not necessary. The manifest key will be lo
Jeffrey Yasskin
2012/06/18 22:16:03
I'm a bit worried about developers using the scrip
|
| + *error = ASCIIToUTF16(errors::kScriptBadgeRequiresActionBox); |
| + return false; |
|
not at google - send to devlin
2012/06/18 18:51:24
Aaron are you saying to delete this whole block th
Aaron Boodman
2012/06/18 21:36:21
yes, or rather:
if (!manifest->HasKey(...))
ret
Jeffrey Yasskin
2012/06/18 22:16:03
We need to generate a script_badge object even whe
|
| + } |
| + return true; |
| + } |
| + |
| + if (manifest_->HasKey(keys::kScriptBadge)) { |
| + if (!manifest_->GetDictionary(keys::kScriptBadge, &script_badge_value)) { |
| + *error = ASCIIToUTF16(errors::kInvalidScriptBadge); |
| + return false; |
| + } |
| + script_badge_ = LoadExtensionActionHelper( |
| + script_badge_value, ExtensionAction::TYPE_SCRIPT_BADGE, error); |
| + if (!script_badge_.get()) |
| + return false; // Failed to parse page action definition. |
|
not at google - send to devlin
2012/06/18 18:51:24
s/page action/script badge/
Jeffrey Yasskin
2012/06/18 22:16:03
Whoops, done.
|
| + declared_action_type_ = ExtensionAction::TYPE_SCRIPT_BADGE; |
| + } else { |
| + script_badge_.reset(new ExtensionAction(id())); |
| + |
| + // Make sure there is always a title. |
| + script_badge_->SetTitle(ExtensionAction::kDefaultTabId, name()); |
| + } |
| + |
| + // Script badges always use their extension's badges so users can |
|
Aaron Boodman
2012/06/16 01:50:38
extension's icon
Jeffrey Yasskin
2012/06/18 22:16:03
Done.
|
| + // rely on the visual appearance to know which extension is |
| + // running. This isn't bulletproof since an malicious extension |
| + // could use a different 16x16 icon that matches the icon of a |
| + // trusted extension, and users wouldn't be warned during |
| + // installation. |
| + |
| + script_badge_->set_default_icon_path( |
| + icons().Get(ExtensionIconSet::EXTENSION_ICON_BITTY, |
| + ExtensionIconSet::MATCH_BIGGER)); |
| + |
| + script_badge_->SetIsVisible(ExtensionAction::kDefaultTabId, true); |
| + |
| + return true; |
| +} |
| + |
| bool Extension::LoadFileBrowserHandlers(string16* error) { |
| if (!manifest_->HasKey(keys::kFileBrowserHandlers)) |
| return true; |
| @@ -3664,46 +3717,6 @@ bool Extension::HasContentScriptAtURL(const GURL& url) const { |
| return false; |
| } |
| -ExtensionAction* Extension::GetScriptBadge() const { |
| - if (!script_badge_.get()) { |
| - script_badge_.reset(new ExtensionAction(id())); |
| - |
| - // On initialization, copy the default icon path from the browser action, |
| - // or generate a puzzle piece if there isn't one. Extensions may later |
| - // overwrite this icon using the browserAction API. |
| - if (browser_action() && !browser_action()->default_icon_path().empty()) { |
| - script_badge_->set_default_icon_path( |
| - browser_action()->default_icon_path()); |
| - } else { |
| - script_badge_->SetIcon( |
| - ExtensionAction::kDefaultTabId, |
| - *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| - IDR_EXTENSIONS_FAVICON).ToSkBitmap()); |
| - } |
| - |
| - // Likewise, make sure there is always a title. |
| - script_badge_->SetTitle(ExtensionAction::kDefaultTabId, name()); |
| - } |
| - |
| - // Every time, re-initialize the script badge based on the current state of |
| - // the browser action. |
| - int kDefaultTabId = ExtensionAction::kDefaultTabId; |
| - |
| - script_badge_->SetIsVisible(kDefaultTabId, true); |
| - |
| - if (browser_action()) { |
| - SkBitmap icon = browser_action()->GetIcon(kDefaultTabId); |
| - if (!icon.isNull()) |
| - script_badge_->SetIcon(kDefaultTabId, icon); |
| - |
| - std::string title = browser_action()->GetTitle(kDefaultTabId); |
| - if (!title.empty()) |
| - script_badge_->SetTitle(kDefaultTabId, title); |
| - } |
| - |
| - return script_badge_.get(); |
| -} |
| - |
| const URLPatternSet* Extension::GetTabSpecificHostPermissions( |
| int tab_id) const { |
| base::AutoLock auto_lock(runtime_data_lock_); |