Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "base/version.h" | 25 #include "base/version.h" |
| 26 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 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 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and | 29 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and |
| 30 // SystemIndicator have been moved out of Extension. | 30 // SystemIndicator have been moved out of Extension. |
| 31 #include "chrome/common/extensions/api/extension_action/action_handler_helpers.h " | 31 #include "chrome/common/extensions/api/extension_action/action_handler_helpers.h " |
| 32 #include "chrome/common/extensions/api/extension_action/action_info.h" | 32 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 33 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h " | |
| 33 #include "chrome/common/extensions/csp_validator.h" | 34 #include "chrome/common/extensions/csp_validator.h" |
| 34 #include "chrome/common/extensions/extension_manifest_constants.h" | 35 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 35 #include "chrome/common/extensions/extension_resource.h" | 36 #include "chrome/common/extensions/extension_resource.h" |
| 36 #include "chrome/common/extensions/feature_switch.h" | 37 #include "chrome/common/extensions/feature_switch.h" |
| 37 #include "chrome/common/extensions/features/base_feature_provider.h" | 38 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 38 #include "chrome/common/extensions/features/feature.h" | 39 #include "chrome/common/extensions/features/feature.h" |
| 39 #include "chrome/common/extensions/manifest.h" | 40 #include "chrome/common/extensions/manifest.h" |
| 40 #include "chrome/common/extensions/manifest_handler.h" | 41 #include "chrome/common/extensions/manifest_handler.h" |
| 41 #include "chrome/common/extensions/manifest_handler_helpers.h" | 42 #include "chrome/common/extensions/manifest_handler_helpers.h" |
| 42 #include "chrome/common/extensions/permissions/permission_set.h" | 43 #include "chrome/common/extensions/permissions/permission_set.h" |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 | 950 |
| 950 if (page_action_info() && !page_action_info()->default_icon.empty()) { | 951 if (page_action_info() && !page_action_info()->default_icon.empty()) { |
| 951 for (ExtensionIconSet::IconMap::const_iterator iter = | 952 for (ExtensionIconSet::IconMap::const_iterator iter = |
| 952 page_action_info()->default_icon.map().begin(); | 953 page_action_info()->default_icon.map().begin(); |
| 953 iter != page_action_info()->default_icon.map().end(); | 954 iter != page_action_info()->default_icon.map().end(); |
| 954 ++iter) { | 955 ++iter) { |
| 955 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 956 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| 956 } | 957 } |
| 957 } | 958 } |
| 958 | 959 |
| 959 if (browser_action_info() && !browser_action_info()->default_icon.empty()) { | 960 const ActionInfo* browser_action = BrowserActionInfo::GetBrowserAction(this); |
| 961 if (browser_action && !browser_action->default_icon.empty()) { | |
| 960 for (ExtensionIconSet::IconMap::const_iterator iter = | 962 for (ExtensionIconSet::IconMap::const_iterator iter = |
| 961 browser_action_info()->default_icon.map().begin(); | 963 browser_action->default_icon.map().begin(); |
| 962 iter != browser_action_info()->default_icon.map().end(); | 964 iter != browser_action->default_icon.map().end(); |
| 963 ++iter) { | 965 ++iter) { |
| 964 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 966 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| 965 } | 967 } |
| 966 } | 968 } |
| 967 | 969 |
| 968 return image_paths; | 970 return image_paths; |
| 969 } | 971 } |
| 970 | 972 |
| 971 ExtensionResource Extension::GetIconResource( | 973 ExtensionResource Extension::GetIconResource( |
| 972 int size, ExtensionIconSet::MatchType match_type) const { | 974 int size, ExtensionIconSet::MatchType match_type) const { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1257 runtime_data_.UpdateTabSpecificPermissions(tab_id, permissions); | 1259 runtime_data_.UpdateTabSpecificPermissions(tab_id, permissions); |
| 1258 } | 1260 } |
| 1259 | 1261 |
| 1260 void Extension::ClearTabSpecificPermissions(int tab_id) const { | 1262 void Extension::ClearTabSpecificPermissions(int tab_id) const { |
| 1261 base::AutoLock auto_lock(runtime_data_lock_); | 1263 base::AutoLock auto_lock(runtime_data_lock_); |
| 1262 runtime_data_.ClearTabSpecificPermissions(tab_id); | 1264 runtime_data_.ClearTabSpecificPermissions(tab_id); |
| 1263 } | 1265 } |
| 1264 | 1266 |
| 1265 Extension::ManifestData* Extension::GetManifestData(const std::string& key) | 1267 Extension::ManifestData* Extension::GetManifestData(const std::string& key) |
| 1266 const { | 1268 const { |
| 1267 DCHECK(finished_parsing_manifest_); | 1269 DCHECK(finished_parsing_manifest_ || thread_checker_.CalledOnValidThread()); |
| 1268 ManifestDataMap::const_iterator iter = manifest_data_.find(key); | 1270 ManifestDataMap::const_iterator iter = manifest_data_.find(key); |
| 1269 if (iter != manifest_data_.end()) | 1271 if (iter != manifest_data_.end()) |
| 1270 return iter->second.get(); | 1272 return iter->second.get(); |
| 1271 return NULL; | 1273 return NULL; |
| 1272 } | 1274 } |
| 1273 | 1275 |
| 1274 void Extension::SetManifestData(const std::string& key, | 1276 void Extension::SetManifestData(const std::string& key, |
| 1275 Extension::ManifestData* data) { | 1277 Extension::ManifestData* data) { |
| 1278 | |
|
Yoyo Zhou
2012/12/21 23:50:59
newline is extraneous
Devlin
2012/12/27 20:36:46
Done.
| |
| 1276 DCHECK(!finished_parsing_manifest_); | 1279 DCHECK(!finished_parsing_manifest_); |
|
Yoyo Zhou
2012/12/21 23:50:59
&& thread_checker_.CalledOnValidThread()
Devlin
2012/12/27 20:36:46
Done.
| |
| 1277 manifest_data_[key] = linked_ptr<ManifestData>(data); | 1280 manifest_data_[key] = linked_ptr<ManifestData>(data); |
| 1278 } | 1281 } |
| 1279 | 1282 |
| 1280 Extension::Location Extension::location() const { | 1283 Extension::Location Extension::location() const { |
| 1281 return manifest_->location(); | 1284 return manifest_->location(); |
| 1282 } | 1285 } |
| 1283 | 1286 |
| 1284 const std::string& Extension::id() const { | 1287 const std::string& Extension::id() const { |
| 1285 return manifest_->extension_id(); | 1288 return manifest_->extension_id(); |
| 1286 } | 1289 } |
| (...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2761 string16* error) { | 2764 string16* error) { |
| 2762 if (manifest_->HasKey(keys::kConvertedFromUserScript)) | 2765 if (manifest_->HasKey(keys::kConvertedFromUserScript)) |
| 2763 manifest_->GetBoolean(keys::kConvertedFromUserScript, | 2766 manifest_->GetBoolean(keys::kConvertedFromUserScript, |
| 2764 &converted_from_user_script_); | 2767 &converted_from_user_script_); |
| 2765 | 2768 |
| 2766 if (!LoadManifestHandlerFeatures(error) || | 2769 if (!LoadManifestHandlerFeatures(error) || |
| 2767 !LoadDevToolsPage(error) || | 2770 !LoadDevToolsPage(error) || |
| 2768 !LoadInputComponents(*api_permissions, error) || | 2771 !LoadInputComponents(*api_permissions, error) || |
| 2769 !LoadContentScripts(error) || | 2772 !LoadContentScripts(error) || |
| 2770 !LoadPageAction(error) || | 2773 !LoadPageAction(error) || |
| 2771 !LoadBrowserAction(error) || | |
| 2772 !LoadSystemIndicator(api_permissions, error) || | 2774 !LoadSystemIndicator(api_permissions, error) || |
| 2773 !LoadChromeURLOverrides(error) || | 2775 !LoadChromeURLOverrides(error) || |
| 2774 !LoadTextToSpeechVoices(error) || | 2776 !LoadTextToSpeechVoices(error) || |
| 2775 !LoadIncognitoMode(error) || | 2777 !LoadIncognitoMode(error) || |
| 2776 !LoadFileHandlers(error) || | 2778 !LoadFileHandlers(error) || |
| 2777 !LoadContentSecurityPolicy(error)) | 2779 !LoadContentSecurityPolicy(error)) |
| 2778 return false; | 2780 return false; |
| 2779 | 2781 |
| 2780 return true; | 2782 return true; |
| 2781 } | 2783 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3004 if (page_action_value) { | 3006 if (page_action_value) { |
| 3005 page_action_info_ = LoadExtensionActionInfoHelper( | 3007 page_action_info_ = LoadExtensionActionInfoHelper( |
| 3006 this, page_action_value, error); | 3008 this, page_action_value, error); |
| 3007 if (!page_action_info_.get()) | 3009 if (!page_action_info_.get()) |
| 3008 return false; // Failed to parse page action definition. | 3010 return false; // Failed to parse page action definition. |
| 3009 } | 3011 } |
| 3010 | 3012 |
| 3011 return true; | 3013 return true; |
| 3012 } | 3014 } |
| 3013 | 3015 |
| 3014 bool Extension::LoadBrowserAction(string16* error) { | |
| 3015 if (!manifest_->HasKey(keys::kBrowserAction)) | |
| 3016 return true; | |
| 3017 DictionaryValue* browser_action_value = NULL; | |
| 3018 if (!manifest_->GetDictionary(keys::kBrowserAction, &browser_action_value)) { | |
| 3019 *error = ASCIIToUTF16(errors::kInvalidBrowserAction); | |
| 3020 return false; | |
| 3021 } | |
| 3022 | |
| 3023 browser_action_info_ = LoadExtensionActionInfoHelper( | |
| 3024 this, browser_action_value, error); | |
| 3025 if (!browser_action_info_.get()) | |
| 3026 return false; // Failed to parse browser action definition. | |
| 3027 return true; | |
| 3028 } | |
| 3029 | |
| 3030 bool Extension::LoadSystemIndicator(APIPermissionSet* api_permissions, | 3016 bool Extension::LoadSystemIndicator(APIPermissionSet* api_permissions, |
| 3031 string16* error) { | 3017 string16* error) { |
| 3032 if (!manifest_->HasKey(keys::kSystemIndicator)) { | 3018 if (!manifest_->HasKey(keys::kSystemIndicator)) { |
| 3033 // There was no manifest entry for the system indicator. | 3019 // There was no manifest entry for the system indicator. |
| 3034 return true; | 3020 return true; |
| 3035 } | 3021 } |
| 3036 | 3022 |
| 3037 DictionaryValue* system_indicator_value = NULL; | 3023 DictionaryValue* system_indicator_value = NULL; |
| 3038 if (!manifest_->GetDictionary(keys::kSystemIndicator, | 3024 if (!manifest_->GetDictionary(keys::kSystemIndicator, |
| 3039 &system_indicator_value)) { | 3025 &system_indicator_value)) { |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3652 | 3638 |
| 3653 return true; | 3639 return true; |
| 3654 } | 3640 } |
| 3655 | 3641 |
| 3656 bool Extension::HasMultipleUISurfaces() const { | 3642 bool Extension::HasMultipleUISurfaces() const { |
| 3657 int num_surfaces = 0; | 3643 int num_surfaces = 0; |
| 3658 | 3644 |
| 3659 if (page_action_info()) | 3645 if (page_action_info()) |
| 3660 ++num_surfaces; | 3646 ++num_surfaces; |
| 3661 | 3647 |
| 3662 if (browser_action_info()) | 3648 if (BrowserActionInfo::GetBrowserAction(this)) |
| 3663 ++num_surfaces; | 3649 ++num_surfaces; |
| 3664 | 3650 |
| 3665 if (is_app()) | 3651 if (is_app()) |
| 3666 ++num_surfaces; | 3652 ++num_surfaces; |
| 3667 | 3653 |
| 3668 return num_surfaces > 1; | 3654 return num_surfaces > 1; |
| 3669 } | 3655 } |
| 3670 | 3656 |
| 3671 void Extension::OverrideLaunchUrl(const GURL& override_url) { | 3657 void Extension::OverrideLaunchUrl(const GURL& override_url) { |
| 3672 GURL new_url(override_url); | 3658 GURL new_url(override_url); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3837 | 3823 |
| 3838 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3824 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3839 const Extension* extension, | 3825 const Extension* extension, |
| 3840 const PermissionSet* permissions, | 3826 const PermissionSet* permissions, |
| 3841 Reason reason) | 3827 Reason reason) |
| 3842 : reason(reason), | 3828 : reason(reason), |
| 3843 extension(extension), | 3829 extension(extension), |
| 3844 permissions(permissions) {} | 3830 permissions(permissions) {} |
| 3845 | 3831 |
| 3846 } // namespace extensions | 3832 } // namespace extensions |
| OLD | NEW |