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/externally_connectable.h" | 5 #include "extensions/common/manifest_handlers/externally_connectable.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "components/crx_file/id_util.h" | 15 #include "components/crx_file/id_util.h" |
16 #include "extensions/common/api/extensions_manifest_types.h" | 16 #include "extensions/common/api/extensions_manifest_types.h" |
17 #include "extensions/common/error_utils.h" | 17 #include "extensions/common/error_utils.h" |
18 #include "extensions/common/manifest_constants.h" | 18 #include "extensions/common/manifest_constants.h" |
19 #include "extensions/common/manifest_handlers/permissions_parser.h" | 19 #include "extensions/common/manifest_handlers/permissions_parser.h" |
20 #include "extensions/common/permissions/api_permission_set.h" | 20 #include "extensions/common/permissions/api_permission_set.h" |
21 #include "extensions/common/url_pattern.h" | 21 #include "extensions/common/url_pattern.h" |
22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
23 #include "net/base/url_util.h" | |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
24 | 25 |
25 namespace rcd = net::registry_controlled_domains; | 26 namespace rcd = net::registry_controlled_domains; |
26 | 27 |
27 namespace extensions { | 28 namespace extensions { |
28 | 29 |
29 namespace externally_connectable_errors { | 30 namespace externally_connectable_errors { |
30 const char kErrorInvalidMatchPattern[] = "Invalid match pattern '*'"; | 31 const char kErrorInvalidMatchPattern[] = "Invalid match pattern '*'"; |
31 const char kErrorInvalidId[] = "Invalid ID '*'"; | 32 const char kErrorInvalidId[] = "Invalid ID '*'"; |
32 const char kErrorNothingSpecified[] = | 33 const char kErrorNothingSpecified[] = |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 if (pattern.host().empty()) { | 133 if (pattern.host().empty()) { |
133 // Warning not error for forwards compatibility. | 134 // Warning not error for forwards compatibility. |
134 install_warnings->push_back( | 135 install_warnings->push_back( |
135 InstallWarning(ErrorUtils::FormatErrorMessage( | 136 InstallWarning(ErrorUtils::FormatErrorMessage( |
136 errors::kErrorWildcardHostsNotAllowed, *it), | 137 errors::kErrorWildcardHostsNotAllowed, *it), |
137 keys::kExternallyConnectable, | 138 keys::kExternallyConnectable, |
138 *it)); | 139 *it)); |
139 continue; | 140 continue; |
140 } | 141 } |
141 | 142 |
143 url::CanonHostInfo host_info; | |
brettw
2016/10/19 20:16:36
This is changed around a bit because it wanted to
| |
144 std::string canonical_host = | |
145 net::CanonicalizeHost(pattern.host(), &host_info); | |
146 if (canonical_host.empty()) { | |
147 // CanonicalizeHost returns empty string on error. The URL parsing | |
148 // combined with host().empty() should have caught this above. | |
149 NOTREACHED() << *it; | |
150 *error = ErrorUtils::FormatErrorMessageUTF16( | |
151 errors::kErrorInvalidMatchPattern, *it); | |
152 return std::unique_ptr<ExternallyConnectableInfo>(); | |
153 } | |
154 | |
142 // Wildcards on subdomains of a TLD are not allowed. | 155 // Wildcards on subdomains of a TLD are not allowed. |
143 size_t registry_length = rcd::GetRegistryLength( | 156 bool has_registry = rcd::HostHasRegistryControlledDomain( |
144 pattern.host(), | 157 canonical_host, |
145 // This means that things that look like TLDs - the foobar in | 158 // This means that things that look like TLDs - the foobar in |
146 // http://google.foobar - count as TLDs. | 159 // http://google.foobar - count as TLDs. |
147 rcd::INCLUDE_UNKNOWN_REGISTRIES, | 160 rcd::INCLUDE_UNKNOWN_REGISTRIES, |
148 // This means that effective TLDs like appspot.com count as TLDs; | 161 // This means that effective TLDs like appspot.com count as TLDs; |
149 // codereview.appspot.com and evil.appspot.com are different. | 162 // codereview.appspot.com and evil.appspot.com are different. |
150 rcd::INCLUDE_PRIVATE_REGISTRIES); | 163 rcd::INCLUDE_PRIVATE_REGISTRIES); |
151 | 164 |
152 if (registry_length == std::string::npos) { | |
153 // The URL parsing combined with host().empty() should have caught this. | |
154 NOTREACHED() << *it; | |
155 *error = ErrorUtils::FormatErrorMessageUTF16( | |
156 errors::kErrorInvalidMatchPattern, *it); | |
157 return std::unique_ptr<ExternallyConnectableInfo>(); | |
158 } | |
159 | |
160 // Broad match patterns like "*.com", "*.co.uk", and even "*.appspot.com" | 165 // Broad match patterns like "*.com", "*.co.uk", and even "*.appspot.com" |
161 // are not allowed. However just "appspot.com" is ok. | 166 // are not allowed. However just "appspot.com" is ok. |
162 if (registry_length == 0 && pattern.match_subdomains()) { | 167 if (!has_registry && pattern.match_subdomains()) { |
163 // Warning not error for forwards compatibility. | 168 // Warning not error for forwards compatibility. |
164 install_warnings->push_back( | 169 install_warnings->push_back( |
165 InstallWarning(ErrorUtils::FormatErrorMessage( | 170 InstallWarning(ErrorUtils::FormatErrorMessage( |
166 errors::kErrorTopLevelDomainsNotAllowed, | 171 errors::kErrorTopLevelDomainsNotAllowed, |
167 pattern.host().c_str(), | 172 pattern.host().c_str(), |
168 *it), | 173 *it), |
169 keys::kExternallyConnectable, | 174 keys::kExternallyConnectable, |
170 *it)); | 175 *it)); |
171 continue; | 176 continue; |
172 } | 177 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 } | 227 } |
223 | 228 |
224 bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) { | 229 bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) { |
225 if (all_ids) | 230 if (all_ids) |
226 return true; | 231 return true; |
227 DCHECK(base::STLIsSorted(ids)); | 232 DCHECK(base::STLIsSorted(ids)); |
228 return std::binary_search(ids.begin(), ids.end(), id); | 233 return std::binary_search(ids.begin(), ids.end(), id); |
229 } | 234 } |
230 | 235 |
231 } // namespace extensions | 236 } // namespace extensions |
OLD | NEW |