OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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> | |
8 | |
9 #include "base/base64.h" | 7 #include "base/base64.h" |
10 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
11 #include "base/command_line.h" | 9 #include "base/command_line.h" |
12 #include "base/file_path.h" | 10 #include "base/file_path.h" |
13 #include "base/file_util.h" | 11 #include "base/file_util.h" |
14 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
15 #include "base/logging.h" | 13 #include "base/logging.h" |
16 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
17 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
18 #include "base/string16.h" | 16 #include "base/string16.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 157 } |
160 ~ExtensionConfig() { } | 158 ~ExtensionConfig() { } |
161 | 159 |
162 // A whitelist of extensions that can script anywhere. Do not add to this | 160 // A whitelist of extensions that can script anywhere. Do not add to this |
163 // list (except in tests) without consulting the Extensions team first. | 161 // list (except in tests) without consulting the Extensions team first. |
164 // Note: Component extensions have this right implicitly and do not need to be | 162 // Note: Component extensions have this right implicitly and do not need to be |
165 // added to this list. | 163 // added to this list. |
166 Extension::ScriptingWhitelist scripting_whitelist_; | 164 Extension::ScriptingWhitelist scripting_whitelist_; |
167 }; | 165 }; |
168 | 166 |
169 // Rank extension locations in a way that allows | |
170 // Extension::GetHigherPriorityLocation() to compare locations. | |
171 // An extension installed from two locations will have the location | |
172 // with the higher rank, as returned by this function. The actual | |
173 // integer values may change, and should never be persisted. | |
174 int GetLocationRank(Extension::Location location) { | |
175 const int kInvalidRank = -1; | |
176 int rank = kInvalidRank; // Will CHECK that rank is not kInvalidRank. | |
177 | |
178 switch (location) { | |
179 // Component extensions can not be overriden by any other type. | |
180 case Extension::COMPONENT: | |
181 rank = 6; | |
182 break; | |
183 | |
184 // Policy controlled extensions may not be overridden by any type | |
185 // that is not part of chrome. | |
186 case Extension::EXTERNAL_POLICY_DOWNLOAD: | |
187 rank = 5; | |
188 break; | |
189 | |
190 // A developer-loaded extension should override any installed type | |
191 // that a user can disable. | |
192 case Extension::LOAD: | |
193 rank = 4; | |
194 break; | |
195 | |
196 // The relative priority of various external sources is not important, | |
197 // but having some order ensures deterministic behavior. | |
198 case Extension::EXTERNAL_REGISTRY: | |
199 rank = 3; | |
200 break; | |
201 | |
202 case Extension::EXTERNAL_PREF: | |
203 rank = 2; | |
204 break; | |
205 | |
206 case Extension::EXTERNAL_PREF_DOWNLOAD: | |
207 rank = 1; | |
208 break; | |
209 | |
210 // User installed extensions are overridden by any external type. | |
211 case Extension::INTERNAL: | |
212 rank = 0; | |
213 break; | |
214 | |
215 default: | |
216 NOTREACHED() << "Need to add new extension locaton " << location; | |
217 } | |
218 | |
219 CHECK(rank != kInvalidRank); | |
220 return rank; | |
221 } | |
222 | |
223 bool ReadLaunchDimension(const extensions::Manifest* manifest, | 167 bool ReadLaunchDimension(const extensions::Manifest* manifest, |
224 const char* key, | 168 const char* key, |
225 int* target, | 169 int* target, |
226 bool is_valid_container, | 170 bool is_valid_container, |
227 string16* error) { | 171 string16* error) { |
228 Value* temp = NULL; | 172 Value* temp = NULL; |
229 if (manifest->Get(key, &temp)) { | 173 if (manifest->Get(key, &temp)) { |
230 if (!is_valid_container) { | 174 if (!is_valid_container) { |
231 *error = ErrorUtils::FormatErrorMessageUTF16( | 175 *error = ErrorUtils::FormatErrorMessageUTF16( |
232 errors::kInvalidLaunchValueContainer, | 176 errors::kInvalidLaunchValueContainer, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 256 |
313 Extension::Requirements::~Requirements() {} | 257 Extension::Requirements::~Requirements() {} |
314 | 258 |
315 Extension::OAuth2Info::OAuth2Info() {} | 259 Extension::OAuth2Info::OAuth2Info() {} |
316 Extension::OAuth2Info::~OAuth2Info() {} | 260 Extension::OAuth2Info::~OAuth2Info() {} |
317 | 261 |
318 // | 262 // |
319 // Extension | 263 // Extension |
320 // | 264 // |
321 | 265 |
322 bool Extension::InstallWarning::operator==(const InstallWarning& other) const { | |
323 return format == other.format && message == other.message; | |
324 } | |
325 | |
326 // static | 266 // static |
327 scoped_refptr<Extension> Extension::Create(const FilePath& path, | 267 scoped_refptr<Extension> Extension::Create(const FilePath& path, |
328 Location location, | 268 Manifest::Location location, |
329 const DictionaryValue& value, | 269 const DictionaryValue& value, |
330 int flags, | 270 int flags, |
331 std::string* utf8_error) { | 271 std::string* utf8_error) { |
332 return Extension::Create(path, | 272 return Extension::Create(path, |
333 location, | 273 location, |
334 value, | 274 value, |
335 flags, | 275 flags, |
336 std::string(), // ID is ignored if empty. | 276 std::string(), // ID is ignored if empty. |
337 utf8_error); | 277 utf8_error); |
338 } | 278 } |
339 | 279 |
340 scoped_refptr<Extension> Extension::Create(const FilePath& path, | 280 scoped_refptr<Extension> Extension::Create(const FilePath& path, |
341 Location location, | 281 Manifest::Location location, |
342 const DictionaryValue& value, | 282 const DictionaryValue& value, |
343 int flags, | 283 int flags, |
344 const std::string& explicit_id, | 284 const std::string& explicit_id, |
345 std::string* utf8_error) { | 285 std::string* utf8_error) { |
346 DCHECK(utf8_error); | 286 DCHECK(utf8_error); |
347 string16 error; | 287 string16 error; |
348 scoped_ptr<extensions::Manifest> manifest( | 288 scoped_ptr<extensions::Manifest> manifest( |
349 new extensions::Manifest(location, | 289 new extensions::Manifest(location, |
350 scoped_ptr<DictionaryValue>(value.DeepCopy()))); | 290 scoped_ptr<DictionaryValue>(value.DeepCopy()))); |
351 | 291 |
352 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) { | 292 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) { |
353 *utf8_error = UTF16ToUTF8(error); | 293 *utf8_error = UTF16ToUTF8(error); |
354 return NULL; | 294 return NULL; |
355 } | 295 } |
356 | 296 |
357 InstallWarningVector install_warnings; | 297 std::vector<InstallWarning> install_warnings; |
358 manifest->ValidateManifest(utf8_error, &install_warnings); | 298 manifest->ValidateManifest(utf8_error, &install_warnings); |
359 if (!utf8_error->empty()) | 299 if (!utf8_error->empty()) |
360 return NULL; | 300 return NULL; |
361 | 301 |
362 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); | 302 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); |
363 extension->install_warnings_.swap(install_warnings); | 303 extension->install_warnings_.swap(install_warnings); |
364 | 304 |
365 if (!extension->InitFromValue(flags, &error)) { | 305 if (!extension->InitFromValue(flags, &error)) { |
366 *utf8_error = UTF16ToUTF8(error); | 306 *utf8_error = UTF16ToUTF8(error); |
367 return NULL; | 307 return NULL; |
368 } | 308 } |
369 | 309 |
370 if (!extension->CheckPlatformAppFeatures(utf8_error) || | 310 if (!extension->CheckPlatformAppFeatures(utf8_error) || |
371 !extension->CheckConflictingFeatures(utf8_error)) { | 311 !extension->CheckConflictingFeatures(utf8_error)) { |
372 return NULL; | 312 return NULL; |
373 } | 313 } |
374 | 314 |
375 return extension; | 315 return extension; |
376 } | 316 } |
377 | 317 |
378 // static | 318 // static |
379 Extension::Location Extension::GetHigherPriorityLocation( | |
380 Extension::Location loc1, Extension::Location loc2) { | |
381 if (loc1 == loc2) | |
382 return loc1; | |
383 | |
384 int loc1_rank = GetLocationRank(loc1); | |
385 int loc2_rank = GetLocationRank(loc2); | |
386 | |
387 // If two different locations have the same rank, then we can not | |
388 // deterministicly choose a location. | |
389 CHECK(loc1_rank != loc2_rank); | |
390 | |
391 // Highest rank has highest priority. | |
392 return (loc1_rank > loc2_rank ? loc1 : loc2 ); | |
393 } | |
394 | |
395 // static | |
396 bool Extension::IdIsValid(const std::string& id) { | 319 bool Extension::IdIsValid(const std::string& id) { |
397 // Verify that the id is legal. | 320 // Verify that the id is legal. |
398 if (id.size() != (kIdSize * 2)) | 321 if (id.size() != (kIdSize * 2)) |
399 return false; | 322 return false; |
400 | 323 |
401 // We only support lowercase IDs, because IDs can be used as URL components | 324 // We only support lowercase IDs, because IDs can be used as URL components |
402 // (where GURL will lowercase it). | 325 // (where GURL will lowercase it). |
403 std::string temp = StringToLowerASCII(id); | 326 std::string temp = StringToLowerASCII(id); |
404 for (size_t i = 0; i < temp.size(); i++) | 327 for (size_t i = 0; i < temp.size(); i++) |
405 if (temp[i] < 'a' || temp[i] > 'p') | 328 if (temp[i] < 'a' || temp[i] > 'p') |
(...skipping 27 matching lines...) Expand all Loading... |
433 info->SetString(info_keys::kDescriptionKey, description()); | 356 info->SetString(info_keys::kDescriptionKey, description()); |
434 info->SetString(info_keys::kOptionsUrlKey, | 357 info->SetString(info_keys::kOptionsUrlKey, |
435 ManifestURL::GetOptionsPage(this).possibly_invalid_spec()); | 358 ManifestURL::GetOptionsPage(this).possibly_invalid_spec()); |
436 info->SetString(info_keys::kHomepageUrlKey, | 359 info->SetString(info_keys::kHomepageUrlKey, |
437 ManifestURL::GetHomepageURL(this).possibly_invalid_spec()); | 360 ManifestURL::GetHomepageURL(this).possibly_invalid_spec()); |
438 info->SetString(info_keys::kDetailsUrlKey, | 361 info->SetString(info_keys::kDetailsUrlKey, |
439 ManifestURL::GetDetailsURL(this).possibly_invalid_spec()); | 362 ManifestURL::GetDetailsURL(this).possibly_invalid_spec()); |
440 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); | 363 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); |
441 } | 364 } |
442 | 365 |
443 Extension::Type Extension::GetType() const { | 366 Manifest::Type Extension::GetType() const { |
444 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type(); | 367 return converted_from_user_script() ? |
| 368 Manifest::TYPE_USER_SCRIPT : manifest_->type(); |
445 } | 369 } |
446 | 370 |
447 // static | 371 // static |
448 GURL Extension::GetResourceURL(const GURL& extension_url, | 372 GURL Extension::GetResourceURL(const GURL& extension_url, |
449 const std::string& relative_path) { | 373 const std::string& relative_path) { |
450 DCHECK(extension_url.SchemeIs(extensions::kExtensionScheme)); | 374 DCHECK(extension_url.SchemeIs(extensions::kExtensionScheme)); |
451 DCHECK_EQ("/", extension_url.path()); | 375 DCHECK_EQ("/", extension_url.path()); |
452 | 376 |
453 std::string path = relative_path; | 377 std::string path = relative_path; |
454 | 378 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 return runtime_data_.GetActivePermissions()-> | 734 return runtime_data_.GetActivePermissions()-> |
811 CheckAPIPermissionWithParam(permission, param); | 735 CheckAPIPermissionWithParam(permission, param); |
812 } | 736 } |
813 | 737 |
814 const URLPatternSet& Extension::GetEffectiveHostPermissions() const { | 738 const URLPatternSet& Extension::GetEffectiveHostPermissions() const { |
815 base::AutoLock auto_lock(runtime_data_lock_); | 739 base::AutoLock auto_lock(runtime_data_lock_); |
816 return runtime_data_.GetActivePermissions()->effective_hosts(); | 740 return runtime_data_.GetActivePermissions()->effective_hosts(); |
817 } | 741 } |
818 | 742 |
819 bool Extension::CanSilentlyIncreasePermissions() const { | 743 bool Extension::CanSilentlyIncreasePermissions() const { |
820 return location() != INTERNAL; | 744 return location() != Manifest::INTERNAL; |
821 } | 745 } |
822 | 746 |
823 bool Extension::HasHostPermission(const GURL& url) const { | 747 bool Extension::HasHostPermission(const GURL& url) const { |
824 if (url.SchemeIs(chrome::kChromeUIScheme) && | 748 if (url.SchemeIs(chrome::kChromeUIScheme) && |
825 url.host() != chrome::kChromeUIFaviconHost && | 749 url.host() != chrome::kChromeUIFaviconHost && |
826 url.host() != chrome::kChromeUIThumbnailHost && | 750 url.host() != chrome::kChromeUIThumbnailHost && |
827 location() != Extension::COMPONENT) { | 751 location() != Manifest::COMPONENT) { |
828 return false; | 752 return false; |
829 } | 753 } |
830 | 754 |
831 base::AutoLock auto_lock(runtime_data_lock_); | 755 base::AutoLock auto_lock(runtime_data_lock_); |
832 return runtime_data_.GetActivePermissions()-> | 756 return runtime_data_.GetActivePermissions()-> |
833 HasExplicitAccessToOrigin(url); | 757 HasExplicitAccessToOrigin(url); |
834 } | 758 } |
835 | 759 |
836 bool Extension::HasEffectiveAccessToAllHosts() const { | 760 bool Extension::HasEffectiveAccessToAllHosts() const { |
837 base::AutoLock auto_lock(runtime_data_lock_); | 761 base::AutoLock auto_lock(runtime_data_lock_); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 Extension::GetActivePermissions() const { | 799 Extension::GetActivePermissions() const { |
876 base::AutoLock auto_lock(runtime_data_lock_); | 800 base::AutoLock auto_lock(runtime_data_lock_); |
877 return runtime_data_.GetActivePermissions(); | 801 return runtime_data_.GetActivePermissions(); |
878 } | 802 } |
879 | 803 |
880 bool Extension::ShowConfigureContextMenus() const { | 804 bool Extension::ShowConfigureContextMenus() const { |
881 // Don't show context menu for component extensions. We might want to show | 805 // Don't show context menu for component extensions. We might want to show |
882 // options for component extension button but now there is no component | 806 // options for component extension button but now there is no component |
883 // extension with options. All other menu items like uninstall have | 807 // extension with options. All other menu items like uninstall have |
884 // no sense for component extensions. | 808 // no sense for component extensions. |
885 return location() != Extension::COMPONENT; | 809 return location() != Manifest::COMPONENT; |
886 } | 810 } |
887 | 811 |
888 std::set<FilePath> Extension::GetBrowserImages() const { | 812 std::set<FilePath> Extension::GetBrowserImages() const { |
889 std::set<FilePath> image_paths; | 813 std::set<FilePath> image_paths; |
890 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| | 814 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| |
891 // indicate that we're doing something wrong. | 815 // indicate that we're doing something wrong. |
892 | 816 |
893 // Extension icons. | 817 // Extension icons. |
894 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); | 818 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); |
895 iter != icons().map().end(); ++iter) { | 819 iter != icons().map().end(); ++iter) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 | 954 |
1031 if (error) { | 955 if (error) { |
1032 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, | 956 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
1033 document_url.spec()); | 957 document_url.spec()); |
1034 } | 958 } |
1035 | 959 |
1036 return false; | 960 return false; |
1037 } | 961 } |
1038 | 962 |
1039 bool Extension::CanExecuteScriptEverywhere() const { | 963 bool Extension::CanExecuteScriptEverywhere() const { |
1040 if (location() == Extension::COMPONENT) | 964 if (location() == Manifest::COMPONENT) |
1041 return true; | 965 return true; |
1042 | 966 |
1043 ScriptingWhitelist* whitelist = ExtensionConfig::GetInstance()->whitelist(); | 967 ScriptingWhitelist* whitelist = ExtensionConfig::GetInstance()->whitelist(); |
1044 | 968 |
1045 for (ScriptingWhitelist::const_iterator it = whitelist->begin(); | 969 for (ScriptingWhitelist::const_iterator it = whitelist->begin(); |
1046 it != whitelist->end(); ++it) { | 970 it != whitelist->end(); ++it) { |
1047 if (id() == *it) { | 971 if (id() == *it) { |
1048 return true; | 972 return true; |
1049 } | 973 } |
1050 } | 974 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 | 1037 |
1114 // Disallow extensions with native code plugins. | 1038 // Disallow extensions with native code plugins. |
1115 // | 1039 // |
1116 // TODO(akalin): Relax this restriction once we've put in UI to | 1040 // TODO(akalin): Relax this restriction once we've put in UI to |
1117 // approve synced extensions. | 1041 // approve synced extensions. |
1118 if (!plugins().empty()) { | 1042 if (!plugins().empty()) { |
1119 return SYNC_TYPE_NONE; | 1043 return SYNC_TYPE_NONE; |
1120 } | 1044 } |
1121 | 1045 |
1122 switch (GetType()) { | 1046 switch (GetType()) { |
1123 case Extension::TYPE_EXTENSION: | 1047 case Manifest::TYPE_EXTENSION: |
1124 return SYNC_TYPE_EXTENSION; | 1048 return SYNC_TYPE_EXTENSION; |
1125 | 1049 |
1126 case Extension::TYPE_USER_SCRIPT: | 1050 case Manifest::TYPE_USER_SCRIPT: |
1127 // We only want to sync user scripts with gallery update URLs. | 1051 // We only want to sync user scripts with gallery update URLs. |
1128 if (UpdatesFromGallery()) | 1052 if (UpdatesFromGallery()) |
1129 return SYNC_TYPE_EXTENSION; | 1053 return SYNC_TYPE_EXTENSION; |
1130 else | 1054 else |
1131 return SYNC_TYPE_NONE; | 1055 return SYNC_TYPE_NONE; |
1132 | 1056 |
1133 case Extension::TYPE_HOSTED_APP: | 1057 case Manifest::TYPE_HOSTED_APP: |
1134 case Extension::TYPE_LEGACY_PACKAGED_APP: | 1058 case Manifest::TYPE_LEGACY_PACKAGED_APP: |
1135 case Extension::TYPE_PLATFORM_APP: | 1059 case Manifest::TYPE_PLATFORM_APP: |
1136 return SYNC_TYPE_APP; | 1060 return SYNC_TYPE_APP; |
1137 | 1061 |
1138 default: | 1062 default: |
1139 return SYNC_TYPE_NONE; | 1063 return SYNC_TYPE_NONE; |
1140 } | 1064 } |
1141 } | 1065 } |
1142 | 1066 |
1143 bool Extension::IsSyncable() const { | 1067 bool Extension::IsSyncable() const { |
1144 // TODO(akalin): Figure out if we need to allow some other types. | 1068 // TODO(akalin): Figure out if we need to allow some other types. |
1145 | 1069 |
1146 // Default apps are not synced because otherwise they will pollute profiles | 1070 // Default apps are not synced because otherwise they will pollute profiles |
1147 // that don't already have them. Specially, if a user doesn't have default | 1071 // that don't already have them. Specially, if a user doesn't have default |
1148 // apps, creates a new profile (which get default apps) and then enables sync | 1072 // apps, creates a new profile (which get default apps) and then enables sync |
1149 // for it, then their profile everywhere gets the default apps. | 1073 // for it, then their profile everywhere gets the default apps. |
1150 bool is_syncable = (location() == Extension::INTERNAL && | 1074 bool is_syncable = (location() == Manifest::INTERNAL && |
1151 !was_installed_by_default()); | 1075 !was_installed_by_default()); |
1152 // Sync the chrome web store to maintain its position on the new tab page. | 1076 // Sync the chrome web store to maintain its position on the new tab page. |
1153 is_syncable |= (id() == extension_misc::kWebStoreAppId); | 1077 is_syncable |= (id() == extension_misc::kWebStoreAppId); |
1154 return is_syncable; | 1078 return is_syncable; |
1155 } | 1079 } |
1156 | 1080 |
1157 bool Extension::RequiresSortOrdinal() const { | 1081 bool Extension::RequiresSortOrdinal() const { |
1158 return is_app() && (display_in_launcher_ || display_in_new_tab_page_); | 1082 return is_app() && (display_in_launcher_ || display_in_new_tab_page_); |
1159 } | 1083 } |
1160 | 1084 |
1161 bool Extension::ShouldDisplayInAppLauncher() const { | 1085 bool Extension::ShouldDisplayInAppLauncher() const { |
1162 // Only apps should be displayed in the launcher. | 1086 // Only apps should be displayed in the launcher. |
1163 return is_app() && display_in_launcher_; | 1087 return is_app() && display_in_launcher_; |
1164 } | 1088 } |
1165 | 1089 |
1166 bool Extension::ShouldDisplayInNewTabPage() const { | 1090 bool Extension::ShouldDisplayInNewTabPage() const { |
1167 // Only apps should be displayed on the NTP. | 1091 // Only apps should be displayed on the NTP. |
1168 return is_app() && display_in_new_tab_page_; | 1092 return is_app() && display_in_new_tab_page_; |
1169 } | 1093 } |
1170 | 1094 |
1171 bool Extension::ShouldDisplayInExtensionSettings() const { | 1095 bool Extension::ShouldDisplayInExtensionSettings() const { |
1172 // Don't show for themes since the settings UI isn't really useful for them. | 1096 // Don't show for themes since the settings UI isn't really useful for them. |
1173 if (is_theme()) | 1097 if (is_theme()) |
1174 return false; | 1098 return false; |
1175 | 1099 |
1176 // Don't show component extensions because they are only extensions as an | 1100 // Don't show component extensions because they are only extensions as an |
1177 // implementation detail of Chrome. | 1101 // implementation detail of Chrome. |
1178 if (location() == Extension::COMPONENT && | 1102 if (location() == Manifest::COMPONENT && |
1179 !CommandLine::ForCurrentProcess()->HasSwitch( | 1103 !CommandLine::ForCurrentProcess()->HasSwitch( |
1180 switches::kShowComponentExtensionOptions)) { | 1104 switches::kShowComponentExtensionOptions)) { |
1181 return false; | 1105 return false; |
1182 } | 1106 } |
1183 | 1107 |
1184 // Always show unpacked extensions and apps. | 1108 // Always show unpacked extensions and apps. |
1185 if (location() == Extension::LOAD) | 1109 if (location() == Manifest::LOAD) |
1186 return true; | 1110 return true; |
1187 | 1111 |
1188 // Unless they are unpacked, never show hosted apps. Note: We intentionally | 1112 // Unless they are unpacked, never show hosted apps. Note: We intentionally |
1189 // show packaged apps and platform apps because there are some pieces of | 1113 // show packaged apps and platform apps because there are some pieces of |
1190 // functionality that are only available in chrome://extensions/ but which | 1114 // functionality that are only available in chrome://extensions/ but which |
1191 // are needed for packaged and platform apps. For example, inspecting | 1115 // are needed for packaged and platform apps. For example, inspecting |
1192 // background pages. See http://crbug.com/116134. | 1116 // background pages. See http://crbug.com/116134. |
1193 if (is_hosted_app()) | 1117 if (is_hosted_app()) |
1194 return false; | 1118 return false; |
1195 | 1119 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 return iter->second.get(); | 1155 return iter->second.get(); |
1232 return NULL; | 1156 return NULL; |
1233 } | 1157 } |
1234 | 1158 |
1235 void Extension::SetManifestData(const std::string& key, | 1159 void Extension::SetManifestData(const std::string& key, |
1236 Extension::ManifestData* data) { | 1160 Extension::ManifestData* data) { |
1237 DCHECK(!finished_parsing_manifest_ && thread_checker_.CalledOnValidThread()); | 1161 DCHECK(!finished_parsing_manifest_ && thread_checker_.CalledOnValidThread()); |
1238 manifest_data_[key] = linked_ptr<ManifestData>(data); | 1162 manifest_data_[key] = linked_ptr<ManifestData>(data); |
1239 } | 1163 } |
1240 | 1164 |
1241 Extension::Location Extension::location() const { | 1165 Manifest::Location Extension::location() const { |
1242 return manifest_->location(); | 1166 return manifest_->location(); |
1243 } | 1167 } |
1244 | 1168 |
1245 const std::string& Extension::id() const { | 1169 const std::string& Extension::id() const { |
1246 return manifest_->extension_id(); | 1170 return manifest_->extension_id(); |
1247 } | 1171 } |
1248 | 1172 |
1249 const std::string Extension::VersionString() const { | 1173 const std::string Extension::VersionString() const { |
1250 return version()->GetString(); | 1174 return version()->GetString(); |
1251 } | 1175 } |
1252 | 1176 |
1253 void Extension::AddInstallWarning(const InstallWarning& new_warning) { | 1177 void Extension::AddInstallWarning(const InstallWarning& new_warning) { |
1254 install_warnings_.push_back(new_warning); | 1178 install_warnings_.push_back(new_warning); |
1255 } | 1179 } |
1256 | 1180 |
1257 void Extension::AddInstallWarnings( | 1181 void Extension::AddInstallWarnings( |
1258 const InstallWarningVector& new_warnings) { | 1182 const std::vector<InstallWarning>& new_warnings) { |
1259 install_warnings_.insert(install_warnings_.end(), | 1183 install_warnings_.insert(install_warnings_.end(), |
1260 new_warnings.begin(), new_warnings.end()); | 1184 new_warnings.begin(), new_warnings.end()); |
1261 } | 1185 } |
1262 | 1186 |
1263 bool Extension::is_platform_app() const { | 1187 bool Extension::is_platform_app() const { |
1264 return manifest_->is_platform_app(); | 1188 return manifest_->is_platform_app(); |
1265 } | 1189 } |
1266 | 1190 |
1267 bool Extension::is_hosted_app() const { | 1191 bool Extension::is_hosted_app() const { |
1268 return manifest()->is_hosted_app(); | 1192 return manifest()->is_hosted_app(); |
(...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2965 | 2889 |
2966 URLPattern pattern(kValidWebExtentSchemes); | 2890 URLPattern pattern(kValidWebExtentSchemes); |
2967 URLPattern::ParseResult result = pattern.Parse(new_url.spec()); | 2891 URLPattern::ParseResult result = pattern.Parse(new_url.spec()); |
2968 DCHECK_EQ(result, URLPattern::PARSE_SUCCESS); | 2892 DCHECK_EQ(result, URLPattern::PARSE_SUCCESS); |
2969 pattern.SetPath(pattern.path() + '*'); | 2893 pattern.SetPath(pattern.path() + '*'); |
2970 extent_.AddPattern(pattern); | 2894 extent_.AddPattern(pattern); |
2971 } | 2895 } |
2972 } | 2896 } |
2973 | 2897 |
2974 bool Extension::CanSpecifyExperimentalPermission() const { | 2898 bool Extension::CanSpecifyExperimentalPermission() const { |
2975 if (location() == Extension::COMPONENT) | 2899 if (location() == Manifest::COMPONENT) |
2976 return true; | 2900 return true; |
2977 | 2901 |
2978 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2902 if (CommandLine::ForCurrentProcess()->HasSwitch( |
2979 switches::kEnableExperimentalExtensionApis)) { | 2903 switches::kEnableExperimentalExtensionApis)) { |
2980 return true; | 2904 return true; |
2981 } | 2905 } |
2982 | 2906 |
2983 // We rely on the webstore to check access to experimental. This way we can | 2907 // We rely on the webstore to check access to experimental. This way we can |
2984 // whitelist extensions to have access to experimental in just the store, and | 2908 // whitelist extensions to have access to experimental in just the store, and |
2985 // not have to push a new version of the client. | 2909 // not have to push a new version of the client. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3072 bool Extension::CheckConflictingFeatures(std::string* utf8_error) const { | 2996 bool Extension::CheckConflictingFeatures(std::string* utf8_error) const { |
3073 if (has_lazy_background_page() && | 2997 if (has_lazy_background_page() && |
3074 HasAPIPermission(APIPermission::kWebRequest)) { | 2998 HasAPIPermission(APIPermission::kWebRequest)) { |
3075 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; | 2999 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; |
3076 return false; | 3000 return false; |
3077 } | 3001 } |
3078 | 3002 |
3079 return true; | 3003 return true; |
3080 } | 3004 } |
3081 | 3005 |
3082 void PrintTo(const Extension::InstallWarning& warning, ::std::ostream* os) { | |
3083 *os << "InstallWarning("; | |
3084 switch (warning.format) { | |
3085 case Extension::InstallWarning::FORMAT_TEXT: | |
3086 *os << "FORMAT_TEXT, \""; | |
3087 break; | |
3088 case Extension::InstallWarning::FORMAT_HTML: | |
3089 *os << "FORMAT_HTML, \""; | |
3090 break; | |
3091 } | |
3092 // This is just for test error messages, so no need to escape '"' | |
3093 // characters inside the message. | |
3094 *os << warning.message << "\")"; | |
3095 } | |
3096 | |
3097 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, | 3006 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, |
3098 const std::string& id, | 3007 const std::string& id, |
3099 const FilePath& path, | 3008 const FilePath& path, |
3100 Extension::Location location) | 3009 Manifest::Location location) |
3101 : extension_id(id), | 3010 : extension_id(id), |
3102 extension_path(path), | 3011 extension_path(path), |
3103 extension_location(location) { | 3012 extension_location(location) { |
3104 if (manifest) | 3013 if (manifest) |
3105 extension_manifest.reset(manifest->DeepCopy()); | 3014 extension_manifest.reset(manifest->DeepCopy()); |
3106 } | 3015 } |
3107 | 3016 |
3108 ExtensionInfo::~ExtensionInfo() {} | 3017 ExtensionInfo::~ExtensionInfo() {} |
3109 | 3018 |
3110 UnloadedExtensionInfo::UnloadedExtensionInfo( | 3019 UnloadedExtensionInfo::UnloadedExtensionInfo( |
3111 const Extension* extension, | 3020 const Extension* extension, |
3112 extension_misc::UnloadedExtensionReason reason) | 3021 extension_misc::UnloadedExtensionReason reason) |
3113 : reason(reason), | 3022 : reason(reason), |
3114 already_disabled(false), | 3023 already_disabled(false), |
3115 extension(extension) {} | 3024 extension(extension) {} |
3116 | 3025 |
3117 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3026 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3118 const Extension* extension, | 3027 const Extension* extension, |
3119 const PermissionSet* permissions, | 3028 const PermissionSet* permissions, |
3120 Reason reason) | 3029 Reason reason) |
3121 : reason(reason), | 3030 : reason(reason), |
3122 extension(extension), | 3031 extension(extension), |
3123 permissions(permissions) {} | 3032 permissions(permissions) {} |
3124 | 3033 |
3125 } // namespace extensions | 3034 } // namespace extensions |
OLD | NEW |