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

Unified Diff: chrome/browser/ui/views/profiles/force_signout_dialog.cc

Issue 2862653002: If force-sign-in policy is enabled, popup warning dialog before window closing if auth token becom… (Closed)
Patch Set: cr and rebase from master Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/profiles/force_signout_dialog.cc
diff --git a/chrome/browser/ui/views/profiles/force_signout_dialog.cc b/chrome/browser/ui/views/profiles/force_signout_dialog.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ef5d47f80711bdda29c741455ed8660e4550e415
--- /dev/null
+++ b/chrome/browser/ui/views/profiles/force_signout_dialog.cc
@@ -0,0 +1,243 @@
+// Copyright 2017 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/profiles/force_signout_dialog.h"
+
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "base/strings/string16.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/grit/chromium_strings.h"
+#include "chrome/grit/generated_resources.h"
+#include "components/constrained_window/constrained_window_views.h"
+#include "components/signin/core/browser/signin_manager.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/views/background.h"
+#include "ui/views/border.h"
+#include "ui/views/controls/styled_label.h"
+#include "ui/views/layout/grid_layout.h"
+#include "ui/views/layout/layout_constants.h"
+#include "ui/views/layout/layout_provider.h"
+#include "ui/views/view.h"
+#include "ui/views/window/dialog_client_view.h"
+
+namespace {
+
+void Signout(SigninManager* signin_manager) {
+ signin_manager->SignOut(
+ signin_metrics::AUTHENTICATION_FAILED_WITH_FORCE_SIGNIN,
+ signin_metrics::SignoutDelete::KEEPING);
+}
+
+bool IsMatchingBrowser(Browser* browser, Profile* profile) {
+ return browser->profile()->GetOriginalProfile() ==
+ profile->GetOriginalProfile() &&
+ !browser->tab_strip_model()->empty() &&
+ BrowserView::GetBrowserViewForBrowser(browser)->frame()->IsVisible();
+}
+
+// Find a browser that is assoicated with |profile| to show the dialog for
+// Sign out warning.
+Browser* FindBrowserWithProfile(Profile* profile) {
+ Browser* browser = BrowserList::GetInstance()->GetLastActive();
+ if (browser && IsMatchingBrowser(browser, profile))
+ return browser;
+ for (auto* browser : *BrowserList::GetInstance()) {
+ if (IsMatchingBrowser(browser, profile)) {
+ return browser;
+ }
+ }
+ return nullptr;
+}
+
+} // namespace
+
+ForceSignoutDialog::ForceSignoutDialog(Browser* browser,
+ SigninManager* signin_manager,
+ const SignoutCallback& signout_callback,
+ bool delay_allowed)
+ : browser_(browser),
+ signin_manager_(signin_manager),
+ signout_callback_(signout_callback),
+ delay_allowed_(delay_allowed) {
+ BrowserModalDialogList::GetInstance()->AddDialog(this);
+ BrowserList::AddObserver(this);
+ constrained_window::CreateBrowserModalDialogViews(
+ this, browser->window()->GetNativeWindow())
+ ->Show();
+}
+
+ForceSignoutDialog::~ForceSignoutDialog() {
+ BrowserList::RemoveObserver(this);
+ BrowserModalDialogList::GetInstance()->RemoveDialog(this);
+}
sky 2017/05/18 16:50:51 It's possible to get here without accept/cancel be
+
+// static
+ForceSignoutDialog* ForceSignoutDialog::ShowDialog(
+ Profile* profile,
+ SigninManager* signin_manager,
+ const SignoutCallback& signout_callback,
+ bool delay_allowed) {
+ Browser* browser = FindBrowserWithProfile(profile);
+ if (browser == nullptr) { // If there is no browser, we can just sign
+ // out profile directly.
+ Signout(signin_manager);
+ if (!signout_callback.is_null())
+ signout_callback.Run(true);
+ return nullptr;
+ }
+
+ return new ForceSignoutDialog(browser, signin_manager, signout_callback,
+ delay_allowed);
+}
+
+void ForceSignoutDialog::ActivateModalDialog(Browser* browser) {
+ if (browser_ && browser_ != browser) {
+ browser_->window()->FlashFrame(true);
+ browser_->window()->Activate();
+ }
+ GetWidget()->Show();
+ GetWidget()->Activate();
+}
+
+bool ForceSignoutDialog::IsShowing() {
+ return GetWidget()->IsVisible();
+}
+
+void ForceSignoutDialog::OnBrowserRemoved(Browser* browser) {
+ if (browser_ == browser)
sky 2017/05/18 16:50:51 You shouldn't need this. The dialog is parented to
+ browser_ = nullptr;
+}
+
+bool ForceSignoutDialog::Accept() {
+ Signout(signin_manager_);
+ if (!signout_callback_.is_null())
+ signout_callback_.Run(true);
+ return true;
+}
+
+bool ForceSignoutDialog::Cancel() {
+ if (!signout_callback_.is_null())
+ signout_callback_.Run(false);
+ return true;
+}
+
+base::string16 ForceSignoutDialog::GetWindowTitle() const {
+ return l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_TITLE);
+}
+
+base::string16 ForceSignoutDialog::GetDialogButtonLabel(
+ ui::DialogButton button) const {
+ if (button == ui::DIALOG_BUTTON_OK)
+ return l10n_util::GetStringUTF16(
+ IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_CONFIRM);
+ else
+ return l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_DELAY);
+}
+
+int ForceSignoutDialog::GetDialogButtons() const {
+ if (delay_allowed_)
+ return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
+ return ui::DIALOG_BUTTON_OK;
+}
+
+ui::ModalType ForceSignoutDialog::GetModalType() const {
+ return ui::MODAL_TYPE_WINDOW;
+}
+
+void ForceSignoutDialog::AddedToWidget() {
+ const SkColor prompt_bar_background_color =
+ GetSigninConfirmationPromptBarColor(
+ GetNativeTheme(), ui::kSigninConfirmationPromptBarBackgroundAlpha);
+ // Create the prompt label.
+ size_t offset;
+ std::string email = signin_manager_->GetAuthenticatedAccountInfo().email;
+ const base::string16 domain =
+ base::ASCIIToUTF16(gaia::ExtractDomainName(email));
+ const base::string16 prompt_text =
+ l10n_util::GetStringFUTF16(IDS_ENTERPRISE_SIGNIN_ALERT, domain, &offset);
+ views::StyledLabel* prompt_label =
+ new views::StyledLabel(prompt_text, nullptr);
+ prompt_label->SetDisplayedOnBackgroundColor(prompt_bar_background_color);
+
+ views::StyledLabel::RangeStyleInfo bold_style;
+ bold_style.weight = gfx::Font::Weight::BOLD;
+ prompt_label->AddStyleRange(gfx::Range(offset, offset + domain.size()),
+ bold_style);
+
+ // Create the prompt bar.
+ views::View* prompt_bar = new views::View;
+ prompt_bar->SetBorder(views::CreateSolidSidedBorder(
+ 1, 0, 1, 0,
+ ui::GetSigninConfirmationPromptBarColor(
+ GetNativeTheme(), ui::kSigninConfirmationPromptBarBorderAlpha)));
+ prompt_bar->set_background(
+ views::Background::CreateSolidBackground(prompt_bar_background_color));
+
+ // Create the explanation label.
+ base::string16 signin_explanation_text;
+ base::string16 close_warning;
+ if (delay_allowed_) {
+ close_warning = l10n_util::GetStringUTF16(
+ IDS_ENTERPRISE_FORCE_SIGNOUT_ADDITIONAL_EXPLANATION);
+ }
+ if (email.empty()) {
+ signin_explanation_text = l10n_util::GetStringFUTF16(
+ IDS_ENTERPRISE_FORCE_SIGNOUT_EXPLANATION_WITHOUT_USER_NAME,
+ close_warning);
+ } else {
+ signin_explanation_text =
+ l10n_util::GetStringFUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_EXPLANATION,
+ base::ASCIIToUTF16(email), close_warning);
+ }
+ views::StyledLabel* explanation_label =
+ new views::StyledLabel(signin_explanation_text, nullptr);
+
+ // Layout the components.
+ const gfx::Insets panel_insets =
+ views::LayoutProvider::Get()->GetInsetsMetric(views::INSETS_PANEL);
+ SetBorder(views::CreateEmptyBorder(panel_insets.top(), 0,
+ panel_insets.bottom(), 0));
+ views::GridLayout* dialog_layout = new views::GridLayout(this);
+ SetLayoutManager(dialog_layout);
+
+ // Use GridLayout inside the prompt bar because StyledLabel requires it.
+ views::GridLayout* prompt_layout = views::GridLayout::CreatePanel(prompt_bar);
+ prompt_bar->SetLayoutManager(prompt_layout);
+ prompt_layout->AddColumnSet(0)->AddColumn(views::GridLayout::FILL,
+ views::GridLayout::CENTER, 100,
+ views::GridLayout::USE_PREF, 0, 0);
+ prompt_layout->StartRow(0, 0);
+ prompt_layout->AddView(prompt_label);
+ // Use a column set with no padding.
+ dialog_layout->AddColumnSet(0)->AddColumn(views::GridLayout::FILL,
+ views::GridLayout::FILL, 100,
+ views::GridLayout::USE_PREF, 0, 0);
+ dialog_layout->StartRow(0, 0);
+ dialog_layout->AddView(prompt_bar, 1, 1, views::GridLayout::FILL,
+ views::GridLayout::FILL, 0, 0);
+
+ // Use a new column set for the explanation label so we can add padding.
+ dialog_layout->AddPaddingRow(0.0, views::kPanelVertMargin);
+ views::ColumnSet* explanation_columns = dialog_layout->AddColumnSet(1);
+ explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew);
+ explanation_columns->AddColumn(views::GridLayout::FILL,
+ views::GridLayout::FILL, 100,
+ views::GridLayout::USE_PREF, 0, 0);
+ explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew);
+ dialog_layout->StartRow(0, 1);
+ const int kPreferredWidth = 440;
+ dialog_layout->AddView(explanation_label, 1, 1, views::GridLayout::FILL,
+ views::GridLayout::FILL, kPreferredWidth,
+ explanation_label->GetHeightForWidth(kPreferredWidth));
+}

Powered by Google App Engine
This is Rietveld 408576698