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

Side by Side Diff: extensions/common/manifest_handlers/background_info.cc

Issue 309533007: Refactor PermissionsData pt1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "extensions/common/manifest_handlers/background_info.h" 5 #include "extensions/common/manifest_handlers/background_info.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
14 #include "extensions/common/constants.h" 14 #include "extensions/common/constants.h"
15 #include "extensions/common/error_utils.h" 15 #include "extensions/common/error_utils.h"
16 #include "extensions/common/file_util.h" 16 #include "extensions/common/file_util.h"
17 #include "extensions/common/manifest_constants.h" 17 #include "extensions/common/manifest_constants.h"
18 #include "extensions/common/manifest_handlers/permissions_parser.h"
18 #include "extensions/common/permissions/api_permission_set.h" 19 #include "extensions/common/permissions/api_permission_set.h"
19 #include "extensions/common/permissions/permissions_data.h"
20 #include "extensions/common/switches.h" 20 #include "extensions/common/switches.h"
21 #include "grit/extensions_strings.h" 21 #include "grit/extensions_strings.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 23
24 using base::ASCIIToUTF16; 24 using base::ASCIIToUTF16;
25 using base::DictionaryValue; 25 using base::DictionaryValue;
26 26
27 namespace extensions { 27 namespace extensions {
28 28
29 namespace keys = manifest_keys; 29 namespace keys = manifest_keys;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 190
191 std::string background_str; 191 std::string background_str;
192 if (!background_page_value->GetAsString(&background_str)) { 192 if (!background_page_value->GetAsString(&background_str)) {
193 *error = ASCIIToUTF16(errors::kInvalidBackground); 193 *error = ASCIIToUTF16(errors::kInvalidBackground);
194 return false; 194 return false;
195 } 195 }
196 196
197 if (extension->is_hosted_app()) { 197 if (extension->is_hosted_app()) {
198 background_url_ = GURL(background_str); 198 background_url_ = GURL(background_str);
199 199
200 if (!PermissionsData::GetInitialAPIPermissions(extension)->count( 200 if (!PermissionsParser::HasAPIPermission(extension,
201 APIPermission::kBackground)) { 201 APIPermission::kBackground)) {
202 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); 202 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded);
203 return false; 203 return false;
204 } 204 }
205 // Hosted apps require an absolute URL. 205 // Hosted apps require an absolute URL.
206 if (!background_url_.is_valid()) { 206 if (!background_url_.is_valid()) {
207 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); 207 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
208 return false; 208 return false;
209 } 209 }
210 210
211 if (!(background_url_.SchemeIs("https") || 211 if (!(background_url_.SchemeIs("https") ||
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 return false; 290 return false;
291 291
292 // Platform apps must have background pages or service workers. 292 // Platform apps must have background pages or service workers.
293 if (extension->is_platform_app() && !info->has_background_page() && 293 if (extension->is_platform_app() && !info->has_background_page() &&
294 !info->has_service_worker()) { 294 !info->has_service_worker()) {
295 *error = ASCIIToUTF16(errors::kBackgroundRequiredForPlatformApps); 295 *error = ASCIIToUTF16(errors::kBackgroundRequiredForPlatformApps);
296 return false; 296 return false;
297 } 297 }
298 // Lazy background pages are incompatible with the webRequest API. 298 // Lazy background pages are incompatible with the webRequest API.
299 if (info->has_lazy_background_page() && 299 if (info->has_lazy_background_page() &&
300 PermissionsData::GetInitialAPIPermissions(extension)->count( 300 PermissionsParser::HasAPIPermission(extension,
301 APIPermission::kWebRequest)) { 301 APIPermission::kWebRequest)) {
302 *error = ASCIIToUTF16(errors::kWebRequestConflictsWithLazyBackground); 302 *error = ASCIIToUTF16(errors::kWebRequestConflictsWithLazyBackground);
303 return false; 303 return false;
304 } 304 }
305 305
306 extension->SetManifestData(kBackground, info.release()); 306 extension->SetManifestData(kBackground, info.release());
307 return true; 307 return true;
308 } 308 }
309 309
310 bool BackgroundManifestHandler::Validate( 310 bool BackgroundManifestHandler::Validate(
311 const Extension* extension, 311 const Extension* extension,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 keys::kBackgroundPageLegacy, 353 keys::kBackgroundPageLegacy,
354 keys::kBackgroundPersistent, 354 keys::kBackgroundPersistent,
355 keys::kBackgroundScripts, 355 keys::kBackgroundScripts,
356 keys::kPlatformAppBackgroundPage, 356 keys::kPlatformAppBackgroundPage,
357 keys::kPlatformAppBackgroundScripts, 357 keys::kPlatformAppBackgroundScripts,
358 keys::kPlatformAppServiceWorkerScript}; 358 keys::kPlatformAppServiceWorkerScript};
359 return std::vector<std::string>(keys, keys + arraysize(keys)); 359 return std::vector<std::string>(keys, keys + arraysize(keys));
360 } 360 }
361 361
362 } // namespace extensions 362 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698