File: password_dialog_controller_impl.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (177 lines) | stat: -rw-r--r-- 6,456 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/passwords/password_dialog_controller_impl.h"

#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/passwords/password_dialog_prompts.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate.h"
#include "chrome/grit/generated_resources.h"
#include "components/autofill/core/common/password_form.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "ui/base/l10n/l10n_util.h"

namespace {

bool IsSmartLockBrandingEnabled(Profile* profile) {
  const browser_sync::ProfileSyncService* sync_service =
      ProfileSyncServiceFactory::GetForProfile(profile);
  return password_bubble_experiment::IsSmartLockUser(sync_service);
}

}  // namespace

PasswordDialogControllerImpl::PasswordDialogControllerImpl(
    Profile* profle,
    PasswordsModelDelegate* delegate)
    : profile_(profle),
      delegate_(delegate),
      account_chooser_dialog_(nullptr),
      autosignin_dialog_(nullptr) {
}

PasswordDialogControllerImpl::~PasswordDialogControllerImpl() {
  ResetDialog();
}

void PasswordDialogControllerImpl::ShowAccountChooser(
    AccountChooserPrompt* dialog,
    std::vector<std::unique_ptr<autofill::PasswordForm>> locals) {
  DCHECK(!account_chooser_dialog_);
  DCHECK(!autosignin_dialog_);
  DCHECK(dialog);
  local_credentials_.swap(locals);
  account_chooser_dialog_ = dialog;
  account_chooser_dialog_->ShowAccountChooser();
}

void PasswordDialogControllerImpl::ShowAutosigninPrompt(
    AutoSigninFirstRunPrompt* dialog) {
  DCHECK(!account_chooser_dialog_);
  DCHECK(!autosignin_dialog_);
  DCHECK(dialog);
  autosignin_dialog_ = dialog;
  autosignin_dialog_->ShowAutoSigninPrompt();
}

const PasswordDialogController::FormsVector&
PasswordDialogControllerImpl::GetLocalForms() const {
  return local_credentials_;
}

std::pair<base::string16, gfx::Range>
PasswordDialogControllerImpl::GetAccoutChooserTitle() const {
  std::pair<base::string16, gfx::Range> result;
  GetAccountChooserDialogTitleTextAndLinkRange(
      IsSmartLockBrandingEnabled(profile_),
      local_credentials_.size() > 1,
      &result.first,
      &result.second);
  return result;
}

bool PasswordDialogControllerImpl::ShouldShowSignInButton() const {
  return local_credentials_.size() == 1;
}

base::string16 PasswordDialogControllerImpl::GetAutoSigninPromoTitle() const {
  int message_id = IsSyncingAutosignSetting(profile_)
                       ? IDS_AUTO_SIGNIN_FIRST_RUN_TITLE_MANY_DEVICES
                       : IDS_AUTO_SIGNIN_FIRST_RUN_TITLE_LOCAL_DEVICE;
  return l10n_util::GetStringUTF16(message_id);
}

std::pair<base::string16, gfx::Range>
PasswordDialogControllerImpl::GetAutoSigninText() const {
  std::pair<base::string16, gfx::Range> result;
  GetBrandedTextAndLinkRange(IsSmartLockBrandingEnabled(profile_),
                             IDS_AUTO_SIGNIN_FIRST_RUN_SMART_LOCK_TEXT,
                             IDS_AUTO_SIGNIN_FIRST_RUN_TEXT, &result.first,
                             &result.second);
  return result;
}

void PasswordDialogControllerImpl::OnSmartLockLinkClicked() {
  delegate_->NavigateToSmartLockHelpPage();
}

void PasswordDialogControllerImpl::OnChooseCredentials(
    const autofill::PasswordForm& password_form,
    password_manager::CredentialType credential_type) {
  if (local_credentials_.size() == 1) {
    password_manager::metrics_util::LogAccountChooserUserActionOneAccount(
        password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN);
  } else {
    password_manager::metrics_util::LogAccountChooserUserActionManyAccounts(
        password_manager::metrics_util::ACCOUNT_CHOOSER_CREDENTIAL_CHOSEN);
  }
  ResetDialog();
  delegate_->ChooseCredential(password_form, credential_type);
}

void PasswordDialogControllerImpl::OnSignInClicked() {
  DCHECK_EQ(1u, local_credentials_.size());
  password_manager::metrics_util::LogAccountChooserUserActionOneAccount(
      password_manager::metrics_util::ACCOUNT_CHOOSER_SIGN_IN);
  ResetDialog();
  delegate_->ChooseCredential(
      *local_credentials_[0],
      password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
}

void PasswordDialogControllerImpl::OnAutoSigninOK() {
  password_bubble_experiment::RecordAutoSignInPromptFirstRunExperienceWasShown(
      profile_->GetPrefs());
  password_manager::metrics_util::LogAutoSigninPromoUserAction(
      password_manager::metrics_util::AUTO_SIGNIN_OK_GOT_IT);
  ResetDialog();
  OnCloseDialog();
}

void PasswordDialogControllerImpl::OnAutoSigninTurnOff() {
  profile_->GetPrefs()->SetBoolean(
      password_manager::prefs::kCredentialsEnableAutosignin, false);
  password_bubble_experiment::RecordAutoSignInPromptFirstRunExperienceWasShown(
      profile_->GetPrefs());
  password_manager::metrics_util::LogAutoSigninPromoUserAction(
      password_manager::metrics_util::AUTO_SIGNIN_TURN_OFF);
  ResetDialog();
  OnCloseDialog();
}

void PasswordDialogControllerImpl::OnCloseDialog() {
  if (account_chooser_dialog_) {
    if (local_credentials_.size() == 1) {
      password_manager::metrics_util::LogAccountChooserUserActionOneAccount(
          password_manager::metrics_util::ACCOUNT_CHOOSER_DISMISSED);
    } else {
      password_manager::metrics_util::LogAccountChooserUserActionManyAccounts(
          password_manager::metrics_util::ACCOUNT_CHOOSER_DISMISSED);
    }
    account_chooser_dialog_ = nullptr;
  }
  if (autosignin_dialog_) {
    password_manager::metrics_util::LogAutoSigninPromoUserAction(
        password_manager::metrics_util::AUTO_SIGNIN_NO_ACTION);
    autosignin_dialog_ = nullptr;
  }
  delegate_->OnDialogHidden();
}

void PasswordDialogControllerImpl::ResetDialog() {
  if (account_chooser_dialog_) {
    account_chooser_dialog_->ControllerGone();
    account_chooser_dialog_ = nullptr;
  }
  if (autosignin_dialog_) {
    autosignin_dialog_->ControllerGone();
    autosignin_dialog_ = nullptr;
  }
}