OLD | NEW |
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 <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 << " should not contain a port. Removing it."; | 365 << " should not contain a port. Removing it."; |
366 | 366 |
367 GURL::Replacements remove_port; | 367 GURL::Replacements remove_port; |
368 remove_port.ClearPort(); | 368 remove_port.ClearPort(); |
369 new_url = new_url.ReplaceComponents(remove_port); | 369 new_url = new_url.ReplaceComponents(remove_port); |
370 } | 370 } |
371 | 371 |
372 launch_web_url_ = new_url.spec(); | 372 launch_web_url_ = new_url.spec(); |
373 | 373 |
374 URLPattern pattern(kValidWebExtentSchemes); | 374 URLPattern pattern(kValidWebExtentSchemes); |
375 pattern.Parse(new_url.spec()); | 375 URLPattern::ParseResult result = pattern.Parse(new_url.spec()); |
| 376 DCHECK_EQ(result, URLPattern::PARSE_SUCCESS); |
376 pattern.SetPath(pattern.path() + '*'); | 377 pattern.SetPath(pattern.path() + '*'); |
377 extent_.AddPattern(pattern); | 378 extent_.AddPattern(pattern); |
378 } | 379 } |
379 } | 380 } |
380 | 381 |
381 FilePath Extension::MaybeNormalizePath(const FilePath& path) { | 382 FilePath Extension::MaybeNormalizePath(const FilePath& path) { |
382 #if defined(OS_WIN) | 383 #if defined(OS_WIN) |
383 // Normalize any drive letter to upper-case. We do this for consistency with | 384 // Normalize any drive letter to upper-case. We do this for consistency with |
384 // net_utils::FilePathToFileURL(), which does the same thing, to make string | 385 // net_utils::FilePathToFileURL(), which does the same thing, to make string |
385 // comparisons simpler. | 386 // comparisons simpler. |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 return false; | 1604 return false; |
1604 } | 1605 } |
1605 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1606 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1606 std::string relative_path; | 1607 std::string relative_path; |
1607 if (!list_value->GetString(i, &relative_path)) { | 1608 if (!list_value->GetString(i, &relative_path)) { |
1608 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1609 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1609 errors::kInvalidWebAccessibleResource, base::IntToString(i)); | 1610 errors::kInvalidWebAccessibleResource, base::IntToString(i)); |
1610 return false; | 1611 return false; |
1611 } | 1612 } |
1612 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | 1613 URLPattern pattern(URLPattern::SCHEME_EXTENSION); |
1613 pattern.Parse(extension_url_.spec()); | 1614 if (pattern.Parse(extension_url_.spec()) != URLPattern::PARSE_SUCCESS) { |
| 1615 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 1616 errors::kInvalidURLPatternError, extension_url_.spec()); |
| 1617 return false; |
| 1618 } |
1614 while (relative_path[0] == '/') | 1619 while (relative_path[0] == '/') |
1615 relative_path = relative_path.substr(1, relative_path.length() - 1); | 1620 relative_path = relative_path.substr(1, relative_path.length() - 1); |
1616 pattern.SetPath(pattern.path() + relative_path); | 1621 pattern.SetPath(pattern.path() + relative_path); |
1617 web_accessible_resources_.AddPattern(pattern); | 1622 web_accessible_resources_.AddPattern(pattern); |
1618 } | 1623 } |
1619 | 1624 |
1620 return true; | 1625 return true; |
1621 } | 1626 } |
1622 | 1627 |
1623 bool Extension::LoadSandboxedPages(string16* error) { | 1628 bool Extension::LoadSandboxedPages(string16* error) { |
1624 if (!manifest_->HasPath(keys::kSandboxedPages)) | 1629 if (!manifest_->HasPath(keys::kSandboxedPages)) |
1625 return true; | 1630 return true; |
1626 | 1631 |
1627 ListValue* list_value = NULL; | 1632 ListValue* list_value = NULL; |
1628 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { | 1633 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { |
1629 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); | 1634 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); |
1630 return false; | 1635 return false; |
1631 } | 1636 } |
1632 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1637 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1633 std::string relative_path; | 1638 std::string relative_path; |
1634 if (!list_value->GetString(i, &relative_path)) { | 1639 if (!list_value->GetString(i, &relative_path)) { |
1635 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1640 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1636 errors::kInvalidSandboxedPage, base::IntToString(i)); | 1641 errors::kInvalidSandboxedPage, base::IntToString(i)); |
1637 return false; | 1642 return false; |
1638 } | 1643 } |
1639 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | 1644 URLPattern pattern(URLPattern::SCHEME_EXTENSION); |
1640 pattern.Parse(extension_url_.spec()); | 1645 if (pattern.Parse(extension_url_.spec()) != URLPattern::PARSE_SUCCESS) { |
| 1646 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 1647 errors::kInvalidURLPatternError, extension_url_.spec()); |
| 1648 return false; |
| 1649 } |
1641 while (relative_path[0] == '/') | 1650 while (relative_path[0] == '/') |
1642 relative_path = relative_path.substr(1, relative_path.length() - 1); | 1651 relative_path = relative_path.substr(1, relative_path.length() - 1); |
1643 pattern.SetPath(pattern.path() + relative_path); | 1652 pattern.SetPath(pattern.path() + relative_path); |
1644 sandboxed_pages_.AddPattern(pattern); | 1653 sandboxed_pages_.AddPattern(pattern); |
1645 } | 1654 } |
1646 | 1655 |
1647 if (manifest_->HasPath(keys::kSandboxedPagesCSP)) { | 1656 if (manifest_->HasPath(keys::kSandboxedPagesCSP)) { |
1648 if (!manifest_->GetString( | 1657 if (!manifest_->GetString( |
1649 keys::kSandboxedPagesCSP, &sandboxed_pages_content_security_policy_)) { | 1658 keys::kSandboxedPagesCSP, &sandboxed_pages_content_security_policy_)) { |
1650 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesCSP); | 1659 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesCSP); |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2551 !overrides->GetStringWithoutPathExpansion(*iter, &val)) { | 2560 !overrides->GetStringWithoutPathExpansion(*iter, &val)) { |
2552 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides); | 2561 *error = ASCIIToUTF16(errors::kInvalidChromeURLOverrides); |
2553 return false; | 2562 return false; |
2554 } | 2563 } |
2555 // Replace the entry with a fully qualified chrome-extension:// URL. | 2564 // Replace the entry with a fully qualified chrome-extension:// URL. |
2556 chrome_url_overrides_[page] = GetResourceURL(val); | 2565 chrome_url_overrides_[page] = GetResourceURL(val); |
2557 | 2566 |
2558 // For component extensions, add override URL to extent patterns. | 2567 // For component extensions, add override URL to extent patterns. |
2559 if (is_packaged_app() && location() == COMPONENT) { | 2568 if (is_packaged_app() && location() == COMPONENT) { |
2560 URLPattern pattern(URLPattern::SCHEME_CHROMEUI); | 2569 URLPattern pattern(URLPattern::SCHEME_CHROMEUI); |
2561 pattern.Parse(base::StringPrintf(kOverrideExtentUrlPatternFormat, | 2570 std::string url = base::StringPrintf(kOverrideExtentUrlPatternFormat, |
2562 page.c_str())); | 2571 page.c_str()); |
| 2572 if (pattern.Parse(url) != URLPattern::PARSE_SUCCESS) { |
| 2573 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 2574 errors::kInvalidURLPatternError, url); |
| 2575 return false; |
| 2576 } |
2563 extent_.AddPattern(pattern); | 2577 extent_.AddPattern(pattern); |
2564 } | 2578 } |
2565 } | 2579 } |
2566 | 2580 |
2567 // An extension may override at most one page. | 2581 // An extension may override at most one page. |
2568 if (overrides->size() > 1) { | 2582 if (overrides->size() > 1) { |
2569 *error = ASCIIToUTF16(errors::kMultipleOverrides); | 2583 *error = ASCIIToUTF16(errors::kMultipleOverrides); |
2570 return false; | 2584 return false; |
2571 } | 2585 } |
2572 | 2586 |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3085 return false; | 3099 return false; |
3086 | 3100 |
3087 // Validate minimum Chrome version. We don't need to store this, since the | 3101 // Validate minimum Chrome version. We don't need to store this, since the |
3088 // extension is not valid if it is incorrect | 3102 // extension is not valid if it is incorrect |
3089 if (!CheckMinimumChromeVersion(error)) | 3103 if (!CheckMinimumChromeVersion(error)) |
3090 return false; | 3104 return false; |
3091 | 3105 |
3092 if (!LoadRequiredFeatures(error)) | 3106 if (!LoadRequiredFeatures(error)) |
3093 return false; | 3107 return false; |
3094 | 3108 |
3095 // We don't ned to validate because InitExtensionID already did that. | 3109 // We don't need to validate because InitExtensionID already did that. |
3096 manifest_->GetString(keys::kPublicKey, &public_key_); | 3110 manifest_->GetString(keys::kPublicKey, &public_key_); |
3097 | 3111 |
3098 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); | 3112 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); |
3099 | 3113 |
3100 // Load App settings. LoadExtent at least has to be done before | 3114 // Load App settings. LoadExtent at least has to be done before |
3101 // ParsePermissions(), because the valid permissions depend on what type of | 3115 // ParsePermissions(), because the valid permissions depend on what type of |
3102 // package this is. | 3116 // package this is. |
3103 if (is_app() && !LoadAppFeatures(error)) | 3117 if (is_app() && !LoadAppFeatures(error)) |
3104 return false; | 3118 return false; |
3105 | 3119 |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3870 | 3884 |
3871 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3885 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3872 const Extension* extension, | 3886 const Extension* extension, |
3873 const PermissionSet* permissions, | 3887 const PermissionSet* permissions, |
3874 Reason reason) | 3888 Reason reason) |
3875 : reason(reason), | 3889 : reason(reason), |
3876 extension(extension), | 3890 extension(extension), |
3877 permissions(permissions) {} | 3891 permissions(permissions) {} |
3878 | 3892 |
3879 } // namespace extensions | 3893 } // namespace extensions |
OLD | NEW |