OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/common/manifest_handlers/content_capabilities_handler.h" | 5 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "content/public/common/content_switches.h" |
12 #include "extensions/common/api/extensions_manifest_types.h" | 14 #include "extensions/common/api/extensions_manifest_types.h" |
13 #include "extensions/common/error_utils.h" | 15 #include "extensions/common/error_utils.h" |
14 #include "extensions/common/install_warning.h" | 16 #include "extensions/common/install_warning.h" |
15 #include "extensions/common/manifest_constants.h" | 17 #include "extensions/common/manifest_constants.h" |
16 #include "extensions/common/permissions/permissions_info.h" | 18 #include "extensions/common/permissions/permissions_info.h" |
17 #include "extensions/common/url_pattern.h" | 19 #include "extensions/common/url_pattern.h" |
18 | 20 |
19 namespace extensions { | 21 namespace extensions { |
20 | 22 |
21 namespace keys = manifest_keys; | 23 namespace keys = manifest_keys; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 if (!extension->manifest()->Get(keys::kContentCapabilities, &value)) { | 56 if (!extension->manifest()->Get(keys::kContentCapabilities, &value)) { |
55 *error = base::ASCIIToUTF16(errors::kInvalidContentCapabilities); | 57 *error = base::ASCIIToUTF16(errors::kInvalidContentCapabilities); |
56 return false; | 58 return false; |
57 } | 59 } |
58 | 60 |
59 scoped_ptr<ContentCapabilities> capabilities(ContentCapabilities::FromValue( | 61 scoped_ptr<ContentCapabilities> capabilities(ContentCapabilities::FromValue( |
60 *value, error)); | 62 *value, error)); |
61 if (!capabilities) | 63 if (!capabilities) |
62 return false; | 64 return false; |
63 | 65 |
| 66 int supported_schemes = URLPattern::SCHEME_HTTPS; |
| 67 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 68 switches::kTestType)) { |
| 69 // We don't have a suitable HTTPS test server, so this will have to do. |
| 70 supported_schemes |= URLPattern::SCHEME_HTTP; |
| 71 } |
| 72 |
64 std::string url_error; | 73 std::string url_error; |
65 URLPatternSet potential_url_patterns; | 74 URLPatternSet potential_url_patterns; |
66 if (!potential_url_patterns.Populate(capabilities->matches, | 75 if (!potential_url_patterns.Populate(capabilities->matches, |
67 URLPattern::SCHEME_HTTPS, false /* allow_file_access */, | 76 supported_schemes, false /* allow_file_access */, |
68 &url_error)) { | 77 &url_error)) { |
69 *error = ErrorUtils::FormatErrorMessageUTF16( | 78 *error = ErrorUtils::FormatErrorMessageUTF16( |
70 errors::kInvalidContentCapabilitiesMatch, url_error); | 79 errors::kInvalidContentCapabilitiesMatch, url_error); |
71 return false; | 80 return false; |
72 } | 81 } |
73 | 82 |
74 // Filter wildcard URL patterns and emit warnings for them. | 83 // Filter wildcard URL patterns and emit warnings for them. |
75 std::set<URLPattern> valid_url_patterns; | 84 std::set<URLPattern> valid_url_patterns; |
76 for (const URLPattern& pattern : potential_url_patterns) { | 85 for (const URLPattern& pattern : potential_url_patterns) { |
77 if (pattern.match_subdomains() || pattern.ImpliesAllHosts()) { | 86 if (pattern.match_subdomains() || pattern.ImpliesAllHosts()) { |
(...skipping 22 matching lines...) Expand all Loading... |
100 extension->SetManifestData(keys::kContentCapabilities, info.release()); | 109 extension->SetManifestData(keys::kContentCapabilities, info.release()); |
101 return true; | 110 return true; |
102 } | 111 } |
103 | 112 |
104 const std::vector<std::string> ContentCapabilitiesHandler::Keys() | 113 const std::vector<std::string> ContentCapabilitiesHandler::Keys() |
105 const { | 114 const { |
106 return SingleKey(keys::kContentCapabilities); | 115 return SingleKey(keys::kContentCapabilities); |
107 } | 116 } |
108 | 117 |
109 } // namespace extensions | 118 } // namespace extensions |
OLD | NEW |