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 3509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3520 | 3520 |
| 3521 if (browser_action()) | 3521 if (browser_action()) |
| 3522 ++num_surfaces; | 3522 ++num_surfaces; |
| 3523 | 3523 |
| 3524 if (is_app()) | 3524 if (is_app()) |
| 3525 ++num_surfaces; | 3525 ++num_surfaces; |
| 3526 | 3526 |
| 3527 return num_surfaces > 1; | 3527 return num_surfaces > 1; |
| 3528 } | 3528 } |
| 3529 | 3529 |
| 3530 bool Extension::CanExecuteScriptOnPage(const GURL& page_url, | 3530 bool Extension::IsPageTooSensitiveForScript(const GURL& page_url, |
| 3531 int tab_id, | 3531 std::string* error) const { |
| 3532 const UserScript* script, | |
| 3533 std::string* error) const { | |
| 3534 base::AutoLock auto_lock(runtime_data_lock_); | |
| 3535 // The gallery is special-cased as a restricted URL for scripting to prevent | 3532 // The gallery is special-cased as a restricted URL for scripting to prevent |
| 3536 // access to special JS bindings we expose to the gallery (and avoid things | 3533 // access to special JS bindings we expose to the gallery (and avoid things |
| 3537 // like extensions removing the "report abuse" link). | 3534 // like extensions removing the "report abuse" link). |
| 3538 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing | 3535 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing |
| 3539 // against the store app extent? | 3536 // against the store app extent? |
| 3540 GURL store_url(extension_urls::GetWebstoreLaunchURL()); | 3537 GURL store_url(extension_urls::GetWebstoreLaunchURL()); |
| 3541 if ((page_url.host() == store_url.host()) && | 3538 if ((page_url.host() == store_url.host()) && |
| 3542 !CanExecuteScriptEverywhere() && | 3539 !CanExecuteScriptEverywhere() && |
| 3543 !CommandLine::ForCurrentProcess()->HasSwitch( | 3540 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 3544 switches::kAllowScriptingGallery)) { | 3541 switches::kAllowScriptingGallery)) { |
| 3545 if (error) | 3542 if (error) |
| 3546 *error = errors::kCannotScriptGallery; | 3543 *error = errors::kCannotScriptGallery; |
| 3547 return false; | 3544 return true; |
| 3548 } | 3545 } |
| 3549 | 3546 |
| 3550 if (page_url.SchemeIs(chrome::kChromeUIScheme) && | 3547 if (page_url.SchemeIs(chrome::kChromeUIScheme) && |
| 3551 !CanExecuteScriptEverywhere()) | 3548 !CanExecuteScriptEverywhere()) |
| 3549 return true; | |
| 3550 | |
| 3551 return false; | |
| 3552 } | |
| 3553 | |
| 3554 bool Extension::CanExecuteScriptOnPage(const GURL& page_url, | |
| 3555 int tab_id, | |
| 3556 const UserScript* script, | |
| 3557 std::string* error) const { | |
| 3558 if (IsPageTooSensitiveForScript(page_url, error)) | |
| 3552 return false; | 3559 return false; |
| 3553 | 3560 |
| 3561 base::AutoLock auto_lock(runtime_data_lock_); | |
| 3554 // If a tab ID is specified, try the tab-specific permissions. | 3562 // If a tab ID is specified, try the tab-specific permissions. |
| 3555 if (tab_id >= 0) { | 3563 if (tab_id >= 0) { |
| 3556 const URLPatternSet* tab_permissions = | 3564 const URLPatternSet* tab_permissions = |
| 3557 runtime_data_.GetTabSpecificHostPermissions(tab_id); | 3565 runtime_data_.GetTabSpecificHostPermissions(tab_id); |
| 3558 if (tab_permissions && | 3566 if (tab_permissions && |
| 3559 tab_permissions->MatchesSecurityOrigin(page_url)) { | 3567 tab_permissions->MatchesSecurityOrigin(page_url)) { |
| 3560 return true; | 3568 return true; |
| 3561 } | 3569 } |
| 3562 } | 3570 } |
| 3563 | 3571 |
| 3564 // If a script is specified, use its matches. | 3572 // If a script is specified, use its matches. |
| 3565 if (script) | 3573 if (script) |
| 3566 return script->MatchesURL(page_url); | 3574 return script->MatchesURL(page_url); |
| 3567 | 3575 |
| 3568 // Otherwise, see if this extension has permission to execute script | 3576 // Otherwise, see if this extension has permission to execute script |
| 3569 // programmatically on pages. | 3577 // programmatically on pages. |
| 3570 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin( | 3578 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin( |
| 3571 page_url)) | 3579 page_url)) |
| 3572 return true; | 3580 return true; |
| 3573 | 3581 |
| 3574 if (error) { | 3582 if (error) { |
| 3575 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, | 3583 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
| 3576 page_url.spec()); | 3584 page_url.spec()); |
| 3577 } | 3585 } |
| 3578 | 3586 |
| 3579 return false; | 3587 return false; |
| 3580 } | 3588 } |
| 3581 | 3589 |
| 3590 bool Extension::CanRequestToActOnPage(const GURL& page_url, | |
| 3591 int tab_id) const { | |
| 3592 if (IsPageTooSensitiveForScript(page_url, NULL)) | |
|
Aaron Boodman
2012/07/03 01:29:31
I think this should just be IsPageTooSensitive...
Jeffrey Yasskin
2012/07/10 21:52:33
Done.
| |
| 3593 return false; | |
| 3594 return !CanExecuteScriptOnPage(page_url, tab_id, NULL, NULL); | |
| 3595 } | |
| 3596 | |
| 3582 bool Extension::ShowConfigureContextMenus() const { | 3597 bool Extension::ShowConfigureContextMenus() const { |
| 3583 // Don't show context menu for component extensions. We might want to show | 3598 // Don't show context menu for component extensions. We might want to show |
| 3584 // options for component extension button but now there is no component | 3599 // options for component extension button but now there is no component |
| 3585 // extension with options. All other menu items like uninstall have | 3600 // extension with options. All other menu items like uninstall have |
| 3586 // no sense for component extensions. | 3601 // no sense for component extensions. |
| 3587 return location() != Extension::COMPONENT; | 3602 return location() != Extension::COMPONENT; |
| 3588 } | 3603 } |
| 3589 | 3604 |
| 3590 bool Extension::CanSpecifyExperimentalPermission() const { | 3605 bool Extension::CanSpecifyExperimentalPermission() const { |
| 3591 if (location() == Extension::COMPONENT) | 3606 if (location() == Extension::COMPONENT) |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3875 | 3890 |
| 3876 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3891 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3877 const Extension* extension, | 3892 const Extension* extension, |
| 3878 const PermissionSet* permissions, | 3893 const PermissionSet* permissions, |
| 3879 Reason reason) | 3894 Reason reason) |
| 3880 : reason(reason), | 3895 : reason(reason), |
| 3881 extension(extension), | 3896 extension(extension), |
| 3882 permissions(permissions) {} | 3897 permissions(permissions) {} |
| 3883 | 3898 |
| 3884 } // namespace extensions | 3899 } // namespace extensions |
| OLD | NEW |