Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/extensions/api/permissions/permissions_api.cc

Issue 11312228: Move extension_error_utils.* and url_pattern_set.* into (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hate Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/permissions_updater.h" 10 #include "chrome/browser/extensions/permissions_updater.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
13 #include "chrome/common/extensions/api/permissions.h" 13 #include "chrome/common/extensions/api/permissions.h"
14 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_error_utils.h"
16 #include "chrome/common/extensions/permissions/permissions_info.h" 15 #include "chrome/common/extensions/permissions/permissions_info.h"
17 #include "chrome/common/extensions/url_pattern_set.h" 16 #include "extensions/common/error_utils.h"
17 #include "extensions/common/url_pattern_set.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 19
20 using extensions::api::permissions::Permissions; 20 using extensions::api::permissions::Permissions;
21 using extensions::APIPermission; 21 using extensions::APIPermission;
22 using extensions::APIPermissionSet; 22 using extensions::APIPermissionSet;
23 using extensions::ErrorUtils;
23 using extensions::PermissionSet; 24 using extensions::PermissionSet;
24 using extensions::PermissionsInfo; 25 using extensions::PermissionsInfo;
25 using extensions::PermissionsUpdater; 26 using extensions::PermissionsUpdater;
26 27
27 namespace Contains = extensions::api::permissions::Contains; 28 namespace Contains = extensions::api::permissions::Contains;
28 namespace GetAll = extensions::api::permissions::GetAll; 29 namespace GetAll = extensions::api::permissions::GetAll;
29 namespace Remove = extensions::api::permissions::Remove; 30 namespace Remove = extensions::api::permissions::Remove;
30 namespace Request = extensions::api::permissions::Request; 31 namespace Request = extensions::api::permissions::Request;
31 namespace helpers = extensions::permissions_api_helpers; 32 namespace helpers = extensions::permissions_api_helpers;
32 33
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 if (!permissions.get()) 81 if (!permissions.get())
81 return false; 82 return false;
82 83
83 const extensions::Extension* extension = GetExtension(); 84 const extensions::Extension* extension = GetExtension();
84 85
85 // Make sure they're only trying to remove permissions supported by this API. 86 // Make sure they're only trying to remove permissions supported by this API.
86 APIPermissionSet apis = permissions->apis(); 87 APIPermissionSet apis = permissions->apis();
87 for (APIPermissionSet::const_iterator i = apis.begin(); 88 for (APIPermissionSet::const_iterator i = apis.begin();
88 i != apis.end(); ++i) { 89 i != apis.end(); ++i) {
89 if (!i->info()->supports_optional()) { 90 if (!i->info()->supports_optional()) {
90 error_ = ExtensionErrorUtils::FormatErrorMessage( 91 error_ = ErrorUtils::FormatErrorMessage(
91 kNotWhitelistedError, i->name()); 92 kNotWhitelistedError, i->name());
92 return false; 93 return false;
93 } 94 }
94 } 95 }
95 96
96 // Make sure we don't remove any required pemissions. 97 // Make sure we don't remove any required pemissions.
97 const PermissionSet* required = extension->required_permission_set(); 98 const PermissionSet* required = extension->required_permission_set();
98 scoped_refptr<PermissionSet> intersection( 99 scoped_refptr<PermissionSet> intersection(
99 PermissionSet::CreateIntersection(permissions.get(), required)); 100 PermissionSet::CreateIntersection(permissions.get(), required));
100 if (!intersection->IsEmpty()) { 101 if (!intersection->IsEmpty()) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return false; 156 return false;
156 157
157 extensions::ExtensionPrefs* prefs = 158 extensions::ExtensionPrefs* prefs =
158 profile()->GetExtensionService()->extension_prefs(); 159 profile()->GetExtensionService()->extension_prefs();
159 160
160 // Make sure they're only requesting permissions supported by this API. 161 // Make sure they're only requesting permissions supported by this API.
161 APIPermissionSet apis = requested_permissions_->apis(); 162 APIPermissionSet apis = requested_permissions_->apis();
162 for (APIPermissionSet::const_iterator i = apis.begin(); 163 for (APIPermissionSet::const_iterator i = apis.begin();
163 i != apis.end(); ++i) { 164 i != apis.end(); ++i) {
164 if (!i->info()->supports_optional()) { 165 if (!i->info()->supports_optional()) {
165 error_ = ExtensionErrorUtils::FormatErrorMessage( 166 error_ = ErrorUtils::FormatErrorMessage(
166 kNotWhitelistedError, i->name()); 167 kNotWhitelistedError, i->name());
167 return false; 168 return false;
168 } 169 }
169 } 170 }
170 171
171 // The requested permissions must be defined as optional in the manifest. 172 // The requested permissions must be defined as optional in the manifest.
172 if (!GetExtension()->optional_permission_set()->Contains( 173 if (!GetExtension()->optional_permission_set()->Contains(
173 *requested_permissions_)) { 174 *requested_permissions_)) {
174 error_ = kNotInOptionalPermissionsError; 175 error_ = kNotInOptionalPermissionsError;
175 results_ = Request::Results::Create(false); 176 results_ = Request::Results::Create(false);
(...skipping 30 matching lines...) Expand all
206 InstallUIAbort(true); 207 InstallUIAbort(true);
207 } else { 208 } else {
208 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests); 209 CHECK_EQ(DO_NOT_SKIP, auto_confirm_for_tests);
209 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents())); 210 install_ui_.reset(new ExtensionInstallPrompt(GetAssociatedWebContents()));
210 install_ui_->ConfirmPermissions( 211 install_ui_->ConfirmPermissions(
211 this, GetExtension(), requested_permissions_.get()); 212 this, GetExtension(), requested_permissions_.get());
212 } 213 }
213 214
214 return true; 215 return true;
215 } 216 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698