| 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/extensions/api/permissions/permissions_api_helpers.h" | 10 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 PermissionsUpdater::PermissionsUpdater(Profile* profile) | 37 PermissionsUpdater::PermissionsUpdater(Profile* profile) |
| 38 : profile_(profile) {} | 38 : profile_(profile) {} |
| 39 | 39 |
| 40 PermissionsUpdater::~PermissionsUpdater() {} | 40 PermissionsUpdater::~PermissionsUpdater() {} |
| 41 | 41 |
| 42 void PermissionsUpdater::AddPermissions( | 42 void PermissionsUpdater::AddPermissions( |
| 43 const Extension* extension, const PermissionSet* permissions) { | 43 const Extension* extension, const PermissionSet* permissions) { |
| 44 scoped_refptr<const PermissionSet> existing( | 44 scoped_refptr<const PermissionSet> existing( |
| 45 extension->GetActivePermissions()); | 45 extension->GetActivePermissions()); |
| 46 scoped_refptr<PermissionSet> total( | 46 scoped_refptr<PermissionSet> total( |
| 47 PermissionSet::CreateUnion(existing, permissions)); | 47 PermissionSet::CreateUnion(existing.get(), permissions)); |
| 48 scoped_refptr<PermissionSet> added( | 48 scoped_refptr<PermissionSet> added( |
| 49 PermissionSet::CreateDifference(total.get(), existing)); | 49 PermissionSet::CreateDifference(total.get(), existing.get())); |
| 50 | 50 |
| 51 UpdateActivePermissions(extension, total.get()); | 51 UpdateActivePermissions(extension, total.get()); |
| 52 | 52 |
| 53 // Update the granted permissions so we don't auto-disable the extension. | 53 // Update the granted permissions so we don't auto-disable the extension. |
| 54 GrantActivePermissions(extension); | 54 GrantActivePermissions(extension); |
| 55 | 55 |
| 56 NotifyPermissionsUpdated(ADDED, extension, added.get()); | 56 NotifyPermissionsUpdated(ADDED, extension, added.get()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void PermissionsUpdater::RemovePermissions( | 59 void PermissionsUpdater::RemovePermissions( |
| 60 const Extension* extension, const PermissionSet* permissions) { | 60 const Extension* extension, const PermissionSet* permissions) { |
| 61 scoped_refptr<const PermissionSet> existing( | 61 scoped_refptr<const PermissionSet> existing( |
| 62 extension->GetActivePermissions()); | 62 extension->GetActivePermissions()); |
| 63 scoped_refptr<PermissionSet> total( | 63 scoped_refptr<PermissionSet> total( |
| 64 PermissionSet::CreateDifference(existing, permissions)); | 64 PermissionSet::CreateDifference(existing.get(), permissions)); |
| 65 scoped_refptr<PermissionSet> removed( | 65 scoped_refptr<PermissionSet> removed( |
| 66 PermissionSet::CreateDifference(existing, total.get())); | 66 PermissionSet::CreateDifference(existing.get(), total.get())); |
| 67 | 67 |
| 68 // We update the active permissions, and not the granted permissions, because | 68 // We update the active permissions, and not the granted permissions, because |
| 69 // the extension, not the user, removed the permissions. This allows the | 69 // the extension, not the user, removed the permissions. This allows the |
| 70 // extension to add them again without prompting the user. | 70 // extension to add them again without prompting the user. |
| 71 UpdateActivePermissions(extension, total.get()); | 71 UpdateActivePermissions(extension, total.get()); |
| 72 | 72 |
| 73 NotifyPermissionsUpdated(REMOVED, extension, removed.get()); | 73 NotifyPermissionsUpdated(REMOVED, extension, removed.get()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void PermissionsUpdater::GrantActivePermissions(const Extension* extension) { | 76 void PermissionsUpdater::GrantActivePermissions(const Extension* extension) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 changed->apis(), | 150 changed->apis(), |
| 151 changed->explicit_hosts(), | 151 changed->explicit_hosts(), |
| 152 changed->scriptable_hosts())); | 152 changed->scriptable_hosts())); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Trigger the onAdded and onRemoved events in the extension. | 155 // Trigger the onAdded and onRemoved events in the extension. |
| 156 DispatchEvent(extension->id(), event_name, changed); | 156 DispatchEvent(extension->id(), event_name, changed); |
| 157 } | 157 } |
| 158 | 158 |
| 159 } // namespace extensions | 159 } // namespace extensions |
| OLD | NEW |