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> |
| 8 |
| 9 #include "base/stl_util.h" |
7 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
8 #include "chrome/common/extensions/api/manifest_types.h" | 11 #include "chrome/common/extensions/api/manifest_types.h" |
9 #include "chrome/common/extensions/extension_manifest_constants.h" | 12 #include "chrome/common/extensions/extension_manifest_constants.h" |
10 #include "extensions/common/error_utils.h" | 13 #include "extensions/common/error_utils.h" |
11 #include "extensions/common/url_pattern.h" | 14 #include "extensions/common/url_pattern.h" |
12 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
13 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
14 | 17 |
15 namespace rcd = net::registry_controlled_domains; | 18 namespace rcd = net::registry_controlled_domains; |
16 | 19 |
17 namespace extensions { | 20 namespace extensions { |
18 | 21 |
19 namespace externally_connectable_errors { | 22 namespace externally_connectable_errors { |
20 const char kErrorInvalid[] = "Invalid value for 'externally_connectable'"; | 23 const char kErrorInvalid[] = "Invalid value for 'externally_connectable'"; |
21 const char kErrorInvalidMatchPattern[] = "Invalid match pattern '*'"; | 24 const char kErrorInvalidMatchPattern[] = "Invalid match pattern '*'"; |
22 const char kErrorInvalidId[] = "Invalid ID '*'"; | 25 const char kErrorInvalidId[] = "Invalid ID '*'"; |
23 const char kErrorTopLevelDomainsNotAllowed[] = | 26 const char kErrorTopLevelDomainsNotAllowed[] = |
24 "\"*\" is an effective top level domain for which wildcard subdomains such " | 27 "\"*\" is an effective top level domain for which wildcard subdomains such " |
25 "as \"*\" are not allowed"; | 28 "as \"*\" are not allowed"; |
26 const char kErrorWildcardHostsNotAllowed[] = | 29 const char kErrorWildcardHostsNotAllowed[] = |
27 "Wildcard domain patterns such as \"*\" are not allowed"; | 30 "Wildcard domain patterns such as \"*\" are not allowed"; |
28 } | 31 } |
29 | 32 |
30 namespace keys = extension_manifest_keys; | 33 namespace keys = extension_manifest_keys; |
31 namespace errors = externally_connectable_errors; | 34 namespace errors = externally_connectable_errors; |
32 using api::manifest_types::ExternallyConnectable; | 35 using api::manifest_types::ExternallyConnectable; |
33 | 36 |
34 namespace { | 37 namespace { |
| 38 |
35 const char kAllIds[] = "*"; | 39 const char kAllIds[] = "*"; |
| 40 |
| 41 template <typename T> |
| 42 std::vector<T> Sorted(const std::vector<T>& in) { |
| 43 std::vector<T> out = in; |
| 44 std::sort(out.begin(), out.end()); |
| 45 return out; |
| 46 } |
| 47 |
36 } | 48 } |
37 | 49 |
38 ExternallyConnectableHandler::ExternallyConnectableHandler() {} | 50 ExternallyConnectableHandler::ExternallyConnectableHandler() {} |
39 | 51 |
40 ExternallyConnectableHandler::~ExternallyConnectableHandler() {} | 52 ExternallyConnectableHandler::~ExternallyConnectableHandler() {} |
41 | 53 |
42 bool ExternallyConnectableHandler::Parse(Extension* extension, | 54 bool ExternallyConnectableHandler::Parse(Extension* extension, |
43 string16* error) { | 55 string16* error) { |
44 const base::Value* externally_connectable = NULL; | 56 const base::Value* externally_connectable = NULL; |
45 CHECK(extension->manifest()->Get(keys::kExternallyConnectable, | 57 CHECK(extension->manifest()->Get(keys::kExternallyConnectable, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 return make_scoped_ptr( | 162 return make_scoped_ptr( |
151 new ExternallyConnectableInfo(matches, ids, matches_all_ids)); | 163 new ExternallyConnectableInfo(matches, ids, matches_all_ids)); |
152 } | 164 } |
153 | 165 |
154 ExternallyConnectableInfo::~ExternallyConnectableInfo() {} | 166 ExternallyConnectableInfo::~ExternallyConnectableInfo() {} |
155 | 167 |
156 ExternallyConnectableInfo::ExternallyConnectableInfo( | 168 ExternallyConnectableInfo::ExternallyConnectableInfo( |
157 const URLPatternSet& matches, | 169 const URLPatternSet& matches, |
158 const std::vector<std::string>& ids, | 170 const std::vector<std::string>& ids, |
159 bool matches_all_ids) | 171 bool matches_all_ids) |
160 : matches(matches), ids(ids), matches_all_ids(matches_all_ids) {} | 172 : matches(matches), ids(Sorted(ids)), matches_all_ids(matches_all_ids) {} |
| 173 |
| 174 bool ExternallyConnectableInfo::MatchesIdOrAllIds(const std::string& id) { |
| 175 if (matches_all_ids) |
| 176 return true; |
| 177 DCHECK(base::STLIsSorted(ids)); |
| 178 return std::binary_search(ids.begin(), ids.end(), id); |
| 179 } |
161 | 180 |
162 } // namespace extensions | 181 } // namespace extensions |
OLD | NEW |