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 194 195 196 197 198 199 200 201 202 203 204
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h"
#include "base/feature_list.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/actions/chrome_action_id.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_actions.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/passwords/password_bubble_view_base.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/grit/generated_resources.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/view_class_properties.h"
ManagePasswordsIconViews::ManagePasswordsIconViews(
CommandUpdater* updater,
IconLabelBubbleView::Delegate* icon_label_bubble_delegate,
PageActionIconView::Delegate* page_action_icon_delegate,
Browser* browser)
: PageActionIconView(updater,
IDC_MANAGE_PASSWORDS_FOR_PAGE,
icon_label_bubble_delegate,
page_action_icon_delegate,
"ManagePasswords",
kActionShowPasswordsBubbleOrPage,
browser) {
// Password icon should not be mirrored in RTL.
image_container_view()->SetFlipCanvasOnPaintForRTLUI(false);
SetProperty(views::kElementIdentifierKey, kPasswordsOmniboxKeyIconElementId);
const std::u16string tooltip_and_accessible_name_text =
GetTextForTooltipAndAccessibleName();
GetViewAccessibility().SetName(tooltip_and_accessible_name_text);
UpdateTooltipText();
// TODO(b/353777476): Strip out pinned toolbar button code into a shared
// controller for page action and pinned button.
BrowserActions* browser_actions = browser->browser_actions();
actions::ActionManager::Get()
.FindAction(kActionShowPasswordsBubbleOrPage,
browser_actions->root_action_item())
->SetTooltipText(tooltip_and_accessible_name_text);
}
ManagePasswordsIconViews::~ManagePasswordsIconViews() = default;
void ManagePasswordsIconViews::SetState(password_manager::ui::State state,
bool is_blocklisted) {
if (state_ == state && is_blocklisted_ == is_blocklisted) {
return;
}
// If there is an opened bubble for the current icon it should go away.
PasswordBubbleViewBase::CloseCurrentBubble();
state_ = state;
is_blocklisted_ = is_blocklisted;
UpdateUiForState();
const std::u16string tooltip_and_accessible_name_text =
GetTextForTooltipAndAccessibleName();
GetViewAccessibility().SetName(tooltip_and_accessible_name_text);
UpdateTooltipText();
UpdateIconImage();
// TODO(b/353777476): Strip out pinned toolbar button code into a shared
// controller for page action and pinned button.
BrowserActions* browser_actions = browser()->browser_actions();
actions::ActionManager::Get()
.FindAction(kActionShowPasswordsBubbleOrPage,
browser_actions->root_action_item())
->SetTooltipText(tooltip_and_accessible_name_text);
}
void ManagePasswordsIconViews::UpdateUiForState() {
BrowserActions* browser_actions = browser()->browser_actions();
actions::ActionManager::Get()
.FindAction(kActionShowPasswordsBubbleOrPage,
browser_actions->root_action_item())
->SetProperty(kActionItemUnderlineIndicatorKey,
(state_ != password_manager::ui::INACTIVE_STATE));
// Hides the page action icon if the associated toolbar icon is pinned.
if (state_ == password_manager::ui::INACTIVE_STATE ||
state_ == password_manager::ui::PASSWORD_CHANGE_STATE ||
delegate()->ShouldHidePageActionIcon(this)) {
SetVisible(false);
return;
}
SetVisible(true);
// We may be about to automatically pop up a passwords bubble.
// Force layout of the icon's parent now; the bubble will be incorrectly
// positioned otherwise, as the icon won't have been drawn into position.
parent()->DeprecatedLayoutImmediately();
}
views::BubbleDialogDelegate* ManagePasswordsIconViews::GetBubble() const {
return PasswordBubbleViewBase::manage_password_bubble();
}
void ManagePasswordsIconViews::UpdateImpl() {
if (!GetWebContents()) {
return;
}
ManagePasswordsUIController::FromWebContents(GetWebContents())
->UpdateIconAndBubbleState(this);
}
void ManagePasswordsIconViews::OnExecuting(
PageActionIconView::ExecuteSource source) {
browser()->window()->NotifyFeaturePromoFeatureUsed(
feature_engagement::kIPHPasswordsSaveRecoveryPromoFeature,
FeaturePromoFeatureUsedAction::kClosePromoIfPresent);
}
bool ManagePasswordsIconViews::OnMousePressed(const ui::MouseEvent& event) {
bool result = PageActionIconView::OnMousePressed(event);
PasswordBubbleViewBase::CloseCurrentBubble();
return result;
}
const gfx::VectorIcon& ManagePasswordsIconViews::GetVectorIcon() const {
return is_blocklisted_ && base::FeatureList::IsEnabled(
features::kSavePasswordsContextualUi)
? vector_icons::kPasswordManagerOffIcon
: vector_icons::kPasswordManagerIcon;
}
std::u16string ManagePasswordsIconViews::GetTextForTooltipAndAccessibleName()
const {
std::u16string result;
switch (state_) {
case password_manager::ui::INACTIVE_STATE:
case password_manager::ui::SAVE_CONFIRMATION_STATE:
case password_manager::ui::UPDATE_CONFIRMATION_STATE:
case password_manager::ui::CREDENTIAL_REQUEST_STATE:
case password_manager::ui::AUTO_SIGNIN_STATE:
case password_manager::ui::WILL_DELETE_UNSYNCED_ACCOUNT_PASSWORDS_STATE:
case password_manager::ui::MANAGE_STATE:
case password_manager::ui::PASSWORD_UPDATED_SAFE_STATE:
case password_manager::ui::PASSWORD_UPDATED_MORE_TO_FIX:
// TODO(crbug.com/375564659): Add tooltip reflecting password change flow
// state.
case password_manager::ui::PASSWORD_CHANGE_STATE:
// TODO(b/345242100): Add correct tooltip for passkey saved.
case password_manager::ui::PASSKEY_SAVED_CONFIRMATION_STATE:
case password_manager::ui::PASSKEY_DELETED_CONFIRMATION_STATE:
case password_manager::ui::PASSKEY_UPDATED_CONFIRMATION_STATE:
case password_manager::ui::PASSKEY_NOT_ACCEPTED_STATE:
case password_manager::ui::PASSKEY_UPGRADE_STATE:
result = l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE);
break;
case password_manager::ui::PENDING_PASSWORD_UPDATE_STATE:
case password_manager::ui::PENDING_PASSWORD_STATE:
case password_manager::ui::GENERATED_PASSWORD_CONFIRMATION_STATE:
result = l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TOOLTIP_SAVE);
break;
case password_manager::ui::MOVE_CREDENTIAL_AFTER_LOG_IN_STATE:
case password_manager::ui::MOVE_CREDENTIAL_FROM_MANAGE_BUBBLE_STATE:
result = l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TOOLTIP_MOVE);
break;
case password_manager::ui::BIOMETRIC_AUTHENTICATION_FOR_FILLING_STATE:
case password_manager::ui::BIOMETRIC_AUTHENTICATION_CONFIRMATION_STATE:
result = l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TOOLTIP_PROTECT);
break;
case password_manager::ui::NOTIFY_RECEIVED_SHARED_CREDENTIALS:
result = l10n_util::GetStringUTF16(
IDS_PASSWORD_MANAGER_TOOLTIP_SHARED_NOTIFICATION);
break;
case password_manager::ui::KEYCHAIN_ERROR_STATE:
result = l10n_util::GetStringUTF16(
IDS_PASSWORD_MANAGER_TOOLTIP_KEYCHAIN_ERROR);
break;
}
if (is_blocklisted_ &&
base::FeatureList::IsEnabled(features::kSavePasswordsContextualUi)) {
result += u" - " +
l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_TOOLTIP_BLOCKED);
}
return result;
}
void ManagePasswordsIconViews::AboutToRequestFocusFromTabTraversal(
bool reverse) {
if (IsBubbleShowing()) {
PasswordBubbleViewBase::ActivateBubble();
}
}
BEGIN_METADATA(ManagePasswordsIconViews)
END_METADATA
|