OLD | NEW |
---|---|
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" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/value_conversions.h" | 13 #include "base/value_conversions.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/extensions/admin_policy.h" | 15 #include "chrome/browser/extensions/admin_policy.h" |
16 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h" | 16 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h" |
17 #include "chrome/browser/extensions/api/preference/preference_api.h" | 17 #include "chrome/browser/extensions/api/preference/preference_api.h" |
18 #include "chrome/browser/extensions/event_router.h" | 18 #include "chrome/browser/extensions/event_router.h" |
19 #include "chrome/browser/extensions/extension_pref_store.h" | 19 #include "chrome/browser/extensions/extension_pref_store.h" |
20 #include "chrome/browser/extensions/extension_prefs_factory.h" | 20 #include "chrome/browser/extensions/extension_prefs_factory.h" |
21 #include "chrome/browser/extensions/extension_sorting.h" | 21 #include "chrome/browser/extensions/extension_sorting.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/host_desktop.h" | 23 #include "chrome/browser/ui/host_desktop.h" |
24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/extensions/chrome_manifest_permission_set.h" | |
25 #include "chrome/common/extensions/feature_switch.h" | 26 #include "chrome/common/extensions/feature_switch.h" |
26 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 27 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
29 #include "components/user_prefs/pref_registry_syncable.h" | 30 #include "components/user_prefs/pref_registry_syncable.h" |
30 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
31 #include "extensions/browser/pref_names.h" | 32 #include "extensions/browser/pref_names.h" |
32 #include "extensions/common/manifest.h" | 33 #include "extensions/common/manifest.h" |
33 #include "extensions/common/permissions/permission_set.h" | 34 #include "extensions/common/permissions/permission_set.h" |
34 #include "extensions/common/permissions/permissions_info.h" | 35 #include "extensions/common/permissions/permissions_info.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 // Preferences that hold which permissions the user has granted the extension. | 151 // Preferences that hold which permissions the user has granted the extension. |
151 // We explicitly keep track of these so that extensions can contain unknown | 152 // We explicitly keep track of these so that extensions can contain unknown |
152 // permissions, for backwards compatibility reasons, and we can still prompt | 153 // permissions, for backwards compatibility reasons, and we can still prompt |
153 // the user to accept them once recognized. We store the active permission | 154 // the user to accept them once recognized. We store the active permission |
154 // permissions because they may differ from those defined in the manifest. | 155 // permissions because they may differ from those defined in the manifest. |
155 const char kPrefActivePermissions[] = "active_permissions"; | 156 const char kPrefActivePermissions[] = "active_permissions"; |
156 const char kPrefGrantedPermissions[] = "granted_permissions"; | 157 const char kPrefGrantedPermissions[] = "granted_permissions"; |
157 | 158 |
158 // The preference names for PermissionSet values. | 159 // The preference names for PermissionSet values. |
159 const char kPrefAPIs[] = "api"; | 160 const char kPrefAPIs[] = "api"; |
161 const char kPrefManifestPermissions[] = "manifest_permissions"; | |
160 const char kPrefExplicitHosts[] = "explicit_host"; | 162 const char kPrefExplicitHosts[] = "explicit_host"; |
161 const char kPrefScriptableHosts[] = "scriptable_host"; | 163 const char kPrefScriptableHosts[] = "scriptable_host"; |
162 | 164 |
163 // The preference names for the old granted permissions scheme. | 165 // The preference names for the old granted permissions scheme. |
164 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; | 166 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; |
165 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; | 167 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; |
166 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; | 168 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; |
167 | 169 |
168 // A preference that indicates when an extension was installed. | 170 // A preference that indicates when an extension was installed. |
169 const char kPrefInstallTime[] = "install_time"; | 171 const char kPrefInstallTime[] = "install_time"; |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 // for api_values format. | 537 // for api_values format. |
536 APIPermissionSet apis; | 538 APIPermissionSet apis; |
537 const ListValue* api_values = NULL; | 539 const ListValue* api_values = NULL; |
538 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); | 540 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
539 if (ReadPrefAsList(extension_id, api_pref, &api_values)) { | 541 if (ReadPrefAsList(extension_id, api_pref, &api_values)) { |
540 APIPermissionSet::ParseFromJSON(api_values, | 542 APIPermissionSet::ParseFromJSON(api_values, |
541 APIPermissionSet::kAllowInternalPermissions, | 543 APIPermissionSet::kAllowInternalPermissions, |
542 &apis, NULL, NULL); | 544 &apis, NULL, NULL); |
543 } | 545 } |
544 | 546 |
547 // Retrieve the Manifest Keys permissions. Please refer | |
Yoyo Zhou
2013/11/09 01:15:30
nit: add "to"
rpaquay
2013/11/12 21:40:31
Done.
| |
548 // SetExtensionPrefPermissionSet() for manifest_permissions_values format. | |
549 ManifestPermissionSet manifest_permissions; | |
550 const ListValue* manifest_permissions_values = NULL; | |
551 std::string manifest_permission_pref = | |
552 JoinPrefs(pref_key, kPrefManifestPermissions); | |
553 if (ReadPrefAsList(extension_id, manifest_permission_pref, | |
554 &manifest_permissions_values)) { | |
555 ChromeManifestPermissionSet::ParseFromJSON( | |
556 manifest_permissions_values, &manifest_permissions, NULL, NULL); | |
557 } | |
558 | |
545 // Retrieve the explicit host permissions. | 559 // Retrieve the explicit host permissions. |
546 URLPatternSet explicit_hosts; | 560 URLPatternSet explicit_hosts; |
547 ReadPrefAsURLPatternSet( | 561 ReadPrefAsURLPatternSet( |
548 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), | 562 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), |
549 &explicit_hosts, Extension::kValidHostPermissionSchemes); | 563 &explicit_hosts, Extension::kValidHostPermissionSchemes); |
550 | 564 |
551 // Retrieve the scriptable host permissions. | 565 // Retrieve the scriptable host permissions. |
552 URLPatternSet scriptable_hosts; | 566 URLPatternSet scriptable_hosts; |
553 ReadPrefAsURLPatternSet( | 567 ReadPrefAsURLPatternSet( |
554 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), | 568 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), |
555 &scriptable_hosts, UserScript::ValidUserScriptSchemes()); | 569 &scriptable_hosts, UserScript::ValidUserScriptSchemes()); |
556 | 570 |
557 return new PermissionSet(apis, explicit_hosts, scriptable_hosts); | 571 return new PermissionSet( |
572 apis, manifest_permissions, explicit_hosts, scriptable_hosts); | |
573 } | |
574 | |
575 // Set the API permissions. | |
Yoyo Zhou
2013/11/12 02:39:29
Or manifest permissions.
rpaquay
2013/11/12 21:40:31
Done.
| |
576 // The format of api_values is: | |
577 // [ "permission_name1", // permissions do not support detail. | |
578 // "permission_name2", | |
579 // {"permission_name3": value }, | |
580 // // permission supports detail, permission detail will be stored in value. | |
581 // ... | |
582 // ] | |
583 template<typename T> | |
584 static ListValue* CreatePermisionList(const T& permissions) { | |
Yoyo Zhou
2013/11/12 02:39:29
typo: Permission
rpaquay
2013/11/12 21:40:31
Done.
| |
585 ListValue* values = new ListValue(); | |
586 for (T::const_iterator i = permissions.begin(); i != permissions.end(); ++i) { | |
587 scoped_ptr<Value> detail(i->ToValue()); | |
588 if (detail) { | |
589 DictionaryValue* tmp = new DictionaryValue(); | |
590 tmp->Set(i->name(), detail.release()); | |
591 values->Append(tmp); | |
592 } else { | |
593 values->Append(new base::StringValue(i->name())); | |
594 } | |
595 } | |
596 return values; | |
558 } | 597 } |
559 | 598 |
560 void ExtensionPrefs::SetExtensionPrefPermissionSet( | 599 void ExtensionPrefs::SetExtensionPrefPermissionSet( |
561 const std::string& extension_id, | 600 const std::string& extension_id, |
562 const std::string& pref_key, | 601 const std::string& pref_key, |
563 const PermissionSet* new_value) { | 602 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); | 603 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); |
575 for (APIPermissionSet::const_iterator i = apis.begin(); | 604 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); | 605 UpdateExtensionPref(extension_id, api_pref, api_values); |
587 | 606 |
607 std::string manifest_permissions_pref = | |
608 JoinPrefs(pref_key, kPrefManifestPermissions); | |
609 ListValue* manifest_permissions_values = CreatePermisionList( | |
610 new_value->manifest_permissions()); | |
611 UpdateExtensionPref(extension_id, | |
612 manifest_permissions_pref, | |
613 manifest_permissions_values); | |
614 | |
588 // Set the explicit host permissions. | 615 // Set the explicit host permissions. |
589 if (!new_value->explicit_hosts().is_empty()) { | 616 if (!new_value->explicit_hosts().is_empty()) { |
590 SetExtensionPrefURLPatternSet(extension_id, | 617 SetExtensionPrefURLPatternSet(extension_id, |
591 JoinPrefs(pref_key, kPrefExplicitHosts), | 618 JoinPrefs(pref_key, kPrefExplicitHosts), |
592 new_value->explicit_hosts()); | 619 new_value->explicit_hosts()); |
593 } | 620 } |
594 | 621 |
595 // Set the scriptable host permissions. | 622 // Set the scriptable host permissions. |
596 if (!new_value->scriptable_hosts().is_empty()) { | 623 if (!new_value->scriptable_hosts().is_empty()) { |
597 SetExtensionPrefURLPatternSet(extension_id, | 624 SetExtensionPrefURLPatternSet(extension_id, |
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1918 is_enabled = initial_state == Extension::ENABLED; | 1945 is_enabled = initial_state == Extension::ENABLED; |
1919 } | 1946 } |
1920 | 1947 |
1921 extension_pref_value_map_->RegisterExtension(extension_id, install_time, | 1948 extension_pref_value_map_->RegisterExtension(extension_id, install_time, |
1922 is_enabled); | 1949 is_enabled); |
1923 content_settings_store_->RegisterExtension(extension_id, install_time, | 1950 content_settings_store_->RegisterExtension(extension_id, install_time, |
1924 is_enabled); | 1951 is_enabled); |
1925 } | 1952 } |
1926 | 1953 |
1927 } // namespace extensions | 1954 } // namespace extensions |
OLD | NEW |