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

Side by Side Diff: content/browser/ssl/ssl_error_handler.cc

Issue 9406001: Factor out ResourceDispatcherHost dependent code around SSLManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix an error on merging tpayne's change Created 8 years, 9 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 "content/browser/ssl/ssl_error_handler.h" 5 #include "content/browser/ssl/ssl_error_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/renderer_host/render_view_host.h" 8 #include "content/browser/renderer_host/render_view_host.h"
9 #include "content/browser/renderer_host/resource_dispatcher_host.h"
10 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
11 #include "content/browser/ssl/ssl_cert_error_handler.h" 9 #include "content/browser/ssl/ssl_cert_error_handler.h"
12 #include "content/browser/tab_contents/navigation_controller_impl.h" 10 #include "content/browser/tab_contents/navigation_controller_impl.h"
13 #include "content/browser/tab_contents/tab_contents.h" 11 #include "content/browser/tab_contents/tab_contents.h"
14 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
15 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
16 #include "net/url_request/url_request.h" 14 #include "net/url_request/url_request.h"
17 15
18 using content::BrowserThread; 16 using content::BrowserThread;
19 using content::WebContents; 17 using content::WebContents;
18 using net::SSLInfo;
20 19
21 SSLErrorHandler::SSLErrorHandler(ResourceDispatcherHost* rdh, 20 SSLErrorHandler::SSLErrorHandler(Delegate* delegate,
22 net::URLRequest* request, 21 const content::GlobalRequestID& id)
23 ResourceType::Type resource_type)
24 : manager_(NULL), 22 : manager_(NULL),
25 request_id_(0, 0), 23 request_id_(id),
26 resource_dispatcher_host_(rdh), 24 delegate_(delegate),
27 request_url_(request->url()), 25 request_url_(delegate->URLForSSLRequest(id)),
darin (slow to review) 2012/02/28 23:36:44 why are these delegate function calls instead of j
Takashi Toyoshima 2012/02/29 00:15:24 I thought minimizing number of arguments would be
28 resource_type_(resource_type), 26 resource_type_(delegate->ResourceTypeForSSLRequest(id)),
29 request_has_been_notified_(false) { 27 request_has_been_notified_(false) {
30 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 28 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
29 DCHECK(delegate);
31 30
32 ResourceDispatcherHostRequestInfo* info = 31 if (!delegate->RenderViewForSSLRequest(
33 ResourceDispatcherHost::InfoForRequest(request); 32 id, &render_process_id_, &render_view_id_))
34 request_id_.child_id = info->child_id();
35 request_id_.request_id = info->request_id();
36
37 if (!ResourceDispatcherHost::RenderViewForRequest(request,
38 &render_process_id_,
39 &render_view_id_))
40 NOTREACHED(); 33 NOTREACHED();
41 34
42 // This makes sure we don't disappear on the IO thread until we've given an 35 // This makes sure we don't disappear on the IO thread until we've given an
43 // answer to the net::URLRequest. 36 // answer to the net::URLRequest.
44 // 37 //
45 // Release in CompleteCancelRequest, CompleteContinueRequest, or 38 // Release in CompleteCancelRequest, CompleteContinueRequest, or
46 // CompleteTakeNoAction. 39 // CompleteTakeNoAction.
47 AddRef(); 40 AddRef();
48 } 41 }
49 42
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 void SSLErrorHandler::CompleteCancelRequest(int error) { 119 void SSLErrorHandler::CompleteCancelRequest(int error) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
128 121
129 // It is important that we notify the net::URLRequest only once. If we try 122 // It is important that we notify the net::URLRequest only once. If we try
130 // to notify the request twice, it may no longer exist and |this| might have 123 // to notify the request twice, it may no longer exist and |this| might have
131 // already have been deleted. 124 // already have been deleted.
132 DCHECK(!request_has_been_notified_); 125 DCHECK(!request_has_been_notified_);
133 if (request_has_been_notified_) 126 if (request_has_been_notified_)
134 return; 127 return;
135 128
136 net::URLRequest* request = 129 SSLCertErrorHandler* cert_error = AsSSLCertErrorHandler();
137 resource_dispatcher_host_->GetURLRequest(request_id_); 130 const SSLInfo* ssl_info = NULL;
138 if (request && request->is_pending()) { 131 if (cert_error)
139 // The request can be NULL if it was cancelled by the renderer (as the 132 ssl_info = &cert_error->ssl_info();
140 // result of the user navigating to a new page from the location bar). 133 delegate_->CancelSSLRequest(request_id_, error, ssl_info);
141 DVLOG(1) << "CompleteCancelRequest() url: " << request->url().spec();
142 SSLCertErrorHandler* cert_error = AsSSLCertErrorHandler();
143 if (cert_error)
144 request->SimulateSSLError(error, cert_error->ssl_info());
145 else
146 request->SimulateError(error);
147 }
148 request_has_been_notified_ = true; 134 request_has_been_notified_ = true;
149 135
150 // We're done with this object on the IO thread. 136 // We're done with this object on the IO thread.
151 Release(); 137 Release();
152 } 138 }
153 139
154 void SSLErrorHandler::CompleteContinueRequest() { 140 void SSLErrorHandler::CompleteContinueRequest() {
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
156 142
157 // It is important that we notify the net::URLRequest only once. If we try to 143 // It is important that we notify the net::URLRequest only once. If we try to
158 // notify the request twice, it may no longer exist and |this| might have 144 // notify the request twice, it may no longer exist and |this| might have
159 // already have been deleted. 145 // already have been deleted.
160 DCHECK(!request_has_been_notified_); 146 DCHECK(!request_has_been_notified_);
161 if (request_has_been_notified_) 147 if (request_has_been_notified_)
162 return; 148 return;
163 149
164 net::URLRequest* request = 150 delegate_->ContinueSSLRequest(request_id_);
165 resource_dispatcher_host_->GetURLRequest(request_id_);
166 if (request) {
167 // The request can be NULL if it was cancelled by the renderer (as the
168 // result of the user navigating to a new page from the location bar).
169 DVLOG(1) << "CompleteContinueRequest() url: " << request->url().spec();
170 request->ContinueDespiteLastError();
171 }
172 request_has_been_notified_ = true; 151 request_has_been_notified_ = true;
173 152
174 // We're done with this object on the IO thread. 153 // We're done with this object on the IO thread.
175 Release(); 154 Release();
176 } 155 }
177 156
178 void SSLErrorHandler::CompleteTakeNoAction() { 157 void SSLErrorHandler::CompleteTakeNoAction() {
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
180 159
181 // It is important that we notify the net::URLRequest only once. If we try to 160 // It is important that we notify the net::URLRequest only once. If we try to
182 // notify the request twice, it may no longer exist and |this| might have 161 // notify the request twice, it may no longer exist and |this| might have
183 // already have been deleted. 162 // already have been deleted.
184 DCHECK(!request_has_been_notified_); 163 DCHECK(!request_has_been_notified_);
185 if (request_has_been_notified_) 164 if (request_has_been_notified_)
186 return; 165 return;
187 166
188 request_has_been_notified_ = true; 167 request_has_been_notified_ = true;
189 168
190 // We're done with this object on the IO thread. 169 // We're done with this object on the IO thread.
191 Release(); 170 Release();
192 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698