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

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 10080017: Switch platform apps from a declarative launch container to handling an onLaunched event. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: remove debug logging code Created 8 years, 8 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 *utf8_error = UTF16ToUTF8(error); 471 *utf8_error = UTF16ToUTF8(error);
472 return NULL; 472 return NULL;
473 } 473 }
474 474
475 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); 475 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass());
476 if (!extension->InitFromValue(flags, &error)) { 476 if (!extension->InitFromValue(flags, &error)) {
477 *utf8_error = UTF16ToUTF8(error); 477 *utf8_error = UTF16ToUTF8(error);
478 return NULL; 478 return NULL;
479 } 479 }
480 480
481 if (extension->is_platform_app() && 481 if (extension->is_platform_app()) {
482 !CommandLine::ForCurrentProcess()->HasSwitch( 482 if (!CommandLine::ForCurrentProcess()->HasSwitch(
483 switches::kEnablePlatformApps)) { 483 switches::kEnablePlatformApps)) {
484 *utf8_error = errors::kPlatformAppFlagRequired; 484 *utf8_error = errors::kPlatformAppFlagRequired;
485 return NULL; 485 return NULL;
486 }
487
488 if (!extension->has_background_page()) {
489 *utf8_error = errors::kBackgroundRequiredForPlatformApps;
490 return NULL;
491 }
486 } 492 }
487 493
488 return extension; 494 return extension;
489 } 495 }
490 496
491 // static 497 // static
492 Extension::Location Extension::GetHigherPriorityLocation( 498 Extension::Location Extension::GetHigherPriorityLocation(
493 Extension::Location loc1, Extension::Location loc2) { 499 Extension::Location loc1, Extension::Location loc2) {
494 if (loc1 == loc2) 500 if (loc1 == loc2)
495 return loc1; 501 return loc1;
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 1264
1259 extent->AddPattern(pattern); 1265 extent->AddPattern(pattern);
1260 } 1266 }
1261 1267
1262 return true; 1268 return true;
1263 } 1269 }
1264 1270
1265 bool Extension::LoadLaunchURL(string16* error) { 1271 bool Extension::LoadLaunchURL(string16* error) {
1266 Value* temp = NULL; 1272 Value* temp = NULL;
1267 1273
1274 // TODO(mihaip): Implement this check via _manifest_features.json (requires
1275 // subkey support, see http://crbug.com/122459).
1276 if (is_platform_app() && manifest_->Get(keys::kLaunch, &temp)) {
1277 *error = ASCIIToUTF16(errors::kLaunchNotAllowedForPlatformApps);
1278 return false;
1279 }
1280
1268 // launch URL can be either local (to chrome-extension:// root) or an absolute 1281 // launch URL can be either local (to chrome-extension:// root) or an absolute
1269 // web URL. 1282 // web URL.
1270 if (manifest_->Get(keys::kLaunchLocalPath, &temp)) { 1283 if (manifest_->Get(keys::kLaunchLocalPath, &temp)) {
1271 if (manifest_->Get(keys::kLaunchWebURL, NULL)) { 1284 if (manifest_->Get(keys::kLaunchWebURL, NULL)) {
1272 *error = ASCIIToUTF16(errors::kLaunchPathAndURLAreExclusive); 1285 *error = ASCIIToUTF16(errors::kLaunchPathAndURLAreExclusive);
1273 return false; 1286 return false;
1274 } 1287 }
1275 1288
1276 if (manifest_->Get(keys::kWebURLs, NULL)) { 1289 if (manifest_->Get(keys::kWebURLs, NULL)) {
1277 *error = ASCIIToUTF16(errors::kLaunchPathAndExtentAreExclusive); 1290 *error = ASCIIToUTF16(errors::kLaunchPathAndExtentAreExclusive);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 GURL url(launch_url); 1322 GURL url(launch_url);
1310 URLPattern pattern(kValidWebExtentSchemes); 1323 URLPattern pattern(kValidWebExtentSchemes);
1311 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) { 1324 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) {
1312 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 1325 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1313 errors::kInvalidLaunchValue, 1326 errors::kInvalidLaunchValue,
1314 keys::kLaunchWebURL); 1327 keys::kLaunchWebURL);
1315 return false; 1328 return false;
1316 } 1329 }
1317 1330
1318 launch_web_url_ = launch_url; 1331 launch_web_url_ = launch_url;
1319 } else if (is_app()) { 1332 } else if (is_packaged_app() || is_hosted_app()) {
1320 *error = ASCIIToUTF16(errors::kLaunchURLRequired); 1333 *error = ASCIIToUTF16(errors::kLaunchURLRequired);
1321 return false; 1334 return false;
1322 } 1335 }
1323 1336
1324 // If there is no extent, we default the extent based on the launch URL. 1337 // If there is no extent, we default the extent based on the launch URL.
1325 if (web_extent().is_empty() && !launch_web_url().empty()) { 1338 if (web_extent().is_empty() && !launch_web_url().empty()) {
1326 GURL launch_url(launch_web_url()); 1339 GURL launch_url(launch_web_url());
1327 URLPattern pattern(kValidWebExtentSchemes); 1340 URLPattern pattern(kValidWebExtentSchemes);
1328 if (!pattern.SetScheme("*")) { 1341 if (!pattern.SetScheme("*")) {
1329 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 1342 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 Value* temp = NULL; 1387 Value* temp = NULL;
1375 if (!manifest_->Get(keys::kLaunchContainer, &temp)) 1388 if (!manifest_->Get(keys::kLaunchContainer, &temp))
1376 return true; 1389 return true;
1377 1390
1378 std::string launch_container_string; 1391 std::string launch_container_string;
1379 if (!temp->GetAsString(&launch_container_string)) { 1392 if (!temp->GetAsString(&launch_container_string)) {
1380 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer); 1393 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer);
1381 return false; 1394 return false;
1382 } 1395 }
1383 1396
1384 if (launch_container_string == values::kLaunchContainerShell) { 1397 if (launch_container_string == values::kLaunchContainerPanel) {
1385 launch_container_ = extension_misc::LAUNCH_SHELL;
1386 } else if (launch_container_string == values::kLaunchContainerPanel) {
1387 launch_container_ = extension_misc::LAUNCH_PANEL; 1398 launch_container_ = extension_misc::LAUNCH_PANEL;
1388 } else if (launch_container_string == values::kLaunchContainerTab) { 1399 } else if (launch_container_string == values::kLaunchContainerTab) {
1389 launch_container_ = extension_misc::LAUNCH_TAB; 1400 launch_container_ = extension_misc::LAUNCH_TAB;
1390 } else { 1401 } else {
1391 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer); 1402 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer);
1392 return false; 1403 return false;
1393 } 1404 }
1394 1405
1395 bool can_specify_initial_size = 1406 bool can_specify_initial_size =
1396 launch_container_ == extension_misc::LAUNCH_PANEL || 1407 launch_container_ == extension_misc::LAUNCH_PANEL ||
1397 launch_container_ == extension_misc::LAUNCH_WINDOW || 1408 launch_container_ == extension_misc::LAUNCH_WINDOW;
1398 launch_container_ == extension_misc::LAUNCH_SHELL;
1399 1409
1400 // Validate the container width if present. 1410 // Validate the container width if present.
1401 if (!ReadLaunchDimension(manifest_, 1411 if (!ReadLaunchDimension(manifest_,
1402 keys::kLaunchWidth, 1412 keys::kLaunchWidth,
1403 &launch_width_, 1413 &launch_width_,
1404 can_specify_initial_size, 1414 can_specify_initial_size,
1405 error)) 1415 error))
1406 return false; 1416 return false;
1407 1417
1408 // Validate container height if present. 1418 // Validate container height if present.
1409 if (!ReadLaunchDimension(manifest_, 1419 if (!ReadLaunchDimension(manifest_,
1410 keys::kLaunchHeight, 1420 keys::kLaunchHeight,
1411 &launch_height_, 1421 &launch_height_,
1412 can_specify_initial_size, 1422 can_specify_initial_size,
1413 error)) 1423 error))
1414 return false; 1424 return false;
1415 1425
1416 bool can_specify_size_range =
1417 launch_container_ == extension_misc::LAUNCH_SHELL;
1418
1419 // Validate min size if present.
1420 if (!ReadLaunchDimension(manifest_,
1421 keys::kLaunchMinWidth,
1422 &launch_min_width_,
1423 can_specify_size_range,
1424 error))
1425 return false;
1426 if (!ReadLaunchDimension(manifest_,
1427 keys::kLaunchMinHeight,
1428 &launch_min_height_,
1429 can_specify_size_range,
1430 error))
1431 return false;
1432 if (!ReadLaunchDimension(manifest_,
1433 keys::kLaunchMaxWidth,
1434 &launch_max_width_,
1435 can_specify_size_range,
1436 error))
1437 return false;
1438 if (!ReadLaunchDimension(manifest_,
1439 keys::kLaunchMaxHeight,
1440 &launch_max_height_,
1441 can_specify_size_range,
1442 error))
1443 return false;
1444
1445 if (launch_container_ == extension_misc::LAUNCH_SHELL) {
1446 if (!manifest_->Get(keys::kLaunchWidth, &temp)) {
1447 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1448 errors::kInvalidLaunchValue,
1449 keys::kLaunchWidth);
1450 return false;
1451 }
1452 if (!manifest_->Get(keys::kLaunchHeight, &temp)) {
1453 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1454 errors::kInvalidLaunchValue,
1455 keys::kLaunchHeight);
1456 return false;
1457 }
1458 if (launch_max_width_ > 0 && launch_max_width_ < launch_min_width_) {
1459 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1460 errors::kInvalidLaunchValue,
1461 keys::kLaunchMaxWidth);
1462 return false;
1463 }
1464 if (launch_max_height_ > 0 && launch_max_height_ < launch_min_height_) {
1465 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1466 errors::kInvalidLaunchValue,
1467 keys::kLaunchMaxHeight);
1468 return false;
1469 }
1470 }
1471
1472 if (is_platform_app()) {
1473 if (launch_container_ != extension_misc::LAUNCH_SHELL) {
1474 *error = ASCIIToUTF16(errors::kInvalidLaunchContainerForPlatform);
1475 return false;
1476 }
1477 } else if (launch_container_ == extension_misc::LAUNCH_SHELL) {
1478 *error = ASCIIToUTF16(errors::kInvalidLaunchContainerForNonPlatform);
1479 return false;
1480 }
1481
1482 return true; 1426 return true;
1483 } 1427 }
1484 1428
1485 bool Extension::LoadSharedFeatures( 1429 bool Extension::LoadSharedFeatures(
1486 const ExtensionAPIPermissionSet& api_permissions, 1430 const ExtensionAPIPermissionSet& api_permissions,
1487 string16* error) { 1431 string16* error) {
1488 if (!LoadDescription(error) || 1432 if (!LoadDescription(error) ||
1489 !LoadHomepageURL(error) || 1433 !LoadHomepageURL(error) ||
1490 !LoadUpdateURL(error) || 1434 !LoadUpdateURL(error) ||
1491 !LoadIcons(error) || 1435 !LoadIcons(error) ||
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 incognito_split_mode_(false), 2805 incognito_split_mode_(false),
2862 offline_enabled_(false), 2806 offline_enabled_(false),
2863 converted_from_user_script_(false), 2807 converted_from_user_script_(false),
2864 background_page_is_transient_(false), 2808 background_page_is_transient_(false),
2865 allow_background_js_access_(true), 2809 allow_background_js_access_(true),
2866 manifest_(manifest.release()), 2810 manifest_(manifest.release()),
2867 is_storage_isolated_(false), 2811 is_storage_isolated_(false),
2868 launch_container_(extension_misc::LAUNCH_TAB), 2812 launch_container_(extension_misc::LAUNCH_TAB),
2869 launch_width_(0), 2813 launch_width_(0),
2870 launch_height_(0), 2814 launch_height_(0),
2871 launch_min_width_(0),
2872 launch_min_height_(0),
2873 launch_max_width_(0),
2874 launch_max_height_(0),
2875 wants_file_access_(false), 2815 wants_file_access_(false),
2876 creation_flags_(0) { 2816 creation_flags_(0) {
2877 DCHECK(path.empty() || path.IsAbsolute()); 2817 DCHECK(path.empty() || path.IsAbsolute());
2878 path_ = MaybeNormalizePath(path); 2818 path_ = MaybeNormalizePath(path);
2879 } 2819 }
2880 2820
2881 Extension::~Extension() { 2821 Extension::~Extension() {
2882 if (manifest_) 2822 if (manifest_)
2883 delete manifest_; 2823 delete manifest_;
2884 } 2824 }
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
3707 already_disabled(false), 3647 already_disabled(false),
3708 extension(extension) {} 3648 extension(extension) {}
3709 3649
3710 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3650 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3711 const Extension* extension, 3651 const Extension* extension,
3712 const ExtensionPermissionSet* permissions, 3652 const ExtensionPermissionSet* permissions,
3713 Reason reason) 3653 Reason reason)
3714 : reason(reason), 3654 : reason(reason),
3715 extension(extension), 3655 extension(extension),
3716 permissions(permissions) {} 3656 permissions(permissions) {}
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698