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

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

Issue 319013002: Reland Fix Views web-modal dialog widget creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert MediaGalleriesScanResultDialogViews::AcceptDialogForTesting. Created 6 years, 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/login/login_prompt.h" 5 #include "chrome/browser/ui/login/login_prompt.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/tab_contents/tab_util.h" 9 #include "chrome/browser/ui/views/constrained_window_views.h"
10 #include "chrome/browser/ui/views/login_view.h" 10 #include "chrome/browser/ui/views/login_view.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "components/password_manager/core/browser/password_manager.h" 11 #include "components/password_manager/core/browser/password_manager.h"
13 #include "components/web_modal/web_contents_modal_dialog_host.h"
14 #include "components/web_modal/web_contents_modal_dialog_manager.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
16 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
19 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
20 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
21 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
23 #include "ui/views/window/dialog_delegate.h" 19 #include "ui/views/window/dialog_delegate.h"
24 20
25 using autofill::PasswordForm;
26 using content::BrowserThread;
27 using content::WebContents;
28 using web_modal::WebContentsModalDialogManager;
29 using web_modal::WebContentsModalDialogManagerDelegate;
30
31 // ---------------------------------------------------------------------------- 21 // ----------------------------------------------------------------------------
32 // LoginHandlerViews 22 // LoginHandlerViews
33 23
34 // This class simply forwards the authentication from the LoginView (on 24 // This class simply forwards the authentication from the LoginView (on
35 // the UI thread) to the net::URLRequest (on the I/O thread). 25 // the UI thread) to the net::URLRequest (on the I/O thread).
36 // This class uses ref counting to ensure that it lives until all InvokeLaters 26 // This class uses ref counting to ensure that it lives until all InvokeLaters
37 // have been called. 27 // have been called.
38 class LoginHandlerViews : public LoginHandler, 28 class LoginHandlerViews : public LoginHandler, public views::DialogDelegate {
39 public views::DialogDelegate {
40 public: 29 public:
41 LoginHandlerViews(net::AuthChallengeInfo* auth_info, net::URLRequest* request) 30 LoginHandlerViews(net::AuthChallengeInfo* auth_info, net::URLRequest* request)
42 : LoginHandler(auth_info, request), 31 : LoginHandler(auth_info, request),
43 login_view_(NULL), 32 login_view_(NULL),
44 dialog_(NULL) { 33 dialog_(NULL) {
45 } 34 }
46 35
47 // LoginModelObserver implementation. 36 // LoginModelObserver:
48 virtual void OnAutofillDataAvailable( 37 virtual void OnAutofillDataAvailable(
49 const base::string16& username, 38 const base::string16& username,
50 const base::string16& password) OVERRIDE { 39 const base::string16& password) OVERRIDE {
51 // Nothing to do here since LoginView takes care of autofill for win. 40 // Nothing to do here since LoginView takes care of autofill for win.
52 } 41 }
53 virtual void OnLoginModelDestroying() OVERRIDE {} 42 virtual void OnLoginModelDestroying() OVERRIDE {}
54 43
55 // views::DialogDelegate methods: 44 // views::DialogDelegate:
56 virtual base::string16 GetDialogButtonLabel( 45 virtual base::string16 GetDialogButtonLabel(
57 ui::DialogButton button) const OVERRIDE { 46 ui::DialogButton button) const OVERRIDE {
58 if (button == ui::DIALOG_BUTTON_OK) 47 if (button == ui::DIALOG_BUTTON_OK)
59 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); 48 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_OK_BUTTON_LABEL);
60 return DialogDelegate::GetDialogButtonLabel(button); 49 return DialogDelegate::GetDialogButtonLabel(button);
61 } 50 }
62 51
63 virtual base::string16 GetWindowTitle() const OVERRIDE { 52 virtual base::string16 GetWindowTitle() const OVERRIDE {
64 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_TITLE); 53 return l10n_util::GetStringUTF16(IDS_LOGIN_DIALOG_TITLE);
65 } 54 }
66 55
67 virtual void WindowClosing() OVERRIDE { 56 virtual void WindowClosing() OVERRIDE {
68 DCHECK_CURRENTLY_ON(BrowserThread::UI); 57 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
69 58 content::WebContents* web_contents = GetWebContentsForLogin();
70 WebContents* tab = GetWebContentsForLogin(); 59 if (web_contents)
71 if (tab) 60 web_contents->GetRenderViewHost()->SetIgnoreInputEvents(false);
72 tab->GetRenderViewHost()->SetIgnoreInputEvents(false);
73 61
74 // Reference is no longer valid. 62 // Reference is no longer valid.
75 dialog_ = NULL; 63 dialog_ = NULL;
76
77 CancelAuth(); 64 CancelAuth();
78 } 65 }
79 66
80 virtual void DeleteDelegate() OVERRIDE { 67 virtual void DeleteDelegate() OVERRIDE {
81 DCHECK_CURRENTLY_ON(BrowserThread::UI); 68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
82 69
83 // The widget is going to delete itself; clear our pointer. 70 // The widget is going to delete itself; clear our pointer.
84 dialog_ = NULL; 71 dialog_ = NULL;
85 SetModel(NULL); 72 SetModel(NULL);
86 73
87 ReleaseSoon(); 74 ReleaseSoon();
88 } 75 }
89 76
90 virtual ui::ModalType GetModalType() const OVERRIDE { 77 virtual ui::ModalType GetModalType() const OVERRIDE {
91 #if defined(USE_ASH)
92 return ui::MODAL_TYPE_CHILD; 78 return ui::MODAL_TYPE_CHILD;
93 #else
94 return views::WidgetDelegate::GetModalType();
95 #endif
96 } 79 }
97 80
98 virtual bool Cancel() OVERRIDE { 81 virtual bool Cancel() OVERRIDE {
99 DCHECK_CURRENTLY_ON(BrowserThread::UI); 82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
100
101 CancelAuth(); 83 CancelAuth();
102 return true; 84 return true;
103 } 85 }
104 86
105 virtual bool Accept() OVERRIDE { 87 virtual bool Accept() OVERRIDE {
106 DCHECK_CURRENTLY_ON(BrowserThread::UI); 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
107
108 SetAuth(login_view_->GetUsername(), login_view_->GetPassword()); 89 SetAuth(login_view_->GetUsername(), login_view_->GetPassword());
109 return true; 90 return true;
110 } 91 }
111 92
112 virtual views::View* GetInitiallyFocusedView() OVERRIDE { 93 virtual views::View* GetInitiallyFocusedView() OVERRIDE {
113 return login_view_->GetInitiallyFocusedView(); 94 return login_view_->GetInitiallyFocusedView();
114 } 95 }
115 96
116 virtual views::View* GetContentsView() OVERRIDE { 97 virtual views::View* GetContentsView() OVERRIDE {
117 return login_view_; 98 return login_view_;
118 } 99 }
119 virtual views::Widget* GetWidget() OVERRIDE { 100 virtual views::Widget* GetWidget() OVERRIDE {
120 return login_view_->GetWidget(); 101 return login_view_->GetWidget();
121 } 102 }
122 virtual const views::Widget* GetWidget() const OVERRIDE { 103 virtual const views::Widget* GetWidget() const OVERRIDE {
123 return login_view_->GetWidget(); 104 return login_view_->GetWidget();
124 } 105 }
125 106
126 // LoginHandler: 107 // LoginHandler:
127
128 virtual void BuildViewForPasswordManager( 108 virtual void BuildViewForPasswordManager(
129 password_manager::PasswordManager* manager, 109 password_manager::PasswordManager* manager,
130 const base::string16& explanation) OVERRIDE { 110 const base::string16& explanation) OVERRIDE {
131 DCHECK_CURRENTLY_ON(BrowserThread::UI); 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
132 112
133 // Create a new LoginView and set the model for it. The model (password 113 // Create a new LoginView and set the model for it. The model (password
134 // manager) is owned by the WebContents, but the view is parented to the 114 // manager) is owned by the WebContents, but the view is parented to the
135 // browser window, so the view may be destroyed after the password 115 // browser window, so the view may be destroyed after the password
136 // manager. The view listens for model destruction and unobserves 116 // manager. The view listens for model destruction and unobserves
137 // accordingly. 117 // accordingly.
138 login_view_ = new LoginView(explanation, manager); 118 login_view_ = new LoginView(explanation, manager);
139 119
140 // Scary thread safety note: This can potentially be called *after* SetAuth 120 // Scary thread safety note: This can potentially be called *after* SetAuth
141 // or CancelAuth (say, if the request was cancelled before the UI thread got 121 // or CancelAuth (say, if the request was cancelled before the UI thread got
142 // control). However, that's OK since any UI interaction in those functions 122 // control). However, that's OK since any UI interaction in those functions
143 // will occur via an InvokeLater on the UI thread, which is guaranteed 123 // will occur via an InvokeLater on the UI thread, which is guaranteed
144 // to happen after this is called (since this was InvokeLater'd first). 124 // to happen after this is called (since this was InvokeLater'd first).
145 WebContents* requesting_contents = GetWebContentsForLogin(); 125 dialog_ = ShowWebModalDialogViews(this, GetWebContentsForLogin());
146 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
147 WebContentsModalDialogManager::FromWebContents(requesting_contents);
148 WebContentsModalDialogManagerDelegate* modal_delegate =
149 web_contents_modal_dialog_manager->delegate();
150 CHECK(modal_delegate);
151 dialog_ = views::Widget::CreateWindowAsFramelessChild(
152 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView());
153 web_contents_modal_dialog_manager->ShowModalDialog(
154 dialog_->GetNativeView());
155 NotifyAuthNeeded(); 126 NotifyAuthNeeded();
156 } 127 }
157 128
158 virtual void CloseDialog() OVERRIDE { 129 virtual void CloseDialog() OVERRIDE {
159 // The hosting widget may have been freed. 130 // The hosting widget may have been freed.
160 if (dialog_) 131 if (dialog_)
161 dialog_->Close(); 132 dialog_->Close();
162 } 133 }
163 134
164 private: 135 private:
165 friend class base::RefCountedThreadSafe<LoginHandlerViews>; 136 friend class base::RefCountedThreadSafe<LoginHandlerViews>;
166 friend class LoginPrompt; 137 friend class LoginPrompt;
167 138
168 virtual ~LoginHandlerViews() {} 139 virtual ~LoginHandlerViews() {}
169 140
170 // The LoginView that contains the user's login information 141 // The LoginView that contains the user's login information.
171 LoginView* login_view_; 142 LoginView* login_view_;
172 143
173 views::Widget* dialog_; 144 views::Widget* dialog_;
174 145
175 DISALLOW_COPY_AND_ASSIGN(LoginHandlerViews); 146 DISALLOW_COPY_AND_ASSIGN(LoginHandlerViews);
176 }; 147 };
177 148
178 // static 149 // static
179 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info, 150 LoginHandler* LoginHandler::Create(net::AuthChallengeInfo* auth_info,
180 net::URLRequest* request) { 151 net::URLRequest* request) {
181 return new LoginHandlerViews(auth_info, request); 152 return new LoginHandlerViews(auth_info, request);
182 } 153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698