Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / components / password_manager / core / browser / psl_matching_helper.cc
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
3 // found in the LICENSE file.
4
5 #include "components/password_manager/core/browser/psl_matching_helper.h"
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "components/autofill/core/common/password_form.h"
11 #include "components/password_manager/core/common/password_manager_switches.h"
12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
13 #include "url/gurl.h"
14
15 using autofill::PasswordForm;
16
17 namespace password_manager {
18
19 bool ShouldPSLDomainMatchingApply(
20     const std::string& registry_controlled_domain) {
21   return registry_controlled_domain != "google.com";
22 }
23
24 bool IsPublicSuffixDomainMatch(const std::string& url1,
25                                const std::string& url2) {
26   GURL gurl1(url1);
27   GURL gurl2(url2);
28
29   if (!gurl1.is_valid() || !gurl2.is_valid())
30     return false;
31
32   return gurl1.scheme() == gurl2.scheme() &&
33          GetRegistryControlledDomain(gurl1) ==
34              GetRegistryControlledDomain(gurl2) &&
35          gurl1.port() == gurl2.port();
36 }
37
38 std::string GetRegistryControlledDomain(const GURL& signon_realm) {
39   return net::registry_controlled_domains::GetDomainAndRegistry(
40       signon_realm,
41       net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
42 }
43
44 }  // namespace password_manager