login_view.h revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1// Copyright (c) 2006-2008 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_VIEWS_LOGIN_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_LOGIN_VIEW_H_
7#pragma once
8
9#include "base/task.h"
10#include "chrome/browser/ui/login/login_model.h"
11#include "views/view.h"
12
13namespace views {
14class Label;
15class Textfield;
16class LoginModel;
17}  // namespace views
18
19// This class is responsible for displaying the contents of a login window
20// for HTTP/FTP authentication.
21class LoginView : public views::View, public LoginModelObserver {
22 public:
23  // |focus_view| indicates if the view can be focused.
24  LoginView(const std::wstring& explanation, bool focus_view);
25  virtual ~LoginView();
26
27  // Access the data in the username/password text fields.
28  std::wstring GetUsername();
29  std::wstring GetPassword();
30
31  // LoginModelObserver implementation.
32  virtual void OnAutofillDataAvailable(const std::wstring& username,
33                                       const std::wstring& password);
34
35  // Sets the model. This lets the observer notify the model
36  // when it has been closed / freed, so the model should no longer try and
37  // contact it. The view does not own the model, and it is the responsibility
38  // of the caller to inform this view if the model is deleted.
39  void SetModel(LoginModel* model);
40
41  virtual void RequestFocus();
42
43 protected:
44  // views::View overrides:
45  virtual void ViewHierarchyChanged(bool is_add, views::View *parent,
46                                    views::View *child);
47
48  virtual void NativeViewHierarchyChanged(bool attached,
49                                          gfx::NativeView native_view,
50                                          views::RootView* root_view);
51
52 private:
53  void FocusFirstField();
54
55  // Non-owning refs to the input text fields.
56  views::Textfield* username_field_;
57  views::Textfield* password_field_;
58
59  // Button labels
60  views::Label* username_label_;
61  views::Label* password_label_;
62
63  // Authentication message.
64  views::Label* message_label_;
65
66  // If not null, points to a model we need to notify of our own destruction
67  // so it doesn't try and access this when its too late.
68  LoginModel* login_model_;
69
70  ScopedRunnableMethodFactory<LoginView> focus_grabber_factory_;
71
72  // See description above constructor.
73  const bool focus_view_;
74
75  // Indicates that this view was created when focus manager was unavailable
76  // (on the hidden tab, for example). This is only used if focus_view_ is true.
77  bool focus_delayed_;
78
79  DISALLOW_COPY_AND_ASSIGN(LoginView);
80};
81
82#endif  // CHROME_BROWSER_UI_VIEWS_LOGIN_VIEW_H_
83