| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 scoped_refptr<const PermissionSet> required_permissions = | 70 scoped_refptr<const PermissionSet> required_permissions = |
| 71 PermissionsParser::GetRequiredPermissions(extension); | 71 PermissionsParser::GetRequiredPermissions(extension); |
| 72 | 72 |
| 73 // We restrict the active permissions to be within the bounds defined in the | 73 // We restrict the active permissions to be within the bounds defined in the |
| 74 // extension's manifest. | 74 // extension's manifest. |
| 75 // a) active permissions must be a subset of optional + default permissions | 75 // a) active permissions must be a subset of optional + default permissions |
| 76 // b) active permissions must contains all default permissions | 76 // b) active permissions must contains all default permissions |
| 77 scoped_refptr<PermissionSet> total_permissions = PermissionSet::CreateUnion( | 77 scoped_refptr<PermissionSet> total_permissions = PermissionSet::CreateUnion( |
| 78 required_permissions.get(), | 78 required_permissions.get(), |
| 79 PermissionsParser::GetOptionalPermissions(extension)); | 79 PermissionsParser::GetOptionalPermissions(extension).get()); |
| 80 | 80 |
| 81 // Make sure the active permissions contain no more than optional + default. | 81 // Make sure the active permissions contain no more than optional + default. |
| 82 scoped_refptr<PermissionSet> adjusted_active = | 82 scoped_refptr<PermissionSet> adjusted_active = |
| 83 PermissionSet::CreateIntersection(total_permissions.get(), | 83 PermissionSet::CreateIntersection(total_permissions.get(), |
| 84 active_permissions.get()); | 84 active_permissions.get()); |
| 85 | 85 |
| 86 // Make sure the active permissions contain the default permissions. | 86 // Make sure the active permissions contain the default permissions. |
| 87 adjusted_active = PermissionSet::CreateUnion(required_permissions.get(), | 87 adjusted_active = PermissionSet::CreateUnion(required_permissions.get(), |
| 88 adjusted_active.get()); | 88 adjusted_active.get()); |
| 89 | 89 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 extension, changed, reason); | 331 extension, changed, reason); |
| 332 Profile* profile = Profile::FromBrowserContext(browser_context_); | 332 Profile* profile = Profile::FromBrowserContext(browser_context_); |
| 333 content::NotificationService::current()->Notify( | 333 content::NotificationService::current()->Notify( |
| 334 extensions::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, | 334 extensions::NOTIFICATION_EXTENSION_PERMISSIONS_UPDATED, |
| 335 content::Source<Profile>(profile), | 335 content::Source<Profile>(profile), |
| 336 content::Details<UpdatedExtensionPermissionsInfo>(&info)); | 336 content::Details<UpdatedExtensionPermissionsInfo>(&info)); |
| 337 | 337 |
| 338 ExtensionMsg_UpdatePermissions_Params params; | 338 ExtensionMsg_UpdatePermissions_Params params; |
| 339 params.extension_id = extension->id(); | 339 params.extension_id = extension->id(); |
| 340 params.active_permissions = ExtensionMsg_PermissionSetStruct( | 340 params.active_permissions = ExtensionMsg_PermissionSetStruct( |
| 341 extension->permissions_data()->active_permissions()); | 341 *extension->permissions_data()->active_permissions()); |
| 342 params.withheld_permissions = ExtensionMsg_PermissionSetStruct( | 342 params.withheld_permissions = ExtensionMsg_PermissionSetStruct( |
| 343 extension->permissions_data()->withheld_permissions()); | 343 *extension->permissions_data()->withheld_permissions()); |
| 344 | 344 |
| 345 // Send the new permissions to the renderers. | 345 // Send the new permissions to the renderers. |
| 346 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 346 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 347 !i.IsAtEnd(); i.Advance()) { | 347 !i.IsAtEnd(); i.Advance()) { |
| 348 RenderProcessHost* host = i.GetCurrentValue(); | 348 RenderProcessHost* host = i.GetCurrentValue(); |
| 349 if (profile->IsSameProfile( | 349 if (profile->IsSameProfile( |
| 350 Profile::FromBrowserContext(host->GetBrowserContext()))) { | 350 Profile::FromBrowserContext(host->GetBrowserContext()))) { |
| 351 host->Send(new ExtensionMsg_UpdatePermissions(params)); | 351 host->Send(new ExtensionMsg_UpdatePermissions(params)); |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 // Trigger the onAdded and onRemoved events in the extension. | 355 // Trigger the onAdded and onRemoved events in the extension. |
| 356 DispatchEvent(extension->id(), event_name, changed); | 356 DispatchEvent(extension->id(), event_name, changed); |
| 357 } | 357 } |
| 358 | 358 |
| 359 } // namespace extensions | 359 } // namespace extensions |
| OLD | NEW |