| Index: chrome/browser/ui/views/profiles/force_signout_dialog_view.cc
|
| diff --git a/chrome/browser/ui/views/profiles/force_signout_dialog_view.cc b/chrome/browser/ui/views/profiles/force_signout_dialog_view.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5e4fab54a9a538bb36a38cf7c9bd216f250f704f
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/profiles/force_signout_dialog_view.cc
|
| @@ -0,0 +1,169 @@
|
| +// 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_view.h"
|
| +
|
| +#include <memory>
|
| +#include <string>
|
| +#include <utility>
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/browser_window.h"
|
| +#include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
|
| +#include "chrome/browser/ui/views/profiles/force_signout_dialog.h"
|
| +#include "chrome/grit/chromium_strings.h"
|
| +#include "chrome/grit/generated_resources.h"
|
| +#include "components/constrained_window/constrained_window_views.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"
|
| +
|
| +ForceSignoutDialogView::ForceSignoutDialogView(
|
| + Browser* browser,
|
| + std::unique_ptr<ForceSignoutDialog> dialog)
|
| + : dialog_(std::move(dialog)) {
|
| + constrained_window::CreateBrowserModalDialogViews(
|
| + this, browser->window()->GetNativeWindow())
|
| + ->Show();
|
| +}
|
| +
|
| +ForceSignoutDialogView::~ForceSignoutDialogView() {
|
| + dialog_->OnViewClosing();
|
| +}
|
| +
|
| +bool ForceSignoutDialogView::Accept() {
|
| + dialog_->OnAccept();
|
| + return true;
|
| +}
|
| +
|
| +bool ForceSignoutDialogView::Cancel() {
|
| + dialog_->OnCancel();
|
| + return true;
|
| +}
|
| +
|
| +base::string16 ForceSignoutDialogView::GetWindowTitle() const {
|
| + return l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_TITLE);
|
| +}
|
| +
|
| +base::string16 ForceSignoutDialogView::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 ForceSignoutDialogView::GetDialogButtons() const {
|
| + if (dialog_->IsDelayAllowed())
|
| + return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
|
| + return ui::DIALOG_BUTTON_OK;
|
| +}
|
| +
|
| +ui::ModalType ForceSignoutDialogView::GetModalType() const {
|
| + return ui::MODAL_TYPE_WINDOW;
|
| +}
|
| +
|
| +void ForceSignoutDialogView::AddedToWidget() {
|
| + const SkColor prompt_bar_background_color =
|
| + GetSigninConfirmationPromptBarColor(
|
| + GetNativeTheme(), ui::kSigninConfirmationPromptBarBackgroundAlpha);
|
| + // Create the prompt label.
|
| + size_t offset;
|
| + std::string email = dialog_->GetEmail();
|
| + 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 (dialog_->IsDelayAllowed()) {
|
| + 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));
|
| +}
|
| +
|
| +void ForceSignoutDialogView::ActivateModalDialog() {
|
| + GetWidget()->Show();
|
| + GetWidget()->Activate();
|
| +}
|
| +
|
| +bool ForceSignoutDialogView::IsShowing() const {
|
| + return GetWidget()->IsVisible();
|
| +}
|
|
|