OLD | NEW |
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 "android_webview/browser/aw_login_delegate.h" | 5 #include "android_webview/browser/aw_login_delegate.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/supports_user_data.h" | 9 #include "base/supports_user_data.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 static_cast<UrlRequestAuthAttemptsData*>( | 49 static_cast<UrlRequestAuthAttemptsData*>( |
50 request->GetUserData(kAuthAttemptsKey)); | 50 request->GetUserData(kAuthAttemptsKey)); |
51 | 51 |
52 if (count == NULL) { | 52 if (count == NULL) { |
53 count = new UrlRequestAuthAttemptsData(); | 53 count = new UrlRequestAuthAttemptsData(); |
54 request->SetUserData(kAuthAttemptsKey, count); | 54 request->SetUserData(kAuthAttemptsKey, count); |
55 } | 55 } |
56 | 56 |
57 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 57 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
58 base::Bind(&AwLoginDelegate::HandleHttpAuthRequestOnUIThread, | 58 base::Bind(&AwLoginDelegate::HandleHttpAuthRequestOnUIThread, |
59 make_scoped_refptr(this), (count->auth_attempts_ == 0))); | 59 this, (count->auth_attempts_ == 0))); |
60 count->auth_attempts_++; | 60 count->auth_attempts_++; |
61 } | 61 } |
62 | 62 |
63 AwLoginDelegate::~AwLoginDelegate() { | 63 AwLoginDelegate::~AwLoginDelegate() { |
| 64 // The Auth handler holds a ref count back on |this| object, so it should be |
| 65 // impossible to reach here while this object still owns an auth handler. |
| 66 DCHECK(aw_http_auth_handler_ == NULL); |
64 } | 67 } |
65 | 68 |
66 void AwLoginDelegate::Proceed(const string16& user, | 69 void AwLoginDelegate::Proceed(const string16& user, |
67 const string16& password) { | 70 const string16& password) { |
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
69 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 72 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
70 base::Bind(&AwLoginDelegate::ProceedOnIOThread, | 73 base::Bind(&AwLoginDelegate::ProceedOnIOThread, |
71 make_scoped_refptr(this), user, password)); | 74 this, user, password)); |
72 } | 75 } |
73 | 76 |
74 void AwLoginDelegate::Cancel() { | 77 void AwLoginDelegate::Cancel() { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
76 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 79 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
77 base::Bind(&AwLoginDelegate::CancelOnIOThread, | 80 base::Bind(&AwLoginDelegate::CancelOnIOThread, this)); |
78 make_scoped_refptr(this))); | |
79 } | 81 } |
80 | 82 |
81 void AwLoginDelegate::HandleHttpAuthRequestOnUIThread( | 83 void AwLoginDelegate::HandleHttpAuthRequestOnUIThread( |
82 bool first_auth_attempt) { | 84 bool first_auth_attempt) { |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
84 | 86 |
85 aw_http_auth_handler_.reset(AwHttpAuthHandlerBase::Create( | 87 aw_http_auth_handler_.reset(AwHttpAuthHandlerBase::Create( |
86 this, auth_info_, first_auth_attempt)); | 88 this, auth_info_, first_auth_attempt)); |
87 | 89 |
88 RenderViewHost* render_view_host = RenderViewHost::FromID( | 90 RenderViewHost* render_view_host = RenderViewHost::FromID( |
89 render_process_id_, render_view_id_); | 91 render_process_id_, render_view_id_); |
90 if (!render_view_host) { | 92 if (!render_view_host) { |
91 Cancel(); | 93 Cancel(); |
92 return; | 94 return; |
93 } | 95 } |
94 | 96 |
95 WebContents* web_contents = WebContents::FromRenderViewHost( | 97 WebContents* web_contents = WebContents::FromRenderViewHost( |
96 render_view_host); | 98 render_view_host); |
97 aw_http_auth_handler_->HandleOnUIThread(web_contents); | 99 aw_http_auth_handler_->HandleOnUIThread(web_contents); |
98 } | 100 } |
99 | 101 |
100 void AwLoginDelegate::CancelOnIOThread() { | 102 void AwLoginDelegate::CancelOnIOThread() { |
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
102 if (request_) { | 104 if (request_) { |
103 request_->CancelAuth(); | 105 request_->CancelAuth(); |
104 ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_); | 106 ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_); |
| 107 request_ = NULL; |
105 } | 108 } |
| 109 DeleteAuthHandlerSoon(); |
106 } | 110 } |
107 | 111 |
108 void AwLoginDelegate::ProceedOnIOThread(const string16& user, | 112 void AwLoginDelegate::ProceedOnIOThread(const string16& user, |
109 const string16& password) { | 113 const string16& password) { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
111 if (request_) { | 115 if (request_) { |
112 request_->SetAuth(net::AuthCredentials(user, password)); | 116 request_->SetAuth(net::AuthCredentials(user, password)); |
113 ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_); | 117 ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request_); |
| 118 request_ = NULL; |
114 } | 119 } |
| 120 DeleteAuthHandlerSoon(); |
115 } | 121 } |
116 | 122 |
117 void AwLoginDelegate::OnRequestCancelled() { | 123 void AwLoginDelegate::OnRequestCancelled() { |
118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
119 request_ = NULL; | 125 request_ = NULL; |
| 126 DeleteAuthHandlerSoon(); |
| 127 } |
| 128 |
| 129 void AwLoginDelegate::DeleteAuthHandlerSoon() { |
| 130 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 131 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 132 base::Bind(&AwLoginDelegate::DeleteAuthHandlerSoon, this)); |
| 133 return; |
| 134 } |
120 aw_http_auth_handler_.reset(); | 135 aw_http_auth_handler_.reset(); |
121 } | 136 } |
122 | 137 |
123 } // namespace android_webview | 138 } // namespace android_webview |
OLD | NEW |