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

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

Issue 10957008: Normalize extension action icon paths before adding them to icon set (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 for (size_t i = 0; i < num_icon_sizes; ++i) { 143 for (size_t i = 0; i < num_icon_sizes; ++i) {
144 std::string key = base::IntToString(icon_sizes[i]); 144 std::string key = base::IntToString(icon_sizes[i]);
145 if (icons_value->HasKey(key)) { 145 if (icons_value->HasKey(key)) {
146 std::string icon_path; 146 std::string icon_path;
147 if (!icons_value->GetString(key, &icon_path)) { 147 if (!icons_value->GetString(key, &icon_path)) {
148 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 148 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
149 errors::kInvalidIconPath, key); 149 errors::kInvalidIconPath, key);
150 return false; 150 return false;
151 } 151 }
152 152
153 if (!icon_path.empty() && icon_path[0] == '/')
154 icon_path = icon_path.substr(1);
155
156 if (icon_path.empty()) { 153 if (icon_path.empty()) {
157 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 154 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
158 errors::kInvalidIconPath, key); 155 errors::kInvalidIconPath, key);
159 return false; 156 return false;
160 } 157 }
158
159 if (icon_path[0] == '/')
not at google - send to devlin 2012/09/20 06:00:55 should be "while" not "if"? also seems like this
tbarzic 2012/09/20 06:45:06 Done.
160 icon_path = icon_path.substr(1);
161
161 icons->Add(icon_sizes[i], icon_path); 162 icons->Add(icon_sizes[i], icon_path);
162 } 163 }
163 } 164 }
164 return true; 165 return true;
165 } 166 }
166 167
167 // A singleton object containing global data needed by the extension objects. 168 // A singleton object containing global data needed by the extension objects.
168 class ExtensionConfig { 169 class ExtensionConfig {
169 public: 170 public:
170 static ExtensionConfig* GetInstance() { 171 static ExtensionConfig* GetInstance() {
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 if (extension_action->HasKey(keys::kPageActionIcons) && 851 if (extension_action->HasKey(keys::kPageActionIcons) &&
851 extension_action->GetList(keys::kPageActionIcons, &icons)) { 852 extension_action->GetList(keys::kPageActionIcons, &icons)) {
852 for (ListValue::const_iterator iter = icons->begin(); 853 for (ListValue::const_iterator iter = icons->begin();
853 iter != icons->end(); ++iter) { 854 iter != icons->end(); ++iter) {
854 std::string path; 855 std::string path;
855 if (!(*iter)->GetAsString(&path) || path.empty()) { 856 if (!(*iter)->GetAsString(&path) || path.empty()) {
856 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); 857 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath);
857 return scoped_ptr<ExtensionAction>(); 858 return scoped_ptr<ExtensionAction>();
858 } 859 }
859 860
861 if (path[0] == '/')
not at google - send to devlin 2012/09/20 06:00:55 ditto while? actually it seems like this (and sam
tbarzic 2012/09/20 06:45:06 Yeah, good point.. Done.
862 path = path.substr(1);
863
860 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); 864 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet);
861 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, path); 865 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, path);
862 result->set_default_icon(icon_set.Pass()); 866 result->set_default_icon(icon_set.Pass());
863 break; 867 break;
864 } 868 }
865 } 869 }
866 870
867 std::string id; 871 std::string id;
868 if (extension_action->HasKey(keys::kPageActionId)) { 872 if (extension_action->HasKey(keys::kPageActionId)) {
869 if (!extension_action->GetString(keys::kPageActionId, &id)) { 873 if (!extension_action->GetString(keys::kPageActionId, &id)) {
(...skipping 18 matching lines...) Expand all
888 extension_misc::kNumExtensionActionIconSizes, 892 extension_misc::kNumExtensionActionIconSizes,
889 default_icons.get(), 893 default_icons.get(),
890 error)) { 894 error)) {
891 return scoped_ptr<ExtensionAction>(); 895 return scoped_ptr<ExtensionAction>();
892 } 896 }
893 897
894 result->set_default_icon(default_icons.Pass()); 898 result->set_default_icon(default_icons.Pass());
895 } else if (extension_action->GetString(keys::kPageActionDefaultIcon, 899 } else if (extension_action->GetString(keys::kPageActionDefaultIcon,
896 &default_icon) && 900 &default_icon) &&
897 !default_icon.empty()) { 901 !default_icon.empty()) {
902 if (default_icon[0] == '/')
903 default_icon = default_icon.substr(1);
904
898 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); 905 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet);
899 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, default_icon); 906 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, default_icon);
900 result->set_default_icon(icon_set.Pass()); 907 result->set_default_icon(icon_set.Pass());
901 } else { 908 } else {
902 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); 909 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath);
903 return scoped_ptr<ExtensionAction>(); 910 return scoped_ptr<ExtensionAction>();
904 } 911 }
905 } 912 }
906 913
907 // Read the page action title from |default_title| if present, |name| if not 914 // Read the page action title from |default_title| if present, |name| if not
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 install_warnings_.push_back( 2417 install_warnings_.push_back(
2411 InstallWarning(InstallWarning::FORMAT_TEXT, 2418 InstallWarning(InstallWarning::FORMAT_TEXT,
2412 errors::kScriptBadgeIconIgnored)); 2419 errors::kScriptBadgeIconIgnored));
2413 } 2420 }
2414 2421
2415 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); 2422 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet);
2416 2423
2417 for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; i++) { 2424 for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; i++) {
2418 std::string path = icons().Get(extension_misc::kScriptBadgeIconSizes[i], 2425 std::string path = icons().Get(extension_misc::kScriptBadgeIconSizes[i],
2419 ExtensionIconSet::MATCH_EXACTLY); 2426 ExtensionIconSet::MATCH_EXACTLY);
2420 if (!path.empty()) { 2427 if (!path.empty())
2421 icon_set->Add(extension_misc::kScriptBadgeIconSizes[i], path); 2428 icon_set->Add(extension_misc::kScriptBadgeIconSizes[i], path);
2422 }
2423 } 2429 }
2424 2430
2425 if (!icon_set->map().empty()) { 2431 if (!icon_set->map().empty()) {
2426 script_badge_->set_default_icon(icon_set.Pass()); 2432 script_badge_->set_default_icon(icon_set.Pass());
2427 } else { 2433 } else {
2428 script_badge_->set_default_icon(scoped_ptr<ExtensionIconSet>()); 2434 script_badge_->set_default_icon(scoped_ptr<ExtensionIconSet>());
2429 } 2435 }
2430 2436
2431 return true; 2437 return true;
2432 } 2438 }
(...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after
4021 4027
4022 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 4028 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
4023 const Extension* extension, 4029 const Extension* extension,
4024 const PermissionSet* permissions, 4030 const PermissionSet* permissions,
4025 Reason reason) 4031 Reason reason)
4026 : reason(reason), 4032 : reason(reason),
4027 extension(extension), 4033 extension(extension),
4028 permissions(permissions) {} 4034 permissions(permissions) {}
4029 4035
4030 } // namespace extensions 4036 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698