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

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 10565017: Parse the script_badge manifest section. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 return false; 794 return false;
795 } 795 }
796 796
797 (instance->*add_method)(glob); 797 (instance->*add_method)(glob);
798 } 798 }
799 799
800 return true; 800 return true;
801 } 801 }
802 802
803 scoped_ptr<ExtensionAction> Extension::LoadExtensionActionHelper( 803 scoped_ptr<ExtensionAction> Extension::LoadExtensionActionHelper(
804 const DictionaryValue* extension_action, string16* error) { 804 const DictionaryValue* extension_action,
805 ExtensionAction::Type action_type,
806 string16* error) {
805 scoped_ptr<ExtensionAction> result(new ExtensionAction(id())); 807 scoped_ptr<ExtensionAction> result(new ExtensionAction(id()));
806 808
807 // Page actions are hidden by default, and browser actions ignore 809 // Page actions are hidden by default, and browser actions ignore
808 // visibility. 810 // visibility.
809 result->SetIsVisible(ExtensionAction::kDefaultTabId, false); 811 result->SetIsVisible(ExtensionAction::kDefaultTabId, false);
810 812
811 if (manifest_version_ == 1) { 813 if (manifest_version_ == 1) {
812 ListValue* icons = NULL; 814 ListValue* icons = NULL;
813 if (extension_action->HasKey(keys::kPageActionIcons) && 815 if (extension_action->HasKey(keys::kPageActionIcons) &&
814 extension_action->GetList(keys::kPageActionIcons, &icons)) { 816 extension_action->GetList(keys::kPageActionIcons, &icons)) {
(...skipping 15 matching lines...) Expand all
830 *error = ASCIIToUTF16(errors::kInvalidPageActionId); 832 *error = ASCIIToUTF16(errors::kInvalidPageActionId);
831 return scoped_ptr<ExtensionAction>(); 833 return scoped_ptr<ExtensionAction>();
832 } 834 }
833 result->set_id(id); 835 result->set_id(id);
834 } 836 }
835 } 837 }
836 838
837 std::string default_icon; 839 std::string default_icon;
838 // Read the page action |default_icon| (optional). 840 // Read the page action |default_icon| (optional).
839 if (extension_action->HasKey(keys::kPageActionDefaultIcon)) { 841 if (extension_action->HasKey(keys::kPageActionDefaultIcon)) {
842 if (action_type == ExtensionAction::TYPE_SCRIPT_BADGE) {
843 *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
844 return scoped_ptr<ExtensionAction>();
845 }
840 if (!extension_action->GetString(keys::kPageActionDefaultIcon, 846 if (!extension_action->GetString(keys::kPageActionDefaultIcon,
841 &default_icon) || 847 &default_icon) ||
842 default_icon.empty()) { 848 default_icon.empty()) {
843 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); 849 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath);
844 return scoped_ptr<ExtensionAction>(); 850 return scoped_ptr<ExtensionAction>();
845 } 851 }
846 result->set_default_icon_path(default_icon); 852 result->set_default_icon_path(default_icon);
847 } 853 }
848 854
849 // Read the page action title from |default_title| if present, |name| if not 855 // Read the page action title from |default_title| if present, |name| if not
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 string16* error) { 2025 string16* error) {
2020 if (manifest_->HasKey(keys::kConvertedFromUserScript)) 2026 if (manifest_->HasKey(keys::kConvertedFromUserScript))
2021 manifest_->GetBoolean(keys::kConvertedFromUserScript, 2027 manifest_->GetBoolean(keys::kConvertedFromUserScript,
2022 &converted_from_user_script_); 2028 &converted_from_user_script_);
2023 2029
2024 if (!LoadDevToolsPage(error) || 2030 if (!LoadDevToolsPage(error) ||
2025 !LoadInputComponents(api_permissions, error) || 2031 !LoadInputComponents(api_permissions, error) ||
2026 !LoadContentScripts(error) || 2032 !LoadContentScripts(error) ||
2027 !LoadPageAction(error) || 2033 !LoadPageAction(error) ||
2028 !LoadBrowserAction(error) || 2034 !LoadBrowserAction(error) ||
2035 !LoadScriptBadge(error) ||
2029 !LoadFileBrowserHandlers(error) || 2036 !LoadFileBrowserHandlers(error) ||
2030 !LoadChromeURLOverrides(error) || 2037 !LoadChromeURLOverrides(error) ||
2031 !LoadOmnibox(error) || 2038 !LoadOmnibox(error) ||
2032 !LoadTextToSpeechVoices(error) || 2039 !LoadTextToSpeechVoices(error) ||
2033 !LoadIncognitoMode(error) || 2040 !LoadIncognitoMode(error) ||
2034 !LoadContentSecurityPolicy(error)) 2041 !LoadContentSecurityPolicy(error))
2035 return false; 2042 return false;
2036 2043
2037 return true; 2044 return true;
2038 } 2045 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 } 2246 }
2240 } else if (manifest_->HasKey(keys::kPageAction)) { 2247 } else if (manifest_->HasKey(keys::kPageAction)) {
2241 if (!manifest_->GetDictionary(keys::kPageAction, &page_action_value)) { 2248 if (!manifest_->GetDictionary(keys::kPageAction, &page_action_value)) {
2242 *error = ASCIIToUTF16(errors::kInvalidPageAction); 2249 *error = ASCIIToUTF16(errors::kInvalidPageAction);
2243 return false; 2250 return false;
2244 } 2251 }
2245 } 2252 }
2246 2253
2247 // If page_action_value is not NULL, then there was a valid page action. 2254 // If page_action_value is not NULL, then there was a valid page action.
2248 if (page_action_value) { 2255 if (page_action_value) {
2249 page_action_ = LoadExtensionActionHelper(page_action_value, error); 2256 page_action_ = LoadExtensionActionHelper(
2257 page_action_value, ExtensionAction::TYPE_PAGE, error);
2250 if (!page_action_.get()) 2258 if (!page_action_.get())
2251 return false; // Failed to parse page action definition. 2259 return false; // Failed to parse page action definition.
2252 declared_action_type_ = ExtensionAction::TYPE_PAGE; 2260 declared_action_type_ = ExtensionAction::TYPE_PAGE;
2253 2261
2254 // The action box changes the meaning of the page action area, so we need 2262 // The action box changes the meaning of the page action area, so we need
2255 // to convert page actions into browser actions. 2263 // to convert page actions into browser actions.
2256 if (switch_utils::IsActionBoxEnabled()) { 2264 if (switch_utils::IsActionBoxEnabled()) {
2257 browser_action_ = page_action_.Pass(); 2265 browser_action_ = page_action_.Pass();
2258 // declared_action_type_ stays the same; that's the point. 2266 // declared_action_type_ stays the same; that's the point.
2259 } 2267 }
2260 } 2268 }
2261 2269
2262 return true; 2270 return true;
2263 } 2271 }
2264 2272
2265 bool Extension::LoadBrowserAction(string16* error) { 2273 bool Extension::LoadBrowserAction(string16* error) {
2266 if (!manifest_->HasKey(keys::kBrowserAction)) 2274 if (!manifest_->HasKey(keys::kBrowserAction))
2267 return true; 2275 return true;
2268 DictionaryValue* browser_action_value = NULL; 2276 DictionaryValue* browser_action_value = NULL;
2269 if (!manifest_->GetDictionary(keys::kBrowserAction, &browser_action_value)) { 2277 if (!manifest_->GetDictionary(keys::kBrowserAction, &browser_action_value)) {
2270 *error = ASCIIToUTF16(errors::kInvalidBrowserAction); 2278 *error = ASCIIToUTF16(errors::kInvalidBrowserAction);
2271 return false; 2279 return false;
2272 } 2280 }
2273 2281
2274 browser_action_ = LoadExtensionActionHelper(browser_action_value, error); 2282 browser_action_ = LoadExtensionActionHelper(
2283 browser_action_value, ExtensionAction::TYPE_BROWSER, error);
2275 if (!browser_action_.get()) 2284 if (!browser_action_.get())
2276 return false; // Failed to parse browser action definition. 2285 return false; // Failed to parse browser action definition.
2277 declared_action_type_ = ExtensionAction::TYPE_BROWSER; 2286 declared_action_type_ = ExtensionAction::TYPE_BROWSER;
2278 return true; 2287 return true;
2279 } 2288 }
2280 2289
2290 bool Extension::LoadScriptBadge(string16* error) {
2291 DictionaryValue* script_badge_value = NULL;
2292
2293 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.
2294 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
2295 *error = ASCIIToUTF16(errors::kScriptBadgeRequiresActionBox);
2296 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
2297 }
2298 return true;
2299 }
2300
2301 if (manifest_->HasKey(keys::kScriptBadge)) {
2302 if (!manifest_->GetDictionary(keys::kScriptBadge, &script_badge_value)) {
2303 *error = ASCIIToUTF16(errors::kInvalidScriptBadge);
2304 return false;
2305 }
2306 script_badge_ = LoadExtensionActionHelper(
2307 script_badge_value, ExtensionAction::TYPE_SCRIPT_BADGE, error);
2308 if (!script_badge_.get())
2309 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.
2310 declared_action_type_ = ExtensionAction::TYPE_SCRIPT_BADGE;
2311 } else {
2312 script_badge_.reset(new ExtensionAction(id()));
2313
2314 // Make sure there is always a title.
2315 script_badge_->SetTitle(ExtensionAction::kDefaultTabId, name());
2316 }
2317
2318 // 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.
2319 // rely on the visual appearance to know which extension is
2320 // running. This isn't bulletproof since an malicious extension
2321 // could use a different 16x16 icon that matches the icon of a
2322 // trusted extension, and users wouldn't be warned during
2323 // installation.
2324
2325 script_badge_->set_default_icon_path(
2326 icons().Get(ExtensionIconSet::EXTENSION_ICON_BITTY,
2327 ExtensionIconSet::MATCH_BIGGER));
2328
2329 script_badge_->SetIsVisible(ExtensionAction::kDefaultTabId, true);
2330
2331 return true;
2332 }
2333
2281 bool Extension::LoadFileBrowserHandlers(string16* error) { 2334 bool Extension::LoadFileBrowserHandlers(string16* error) {
2282 if (!manifest_->HasKey(keys::kFileBrowserHandlers)) 2335 if (!manifest_->HasKey(keys::kFileBrowserHandlers))
2283 return true; 2336 return true;
2284 ListValue* file_browser_handlers_value = NULL; 2337 ListValue* file_browser_handlers_value = NULL;
2285 if (!manifest_->GetList(keys::kFileBrowserHandlers, 2338 if (!manifest_->GetList(keys::kFileBrowserHandlers,
2286 &file_browser_handlers_value)) { 2339 &file_browser_handlers_value)) {
2287 *error = ASCIIToUTF16(errors::kInvalidFileBrowserHandler); 2340 *error = ASCIIToUTF16(errors::kInvalidFileBrowserHandler);
2288 return false; 2341 return false;
2289 } 2342 }
2290 file_browser_handlers_.reset( 2343 file_browser_handlers_.reset(
(...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after
3657 3710
3658 bool Extension::HasContentScriptAtURL(const GURL& url) const { 3711 bool Extension::HasContentScriptAtURL(const GURL& url) const {
3659 for (UserScriptList::const_iterator it = content_scripts_.begin(); 3712 for (UserScriptList::const_iterator it = content_scripts_.begin();
3660 it != content_scripts_.end(); ++it) { 3713 it != content_scripts_.end(); ++it) {
3661 if (it->MatchesURL(url)) 3714 if (it->MatchesURL(url))
3662 return true; 3715 return true;
3663 } 3716 }
3664 return false; 3717 return false;
3665 } 3718 }
3666 3719
3667 ExtensionAction* Extension::GetScriptBadge() const {
3668 if (!script_badge_.get()) {
3669 script_badge_.reset(new ExtensionAction(id()));
3670
3671 // On initialization, copy the default icon path from the browser action,
3672 // or generate a puzzle piece if there isn't one. Extensions may later
3673 // overwrite this icon using the browserAction API.
3674 if (browser_action() && !browser_action()->default_icon_path().empty()) {
3675 script_badge_->set_default_icon_path(
3676 browser_action()->default_icon_path());
3677 } else {
3678 script_badge_->SetIcon(
3679 ExtensionAction::kDefaultTabId,
3680 *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
3681 IDR_EXTENSIONS_FAVICON).ToSkBitmap());
3682 }
3683
3684 // Likewise, make sure there is always a title.
3685 script_badge_->SetTitle(ExtensionAction::kDefaultTabId, name());
3686 }
3687
3688 // Every time, re-initialize the script badge based on the current state of
3689 // the browser action.
3690 int kDefaultTabId = ExtensionAction::kDefaultTabId;
3691
3692 script_badge_->SetIsVisible(kDefaultTabId, true);
3693
3694 if (browser_action()) {
3695 SkBitmap icon = browser_action()->GetIcon(kDefaultTabId);
3696 if (!icon.isNull())
3697 script_badge_->SetIcon(kDefaultTabId, icon);
3698
3699 std::string title = browser_action()->GetTitle(kDefaultTabId);
3700 if (!title.empty())
3701 script_badge_->SetTitle(kDefaultTabId, title);
3702 }
3703
3704 return script_badge_.get();
3705 }
3706
3707 const URLPatternSet* Extension::GetTabSpecificHostPermissions( 3720 const URLPatternSet* Extension::GetTabSpecificHostPermissions(
3708 int tab_id) const { 3721 int tab_id) const {
3709 base::AutoLock auto_lock(runtime_data_lock_); 3722 base::AutoLock auto_lock(runtime_data_lock_);
3710 return runtime_data_.GetTabSpecificHostPermissions(tab_id); 3723 return runtime_data_.GetTabSpecificHostPermissions(tab_id);
3711 } 3724 }
3712 3725
3713 void Extension::SetTabSpecificHostPermissions( 3726 void Extension::SetTabSpecificHostPermissions(
3714 int tab_id, 3727 int tab_id,
3715 const URLPatternSet& permissions) const { 3728 const URLPatternSet& permissions) const {
3716 base::AutoLock auto_lock(runtime_data_lock_); 3729 base::AutoLock auto_lock(runtime_data_lock_);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
3797 3810
3798 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3811 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3799 const Extension* extension, 3812 const Extension* extension,
3800 const ExtensionPermissionSet* permissions, 3813 const ExtensionPermissionSet* permissions,
3801 Reason reason) 3814 Reason reason)
3802 : reason(reason), 3815 : reason(reason),
3803 extension(extension), 3816 extension(extension),
3804 permissions(permissions) {} 3817 permissions(permissions) {}
3805 3818
3806 } // namespace extensions 3819 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698