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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 231 |
232 return true; | 232 return true; |
233 } | 233 } |
234 | 234 |
235 // Returns true if this extension id is from a trusted provider. | 235 // Returns true if this extension id is from a trusted provider. |
236 bool IsTrustedId(const std::string& extension_id) { | 236 bool IsTrustedId(const std::string& extension_id) { |
237 // See http://b/4946060 for more details. | 237 // See http://b/4946060 for more details. |
238 return extension_id == std::string("nckgahadagoaajjgafhacjanaoiihapd"); | 238 return extension_id == std::string("nckgahadagoaajjgafhacjanaoiihapd"); |
239 } | 239 } |
240 | 240 |
| 241 // Returns true if the |extension| has tab-specific permission to operate on |
| 242 // the tab specified by |tab_id| with the given |url|. |
| 243 // Note that if this returns false, it doesn't mean the extension can't run on |
| 244 // the given tab, only that it does not have tab-specific permission to do so. |
| 245 bool HasTabSpecificPermissionToExecuteScript( |
| 246 const Extension* extension, |
| 247 int tab_id, |
| 248 const GURL& url) { |
| 249 if (tab_id >= 0) { |
| 250 scoped_refptr<const PermissionSet> tab_permissions = |
| 251 PermissionsData::GetTabSpecificPermissions(extension, tab_id); |
| 252 if (tab_permissions.get() && |
| 253 tab_permissions->explicit_hosts().MatchesSecurityOrigin(url)) { |
| 254 return true; |
| 255 } |
| 256 } |
| 257 return false; |
| 258 } |
| 259 |
241 } // namespace | 260 } // namespace |
242 | 261 |
243 struct PermissionsData::InitialPermissions { | 262 struct PermissionsData::InitialPermissions { |
244 APIPermissionSet api_permissions; | 263 APIPermissionSet api_permissions; |
245 ManifestPermissionSet manifest_permissions; | 264 ManifestPermissionSet manifest_permissions; |
246 URLPatternSet host_permissions; | 265 URLPatternSet host_permissions; |
247 URLPatternSet scriptable_hosts; | 266 URLPatternSet scriptable_hosts; |
248 }; | 267 }; |
249 | 268 |
250 PermissionsData::PermissionsData() { | 269 PermissionsData::PermissionsData() { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 return GetActivePermissions(extension)->HasExplicitAccessToOrigin(url); | 426 return GetActivePermissions(extension)->HasExplicitAccessToOrigin(url); |
408 } | 427 } |
409 | 428 |
410 // static | 429 // static |
411 bool PermissionsData::HasEffectiveAccessToAllHosts(const Extension* extension) { | 430 bool PermissionsData::HasEffectiveAccessToAllHosts(const Extension* extension) { |
412 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); | 431 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); |
413 return GetActivePermissions(extension)->HasEffectiveAccessToAllHosts(); | 432 return GetActivePermissions(extension)->HasEffectiveAccessToAllHosts(); |
414 } | 433 } |
415 | 434 |
416 // static | 435 // static |
| 436 bool PermissionsData::ShouldWarnAllHosts(const Extension* extension) { |
| 437 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); |
| 438 return GetActivePermissions(extension)->ShouldWarnAllHosts(); |
| 439 } |
| 440 |
| 441 // static |
417 PermissionMessages PermissionsData::GetPermissionMessages( | 442 PermissionMessages PermissionsData::GetPermissionMessages( |
418 const Extension* extension) { | 443 const Extension* extension) { |
419 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); | 444 base::AutoLock auto_lock(extension->permissions_data()->runtime_lock_); |
420 if (ShouldSkipPermissionWarnings(extension)) { | 445 if (ShouldSkipPermissionWarnings(extension)) { |
421 return PermissionMessages(); | 446 return PermissionMessages(); |
422 } else { | 447 } else { |
423 return PermissionMessageProvider::Get()->GetPermissionMessages( | 448 return PermissionMessageProvider::Get()->GetPermissionMessages( |
424 GetActivePermissions(extension), extension->GetType()); | 449 GetActivePermissions(extension), extension->GetType()); |
425 } | 450 } |
426 } | 451 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 508 |
484 if (top_frame_url.SchemeIs(extensions::kExtensionScheme) && | 509 if (top_frame_url.SchemeIs(extensions::kExtensionScheme) && |
485 top_frame_url.GetOrigin() != | 510 top_frame_url.GetOrigin() != |
486 Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() && | 511 Extension::GetBaseURLFromExtensionId(extension->id()).GetOrigin() && |
487 !can_execute_everywhere) { | 512 !can_execute_everywhere) { |
488 if (error) | 513 if (error) |
489 *error = errors::kCannotAccessExtensionUrl; | 514 *error = errors::kCannotAccessExtensionUrl; |
490 return false; | 515 return false; |
491 } | 516 } |
492 | 517 |
493 // If a tab ID is specified, try the tab-specific permissions. | 518 if (HasTabSpecificPermissionToExecuteScript(extension, tab_id, top_frame_url)) |
494 if (tab_id >= 0) { | 519 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 | 520 |
503 bool can_access = false; | 521 bool can_access = false; |
504 | 522 |
505 if (script) { | 523 if (script) { |
506 // If a script is specified, use its matches. | 524 // If a script is specified, use its matches. |
507 can_access = script->MatchesURL(document_url); | 525 can_access = script->MatchesURL(document_url); |
508 } else { | 526 } else { |
509 // Otherwise, see if this extension has permission to execute script | 527 // Otherwise, see if this extension has permission to execute script |
510 // programmatically on pages. | 528 // programmatically on pages. |
511 can_access = GetActivePermissions(extension)-> | 529 can_access = GetActivePermissions(extension)-> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 return false; | 573 return false; |
556 } | 574 } |
557 | 575 |
558 if (error) | 576 if (error) |
559 *error = errors::kAllURLOrActiveTabNeeded; | 577 *error = errors::kAllURLOrActiveTabNeeded; |
560 return false; | 578 return false; |
561 } | 579 } |
562 | 580 |
563 // static | 581 // static |
564 bool PermissionsData::RequiresActionForScriptExecution( | 582 bool PermissionsData::RequiresActionForScriptExecution( |
565 const Extension* extension) { | 583 const Extension* extension, |
| 584 int tab_id, |
| 585 const GURL& url) { |
566 // For now, the user should be notified when an extension with all hosts | 586 // 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- | 587 // permission tries to execute a script on a page, with exceptions for policy- |
568 // enabled and component extensions. | 588 // enabled and component extensions. If this doesn't meet those criteria, |
569 return extension->ShouldDisplayInExtensionSettings() && | 589 // return immediately. |
570 !Manifest::IsPolicyLocation(extension->location()) && | 590 if (!extension->ShouldDisplayInExtensionSettings() || |
571 !Manifest::IsComponentLocation(extension->location()) && | 591 Manifest::IsPolicyLocation(extension->location()) || |
572 HasEffectiveAccessToAllHosts(extension); | 592 Manifest::IsComponentLocation(extension->location()) || |
| 593 !ShouldWarnAllHosts(extension)) { |
| 594 return false; |
| 595 } |
| 596 |
| 597 // If the extension has explicit permission to run on the given tab, then |
| 598 // we don't need to alert the user. |
| 599 if (HasTabSpecificPermissionToExecuteScript(extension, tab_id, url)) |
| 600 return false; |
| 601 |
| 602 return true; |
573 } | 603 } |
574 | 604 |
575 bool PermissionsData::ParsePermissions(Extension* extension, | 605 bool PermissionsData::ParsePermissions(Extension* extension, |
576 base::string16* error) { | 606 base::string16* error) { |
577 initial_required_permissions_.reset(new InitialPermissions); | 607 initial_required_permissions_.reset(new InitialPermissions); |
578 if (!ParseHelper(extension, | 608 if (!ParseHelper(extension, |
579 keys::kPermissions, | 609 keys::kPermissions, |
580 &initial_required_permissions_->api_permissions, | 610 &initial_required_permissions_->api_permissions, |
581 &initial_required_permissions_->host_permissions, | 611 &initial_required_permissions_->host_permissions, |
582 error)) { | 612 error)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 initial_optional_permissions_->api_permissions, | 647 initial_optional_permissions_->api_permissions, |
618 initial_optional_permissions_->manifest_permissions, | 648 initial_optional_permissions_->manifest_permissions, |
619 initial_optional_permissions_->host_permissions, | 649 initial_optional_permissions_->host_permissions, |
620 URLPatternSet()); | 650 URLPatternSet()); |
621 | 651 |
622 initial_required_permissions_.reset(); | 652 initial_required_permissions_.reset(); |
623 initial_optional_permissions_.reset(); | 653 initial_optional_permissions_.reset(); |
624 } | 654 } |
625 | 655 |
626 } // namespace extensions | 656 } // namespace extensions |
OLD | NEW |