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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
// Copyright 2014 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.
#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_
#include <memory>
#include <vector>
#include "base/macros.h"
#include "chrome/browser/ui/passwords/manage_passwords_state.h"
#include "chrome/browser/ui/passwords/passwords_client_ui_delegate.h"
#include "chrome/browser/ui/passwords/passwords_model_delegate.h"
#include "chrome/common/features.h"
#include "components/password_manager/core/browser/password_store.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
namespace content {
class WebContents;
}
namespace password_manager {
enum class CredentialType;
struct InteractionsStats;
class PasswordFormManager;
}
class AccountChooserPrompt;
class AutoSigninFirstRunPrompt;
class ManagePasswordsIconView;
class PasswordDialogController;
class PasswordDialogControllerImpl;
// Per-tab class to control the Omnibox password icon and bubble.
class ManagePasswordsUIController
: public content::WebContentsObserver,
public content::WebContentsUserData<ManagePasswordsUIController>,
public password_manager::PasswordStore::Observer,
public PasswordsModelDelegate,
public PasswordsClientUIDelegate {
public:
~ManagePasswordsUIController() override;
// PasswordsClientUIDelegate:
void OnPasswordSubmitted(
std::unique_ptr<password_manager::PasswordFormManager> form_manager)
override;
void OnUpdatePasswordSubmitted(
std::unique_ptr<password_manager::PasswordFormManager> form_manager)
override;
bool OnChooseCredentials(
std::vector<std::unique_ptr<autofill::PasswordForm>> local_credentials,
const GURL& origin,
const ManagePasswordsState::CredentialsCallback& callback) override;
void OnAutoSignin(
std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms,
const GURL& origin) override;
void OnPromptEnableAutoSignin() override;
void OnAutomaticPasswordSave(
std::unique_ptr<password_manager::PasswordFormManager> form_manager)
override;
void OnPasswordAutofilled(
const std::map<base::string16, const autofill::PasswordForm*>&
password_form_map,
const GURL& origin,
const std::vector<const autofill::PasswordForm*>* federated_matches)
override;
// PasswordStore::Observer:
void OnLoginsChanged(
const password_manager::PasswordStoreChangeList& changes) override;
// Set the state of the Omnibox icon, and possibly show the associated bubble
// without user interaction.
virtual void UpdateIconAndBubbleState(ManagePasswordsIconView* icon);
bool IsAutomaticallyOpeningBubble() const {
return bubble_status_ == SHOULD_POP_UP;
}
base::WeakPtr<PasswordsModelDelegate> GetModelDelegateProxy();
// PasswordsModelDelegate:
content::WebContents* GetWebContents() const override;
const GURL& GetOrigin() const override;
password_manager::ui::State GetState() const override;
const autofill::PasswordForm& GetPendingPassword() const override;
bool IsPasswordOverridden() const override;
const std::vector<std::unique_ptr<autofill::PasswordForm>>& GetCurrentForms()
const override;
const password_manager::InteractionsStats* GetCurrentInteractionStats()
const override;
void OnBubbleShown() override;
void OnBubbleHidden() override;
void OnNoInteraction() override;
void OnNopeUpdateClicked() override;
void NeverSavePassword() override;
void SavePassword() override;
void UpdatePassword(const autofill::PasswordForm& password_form) override;
void ChooseCredential(
const autofill::PasswordForm& form,
password_manager::CredentialType credential_type) override;
void NavigateToSmartLockHelpPage() override;
void NavigateToPasswordManagerSettingsPage() override;
void NavigateToChromeSignIn() override;
void OnDialogHidden() override;
protected:
explicit ManagePasswordsUIController(
content::WebContents* web_contents);
// The pieces of saving and blacklisting passwords that interact with
// FormManager, split off into internal functions for testing/mocking.
virtual void SavePasswordInternal();
virtual void UpdatePasswordInternal(
const autofill::PasswordForm& password_form);
virtual void NeverSavePasswordInternal();
// Called when a PasswordForm is autofilled, when a new PasswordForm is
// submitted, or when a navigation occurs to update the visibility of the
// manage passwords icon and bubble.
virtual void UpdateBubbleAndIconVisibility();
// Called to create the account chooser dialog. Mocked in tests.
virtual AccountChooserPrompt* CreateAccountChooser(
PasswordDialogController* controller);
// Called to create the account chooser dialog. Mocked in tests.
virtual AutoSigninFirstRunPrompt* CreateAutoSigninPrompt(
PasswordDialogController* controller);
// Check if |web_contents()| is attached to some Browser. Mocked in tests.
virtual bool HasBrowserWindow() const;
// Overwrites the client for |passwords_data_|.
void set_client(password_manager::PasswordManagerClient* client) {
passwords_data_.set_client(client);
}
// content::WebContentsObserver:
void DidNavigateMainFrame(
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) override;
void WasHidden() override;
private:
friend class content::WebContentsUserData<ManagePasswordsUIController>;
enum BubbleStatus {
NOT_SHOWN,
// The bubble is to be popped up in the next call to
// UpdateBubbleAndIconVisibility().
SHOULD_POP_UP,
SHOWN,
// Same as SHOWN but the icon is to be updated when the bubble is closed.
SHOWN_PENDING_ICON_UPDATE,
};
// Shows the password bubble without user interaction.
void ShowBubbleWithoutUserInteraction();
// Closes the account chooser gracefully so the callback is called. Then sets
// the state to MANAGE_STATE.
void DestroyAccountChooser();
// content::WebContentsObserver:
void WebContentsDestroyed() override;
// The wrapper around current state and data.
ManagePasswordsState passwords_data_;
// The controller for the blocking dialogs.
std::unique_ptr<PasswordDialogControllerImpl> dialog_controller_;
BubbleStatus bubble_status_;
// The bubbles of different types can pop up unpredictably superseding each
// other. However, closing the bubble may affect the state of
// ManagePasswordsUIController internally. This is undesired if
// ManagePasswordsUIController is in the process of opening a new bubble. The
// situation is worse on Windows where the bubble is destroyed asynchronously.
// Thus, OnBubbleHidden() can be called after the new one is shown. By that
// time the internal state of ManagePasswordsUIController has nothing to do
// with the old bubble.
// Invalidating all the weak pointers will detach the current bubble.
base::WeakPtrFactory<ManagePasswordsUIController> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsUIController);
};
#endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_UI_CONTROLLER_H_
|