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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
566 | 567 |
567 // The granted host permissions contain hosts from the manifest's | 568 // The granted host permissions contain hosts from the manifest's |
568 // "permissions" array and from the content script "matches" arrays, | 569 // "permissions" array and from the content script "matches" arrays, |
569 // so the URLPattern needs to accept valid schemes from both types. | 570 // so the URLPattern needs to accept valid schemes from both types. |
| 571 // file:/// is temporarily included, but is removed below if not actually |
| 572 // allowed. |
| 573 int valid_schemes = Extension::kValidHostPermissionSchemes | |
| 574 UserScript::kValidUserScriptSchemes | URLPattern::SCHEME_FILE; |
| 575 bool allow_file_access = AllowFileAccess(extension_id); |
| 576 |
570 for (std::set<std::string>::iterator i = host_permissions.begin(); | 577 for (std::set<std::string>::iterator i = host_permissions.begin(); |
571 i != host_permissions.end(); ++i) { | 578 i != host_permissions.end(); ++i) { |
572 URLPattern pattern( | 579 URLPattern pattern(valid_schemes); |
573 Extension::kValidHostPermissionSchemes | | |
574 UserScript::kValidUserScriptSchemes); | |
575 | 580 |
576 // Parse without strict checks, so that new strict checks do not | 581 // Parse without strict checks, so that new strict checks do not |
577 // fail on a pattern in an installed extension. | 582 // fail on a pattern in an installed extension. |
578 if (URLPattern::PARSE_SUCCESS != pattern.Parse( | 583 if (URLPattern::PARSE_SUCCESS != pattern.Parse( |
579 *i, URLPattern::PARSE_LENIENT)) { | 584 *i, URLPattern::PARSE_LENIENT)) { |
580 NOTREACHED(); // Corrupt prefs? Hand editing? | 585 NOTREACHED(); // Corrupt prefs? Hand editing? |
581 } else { | 586 } else { |
| 587 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { |
| 588 if (pattern.scheme() == chrome::kFileScheme) { |
| 589 continue; |
| 590 } else { |
| 591 CHECK_EQ("*", pattern.scheme()); |
| 592 pattern.set_valid_schemes( |
| 593 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
| 594 } |
| 595 } |
582 host_extent->AddPattern(pattern); | 596 host_extent->AddPattern(pattern); |
583 } | 597 } |
584 } | 598 } |
585 | 599 |
586 return true; | 600 return true; |
587 } | 601 } |
588 | 602 |
589 void ExtensionPrefs::AddGrantedPermissions( | 603 void ExtensionPrefs::AddGrantedPermissions( |
590 const std::string& extension_id, | 604 const std::string& extension_id, |
591 const bool full_access, | 605 const bool full_access, |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1432 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
1419 prefs->RegisterDictionaryPref(kExtensionsPref); | 1433 prefs->RegisterDictionaryPref(kExtensionsPref); |
1420 prefs->RegisterListPref(kExtensionToolbar); | 1434 prefs->RegisterListPref(kExtensionToolbar); |
1421 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); | 1435 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); |
1422 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); | 1436 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); |
1423 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); | 1437 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); |
1424 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); | 1438 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); |
1425 prefs->RegisterListPref(prefs::kExtensionInstallForceList); | 1439 prefs->RegisterListPref(prefs::kExtensionInstallForceList); |
1426 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); | 1440 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); |
1427 } | 1441 } |
OLD | NEW |