1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.h"
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
7eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include <algorithm>
8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/browser_dialogs.h"
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/browser_navigator.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/browser_window.h"
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/ui/views/constrained_window_views.h"
1603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/grit/chromium_strings.h"
186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/grit/generated_resources.h"
1903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "components/signin/core/common/profile_management_switches.h"
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/public/browser/web_contents.h"
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "google_apis/gaia/gaia_auth_util.h"
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h"
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/gfx/font.h"
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
2658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ui/gfx/range/range.h"
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/background.h"
28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/views/border.h"
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/controls/label.h"
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/controls/styled_label.h"
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/layout/box_layout.h"
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/layout/grid_layout.h"
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/layout/layout_constants.h"
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/widget/widget.h"
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/views/window/dialog_client_view.h"
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace chrome {
38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Declared in browser_dialogs.h
39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ShowProfileSigninConfirmationDialog(
40868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    Browser* browser,
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    content::WebContents* web_contents,
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    Profile* profile,
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const std::string& username,
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ui::ProfileSigninConfirmationDelegate* delegate) {
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ProfileSigninConfirmationDialogViews::ShowDialog(browser,
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                   profile,
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                   username,
48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                                   delegate);
49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}  // namespace chrome
51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews(
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    Browser* browser,
54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const std::string& username,
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ui::ProfileSigninConfirmationDelegate* delegate)
5646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    : browser_(browser),
5746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      username_(username),
5846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      delegate_(delegate),
5946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      prompt_for_new_profile_(true),
6046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      continue_signin_button_(NULL) {
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {}
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// static
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ProfileSigninConfirmationDialogViews::ShowDialog(
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    Browser* browser,
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    Profile* profile,
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const std::string& username,
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ui::ProfileSigninConfirmationDelegate* delegate) {
7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Hides the new avatar bubble if it is currently shown. The new avatar bubble
7203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // should be automatically closed when it loses focus. However on windows the
7303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // profile signin confirmation dialog is not modal yet thus it does not take
7403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // away focus, thus as a temporary workaround we need to manually close the
7503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // bubble.
7603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // TODO(guohui): removes the workaround once the profile confirmation dialog
7703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // is fixed.
7803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  if (switches::IsNewAvatarMenu() && ProfileChooserView::IsShowing())
7903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    ProfileChooserView::Hide();
8003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ProfileSigninConfirmationDialogViews* dialog =
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      new ProfileSigninConfirmationDialogViews(
830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch          browser, username, delegate);
84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ui::CheckShouldPromptForNewProfile(
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      profile,
86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      // This callback is guaranteed to be invoked, and once it is, the dialog
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      // owns itself.
88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      base::Bind(&ProfileSigninConfirmationDialogViews::Show,
89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                 base::Unretained(dialog)));
90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ProfileSigninConfirmationDialogViews::Show(bool prompt_for_new_profile) {
93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  prompt_for_new_profile_ = prompt_for_new_profile;
947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  CreateBrowserModalDialogViews(
957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      this, browser_->window()->GetNativeWindow())->Show();
96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
98a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)base::string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const {
99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return l10n_util::GetStringUTF16(
100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      IDS_ENTERPRISE_SIGNIN_TITLE_NEW_STYLE);
101868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)base::string16 ProfileSigninConfirmationDialogViews::GetDialogButtonLabel(
104868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ui::DialogButton button) const {
105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (button == ui::DIALOG_BUTTON_OK) {
106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    // If we're giving the option to create a new profile, then OK is
107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    // "Create new profile".  Otherwise it is "Continue signin".
108eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return l10n_util::GetStringUTF16(
109eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        prompt_for_new_profile_ ?
110eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_NEW_STYLE :
111eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch            IDS_ENTERPRISE_SIGNIN_CONTINUE_NEW_STYLE);
112eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
113eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CANCEL);
114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)int ProfileSigninConfirmationDialogViews::GetDefaultDialogButton() const {
117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return ui::DIALOG_BUTTON_NONE;
118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)views::View* ProfileSigninConfirmationDialogViews::CreateExtraView() {
121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (prompt_for_new_profile_) {
122a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const base::string16 continue_signin_text =
123eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CONTINUE_NEW_STYLE);
124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    continue_signin_button_ =
125eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        new views::LabelButton(this, continue_signin_text);
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    continue_signin_button_->SetStyle(views::Button::STYLE_BUTTON);
1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    continue_signin_button_->SetFocusable(true);
128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
129eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return continue_signin_button_;
130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool ProfileSigninConfirmationDialogViews::Accept() {
133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (delegate_) {
134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    if (prompt_for_new_profile_)
135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      delegate_->OnSigninWithNewProfile();
136eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    else
137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      delegate_->OnContinueSignin();
138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    delegate_ = NULL;
139868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return true;
141868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
142868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
143868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool ProfileSigninConfirmationDialogViews::Cancel() {
144868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (delegate_) {
145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    delegate_->OnCancelSignin();
146868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    delegate_ = NULL;
147868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  }
148868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  return true;
149868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
150868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
151a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void ProfileSigninConfirmationDialogViews::OnClosed() {
152868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  Cancel();
153868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
154868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
155868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)ui::ModalType ProfileSigninConfirmationDialogViews::GetModalType() const {
15646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  return ui::MODAL_TYPE_CHILD;
157868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
158868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
159868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
160868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    const ViewHierarchyChangedDetails& details) {
161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if (!details.is_add || details.child != this)
162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    return;
163868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  const SkColor kPromptBarBackgroundColor =
1657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      ui::GetSigninConfirmationPromptBarColor(
1667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch          ui::kSigninConfirmationPromptBarBackgroundAlpha);
1677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Create the prompt label.
169eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  size_t offset;
170a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const base::string16 domain =
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::ASCIIToUTF16(gaia::ExtractDomainName(username_));
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const base::string16 username = base::ASCIIToUTF16(username_);
173a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const base::string16 prompt_text =
174868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      l10n_util::GetStringFUTF16(
175868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)          IDS_ENTERPRISE_SIGNIN_ALERT_NEW_STYLE,
176eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch          domain, &offset);
177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  views::StyledLabel* prompt_label = new views::StyledLabel(prompt_text, this);
1787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  prompt_label->SetDisplayedOnBackgroundColor(kPromptBarBackgroundColor);
1797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
180868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  views::StyledLabel::RangeStyleInfo bold_style;
181868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  bold_style.font_style = gfx::Font::BOLD;
182868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  prompt_label->AddStyleRange(
18358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      gfx::Range(offset, offset + domain.size()), bold_style);
184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
185eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Create the prompt bar.
186eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  views::View* prompt_bar = new views::View;
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  prompt_bar->SetBorder(views::Border::CreateSolidSidedBorder(
1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      1,
1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      0,
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      1,
1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      0,
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ui::GetSigninConfirmationPromptBarColor(
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          ui::kSigninConfirmationPromptBarBorderAlpha)));
1947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  prompt_bar->set_background(views::Background::CreateSolidBackground(
1957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      kPromptBarBackgroundColor));
196868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
197eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Create the explanation label.
198eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  std::vector<size_t> offsets;
199a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const base::string16 learn_more_text =
200868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      l10n_util::GetStringUTF16(
201868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)          IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE);
202a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  const base::string16 signin_explanation_text =
203868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      l10n_util::GetStringFUTF16(prompt_for_new_profile_ ?
204868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)          IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION_NEW_STYLE :
205868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)          IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITHOUT_PROFILE_CREATION_NEW_STYLE,
206868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)          username, learn_more_text, &offsets);
207868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  explanation_label_ = new views::StyledLabel(signin_explanation_text, this);
208868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  explanation_label_->AddStyleRange(
20958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      gfx::Range(offsets[1], offsets[1] + learn_more_text.size()),
210ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      views::StyledLabel::RangeStyleInfo::CreateForLink());
211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
212eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Layout the components.
213eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  views::GridLayout* dialog_layout = new views::GridLayout(this);
214eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  SetLayoutManager(dialog_layout);
215eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
216eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Use GridLayout inside the prompt bar because StyledLabel requires it.
217eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  views::GridLayout* prompt_layout = views::GridLayout::CreatePanel(prompt_bar);
218eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  prompt_bar->SetLayoutManager(prompt_layout);
219eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  prompt_layout->AddColumnSet(0)->AddColumn(
220eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      views::GridLayout::FILL, views::GridLayout::CENTER, 100,
221eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      views::GridLayout::USE_PREF, 0, 0);
222eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  prompt_layout->StartRow(0, 0);
223eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  prompt_layout->AddView(prompt_label);
224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Use a column set with no padding.
225eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  dialog_layout->AddColumnSet(0)->AddColumn(
226eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      views::GridLayout::FILL, views::GridLayout::FILL, 100,
227eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      views::GridLayout::USE_PREF, 0, 0);
228eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  dialog_layout->StartRow(0, 0);
229eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  dialog_layout->AddView(
230eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      prompt_bar, 1, 1,
231eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      views::GridLayout::FILL, views::GridLayout::FILL, 0, 0);
232eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
233eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Use a new column set for the explanation label so we can add padding.
234eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  dialog_layout->AddPaddingRow(0.0, views::kPanelVertMargin);
235eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  views::ColumnSet* explanation_columns = dialog_layout->AddColumnSet(1);
236eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew);
237eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  explanation_columns->AddColumn(
238eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      views::GridLayout::FILL, views::GridLayout::FILL, 100,
239eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      views::GridLayout::USE_PREF, 0, 0);
240eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew);
241eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  dialog_layout->StartRow(0, 1);
242eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const int kPreferredWidth = 440;
243eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  dialog_layout->AddView(
244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      explanation_label_, 1, 1,
245eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      views::GridLayout::FILL, views::GridLayout::FILL,
246eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      kPreferredWidth, explanation_label_->GetHeightForWidth(kPreferredWidth));
247868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
248868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
249868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked(
25058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    const gfx::Range& range,
251868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    int event_flags) {
252868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  chrome::NavigateParams params(
253868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      browser_,
254868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      GURL("http://support.google.com/chromeos/bin/answer.py?answer=1331549"),
2551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      ui::PAGE_TRANSITION_LINK);
256868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  params.disposition = NEW_POPUP;
257868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  params.window_action = chrome::NavigateParams::SHOW_WINDOW;
258868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  chrome::Navigate(&params);
259868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
260eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
261eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid ProfileSigninConfirmationDialogViews::ButtonPressed(
262eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    views::Button* sender,
263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    const ui::Event& event) {
264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  DCHECK(prompt_for_new_profile_);
265eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  DCHECK_EQ(continue_signin_button_, sender);
266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (delegate_) {
267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    delegate_->OnContinueSignin();
268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    delegate_ = NULL;
269eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
270eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  GetWidget()->Close();
271eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
272