OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 URLPattern::SCHEME_CHROMEUI) & ~URLPattern::SCHEME_FILE; | 268 URLPattern::SCHEME_CHROMEUI) & ~URLPattern::SCHEME_FILE; |
269 | 269 |
270 // | 270 // |
271 // Extension | 271 // Extension |
272 // | 272 // |
273 | 273 |
274 // static | 274 // static |
275 scoped_refptr<Extension> Extension::Create(const FilePath& path, | 275 scoped_refptr<Extension> Extension::Create(const FilePath& path, |
276 Location location, | 276 Location location, |
277 const DictionaryValue& value, | 277 const DictionaryValue& value, |
278 bool require_key, | 278 int flags, |
279 bool strict_error_checks, | |
280 std::string* error) { | 279 std::string* error) { |
281 scoped_refptr<Extension> extension = new Extension(path, location); | 280 scoped_refptr<Extension> extension = new Extension(path, location); |
282 | 281 |
283 if (!extension->InitFromValue(value, require_key, strict_error_checks, error)) | 282 if (!extension->InitFromValue(value, flags, error)) |
284 return NULL; | 283 return NULL; |
285 return extension; | 284 return extension; |
286 } | 285 } |
287 | 286 |
288 namespace { | 287 namespace { |
289 const char* kGalleryUpdateHttpUrl = | 288 const char* kGalleryUpdateHttpUrl = |
290 "http://clients2.google.com/service/update2/crx"; | 289 "http://clients2.google.com/service/update2/crx"; |
291 const char* kGalleryUpdateHttpsUrl = | 290 const char* kGalleryUpdateHttpsUrl = |
292 "https://clients2.google.com/service/update2/crx"; | 291 "https://clients2.google.com/service/update2/crx"; |
293 } // namespace | 292 } // namespace |
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1395 } | 1394 } |
1396 | 1395 |
1397 result->swap(decoded); | 1396 result->swap(decoded); |
1398 } | 1397 } |
1399 | 1398 |
1400 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { | 1399 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { |
1401 return GURL(std::string(chrome::kExtensionScheme) + | 1400 return GURL(std::string(chrome::kExtensionScheme) + |
1402 chrome::kStandardSchemeSeparator + extension_id + "/"); | 1401 chrome::kStandardSchemeSeparator + extension_id + "/"); |
1403 } | 1402 } |
1404 | 1403 |
1405 bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, | 1404 bool Extension::InitFromValue(const DictionaryValue& source, int flags, |
1406 bool strict_error_checks, std::string* error) { | 1405 std::string* error) { |
1407 // When strict error checks are enabled, make URL pattern parsing strict. | 1406 // When strict error checks are enabled, make URL pattern parsing strict. |
1408 URLPattern::ParseOption parse_strictness = | 1407 URLPattern::ParseOption parse_strictness = |
1409 (strict_error_checks ? URLPattern::PARSE_STRICT | 1408 (flags & STRICT_ERROR_CHECKS ? URLPattern::PARSE_STRICT |
1410 : URLPattern::PARSE_LENIENT); | 1409 : URLPattern::PARSE_LENIENT); |
1411 | 1410 |
1412 if (source.HasKey(keys::kPublicKey)) { | 1411 if (source.HasKey(keys::kPublicKey)) { |
1413 std::string public_key_bytes; | 1412 std::string public_key_bytes; |
1414 if (!source.GetString(keys::kPublicKey, | 1413 if (!source.GetString(keys::kPublicKey, |
1415 &public_key_) || | 1414 &public_key_) || |
1416 !ParsePEMKeyBytes(public_key_, | 1415 !ParsePEMKeyBytes(public_key_, |
1417 &public_key_bytes) || | 1416 &public_key_bytes) || |
1418 !GenerateId(public_key_bytes, &id_)) { | 1417 !GenerateId(public_key_bytes, &id_)) { |
1419 *error = errors::kInvalidKey; | 1418 *error = errors::kInvalidKey; |
1420 return false; | 1419 return false; |
1421 } | 1420 } |
1422 } else if (require_key) { | 1421 } else if (flags & REQUIRE_KEY) { |
1423 *error = errors::kInvalidKey; | 1422 *error = errors::kInvalidKey; |
1424 return false; | 1423 return false; |
1425 } else { | 1424 } else { |
1426 // If there is a path, we generate the ID from it. This is useful for | 1425 // If there is a path, we generate the ID from it. This is useful for |
1427 // development mode, because it keeps the ID stable across restarts and | 1426 // development mode, because it keeps the ID stable across restarts and |
1428 // reloading the extension. | 1427 // reloading the extension. |
1429 id_ = Extension::GenerateIdForPath(path()); | 1428 id_ = Extension::GenerateIdForPath(path()); |
1430 if (id_.empty()) { | 1429 if (id_.empty()) { |
1431 NOTREACHED() << "Could not create ID from path."; | 1430 NOTREACHED() << "Could not create ID from path."; |
1432 return false; | 1431 return false; |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2560 | 2559 |
2561 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} | 2560 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} |
2562 | 2561 |
2563 | 2562 |
2564 UnloadedExtensionInfo::UnloadedExtensionInfo( | 2563 UnloadedExtensionInfo::UnloadedExtensionInfo( |
2565 const Extension* extension, | 2564 const Extension* extension, |
2566 Reason reason) | 2565 Reason reason) |
2567 : reason(reason), | 2566 : reason(reason), |
2568 already_disabled(false), | 2567 already_disabled(false), |
2569 extension(extension) {} | 2568 extension(extension) {} |
OLD | NEW |