OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/password_manager/core/browser/affiliation_utils.h" | |
6 | |
7 #include "base/strings/string_util.h" | |
8 #include "url/gurl.h" | |
9 #include "url/third_party/mozilla/url_parse.h" | |
10 | |
11 namespace password_manager { | |
12 | |
13 const char kAndroidAppScheme[] = "android"; | |
14 | |
15 bool IsValidFacetURI(const std::string& uri) { | |
16 return IsValidWebFacetURI(uri) || IsValidAndroidFacetURI(uri); | |
17 } | |
18 | |
19 bool IsValidWebFacetURI(const std::string& uri) { | |
20 url::Parsed url_parsed; | |
21 url::ParseStandardURL(uri.c_str(), uri.size(), &url_parsed); | |
Mike West
2014/12/02 16:33:06
Why parse this manually? Wouldn't it be easier to
engedy
2014/12/02 19:24:55
Using the GURL constructor is doable, but rather h
| |
22 return url_parsed.scheme.is_nonempty() && | |
23 LowerCaseEqualsASCII(&uri[url_parsed.scheme.begin], | |
24 &uri[url_parsed.scheme.end()], | |
25 url::kHttpsScheme) && | |
26 !url_parsed.username.is_valid() && !url_parsed.password.is_valid() && | |
27 url_parsed.host.is_nonempty() && url_parsed.path.is_nonempty() && | |
28 url_parsed.path.len == 1 && uri[url_parsed.path.begin] == '/' && | |
29 !url_parsed.query.is_valid() && !url_parsed.ref.is_valid(); | |
30 } | |
31 | |
32 bool IsValidAndroidFacetURI(const std::string& uri) { | |
33 // Treat URIs with the "android" scheme as standard URLs, so the APK hash will | |
34 // be treated as a username. | |
35 url::Parsed url_parsed; | |
36 url::ParseStandardURL(uri.c_str(), uri.size(), &url_parsed); | |
Mike West
2014/12/02 16:33:06
Ditto.
engedy
2014/12/02 19:24:55
This is, actually, different, see my comment in th
| |
37 return url_parsed.scheme.is_nonempty() && | |
38 LowerCaseEqualsASCII(&uri[url_parsed.scheme.begin], | |
39 &uri[url_parsed.scheme.end()], | |
40 kAndroidAppScheme) && | |
41 url_parsed.username.is_nonempty() && !url_parsed.password.is_valid() && | |
42 url_parsed.host.is_nonempty() && !url_parsed.port.is_valid() && | |
43 url_parsed.path.is_nonempty() && url_parsed.path.len == 1 && | |
44 uri[url_parsed.path.begin] == '/' && !url_parsed.query.is_valid() && | |
45 !url_parsed.ref.is_valid(); | |
46 } | |
47 | |
48 bool AreEquivalenceClassesEqual(const AffiliatedFacets& a, | |
49 const AffiliatedFacets& b) { | |
50 if (a.size() != b.size()) | |
51 return false; | |
52 | |
53 std::vector<std::string> a_sorted(a.begin(), a.end()); | |
54 std::vector<std::string> b_sorted(b.begin(), b.end()); | |
55 std::sort(a_sorted.begin(), a_sorted.end()); | |
Mike West
2014/12/02 16:33:06
Hrm. Where do you intend to call this equality met
engedy
2014/12/02 19:24:55
I am not too worried about this, as most equivalen
| |
56 std::sort(b_sorted.begin(), b_sorted.end()); | |
57 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); | |
58 } | |
59 | |
60 } // namespace password_manager | |
OLD | NEW |