profile_signin_confirmation_dialog.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_PROFILE_SIGNIN_CONFIRMATION_DIALOG_H_
6#define CHROME_BROWSER_UI_WEBUI_SIGNIN_PROFILE_SIGNIN_CONFIRMATION_DIALOG_H_
7
8#include <string>
9
10#include "base/callback.h"
11#include "base/memory/weak_ptr.h"
12#include "base/string16.h"
13#include "chrome/browser/common/cancelable_request.h"
14#include "chrome/browser/history/history_types.h"
15#include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
16#include "ui/base/ui_base_types.h"
17#include "ui/web_dialogs/web_dialog_delegate.h"
18
19class Profile;
20class WebUIMessageHandler;
21
22// A tab-modal dialog to allow a user signing in with a managed account
23// to create a new Chrome profile.
24class ProfileSigninConfirmationDialog : public ui::WebDialogDelegate {
25 public:
26  // Creates and shows the modal dialog.  |profile| is the current Chrome
27  // profile and |username| is the GAIA username that the user is signing
28  // in with.
29  static void ShowDialog(Profile* profile,
30                         const std::string& username,
31                         const base::Closure& cancel_signin,
32                         const base::Closure& signin_with_new_profile,
33                         const base::Closure& continue_signin);
34
35  // Closes the dialog, which will delete itself.
36  void Close() const;
37
38 private:
39  ProfileSigninConfirmationDialog(
40      Profile* profile,
41      const std::string& username,
42      const base::Closure& cancel_signin,
43      const base::Closure& signin_with_new_profile,
44      const base::Closure& continue_signin);
45  virtual ~ProfileSigninConfirmationDialog();
46
47  // Shows the dialog and releases ownership of this object. It will
48  // delete itself when the dialog is closed. If |prompt_for_new_profile|
49  // is true, the dialog will offer to create a new profile before signin.
50  void Show(bool prompt_for_new_profile);
51
52  // WebDialogDelegate implementation.
53  virtual ui::ModalType GetDialogModalType() const OVERRIDE;
54  virtual string16 GetDialogTitle() const OVERRIDE;
55  virtual GURL GetDialogContentURL() const OVERRIDE;
56  virtual void GetWebUIMessageHandlers(
57      std::vector<content::WebUIMessageHandler*>* handlers) const OVERRIDE;
58  virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
59  virtual std::string GetDialogArgs() const OVERRIDE;
60  virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
61  virtual void OnCloseContents(content::WebContents* source,
62                               bool* out_close_dialog) OVERRIDE;
63  virtual bool ShouldShowDialogTitle() const OVERRIDE;
64
65  // Weak ptr to delegate.
66  ConstrainedWebDialogDelegate* delegate_;
67
68  // The GAIA username being signed in.
69  std::string username_;
70
71  // Whether to show the "Create a new profile" button.
72  bool prompt_for_new_profile_;
73
74  // Dialog button callbacks.
75  base::Closure cancel_signin_;
76  base::Closure signin_with_new_profile_;
77  base::Closure continue_signin_;
78
79  // Weak pointer to the profile being signed-in.
80  Profile* profile_;
81
82  // Cleanup bookkeeping.  Labeled mutable to get around inherited const
83  // label on GetWebUIMessageHandlers.
84  mutable bool closed_by_handler_;
85
86  base::WeakPtrFactory<ProfileSigninConfirmationDialog> weak_pointer_factory_;
87
88  DISALLOW_COPY_AND_ASSIGN(ProfileSigninConfirmationDialog);
89};
90
91#endif  // CHROME_BROWSER_UI_WEBUI_SIGNIN_PROFILE_SIGNIN_CONFIRMATION_DIALOG_H_
92