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

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

Issue 51433002: Enable permission warnings from ManifestHandlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Working on adding ManifestPermissionSet to PermissionSet. Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <iterator> 7 #include <iterator>
8 8
9 #include "base/prefs/pref_notifier.h" 9 #include "base/prefs/pref_notifier.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // Preferences that hold which permissions the user has granted the extension. 150 // Preferences that hold which permissions the user has granted the extension.
151 // We explicitly keep track of these so that extensions can contain unknown 151 // We explicitly keep track of these so that extensions can contain unknown
152 // permissions, for backwards compatibility reasons, and we can still prompt 152 // permissions, for backwards compatibility reasons, and we can still prompt
153 // the user to accept them once recognized. We store the active permission 153 // the user to accept them once recognized. We store the active permission
154 // permissions because they may differ from those defined in the manifest. 154 // permissions because they may differ from those defined in the manifest.
155 const char kPrefActivePermissions[] = "active_permissions"; 155 const char kPrefActivePermissions[] = "active_permissions";
156 const char kPrefGrantedPermissions[] = "granted_permissions"; 156 const char kPrefGrantedPermissions[] = "granted_permissions";
157 157
158 // The preference names for PermissionSet values. 158 // The preference names for PermissionSet values.
159 const char kPrefAPIs[] = "api"; 159 const char kPrefAPIs[] = "api";
160 const char kPrefManifestPermissions[] = "manifest_permissions";
160 const char kPrefExplicitHosts[] = "explicit_host"; 161 const char kPrefExplicitHosts[] = "explicit_host";
161 const char kPrefScriptableHosts[] = "scriptable_host"; 162 const char kPrefScriptableHosts[] = "scriptable_host";
162 163
163 // The preference names for the old granted permissions scheme. 164 // The preference names for the old granted permissions scheme.
164 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; 165 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full";
165 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; 166 const char kPrefOldGrantedHosts[] = "granted_permissions.host";
166 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; 167 const char kPrefOldGrantedAPIs[] = "granted_permissions.api";
167 168
168 // A preference that indicates when an extension was installed. 169 // A preference that indicates when an extension was installed.
169 const char kPrefInstallTime[] = "install_time"; 170 const char kPrefInstallTime[] = "install_time";
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // for api_values format. 536 // for api_values format.
536 APIPermissionSet apis; 537 APIPermissionSet apis;
537 const ListValue* api_values = NULL; 538 const ListValue* api_values = NULL;
538 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); 539 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs);
539 if (ReadPrefAsList(extension_id, api_pref, &api_values)) { 540 if (ReadPrefAsList(extension_id, api_pref, &api_values)) {
540 APIPermissionSet::ParseFromJSON(api_values, 541 APIPermissionSet::ParseFromJSON(api_values,
541 APIPermissionSet::kAllowInternalPermissions, 542 APIPermissionSet::kAllowInternalPermissions,
542 &apis, NULL, NULL); 543 &apis, NULL, NULL);
543 } 544 }
544 545
546 // Retrieve the Manifest Keys permissions. Please refer
547 // SetExtensionPrefPermissionSet() for manifest_permissions_values format.
548 ManifestPermissionSet manifest_permissions;
549 const ListValue* manifest_permissions_values = NULL;
550 std::string manifest_permission_pref =
551 JoinPrefs(pref_key, kPrefManifestPermissions);
552 if (ReadPrefAsList(extension_id, api_pref, &manifest_permissions_values)) {
553 ManifestPermissionSet::ParseFromJSON(
554 manifest_permissions_values, &manifest_permissions, NULL, NULL);
555 }
556
545 // Retrieve the explicit host permissions. 557 // Retrieve the explicit host permissions.
546 URLPatternSet explicit_hosts; 558 URLPatternSet explicit_hosts;
547 ReadPrefAsURLPatternSet( 559 ReadPrefAsURLPatternSet(
548 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), 560 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts),
549 &explicit_hosts, Extension::kValidHostPermissionSchemes); 561 &explicit_hosts, Extension::kValidHostPermissionSchemes);
550 562
551 // Retrieve the scriptable host permissions. 563 // Retrieve the scriptable host permissions.
552 URLPatternSet scriptable_hosts; 564 URLPatternSet scriptable_hosts;
553 ReadPrefAsURLPatternSet( 565 ReadPrefAsURLPatternSet(
554 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), 566 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts),
555 &scriptable_hosts, UserScript::ValidUserScriptSchemes()); 567 &scriptable_hosts, UserScript::ValidUserScriptSchemes());
556 568
557 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); 569 return new PermissionSet(
570 apis, manifest_permissions, explicit_hosts, scriptable_hosts);
571 }
572
573 // Set the API permissions.
574 // The format of api_values is:
575 // [ "permission_name1", // permissions do not support detail.
576 // "permission_name2",
577 // {"permission_name3": value },
578 // // permission supports detail, permission detail will be stored in value.
579 // ...
580 // ]
581 template<typename T>
582 static ListValue* CreatePermisionList(const T& permissions) {
583 ListValue* values = new ListValue();
584 for (T::const_iterator i = permissions.begin(); i != permissions.end(); ++i) {
585 scoped_ptr<Value> detail(i->ToValue());
586 if (detail) {
587 DictionaryValue* tmp = new DictionaryValue();
588 tmp->Set(i->name(), detail.release());
589 values->Append(tmp);
590 } else {
591 values->Append(new base::StringValue(i->name()));
592 }
593 }
594 return values;
558 } 595 }
559 596
560 void ExtensionPrefs::SetExtensionPrefPermissionSet( 597 void ExtensionPrefs::SetExtensionPrefPermissionSet(
561 const std::string& extension_id, 598 const std::string& extension_id,
562 const std::string& pref_key, 599 const std::string& pref_key,
563 const PermissionSet* new_value) { 600 const PermissionSet* new_value) {
564 // Set the API permissions.
565 // The format of api_values is:
566 // [ "permission_name1", // permissions do not support detail.
567 // "permission_name2",
568 // {"permission_name3": value },
569 // // permission supports detail, permission detail will be stored in value.
570 // ...
571 // ]
572 ListValue* api_values = new ListValue();
573 APIPermissionSet apis = new_value->apis();
574 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); 601 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs);
575 for (APIPermissionSet::const_iterator i = apis.begin(); 602 ListValue* api_values = CreatePermisionList(new_value->apis());
576 i != apis.end(); ++i) {
577 scoped_ptr<Value> detail(i->ToValue());
578 if (detail) {
579 DictionaryValue* tmp = new DictionaryValue();
580 tmp->Set(i->name(), detail.release());
581 api_values->Append(tmp);
582 } else {
583 api_values->Append(new base::StringValue(i->name()));
584 }
585 }
586 UpdateExtensionPref(extension_id, api_pref, api_values); 603 UpdateExtensionPref(extension_id, api_pref, api_values);
587 604
605 std::string manifest_permissions_pref =
606 JoinPrefs(pref_key, kPrefManifestPermissions);
607 ListValue* manifest_permissions_values = CreatePermisionList(
608 new_value->manifest_permissions());
609 UpdateExtensionPref(extension_id,
610 manifest_permissions_pref,
611 manifest_permissions_values);
612
588 // Set the explicit host permissions. 613 // Set the explicit host permissions.
589 if (!new_value->explicit_hosts().is_empty()) { 614 if (!new_value->explicit_hosts().is_empty()) {
590 SetExtensionPrefURLPatternSet(extension_id, 615 SetExtensionPrefURLPatternSet(extension_id,
591 JoinPrefs(pref_key, kPrefExplicitHosts), 616 JoinPrefs(pref_key, kPrefExplicitHosts),
592 new_value->explicit_hosts()); 617 new_value->explicit_hosts());
593 } 618 }
594 619
595 // Set the scriptable host permissions. 620 // Set the scriptable host permissions.
596 if (!new_value->scriptable_hosts().is_empty()) { 621 if (!new_value->scriptable_hosts().is_empty()) {
597 SetExtensionPrefURLPatternSet(extension_id, 622 SetExtensionPrefURLPatternSet(extension_id,
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 is_enabled = initial_state == Extension::ENABLED; 1942 is_enabled = initial_state == Extension::ENABLED;
1918 } 1943 }
1919 1944
1920 extension_pref_value_map_->RegisterExtension(extension_id, install_time, 1945 extension_pref_value_map_->RegisterExtension(extension_id, install_time,
1921 is_enabled); 1946 is_enabled);
1922 content_settings_store_->RegisterExtension(extension_id, install_time, 1947 content_settings_store_->RegisterExtension(extension_id, install_time,
1923 is_enabled); 1948 is_enabled);
1924 } 1949 }
1925 1950
1926 } // namespace extensions 1951 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698