-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dialog for password leak detection
Implements dialog for desktop that should pop up when user used leaked credential. The picture used is a placeholder and the dialog itself is not called anywhere. At the moment it only covers the case for user who is not saving passwords in Chrome or Google Account. Bug: 986317 Change-Id: Ia725c1282110b4b6657001d3c58943569b77cc15 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1738459 Reviewed-by: Vasilii Sukhanov <vasilii@chromium.org> Commit-Queue: Rafał Godlewski <rgod@google.com> Cr-Commit-Position: refs/heads/master@{#686062}
- Loading branch information
Rafał Godlewski
authored and
Commit Bot
committed
Aug 12, 2019
1 parent
01bf391
commit d9c691a
Showing
16 changed files
with
353 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
chrome/browser/ui/passwords/credential_leak_dialog_controller.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2019 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_CREDENTIAL_LEAK_DIALOG_CONTROLLER_H_ | ||
#define CHROME_BROWSER_UI_PASSWORDS_CREDENTIAL_LEAK_DIALOG_CONTROLLER_H_ | ||
|
||
#include "chrome/browser/ui/passwords/password_base_dialog_controller.h" | ||
|
||
// An interface used by the credential leak dialog for setting and retrieving | ||
// the state. | ||
class CredentialLeakDialogController : public PasswordBaseDialogController { | ||
protected: | ||
~CredentialLeakDialogController() override = default; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_PASSWORDS_CREDENTIAL_LEAK_DIALOG_CONTROLLER_H_ |
25 changes: 25 additions & 0 deletions
25
chrome/browser/ui/passwords/credential_leak_dialog_controller_impl.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2019 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/credential_leak_dialog_controller_impl.h" | ||
|
||
#include "base/logging.h" | ||
#include "chrome/browser/ui/passwords/password_dialog_prompts.h" | ||
|
||
CredentialLeakDialogControllerImpl::CredentialLeakDialogControllerImpl() | ||
: credential_leak_dialog_(nullptr) {} | ||
|
||
CredentialLeakDialogControllerImpl::~CredentialLeakDialogControllerImpl() = | ||
default; | ||
|
||
void CredentialLeakDialogControllerImpl::ShowCredentialLeakPrompt( | ||
CredentialLeakPrompt* dialog) { | ||
DCHECK(dialog); | ||
credential_leak_dialog_ = dialog; | ||
credential_leak_dialog_->ShowCredentialLeakPrompt(); | ||
} | ||
|
||
bool CredentialLeakDialogControllerImpl::IsShowingAccountChooser() const { | ||
return false; | ||
} |
32 changes: 32 additions & 0 deletions
32
chrome/browser/ui/passwords/credential_leak_dialog_controller_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2019 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_CREDENTIAL_LEAK_DIALOG_CONTROLLER_IMPL_H_ | ||
#define CHROME_BROWSER_UI_PASSWORDS_CREDENTIAL_LEAK_DIALOG_CONTROLLER_IMPL_H_ | ||
|
||
#include "base/macros.h" | ||
#include "chrome/browser/ui/passwords/credential_leak_dialog_controller.h" | ||
|
||
class CredentialLeakPrompt; | ||
|
||
// A UI controller responsible for the credential leak dialog. | ||
class CredentialLeakDialogControllerImpl | ||
: public CredentialLeakDialogController { | ||
public: | ||
CredentialLeakDialogControllerImpl(); | ||
~CredentialLeakDialogControllerImpl() override; | ||
|
||
// Pop up the credential leak dialog. | ||
void ShowCredentialLeakPrompt(CredentialLeakPrompt* dialog); | ||
|
||
// CredentialLeakDialogController: | ||
bool IsShowingAccountChooser() const override; | ||
|
||
private: | ||
CredentialLeakPrompt* credential_leak_dialog_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(CredentialLeakDialogControllerImpl); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_PASSWORDS_CREDENTIAL_LEAK_DIALOG_CONTROLLER_IMPL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
chrome/browser/ui/views/passwords/credential_leak_dialog_view.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright 2019 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/views/passwords/credential_leak_dialog_view.h" | ||
|
||
#include "build/build_config.h" | ||
#include "chrome/browser/ui/views/accessibility/non_accessible_image_view.h" | ||
#include "chrome/browser/ui/views/chrome_layout_provider.h" | ||
#include "chrome/grit/generated_resources.h" | ||
#include "chrome/grit/theme_resources.h" | ||
#include "components/constrained_window/constrained_window_views.h" | ||
#include "components/strings/grit/components_strings.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/base/resource/resource_bundle.h" | ||
#include "ui/views/border.h" | ||
#include "ui/views/bubble/bubble_frame_view.h" | ||
#include "ui/views/layout/box_layout.h" | ||
|
||
using views::BoxLayout; | ||
|
||
namespace { | ||
|
||
// Creates the illustration which is rendered on top of the dialog. | ||
std::unique_ptr<views::View> CreateIllustration() { | ||
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | ||
auto image_view = std::make_unique<NonAccessibleImageView>(); | ||
// TODO(crbug.com/986317): Replace with a proper image. | ||
image_view->SetImage( | ||
*rb.GetNativeImageNamed(IDR_PROFILES_DICE_TURN_ON_SYNC).ToImageSkia()); | ||
return image_view; | ||
} | ||
|
||
// Creates the content containing the title and description for the dialog | ||
// rendered below the illustration. | ||
std::unique_ptr<views::View> CreateContent() { | ||
auto content = std::make_unique<views::View>(); | ||
content->SetLayoutManager(std::make_unique<BoxLayout>( | ||
BoxLayout::Orientation::kVertical, gfx::Insets(), | ||
views::LayoutProvider::Get()->GetDistanceMetric( | ||
views::DISTANCE_UNRELATED_CONTROL_VERTICAL))); | ||
content->SetBorder(views::CreateEmptyBorder( | ||
views::LayoutProvider::Get()->GetDialogInsetsForContentType( | ||
views::CONTROL, views::CONTROL))); | ||
|
||
auto title_label = std::make_unique<views::Label>( | ||
l10n_util::GetStringUTF16(IDS_CREDENTIAL_LEAK_TITLE), | ||
views::style::CONTEXT_DIALOG_TITLE, views::style::STYLE_PRIMARY); | ||
title_label->SetMultiLine(true); | ||
title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | ||
content->AddChildView(std::move(title_label)); | ||
|
||
auto description_label = std::make_unique<views::Label>( | ||
l10n_util::GetStringUTF16(IDS_CREDENTIAL_LEAK_MESSAGE), | ||
views::style::CONTEXT_MESSAGE_BOX_BODY_TEXT); | ||
description_label->SetMultiLine(true); | ||
description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | ||
content->AddChildView(std::move(description_label)); | ||
|
||
return content; | ||
} | ||
|
||
} // namespace | ||
|
||
CredentialLeakDialogView::CredentialLeakDialogView( | ||
CredentialLeakDialogController* controller, | ||
content::WebContents* web_contents) | ||
: controller_(controller), web_contents_(web_contents) { | ||
DCHECK(controller); | ||
DCHECK(web_contents); | ||
} | ||
|
||
CredentialLeakDialogView::~CredentialLeakDialogView() = default; | ||
|
||
void CredentialLeakDialogView::ShowCredentialLeakPrompt() { | ||
InitWindow(); | ||
constrained_window::ShowWebModalDialogViews(this, web_contents_); | ||
} | ||
|
||
void CredentialLeakDialogView::ControllerGone() { | ||
// During Widget::Close() phase some accessibility event may occur. Thus, | ||
// |controller_| should be kept around. | ||
GetWidget()->Close(); | ||
controller_ = nullptr; | ||
} | ||
|
||
ui::ModalType CredentialLeakDialogView::GetModalType() const { | ||
return ui::MODAL_TYPE_CHILD; | ||
} | ||
|
||
gfx::Size CredentialLeakDialogView::CalculatePreferredSize() const { | ||
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric( | ||
DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) - | ||
margins().width(); | ||
return gfx::Size(width, GetHeightForWidth(width)); | ||
} | ||
|
||
base::string16 CredentialLeakDialogView::GetDialogButtonLabel( | ||
ui::DialogButton button) const { | ||
return l10n_util::GetStringUTF16( | ||
button == ui::DIALOG_BUTTON_OK ? IDS_CREDENTIAL_LEAK_OK : IDS_CLOSE); | ||
} | ||
|
||
void CredentialLeakDialogView::InitWindow() { | ||
SetLayoutManager(std::make_unique<BoxLayout>( | ||
views::BoxLayout::Orientation::kVertical, gfx::Insets(), | ||
0 /* between_child_spacing */)); | ||
std::unique_ptr<views::View> illustration = CreateIllustration(); | ||
std::unique_ptr<views::View> content = CreateContent(); | ||
AddChildView(std::move(illustration)); | ||
AddChildView(std::move(content)); | ||
} | ||
|
||
CredentialLeakPrompt* CreateCredentialLeakPromptView( | ||
CredentialLeakDialogController* controller, | ||
content::WebContents* web_contents) { | ||
return new CredentialLeakDialogView(controller, web_contents); | ||
} |
Oops, something went wrong.