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 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; |
| 3601 | 3602 |
| 3603 if (top_frame_url.SchemeIs(chrome::kExtensionScheme) && | |
| 3604 top_frame_url.GetOrigin() != | |
| 3605 GetBaseURLFromExtensionId(id()).GetOrigin() && | |
| 3606 !CanExecuteScriptEverywhere()) | |
|
Aaron Boodman
2012/08/23 00:45:59
Braces required here.
zel
2012/08/23 01:28:29
Done.
| |
| 3607 return false; | |
| 3608 | |
| 3602 // If a tab ID is specified, try the tab-specific permissions. | 3609 // If a tab ID is specified, try the tab-specific permissions. |
| 3603 if (tab_id >= 0) { | 3610 if (tab_id >= 0) { |
| 3604 scoped_refptr<const PermissionSet> tab_permissions = | 3611 scoped_refptr<const PermissionSet> tab_permissions = |
| 3605 runtime_data_.GetTabSpecificPermissions(tab_id); | 3612 runtime_data_.GetTabSpecificPermissions(tab_id); |
| 3606 if (tab_permissions.get() && | 3613 if (tab_permissions.get() && |
| 3607 tab_permissions->explicit_hosts().MatchesSecurityOrigin(page_url)) { | 3614 tab_permissions->explicit_hosts().MatchesSecurityOrigin(document_url)) { |
| 3608 return true; | 3615 return true; |
| 3609 } | 3616 } |
| 3610 } | 3617 } |
| 3611 | 3618 |
| 3612 // If a script is specified, use its matches. | 3619 // If a script is specified, use its matches. |
| 3613 if (script) | 3620 if (script) |
| 3614 return script->MatchesURL(page_url); | 3621 return script->MatchesURL(document_url); |
| 3615 | 3622 |
| 3616 // Otherwise, see if this extension has permission to execute script | 3623 // Otherwise, see if this extension has permission to execute script |
| 3617 // programmatically on pages. | 3624 // programmatically on pages. |
| 3618 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin( | 3625 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin( |
| 3619 page_url)) | 3626 document_url)) |
| 3620 return true; | 3627 return true; |
| 3621 | 3628 |
| 3622 if (error) { | 3629 if (error) { |
| 3623 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, | 3630 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
| 3624 page_url.spec()); | 3631 document_url.spec()); |
| 3625 } | 3632 } |
| 3626 | 3633 |
| 3627 return false; | 3634 return false; |
| 3628 } | 3635 } |
| 3629 | 3636 |
| 3630 bool Extension::ShowConfigureContextMenus() const { | 3637 bool Extension::ShowConfigureContextMenus() const { |
| 3631 // Don't show context menu for component extensions. We might want to show | 3638 // 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 | 3639 // options for component extension button but now there is no component |
| 3633 // extension with options. All other menu items like uninstall have | 3640 // extension with options. All other menu items like uninstall have |
| 3634 // no sense for component extensions. | 3641 // no sense for component extensions. |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3927 | 3934 |
| 3928 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3935 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3929 const Extension* extension, | 3936 const Extension* extension, |
| 3930 const PermissionSet* permissions, | 3937 const PermissionSet* permissions, |
| 3931 Reason reason) | 3938 Reason reason) |
| 3932 : reason(reason), | 3939 : reason(reason), |
| 3933 extension(extension), | 3940 extension(extension), |
| 3934 permissions(permissions) {} | 3941 permissions(permissions) {} |
| 3935 | 3942 |
| 3936 } // namespace extensions | 3943 } // namespace extensions |
| OLD | NEW |