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/permissions_updater.h" | 5 #include "chrome/browser/extensions/permissions_updater.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 if (!Manifest::IsUnpackedLocation(extension->location()) && | 137 if (!Manifest::IsUnpackedLocation(extension->location()) && |
138 extension->location() != Manifest::INTERNAL) | 138 extension->location() != Manifest::INTERNAL) |
139 return; | 139 return; |
140 | 140 |
141 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( | 141 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( |
142 extension->id(), | 142 extension->id(), |
143 extension->permissions_data()->active_permissions().get()); | 143 extension->permissions_data()->active_permissions().get()); |
144 } | 144 } |
145 | 145 |
146 void PermissionsUpdater::InitializePermissions(const Extension* extension) { | 146 void PermissionsUpdater::InitializePermissions(const Extension* extension) { |
| 147 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser_context_); |
147 scoped_refptr<const PermissionSet> bounded_active = | 148 scoped_refptr<const PermissionSet> bounded_active = |
148 GetBoundedActivePermissions(extension, | 149 GetBoundedActivePermissions(extension, prefs); |
149 ExtensionPrefs::Get(browser_context_)); | |
150 | 150 |
151 // We withhold permissions iff the switch to do so is enabled, the extension | 151 // We withhold permissions iff the switch to do so is enabled, the extension |
152 // shows up in chrome:extensions (so the user can grant withheld permissions), | 152 // shows up in chrome:extensions (so the user can grant withheld permissions), |
153 // the extension is not part of chrome or corporate policy, and also not on | 153 // the extension is not part of chrome or corporate policy, and also not on |
154 // the scripting whitelist. Additionally, we don't withhold if the extension | 154 // the scripting whitelist. Additionally, we don't withhold if the extension |
155 // has the preference to allow scripting on all urls. | 155 // has the preference to allow scripting on all urls. |
156 bool should_withhold_permissions = | 156 bool should_withhold_permissions = |
157 FeatureSwitch::scripts_require_action()->IsEnabled() && | 157 FeatureSwitch::scripts_require_action()->IsEnabled() && |
158 extension->ShouldDisplayInExtensionSettings() && | 158 extension->ShouldDisplayInExtensionSettings() && |
159 !Manifest::IsPolicyLocation(extension->location()) && | 159 !Manifest::IsPolicyLocation(extension->location()) && |
160 !Manifest::IsComponentLocation(extension->location()) && | 160 !Manifest::IsComponentLocation(extension->location()) && |
161 !PermissionsData::CanExecuteScriptEverywhere(extension) && | 161 !PermissionsData::CanExecuteScriptEverywhere(extension) && |
162 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); | 162 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); |
163 | 163 |
164 URLPatternSet granted_explicit_hosts; | 164 URLPatternSet granted_explicit_hosts; |
165 URLPatternSet withheld_explicit_hosts; | 165 URLPatternSet withheld_explicit_hosts; |
166 SegregateUrlPermissions(bounded_active->explicit_hosts(), | 166 SegregateUrlPermissions(bounded_active->explicit_hosts(), |
167 should_withhold_permissions, | 167 should_withhold_permissions, |
168 &granted_explicit_hosts, | 168 &granted_explicit_hosts, |
169 &withheld_explicit_hosts); | 169 &withheld_explicit_hosts); |
170 | 170 |
171 URLPatternSet granted_scriptable_hosts; | 171 URLPatternSet granted_scriptable_hosts; |
172 URLPatternSet withheld_scriptable_hosts; | 172 URLPatternSet withheld_scriptable_hosts; |
173 SegregateUrlPermissions(bounded_active->scriptable_hosts(), | 173 SegregateUrlPermissions(bounded_active->scriptable_hosts(), |
174 should_withhold_permissions, | 174 should_withhold_permissions, |
175 &granted_scriptable_hosts, | 175 &granted_scriptable_hosts, |
176 &withheld_scriptable_hosts); | 176 &withheld_scriptable_hosts); |
177 | 177 |
| 178 // Add persisted permissions to granted hosts. |
| 179 PermissionSet* persisted = prefs->GetPersistedPermissions(extension->id()); |
| 180 if (persisted) { |
| 181 const URLPatternSet& explicit_hosts = persisted->explicit_hosts(); |
| 182 for (URLPatternSet::const_iterator iter = explicit_hosts.begin(); |
| 183 iter != explicit_hosts.end(); |
| 184 ++iter) { |
| 185 granted_explicit_hosts.AddPattern(*iter); |
| 186 } |
| 187 const URLPatternSet& scriptable_hosts = persisted->scriptable_hosts(); |
| 188 for (URLPatternSet::const_iterator iter = scriptable_hosts.begin(); |
| 189 iter != scriptable_hosts.end(); |
| 190 ++iter) { |
| 191 granted_scriptable_hosts.AddPattern(*iter); |
| 192 } |
| 193 } |
| 194 |
178 bounded_active = new PermissionSet(bounded_active->apis(), | 195 bounded_active = new PermissionSet(bounded_active->apis(), |
179 bounded_active->manifest_permissions(), | 196 bounded_active->manifest_permissions(), |
180 granted_explicit_hosts, | 197 granted_explicit_hosts, |
181 granted_scriptable_hosts); | 198 granted_scriptable_hosts); |
182 | 199 |
183 scoped_refptr<const PermissionSet> withheld = | 200 scoped_refptr<const PermissionSet> withheld = |
184 new PermissionSet(APIPermissionSet(), | 201 new PermissionSet(APIPermissionSet(), |
185 ManifestPermissionSet(), | 202 ManifestPermissionSet(), |
186 withheld_explicit_hosts, | 203 withheld_explicit_hosts, |
187 withheld_scriptable_hosts); | 204 withheld_scriptable_hosts); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 338 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
322 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 339 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
323 } | 340 } |
324 } | 341 } |
325 | 342 |
326 // Trigger the onAdded and onRemoved events in the extension. | 343 // Trigger the onAdded and onRemoved events in the extension. |
327 DispatchEvent(extension->id(), event_name, changed); | 344 DispatchEvent(extension->id(), event_name, changed); |
328 } | 345 } |
329 | 346 |
330 } // namespace extensions | 347 } // namespace extensions |
OLD | NEW |