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

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

Issue 10536084: Add a warning when developing an extension that uses old manifest version. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: blonk Created 8 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_file_util.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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 scoped_ptr<extensions::Manifest> manifest( 314 scoped_ptr<extensions::Manifest> manifest(
315 new extensions::Manifest( 315 new extensions::Manifest(
316 location, 316 location,
317 scoped_ptr<DictionaryValue>(value.DeepCopy()))); 317 scoped_ptr<DictionaryValue>(value.DeepCopy())));
318 318
319 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) { 319 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) {
320 *utf8_error = UTF16ToUTF8(error); 320 *utf8_error = UTF16ToUTF8(error);
321 return NULL; 321 return NULL;
322 } 322 }
323 323
324 std::vector<std::string> install_warnings; 324 InstallWarningVector install_warnings;
325 manifest->ValidateManifest(utf8_error, &install_warnings); 325 manifest->ValidateManifest(utf8_error, &install_warnings);
326 if (!utf8_error->empty()) 326 if (!utf8_error->empty())
327 return NULL; 327 return NULL;
328 328
329 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass()); 329 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass());
330 extension->install_warnings_.swap(install_warnings); 330 extension->install_warnings_.swap(install_warnings);
331 331
332 if (!extension->InitFromValue(flags, &error)) { 332 if (!extension->InitFromValue(flags, &error)) {
333 *utf8_error = UTF16ToUTF8(error); 333 *utf8_error = UTF16ToUTF8(error);
334 return NULL; 334 return NULL;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 403
404 const std::string& Extension::id() const { 404 const std::string& Extension::id() const {
405 return manifest_->extension_id(); 405 return manifest_->extension_id();
406 } 406 }
407 407
408 const std::string Extension::VersionString() const { 408 const std::string Extension::VersionString() const {
409 return version()->GetString(); 409 return version()->GetString();
410 } 410 }
411 411
412 void Extension::AddInstallWarnings( 412 void Extension::AddInstallWarnings(
413 const std::vector<std::string>& new_warnings) { 413 const InstallWarningVector& new_warnings) {
414 install_warnings_.insert(install_warnings_.end(), 414 install_warnings_.insert(install_warnings_.end(),
415 new_warnings.begin(), new_warnings.end()); 415 new_warnings.begin(), new_warnings.end());
416 } 416 }
417 417
418 // static 418 // static
419 bool Extension::IsExtension(const FilePath& file_name) { 419 bool Extension::IsExtension(const FilePath& file_name) {
420 return file_name.MatchesExtension(chrome::kExtensionFileExtension); 420 return file_name.MatchesExtension(chrome::kExtensionFileExtension);
421 } 421 }
422 422
423 // static 423 // static
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 manifest_version < 1) { 1340 manifest_version < 1) {
1341 *error = ASCIIToUTF16(errors::kInvalidManifestVersion); 1341 *error = ASCIIToUTF16(errors::kInvalidManifestVersion);
1342 return false; 1342 return false;
1343 } 1343 }
1344 } 1344 }
1345 1345
1346 manifest_version_ = manifest_->GetManifestVersion(); 1346 manifest_version_ = manifest_->GetManifestVersion();
1347 if (creation_flags_ & REQUIRE_MODERN_MANIFEST_VERSION && 1347 if (creation_flags_ & REQUIRE_MODERN_MANIFEST_VERSION &&
1348 manifest_version_ < kModernManifestVersion && 1348 manifest_version_ < kModernManifestVersion &&
1349 !CommandLine::ForCurrentProcess()->HasSwitch( 1349 !CommandLine::ForCurrentProcess()->HasSwitch(
1350 switches::kAllowLegacyExtensionManifests)) { 1350 switches::kAllowLegacyExtensionManifests)) {
1351 *error = ASCIIToUTF16(errors::kInvalidManifestVersion); 1351 *error = ASCIIToUTF16(errors::kInvalidManifestVersion);
1352 return false; 1352 return false;
1353 }
1354
1355 if (location() == LOAD && manifest_version_ == 1) {
1356 install_warnings_.push_back(Extension::InstallWarning(
1357 Extension::InstallWarning::FORMAT_HTML,
1358 l10n_util::GetStringFUTF8(
1359 IDS_EXTENSION_MANIFEST_VERSION_OLD,
1360 ASCIIToUTF16("<a href='http://code.google.com/chrome/extensions/"
1361 "manifestVersion.html'>"),
1362 ASCIIToUTF16("</a>"))));
1353 } 1363 }
1354 1364
1355 return true; 1365 return true;
1356 } 1366 }
1357 1367
1358 bool Extension::LoadHomepageURL(string16* error) { 1368 bool Extension::LoadHomepageURL(string16* error) {
1359 if (!manifest_->HasKey(keys::kHomepageURL)) 1369 if (!manifest_->HasKey(keys::kHomepageURL))
1360 return true; 1370 return true;
1361 std::string tmp; 1371 std::string tmp;
1362 if (!manifest_->GetString(keys::kHomepageURL, &tmp)) { 1372 if (!manifest_->GetString(keys::kHomepageURL, &tmp)) {
(...skipping 1871 matching lines...) Expand 10 before | Expand all | Expand 10 after
3234 extensions::Feature::Availability availability = 3244 extensions::Feature::Availability availability =
3235 feature->IsAvailableToManifest( 3245 feature->IsAvailableToManifest(
3236 id(), 3246 id(),
3237 GetType(), 3247 GetType(),
3238 extensions::Feature::ConvertLocation(location()), 3248 extensions::Feature::ConvertLocation(location()),
3239 manifest_version()); 3249 manifest_version());
3240 if (availability != extensions::Feature::IS_AVAILABLE) { 3250 if (availability != extensions::Feature::IS_AVAILABLE) {
3241 // Don't fail, but warn the developer that the manifest contains 3251 // Don't fail, but warn the developer that the manifest contains
3242 // unrecognized permissions. This may happen legitimately if the 3252 // unrecognized permissions. This may happen legitimately if the
3243 // extensions requests platform- or channel-specific permissions. 3253 // extensions requests platform- or channel-specific permissions.
3244 install_warnings_.push_back(feature->GetErrorMessage(availability)); 3254 install_warnings_.push_back(
3255 InstallWarning(InstallWarning::FORMAT_TEXT,
3256 feature->GetErrorMessage(availability)));
3245 continue; 3257 continue;
3246 } 3258 }
3247 3259
3248 if (permission->id() == ExtensionAPIPermission::kExperimental) { 3260 if (permission->id() == ExtensionAPIPermission::kExperimental) {
3249 if (!CanSpecifyExperimentalPermission()) { 3261 if (!CanSpecifyExperimentalPermission()) {
3250 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); 3262 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired);
3251 return false; 3263 return false;
3252 } 3264 }
3253 } 3265 }
3254 3266
(...skipping 25 matching lines...) Expand all
3280 pattern.SetValidSchemes( 3292 pattern.SetValidSchemes(
3281 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); 3293 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
3282 } 3294 }
3283 3295
3284 host_permissions->AddPattern(pattern); 3296 host_permissions->AddPattern(pattern);
3285 continue; 3297 continue;
3286 } 3298 }
3287 3299
3288 // It's probably an unknown API permission. Do not throw an error so 3300 // It's probably an unknown API permission. Do not throw an error so
3289 // extensions can retain backwards compatability (http://crbug.com/42742). 3301 // extensions can retain backwards compatability (http://crbug.com/42742).
3290 install_warnings_.push_back(base::StringPrintf( 3302 install_warnings_.push_back(InstallWarning(
3291 "Permission '%s' is unknown or URL pattern is malformed.", 3303 InstallWarning::FORMAT_TEXT,
3292 permission_str.c_str())); 3304 base::StringPrintf(
3305 "Permission '%s' is unknown or URL pattern is malformed.",
3306 permission_str.c_str())));
3293 } 3307 }
3294 } 3308 }
3295 return true; 3309 return true;
3296 } 3310 }
3297 3311
3298 bool Extension::CanSilentlyIncreasePermissions() const { 3312 bool Extension::CanSilentlyIncreasePermissions() const {
3299 return location() != INTERNAL; 3313 return location() != INTERNAL;
3300 } 3314 }
3301 3315
3302 bool Extension::CanSpecifyHostPermission(const URLPattern& pattern, 3316 bool Extension::CanSpecifyHostPermission(const URLPattern& pattern,
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
3723 3737
3724 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3738 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3725 const Extension* extension, 3739 const Extension* extension,
3726 const ExtensionPermissionSet* permissions, 3740 const ExtensionPermissionSet* permissions,
3727 Reason reason) 3741 Reason reason)
3728 : reason(reason), 3742 : reason(reason),
3729 extension(extension), 3743 extension(extension),
3730 permissions(permissions) {} 3744 permissions(permissions) {}
3731 3745
3732 } // namespace extensions 3746 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698