Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/ui/passwords/password_manager_presenter.cc

Issue 2042033003: Displaying human-readable Android credentials on Android OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address minor comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/ui/passwords/password_manager_presenter.h" 5 #include "chrome/browser/ui/passwords/password_manager_presenter.h"
6 6
7 #include <algorithm>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "base/metrics/user_metrics_action.h" 13 #include "base/metrics/user_metrics_action.h"
13 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
14 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
(...skipping 27 matching lines...) Expand all
44 #include "chrome/browser/password_manager/password_manager_util_win.h" 45 #include "chrome/browser/password_manager/password_manager_util_win.h"
45 #elif defined(OS_MACOSX) 46 #elif defined(OS_MACOSX)
46 #include "chrome/browser/password_manager/password_manager_util_mac.h" 47 #include "chrome/browser/password_manager/password_manager_util_mac.h"
47 #endif 48 #endif
48 49
49 using base::StringPiece; 50 using base::StringPiece;
50 using password_manager::PasswordStore; 51 using password_manager::PasswordStore;
51 52
52 namespace { 53 namespace {
53 54
54 const int kAndroidAppSchemeAndDelimiterLength = 10; // Length of 'android://'.
55
56 const char kSortKeyPartsSeparator = ' '; 55 const char kSortKeyPartsSeparator = ' ';
57 56
58 // Reverse order of subdomains in hostname.
59 std::string SplitByDotAndReverse(StringPiece host) {
60 std::vector<std::string> parts =
61 base::SplitString(host, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
62 std::reverse(parts.begin(), parts.end());
63 return base::JoinString(parts, ".");
64 }
65
66 // Helper function that returns the type of the entry (non-Android credentials, 57 // Helper function that returns the type of the entry (non-Android credentials,
67 // Android w/ affiliated web realm (i.e. clickable) or w/o web realm). 58 // Android w/ affiliated web realm (i.e. clickable) or w/o web realm).
68 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) { 59 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) {
69 if (!is_android_uri) 60 if (!is_android_uri)
70 return "0"; 61 return "0";
71 if (is_clickable) 62 if (is_clickable)
72 return "1"; 63 return "1";
73 return "2"; 64 return "2";
74 } 65 }
75 66
76 // Creates key for sorting password or password exception entries. 67 // Creates key for sorting password or password exception entries.
77 // The key is eTLD+1 followed by subdomains 68 // The key is eTLD+1 followed by subdomains
78 // (e.g. secure.accounts.example.com => example.com.accounts.secure). 69 // (e.g. secure.accounts.example.com => example.com.accounts.secure).
79 // If |entry_type == SAVED|, username, password and federation are appended to 70 // If |entry_type == SAVED|, username, password and federation are appended to
80 // the key. The entry type code (non-Android, Android w/ or w/o affiliated web 71 // the key. The entry type code (non-Android, Android w/ or w/o affiliated web
81 // realm) is also appended to the key. 72 // realm) is also appended to the key.
82 std::string CreateSortKey(const autofill::PasswordForm& form, 73 std::string CreateSortKey(const autofill::PasswordForm& form,
83 PasswordEntryType entry_type) { 74 PasswordEntryType entry_type) {
84 bool is_android_uri = false; 75 bool is_android_uri = false;
85 bool is_clickable = false; 76 bool is_clickable = false;
86 GURL link_url; 77 GURL link_url;
87 std::string origin = password_manager::GetShownOriginAndLinkUrl( 78 std::string origin = password_manager::GetShownOriginAndLinkUrl(
88 form, &is_android_uri, &link_url, &is_clickable); 79 form, &is_android_uri, &link_url, &is_clickable);
89 80
90 if (!is_clickable) { // e.g. android://com.example.r => r.example.com. 81 if (!is_clickable) { // e.g. android://com.example.r => r.example.com.
91 origin = SplitByDotAndReverse( 82 origin = password_manager::StripAndroidAndReverse(origin);
92 StringPiece(&origin[kAndroidAppSchemeAndDelimiterLength],
93 origin.length() - kAndroidAppSchemeAndDelimiterLength));
94 } 83 }
95 84
96 std::string site_name = 85 std::string site_name =
97 net::registry_controlled_domains::GetDomainAndRegistry( 86 net::registry_controlled_domains::GetDomainAndRegistry(
98 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 87 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
99 if (site_name.empty()) // e.g. localhost. 88 if (site_name.empty()) // e.g. localhost.
100 site_name = origin; 89 site_name = origin;
101 std::string key = 90 std::string key =
102 site_name + SplitByDotAndReverse(StringPiece( 91 site_name + password_manager::SplitByDotAndReverse(StringPiece(
103 &origin[0], origin.length() - site_name.length())); 92 &origin[0], origin.length() - site_name.length()));
104 93
105 if (entry_type == PasswordEntryType::SAVED) { 94 if (entry_type == PasswordEntryType::SAVED) {
106 key = key + kSortKeyPartsSeparator + 95 key = key + kSortKeyPartsSeparator +
107 base::UTF16ToUTF8(form.username_value) + kSortKeyPartsSeparator + 96 base::UTF16ToUTF8(form.username_value) + kSortKeyPartsSeparator +
108 base::UTF16ToUTF8(form.password_value); 97 base::UTF16ToUTF8(form.password_value);
109 if (!form.federation_origin.unique()) 98 if (!form.federation_origin.unique())
110 key = key + kSortKeyPartsSeparator + form.federation_origin.host(); 99 key = key + kSortKeyPartsSeparator + form.federation_origin.host();
111 } 100 }
112 101
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 387
399 void PasswordManagerPresenter::PasswordExceptionListPopulater:: 388 void PasswordManagerPresenter::PasswordExceptionListPopulater::
400 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { 389 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) {
401 page_->password_exception_list_ = 390 page_->password_exception_list_ =
402 password_manager_util::ConvertScopedVector(std::move(results)); 391 password_manager_util::ConvertScopedVector(std::move(results));
403 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, 392 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_,
404 &page_->password_exception_duplicates_, 393 &page_->password_exception_duplicates_,
405 PasswordEntryType::BLACKLISTED); 394 PasswordEntryType::BLACKLISTED);
406 page_->SetPasswordExceptionList(); 395 page_->SetPasswordExceptionList();
407 } 396 }
OLDNEW
« no previous file with comments | « chrome/browser/android/password_ui_view_android.cc ('k') | components/password_manager/core/browser/password_ui_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698