| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (!Manifest::IsUnpackedLocation(extension->location()) && | 157 if (!Manifest::IsUnpackedLocation(extension->location()) && |
| 158 extension->location() != Manifest::INTERNAL) | 158 extension->location() != Manifest::INTERNAL) |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( | 161 ExtensionPrefs::Get(browser_context_)->AddGrantedPermissions( |
| 162 extension->id(), | 162 extension->id(), |
| 163 extension->permissions_data()->active_permissions().get()); | 163 extension->permissions_data()->active_permissions().get()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void PermissionsUpdater::InitializePermissions(const Extension* extension) { | 166 void PermissionsUpdater::InitializePermissions(const Extension* extension) { |
| 167 scoped_refptr<const PermissionSet> active_permissions = | 167 InitializePermissions(extension, INIT_FLAG_NONE); |
| 168 ExtensionPrefs::Get(browser_context_) | 168 } |
| 169 ->GetActivePermissions(extension->id()); | 169 |
| 170 scoped_refptr<const PermissionSet> bounded_active = | 170 void PermissionsUpdater::InitializePermissions(const Extension* extension, |
| 171 GetBoundedActivePermissions(extension, active_permissions); | 171 InitFlag init_flag) { |
| 172 scoped_refptr<const PermissionSet> active_permissions(NULL); |
| 173 scoped_refptr<const PermissionSet> bounded_active(NULL); |
| 174 // If |extension| is a transient dummy extension, we do not want to look for |
| 175 // it in preferences. |
| 176 if (init_flag & INIT_FLAG_TRANSIENT) { |
| 177 bounded_active = active_permissions = |
| 178 extension->permissions_data()->active_permissions(); |
| 179 } else { |
| 180 active_permissions = ExtensionPrefs::Get(browser_context_) |
| 181 ->GetActivePermissions(extension->id()); |
| 182 bounded_active = GetBoundedActivePermissions(extension, active_permissions); |
| 183 } |
| 172 | 184 |
| 173 // Withhold permissions only if the switch applies to this extension and the | 185 // Withhold permissions only if the switch applies to this extension and the |
| 174 // extension doesn't have the preference to allow scripting on all urls. | 186 // extension doesn't have the preference to allow scripting on all urls. |
| 175 bool should_withhold_permissions = | 187 bool should_withhold_permissions = |
| 176 util::ScriptsMayRequireActionForExtension(extension) && | 188 util::ScriptsMayRequireActionForExtension(extension) && |
| 177 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); | 189 !util::AllowedScriptingOnAllUrls(extension->id(), browser_context_); |
| 178 | 190 |
| 179 URLPatternSet granted_explicit_hosts; | 191 URLPatternSet granted_explicit_hosts; |
| 180 URLPatternSet withheld_explicit_hosts; | 192 URLPatternSet withheld_explicit_hosts; |
| 181 SegregateUrlPermissions(bounded_active->explicit_hosts(), | 193 SegregateUrlPermissions(bounded_active->explicit_hosts(), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 207 bounded_active = new PermissionSet(bounded_active->apis(), | 219 bounded_active = new PermissionSet(bounded_active->apis(), |
| 208 bounded_active->manifest_permissions(), | 220 bounded_active->manifest_permissions(), |
| 209 granted_explicit_hosts, | 221 granted_explicit_hosts, |
| 210 granted_scriptable_hosts); | 222 granted_scriptable_hosts); |
| 211 | 223 |
| 212 scoped_refptr<const PermissionSet> withheld = | 224 scoped_refptr<const PermissionSet> withheld = |
| 213 new PermissionSet(APIPermissionSet(), | 225 new PermissionSet(APIPermissionSet(), |
| 214 ManifestPermissionSet(), | 226 ManifestPermissionSet(), |
| 215 withheld_explicit_hosts, | 227 withheld_explicit_hosts, |
| 216 withheld_scriptable_hosts); | 228 withheld_scriptable_hosts); |
| 217 SetPermissions(extension, bounded_active, withheld); | 229 |
| 230 if (init_flag & INIT_FLAG_TRANSIENT) |
| 231 SetPermissionsWithoutPrefs(extension, bounded_active, withheld); |
| 232 else |
| 233 SetPermissions(extension, bounded_active, withheld); |
| 218 } | 234 } |
| 219 | 235 |
| 220 void PermissionsUpdater::WithholdImpliedAllHosts(const Extension* extension) { | 236 void PermissionsUpdater::WithholdImpliedAllHosts(const Extension* extension) { |
| 221 scoped_refptr<const PermissionSet> active = | 237 scoped_refptr<const PermissionSet> active = |
| 222 extension->permissions_data()->active_permissions(); | 238 extension->permissions_data()->active_permissions(); |
| 223 scoped_refptr<const PermissionSet> withheld = | 239 scoped_refptr<const PermissionSet> withheld = |
| 224 extension->permissions_data()->withheld_permissions(); | 240 extension->permissions_data()->withheld_permissions(); |
| 225 | 241 |
| 226 URLPatternSet withheld_scriptable = withheld->scriptable_hosts(); | 242 URLPatternSet withheld_scriptable = withheld->scriptable_hosts(); |
| 227 URLPatternSet active_scriptable; | 243 URLPatternSet active_scriptable; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 const Extension* extension, | 299 const Extension* extension, |
| 284 const scoped_refptr<const PermissionSet>& active, | 300 const scoped_refptr<const PermissionSet>& active, |
| 285 scoped_refptr<const PermissionSet> withheld) { | 301 scoped_refptr<const PermissionSet> withheld) { |
| 286 withheld = withheld.get() ? withheld | 302 withheld = withheld.get() ? withheld |
| 287 : extension->permissions_data()->withheld_permissions(); | 303 : extension->permissions_data()->withheld_permissions(); |
| 288 extension->permissions_data()->SetPermissions(active, withheld); | 304 extension->permissions_data()->SetPermissions(active, withheld); |
| 289 ExtensionPrefs::Get(browser_context_)->SetActivePermissions( | 305 ExtensionPrefs::Get(browser_context_)->SetActivePermissions( |
| 290 extension->id(), active.get()); | 306 extension->id(), active.get()); |
| 291 } | 307 } |
| 292 | 308 |
| 309 void PermissionsUpdater::SetPermissionsWithoutPrefs( |
| 310 const Extension* extension, |
| 311 const scoped_refptr<const PermissionSet>& active, |
| 312 scoped_refptr<const PermissionSet> withheld) { |
| 313 withheld = withheld.get() |
| 314 ? withheld |
| 315 : extension->permissions_data()->withheld_permissions(); |
| 316 extension->permissions_data()->SetPermissions(active, withheld); |
| 317 } |
| 318 |
| 293 void PermissionsUpdater::DispatchEvent( | 319 void PermissionsUpdater::DispatchEvent( |
| 294 const std::string& extension_id, | 320 const std::string& extension_id, |
| 295 const char* event_name, | 321 const char* event_name, |
| 296 const PermissionSet* changed_permissions) { | 322 const PermissionSet* changed_permissions) { |
| 297 EventRouter* event_router = EventRouter::Get(browser_context_); | 323 EventRouter* event_router = EventRouter::Get(browser_context_); |
| 298 if (!event_router) | 324 if (!event_router) |
| 299 return; | 325 return; |
| 300 | 326 |
| 301 scoped_ptr<base::ListValue> value(new base::ListValue()); | 327 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 302 scoped_ptr<api::permissions::Permissions> permissions = | 328 scoped_ptr<api::permissions::Permissions> permissions = |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 376 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
| 351 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 377 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
| 352 } | 378 } |
| 353 } | 379 } |
| 354 | 380 |
| 355 // Trigger the onAdded and onRemoved events in the extension. | 381 // Trigger the onAdded and onRemoved events in the extension. |
| 356 DispatchEvent(extension->id(), event_name, changed); | 382 DispatchEvent(extension->id(), event_name, changed); |
| 357 } | 383 } |
| 358 | 384 |
| 359 } // namespace extensions | 385 } // namespace extensions |
| OLD | NEW |