| 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" |
| 11 #include "chrome/common/extensions/api/manifest_types.h" | 11 #include "chrome/common/extensions/api/manifest_types.h" |
| 12 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 13 #include "chrome/common/extensions/permissions/api_permission_set.h" | 12 #include "chrome/common/extensions/permissions/api_permission_set.h" |
| 14 #include "chrome/common/extensions/permissions/permissions_data.h" | 13 #include "chrome/common/extensions/permissions/permissions_data.h" |
| 15 #include "extensions/common/error_utils.h" | 14 #include "extensions/common/error_utils.h" |
| 15 #include "extensions/common/manifest_constants.h" |
| 16 #include "extensions/common/url_pattern.h" | 16 #include "extensions/common/url_pattern.h" |
| 17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 namespace rcd = net::registry_controlled_domains; | 20 namespace rcd = net::registry_controlled_domains; |
| 21 | 21 |
| 22 namespace extensions { | 22 namespace extensions { |
| 23 | 23 |
| 24 namespace externally_connectable_errors { | 24 namespace externally_connectable_errors { |
| 25 const char kErrorInvalid[] = "Invalid value for 'externally_connectable'"; | 25 const char kErrorInvalid[] = "Invalid value for 'externally_connectable'"; |
| 26 const char kErrorInvalidMatchPattern[] = "Invalid match pattern '*'"; | 26 const char kErrorInvalidMatchPattern[] = "Invalid match pattern '*'"; |
| 27 const char kErrorInvalidId[] = "Invalid ID '*'"; | 27 const char kErrorInvalidId[] = "Invalid ID '*'"; |
| 28 const char kErrorNothingSpecified[] = | 28 const char kErrorNothingSpecified[] = |
| 29 "'externally_connectable' specifies neither 'matches' nor 'ids'; " | 29 "'externally_connectable' specifies neither 'matches' nor 'ids'; " |
| 30 "nothing will be able to connect"; | 30 "nothing will be able to connect"; |
| 31 const char kErrorTopLevelDomainsNotAllowed[] = | 31 const char kErrorTopLevelDomainsNotAllowed[] = |
| 32 "\"*\" is an effective top level domain for which wildcard subdomains such " | 32 "\"*\" is an effective top level domain for which wildcard subdomains such " |
| 33 "as \"*\" are not allowed"; | 33 "as \"*\" are not allowed"; |
| 34 const char kErrorWildcardHostsNotAllowed[] = | 34 const char kErrorWildcardHostsNotAllowed[] = |
| 35 "Wildcard domain patterns such as \"*\" are not allowed"; | 35 "Wildcard domain patterns such as \"*\" are not allowed"; |
| 36 } // namespace externally_connectable_errors | 36 } // namespace externally_connectable_errors |
| 37 | 37 |
| 38 namespace keys = extension_manifest_keys; | 38 namespace keys = extensions::manifest_keys; |
| 39 namespace errors = externally_connectable_errors; | 39 namespace errors = externally_connectable_errors; |
| 40 using api::manifest_types::ExternallyConnectable; | 40 using api::manifest_types::ExternallyConnectable; |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 const char kAllIds[] = "*"; | 44 const char kAllIds[] = "*"; |
| 45 | 45 |
| 46 template <typename T> | 46 template <typename T> |
| 47 std::vector<T> Sorted(const std::vector<T>& in) { | 47 std::vector<T> Sorted(const std::vector<T>& in) { |
| 48 std::vector<T> out = in; | 48 std::vector<T> out = in; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 : matches(matches), ids(Sorted(ids)), all_ids(all_ids) {} | 196 : matches(matches), ids(Sorted(ids)), all_ids(all_ids) {} |
| 197 | 197 |
| 198 bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) { | 198 bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) { |
| 199 if (all_ids) | 199 if (all_ids) |
| 200 return true; | 200 return true; |
| 201 DCHECK(base::STLIsSorted(ids)); | 201 DCHECK(base::STLIsSorted(ids)); |
| 202 return std::binary_search(ids.begin(), ids.end(), id); | 202 return std::binary_search(ids.begin(), ids.end(), id); |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace extensions | 205 } // namespace extensions |
| OLD | NEW |