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

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

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/password_manager/password_manager.h" 12 #include "chrome/browser/password_manager/password_manager.h"
13 #include "chrome/browser/tab_contents/tab_util.h" 13 #include "chrome/browser/tab_contents/tab_util.h"
14 #include "chrome/browser/ui/constrained_window.h" 14 #include "chrome/browser/ui/constrained_window.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
16 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
17 #include "content/browser/browser_thread.h" 17 #include "content/browser/browser_thread.h"
18 #include "content/browser/renderer_host/render_process_host.h" 18 #include "content/browser/renderer_host/render_process_host.h"
19 #include "content/browser/renderer_host/render_view_host.h" 19 #include "content/browser/renderer_host/render_view_host.h"
20 #include "content/browser/renderer_host/render_view_host_delegate.h" 20 #include "content/browser/renderer_host/render_view_host_delegate.h"
21 #include "content/browser/renderer_host/resource_dispatcher_host.h" 21 #include "content/browser/renderer_host/resource_dispatcher_host.h"
22 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" 22 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
23 #include "content/browser/tab_contents/tab_contents.h" 23 #include "content/browser/tab_contents/tab_contents.h"
24 #include "content/common/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
26 #include "net/base/auth.h" 26 #include "net/base/auth.h"
27 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
28 #include "net/url_request/url_request.h" 28 #include "net/url_request/url_request.h"
29 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/text/text_elider.h" 30 #include "ui/base/text/text_elider.h"
31 31
32 using webkit_glue::PasswordForm; 32 using webkit_glue::PasswordForm;
33 33
34 class LoginHandlerImpl; 34 class LoginHandlerImpl;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // Give up on auth if the request was cancelled. 188 // Give up on auth if the request was cancelled.
189 CancelAuth(); 189 CancelAuth();
190 } 190 }
191 191
192 void LoginHandler::AddObservers() { 192 void LoginHandler::AddObservers() {
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
194 194
195 // This is probably OK; we need to listen to everything and we break out of 195 // This is probably OK; we need to listen to everything and we break out of
196 // the Observe() if we aren't handling the same auth_info(). 196 // the Observe() if we aren't handling the same auth_info().
197 registrar_.Add(this, chrome::NOTIFICATION_AUTH_SUPPLIED, 197 registrar_.Add(this, chrome::NOTIFICATION_AUTH_SUPPLIED,
198 NotificationService::AllBrowserContextsAndSources()); 198 content::NotificationService::AllBrowserContextsAndSources());
199 registrar_.Add(this, chrome::NOTIFICATION_AUTH_CANCELLED, 199 registrar_.Add(this, chrome::NOTIFICATION_AUTH_CANCELLED,
200 NotificationService::AllBrowserContextsAndSources()); 200 content::NotificationService::AllBrowserContextsAndSources());
201 } 201 }
202 202
203 void LoginHandler::RemoveObservers() { 203 void LoginHandler::RemoveObservers() {
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
205 205
206 registrar_.Remove(this, chrome::NOTIFICATION_AUTH_SUPPLIED, 206 registrar_.Remove(
207 NotificationService::AllBrowserContextsAndSources()); 207 this, chrome::NOTIFICATION_AUTH_SUPPLIED,
208 registrar_.Remove(this, chrome::NOTIFICATION_AUTH_CANCELLED, 208 content::NotificationService::AllBrowserContextsAndSources());
209 NotificationService::AllBrowserContextsAndSources()); 209 registrar_.Remove(
210 this, chrome::NOTIFICATION_AUTH_CANCELLED,
211 content::NotificationService::AllBrowserContextsAndSources());
210 212
211 DCHECK(registrar_.IsEmpty()); 213 DCHECK(registrar_.IsEmpty());
212 } 214 }
213 215
214 void LoginHandler::Observe(int type, 216 void LoginHandler::Observe(int type,
215 const content::NotificationSource& source, 217 const content::NotificationSource& source,
216 const content::NotificationDetails& details) { 218 const content::NotificationDetails& details) {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
218 DCHECK(type == chrome::NOTIFICATION_AUTH_SUPPLIED || 220 DCHECK(type == chrome::NOTIFICATION_AUTH_SUPPLIED ||
219 type == chrome::NOTIFICATION_AUTH_CANCELLED); 221 type == chrome::NOTIFICATION_AUTH_CANCELLED);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 260
259 void LoginHandler::SetDialog(ConstrainedWindow* dialog) { 261 void LoginHandler::SetDialog(ConstrainedWindow* dialog) {
260 dialog_ = dialog; 262 dialog_ = dialog;
261 } 263 }
262 264
263 void LoginHandler::NotifyAuthNeeded() { 265 void LoginHandler::NotifyAuthNeeded() {
264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
265 if (WasAuthHandled()) 267 if (WasAuthHandled())
266 return; 268 return;
267 269
268 NotificationService* service = NotificationService::current(); 270 content::NotificationService* service =
271 content::NotificationService::current();
269 NavigationController* controller = NULL; 272 NavigationController* controller = NULL;
270 273
271 TabContents* requesting_contents = GetTabContentsForLogin(); 274 TabContents* requesting_contents = GetTabContentsForLogin();
272 if (requesting_contents) 275 if (requesting_contents)
273 controller = &requesting_contents->controller(); 276 controller = &requesting_contents->controller();
274 277
275 LoginNotificationDetails details(this); 278 LoginNotificationDetails details(this);
276 279
277 service->Notify(chrome::NOTIFICATION_AUTH_NEEDED, 280 service->Notify(chrome::NOTIFICATION_AUTH_NEEDED,
278 content::Source<NavigationController>(controller), 281 content::Source<NavigationController>(controller),
279 content::Details<LoginNotificationDetails>(&details)); 282 content::Details<LoginNotificationDetails>(&details));
280 } 283 }
281 284
282 void LoginHandler::NotifyAuthCancelled() { 285 void LoginHandler::NotifyAuthCancelled() {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
284 DCHECK(WasAuthHandled()); 287 DCHECK(WasAuthHandled());
285 288
286 NotificationService* service = NotificationService::current(); 289 content::NotificationService* service =
290 content::NotificationService::current();
287 NavigationController* controller = NULL; 291 NavigationController* controller = NULL;
288 292
289 TabContents* requesting_contents = GetTabContentsForLogin(); 293 TabContents* requesting_contents = GetTabContentsForLogin();
290 if (requesting_contents) 294 if (requesting_contents)
291 controller = &requesting_contents->controller(); 295 controller = &requesting_contents->controller();
292 296
293 LoginNotificationDetails details(this); 297 LoginNotificationDetails details(this);
294 298
295 service->Notify(chrome::NOTIFICATION_AUTH_CANCELLED, 299 service->Notify(chrome::NOTIFICATION_AUTH_CANCELLED,
296 content::Source<NavigationController>(controller), 300 content::Source<NavigationController>(controller),
297 content::Details<LoginNotificationDetails>(&details)); 301 content::Details<LoginNotificationDetails>(&details));
298 } 302 }
299 303
300 void LoginHandler::NotifyAuthSupplied(const string16& username, 304 void LoginHandler::NotifyAuthSupplied(const string16& username,
301 const string16& password) { 305 const string16& password) {
302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
303 DCHECK(WasAuthHandled()); 307 DCHECK(WasAuthHandled());
304 308
305 TabContents* requesting_contents = GetTabContentsForLogin(); 309 TabContents* requesting_contents = GetTabContentsForLogin();
306 if (!requesting_contents) 310 if (!requesting_contents)
307 return; 311 return;
308 312
309 NotificationService* service = NotificationService::current(); 313 content::NotificationService* service =
314 content::NotificationService::current();
310 NavigationController* controller = &requesting_contents->controller(); 315 NavigationController* controller = &requesting_contents->controller();
311 AuthSuppliedLoginNotificationDetails details(this, username, password); 316 AuthSuppliedLoginNotificationDetails details(this, username, password);
312 317
313 service->Notify( 318 service->Notify(
314 chrome::NOTIFICATION_AUTH_SUPPLIED, 319 chrome::NOTIFICATION_AUTH_SUPPLIED,
315 content::Source<NavigationController>(controller), 320 content::Source<NavigationController>(controller),
316 content::Details<AuthSuppliedLoginNotificationDetails>(&details)); 321 content::Details<AuthSuppliedLoginNotificationDetails>(&details));
317 } 322 }
318 323
319 void LoginHandler::ReleaseSoon() { 324 void LoginHandler::ReleaseSoon() {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // Public API 490 // Public API
486 491
487 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, 492 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info,
488 net::URLRequest* request) { 493 net::URLRequest* request) {
489 LoginHandler* handler = LoginHandler::Create(auth_info, request); 494 LoginHandler* handler = LoginHandler::Create(auth_info, request);
490 BrowserThread::PostTask( 495 BrowserThread::PostTask(
491 BrowserThread::UI, FROM_HERE, new LoginDialogTask( 496 BrowserThread::UI, FROM_HERE, new LoginDialogTask(
492 request->url(), auth_info, handler)); 497 request->url(), auth_info, handler));
493 return handler; 498 return handler;
494 } 499 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/theme_install_bubble_view_gtk.cc ('k') | chrome/browser/ui/login/login_prompt_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698