OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/extensions/extension_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_pref_store.h" | 10 #include "chrome/browser/extensions/extension_pref_store.h" |
11 #include "chrome/browser/prefs/pref_notifier.h" | 11 #include "chrome/browser/prefs/pref_notifier.h" |
12 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 12 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 13 #include "chrome/common/url_constants.h" |
13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/common/extensions/url_pattern.h" | 15 #include "chrome/common/extensions/url_pattern.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "content/common/notification_service.h" | 17 #include "content/common/notification_service.h" |
17 | 18 |
18 using base::Time; | 19 using base::Time; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Additional preferences keys | 23 // Additional preferences keys |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 DictionaryValue* ext = GetExtensionPref(extension_id); | 557 DictionaryValue* ext = GetExtensionPref(extension_id); |
557 if (!ext || !ext->GetBoolean(kPrefGrantedPermissionsAll, full_access)) | 558 if (!ext || !ext->GetBoolean(kPrefGrantedPermissionsAll, full_access)) |
558 return false; | 559 return false; |
559 | 560 |
560 ReadExtensionPrefStringSet( | 561 ReadExtensionPrefStringSet( |
561 extension_id, kPrefGrantedPermissionsAPI, api_permissions); | 562 extension_id, kPrefGrantedPermissionsAPI, api_permissions); |
562 | 563 |
563 std::set<std::string> host_permissions; | 564 std::set<std::string> host_permissions; |
564 ReadExtensionPrefStringSet( | 565 ReadExtensionPrefStringSet( |
565 extension_id, kPrefGrantedPermissionsHost, &host_permissions); | 566 extension_id, kPrefGrantedPermissionsHost, &host_permissions); |
| 567 bool allow_file_access = AllowFileAccess(extension_id); |
566 | 568 |
567 // The granted host permissions contain hosts from the manifest's | 569 // The granted host permissions contain hosts from the manifest's |
568 // "permissions" array and from the content script "matches" arrays, | 570 // "permissions" array and from the content script "matches" arrays, |
569 // so the URLPattern needs to accept valid schemes from both types. | 571 // so the URLPattern needs to accept valid schemes from both types. |
570 for (std::set<std::string>::iterator i = host_permissions.begin(); | 572 for (std::set<std::string>::iterator i = host_permissions.begin(); |
571 i != host_permissions.end(); ++i) { | 573 i != host_permissions.end(); ++i) { |
572 URLPattern pattern( | 574 URLPattern pattern( |
573 Extension::kValidHostPermissionSchemes | | 575 Extension::kValidHostPermissionSchemes | |
574 UserScript::kValidUserScriptSchemes); | 576 UserScript::kValidUserScriptSchemes); |
575 | 577 |
576 // Parse without strict checks, so that new strict checks do not | 578 // Parse without strict checks, so that new strict checks do not |
577 // fail on a pattern in an installed extension. | 579 // fail on a pattern in an installed extension. |
578 if (URLPattern::PARSE_SUCCESS != pattern.Parse( | 580 if (URLPattern::PARSE_SUCCESS != pattern.Parse( |
579 *i, URLPattern::PARSE_LENIENT)) { | 581 *i, URLPattern::PARSE_LENIENT)) { |
580 NOTREACHED(); // Corrupt prefs? Hand editing? | 582 NOTREACHED(); // Corrupt prefs? Hand editing? |
581 } else { | 583 } else { |
| 584 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { |
| 585 pattern.set_valid_schemes( |
| 586 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
| 587 } |
582 host_extent->AddPattern(pattern); | 588 host_extent->AddPattern(pattern); |
583 } | 589 } |
584 } | 590 } |
585 | 591 |
586 return true; | 592 return true; |
587 } | 593 } |
588 | 594 |
589 void ExtensionPrefs::AddGrantedPermissions( | 595 void ExtensionPrefs::AddGrantedPermissions( |
590 const std::string& extension_id, | 596 const std::string& extension_id, |
591 const bool full_access, | 597 const bool full_access, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 return ReadExtensionPrefBoolean(extension_id, kPrefAllowFileAccess); | 633 return ReadExtensionPrefBoolean(extension_id, kPrefAllowFileAccess); |
628 } | 634 } |
629 | 635 |
630 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id, | 636 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id, |
631 bool allow) { | 637 bool allow) { |
632 UpdateExtensionPref(extension_id, kPrefAllowFileAccess, | 638 UpdateExtensionPref(extension_id, kPrefAllowFileAccess, |
633 Value::CreateBooleanValue(allow)); | 639 Value::CreateBooleanValue(allow)); |
634 SavePrefsAndNotify(); | 640 SavePrefsAndNotify(); |
635 } | 641 } |
636 | 642 |
| 643 bool ExtensionPrefs::HasAllowFileAccessSetting( |
| 644 const std::string& extension_id) const { |
| 645 DictionaryValue* ext = GetExtensionPref(extension_id); |
| 646 return ext && ext->HasKey(kPrefAllowFileAccess); |
| 647 } |
| 648 |
637 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType( | 649 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType( |
638 const std::string& extension_id, | 650 const std::string& extension_id, |
639 ExtensionPrefs::LaunchType default_pref_value) { | 651 ExtensionPrefs::LaunchType default_pref_value) { |
640 int value = -1; | 652 int value = -1; |
641 LaunchType result = LAUNCH_REGULAR; | 653 LaunchType result = LAUNCH_REGULAR; |
642 | 654 |
643 if (ReadExtensionPrefInteger(extension_id, kPrefLaunchType, &value) && | 655 if (ReadExtensionPrefInteger(extension_id, kPrefLaunchType, &value) && |
644 (value == LAUNCH_PINNED || | 656 (value == LAUNCH_PINNED || |
645 value == LAUNCH_REGULAR || | 657 value == LAUNCH_REGULAR || |
646 value == LAUNCH_FULLSCREEN || | 658 value == LAUNCH_FULLSCREEN || |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1430 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
1419 prefs->RegisterDictionaryPref(kExtensionsPref); | 1431 prefs->RegisterDictionaryPref(kExtensionsPref); |
1420 prefs->RegisterListPref(kExtensionToolbar); | 1432 prefs->RegisterListPref(kExtensionToolbar); |
1421 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); | 1433 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); |
1422 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); | 1434 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); |
1423 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); | 1435 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); |
1424 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); | 1436 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); |
1425 prefs->RegisterListPref(prefs::kExtensionInstallForceList); | 1437 prefs->RegisterListPref(prefs::kExtensionInstallForceList); |
1426 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); | 1438 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); |
1427 } | 1439 } |
OLD | NEW |