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

Side by Side Diff: chrome/browser/ui/login/login_prompt_views.cc

Issue 10407048: browser: Move speech and login files into views/ directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "chrome/browser/ui/login/login_prompt.h"
6
7 #include "base/string16.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/password_manager/password_manager.h"
10 #include "chrome/browser/tab_contents/tab_util.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "chrome/browser/ui/views/constrained_window_views.h"
13 #include "chrome/browser/ui/views/login_view.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h"
17 #include "grit/generated_resources.h"
18 #include "net/url_request/url_request.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/views/window/dialog_delegate.h"
21
22 using content::BrowserThread;
23 using content::WebContents;
24 using webkit::forms::PasswordForm;
25
26 // ----------------------------------------------------------------------------
27 // LoginHandlerViews
28
29 // This class simply forwards the authentication from the LoginView (on
30 // the UI thread) to the net::URLRequest (on the I/O thread).
31 // This class uses ref counting to ensure that it lives until all InvokeLaters
32 // have been called.
33 class LoginHandlerViews : public LoginHandler,
34 public views::DialogDelegate {
35 public:
36 LoginHandlerViews(net::AuthChallengeInfo* auth_info, net::URLRequest* request)
37 : LoginHandler(auth_info, request),
38 login_view_(NULL) {
39 }
40
41 // LoginModelObserver implementation.
42 virtual void OnAutofillDataAvailable(const string16& username,
43 const string16& password) OVERRIDE {
44 // Nothing to do here since LoginView takes care of autofill for win.
45 }
46
47 // views::DialogDelegate methods:
48 virtual string16 GetDialogButtonLabel(
49 ui::DialogButton button) const OVERRIDE {
50 if (button == ui::DIALOG_BUTTON_OK)
51 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL);
52 return DialogDelegate::GetDialogButtonLabel(button);
53 }
54
55 virtual string16 GetWindowTitle() const OVERRIDE {
56 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_TITLE);
57 }
58
59 virtual void WindowClosing() OVERRIDE {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
61
62 WebContents* tab = GetWebContentsForLogin();
63 if (tab)
64 tab->GetRenderViewHost()->SetIgnoreInputEvents(false);
65
66 // Reference is no longer valid.
67 SetDialog(NULL);
68
69 CancelAuth();
70 }
71
72 virtual void DeleteDelegate() OVERRIDE {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
74
75 // The constrained window is going to delete itself; clear our pointer.
76 SetDialog(NULL);
77 SetModel(NULL);
78
79 ReleaseSoon();
80 }
81
82 virtual bool Cancel() OVERRIDE {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
84
85 CancelAuth();
86 return true;
87 }
88
89 virtual bool Accept() OVERRIDE {
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
91
92 SetAuth(login_view_->GetUsername(), login_view_->GetPassword());
93 return true;
94 }
95
96 virtual views::View* GetInitiallyFocusedView() OVERRIDE {
97 return login_view_->GetInitiallyFocusedView();
98 }
99
100 virtual views::View* GetContentsView() OVERRIDE {
101 return login_view_;
102 }
103 virtual views::Widget* GetWidget() OVERRIDE {
104 return login_view_->GetWidget();
105 }
106 virtual const views::Widget* GetWidget() const OVERRIDE {
107 return login_view_->GetWidget();
108 }
109
110 // LoginHandler:
111
112 virtual void BuildViewForPasswordManager(
113 PasswordManager* manager,
114 const string16& explanation) OVERRIDE {
115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
116
117 // Create a new LoginView and set the model for it. The model
118 // (password manager) is owned by the view's parent WebContents,
119 // so natural destruction order means we don't have to worry about
120 // disassociating the model from the view, because the view will
121 // be deleted before the password manager.
122 login_view_ = new LoginView(explanation, manager);
123
124 // Scary thread safety note: This can potentially be called *after* SetAuth
125 // or CancelAuth (say, if the request was cancelled before the UI thread got
126 // control). However, that's OK since any UI interaction in those functions
127 // will occur via an InvokeLater on the UI thread, which is guaranteed
128 // to happen after this is called (since this was InvokeLater'd first).
129 WebContents* requesting_contents = GetWebContentsForLogin();
130 TabContentsWrapper* wrapper =
131 TabContentsWrapper::GetCurrentWrapperForContents(requesting_contents);
132 SetDialog(new ConstrainedWindowViews(wrapper, this));
133 NotifyAuthNeeded();
134 }
135
136 private:
137 friend class base::RefCountedThreadSafe<LoginHandlerViews>;
138 friend class LoginPrompt;
139
140 ~LoginHandlerViews() {}
141
142 // The LoginView that contains the user's login information
143 LoginView* login_view_;
144
145 DISALLOW_COPY_AND_ASSIGN(LoginHandlerViews);
146 };
147
148 // static
149 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info,
150 net::URLRequest* request) {
151 return new LoginHandlerViews(auth_info, request);
152 }
OLDNEW
« no previous file with comments | « chrome/browser/speech/speech_recognition_bubble_views.cc ('k') | chrome/browser/ui/views/button_dropdown_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698