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

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 6772022: Make <all_urls> and file:///* in permissions trigger "Allow file access" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ExtensionModuleApiTest.(In)CognitoNoFile. Created 9 years, 8 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) 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
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)) {
Aaron Boodman 2011/03/31 16:04:57 I'm not sure why this branch was needed. Perhaps i
Mihai Parparita -not on Chrome 2011/03/31 21:56:31 Without the changes in this file, ExtensionService
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 return ReadExtensionPrefBoolean(extension_id, kPrefAllowFileAccess); 641 return ReadExtensionPrefBoolean(extension_id, kPrefAllowFileAccess);
628 } 642 }
629 643
630 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id, 644 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id,
631 bool allow) { 645 bool allow) {
632 UpdateExtensionPref(extension_id, kPrefAllowFileAccess, 646 UpdateExtensionPref(extension_id, kPrefAllowFileAccess,
633 Value::CreateBooleanValue(allow)); 647 Value::CreateBooleanValue(allow));
634 SavePrefsAndNotify(); 648 SavePrefsAndNotify();
635 } 649 }
636 650
651 bool ExtensionPrefs::HasAllowFileAccessSetting(
652 const std::string& extension_id) const {
653 DictionaryValue* ext = GetExtensionPref(extension_id);
654 return ext && ext->HasKey(kPrefAllowFileAccess);
655 }
656
637 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType( 657 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType(
638 const std::string& extension_id, 658 const std::string& extension_id,
639 ExtensionPrefs::LaunchType default_pref_value) { 659 ExtensionPrefs::LaunchType default_pref_value) {
640 int value = -1; 660 int value = -1;
641 LaunchType result = LAUNCH_REGULAR; 661 LaunchType result = LAUNCH_REGULAR;
642 662
643 if (ReadExtensionPrefInteger(extension_id, kPrefLaunchType, &value) && 663 if (ReadExtensionPrefInteger(extension_id, kPrefLaunchType, &value) &&
644 (value == LAUNCH_PINNED || 664 (value == LAUNCH_PINNED ||
645 value == LAUNCH_REGULAR || 665 value == LAUNCH_REGULAR ||
646 value == LAUNCH_FULLSCREEN || 666 value == LAUNCH_FULLSCREEN ||
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 1438 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
1419 prefs->RegisterDictionaryPref(kExtensionsPref); 1439 prefs->RegisterDictionaryPref(kExtensionsPref);
1420 prefs->RegisterListPref(kExtensionToolbar); 1440 prefs->RegisterListPref(kExtensionToolbar);
1421 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); 1441 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1);
1422 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); 1442 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate);
1423 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); 1443 prefs->RegisterListPref(prefs::kExtensionInstallAllowList);
1424 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); 1444 prefs->RegisterListPref(prefs::kExtensionInstallDenyList);
1425 prefs->RegisterListPref(prefs::kExtensionInstallForceList); 1445 prefs->RegisterListPref(prefs::kExtensionInstallForceList);
1426 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); 1446 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */);
1427 } 1447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698