Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "extensions/common/permissions/permissions_data.h" | 5 #include "extensions/common/permissions/permissions_data.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 | 335 |
| 336 // static | 336 // static |
| 337 void PermissionsData::ClearTabSpecificPermissions( | 337 void PermissionsData::ClearTabSpecificPermissions( |
| 338 const Extension* extension, | 338 const Extension* extension, |
| 339 int tab_id) { | 339 int tab_id) { |
| 340 CHECK_GE(tab_id, 0); | 340 CHECK_GE(tab_id, 0); |
| 341 extension->permissions_data()->tab_specific_permissions_.erase(tab_id); | 341 extension->permissions_data()->tab_specific_permissions_.erase(tab_id); |
| 342 } | 342 } |
| 343 | 343 |
| 344 // static | 344 // static |
| 345 bool PermissionsData::HasTabSpecificPermission(const Extension* extension, | |
| 346 int tab_id, | |
| 347 const GURL& url) { | |
| 348 if (tab_id >= 0) { | |
| 349 scoped_refptr<const PermissionSet> tab_permissions = | |
| 350 GetTabSpecificPermissions(extension, tab_id); | |
| 351 if (tab_permissions.get() && | |
| 352 tab_permissions->explicit_hosts().MatchesSecurityOrigin(url)) { | |
| 353 return true; | |
| 354 } | |
| 355 } | |
| 356 return false; | |
| 357 } | |
| 358 | |
| 359 // static | |
| 345 bool PermissionsData::HasAPIPermission(const Extension* extension, | 360 bool PermissionsData::HasAPIPermission(const Extension* extension, |
| 346 APIPermission::ID permission) { | 361 APIPermission::ID permission) { |
| 347 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); | 362 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); |
| 348 return GetActivePermissions(extension)->HasAPIPermission(permission); | 363 return GetActivePermissions(extension)->HasAPIPermission(permission); |
| 349 } | 364 } |
| 350 | 365 |
| 351 // static | 366 // static |
| 352 bool PermissionsData::HasAPIPermission( | 367 bool PermissionsData::HasAPIPermission( |
| 353 const Extension* extension, | 368 const Extension* extension, |
| 354 const std::string& permission_name) { | 369 const std::string& permission_name) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 return GetActivePermissions(extension)->HasExplicitAccessToOrigin(url); | 422 return GetActivePermissions(extension)->HasExplicitAccessToOrigin(url); |
| 408 } | 423 } |
| 409 | 424 |
| 410 // static | 425 // static |
| 411 bool PermissionsData::HasEffectiveAccessToAllHosts(const Extension* extension) { | 426 bool PermissionsData::HasEffectiveAccessToAllHosts(const Extension* extension) { |
| 412 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); | 427 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); |
| 413 return GetActivePermissions(extension)->HasEffectiveAccessToAllHosts(); | 428 return GetActivePermissions(extension)->HasEffectiveAccessToAllHosts(); |
| 414 } | 429 } |
| 415 | 430 |
| 416 // static | 431 // static |
| 432 bool PermissionsData::HasAccessToMostHosts(const Extension* extension) { | |
| 433 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); | |
| 434 return GetActivePermissions(extension)->HasAccessToMostHosts(); | |
| 435 } | |
| 436 | |
| 437 // static | |
| 417 PermissionMessages PermissionsData::GetPermissionMessages( | 438 PermissionMessages PermissionsData::GetPermissionMessages( |
| 418 const Extension* extension) { | 439 const Extension* extension) { |
| 419 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); | 440 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); |
| 420 if (ShouldSkipPermissionWarnings(extension)) { | 441 if (ShouldSkipPermissionWarnings(extension)) { |
| 421 return PermissionMessages(); | 442 return PermissionMessages(); |
| 422 } else { | 443 } else { |
| 423 return PermissionMessageProvider::Get()->GetPermissionMessages( | 444 return PermissionMessageProvider::Get()->GetPermissionMessages( |
| 424 GetActivePermissions(extension), extension->GetType()); | 445 GetActivePermissions(extension), extension->GetType()); |
| 425 } | 446 } |
| 426 } | 447 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 | 504 |
| 484 if (top_frame_url.SchemeIs(extensions::kExtensionScheme) && | 505 if (top_frame_url.SchemeIs(extensions::kExtensionScheme) && |
| 485 top_frame_url.GetOrigin() != | 506 top_frame_url.GetOrigin() != |
| 486 Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() && | 507 Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() && |
| 487 !can_execute_everywhere) { | 508 !can_execute_everywhere) { |
| 488 if (error) | 509 if (error) |
| 489 *error = errors::kCannotAccessExtensionUrl; | 510 *error = errors::kCannotAccessExtensionUrl; |
| 490 return false; | 511 return false; |
| 491 } | 512 } |
| 492 | 513 |
| 493 // If a tab ID is specified, try the tab-specific permissions. | 514 if (HasTabSpecificPermission(extension, tab_id, document_url)) |
|
not at google - send to devlin
2014/05/21 20:10:20
and "HasTabSpecificPermission" doesn't imply to me
Devlin
2014/05/21 23:16:07
My worry is making it clear that this is only aski
not at google - send to devlin
2014/05/21 23:33:45
or HasTabSpecificPermissionToExecuteScript
times
Devlin
2014/05/22 15:52:14
Done.
| |
| 494 if (tab_id >= 0) { | 515 return true; |
| 495 scoped_refptr<const PermissionSet> tab_permissions = | |
| 496 GetTabSpecificPermissions(extension, tab_id); | |
| 497 if (tab_permissions.get() && | |
| 498 tab_permissions->explicit_hosts().MatchesSecurityOrigin(document_url)) { | |
| 499 return true; | |
| 500 } | |
| 501 } | |
| 502 | 516 |
| 503 bool can_access = false; | 517 bool can_access = false; |
| 504 | 518 |
| 505 if (script) { | 519 if (script) { |
| 506 // If a script is specified, use its matches. | 520 // If a script is specified, use its matches. |
| 507 can_access = script->MatchesURL(document_url); | 521 can_access = script->MatchesURL(document_url); |
| 508 } else { | 522 } else { |
| 509 // Otherwise, see if this extension has permission to execute script | 523 // Otherwise, see if this extension has permission to execute script |
| 510 // programmatically on pages. | 524 // programmatically on pages. |
| 511 can_access = GetActivePermissions(extension)-> | 525 can_access = GetActivePermissions(extension)-> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 return false; | 569 return false; |
| 556 } | 570 } |
| 557 | 571 |
| 558 if (error) | 572 if (error) |
| 559 *error = errors::kAllURLOrActiveTabNeeded; | 573 *error = errors::kAllURLOrActiveTabNeeded; |
| 560 return false; | 574 return false; |
| 561 } | 575 } |
| 562 | 576 |
| 563 // static | 577 // static |
| 564 bool PermissionsData::RequiresActionForScriptExecution( | 578 bool PermissionsData::RequiresActionForScriptExecution( |
| 565 const Extension* extension) { | 579 const Extension* extension, |
| 580 int tab_id, | |
| 581 const GURL& document_url) { | |
|
not at google - send to devlin
2014/05/21 20:10:20
"document URL" isn't right, it's actually top leve
Devlin
2014/05/21 23:16:07
Done.
| |
| 566 // For now, the user should be notified when an extension with all hosts | 582 // For now, the user should be notified when an extension with all hosts |
| 567 // permission tries to execute a script on a page. Exceptions for policy- | 583 // permission tries to execute a script on a page, with exceptions for policy- |
| 568 // enabled and component extensions. | 584 // enabled and component extensions. If this doesn't meet those criteria, |
| 569 return extension->ShouldDisplayInExtensionSettings() && | 585 // return immediately. |
| 570 !Manifest::IsPolicyLocation(extension->location()) && | 586 if (!extension->ShouldDisplayInExtensionSettings() || |
| 571 !Manifest::IsComponentLocation(extension->location()) && | 587 Manifest::IsPolicyLocation(extension->location()) || |
| 572 HasEffectiveAccessToAllHosts(extension); | 588 Manifest::IsComponentLocation(extension->location()) || |
|
not at google - send to devlin
2014/05/21 20:10:20
the ComponentLocation thing is actually unnecessar
Devlin
2014/05/21 23:16:07
Yes, but that's using internal logic from ShouldDi
not at google - send to devlin
2014/05/21 23:33:45
Leaving in is fine.
I think we're going to want 2
| |
| 589 !HasAccessToMostHosts(extension)) { | |
| 590 return false; | |
| 591 } | |
| 592 | |
| 593 // If the extension has explicit permission to run on the given tab, then | |
| 594 // we don't need to alert the user. | |
| 595 if (HasTabSpecificPermission(extension, tab_id, document_url)) | |
| 596 return false; | |
| 597 | |
| 598 return true; | |
| 573 } | 599 } |
| 574 | 600 |
| 575 bool PermissionsData::ParsePermissions(Extension* extension, | 601 bool PermissionsData::ParsePermissions(Extension* extension, |
| 576 base::string16* error) { | 602 base::string16* error) { |
| 577 initial_required_permissions_.reset(new InitialPermissions); | 603 initial_required_permissions_.reset(new InitialPermissions); |
| 578 if (!ParseHelper(extension, | 604 if (!ParseHelper(extension, |
| 579 keys::kPermissions, | 605 keys::kPermissions, |
| 580 &initial_required_permissions_->api_permissions, | 606 &initial_required_permissions_->api_permissions, |
| 581 &initial_required_permissions_->host_permissions, | 607 &initial_required_permissions_->host_permissions, |
| 582 error)) { | 608 error)) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 initial_optional_permissions_->api_permissions, | 643 initial_optional_permissions_->api_permissions, |
| 618 initial_optional_permissions_->manifest_permissions, | 644 initial_optional_permissions_->manifest_permissions, |
| 619 initial_optional_permissions_->host_permissions, | 645 initial_optional_permissions_->host_permissions, |
| 620 URLPatternSet()); | 646 URLPatternSet()); |
| 621 | 647 |
| 622 initial_required_permissions_.reset(); | 648 initial_required_permissions_.reset(); |
| 623 initial_optional_permissions_.reset(); | 649 initial_optional_permissions_.reset(); |
| 624 } | 650 } |
| 625 | 651 |
| 626 } // namespace extensions | 652 } // namespace extensions |
| OLD | NEW |