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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 PermissionsUpdater::PermissionsUpdater(Profile* profile) | 93 PermissionsUpdater::PermissionsUpdater(Profile* profile) |
94 : profile_(profile) {} | 94 : profile_(profile) {} |
95 | 95 |
96 PermissionsUpdater::~PermissionsUpdater() {} | 96 PermissionsUpdater::~PermissionsUpdater() {} |
97 | 97 |
98 void PermissionsUpdater::AddPermissions( | 98 void PermissionsUpdater::AddPermissions( |
99 const Extension* extension, const PermissionSet* permissions) { | 99 const Extension* extension, const PermissionSet* permissions) { |
100 scoped_refptr<const PermissionSet> existing( | 100 scoped_refptr<const PermissionSet> existing( |
101 extension->GetActivePermissions()); | 101 extension->GetActivePermissions()); |
102 scoped_refptr<PermissionSet> total( | 102 scoped_refptr<PermissionSet> total( |
103 PermissionSet::CreateUnion(existing, permissions)); | 103 PermissionSet::CreateUnion(existing.get(), permissions)); |
104 scoped_refptr<PermissionSet> added( | 104 scoped_refptr<PermissionSet> added( |
105 PermissionSet::CreateDifference(total.get(), existing)); | 105 PermissionSet::CreateDifference(total.get(), existing.get())); |
106 | 106 |
107 UpdateActivePermissions(extension, total.get()); | 107 UpdateActivePermissions(extension, total.get()); |
108 | 108 |
109 // Update the granted permissions so we don't auto-disable the extension. | 109 // Update the granted permissions so we don't auto-disable the extension. |
110 GrantActivePermissions(extension, false); | 110 GrantActivePermissions(extension, false); |
111 | 111 |
112 NotifyPermissionsUpdated(ADDED, extension, added.get()); | 112 NotifyPermissionsUpdated(ADDED, extension, added.get()); |
113 } | 113 } |
114 | 114 |
115 void PermissionsUpdater::RemovePermissions( | 115 void PermissionsUpdater::RemovePermissions( |
116 const Extension* extension, const PermissionSet* permissions) { | 116 const Extension* extension, const PermissionSet* permissions) { |
117 scoped_refptr<const PermissionSet> existing( | 117 scoped_refptr<const PermissionSet> existing( |
118 extension->GetActivePermissions()); | 118 extension->GetActivePermissions()); |
119 scoped_refptr<PermissionSet> total( | 119 scoped_refptr<PermissionSet> total( |
120 PermissionSet::CreateDifference(existing, permissions)); | 120 PermissionSet::CreateDifference(existing.get(), permissions)); |
121 scoped_refptr<PermissionSet> removed( | 121 scoped_refptr<PermissionSet> removed( |
122 PermissionSet::CreateDifference(existing, total.get())); | 122 PermissionSet::CreateDifference(existing.get(), total.get())); |
123 | 123 |
124 // We update the active permissions, and not the granted permissions, because | 124 // We update the active permissions, and not the granted permissions, because |
125 // the extension, not the user, removed the permissions. This allows the | 125 // the extension, not the user, removed the permissions. This allows the |
126 // extension to add them again without prompting the user. | 126 // extension to add them again without prompting the user. |
127 UpdateActivePermissions(extension, total.get()); | 127 UpdateActivePermissions(extension, total.get()); |
128 | 128 |
129 NotifyPermissionsUpdated(REMOVED, extension, removed.get()); | 129 NotifyPermissionsUpdated(REMOVED, extension, removed.get()); |
130 } | 130 } |
131 | 131 |
132 void PermissionsUpdater::GrantActivePermissions(const Extension* extension, | 132 void PermissionsUpdater::GrantActivePermissions(const Extension* extension, |
(...skipping 14 matching lines...) Expand all Loading... |
147 if (!oauth2_info.client_id.empty() && !oauth2_info.scopes.empty()) { | 147 if (!oauth2_info.client_id.empty() && !oauth2_info.scopes.empty()) { |
148 TokenService* token_service = TokenServiceFactory::GetForProfile( | 148 TokenService* token_service = TokenServiceFactory::GetForProfile( |
149 profile_); | 149 profile_); |
150 if (token_service && token_service->HasOAuthLoginToken()) { | 150 if (token_service && token_service->HasOAuthLoginToken()) { |
151 new OAuth2GrantRecorder(profile_, extension); | 151 new OAuth2GrantRecorder(profile_, extension); |
152 } | 152 } |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 GetExtensionPrefs()->AddGrantedPermissions(extension->id(), | 156 GetExtensionPrefs()->AddGrantedPermissions(extension->id(), |
157 extension->GetActivePermissions()); | 157 extension-> |
| 158 GetActivePermissions().get()); |
158 } | 159 } |
159 | 160 |
160 void PermissionsUpdater::UpdateActivePermissions( | 161 void PermissionsUpdater::UpdateActivePermissions( |
161 const Extension* extension, const PermissionSet* permissions) { | 162 const Extension* extension, const PermissionSet* permissions) { |
162 GetExtensionPrefs()->SetActivePermissions(extension->id(), permissions); | 163 GetExtensionPrefs()->SetActivePermissions(extension->id(), permissions); |
163 extension->SetActivePermissions(permissions); | 164 extension->SetActivePermissions(permissions); |
164 } | 165 } |
165 | 166 |
166 void PermissionsUpdater::DispatchEvent( | 167 void PermissionsUpdater::DispatchEvent( |
167 const std::string& extension_id, | 168 const std::string& extension_id, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 224 |
224 // Trigger the onAdded and onRemoved events in the extension. | 225 // Trigger the onAdded and onRemoved events in the extension. |
225 DispatchEvent(extension->id(), event_name, changed); | 226 DispatchEvent(extension->id(), event_name, changed); |
226 } | 227 } |
227 | 228 |
228 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() { | 229 ExtensionPrefs* PermissionsUpdater::GetExtensionPrefs() { |
229 return profile_->GetExtensionService()->extension_prefs(); | 230 return profile_->GetExtensionService()->extension_prefs(); |
230 } | 231 } |
231 | 232 |
232 } // namespace extensions | 233 } // namespace extensions |
OLD | NEW |