OLD | NEW |
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 if (base::HexStringToInt(base::StringPiece(id->begin() + i, | 123 if (base::HexStringToInt(base::StringPiece(id->begin() + i, |
124 id->begin() + i + 1), | 124 id->begin() + i + 1), |
125 &val)) { | 125 &val)) { |
126 (*id)[i] = val + 'a'; | 126 (*id)[i] = val + 'a'; |
127 } else { | 127 } else { |
128 (*id)[i] = 'a'; | 128 (*id)[i] = 'a'; |
129 } | 129 } |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
| 133 // Strips leading slashes from the file path. Returns true iff the final path is |
| 134 // non empty. |
| 135 bool NormalizeAndValidatePath(std::string* path) { |
| 136 size_t first_non_slash = path->find_first_not_of('/'); |
| 137 if (first_non_slash == std::string::npos) { |
| 138 *path = ""; |
| 139 return false; |
| 140 } |
| 141 |
| 142 *path = path->substr(first_non_slash); |
| 143 return true; |
| 144 } |
| 145 |
133 // Loads icon paths defined in dictionary |icons_value| into ExtensionIconSet | 146 // Loads icon paths defined in dictionary |icons_value| into ExtensionIconSet |
134 // |icons|. |icons_value| is a dictionary value {icon size -> icon path}. Icons | 147 // |icons|. |icons_value| is a dictionary value {icon size -> icon path}. Icons |
135 // in |icons_value| whose size is not in |icon_sizes| will be ignored. | 148 // in |icons_value| whose size is not in |icon_sizes| will be ignored. |
136 // Returns success. If load fails, |error| will be set. | 149 // Returns success. If load fails, |error| will be set. |
137 bool LoadIconsFromDictionary(const DictionaryValue* icons_value, | 150 bool LoadIconsFromDictionary(const DictionaryValue* icons_value, |
138 const int* icon_sizes, | 151 const int* icon_sizes, |
139 size_t num_icon_sizes, | 152 size_t num_icon_sizes, |
140 ExtensionIconSet* icons, | 153 ExtensionIconSet* icons, |
141 string16* error) { | 154 string16* error) { |
142 DCHECK(icons); | 155 DCHECK(icons); |
143 for (size_t i = 0; i < num_icon_sizes; ++i) { | 156 for (size_t i = 0; i < num_icon_sizes; ++i) { |
144 std::string key = base::IntToString(icon_sizes[i]); | 157 std::string key = base::IntToString(icon_sizes[i]); |
145 if (icons_value->HasKey(key)) { | 158 if (icons_value->HasKey(key)) { |
146 std::string icon_path; | 159 std::string icon_path; |
147 if (!icons_value->GetString(key, &icon_path)) { | 160 if (!icons_value->GetString(key, &icon_path)) { |
148 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 161 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
149 errors::kInvalidIconPath, key); | 162 errors::kInvalidIconPath, key); |
150 return false; | 163 return false; |
151 } | 164 } |
152 | 165 |
153 if (!icon_path.empty() && icon_path[0] == '/') | 166 if (!NormalizeAndValidatePath(&icon_path)) { |
154 icon_path = icon_path.substr(1); | |
155 | |
156 if (icon_path.empty()) { | |
157 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 167 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
158 errors::kInvalidIconPath, key); | 168 errors::kInvalidIconPath, key); |
159 return false; | 169 return false; |
160 } | 170 } |
| 171 |
161 icons->Add(icon_sizes[i], icon_path); | 172 icons->Add(icon_sizes[i], icon_path); |
162 } | 173 } |
163 } | 174 } |
164 return true; | 175 return true; |
165 } | 176 } |
166 | 177 |
167 // A singleton object containing global data needed by the extension objects. | 178 // A singleton object containing global data needed by the extension objects. |
168 class ExtensionConfig { | 179 class ExtensionConfig { |
169 public: | 180 public: |
170 static ExtensionConfig* GetInstance() { | 181 static ExtensionConfig* GetInstance() { |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 | 856 |
846 if (manifest_version_ == 1) { | 857 if (manifest_version_ == 1) { |
847 // kPageActionIcons is obsolete, and used by very few extensions. Continue | 858 // kPageActionIcons is obsolete, and used by very few extensions. Continue |
848 // loading it, but only take the first icon as the default_icon path. | 859 // loading it, but only take the first icon as the default_icon path. |
849 const ListValue* icons = NULL; | 860 const ListValue* icons = NULL; |
850 if (extension_action->HasKey(keys::kPageActionIcons) && | 861 if (extension_action->HasKey(keys::kPageActionIcons) && |
851 extension_action->GetList(keys::kPageActionIcons, &icons)) { | 862 extension_action->GetList(keys::kPageActionIcons, &icons)) { |
852 for (ListValue::const_iterator iter = icons->begin(); | 863 for (ListValue::const_iterator iter = icons->begin(); |
853 iter != icons->end(); ++iter) { | 864 iter != icons->end(); ++iter) { |
854 std::string path; | 865 std::string path; |
855 if (!(*iter)->GetAsString(&path) || path.empty()) { | 866 if (!(*iter)->GetAsString(&path) || !NormalizeAndValidatePath(&path)) { |
856 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); | 867 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); |
857 return scoped_ptr<ExtensionAction>(); | 868 return scoped_ptr<ExtensionAction>(); |
858 } | 869 } |
859 | 870 |
860 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); | 871 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); |
861 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, path); | 872 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, path); |
862 result->set_default_icon(icon_set.Pass()); | 873 result->set_default_icon(icon_set.Pass()); |
863 break; | 874 break; |
864 } | 875 } |
865 } | 876 } |
(...skipping 21 matching lines...) Expand all Loading... |
887 extension_misc::kExtensionActionIconSizes, | 898 extension_misc::kExtensionActionIconSizes, |
888 extension_misc::kNumExtensionActionIconSizes, | 899 extension_misc::kNumExtensionActionIconSizes, |
889 default_icons.get(), | 900 default_icons.get(), |
890 error)) { | 901 error)) { |
891 return scoped_ptr<ExtensionAction>(); | 902 return scoped_ptr<ExtensionAction>(); |
892 } | 903 } |
893 | 904 |
894 result->set_default_icon(default_icons.Pass()); | 905 result->set_default_icon(default_icons.Pass()); |
895 } else if (extension_action->GetString(keys::kPageActionDefaultIcon, | 906 } else if (extension_action->GetString(keys::kPageActionDefaultIcon, |
896 &default_icon) && | 907 &default_icon) && |
897 !default_icon.empty()) { | 908 NormalizeAndValidatePath(&default_icon)) { |
898 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); | 909 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); |
899 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, default_icon); | 910 icon_set->Add(extension_misc::EXTENSION_ICON_ACTION, default_icon); |
900 result->set_default_icon(icon_set.Pass()); | 911 result->set_default_icon(icon_set.Pass()); |
901 } else { | 912 } else { |
902 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); | 913 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); |
903 return scoped_ptr<ExtensionAction>(); | 914 return scoped_ptr<ExtensionAction>(); |
904 } | 915 } |
905 } | 916 } |
906 | 917 |
907 // Read the page action title from |default_title| if present, |name| if not | 918 // 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 Loading... |
2410 install_warnings_.push_back( | 2421 install_warnings_.push_back( |
2411 InstallWarning(InstallWarning::FORMAT_TEXT, | 2422 InstallWarning(InstallWarning::FORMAT_TEXT, |
2412 errors::kScriptBadgeIconIgnored)); | 2423 errors::kScriptBadgeIconIgnored)); |
2413 } | 2424 } |
2414 | 2425 |
2415 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); | 2426 scoped_ptr<ExtensionIconSet> icon_set(new ExtensionIconSet); |
2416 | 2427 |
2417 for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; i++) { | 2428 for (size_t i = 0; i < extension_misc::kNumScriptBadgeIconSizes; i++) { |
2418 std::string path = icons().Get(extension_misc::kScriptBadgeIconSizes[i], | 2429 std::string path = icons().Get(extension_misc::kScriptBadgeIconSizes[i], |
2419 ExtensionIconSet::MATCH_EXACTLY); | 2430 ExtensionIconSet::MATCH_EXACTLY); |
2420 if (!path.empty()) { | 2431 if (!path.empty()) |
2421 icon_set->Add(extension_misc::kScriptBadgeIconSizes[i], path); | 2432 icon_set->Add(extension_misc::kScriptBadgeIconSizes[i], path); |
2422 } | |
2423 } | 2433 } |
2424 | 2434 |
2425 if (!icon_set->map().empty()) { | 2435 if (!icon_set->map().empty()) { |
2426 script_badge_->set_default_icon(icon_set.Pass()); | 2436 script_badge_->set_default_icon(icon_set.Pass()); |
2427 } else { | 2437 } else { |
2428 script_badge_->set_default_icon(scoped_ptr<ExtensionIconSet>()); | 2438 script_badge_->set_default_icon(scoped_ptr<ExtensionIconSet>()); |
2429 } | 2439 } |
2430 | 2440 |
2431 return true; | 2441 return true; |
2432 } | 2442 } |
(...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4021 | 4031 |
4022 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 4032 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
4023 const Extension* extension, | 4033 const Extension* extension, |
4024 const PermissionSet* permissions, | 4034 const PermissionSet* permissions, |
4025 Reason reason) | 4035 Reason reason) |
4026 : reason(reason), | 4036 : reason(reason), |
4027 extension(extension), | 4037 extension(extension), |
4028 permissions(permissions) {} | 4038 permissions(permissions) {} |
4029 | 4039 |
4030 } // namespace extensions | 4040 } // namespace extensions |
OLD | NEW |