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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
15 #include "chrome/common/chrome_notification_types.h"
15 #include "content/browser/browser_thread.h" 16 #include "content/browser/browser_thread.h"
16 #include "content/browser/renderer_host/render_process_host.h" 17 #include "content/browser/renderer_host/render_process_host.h"
17 #include "content/browser/renderer_host/render_view_host.h" 18 #include "content/browser/renderer_host/render_view_host.h"
18 #include "content/browser/renderer_host/render_view_host_delegate.h" 19 #include "content/browser/renderer_host/render_view_host_delegate.h"
19 #include "content/browser/renderer_host/resource_dispatcher_host.h" 20 #include "content/browser/renderer_host/resource_dispatcher_host.h"
20 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" 21 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
21 #include "content/browser/tab_contents/constrained_window.h" 22 #include "content/browser/tab_contents/constrained_window.h"
22 #include "content/browser/tab_contents/tab_contents.h" 23 #include "content/browser/tab_contents/tab_contents.h"
23 #include "content/common/notification_service.h" 24 #include "content/common/notification_service.h"
24 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // Reference is no longer valid. 185 // Reference is no longer valid.
185 request_ = NULL; 186 request_ = NULL;
186 187
187 // Give up on auth if the request was cancelled. 188 // Give up on auth if the request was cancelled.
188 CancelAuth(); 189 CancelAuth();
189 } 190 }
190 191
191 void LoginHandler::AddObservers() { 192 void LoginHandler::AddObservers() {
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
193 194
194 registrar_.Add(this, NotificationType::AUTH_SUPPLIED, 195 registrar_.Add(this, chrome::NOTIFICATION_AUTH_SUPPLIED,
195 NotificationService::AllSources()); 196 NotificationService::AllSources());
196 registrar_.Add(this, NotificationType::AUTH_CANCELLED, 197 registrar_.Add(this, chrome::NOTIFICATION_AUTH_CANCELLED,
197 NotificationService::AllSources()); 198 NotificationService::AllSources());
198 } 199 }
199 200
200 void LoginHandler::RemoveObservers() { 201 void LoginHandler::RemoveObservers() {
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
202 203
203 registrar_.Remove(this, NotificationType::AUTH_SUPPLIED, 204 registrar_.Remove(this, chrome::NOTIFICATION_AUTH_SUPPLIED,
204 NotificationService::AllSources()); 205 NotificationService::AllSources());
205 registrar_.Remove(this, NotificationType::AUTH_CANCELLED, 206 registrar_.Remove(this, chrome::NOTIFICATION_AUTH_CANCELLED,
206 NotificationService::AllSources()); 207 NotificationService::AllSources());
207 208
208 DCHECK(registrar_.IsEmpty()); 209 DCHECK(registrar_.IsEmpty());
209 } 210 }
210 211
211 void LoginHandler::Observe(NotificationType type, 212 void LoginHandler::Observe(int type,
212 const NotificationSource& source, 213 const NotificationSource& source,
213 const NotificationDetails& details) { 214 const NotificationDetails& details) {
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
215 DCHECK(type == NotificationType::AUTH_SUPPLIED || 216 DCHECK(type == chrome::NOTIFICATION_AUTH_SUPPLIED ||
216 type == NotificationType::AUTH_CANCELLED); 217 type == chrome::NOTIFICATION_AUTH_CANCELLED);
217 218
218 TabContents* requesting_contents = GetTabContentsForLogin(); 219 TabContents* requesting_contents = GetTabContentsForLogin();
219 if (!requesting_contents) 220 if (!requesting_contents)
220 return; 221 return;
221 222
222 // Break out early if we aren't interested in the notification. 223 // Break out early if we aren't interested in the notification.
223 if (WasAuthHandled()) 224 if (WasAuthHandled())
224 return; 225 return;
225 226
226 LoginNotificationDetails* login_details = 227 LoginNotificationDetails* login_details =
227 Details<LoginNotificationDetails>(details).ptr(); 228 Details<LoginNotificationDetails>(details).ptr();
228 229
229 // WasAuthHandled() should always test positive before we publish 230 // WasAuthHandled() should always test positive before we publish
230 // AUTH_SUPPLIED or AUTH_CANCELLED notifications. 231 // AUTH_SUPPLIED or AUTH_CANCELLED notifications.
231 DCHECK(login_details->handler() != this); 232 DCHECK(login_details->handler() != this);
232 233
233 // Only handle notification for the identical auth info. 234 // Only handle notification for the identical auth info.
234 if (*login_details->handler()->auth_info() != *auth_info()) 235 if (*login_details->handler()->auth_info() != *auth_info())
235 return; 236 return;
236 237
237 // Set or cancel the auth in this handler. 238 // Set or cancel the auth in this handler.
238 if (type == NotificationType::AUTH_SUPPLIED) { 239 if (type == chrome::NOTIFICATION_AUTH_SUPPLIED) {
239 AuthSuppliedLoginNotificationDetails* supplied_details = 240 AuthSuppliedLoginNotificationDetails* supplied_details =
240 Details<AuthSuppliedLoginNotificationDetails>(details).ptr(); 241 Details<AuthSuppliedLoginNotificationDetails>(details).ptr();
241 SetAuth(supplied_details->username(), supplied_details->password()); 242 SetAuth(supplied_details->username(), supplied_details->password());
242 } else { 243 } else {
243 DCHECK(type == NotificationType::AUTH_CANCELLED); 244 DCHECK(type == chrome::NOTIFICATION_AUTH_CANCELLED);
244 CancelAuth(); 245 CancelAuth();
245 } 246 }
246 } 247 }
247 248
248 void LoginHandler::SetModel(LoginModel* model) { 249 void LoginHandler::SetModel(LoginModel* model) {
249 if (login_model_) 250 if (login_model_)
250 login_model_->SetObserver(NULL); 251 login_model_->SetObserver(NULL);
251 login_model_ = model; 252 login_model_ = model;
252 if (login_model_) 253 if (login_model_)
253 login_model_->SetObserver(this); 254 login_model_->SetObserver(this);
(...skipping 10 matching lines...) Expand all
264 265
265 NotificationService* service = NotificationService::current(); 266 NotificationService* service = NotificationService::current();
266 NavigationController* controller = NULL; 267 NavigationController* controller = NULL;
267 268
268 TabContents* requesting_contents = GetTabContentsForLogin(); 269 TabContents* requesting_contents = GetTabContentsForLogin();
269 if (requesting_contents) 270 if (requesting_contents)
270 controller = &requesting_contents->controller(); 271 controller = &requesting_contents->controller();
271 272
272 LoginNotificationDetails details(this); 273 LoginNotificationDetails details(this);
273 274
274 service->Notify(NotificationType::AUTH_NEEDED, 275 service->Notify(chrome::NOTIFICATION_AUTH_NEEDED,
275 Source<NavigationController>(controller), 276 Source<NavigationController>(controller),
276 Details<LoginNotificationDetails>(&details)); 277 Details<LoginNotificationDetails>(&details));
277 } 278 }
278 279
279 void LoginHandler::NotifyAuthCancelled() { 280 void LoginHandler::NotifyAuthCancelled() {
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
281 DCHECK(WasAuthHandled()); 282 DCHECK(WasAuthHandled());
282 283
283 NotificationService* service = NotificationService::current(); 284 NotificationService* service = NotificationService::current();
284 NavigationController* controller = NULL; 285 NavigationController* controller = NULL;
285 286
286 TabContents* requesting_contents = GetTabContentsForLogin(); 287 TabContents* requesting_contents = GetTabContentsForLogin();
287 if (requesting_contents) 288 if (requesting_contents)
288 controller = &requesting_contents->controller(); 289 controller = &requesting_contents->controller();
289 290
290 LoginNotificationDetails details(this); 291 LoginNotificationDetails details(this);
291 292
292 service->Notify(NotificationType::AUTH_CANCELLED, 293 service->Notify(chrome::NOTIFICATION_AUTH_CANCELLED,
293 Source<NavigationController>(controller), 294 Source<NavigationController>(controller),
294 Details<LoginNotificationDetails>(&details)); 295 Details<LoginNotificationDetails>(&details));
295 } 296 }
296 297
297 void LoginHandler::NotifyAuthSupplied(const string16& username, 298 void LoginHandler::NotifyAuthSupplied(const string16& username,
298 const string16& password) { 299 const string16& password) {
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
300 DCHECK(WasAuthHandled()); 301 DCHECK(WasAuthHandled());
301 302
302 TabContents* requesting_contents = GetTabContentsForLogin(); 303 TabContents* requesting_contents = GetTabContentsForLogin();
303 if (!requesting_contents) 304 if (!requesting_contents)
304 return; 305 return;
305 306
306 NotificationService* service = NotificationService::current(); 307 NotificationService* service = NotificationService::current();
307 NavigationController* controller = &requesting_contents->controller(); 308 NavigationController* controller = &requesting_contents->controller();
308 AuthSuppliedLoginNotificationDetails details(this, username, password); 309 AuthSuppliedLoginNotificationDetails details(this, username, password);
309 310
310 service->Notify(NotificationType::AUTH_SUPPLIED, 311 service->Notify(chrome::NOTIFICATION_AUTH_SUPPLIED,
311 Source<NavigationController>(controller), 312 Source<NavigationController>(controller),
312 Details<AuthSuppliedLoginNotificationDetails>(&details)); 313 Details<AuthSuppliedLoginNotificationDetails>(&details));
313 } 314 }
314 315
315 void LoginHandler::ReleaseSoon() { 316 void LoginHandler::ReleaseSoon() {
316 if (!TestAndSetAuthHandled()) { 317 if (!TestAndSetAuthHandled()) {
317 BrowserThread::PostTask( 318 BrowserThread::PostTask(
318 BrowserThread::IO, FROM_HERE, 319 BrowserThread::IO, FROM_HERE,
319 NewRunnableMethod(this, &LoginHandler::CancelAuthDeferred)); 320 NewRunnableMethod(this, &LoginHandler::CancelAuthDeferred));
320 BrowserThread::PostTask( 321 BrowserThread::PostTask(
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 // Public API 480 // Public API
480 481
481 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, 482 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info,
482 net::URLRequest* request) { 483 net::URLRequest* request) {
483 LoginHandler* handler = LoginHandler::Create(auth_info, request); 484 LoginHandler* handler = LoginHandler::Create(auth_info, request);
484 BrowserThread::PostTask( 485 BrowserThread::PostTask(
485 BrowserThread::UI, FROM_HERE, new LoginDialogTask( 486 BrowserThread::UI, FROM_HERE, new LoginDialogTask(
486 request->url(), auth_info, handler)); 487 request->url(), auth_info, handler));
487 return handler; 488 return handler;
488 } 489 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/login/login_prompt.h ('k') | chrome/browser/ui/login/login_prompt_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698