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/api/permissions/permissions_api.h" | 5 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" | 8 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
9 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
10 #include "chrome/browser/extensions/permissions_updater.h" | 10 #include "chrome/browser/extensions/permissions_updater.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 scoped_refptr<PermissionSet> permissions = | 56 scoped_refptr<PermissionSet> permissions = |
57 helpers::UnpackPermissionSet( | 57 helpers::UnpackPermissionSet( |
58 params->permissions, | 58 params->permissions, |
59 ExtensionPrefs::Get(profile_)->AllowFileAccess(extension_->id()), | 59 ExtensionPrefs::Get(profile_)->AllowFileAccess(extension_->id()), |
60 &error_); | 60 &error_); |
61 if (!permissions.get()) | 61 if (!permissions.get()) |
62 return false; | 62 return false; |
63 | 63 |
64 results_ = Contains::Results::Create( | 64 results_ = Contains::Results::Create( |
65 GetExtension()->GetActivePermissions()->Contains(*permissions)); | 65 GetExtension()->GetActivePermissions()->Contains(*permissions.get())); |
66 return true; | 66 return true; |
67 } | 67 } |
68 | 68 |
69 bool PermissionsGetAllFunction::RunImpl() { | 69 bool PermissionsGetAllFunction::RunImpl() { |
70 scoped_ptr<Permissions> permissions = | 70 scoped_ptr<Permissions> permissions = |
71 helpers::PackPermissionSet(GetExtension()->GetActivePermissions()); | 71 helpers::PackPermissionSet(GetExtension()->GetActivePermissions()); |
72 results_ = GetAll::Results::Create(*permissions); | 72 results_ = GetAll::Results::Create(*permissions); |
73 return true; | 73 return true; |
74 } | 74 } |
75 | 75 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 // Filter out permissions that do not need to be listed in the optional | 177 // Filter out permissions that do not need to be listed in the optional |
178 // section of the manifest. | 178 // section of the manifest. |
179 scoped_refptr<PermissionSet> manifest_required_requested_permissions = | 179 scoped_refptr<PermissionSet> manifest_required_requested_permissions = |
180 PermissionSet::ExcludeNotInManifestPermissions( | 180 PermissionSet::ExcludeNotInManifestPermissions( |
181 requested_permissions_.get()); | 181 requested_permissions_.get()); |
182 | 182 |
183 // The requested permissions must be defined as optional in the manifest. | 183 // The requested permissions must be defined as optional in the manifest. |
184 if (!PermissionsData::GetOptionalPermissions(GetExtension())->Contains( | 184 if (!PermissionsData::GetOptionalPermissions(GetExtension()) |
185 *manifest_required_requested_permissions)) { | 185 ->Contains(*manifest_required_requested_permissions.get())) { |
186 error_ = kNotInOptionalPermissionsError; | 186 error_ = kNotInOptionalPermissionsError; |
187 return false; | 187 return false; |
188 } | 188 } |
189 | 189 |
190 // We don't need to prompt the user if the requested permissions are a subset | 190 // We don't need to prompt the user if the requested permissions are a subset |
191 // of the granted permissions set. | 191 // of the granted permissions set. |
192 scoped_refptr<const PermissionSet> granted = | 192 scoped_refptr<const PermissionSet> granted = |
193 ExtensionPrefs::Get(profile_)-> | 193 ExtensionPrefs::Get(profile_)-> |
194 GetGrantedPermissions(GetExtension()->id()); | 194 GetGrantedPermissions(GetExtension()->id()); |
195 if (granted && granted->Contains(*requested_permissions_)) { | 195 if (granted.get() && granted->Contains(*requested_permissions_.get())) { |
196 PermissionsUpdater perms_updater(profile()); | 196 PermissionsUpdater perms_updater(profile()); |
197 perms_updater.AddPermissions(GetExtension(), requested_permissions_.get()); | 197 perms_updater.AddPermissions(GetExtension(), requested_permissions_.get()); |
198 results_ = Request::Results::Create(true); | 198 results_ = Request::Results::Create(true); |
199 SendResponse(true); | 199 SendResponse(true); |
200 return true; | 200 return true; |
201 } | 201 } |
202 | 202 |
203 // Filter out the granted permissions so we only prompt for new ones. | 203 // Filter out the granted permissions so we only prompt for new ones. |
204 requested_permissions_ = PermissionSet::CreateDifference( | 204 requested_permissions_ = PermissionSet::CreateDifference( |
205 requested_permissions_.get(), granted.get()); | 205 requested_permissions_.get(), granted.get()); |
(...skipping 14 matching lines...) Expand all Loading... |
220 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); | 220 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); |
221 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); | 221 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); |
222 install_ui_->ConfirmPermissions( | 222 install_ui_->ConfirmPermissions( |
223 this, GetExtension(), requested_permissions_.get()); | 223 this, GetExtension(), requested_permissions_.get()); |
224 } | 224 } |
225 | 225 |
226 return true; | 226 return true; |
227 } | 227 } |
228 | 228 |
229 } // namespace extensions | 229 } // namespace extensions |
OLD | NEW |