| 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 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/chrome_version_info.h" | 28 #include "chrome/common/chrome_version_info.h" |
| 29 #include "chrome/common/extensions/csp_validator.h" | 29 #include "chrome/common/extensions/csp_validator.h" |
| 30 #include "chrome/common/extensions/extension_manifest_constants.h" | 30 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 31 #include "chrome/common/extensions/extension_resource.h" | 31 #include "chrome/common/extensions/extension_resource.h" |
| 32 #include "chrome/common/extensions/feature_switch.h" | 32 #include "chrome/common/extensions/feature_switch.h" |
| 33 #include "chrome/common/extensions/features/feature.h" | 33 #include "chrome/common/extensions/features/feature.h" |
| 34 #include "chrome/common/extensions/features/simple_feature_provider.h" | 34 #include "chrome/common/extensions/features/simple_feature_provider.h" |
| 35 #include "chrome/common/extensions/file_browser_handler.h" | 35 #include "chrome/common/extensions/file_browser_handler.h" |
| 36 #include "chrome/common/extensions/manifest.h" | 36 #include "chrome/common/extensions/manifest.h" |
| 37 #include "chrome/common/extensions/manifest_handler.h" |
| 37 #include "chrome/common/extensions/permissions/permission_set.h" | 38 #include "chrome/common/extensions/permissions/permission_set.h" |
| 38 #include "chrome/common/extensions/permissions/permissions_info.h" | 39 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 39 #include "chrome/common/extensions/user_script.h" | 40 #include "chrome/common/extensions/user_script.h" |
| 40 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
| 41 #include "crypto/sha2.h" | 42 #include "crypto/sha2.h" |
| 42 #include "extensions/common/constants.h" | 43 #include "extensions/common/constants.h" |
| 43 #include "extensions/common/error_utils.h" | 44 #include "extensions/common/error_utils.h" |
| 44 #include "extensions/common/url_pattern_set.h" | 45 #include "extensions/common/url_pattern_set.h" |
| 45 #include "googleurl/src/url_util.h" | 46 #include "googleurl/src/url_util.h" |
| 46 #include "grit/chromium_strings.h" | 47 #include "grit/chromium_strings.h" |
| (...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 scoped_refptr<const PermissionSet> permissions) const { | 1266 scoped_refptr<const PermissionSet> permissions) const { |
| 1266 base::AutoLock auto_lock(runtime_data_lock_); | 1267 base::AutoLock auto_lock(runtime_data_lock_); |
| 1267 runtime_data_.UpdateTabSpecificPermissions(tab_id, permissions); | 1268 runtime_data_.UpdateTabSpecificPermissions(tab_id, permissions); |
| 1268 } | 1269 } |
| 1269 | 1270 |
| 1270 void Extension::ClearTabSpecificPermissions(int tab_id) const { | 1271 void Extension::ClearTabSpecificPermissions(int tab_id) const { |
| 1271 base::AutoLock auto_lock(runtime_data_lock_); | 1272 base::AutoLock auto_lock(runtime_data_lock_); |
| 1272 runtime_data_.ClearTabSpecificPermissions(tab_id); | 1273 runtime_data_.ClearTabSpecificPermissions(tab_id); |
| 1273 } | 1274 } |
| 1274 | 1275 |
| 1276 Extension::ManifestData* Extension::GetManifestData(const std::string& key) |
| 1277 const { |
| 1278 DCHECK(finished_parsing_manifest_); |
| 1279 ManifestDataMap::const_iterator iter = manifest_data_.find(key); |
| 1280 if (iter != manifest_data_.end()) |
| 1281 return iter->second.get(); |
| 1282 return NULL; |
| 1283 } |
| 1284 |
| 1285 void Extension::SetManifestData(const std::string& key, |
| 1286 Extension::ManifestData* data) { |
| 1287 DCHECK(!finished_parsing_manifest_); |
| 1288 manifest_data_[key] = linked_ptr<ManifestData>(data); |
| 1289 } |
| 1290 |
| 1275 Extension::Location Extension::location() const { | 1291 Extension::Location Extension::location() const { |
| 1276 return manifest_->location(); | 1292 return manifest_->location(); |
| 1277 } | 1293 } |
| 1278 | 1294 |
| 1279 const std::string& Extension::id() const { | 1295 const std::string& Extension::id() const { |
| 1280 return manifest_->extension_id(); | 1296 return manifest_->extension_id(); |
| 1281 } | 1297 } |
| 1282 | 1298 |
| 1283 const std::string Extension::VersionString() const { | 1299 const std::string Extension::VersionString() const { |
| 1284 return version()->GetString(); | 1300 return version()->GetString(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 | 1439 |
| 1424 Extension::Extension(const FilePath& path, | 1440 Extension::Extension(const FilePath& path, |
| 1425 scoped_ptr<extensions::Manifest> manifest) | 1441 scoped_ptr<extensions::Manifest> manifest) |
| 1426 : manifest_version_(0), | 1442 : manifest_version_(0), |
| 1427 incognito_split_mode_(false), | 1443 incognito_split_mode_(false), |
| 1428 offline_enabled_(false), | 1444 offline_enabled_(false), |
| 1429 converted_from_user_script_(false), | 1445 converted_from_user_script_(false), |
| 1430 background_page_is_persistent_(true), | 1446 background_page_is_persistent_(true), |
| 1431 allow_background_js_access_(true), | 1447 allow_background_js_access_(true), |
| 1432 manifest_(manifest.release()), | 1448 manifest_(manifest.release()), |
| 1449 finished_parsing_manifest_(false), |
| 1433 is_storage_isolated_(false), | 1450 is_storage_isolated_(false), |
| 1434 launch_container_(extension_misc::LAUNCH_TAB), | 1451 launch_container_(extension_misc::LAUNCH_TAB), |
| 1435 launch_width_(0), | 1452 launch_width_(0), |
| 1436 launch_height_(0), | 1453 launch_height_(0), |
| 1437 display_in_launcher_(true), | 1454 display_in_launcher_(true), |
| 1438 display_in_new_tab_page_(true), | 1455 display_in_new_tab_page_(true), |
| 1439 wants_file_access_(false), | 1456 wants_file_access_(false), |
| 1440 creation_flags_(0) { | 1457 creation_flags_(0) { |
| 1441 DCHECK(path.empty() || path.IsAbsolute()); | 1458 DCHECK(path.empty() || path.IsAbsolute()); |
| 1442 path_ = MaybeNormalizePath(path); | 1459 path_ = MaybeNormalizePath(path); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 return false; | 1557 return false; |
| 1541 } | 1558 } |
| 1542 | 1559 |
| 1543 runtime_data_.SetActivePermissions(new PermissionSet( | 1560 runtime_data_.SetActivePermissions(new PermissionSet( |
| 1544 this, api_permissions, host_permissions)); | 1561 this, api_permissions, host_permissions)); |
| 1545 required_permission_set_ = new PermissionSet( | 1562 required_permission_set_ = new PermissionSet( |
| 1546 this, api_permissions, host_permissions); | 1563 this, api_permissions, host_permissions); |
| 1547 optional_permission_set_ = new PermissionSet( | 1564 optional_permission_set_ = new PermissionSet( |
| 1548 optional_api_permissions, optional_host_permissions, URLPatternSet()); | 1565 optional_api_permissions, optional_host_permissions, URLPatternSet()); |
| 1549 | 1566 |
| 1567 finished_parsing_manifest_ = true; |
| 1568 |
| 1550 return true; | 1569 return true; |
| 1551 } | 1570 } |
| 1552 | 1571 |
| 1553 bool Extension::LoadAppIsolation(const APIPermissionSet& api_permissions, | 1572 bool Extension::LoadAppIsolation(const APIPermissionSet& api_permissions, |
| 1554 string16* error) { | 1573 string16* error) { |
| 1555 // Platform apps always get isolated storage. | 1574 // Platform apps always get isolated storage. |
| 1556 if (is_platform_app()) { | 1575 if (is_platform_app()) { |
| 1557 is_storage_isolated_ = true; | 1576 is_storage_isolated_ = true; |
| 1558 return true; | 1577 return true; |
| 1559 } | 1578 } |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2734 } | 2753 } |
| 2735 return true; | 2754 return true; |
| 2736 } | 2755 } |
| 2737 | 2756 |
| 2738 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, | 2757 bool Extension::LoadExtensionFeatures(APIPermissionSet* api_permissions, |
| 2739 string16* error) { | 2758 string16* error) { |
| 2740 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2759 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
| 2741 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2760 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
| 2742 &converted_from_user_script_); | 2761 &converted_from_user_script_); |
| 2743 | 2762 |
| 2744 if (!LoadDevToolsPage(error) || | 2763 if (!LoadManifestHandlerFeatures(error) || |
| 2764 !LoadDevToolsPage(error) || |
| 2745 !LoadInputComponents(*api_permissions, error) || | 2765 !LoadInputComponents(*api_permissions, error) || |
| 2746 !LoadContentScripts(error) || | 2766 !LoadContentScripts(error) || |
| 2747 !LoadPageAction(error) || | 2767 !LoadPageAction(error) || |
| 2748 !LoadBrowserAction(error) || | 2768 !LoadBrowserAction(error) || |
| 2749 !LoadSystemIndicator(api_permissions, error) || | 2769 !LoadSystemIndicator(api_permissions, error) || |
| 2750 !LoadScriptBadge(error) || | 2770 !LoadScriptBadge(error) || |
| 2751 !LoadFileBrowserHandlers(error) || | 2771 !LoadFileBrowserHandlers(error) || |
| 2752 !LoadChromeURLOverrides(error) || | 2772 !LoadChromeURLOverrides(error) || |
| 2753 !LoadOmnibox(error) || | |
| 2754 !LoadTextToSpeechVoices(error) || | 2773 !LoadTextToSpeechVoices(error) || |
| 2755 !LoadIncognitoMode(error) || | 2774 !LoadIncognitoMode(error) || |
| 2756 !LoadFileHandlers(error) || | 2775 !LoadFileHandlers(error) || |
| 2757 !LoadContentSecurityPolicy(error)) | 2776 !LoadContentSecurityPolicy(error)) |
| 2758 return false; | 2777 return false; |
| 2759 | 2778 |
| 2760 return true; | 2779 return true; |
| 2761 } | 2780 } |
| 2762 | 2781 |
| 2782 bool Extension::LoadManifestHandlerFeatures(string16* error) { |
| 2783 std::vector<std::string> keys = ManifestHandler::GetKeys(); |
| 2784 for (size_t i = 0; i < keys.size(); ++i) { |
| 2785 Value* value = NULL; |
| 2786 if (!manifest_->Get(keys[i], &value)) |
| 2787 continue; |
| 2788 if (!ManifestHandler::Get(keys[i])->Parse(value, this, error)) |
| 2789 return false; |
| 2790 } |
| 2791 return true; |
| 2792 } |
| 2793 |
| 2763 bool Extension::LoadDevToolsPage(string16* error) { | 2794 bool Extension::LoadDevToolsPage(string16* error) { |
| 2764 if (!manifest_->HasKey(keys::kDevToolsPage)) | 2795 if (!manifest_->HasKey(keys::kDevToolsPage)) |
| 2765 return true; | 2796 return true; |
| 2766 std::string devtools_str; | 2797 std::string devtools_str; |
| 2767 if (!manifest_->GetString(keys::kDevToolsPage, &devtools_str)) { | 2798 if (!manifest_->GetString(keys::kDevToolsPage, &devtools_str)) { |
| 2768 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage); | 2799 *error = ASCIIToUTF16(errors::kInvalidDevToolsPage); |
| 2769 return false; | 2800 return false; |
| 2770 } | 2801 } |
| 2771 devtools_url_ = GetResourceURL(devtools_str); | 2802 devtools_url_ = GetResourceURL(devtools_str); |
| 2772 return true; | 2803 return true; |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3305 | 3336 |
| 3306 // An extension may override at most one page. | 3337 // An extension may override at most one page. |
| 3307 if (overrides->size() > 1) { | 3338 if (overrides->size() > 1) { |
| 3308 *error = ASCIIToUTF16(errors::kMultipleOverrides); | 3339 *error = ASCIIToUTF16(errors::kMultipleOverrides); |
| 3309 return false; | 3340 return false; |
| 3310 } | 3341 } |
| 3311 | 3342 |
| 3312 return true; | 3343 return true; |
| 3313 } | 3344 } |
| 3314 | 3345 |
| 3315 bool Extension::LoadOmnibox(string16* error) { | |
| 3316 if (!manifest_->HasKey(keys::kOmnibox)) | |
| 3317 return true; | |
| 3318 if (!manifest_->GetString(keys::kOmniboxKeyword, &omnibox_keyword_) || | |
| 3319 omnibox_keyword_.empty()) { | |
| 3320 *error = ASCIIToUTF16(errors::kInvalidOmniboxKeyword); | |
| 3321 return false; | |
| 3322 } | |
| 3323 return true; | |
| 3324 } | |
| 3325 | |
| 3326 bool Extension::LoadTextToSpeechVoices(string16* error) { | 3346 bool Extension::LoadTextToSpeechVoices(string16* error) { |
| 3327 if (!manifest_->HasKey(keys::kTtsEngine)) | 3347 if (!manifest_->HasKey(keys::kTtsEngine)) |
| 3328 return true; | 3348 return true; |
| 3329 DictionaryValue* tts_dict = NULL; | 3349 DictionaryValue* tts_dict = NULL; |
| 3330 if (!manifest_->GetDictionary(keys::kTtsEngine, &tts_dict)) { | 3350 if (!manifest_->GetDictionary(keys::kTtsEngine, &tts_dict)) { |
| 3331 *error = ASCIIToUTF16(errors::kInvalidTts); | 3351 *error = ASCIIToUTF16(errors::kInvalidTts); |
| 3332 return false; | 3352 return false; |
| 3333 } | 3353 } |
| 3334 | 3354 |
| 3335 if (tts_dict->HasKey(keys::kTtsVoices)) { | 3355 if (tts_dict->HasKey(keys::kTtsVoices)) { |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4174 | 4194 |
| 4175 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 4195 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 4176 const Extension* extension, | 4196 const Extension* extension, |
| 4177 const PermissionSet* permissions, | 4197 const PermissionSet* permissions, |
| 4178 Reason reason) | 4198 Reason reason) |
| 4179 : reason(reason), | 4199 : reason(reason), |
| 4180 extension(extension), | 4200 extension(extension), |
| 4181 permissions(permissions) {} | 4201 permissions(permissions) {} |
| 4182 | 4202 |
| 4183 } // namespace extensions | 4203 } // namespace extensions |
| OLD | NEW |