| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/manifest_handlers/externally_connectable.h" | 5 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 URLPattern pattern(URLPattern::SCHEME_ALL); | 111 URLPattern pattern(URLPattern::SCHEME_ALL); |
| 112 if (pattern.Parse(*it) != URLPattern::PARSE_SUCCESS) { | 112 if (pattern.Parse(*it) != URLPattern::PARSE_SUCCESS) { |
| 113 *error = ErrorUtils::FormatErrorMessageUTF16( | 113 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 114 errors::kErrorInvalidMatchPattern, *it); | 114 errors::kErrorInvalidMatchPattern, *it); |
| 115 return scoped_ptr<ExternallyConnectableInfo>(); | 115 return scoped_ptr<ExternallyConnectableInfo>(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Wildcard hosts are not allowed. | 118 // Wildcard hosts are not allowed. |
| 119 if (pattern.host().empty()) { | 119 if (pattern.host().empty()) { |
| 120 // Warning not error for forwards compatibility. | 120 // Warning not error for forwards compatibility. |
| 121 install_warnings->push_back( | 121 install_warnings->push_back(InstallWarning( |
| 122 InstallWarning::Text(ErrorUtils::FormatErrorMessage( | 122 keys::kExternallyConnectable, |
| 123 *it, |
| 124 ErrorUtils::FormatErrorMessage( |
| 123 errors::kErrorWildcardHostsNotAllowed, *it))); | 125 errors::kErrorWildcardHostsNotAllowed, *it))); |
| 124 continue; | 126 continue; |
| 125 } | 127 } |
| 126 | 128 |
| 127 // Wildcards on subdomains of a TLD are not allowed. | 129 // Wildcards on subdomains of a TLD are not allowed. |
| 128 size_t registry_length = rcd::GetRegistryLength( | 130 size_t registry_length = rcd::GetRegistryLength( |
| 129 pattern.host(), | 131 pattern.host(), |
| 130 // This means that things that look like TLDs - the foobar in | 132 // This means that things that look like TLDs - the foobar in |
| 131 // http://google.foobar - count as TLDs. | 133 // http://google.foobar - count as TLDs. |
| 132 rcd::INCLUDE_UNKNOWN_REGISTRIES, | 134 rcd::INCLUDE_UNKNOWN_REGISTRIES, |
| 133 // This means that effective TLDs like appspot.com count as TLDs; | 135 // This means that effective TLDs like appspot.com count as TLDs; |
| 134 // codereview.appspot.com and evil.appspot.com are different. | 136 // codereview.appspot.com and evil.appspot.com are different. |
| 135 rcd::INCLUDE_PRIVATE_REGISTRIES); | 137 rcd::INCLUDE_PRIVATE_REGISTRIES); |
| 136 | 138 |
| 137 if (registry_length == std::string::npos) { | 139 if (registry_length == std::string::npos) { |
| 138 // The URL parsing combined with host().empty() should have caught this. | 140 // The URL parsing combined with host().empty() should have caught this. |
| 139 NOTREACHED() << *it; | 141 NOTREACHED() << *it; |
| 140 *error = ErrorUtils::FormatErrorMessageUTF16( | 142 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 141 errors::kErrorInvalidMatchPattern, *it); | 143 errors::kErrorInvalidMatchPattern, *it); |
| 142 return scoped_ptr<ExternallyConnectableInfo>(); | 144 return scoped_ptr<ExternallyConnectableInfo>(); |
| 143 } | 145 } |
| 144 | 146 |
| 145 // Broad match patterns like "*.com", "*.co.uk", and even "*.appspot.com" | 147 // Broad match patterns like "*.com", "*.co.uk", and even "*.appspot.com" |
| 146 // are not allowed. However just "appspot.com" is ok. | 148 // are not allowed. However just "appspot.com" is ok. |
| 147 if (registry_length == 0 && pattern.match_subdomains()) { | 149 if (registry_length == 0 && pattern.match_subdomains()) { |
| 148 // Warning not error for forwards compatibility. | 150 // Warning not error for forwards compatibility. |
| 149 install_warnings->push_back(InstallWarning::Text( | 151 install_warnings->push_back(InstallWarning( |
| 152 keys::kExternallyConnectable, |
| 153 *it, |
| 150 ErrorUtils::FormatErrorMessage( | 154 ErrorUtils::FormatErrorMessage( |
| 151 errors::kErrorTopLevelDomainsNotAllowed, | 155 errors::kErrorTopLevelDomainsNotAllowed, |
| 152 pattern.host().c_str(), | 156 pattern.host().c_str(), |
| 153 *it))); | 157 *it))); |
| 154 continue; | 158 continue; |
| 155 } | 159 } |
| 156 | 160 |
| 157 matches.AddPattern(pattern); | 161 matches.AddPattern(pattern); |
| 158 } | 162 } |
| 159 } | 163 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 172 } else { | 176 } else { |
| 173 *error = ErrorUtils::FormatErrorMessageUTF16( | 177 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 174 errors::kErrorInvalidId, *it); | 178 errors::kErrorInvalidId, *it); |
| 175 return scoped_ptr<ExternallyConnectableInfo>(); | 179 return scoped_ptr<ExternallyConnectableInfo>(); |
| 176 } | 180 } |
| 177 } | 181 } |
| 178 } | 182 } |
| 179 | 183 |
| 180 if (!externally_connectable->matches && | 184 if (!externally_connectable->matches && |
| 181 !externally_connectable->ids) { | 185 !externally_connectable->ids) { |
| 182 install_warnings->push_back(InstallWarning::Text( | 186 install_warnings->push_back(InstallWarning( |
| 187 keys::kExternallyConnectable, |
| 183 errors::kErrorNothingSpecified)); | 188 errors::kErrorNothingSpecified)); |
| 184 } | 189 } |
| 185 | 190 |
| 186 return make_scoped_ptr( | 191 return make_scoped_ptr( |
| 187 new ExternallyConnectableInfo(matches, ids, all_ids)); | 192 new ExternallyConnectableInfo(matches, ids, all_ids)); |
| 188 } | 193 } |
| 189 | 194 |
| 190 ExternallyConnectableInfo::~ExternallyConnectableInfo() {} | 195 ExternallyConnectableInfo::~ExternallyConnectableInfo() {} |
| 191 | 196 |
| 192 ExternallyConnectableInfo::ExternallyConnectableInfo( | 197 ExternallyConnectableInfo::ExternallyConnectableInfo( |
| 193 const URLPatternSet& matches, | 198 const URLPatternSet& matches, |
| 194 const std::vector<std::string>& ids, | 199 const std::vector<std::string>& ids, |
| 195 bool all_ids) | 200 bool all_ids) |
| 196 : matches(matches), ids(Sorted(ids)), all_ids(all_ids) {} | 201 : matches(matches), ids(Sorted(ids)), all_ids(all_ids) {} |
| 197 | 202 |
| 198 bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) { | 203 bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) { |
| 199 if (all_ids) | 204 if (all_ids) |
| 200 return true; | 205 return true; |
| 201 DCHECK(base::STLIsSorted(ids)); | 206 DCHECK(base::STLIsSorted(ids)); |
| 202 return std::binary_search(ids.begin(), ids.end(), id); | 207 return std::binary_search(ids.begin(), ids.end(), id); |
| 203 } | 208 } |
| 204 | 209 |
| 205 } // namespace extensions | 210 } // namespace extensions |
| OLD | NEW |