Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 10443105: Take 2 at implementing activeTab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: aa comments, revert XHR stuff Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 3391 matching lines...) Expand 10 before | Expand all | Expand 10 after
3402 if (browser_action()) 3402 if (browser_action())
3403 ++num_surfaces; 3403 ++num_surfaces;
3404 3404
3405 if (is_app()) 3405 if (is_app())
3406 ++num_surfaces; 3406 ++num_surfaces;
3407 3407
3408 return num_surfaces > 1; 3408 return num_surfaces > 1;
3409 } 3409 }
3410 3410
3411 bool Extension::CanExecuteScriptOnPage(const GURL& page_url, 3411 bool Extension::CanExecuteScriptOnPage(const GURL& page_url,
3412 int tab_id,
3412 const UserScript* script, 3413 const UserScript* script,
3413 std::string* error) const { 3414 std::string* error) const {
3414 base::AutoLock auto_lock(runtime_data_lock_); 3415 base::AutoLock auto_lock(runtime_data_lock_);
3415 // The gallery is special-cased as a restricted URL for scripting to prevent 3416 // The gallery is special-cased as a restricted URL for scripting to prevent
3416 // access to special JS bindings we expose to the gallery (and avoid things 3417 // access to special JS bindings we expose to the gallery (and avoid things
3417 // like extensions removing the "report abuse" link). 3418 // like extensions removing the "report abuse" link).
3418 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing 3419 // TODO(erikkay): This seems like the wrong test. Shouldn't we we testing
3419 // against the store app extent? 3420 // against the store app extent?
3420 GURL store_url(extension_urls::GetWebstoreLaunchURL()); 3421 GURL store_url(extension_urls::GetWebstoreLaunchURL());
3421 if ((page_url.host() == store_url.host()) && 3422 if ((page_url.host() == store_url.host()) &&
3422 !CanExecuteScriptEverywhere() && 3423 !CanExecuteScriptEverywhere() &&
3423 !CommandLine::ForCurrentProcess()->HasSwitch( 3424 !CommandLine::ForCurrentProcess()->HasSwitch(
3424 switches::kAllowScriptingGallery)) { 3425 switches::kAllowScriptingGallery)) {
3425 if (error) 3426 if (error)
3426 *error = errors::kCannotScriptGallery; 3427 *error = errors::kCannotScriptGallery;
3427 return false; 3428 return false;
3428 } 3429 }
3429 3430
3430 if (page_url.SchemeIs(chrome::kChromeUIScheme) && 3431 if (page_url.SchemeIs(chrome::kChromeUIScheme) &&
3431 !CanExecuteScriptEverywhere()) 3432 !CanExecuteScriptEverywhere())
3432 return false; 3433 return false;
3433 3434
3435 // If a tab ID is specified, try the tab-specific permissions.
3436 if (tab_id >= 0) {
3437 const URLPatternSet* tab_permissions =
3438 runtime_data_.GetTabSpecificHostPermissions(tab_id);
3439 if (tab_permissions &&
3440 tab_permissions->MatchesSecurityOrigin(page_url)) {
3441 return true;
3442 }
3443 }
3444
3434 // If a script is specified, use its matches. 3445 // If a script is specified, use its matches.
3435 if (script) 3446 if (script)
3436 return script->MatchesURL(page_url); 3447 return script->MatchesURL(page_url);
3437 3448
3438 // Otherwise, see if this extension has permission to execute script 3449 // Otherwise, see if this extension has permission to execute script
3439 // programmatically on pages. 3450 // programmatically on pages.
3440 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin( 3451 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin(
3441 page_url)) 3452 page_url))
3442 return true; 3453 return true;
3443 3454
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3486 it != whitelist->end(); ++it) { 3497 it != whitelist->end(); ++it) {
3487 if (id() == *it) { 3498 if (id() == *it) {
3488 return true; 3499 return true;
3489 } 3500 }
3490 } 3501 }
3491 3502
3492 return false; 3503 return false;
3493 } 3504 }
3494 3505
3495 bool Extension::CanCaptureVisiblePage(const GURL& page_url, 3506 bool Extension::CanCaptureVisiblePage(const GURL& page_url,
3507 int tab_id,
3496 std::string *error) const { 3508 std::string *error) const {
3509 if (tab_id >= 0) {
3510 const URLPatternSet* tab = GetTabSpecificHostPermissions(tab_id);
3511 if (tab && tab->MatchesSecurityOrigin(page_url))
3512 return true;
3513 }
3514
3497 if (HasHostPermission(page_url) || page_url.GetOrigin() == url()) 3515 if (HasHostPermission(page_url) || page_url.GetOrigin() == url())
3498 return true; 3516 return true;
3499 3517
3500 if (error) { 3518 if (error) {
3501 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, 3519 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage,
3502 page_url.spec()); 3520 page_url.spec());
3503 } 3521 }
3504 return false; 3522 return false;
3505 } 3523 }
3506 3524
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
3662 script_badge_->SetIcon(kDefaultTabId, icon); 3680 script_badge_->SetIcon(kDefaultTabId, icon);
3663 3681
3664 std::string title = browser_action()->GetTitle(kDefaultTabId); 3682 std::string title = browser_action()->GetTitle(kDefaultTabId);
3665 if (!title.empty()) 3683 if (!title.empty())
3666 script_badge_->SetTitle(kDefaultTabId, title); 3684 script_badge_->SetTitle(kDefaultTabId, title);
3667 } 3685 }
3668 3686
3669 return script_badge_.get(); 3687 return script_badge_.get();
3670 } 3688 }
3671 3689
3690 const URLPatternSet* Extension::GetTabSpecificHostPermissions(
3691 int tab_id) const {
3692 base::AutoLock auto_lock(runtime_data_lock_);
3693 return runtime_data_.GetTabSpecificHostPermissions(tab_id);
3694 }
3695
3696 void Extension::SetTabSpecificHostPermissions(
3697 int tab_id,
3698 const URLPatternSet& permissions) const {
3699 base::AutoLock auto_lock(runtime_data_lock_);
3700 runtime_data_.SetTabSpecificHostPermissions(tab_id, permissions);
3701 }
3702
3703 void Extension::ClearTabSpecificHostPermissions(int tab_id) const {
3704 base::AutoLock auto_lock(runtime_data_lock_);
3705 runtime_data_.ClearTabSpecificHostPermissions(tab_id);
3706 }
3707
3672 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) { 3708 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) {
3673 if (!is_platform_app()) 3709 if (!is_platform_app())
3674 return true; 3710 return true;
3675 3711
3676 if (!CommandLine::ForCurrentProcess()->HasSwitch( 3712 if (!CommandLine::ForCurrentProcess()->HasSwitch(
3677 switches::kEnablePlatformApps)) { 3713 switches::kEnablePlatformApps)) {
3678 *utf8_error = errors::kPlatformAppFlagRequired; 3714 *utf8_error = errors::kPlatformAppFlagRequired;
3679 return false; 3715 return false;
3680 } 3716 }
3681 3717
(...skipping 25 matching lines...) Expand all
3707 scoped_refptr<const ExtensionPermissionSet> 3743 scoped_refptr<const ExtensionPermissionSet>
3708 Extension::RuntimeData::GetActivePermissions() const { 3744 Extension::RuntimeData::GetActivePermissions() const {
3709 return active_permissions_; 3745 return active_permissions_;
3710 } 3746 }
3711 3747
3712 void Extension::RuntimeData::SetActivePermissions( 3748 void Extension::RuntimeData::SetActivePermissions(
3713 const ExtensionPermissionSet* active) { 3749 const ExtensionPermissionSet* active) {
3714 active_permissions_ = active; 3750 active_permissions_ = active;
3715 } 3751 }
3716 3752
3753 const URLPatternSet*
3754 Extension::RuntimeData::GetTabSpecificHostPermissions(int tab_id) const {
3755 CHECK_GE(tab_id, 0);
3756 TabHostPermissionsMap::const_iterator it =
3757 tab_specific_host_permissions_.find(tab_id);
3758 return (it != tab_specific_host_permissions_.end()) ? it->second.get() : NULL;
3759 }
3760
3761 void Extension::RuntimeData::SetTabSpecificHostPermissions(
3762 int tab_id,
3763 const URLPatternSet& hosts) {
3764 CHECK_GE(tab_id, 0);
3765 tab_specific_host_permissions_[tab_id] =
3766 make_linked_ptr(new URLPatternSet(hosts));
3767 }
3768
3769 void Extension::RuntimeData::ClearTabSpecificHostPermissions(int tab_id) {
3770 CHECK_GE(tab_id, 0);
3771 tab_specific_host_permissions_.erase(tab_id);
3772 }
3773
3717 UnloadedExtensionInfo::UnloadedExtensionInfo( 3774 UnloadedExtensionInfo::UnloadedExtensionInfo(
3718 const Extension* extension, 3775 const Extension* extension,
3719 extension_misc::UnloadedExtensionReason reason) 3776 extension_misc::UnloadedExtensionReason reason)
3720 : reason(reason), 3777 : reason(reason),
3721 already_disabled(false), 3778 already_disabled(false),
3722 extension(extension) {} 3779 extension(extension) {}
3723 3780
3724 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3781 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3725 const Extension* extension, 3782 const Extension* extension,
3726 const ExtensionPermissionSet* permissions, 3783 const ExtensionPermissionSet* permissions,
3727 Reason reason) 3784 Reason reason)
3728 : reason(reason), 3785 : reason(reason),
3729 extension(extension), 3786 extension(extension),
3730 permissions(permissions) {} 3787 permissions(permissions) {}
3731 3788
3732 } // namespace extensions 3789 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698