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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 2316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2327 return false; | 2327 return false; |
2328 } | 2328 } |
2329 | 2329 |
2330 browser_action_ = LoadExtensionActionHelper(browser_action_value, error); | 2330 browser_action_ = LoadExtensionActionHelper(browser_action_value, error); |
2331 if (!browser_action_.get()) | 2331 if (!browser_action_.get()) |
2332 return false; // Failed to parse browser action definition. | 2332 return false; // Failed to parse browser action definition. |
2333 declared_action_type_ = ExtensionAction::TYPE_BROWSER; | 2333 declared_action_type_ = ExtensionAction::TYPE_BROWSER; |
2334 return true; | 2334 return true; |
2335 } | 2335 } |
2336 | 2336 |
| 2337 void Extension::GenerateBrowserActionIfPossible() { |
| 2338 // It only makes sense to generate brower actions for extensions that are |
| 2339 // shown in chrome://extensions. |
| 2340 if (!ShouldDisplayInExtensionSettings()) |
| 2341 return; |
| 2342 |
| 2343 // Hosted and platform apps are shown in extension settings, but we don't |
| 2344 // want to generate browser actions for those either, since they can't define |
| 2345 // browser actions. |
| 2346 if (is_app()) |
| 2347 return; |
| 2348 |
| 2349 browser_action_.reset(new ExtensionAction(id())); |
| 2350 browser_action_->SetTitle(ExtensionAction::kDefaultTabId, name()); |
| 2351 } |
| 2352 |
2337 bool Extension::LoadFileBrowserHandlers(string16* error) { | 2353 bool Extension::LoadFileBrowserHandlers(string16* error) { |
2338 if (!manifest_->HasKey(keys::kFileBrowserHandlers)) | 2354 if (!manifest_->HasKey(keys::kFileBrowserHandlers)) |
2339 return true; | 2355 return true; |
2340 ListValue* file_browser_handlers_value = NULL; | 2356 ListValue* file_browser_handlers_value = NULL; |
2341 if (!manifest_->GetList(keys::kFileBrowserHandlers, | 2357 if (!manifest_->GetList(keys::kFileBrowserHandlers, |
2342 &file_browser_handlers_value)) { | 2358 &file_browser_handlers_value)) { |
2343 *error = ASCIIToUTF16(errors::kInvalidFileBrowserHandler); | 2359 *error = ASCIIToUTF16(errors::kInvalidFileBrowserHandler); |
2344 return false; | 2360 return false; |
2345 } | 2361 } |
2346 file_browser_handlers_.reset( | 2362 file_browser_handlers_.reset( |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3076 | 3092 |
3077 if (!LoadSharedFeatures(api_permissions, error)) | 3093 if (!LoadSharedFeatures(api_permissions, error)) |
3078 return false; | 3094 return false; |
3079 | 3095 |
3080 if (!LoadExtensionFeatures(api_permissions, error)) | 3096 if (!LoadExtensionFeatures(api_permissions, error)) |
3081 return false; | 3097 return false; |
3082 | 3098 |
3083 if (!LoadThemeFeatures(error)) | 3099 if (!LoadThemeFeatures(error)) |
3084 return false; | 3100 return false; |
3085 | 3101 |
| 3102 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 3103 switches::kEnableBrowserActionsForAll) && |
| 3104 !browser_action()) { |
| 3105 GenerateBrowserActionIfPossible(); |
| 3106 } |
| 3107 |
3086 if (HasMultipleUISurfaces()) { | 3108 if (HasMultipleUISurfaces()) { |
3087 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 3109 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
3088 return false; | 3110 return false; |
3089 } | 3111 } |
3090 | 3112 |
3091 runtime_data_.SetActivePermissions(new ExtensionPermissionSet( | 3113 runtime_data_.SetActivePermissions(new ExtensionPermissionSet( |
3092 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet())); | 3114 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet())); |
3093 required_permission_set_ = new ExtensionPermissionSet( | 3115 required_permission_set_ = new ExtensionPermissionSet( |
3094 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet()); | 3116 this, api_permissions, host_permissions, oauth2_info_.GetScopesAsSet()); |
3095 optional_permission_set_ = new ExtensionPermissionSet( | 3117 optional_permission_set_ = new ExtensionPermissionSet( |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3640 const std::string& id, | 3662 const std::string& id, |
3641 const FilePath& path, | 3663 const FilePath& path, |
3642 Extension::Location location) | 3664 Extension::Location location) |
3643 : extension_id(id), | 3665 : extension_id(id), |
3644 extension_path(path), | 3666 extension_path(path), |
3645 extension_location(location) { | 3667 extension_location(location) { |
3646 if (manifest) | 3668 if (manifest) |
3647 extension_manifest.reset(manifest->DeepCopy()); | 3669 extension_manifest.reset(manifest->DeepCopy()); |
3648 } | 3670 } |
3649 | 3671 |
| 3672 bool Extension::ShouldDisplayInExtensionSettings() const { |
| 3673 // Don't show for themes since the settings UI isn't really useful for them. |
| 3674 if (is_theme()) |
| 3675 return false; |
| 3676 |
| 3677 // Don't show component extensions because they are only extensions as an |
| 3678 // implementation detail of Chrome. |
| 3679 if (location() == Extension::COMPONENT && |
| 3680 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 3681 switches::kShowComponentExtensionOptions)) |
| 3682 return false; |
| 3683 |
| 3684 // Always show unpacked extensions and apps. |
| 3685 if (location() == Extension::LOAD) |
| 3686 return true; |
| 3687 |
| 3688 // Unless they are unpacked, never show hosted apps. Note: We intentionally |
| 3689 // show packaged apps and platform apps because there are some pieces of |
| 3690 // functionality that are only available in chrome://extensions/ but which |
| 3691 // are needed for packaged and platform apps. For example, inspecting |
| 3692 // background pages. See http://crbug.com/116134. |
| 3693 if (is_hosted_app()) |
| 3694 return false; |
| 3695 |
| 3696 return true; |
| 3697 } |
| 3698 |
3650 ExtensionInfo::~ExtensionInfo() {} | 3699 ExtensionInfo::~ExtensionInfo() {} |
3651 | 3700 |
3652 Extension::RuntimeData::RuntimeData() {} | 3701 Extension::RuntimeData::RuntimeData() {} |
3653 Extension::RuntimeData::RuntimeData(const ExtensionPermissionSet* active) | 3702 Extension::RuntimeData::RuntimeData(const ExtensionPermissionSet* active) |
3654 : active_permissions_(active) {} | 3703 : active_permissions_(active) {} |
3655 Extension::RuntimeData::~RuntimeData() {} | 3704 Extension::RuntimeData::~RuntimeData() {} |
3656 | 3705 |
3657 scoped_refptr<const ExtensionPermissionSet> | 3706 scoped_refptr<const ExtensionPermissionSet> |
3658 Extension::RuntimeData::GetActivePermissions() const { | 3707 Extension::RuntimeData::GetActivePermissions() const { |
3659 return active_permissions_; | 3708 return active_permissions_; |
(...skipping 11 matching lines...) Expand all Loading... |
3671 already_disabled(false), | 3720 already_disabled(false), |
3672 extension(extension) {} | 3721 extension(extension) {} |
3673 | 3722 |
3674 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3723 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3675 const Extension* extension, | 3724 const Extension* extension, |
3676 const ExtensionPermissionSet* permissions, | 3725 const ExtensionPermissionSet* permissions, |
3677 Reason reason) | 3726 Reason reason) |
3678 : reason(reason), | 3727 : reason(reason), |
3679 extension(extension), | 3728 extension(extension), |
3680 permissions(permissions) {} | 3729 permissions(permissions) {} |
OLD | NEW |