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

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

Issue 10905005: Change browser/page action default icon defined in manifest to support hidpi. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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 <ostream> 7 #include <ostream>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (base::HexStringToInt(base::StringPiece(id->begin() + i, 126 if (base::HexStringToInt(base::StringPiece(id->begin() + i,
127 id->begin() + i + 1), 127 id->begin() + i + 1),
128 &val)) { 128 &val)) {
129 (*id)[i] = val + 'a'; 129 (*id)[i] = val + 'a';
130 } else { 130 } else {
131 (*id)[i] = 'a'; 131 (*id)[i] = 'a';
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 bool LoadIconsFromDictionary(const DictionaryValue* icons_value,
137 const int* icon_sizes,
138 size_t num_icon_sizes,
139 ExtensionIconSet* icons,
140 string16* error) {
141 DCHECK(icons);
142 for (size_t i = 0; i < num_icon_sizes; ++i) {
143 std::string key = base::IntToString(icon_sizes[i]);
144 if (icons_value->HasKey(key)) {
145 std::string icon_path;
146 if (!icons_value->GetString(key, &icon_path)) {
147 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
148 errors::kInvalidIconPath, key);
149 return false;
150 }
151
152 if (!icon_path.empty() && icon_path[0] == '/')
153 icon_path = icon_path.substr(1);
154
155 if (icon_path.empty()) {
156 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
157 errors::kInvalidIconPath, key);
158 return false;
159 }
160 icons->Add(icon_sizes[i], icon_path);
161 }
162 }
163 return true;
164 }
165
136 // A singleton object containing global data needed by the extension objects. 166 // A singleton object containing global data needed by the extension objects.
137 class ExtensionConfig { 167 class ExtensionConfig {
138 public: 168 public:
139 static ExtensionConfig* GetInstance() { 169 static ExtensionConfig* GetInstance() {
140 return Singleton<ExtensionConfig>::get(); 170 return Singleton<ExtensionConfig>::get();
141 } 171 }
142 172
143 Extension::ScriptingWhitelist* whitelist() { return &scripting_whitelist_; } 173 Extension::ScriptingWhitelist* whitelist() { return &scripting_whitelist_; }
144 174
145 private: 175 private:
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 if (extension_action->HasKey(keys::kPageActionIcons) && 851 if (extension_action->HasKey(keys::kPageActionIcons) &&
822 extension_action->GetList(keys::kPageActionIcons, &icons)) { 852 extension_action->GetList(keys::kPageActionIcons, &icons)) {
823 for (ListValue::const_iterator iter = icons->begin(); 853 for (ListValue::const_iterator iter = icons->begin();
824 iter != icons->end(); ++iter) { 854 iter != icons->end(); ++iter) {
825 std::string path; 855 std::string path;
826 if (!(*iter)->GetAsString(&path) || path.empty()) { 856 if (!(*iter)->GetAsString(&path) || path.empty()) {
827 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); 857 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath);
828 return scoped_ptr<ExtensionAction>(); 858 return scoped_ptr<ExtensionAction>();
829 } 859 }
830 860
831 result->icon_paths()->push_back(path); 861 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet);
862 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, path);
863 result->AddPageActionIcon(icon_set.release());
832 } 864 }
833 } 865 }
834 866
835 std::string id; 867 std::string id;
836 if (extension_action->HasKey(keys::kPageActionId)) { 868 if (extension_action->HasKey(keys::kPageActionId)) {
837 if (!extension_action->GetString(keys::kPageActionId, &id)) { 869 if (!extension_action->GetString(keys::kPageActionId, &id)) {
838 *error = ASCIIToUTF16(errors::kInvalidPageActionId); 870 *error = ASCIIToUTF16(errors::kInvalidPageActionId);
839 return scoped_ptr<ExtensionAction>(); 871 return scoped_ptr<ExtensionAction>();
840 } 872 }
841 result->set_id(id); 873 result->set_id(id);
842 } 874 }
843 } 875 }
844 876
845 std::string default_icon; 877 if (extension_action->HasKey(keys::kPageActionDefaultIconSet)) {
tbarzic 2012/08/30 18:06:45 I'm not too content with the name here ("default_i
846 // Read the page action |default_icon| (optional). 878 const DictionaryValue* icons_value = NULL;
847 if (extension_action->HasKey(keys::kPageActionDefaultIcon)) { 879 if (!extension_action->GetDictionary(keys::kPageActionDefaultIconSet,
880 &icons_value)) {
881 *error = ASCIIToUTF16(errors::kInvalidIcons);
882 return scoped_ptr<ExtensionAction>();
883 }
884
885 scoped_ptr<ExtensionIconSet> default_icons(new ExtensionIconSet());
886 if (!LoadIconsFromDictionary(icons_value,
887 extension_misc::kExtensionActionIconSizes,
888 extension_misc::kNumExtensionActionIconSizes,
889 default_icons.get(),
890 error)) {
891 return scoped_ptr<ExtensionAction>();
892 }
893
894 result->set_default_icon(default_icons.release());
895 } else if (extension_action->HasKey(keys::kPageActionDefaultIcon)) {
896 // Read the page action |default_icon| (optional).
897 std::string default_icon;
848 if (!extension_action->GetString(keys::kPageActionDefaultIcon, 898 if (!extension_action->GetString(keys::kPageActionDefaultIcon,
849 &default_icon) || 899 &default_icon) ||
850 default_icon.empty()) { 900 default_icon.empty()) {
851 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); 901 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath);
852 return scoped_ptr<ExtensionAction>(); 902 return scoped_ptr<ExtensionAction>();
853 } 903 }
854 result->set_default_icon_path(default_icon); 904 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet);
905 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, default_icon);
906 result->set_default_icon(icon_set.release());
855 } 907 }
856 908
857 // Read the page action title from |default_title| if present, |name| if not 909 // Read the page action title from |default_title| if present, |name| if not
858 // (both optional). 910 // (both optional).
859 std::string title; 911 std::string title;
860 if (extension_action->HasKey(keys::kPageActionDefaultTitle)) { 912 if (extension_action->HasKey(keys::kPageActionDefaultTitle)) {
861 if (!extension_action->GetString(keys::kPageActionDefaultTitle, &title)) { 913 if (!extension_action->GetString(keys::kPageActionDefaultTitle, &title)) {
862 *error = ASCIIToUTF16(errors::kInvalidPageActionDefaultTitle); 914 *error = ASCIIToUTF16(errors::kInvalidPageActionDefaultTitle);
863 return scoped_ptr<ExtensionAction>(); 915 return scoped_ptr<ExtensionAction>();
864 } 916 }
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 1468
1417 bool Extension::LoadIcons(string16* error) { 1469 bool Extension::LoadIcons(string16* error) {
1418 if (!manifest_->HasKey(keys::kIcons)) 1470 if (!manifest_->HasKey(keys::kIcons))
1419 return true; 1471 return true;
1420 DictionaryValue* icons_value = NULL; 1472 DictionaryValue* icons_value = NULL;
1421 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) { 1473 if (!manifest_->GetDictionary(keys::kIcons, &icons_value)) {
1422 *error = ASCIIToUTF16(errors::kInvalidIcons); 1474 *error = ASCIIToUTF16(errors::kInvalidIcons);
1423 return false; 1475 return false;
1424 } 1476 }
1425 1477
1426 for (size_t i = 0; i < extension_misc::kNumExtensionIconSizes; ++i) { 1478 return LoadIconsFromDictionary(icons_value,
1427 std::string key = 1479 extension_misc::kExtensionIconSizes,
1428 base::IntToString(extension_misc::kExtensionIconSizes[i]); 1480 extension_misc::kNumExtensionIconSizes,
1429 if (icons_value->HasKey(key)) { 1481 &icons_,
1430 std::string icon_path; 1482 error);
1431 if (!icons_value->GetString(key, &icon_path)) {
1432 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1433 errors::kInvalidIconPath, key);
1434 return false;
1435 }
1436
1437 if (!icon_path.empty() && icon_path[0] == '/')
1438 icon_path = icon_path.substr(1);
1439
1440 if (icon_path.empty()) {
1441 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1442 errors::kInvalidIconPath, key);
1443 return false;
1444 }
1445 icons_.Add(extension_misc::kExtensionIconSizes[i], icon_path);
1446 }
1447 }
1448 return true;
1449 } 1483 }
1450 1484
1451 bool Extension::LoadCommands(string16* error) { 1485 bool Extension::LoadCommands(string16* error) {
1452 if (manifest_->HasKey(keys::kCommands)) { 1486 if (manifest_->HasKey(keys::kCommands)) {
1453 DictionaryValue* commands = NULL; 1487 DictionaryValue* commands = NULL;
1454 if (!manifest_->GetDictionary(keys::kCommands, &commands)) { 1488 if (!manifest_->GetDictionary(keys::kCommands, &commands)) {
1455 *error = ASCIIToUTF16(errors::kInvalidCommandsKey); 1489 *error = ASCIIToUTF16(errors::kInvalidCommandsKey);
1456 return false; 1490 return false;
1457 } 1491 }
1458 1492
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 // that matches the icon of a trusted extension, and users wouldn't be warned 2396 // that matches the icon of a trusted extension, and users wouldn't be warned
2363 // during installation. 2397 // during installation.
2364 2398
2365 if (!script_badge_->GetTitle(ExtensionAction::kDefaultTabId).empty()) { 2399 if (!script_badge_->GetTitle(ExtensionAction::kDefaultTabId).empty()) {
2366 install_warnings_.push_back( 2400 install_warnings_.push_back(
2367 InstallWarning(InstallWarning::FORMAT_TEXT, 2401 InstallWarning(InstallWarning::FORMAT_TEXT,
2368 errors::kScriptBadgeTitleIgnored)); 2402 errors::kScriptBadgeTitleIgnored));
2369 } 2403 }
2370 script_badge_->SetTitle(ExtensionAction::kDefaultTabId, name()); 2404 script_badge_->SetTitle(ExtensionAction::kDefaultTabId, name());
2371 2405
2372 if (!script_badge_->default_icon_path().empty()) { 2406 if (script_badge_->default_icon()) {
2373 install_warnings_.push_back( 2407 install_warnings_.push_back(
2374 InstallWarning(InstallWarning::FORMAT_TEXT, 2408 InstallWarning(InstallWarning::FORMAT_TEXT,
2375 errors::kScriptBadgeIconIgnored)); 2409 errors::kScriptBadgeIconIgnored));
2376 } 2410 }
2377 std::string icon16_path = icons().Get(extension_misc::EXTENSION_ICON_BITTY, 2411
2378 ExtensionIconSet::MATCH_EXACTLY); 2412 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet);
2379 if (!icon16_path.empty()) { 2413
2380 script_badge_->set_default_icon_path(icon16_path); 2414 for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; i++) {
2415 std::string path = icons().Get(extension_misc::kScriptBadgeIconSizes[i],
2416 ExtensionIconSet::MATCH_EXACTLY);
2417 if (!path.empty()) {
2418 icon_set->Add(extension_misc::kScriptBadgeIconSizes[i], path);
2419 }
2420 }
2421
2422 if (!icon_set->map().empty()) {
2423 script_badge_->set_default_icon(icon_set.release());
2381 } else { 2424 } else {
2382 script_badge_->SetIcon( 2425 script_badge_->set_default_icon(NULL);
2383 ExtensionAction::kDefaultTabId,
2384 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
2385 IDR_EXTENSIONS_FAVICON));
2386 } 2426 }
2387 2427
2388 return true; 2428 return true;
2389 } 2429 }
2390 2430
2391 bool Extension::LoadFileBrowserHandlers(string16* error) { 2431 bool Extension::LoadFileBrowserHandlers(string16* error) {
2392 if (!manifest_->HasKey(keys::kFileBrowserHandlers)) 2432 if (!manifest_->HasKey(keys::kFileBrowserHandlers))
2393 return true; 2433 return true;
2394 ListValue* file_browser_handlers_value = NULL; 2434 ListValue* file_browser_handlers_value = NULL;
2395 if (!manifest_->GetList(keys::kFileBrowserHandlers, 2435 if (!manifest_->GetList(keys::kFileBrowserHandlers,
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
3207 for (DictionaryValue::key_iterator it = theme_images->begin_keys(); 3247 for (DictionaryValue::key_iterator it = theme_images->begin_keys();
3208 it != theme_images->end_keys(); ++it) { 3248 it != theme_images->end_keys(); ++it) {
3209 std::string val; 3249 std::string val;
3210 if (theme_images->GetStringWithoutPathExpansion(*it, &val)) 3250 if (theme_images->GetStringWithoutPathExpansion(*it, &val))
3211 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(val))); 3251 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(val)));
3212 } 3252 }
3213 } 3253 }
3214 3254
3215 // Page action icons. 3255 // Page action icons.
3216 if (page_action()) { 3256 if (page_action()) {
3217 std::vector<std::string>* icon_paths = page_action()->icon_paths(); 3257 const std::vector<const ExtensionIconSet*>& page_action_icons =
3218 for (std::vector<std::string>::iterator iter = icon_paths->begin(); 3258 page_action()->page_action_icons();
3219 iter != icon_paths->end(); ++iter) { 3259 for (size_t icon = 0; icon < page_action_icons.size(); icon++) {
3220 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter))); 3260 for (ExtensionIconSet::IconMap::const_iterator iter =
3261 page_action_icons[icon]->map().begin();
3262 iter != page_action_icons[icon]->map().end();
3263 ++iter) {
3264 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second)));
3265 }
3221 } 3266 }
3222 } 3267 }
3223 3268
3224 // Browser action icons. 3269 // Browser action icons.
3225 if (browser_action()) { 3270 if (browser_action()) {
3226 std::vector<std::string>* icon_paths = browser_action()->icon_paths(); 3271 const std::vector<const ExtensionIconSet*>& page_action_icons =
3227 for (std::vector<std::string>::iterator iter = icon_paths->begin(); 3272 browser_action()->page_action_icons();
3228 iter != icon_paths->end(); ++iter) { 3273 for (size_t icon = 0; icon < page_action_icons.size(); icon++) {
3229 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(*iter))); 3274 for (ExtensionIconSet::IconMap::const_iterator iter =
3275 page_action_icons[icon]->map().begin();
3276 iter != page_action_icons[icon]->map().end();
3277 ++iter) {
3278 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second)));
3279 }
3230 } 3280 }
3231 } 3281 }
3232 3282
3233 return image_paths; 3283 return image_paths;
3234 } 3284 }
3235 3285
3236 GURL Extension::GetFullLaunchURL() const { 3286 GURL Extension::GetFullLaunchURL() const {
3237 if (!launch_local_path().empty()) 3287 if (!launch_local_path().empty())
3238 return url().Resolve(launch_local_path()); 3288 return url().Resolve(launch_local_path());
3239 else 3289 else
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
3949 3999
3950 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 4000 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3951 const Extension* extension, 4001 const Extension* extension,
3952 const PermissionSet* permissions, 4002 const PermissionSet* permissions,
3953 Reason reason) 4003 Reason reason)
3954 : reason(reason), 4004 : reason(reason),
3955 extension(extension), 4005 extension(extension),
3956 permissions(permissions) {} 4006 permissions(permissions) {}
3957 4007
3958 } // namespace extensions 4008 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698