| 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 3557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3568 | 3568 |
| 3569 if (browser_action()) | 3569 if (browser_action()) |
| 3570 ++num_surfaces; | 3570 ++num_surfaces; |
| 3571 | 3571 |
| 3572 if (is_app()) | 3572 if (is_app()) |
| 3573 ++num_surfaces; | 3573 ++num_surfaces; |
| 3574 | 3574 |
| 3575 return num_surfaces > 1; | 3575 return num_surfaces > 1; |
| 3576 } | 3576 } |
| 3577 | 3577 |
| 3578 bool Extension::CanExecuteScriptOnPage(const GURL& page_url, | 3578 bool Extension::CanExecuteScriptOnPage(const GURL& document_url, |
| 3579 const GURL& top_frame_url, |
| 3579 int tab_id, | 3580 int tab_id, |
| 3580 const UserScript* script, | 3581 const UserScript* script, |
| 3581 std::string* error) const { | 3582 std::string* error) const { |
| 3582 base::AutoLock auto_lock(runtime_data_lock_); | 3583 base::AutoLock auto_lock(runtime_data_lock_); |
| 3583 // The gallery is special-cased as a restricted URL for scripting to prevent | 3584 // The gallery is special-cased as a restricted URL for scripting to prevent |
| 3584 // access to special JS bindings we expose to the gallery (and avoid things | 3585 // access to special JS bindings we expose to the gallery (and avoid things |
| 3585 // like extensions removing the "report abuse" link). | 3586 // like extensions removing the "report abuse" link). |
| 3586 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing | 3587 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing |
| 3587 // against the store app extent? | 3588 // against the store app extent? |
| 3588 GURL store_url(extension_urls::GetWebstoreLaunchURL()); | 3589 GURL store_url(extension_urls::GetWebstoreLaunchURL()); |
| 3589 if ((page_url.host() == store_url.host()) && | 3590 if ((document_url.host() == store_url.host()) && |
| 3590 !CanExecuteScriptEverywhere() && | 3591 !CanExecuteScriptEverywhere() && |
| 3591 !CommandLine::ForCurrentProcess()->HasSwitch( | 3592 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 3592 switches::kAllowScriptingGallery)) { | 3593 switches::kAllowScriptingGallery)) { |
| 3593 if (error) | 3594 if (error) |
| 3594 *error = errors::kCannotScriptGallery; | 3595 *error = errors::kCannotScriptGallery; |
| 3595 return false; | 3596 return false; |
| 3596 } | 3597 } |
| 3597 | 3598 |
| 3598 if (page_url.SchemeIs(chrome::kChromeUIScheme) && | 3599 if (document_url.SchemeIs(chrome::kChromeUIScheme) && |
| 3599 !CanExecuteScriptEverywhere()) | 3600 !CanExecuteScriptEverywhere()) { |
| 3600 return false; | 3601 return false; |
| 3602 } |
| 3603 |
| 3604 if (top_frame_url.SchemeIs(chrome::kExtensionScheme) && |
| 3605 top_frame_url.GetOrigin() != |
| 3606 GetBaseURLFromExtensionId(id()).GetOrigin() && |
| 3607 !CanExecuteScriptEverywhere()) { |
| 3608 return false; |
| 3609 } |
| 3601 | 3610 |
| 3602 // If a tab ID is specified, try the tab-specific permissions. | 3611 // If a tab ID is specified, try the tab-specific permissions. |
| 3603 if (tab_id >= 0) { | 3612 if (tab_id >= 0) { |
| 3604 scoped_refptr<const PermissionSet> tab_permissions = | 3613 scoped_refptr<const PermissionSet> tab_permissions = |
| 3605 runtime_data_.GetTabSpecificPermissions(tab_id); | 3614 runtime_data_.GetTabSpecificPermissions(tab_id); |
| 3606 if (tab_permissions.get() && | 3615 if (tab_permissions.get() && |
| 3607 tab_permissions->explicit_hosts().MatchesSecurityOrigin(page_url)) { | 3616 tab_permissions->explicit_hosts().MatchesSecurityOrigin(document_url)) { |
| 3608 return true; | 3617 return true; |
| 3609 } | 3618 } |
| 3610 } | 3619 } |
| 3611 | 3620 |
| 3612 // If a script is specified, use its matches. | 3621 // If a script is specified, use its matches. |
| 3613 if (script) | 3622 if (script) |
| 3614 return script->MatchesURL(page_url); | 3623 return script->MatchesURL(document_url); |
| 3615 | 3624 |
| 3616 // Otherwise, see if this extension has permission to execute script | 3625 // Otherwise, see if this extension has permission to execute script |
| 3617 // programmatically on pages. | 3626 // programmatically on pages. |
| 3618 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin( | 3627 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin( |
| 3619 page_url)) | 3628 document_url)) |
| 3620 return true; | 3629 return true; |
| 3621 | 3630 |
| 3622 if (error) { | 3631 if (error) { |
| 3623 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, | 3632 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
| 3624 page_url.spec()); | 3633 document_url.spec()); |
| 3625 } | 3634 } |
| 3626 | 3635 |
| 3627 return false; | 3636 return false; |
| 3628 } | 3637 } |
| 3629 | 3638 |
| 3630 bool Extension::ShowConfigureContextMenus() const { | 3639 bool Extension::ShowConfigureContextMenus() const { |
| 3631 // Don't show context menu for component extensions. We might want to show | 3640 // Don't show context menu for component extensions. We might want to show |
| 3632 // options for component extension button but now there is no component | 3641 // options for component extension button but now there is no component |
| 3633 // extension with options. All other menu items like uninstall have | 3642 // extension with options. All other menu items like uninstall have |
| 3634 // no sense for component extensions. | 3643 // no sense for component extensions. |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3927 | 3936 |
| 3928 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3937 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3929 const Extension* extension, | 3938 const Extension* extension, |
| 3930 const PermissionSet* permissions, | 3939 const PermissionSet* permissions, |
| 3931 Reason reason) | 3940 Reason reason) |
| 3932 : reason(reason), | 3941 : reason(reason), |
| 3933 extension(extension), | 3942 extension(extension), |
| 3934 permissions(permissions) {} | 3943 permissions(permissions) {} |
| 3935 | 3944 |
| 3936 } // namespace extensions | 3945 } // namespace extensions |
| OLD | NEW |