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

Unified Diff: chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc

Issue 14846020: Add Views implementation of ProfileSigninConfirmationDialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no ifdef on function proto Created 7 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/sync/profile_signin_confirmation_dialog_views.cc
diff --git a/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc b/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3cffa724f0deb5e50e4d547956ea93c7d031139c
--- /dev/null
+++ b/chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc
@@ -0,0 +1,239 @@
+// Copyright 2013 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/sync/profile_signin_confirmation_dialog_views.h"
+
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_navigator.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/host_desktop.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/constrained_window_views.h"
+#include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
+#include "chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+#include "google_apis/gaia/gaia_auth_util.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "third_party/skia/include/core/SkColor.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/range/range.h"
+#include "ui/gfx/font.h"
+#include "ui/gfx/native_widget_types.h"
+#include "ui/views/background.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/controls/link.h"
+#include "ui/views/controls/styled_label.h"
+#include "ui/views/layout/box_layout.h"
+#include "ui/views/layout/grid_layout.h"
+#include "ui/views/layout/layout_constants.h"
+#include "ui/views/widget/widget.h"
+
+namespace {
+
+// Wrap a view in a fixed-width container.
+views::View* MakeFixedWidth(views::View* view, int width) {
+ views::View* container = new views::View;
+ views::GridLayout* layout = views::GridLayout::CreatePanel(container);
+ container->SetLayoutManager(layout);
+ layout->AddColumnSet(0)->AddColumn(
+ views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
+ views::GridLayout::FIXED, width, false);
+ layout->StartRow(0, 0);
+ layout->AddView(view, 1, 1, views::GridLayout::FILL, views::GridLayout::FILL);
+ return container;
+}
+
+} // namespace
+
+#if defined(TOOLKIT_VIEWS)
Andrew T Wilson (Slow) 2013/05/08 14:23:48 Is this needed? I would have thought that _views.c
dconnelly 2013/05/13 14:45:21 Done.
+namespace chrome {
+// static
+// Declared in browser_dialogs.h
+void ShowProfileSigninConfirmationDialog(
+ Profile* profile,
+ const std::string& username,
+ const base::Closure& cancel_signin,
+ const base::Closure& signin_with_new_profile,
+ const base::Closure& continue_signin) {
+ ProfileSigninConfirmationDialogViews* dialog =
+ new ProfileSigninConfirmationDialogViews(profile,
+ username,
+ cancel_signin,
+ signin_with_new_profile,
+ continue_signin);
+ ui::CheckShouldPromptForNewProfile(
+ profile,
+ // This callback is guaranteed to be invoked, and once it is, the dialog
+ // owns itself.
+ base::Bind(&ProfileSigninConfirmationDialogViews::Show,
+ base::Unretained(dialog)));
+}
+} // namespace chrome
+#endif
+
+ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews(
+ Profile* profile,
+ const std::string& username,
+ const base::Closure& cancel_signin,
+ const base::Closure& signin_with_new_profile,
+ const base::Closure& continue_signin)
+ : profile_(profile),
+ username_(username),
+ prompt_for_new_profile_(true),
+ responded(false),
+ cancel_signin_(cancel_signin),
+ signin_with_new_profile_(signin_with_new_profile),
+ continue_signin_(continue_signin),
+ link_(NULL) {
+ // Layout the labels in a single fixed-width column.
+ SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
+ const int kDialogWidth = 440;
+
+ // Create the prompt label.
+ std::vector<size_t> offsets;
+ const string16 domain = ASCIIToUTF16(gaia::ExtractDomainName(username_));
+ const string16 prompt_text =
+ l10n_util::GetStringFUTF16(
+ IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_PROMPT_NEW_STYLE,
+ ASCIIToUTF16(username_), domain, &offsets);
+ views::StyledLabel* prompt_label = new views::StyledLabel(prompt_text, this);
+ views::StyledLabel::RangeStyleInfo bold_style;
+ bold_style.font_style = gfx::Font::BOLD;
+ prompt_label->AddStyleRange(
+ ui::Range(offsets[1], offsets[1] + domain.size()), bold_style);
+
+ // Add the prompt label with a darker background and border.
+ views::View* prompt_container = MakeFixedWidth(prompt_label, kDialogWidth);
+ prompt_container->set_border(
+ views::Border::CreateSolidSidedBorder(
+ 1, 0, 1, 0, SkColorSetRGB(0xE1, 0xE1, 0xE1)));
+ prompt_container->set_background(
+ views::Background::CreateSolidBackground(
+ SkColorSetRGB(0xF6, 0xF6, 0xF6)));
+ AddChildView(prompt_container);
+
+ // Create the explanation label.
+ offsets.clear();
+ const string16 learn_more_text =
+ l10n_util::GetStringUTF16(
+ IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE);
+ const string16 explanation_text =
+ l10n_util::GetStringFUTF16(
+ IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_MESSAGE_NEW_STYLE,
+ domain, learn_more_text, &offsets);
+ views::StyledLabel* explanation_label =
+ new views::StyledLabel(explanation_text, this);
+ views::StyledLabel::RangeStyleInfo link_style =
+ views::StyledLabel::RangeStyleInfo::CreateForLink();
+ link_style.font_style = gfx::Font::NORMAL;
+ explanation_label->AddStyleRange(
+ ui::Range(offsets[1], offsets[1] + learn_more_text.size()), link_style);
+
+ // Add the explanation label.
+ AddChildView(MakeFixedWidth(explanation_label, kDialogWidth));
+
+ // Initialize the create profile link.
+ const string16 create_profile_text =
+ l10n_util::GetStringUTF16(
+ IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_YES_NEW_STYLE);
+ link_ = new views::Link(create_profile_text);
+ link_->SetUnderline(false);
+ link_->set_listener(this);
+ link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+}
+
+ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {}
+
+void ProfileSigninConfirmationDialogViews::Show(bool prompt) {
Andrew T Wilson (Slow) 2013/05/08 14:23:48 BTW, I don't like bools that much for things like
dconnelly 2013/05/13 14:45:21 Done.
+ Browser* browser =
+ FindBrowserWithProfile(profile_, chrome::GetActiveDesktop());
+ if (!browser) {
+ DLOG(WARNING) << "No browser found to display the confirmation dialog";
+ cancel_signin_.Run();
Andrew T Wilson (Slow) 2013/05/08 14:23:48 This is possibly OK, although I suspect it might b
dconnelly 2013/05/13 14:45:21 Done. Browser now passed by the caller.
+ delete this;
+ return;
+ }
+ prompt_for_new_profile_ = prompt;
+ CreateDialogWidget(this, NULL, browser->window()->GetNativeWindow())->Show();
+}
+
+string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const {
+ return l10n_util::GetStringUTF16(
+ IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE_NEW_STYLE);
+}
+
+int ProfileSigninConfirmationDialogViews::GetDialogButtons() const {
+ return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
+}
+
+string16 ProfileSigninConfirmationDialogViews::GetDialogButtonLabel(
+ ui::DialogButton button) const {
+ switch (button) {
+ case ui::DIALOG_BUTTON_OK:
+ return l10n_util::GetStringUTF16(
+ IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_NO_NEW_STYLE);
+ case ui::DIALOG_BUTTON_CANCEL:
+ return l10n_util::GetStringUTF16(
+ IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_CANCEL);
+ default:
+ NOTREACHED();
+ return DialogDelegateView::GetDialogButtonLabel(button);
+ }
+}
+
+views::View* ProfileSigninConfirmationDialogViews::CreateExtraView() {
+ return link_;
+}
+
+void ProfileSigninConfirmationDialogViews::DeleteDelegate() {
+ delete this;
+}
+
+bool ProfileSigninConfirmationDialogViews::Accept() {
+ responded = true;
Andrew T Wilson (Slow) 2013/05/08 14:23:48 Consider just Reset()-ing the callbacks once you'v
dconnelly 2013/05/13 14:45:21 Done.
+ continue_signin_.Run();
+ return true;
+}
+
+bool ProfileSigninConfirmationDialogViews::Cancel() {
+ responded = true;
+ cancel_signin_.Run();
+ return true;
+}
+
+void ProfileSigninConfirmationDialogViews::OnClose() {
+ if (!responded)
+ cancel_signin_.Run();
+}
+
+ui::ModalType ProfileSigninConfirmationDialogViews::GetModalType() const {
+ return ui::MODAL_TYPE_WINDOW;
+}
+
+void ProfileSigninConfirmationDialogViews::LinkClicked(views::Link* source,
+ int event_flags) {
+ if (source == link_) {
Andrew T Wilson (Slow) 2013/05/08 14:23:48 What does it mean if source != link? Is this possi
dconnelly 2013/05/13 14:45:21 Done.
+ responded = true;
+ signin_with_new_profile_.Run();
+ GetWidget()->Close();
+ }
+}
+
+void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked(
+ const ui::Range& range,
+ int event_flags) {
+ const std::string url =
+ "http://support.google.com/chromeos/bin/answer.py?hl=en&answer=1331549";
+ chrome::NavigateParams params(
+ FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()),
+ GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL);
+ params.disposition = NEW_POPUP;
+ params.window_action = chrome::NavigateParams::SHOW_WINDOW;
+ chrome::Navigate(&params);
+}

Powered by Google App Engine
This is Rietveld 408576698