OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_management_internal.h" | 5 #include "chrome/browser/extensions/extension_management_internal.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_management_constants.h" | 9 #include "chrome/browser/extensions/extension_management_constants.h" |
10 #include "extensions/common/url_pattern_set.h" | 10 #include "extensions/common/url_pattern_set.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 GURL(update_url_str).is_valid()) { | 60 GURL(update_url_str).is_valid()) { |
61 update_url = update_url_str; | 61 update_url = update_url_str; |
62 } else { | 62 } else { |
63 // No valid update URL for extension. | 63 // No valid update URL for extension. |
64 LOG(WARNING) << kMalformedPreferenceWarning; | 64 LOG(WARNING) << kMalformedPreferenceWarning; |
65 return false; | 65 return false; |
66 } | 66 } |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
| 70 // Parses the blocked permission settings. |
| 71 const base::ListValue* list_value = nullptr; |
| 72 base::string16 error; |
| 73 |
| 74 // If applicable, inherit from global block list and remove all explicitly |
| 75 // allowed permissions. |
| 76 if (scope != SCOPE_DEFAULT && |
| 77 dict->GetListWithoutPathExpansion(schema_constants::kAllowedPermissions, |
| 78 &list_value)) { |
| 79 // It is assumed that Parse() is already called for SCOPE_DEFAULT and |
| 80 // settings specified for |this| is initialized by copying from default |
| 81 // settings, including the |blocked_permissions| setting here. |
| 82 // That is, |blocked_permissions| should be the default block permissions |
| 83 // list settings here. |
| 84 APIPermissionSet globally_blocked_permissions = blocked_permissions; |
| 85 APIPermissionSet explicitly_allowed_permissions; |
| 86 // Reuses code for parsing API permissions from manifest. But note that we |
| 87 // only support list of strings type. |
| 88 if (!APIPermissionSet::ParseFromJSON( |
| 89 list_value, |
| 90 APIPermissionSet::kDisallowInternalPermissions, |
| 91 &explicitly_allowed_permissions, |
| 92 &error, |
| 93 nullptr)) { |
| 94 // There might be unknown permissions, warn and just ignore them; |
| 95 LOG(WARNING) << error; |
| 96 } |
| 97 APIPermissionSet::Difference(globally_blocked_permissions, |
| 98 explicitly_allowed_permissions, |
| 99 &blocked_permissions); |
| 100 } |
| 101 |
| 102 // Then add all newly blocked permissions to the list. |
| 103 if (dict->GetListWithoutPathExpansion(schema_constants::kBlockedPermissions, |
| 104 &list_value)) { |
| 105 // The |blocked_permissions| might be the result of the routines above, |
| 106 // or remains the same as default block permissions settings. |
| 107 APIPermissionSet permissions_to_merge_from = blocked_permissions; |
| 108 APIPermissionSet permissions_parsed; |
| 109 if (!APIPermissionSet::ParseFromJSON( |
| 110 list_value, |
| 111 APIPermissionSet::kDisallowInternalPermissions, |
| 112 &permissions_parsed, |
| 113 &error, |
| 114 nullptr)) { |
| 115 LOG(WARNING) << error; |
| 116 } |
| 117 APIPermissionSet::Union( |
| 118 permissions_to_merge_from, permissions_parsed, &blocked_permissions); |
| 119 } |
| 120 |
70 return true; | 121 return true; |
71 } | 122 } |
72 | 123 |
73 void IndividualSettings::Reset() { | 124 void IndividualSettings::Reset() { |
74 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 125 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
75 update_url.clear(); | 126 update_url.clear(); |
| 127 blocked_permissions.clear(); |
76 } | 128 } |
77 | 129 |
78 GlobalSettings::GlobalSettings() { | 130 GlobalSettings::GlobalSettings() { |
79 Reset(); | 131 Reset(); |
80 } | 132 } |
81 | 133 |
82 GlobalSettings::~GlobalSettings() { | 134 GlobalSettings::~GlobalSettings() { |
83 } | 135 } |
84 | 136 |
85 void GlobalSettings::Reset() { | 137 void GlobalSettings::Reset() { |
86 has_restricted_install_sources = false; | 138 has_restricted_install_sources = false; |
87 install_sources.ClearPatterns(); | 139 install_sources.ClearPatterns(); |
88 has_restricted_allowed_types = false; | 140 has_restricted_allowed_types = false; |
89 allowed_types.clear(); | 141 allowed_types.clear(); |
90 } | 142 } |
91 | 143 |
92 } // namespace internal | 144 } // namespace internal |
93 | 145 |
94 } // namespace extensions | 146 } // namespace extensions |
OLD | NEW |