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 supported_schemes |= URLPattern::SCHEME_HTTP; | |
not at google - send to devlin
2014/12/10 17:33:54
Mention why (... and shame there is no https mode
Ken Rockot(use gerrit already)
2014/12/10 18:31:41
Heh. Done.
| |
70 } | |
71 | |
64 std::string url_error; | 72 std::string url_error; |
65 URLPatternSet potential_url_patterns; | 73 URLPatternSet potential_url_patterns; |
66 if (!potential_url_patterns.Populate(capabilities->matches, | 74 if (!potential_url_patterns.Populate(capabilities->matches, |
67 URLPattern::SCHEME_HTTPS, false /* allow_file_access */, | 75 supported_schemes, false /* allow_file_access */, |
68 &url_error)) { | 76 &url_error)) { |
69 *error = ErrorUtils::FormatErrorMessageUTF16( | 77 *error = ErrorUtils::FormatErrorMessageUTF16( |
70 errors::kInvalidContentCapabilitiesMatch, url_error); | 78 errors::kInvalidContentCapabilitiesMatch, url_error); |
71 return false; | 79 return false; |
72 } | 80 } |
73 | 81 |
74 // Filter wildcard URL patterns and emit warnings for them. | 82 // Filter wildcard URL patterns and emit warnings for them. |
75 std::set<URLPattern> valid_url_patterns; | 83 std::set<URLPattern> valid_url_patterns; |
76 for (const URLPattern& pattern : potential_url_patterns) { | 84 for (const URLPattern& pattern : potential_url_patterns) { |
77 if (pattern.match_subdomains() || pattern.ImpliesAllHosts()) { | 85 if (pattern.match_subdomains() || pattern.ImpliesAllHosts()) { |
(...skipping 22 matching lines...) Expand all Loading... | |
100 extension->SetManifestData(keys::kContentCapabilities, info.release()); | 108 extension->SetManifestData(keys::kContentCapabilities, info.release()); |
101 return true; | 109 return true; |
102 } | 110 } |
103 | 111 |
104 const std::vector<std::string> ContentCapabilitiesHandler::Keys() | 112 const std::vector<std::string> ContentCapabilitiesHandler::Keys() |
105 const { | 113 const { |
106 return SingleKey(keys::kContentCapabilities); | 114 return SingleKey(keys::kContentCapabilities); |
107 } | 115 } |
108 | 116 |
109 } // namespace extensions | 117 } // namespace extensions |
OLD | NEW |