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 "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/supports_user_data.h" | 10 #include "base/supports_user_data.h" |
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ
est_handler.h" | |
12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | |
13 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
15 #include "content/public/browser/resource_dispatcher_host.h" | 13 #include "content/public/browser/resource_dispatcher_host.h" |
16 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
17 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
18 #include "net/base/auth.h" | 16 #include "net/base/auth.h" |
19 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
20 | 18 |
21 using namespace base::android; | 19 using namespace base::android; |
22 | 20 |
23 using content::BrowserThread; | 21 using content::BrowserThread; |
24 using content::RenderFrameHost; | 22 using content::RenderFrameHost; |
25 using content::ResourceDispatcherHost; | 23 using content::ResourceDispatcherHost; |
26 using content::ResourceRequestInfo; | 24 using content::ResourceRequestInfo; |
27 using content::WebContents; | 25 using content::WebContents; |
28 using data_reduction_proxy::DataReductionProxyAuthRequestHandler; | |
29 using data_reduction_proxy::DataReductionProxySettings; | |
30 | 26 |
31 namespace { | 27 namespace { |
32 const char* kAuthAttemptsKey = "android_webview_auth_attempts"; | 28 const char* kAuthAttemptsKey = "android_webview_auth_attempts"; |
33 | 29 |
34 class UrlRequestAuthAttemptsData : public base::SupportsUserData::Data { | 30 class UrlRequestAuthAttemptsData : public base::SupportsUserData::Data { |
35 public: | 31 public: |
36 UrlRequestAuthAttemptsData() : auth_attempts_(0) { } | 32 UrlRequestAuthAttemptsData() : auth_attempts_(0) { } |
37 int auth_attempts_; | 33 int auth_attempts_; |
38 }; | 34 }; |
39 | 35 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 bool first_auth_attempt) { | 85 bool first_auth_attempt) { |
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
91 | 87 |
92 aw_http_auth_handler_.reset(AwHttpAuthHandlerBase::Create( | 88 aw_http_auth_handler_.reset(AwHttpAuthHandlerBase::Create( |
93 this, auth_info_.get(), first_auth_attempt)); | 89 this, auth_info_.get(), first_auth_attempt)); |
94 | 90 |
95 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( | 91 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( |
96 render_process_id_, render_frame_id_); | 92 render_process_id_, render_frame_id_); |
97 WebContents* web_contents = WebContents::FromRenderFrameHost( | 93 WebContents* web_contents = WebContents::FromRenderFrameHost( |
98 render_frame_host); | 94 render_frame_host); |
99 AwBrowserContext* browser_context = | |
100 AwBrowserContext::FromWebContents(web_contents); | |
101 DataReductionProxySettings* drp_settings = | |
102 browser_context->GetDataReductionProxySettings(); | |
103 if (drp_settings && drp_settings->IsDataReductionProxyEnabled()) { | |
104 // The data reduction proxy auth handler should only be reset on the first | |
105 // auth attempt, because it maintains internal state to cancel if there have | |
106 // been too many attempts. | |
107 if (!drp_auth_handler_.get()) { | |
108 drp_auth_handler_.reset(new DataReductionProxyAuthRequestHandler( | |
109 drp_settings)); | |
110 } | |
111 DCHECK(drp_auth_handler_.get()); | |
112 base::string16 user, password; | |
113 DataReductionProxyAuthRequestHandler::TryHandleResult drp_result = | |
114 drp_auth_handler_->TryHandleAuthentication( | |
115 auth_info_.get(), &user, &password); | |
116 if (drp_result == | |
117 DataReductionProxyAuthRequestHandler::TRY_HANDLE_RESULT_PROCEED) { | |
118 Proceed(user, password); | |
119 return; | |
120 } | |
121 if (drp_result == | |
122 DataReductionProxyAuthRequestHandler::TRY_HANDLE_RESULT_CANCEL) { | |
123 Cancel(); | |
124 return; | |
125 } | |
126 // Fall through if |drp_result| is IGNORE | |
127 } | |
128 | |
129 if (!aw_http_auth_handler_->HandleOnUIThread(web_contents)) { | 95 if (!aw_http_auth_handler_->HandleOnUIThread(web_contents)) { |
130 Cancel(); | 96 Cancel(); |
131 return; | 97 return; |
132 } | 98 } |
133 } | 99 } |
134 | 100 |
135 void AwLoginDelegate::CancelOnIOThread() { | 101 void AwLoginDelegate::CancelOnIOThread() { |
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
137 if (request_) { | 103 if (request_) { |
138 request_->CancelAuth(); | 104 request_->CancelAuth(); |
(...skipping 23 matching lines...) Expand all Loading... |
162 void AwLoginDelegate::DeleteAuthHandlerSoon() { | 128 void AwLoginDelegate::DeleteAuthHandlerSoon() { |
163 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 129 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
164 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 130 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
165 base::Bind(&AwLoginDelegate::DeleteAuthHandlerSoon, this)); | 131 base::Bind(&AwLoginDelegate::DeleteAuthHandlerSoon, this)); |
166 return; | 132 return; |
167 } | 133 } |
168 aw_http_auth_handler_.reset(); | 134 aw_http_auth_handler_.reset(); |
169 } | 135 } |
170 | 136 |
171 } // namespace android_webview | 137 } // namespace android_webview |
OLD | NEW |