| 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> | 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 159 } |
| 160 ~ExtensionConfig() { } | 160 ~ExtensionConfig() { } |
| 161 | 161 |
| 162 // A whitelist of extensions that can script anywhere. Do not add to this | 162 // A whitelist of extensions that can script anywhere. Do not add to this |
| 163 // list (except in tests) without consulting the Extensions team first. | 163 // list (except in tests) without consulting the Extensions team first. |
| 164 // Note: Component extensions have this right implicitly and do not need to be | 164 // Note: Component extensions have this right implicitly and do not need to be |
| 165 // added to this list. | 165 // added to this list. |
| 166 Extension::ScriptingWhitelist scripting_whitelist_; | 166 Extension::ScriptingWhitelist scripting_whitelist_; |
| 167 }; | 167 }; |
| 168 | 168 |
| 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, | 169 bool ReadLaunchDimension(const extensions::Manifest* manifest, |
| 224 const char* key, | 170 const char* key, |
| 225 int* target, | 171 int* target, |
| 226 bool is_valid_container, | 172 bool is_valid_container, |
| 227 string16* error) { | 173 string16* error) { |
| 228 Value* temp = NULL; | 174 Value* temp = NULL; |
| 229 if (manifest->Get(key, &temp)) { | 175 if (manifest->Get(key, &temp)) { |
| 230 if (!is_valid_container) { | 176 if (!is_valid_container) { |
| 231 *error = ErrorUtils::FormatErrorMessageUTF16( | 177 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 232 errors::kInvalidLaunchValueContainer, | 178 errors::kInvalidLaunchValueContainer, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 258 |
| 313 Extension::Requirements::~Requirements() {} | 259 Extension::Requirements::~Requirements() {} |
| 314 | 260 |
| 315 Extension::OAuth2Info::OAuth2Info() {} | 261 Extension::OAuth2Info::OAuth2Info() {} |
| 316 Extension::OAuth2Info::~OAuth2Info() {} | 262 Extension::OAuth2Info::~OAuth2Info() {} |
| 317 | 263 |
| 318 // | 264 // |
| 319 // Extension | 265 // Extension |
| 320 // | 266 // |
| 321 | 267 |
| 322 bool Extension::InstallWarning::operator==(const InstallWarning& other) const { | |
| 323 return format == other.format && message == other.message; | |
| 324 } | |
| 325 | |
| 326 // static | 268 // static |
| 327 scoped_refptr<Extension> Extension::Create(const FilePath& path, | 269 scoped_refptr<Extension> Extension::Create(const FilePath& path, |
| 328 Location location, | 270 Manifest::Location location, |
| 329 const DictionaryValue& value, | 271 const DictionaryValue& value, |
| 330 int flags, | 272 int flags, |
| 331 std::string* utf8_error) { | 273 std::string* utf8_error) { |
| 332 return Extension::Create(path, | 274 return Extension::Create(path, |
| 333 location, | 275 location, |
| 334 value, | 276 value, |
| 335 flags, | 277 flags, |
| 336 std::string(), // ID is ignored if empty. | 278 std::string(), // ID is ignored if empty. |
| 337 utf8_error); | 279 utf8_error); |
| 338 } | 280 } |
| 339 | 281 |
| 340 scoped_refptr<Extension> Extension::Create(const FilePath& path, | 282 scoped_refptr<Extension> Extension::Create(const FilePath& path, |
| 341 Location location, | 283 Manifest::Location location, |
| 342 const DictionaryValue& value, | 284 const DictionaryValue& value, |
| 343 int flags, | 285 int flags, |
| 344 const std::string& explicit_id, | 286 const std::string& explicit_id, |
| 345 std::string* utf8_error) { | 287 std::string* utf8_error) { |
| 346 DCHECK(utf8_error); | 288 DCHECK(utf8_error); |
| 347 string16 error; | 289 string16 error; |
| 348 scoped_ptr<extensions::Manifest> manifest( | 290 scoped_ptr<extensions::Manifest> manifest( |
| 349 new extensions::Manifest(location, | 291 new extensions::Manifest(location, |
| 350 scoped_ptr<DictionaryValue>(value.DeepCopy()))); | 292 scoped_ptr<DictionaryValue>(value.DeepCopy()))); |
| 351 | 293 |
| 352 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) { | 294 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) { |
| 353 *utf8_error = UTF16ToUTF8(error); | 295 *utf8_error = UTF16ToUTF8(error); |
| 354 return NULL; | 296 return NULL; |
| 355 } | 297 } |
| 356 | 298 |
| 357 InstallWarningVector install_warnings; | 299 InstallWarning::Vector install_warnings; |
| 358 manifest->ValidateManifest(utf8_error, &install_warnings); | 300 manifest->ValidateManifest(utf8_error, &install_warnings); |
| 359 if (!utf8_error->empty()) | 301 if (!utf8_error->empty()) |
| 360 return NULL; | 302 return NULL; |
| 361 | 303 |
| 362 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); | 304 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); |
| 363 extension->install_warnings_.swap(install_warnings); | 305 extension->install_warnings_.swap(install_warnings); |
| 364 | 306 |
| 365 if (!extension->InitFromValue(flags, &error)) { | 307 if (!extension->InitFromValue(flags, &error)) { |
| 366 *utf8_error = UTF16ToUTF8(error); | 308 *utf8_error = UTF16ToUTF8(error); |
| 367 return NULL; | 309 return NULL; |
| 368 } | 310 } |
| 369 | 311 |
| 370 if (!extension->CheckPlatformAppFeatures(utf8_error) || | 312 if (!extension->CheckPlatformAppFeatures(utf8_error) || |
| 371 !extension->CheckConflictingFeatures(utf8_error)) { | 313 !extension->CheckConflictingFeatures(utf8_error)) { |
| 372 return NULL; | 314 return NULL; |
| 373 } | 315 } |
| 374 | 316 |
| 375 return extension; | 317 return extension; |
| 376 } | 318 } |
| 377 | 319 |
| 378 // static | 320 // 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) { | 321 bool Extension::IdIsValid(const std::string& id) { |
| 397 // Verify that the id is legal. | 322 // Verify that the id is legal. |
| 398 if (id.size() != (kIdSize * 2)) | 323 if (id.size() != (kIdSize * 2)) |
| 399 return false; | 324 return false; |
| 400 | 325 |
| 401 // We only support lowercase IDs, because IDs can be used as URL components | 326 // We only support lowercase IDs, because IDs can be used as URL components |
| 402 // (where GURL will lowercase it). | 327 // (where GURL will lowercase it). |
| 403 std::string temp = StringToLowerASCII(id); | 328 std::string temp = StringToLowerASCII(id); |
| 404 for (size_t i = 0; i < temp.size(); i++) | 329 for (size_t i = 0; i < temp.size(); i++) |
| 405 if (temp[i] < 'a' || temp[i] > 'p') | 330 if (temp[i] < 'a' || temp[i] > 'p') |
| (...skipping 27 matching lines...) Expand all Loading... |
| 433 info->SetString(info_keys::kDescriptionKey, description()); | 358 info->SetString(info_keys::kDescriptionKey, description()); |
| 434 info->SetString(info_keys::kOptionsUrlKey, | 359 info->SetString(info_keys::kOptionsUrlKey, |
| 435 ManifestURL::GetOptionsPage(this).possibly_invalid_spec()); | 360 ManifestURL::GetOptionsPage(this).possibly_invalid_spec()); |
| 436 info->SetString(info_keys::kHomepageUrlKey, | 361 info->SetString(info_keys::kHomepageUrlKey, |
| 437 ManifestURL::GetHomepageURL(this).possibly_invalid_spec()); | 362 ManifestURL::GetHomepageURL(this).possibly_invalid_spec()); |
| 438 info->SetString(info_keys::kDetailsUrlKey, | 363 info->SetString(info_keys::kDetailsUrlKey, |
| 439 ManifestURL::GetDetailsURL(this).possibly_invalid_spec()); | 364 ManifestURL::GetDetailsURL(this).possibly_invalid_spec()); |
| 440 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); | 365 info->SetBoolean(info_keys::kPackagedAppKey, is_platform_app()); |
| 441 } | 366 } |
| 442 | 367 |
| 443 Extension::Type Extension::GetType() const { | 368 Manifest::Type Extension::GetType() const { |
| 444 return converted_from_user_script() ? TYPE_USER_SCRIPT : manifest_->type(); | 369 return converted_from_user_script() ? |
| 370 Manifest::TYPE_USER_SCRIPT : manifest_->type(); |
| 445 } | 371 } |
| 446 | 372 |
| 447 // static | 373 // static |
| 448 GURL Extension::GetResourceURL(const GURL& extension_url, | 374 GURL Extension::GetResourceURL(const GURL& extension_url, |
| 449 const std::string& relative_path) { | 375 const std::string& relative_path) { |
| 450 DCHECK(extension_url.SchemeIs(extensions::kExtensionScheme)); | 376 DCHECK(extension_url.SchemeIs(extensions::kExtensionScheme)); |
| 451 DCHECK_EQ("/", extension_url.path()); | 377 DCHECK_EQ("/", extension_url.path()); |
| 452 | 378 |
| 453 std::string path = relative_path; | 379 std::string path = relative_path; |
| 454 | 380 |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 return runtime_data_.GetActivePermissions()-> | 736 return runtime_data_.GetActivePermissions()-> |
| 811 CheckAPIPermissionWithParam(permission, param); | 737 CheckAPIPermissionWithParam(permission, param); |
| 812 } | 738 } |
| 813 | 739 |
| 814 const URLPatternSet& Extension::GetEffectiveHostPermissions() const { | 740 const URLPatternSet& Extension::GetEffectiveHostPermissions() const { |
| 815 base::AutoLock auto_lock(runtime_data_lock_); | 741 base::AutoLock auto_lock(runtime_data_lock_); |
| 816 return runtime_data_.GetActivePermissions()->effective_hosts(); | 742 return runtime_data_.GetActivePermissions()->effective_hosts(); |
| 817 } | 743 } |
| 818 | 744 |
| 819 bool Extension::CanSilentlyIncreasePermissions() const { | 745 bool Extension::CanSilentlyIncreasePermissions() const { |
| 820 return location() != INTERNAL; | 746 return location() != Manifest::INTERNAL; |
| 821 } | 747 } |
| 822 | 748 |
| 823 bool Extension::HasHostPermission(const GURL& url) const { | 749 bool Extension::HasHostPermission(const GURL& url) const { |
| 824 if (url.SchemeIs(chrome::kChromeUIScheme) && | 750 if (url.SchemeIs(chrome::kChromeUIScheme) && |
| 825 url.host() != chrome::kChromeUIFaviconHost && | 751 url.host() != chrome::kChromeUIFaviconHost && |
| 826 url.host() != chrome::kChromeUIThumbnailHost && | 752 url.host() != chrome::kChromeUIThumbnailHost && |
| 827 location() != Extension::COMPONENT) { | 753 location() != Manifest::COMPONENT) { |
| 828 return false; | 754 return false; |
| 829 } | 755 } |
| 830 | 756 |
| 831 base::AutoLock auto_lock(runtime_data_lock_); | 757 base::AutoLock auto_lock(runtime_data_lock_); |
| 832 return runtime_data_.GetActivePermissions()-> | 758 return runtime_data_.GetActivePermissions()-> |
| 833 HasExplicitAccessToOrigin(url); | 759 HasExplicitAccessToOrigin(url); |
| 834 } | 760 } |
| 835 | 761 |
| 836 bool Extension::HasEffectiveAccessToAllHosts() const { | 762 bool Extension::HasEffectiveAccessToAllHosts() const { |
| 837 base::AutoLock auto_lock(runtime_data_lock_); | 763 base::AutoLock auto_lock(runtime_data_lock_); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 Extension::GetActivePermissions() const { | 801 Extension::GetActivePermissions() const { |
| 876 base::AutoLock auto_lock(runtime_data_lock_); | 802 base::AutoLock auto_lock(runtime_data_lock_); |
| 877 return runtime_data_.GetActivePermissions(); | 803 return runtime_data_.GetActivePermissions(); |
| 878 } | 804 } |
| 879 | 805 |
| 880 bool Extension::ShowConfigureContextMenus() const { | 806 bool Extension::ShowConfigureContextMenus() const { |
| 881 // Don't show context menu for component extensions. We might want to show | 807 // 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 | 808 // options for component extension button but now there is no component |
| 883 // extension with options. All other menu items like uninstall have | 809 // extension with options. All other menu items like uninstall have |
| 884 // no sense for component extensions. | 810 // no sense for component extensions. |
| 885 return location() != Extension::COMPONENT; | 811 return location() != Manifest::COMPONENT; |
| 886 } | 812 } |
| 887 | 813 |
| 888 std::set<FilePath> Extension::GetBrowserImages() const { | 814 std::set<FilePath> Extension::GetBrowserImages() const { |
| 889 std::set<FilePath> image_paths; | 815 std::set<FilePath> image_paths; |
| 890 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| | 816 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| |
| 891 // indicate that we're doing something wrong. | 817 // indicate that we're doing something wrong. |
| 892 | 818 |
| 893 // Extension icons. | 819 // Extension icons. |
| 894 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); | 820 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); |
| 895 iter != icons().map().end(); ++iter) { | 821 iter != icons().map().end(); ++iter) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 | 956 |
| 1031 if (error) { | 957 if (error) { |
| 1032 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, | 958 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
| 1033 document_url.spec()); | 959 document_url.spec()); |
| 1034 } | 960 } |
| 1035 | 961 |
| 1036 return false; | 962 return false; |
| 1037 } | 963 } |
| 1038 | 964 |
| 1039 bool Extension::CanExecuteScriptEverywhere() const { | 965 bool Extension::CanExecuteScriptEverywhere() const { |
| 1040 if (location() == Extension::COMPONENT) | 966 if (location() == Manifest::COMPONENT) |
| 1041 return true; | 967 return true; |
| 1042 | 968 |
| 1043 ScriptingWhitelist* whitelist = ExtensionConfig::GetInstance()->whitelist(); | 969 ScriptingWhitelist* whitelist = ExtensionConfig::GetInstance()->whitelist(); |
| 1044 | 970 |
| 1045 for (ScriptingWhitelist::const_iterator it = whitelist->begin(); | 971 for (ScriptingWhitelist::const_iterator it = whitelist->begin(); |
| 1046 it != whitelist->end(); ++it) { | 972 it != whitelist->end(); ++it) { |
| 1047 if (id() == *it) { | 973 if (id() == *it) { |
| 1048 return true; | 974 return true; |
| 1049 } | 975 } |
| 1050 } | 976 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 | 1039 |
| 1114 // Disallow extensions with native code plugins. | 1040 // Disallow extensions with native code plugins. |
| 1115 // | 1041 // |
| 1116 // TODO(akalin): Relax this restriction once we've put in UI to | 1042 // TODO(akalin): Relax this restriction once we've put in UI to |
| 1117 // approve synced extensions. | 1043 // approve synced extensions. |
| 1118 if (!plugins().empty()) { | 1044 if (!plugins().empty()) { |
| 1119 return SYNC_TYPE_NONE; | 1045 return SYNC_TYPE_NONE; |
| 1120 } | 1046 } |
| 1121 | 1047 |
| 1122 switch (GetType()) { | 1048 switch (GetType()) { |
| 1123 case Extension::TYPE_EXTENSION: | 1049 case Manifest::TYPE_EXTENSION: |
| 1124 return SYNC_TYPE_EXTENSION; | 1050 return SYNC_TYPE_EXTENSION; |
| 1125 | 1051 |
| 1126 case Extension::TYPE_USER_SCRIPT: | 1052 case Manifest::TYPE_USER_SCRIPT: |
| 1127 // We only want to sync user scripts with gallery update URLs. | 1053 // We only want to sync user scripts with gallery update URLs. |
| 1128 if (UpdatesFromGallery()) | 1054 if (UpdatesFromGallery()) |
| 1129 return SYNC_TYPE_EXTENSION; | 1055 return SYNC_TYPE_EXTENSION; |
| 1130 else | 1056 else |
| 1131 return SYNC_TYPE_NONE; | 1057 return SYNC_TYPE_NONE; |
| 1132 | 1058 |
| 1133 case Extension::TYPE_HOSTED_APP: | 1059 case Manifest::TYPE_HOSTED_APP: |
| 1134 case Extension::TYPE_LEGACY_PACKAGED_APP: | 1060 case Manifest::TYPE_LEGACY_PACKAGED_APP: |
| 1135 case Extension::TYPE_PLATFORM_APP: | 1061 case Manifest::TYPE_PLATFORM_APP: |
| 1136 return SYNC_TYPE_APP; | 1062 return SYNC_TYPE_APP; |
| 1137 | 1063 |
| 1138 default: | 1064 default: |
| 1139 return SYNC_TYPE_NONE; | 1065 return SYNC_TYPE_NONE; |
| 1140 } | 1066 } |
| 1141 } | 1067 } |
| 1142 | 1068 |
| 1143 bool Extension::IsSyncable() const { | 1069 bool Extension::IsSyncable() const { |
| 1144 // TODO(akalin): Figure out if we need to allow some other types. | 1070 // TODO(akalin): Figure out if we need to allow some other types. |
| 1145 | 1071 |
| 1146 // Default apps are not synced because otherwise they will pollute profiles | 1072 // 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 | 1073 // 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 | 1074 // apps, creates a new profile (which get default apps) and then enables sync |
| 1149 // for it, then their profile everywhere gets the default apps. | 1075 // for it, then their profile everywhere gets the default apps. |
| 1150 bool is_syncable = (location() == Extension::INTERNAL && | 1076 bool is_syncable = (location() == Manifest::INTERNAL && |
| 1151 !was_installed_by_default()); | 1077 !was_installed_by_default()); |
| 1152 // Sync the chrome web store to maintain its position on the new tab page. | 1078 // Sync the chrome web store to maintain its position on the new tab page. |
| 1153 is_syncable |= (id() == extension_misc::kWebStoreAppId); | 1079 is_syncable |= (id() == extension_misc::kWebStoreAppId); |
| 1154 return is_syncable; | 1080 return is_syncable; |
| 1155 } | 1081 } |
| 1156 | 1082 |
| 1157 bool Extension::RequiresSortOrdinal() const { | 1083 bool Extension::RequiresSortOrdinal() const { |
| 1158 return is_app() && (display_in_launcher_ || display_in_new_tab_page_); | 1084 return is_app() && (display_in_launcher_ || display_in_new_tab_page_); |
| 1159 } | 1085 } |
| 1160 | 1086 |
| 1161 bool Extension::ShouldDisplayInAppLauncher() const { | 1087 bool Extension::ShouldDisplayInAppLauncher() const { |
| 1162 // Only apps should be displayed in the launcher. | 1088 // Only apps should be displayed in the launcher. |
| 1163 return is_app() && display_in_launcher_; | 1089 return is_app() && display_in_launcher_; |
| 1164 } | 1090 } |
| 1165 | 1091 |
| 1166 bool Extension::ShouldDisplayInNewTabPage() const { | 1092 bool Extension::ShouldDisplayInNewTabPage() const { |
| 1167 // Only apps should be displayed on the NTP. | 1093 // Only apps should be displayed on the NTP. |
| 1168 return is_app() && display_in_new_tab_page_; | 1094 return is_app() && display_in_new_tab_page_; |
| 1169 } | 1095 } |
| 1170 | 1096 |
| 1171 bool Extension::ShouldDisplayInExtensionSettings() const { | 1097 bool Extension::ShouldDisplayInExtensionSettings() const { |
| 1172 // Don't show for themes since the settings UI isn't really useful for them. | 1098 // Don't show for themes since the settings UI isn't really useful for them. |
| 1173 if (is_theme()) | 1099 if (is_theme()) |
| 1174 return false; | 1100 return false; |
| 1175 | 1101 |
| 1176 // Don't show component extensions because they are only extensions as an | 1102 // Don't show component extensions because they are only extensions as an |
| 1177 // implementation detail of Chrome. | 1103 // implementation detail of Chrome. |
| 1178 if (location() == Extension::COMPONENT && | 1104 if (location() == Manifest::COMPONENT && |
| 1179 !CommandLine::ForCurrentProcess()->HasSwitch( | 1105 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 1180 switches::kShowComponentExtensionOptions)) { | 1106 switches::kShowComponentExtensionOptions)) { |
| 1181 return false; | 1107 return false; |
| 1182 } | 1108 } |
| 1183 | 1109 |
| 1184 // Always show unpacked extensions and apps. | 1110 // Always show unpacked extensions and apps. |
| 1185 if (location() == Extension::LOAD) | 1111 if (location() == Manifest::LOAD) |
| 1186 return true; | 1112 return true; |
| 1187 | 1113 |
| 1188 // Unless they are unpacked, never show hosted apps. Note: We intentionally | 1114 // Unless they are unpacked, never show hosted apps. Note: We intentionally |
| 1189 // show packaged apps and platform apps because there are some pieces of | 1115 // show packaged apps and platform apps because there are some pieces of |
| 1190 // functionality that are only available in chrome://extensions/ but which | 1116 // functionality that are only available in chrome://extensions/ but which |
| 1191 // are needed for packaged and platform apps. For example, inspecting | 1117 // are needed for packaged and platform apps. For example, inspecting |
| 1192 // background pages. See http://crbug.com/116134. | 1118 // background pages. See http://crbug.com/116134. |
| 1193 if (is_hosted_app()) | 1119 if (is_hosted_app()) |
| 1194 return false; | 1120 return false; |
| 1195 | 1121 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 return iter->second.get(); | 1157 return iter->second.get(); |
| 1232 return NULL; | 1158 return NULL; |
| 1233 } | 1159 } |
| 1234 | 1160 |
| 1235 void Extension::SetManifestData(const std::string& key, | 1161 void Extension::SetManifestData(const std::string& key, |
| 1236 Extension::ManifestData* data) { | 1162 Extension::ManifestData* data) { |
| 1237 DCHECK(!finished_parsing_manifest_ && thread_checker_.CalledOnValidThread()); | 1163 DCHECK(!finished_parsing_manifest_ && thread_checker_.CalledOnValidThread()); |
| 1238 manifest_data_[key] = linked_ptr<ManifestData>(data); | 1164 manifest_data_[key] = linked_ptr<ManifestData>(data); |
| 1239 } | 1165 } |
| 1240 | 1166 |
| 1241 Extension::Location Extension::location() const { | 1167 Manifest::Location Extension::location() const { |
| 1242 return manifest_->location(); | 1168 return manifest_->location(); |
| 1243 } | 1169 } |
| 1244 | 1170 |
| 1245 const std::string& Extension::id() const { | 1171 const std::string& Extension::id() const { |
| 1246 return manifest_->extension_id(); | 1172 return manifest_->extension_id(); |
| 1247 } | 1173 } |
| 1248 | 1174 |
| 1249 const std::string Extension::VersionString() const { | 1175 const std::string Extension::VersionString() const { |
| 1250 return version()->GetString(); | 1176 return version()->GetString(); |
| 1251 } | 1177 } |
| 1252 | 1178 |
| 1253 void Extension::AddInstallWarning(const InstallWarning& new_warning) { | 1179 void Extension::AddInstallWarning(const InstallWarning& new_warning) { |
| 1254 install_warnings_.push_back(new_warning); | 1180 install_warnings_.push_back(new_warning); |
| 1255 } | 1181 } |
| 1256 | 1182 |
| 1257 void Extension::AddInstallWarnings( | 1183 void Extension::AddInstallWarnings( |
| 1258 const InstallWarningVector& new_warnings) { | 1184 const InstallWarning::Vector& new_warnings) { |
| 1259 install_warnings_.insert(install_warnings_.end(), | 1185 install_warnings_.insert(install_warnings_.end(), |
| 1260 new_warnings.begin(), new_warnings.end()); | 1186 new_warnings.begin(), new_warnings.end()); |
| 1261 } | 1187 } |
| 1262 | 1188 |
| 1263 bool Extension::is_platform_app() const { | 1189 bool Extension::is_platform_app() const { |
| 1264 return manifest_->is_platform_app(); | 1190 return manifest_->is_platform_app(); |
| 1265 } | 1191 } |
| 1266 | 1192 |
| 1267 bool Extension::is_hosted_app() const { | 1193 bool Extension::is_hosted_app() const { |
| 1268 return manifest()->is_hosted_app(); | 1194 return manifest()->is_hosted_app(); |
| (...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2991 | 2917 |
| 2992 URLPattern pattern(kValidWebExtentSchemes); | 2918 URLPattern pattern(kValidWebExtentSchemes); |
| 2993 URLPattern::ParseResult result = pattern.Parse(new_url.spec()); | 2919 URLPattern::ParseResult result = pattern.Parse(new_url.spec()); |
| 2994 DCHECK_EQ(result, URLPattern::PARSE_SUCCESS); | 2920 DCHECK_EQ(result, URLPattern::PARSE_SUCCESS); |
| 2995 pattern.SetPath(pattern.path() + '*'); | 2921 pattern.SetPath(pattern.path() + '*'); |
| 2996 extent_.AddPattern(pattern); | 2922 extent_.AddPattern(pattern); |
| 2997 } | 2923 } |
| 2998 } | 2924 } |
| 2999 | 2925 |
| 3000 bool Extension::CanSpecifyExperimentalPermission() const { | 2926 bool Extension::CanSpecifyExperimentalPermission() const { |
| 3001 if (location() == Extension::COMPONENT) | 2927 if (location() == Manifest::COMPONENT) |
| 3002 return true; | 2928 return true; |
| 3003 | 2929 |
| 3004 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2930 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 3005 switches::kEnableExperimentalExtensionApis)) { | 2931 switches::kEnableExperimentalExtensionApis)) { |
| 3006 return true; | 2932 return true; |
| 3007 } | 2933 } |
| 3008 | 2934 |
| 3009 // We rely on the webstore to check access to experimental. This way we can | 2935 // We rely on the webstore to check access to experimental. This way we can |
| 3010 // whitelist extensions to have access to experimental in just the store, and | 2936 // whitelist extensions to have access to experimental in just the store, and |
| 3011 // not have to push a new version of the client. | 2937 // not have to push a new version of the client. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3098 bool Extension::CheckConflictingFeatures(std::string* utf8_error) const { | 3024 bool Extension::CheckConflictingFeatures(std::string* utf8_error) const { |
| 3099 if (has_lazy_background_page() && | 3025 if (has_lazy_background_page() && |
| 3100 HasAPIPermission(APIPermission::kWebRequest)) { | 3026 HasAPIPermission(APIPermission::kWebRequest)) { |
| 3101 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; | 3027 *utf8_error = errors::kWebRequestConflictsWithLazyBackground; |
| 3102 return false; | 3028 return false; |
| 3103 } | 3029 } |
| 3104 | 3030 |
| 3105 return true; | 3031 return true; |
| 3106 } | 3032 } |
| 3107 | 3033 |
| 3108 void PrintTo(const Extension::InstallWarning& warning, ::std::ostream* os) { | 3034 void PrintTo(const InstallWarning& warning, ::std::ostream* os) { |
| 3109 *os << "InstallWarning("; | 3035 *os << "InstallWarning("; |
| 3110 switch (warning.format) { | 3036 switch (warning.format) { |
| 3111 case Extension::InstallWarning::FORMAT_TEXT: | 3037 case InstallWarning::FORMAT_TEXT: |
| 3112 *os << "FORMAT_TEXT, \""; | 3038 *os << "FORMAT_TEXT, \""; |
| 3113 break; | 3039 break; |
| 3114 case Extension::InstallWarning::FORMAT_HTML: | 3040 case InstallWarning::FORMAT_HTML: |
| 3115 *os << "FORMAT_HTML, \""; | 3041 *os << "FORMAT_HTML, \""; |
| 3116 break; | 3042 break; |
| 3117 } | 3043 } |
| 3118 // This is just for test error messages, so no need to escape '"' | 3044 // This is just for test error messages, so no need to escape '"' |
| 3119 // characters inside the message. | 3045 // characters inside the message. |
| 3120 *os << warning.message << "\")"; | 3046 *os << warning.message << "\")"; |
| 3121 } | 3047 } |
| 3122 | 3048 |
| 3123 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, | 3049 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, |
| 3124 const std::string& id, | 3050 const std::string& id, |
| 3125 const FilePath& path, | 3051 const FilePath& path, |
| 3126 Extension::Location location) | 3052 Manifest::Location location) |
| 3127 : extension_id(id), | 3053 : extension_id(id), |
| 3128 extension_path(path), | 3054 extension_path(path), |
| 3129 extension_location(location) { | 3055 extension_location(location) { |
| 3130 if (manifest) | 3056 if (manifest) |
| 3131 extension_manifest.reset(manifest->DeepCopy()); | 3057 extension_manifest.reset(manifest->DeepCopy()); |
| 3132 } | 3058 } |
| 3133 | 3059 |
| 3134 ExtensionInfo::~ExtensionInfo() {} | 3060 ExtensionInfo::~ExtensionInfo() {} |
| 3135 | 3061 |
| 3136 UnloadedExtensionInfo::UnloadedExtensionInfo( | 3062 UnloadedExtensionInfo::UnloadedExtensionInfo( |
| 3137 const Extension* extension, | 3063 const Extension* extension, |
| 3138 extension_misc::UnloadedExtensionReason reason) | 3064 extension_misc::UnloadedExtensionReason reason) |
| 3139 : reason(reason), | 3065 : reason(reason), |
| 3140 already_disabled(false), | 3066 already_disabled(false), |
| 3141 extension(extension) {} | 3067 extension(extension) {} |
| 3142 | 3068 |
| 3143 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3069 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3144 const Extension* extension, | 3070 const Extension* extension, |
| 3145 const PermissionSet* permissions, | 3071 const PermissionSet* permissions, |
| 3146 Reason reason) | 3072 Reason reason) |
| 3147 : reason(reason), | 3073 : reason(reason), |
| 3148 extension(extension), | 3074 extension(extension), |
| 3149 permissions(permissions) {} | 3075 permissions(permissions) {} |
| 3150 | 3076 |
| 3151 } // namespace extensions | 3077 } // namespace extensions |
| OLD | NEW |