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

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

Issue 9969087: Switch platform apps from a declarative launch container to handling an onLaunched event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bring back 512x384 default bounds. 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
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 *utf8_error = UTF16ToUTF8(error); 472 *utf8_error = UTF16ToUTF8(error);
473 return NULL; 473 return NULL;
474 } 474 }
475 475
476 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); 476 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass());
477 if (!extension->InitFromValue(flags, &error)) { 477 if (!extension->InitFromValue(flags, &error)) {
478 *utf8_error = UTF16ToUTF8(error); 478 *utf8_error = UTF16ToUTF8(error);
479 return NULL; 479 return NULL;
480 } 480 }
481 481
482 if (extension->is_platform_app() && 482 if (extension->is_platform_app()) {
483 !CommandLine::ForCurrentProcess()->HasSwitch( 483 if (!CommandLine::ForCurrentProcess()->HasSwitch(
484 switches::kEnablePlatformApps)) { 484 switches::kEnablePlatformApps)) {
485 *utf8_error = errors::kPlatformAppFlagRequired; 485 *utf8_error = errors::kPlatformAppFlagRequired;
486 return NULL; 486 return NULL;
487 }
488
489 if (!extension->has_background_page()) {
490 *utf8_error = errors::kBackgroundRequiredForPlatformApps;
491 return NULL;
492 }
487 } 493 }
488 494
489 return extension; 495 return extension;
490 } 496 }
491 497
492 // static 498 // static
493 Extension::Location Extension::GetHigherPriorityLocation( 499 Extension::Location Extension::GetHigherPriorityLocation(
494 Extension::Location loc1, Extension::Location loc2) { 500 Extension::Location loc1, Extension::Location loc2) {
495 if (loc1 == loc2) 501 if (loc1 == loc2)
496 return loc1; 502 return loc1;
(...skipping 761 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 if (is_platform_app() && manifest_->Get(keys::kLaunch, &temp)) {
1275 *error = ASCIIToUTF16(errors::kLaunchNotAllowedForPlatformApps);
1276 return false;
1277 }
miket_OOO 2012/04/06 18:05:01 I wish there were a single point in this file wher
Aaron Boodman 2012/04/06 18:59:01 It should be possible to extend the feature system
Mihai Parparita -not on Chrome 2012/04/06 22:02:59 That seems pretty doable if we invert the loop in
1278
1268 // launch URL can be either local (to chrome-extension:// root) or an absolute 1279 // launch URL can be either local (to chrome-extension:// root) or an absolute
1269 // web URL. 1280 // web URL.
1270 if (manifest_->Get(keys::kLaunchLocalPath, &temp)) { 1281 if (manifest_->Get(keys::kLaunchLocalPath, &temp)) {
1271 if (manifest_->Get(keys::kLaunchWebURL, NULL)) { 1282 if (manifest_->Get(keys::kLaunchWebURL, NULL)) {
1272 *error = ASCIIToUTF16(errors::kLaunchPathAndURLAreExclusive); 1283 *error = ASCIIToUTF16(errors::kLaunchPathAndURLAreExclusive);
1273 return false; 1284 return false;
1274 } 1285 }
1275 1286
1276 if (manifest_->Get(keys::kWebURLs, NULL)) { 1287 if (manifest_->Get(keys::kWebURLs, NULL)) {
1277 *error = ASCIIToUTF16(errors::kLaunchPathAndExtentAreExclusive); 1288 *error = ASCIIToUTF16(errors::kLaunchPathAndExtentAreExclusive);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 GURL url(launch_url); 1320 GURL url(launch_url);
1310 URLPattern pattern(kValidWebExtentSchemes); 1321 URLPattern pattern(kValidWebExtentSchemes);
1311 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) { 1322 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) {
1312 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 1323 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1313 errors::kInvalidLaunchValue, 1324 errors::kInvalidLaunchValue,
1314 keys::kLaunchWebURL); 1325 keys::kLaunchWebURL);
1315 return false; 1326 return false;
1316 } 1327 }
1317 1328
1318 launch_web_url_ = launch_url; 1329 launch_web_url_ = launch_url;
1319 } else if (is_app()) { 1330 } else if (is_packaged_app() || is_hosted_app()) {
1320 *error = ASCIIToUTF16(errors::kLaunchURLRequired); 1331 *error = ASCIIToUTF16(errors::kLaunchURLRequired);
1321 return false; 1332 return false;
1322 } 1333 }
1323 1334
1324 // If there is no extent, we default the extent based on the launch URL. 1335 // If there is no extent, we default the extent based on the launch URL.
1325 if (web_extent().is_empty() && !launch_web_url().empty()) { 1336 if (web_extent().is_empty() && !launch_web_url().empty()) {
1326 GURL launch_url(launch_web_url()); 1337 GURL launch_url(launch_web_url());
1327 URLPattern pattern(kValidWebExtentSchemes); 1338 URLPattern pattern(kValidWebExtentSchemes);
1328 if (!pattern.SetScheme("*")) { 1339 if (!pattern.SetScheme("*")) {
1329 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 1340 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 Value* temp = NULL; 1385 Value* temp = NULL;
1375 if (!manifest_->Get(keys::kLaunchContainer, &temp)) 1386 if (!manifest_->Get(keys::kLaunchContainer, &temp))
1376 return true; 1387 return true;
1377 1388
1378 std::string launch_container_string; 1389 std::string launch_container_string;
1379 if (!temp->GetAsString(&launch_container_string)) { 1390 if (!temp->GetAsString(&launch_container_string)) {
1380 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer); 1391 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer);
1381 return false; 1392 return false;
1382 } 1393 }
1383 1394
1384 if (launch_container_string == values::kLaunchContainerShell) { 1395 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; 1396 launch_container_ = extension_misc::LAUNCH_PANEL;
1388 } else if (launch_container_string == values::kLaunchContainerTab) { 1397 } else if (launch_container_string == values::kLaunchContainerTab) {
1389 launch_container_ = extension_misc::LAUNCH_TAB; 1398 launch_container_ = extension_misc::LAUNCH_TAB;
1390 } else { 1399 } else {
1391 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer); 1400 *error = ASCIIToUTF16(errors::kInvalidLaunchContainer);
1392 return false; 1401 return false;
1393 } 1402 }
1394 1403
1395 bool can_specify_initial_size = 1404 bool can_specify_initial_size =
1396 launch_container_ == extension_misc::LAUNCH_PANEL || 1405 launch_container_ == extension_misc::LAUNCH_PANEL ||
1397 launch_container_ == extension_misc::LAUNCH_WINDOW || 1406 launch_container_ == extension_misc::LAUNCH_WINDOW;
1398 launch_container_ == extension_misc::LAUNCH_SHELL;
1399 1407
1400 // Validate the container width if present. 1408 // Validate the container width if present.
1401 if (!ReadLaunchDimension(manifest_, 1409 if (!ReadLaunchDimension(manifest_,
1402 keys::kLaunchWidth, 1410 keys::kLaunchWidth,
1403 &launch_width_, 1411 &launch_width_,
1404 can_specify_initial_size, 1412 can_specify_initial_size,
1405 error)) 1413 error))
1406 return false; 1414 return false;
1407 1415
1408 // Validate container height if present. 1416 // Validate container height if present.
1409 if (!ReadLaunchDimension(manifest_, 1417 if (!ReadLaunchDimension(manifest_,
1410 keys::kLaunchHeight, 1418 keys::kLaunchHeight,
1411 &launch_height_, 1419 &launch_height_,
1412 can_specify_initial_size, 1420 can_specify_initial_size,
1413 error)) 1421 error))
1414 return false; 1422 return false;
1415 1423
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 }
miket_OOO 2012/04/06 18:05:01 Great!
1481
1482 return true; 1424 return true;
1483 } 1425 }
1484 1426
1485 bool Extension::LoadSharedFeatures( 1427 bool Extension::LoadSharedFeatures(
1486 const ExtensionAPIPermissionSet& api_permissions, 1428 const ExtensionAPIPermissionSet& api_permissions,
1487 string16* error) { 1429 string16* error) {
1488 if (!LoadDescription(error) || 1430 if (!LoadDescription(error) ||
1489 !LoadHomepageURL(error) || 1431 !LoadHomepageURL(error) ||
1490 !LoadUpdateURL(error) || 1432 !LoadUpdateURL(error) ||
1491 !LoadIcons(error) || 1433 !LoadIcons(error) ||
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 incognito_split_mode_(false), 2803 incognito_split_mode_(false),
2862 offline_enabled_(false), 2804 offline_enabled_(false),
2863 converted_from_user_script_(false), 2805 converted_from_user_script_(false),
2864 background_page_is_transient_(false), 2806 background_page_is_transient_(false),
2865 allow_background_js_access_(true), 2807 allow_background_js_access_(true),
2866 manifest_(manifest.release()), 2808 manifest_(manifest.release()),
2867 is_storage_isolated_(false), 2809 is_storage_isolated_(false),
2868 launch_container_(extension_misc::LAUNCH_TAB), 2810 launch_container_(extension_misc::LAUNCH_TAB),
2869 launch_width_(0), 2811 launch_width_(0),
2870 launch_height_(0), 2812 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), 2813 wants_file_access_(false),
2876 creation_flags_(0) { 2814 creation_flags_(0) {
2877 DCHECK(path.empty() || path.IsAbsolute()); 2815 DCHECK(path.empty() || path.IsAbsolute());
2878 path_ = MaybeNormalizePath(path); 2816 path_ = MaybeNormalizePath(path);
2879 } 2817 }
2880 2818
2881 Extension::~Extension() { 2819 Extension::~Extension() {
2882 if (manifest_) 2820 if (manifest_)
2883 delete manifest_; 2821 delete manifest_;
2884 } 2822 }
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
3705 already_disabled(false), 3643 already_disabled(false),
3706 extension(extension) {} 3644 extension(extension) {}
3707 3645
3708 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3646 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3709 const Extension* extension, 3647 const Extension* extension,
3710 const ExtensionPermissionSet* permissions, 3648 const ExtensionPermissionSet* permissions,
3711 Reason reason) 3649 Reason reason)
3712 : reason(reason), 3650 : reason(reason),
3713 extension(extension), 3651 extension(extension),
3714 permissions(permissions) {} 3652 permissions(permissions) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698