Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "android_webview/browser/aw_request_handler.h" | |
| 6 | |
| 7 #include "android_webview/browser/aw_contents_io_thread_client.h" | |
| 8 #include "android_webview/browser/aw_web_resource_response.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/resource_request_info.h" | |
| 11 #include "net/url_request/url_request.h" | |
| 12 #include "net/url_request/url_request_job.h" | |
| 13 | |
| 14 namespace android_webview { | |
| 15 | |
| 16 AwRequestHandler::AwRequestHandler() { | |
| 17 } | |
| 18 | |
| 19 AwRequestHandler::~AwRequestHandler() { | |
| 20 } | |
|
mmenke
2015/09/29 15:56:05
nit: Definition order should match declaration or
mnaganov (inactive)
2015/09/29 23:45:35
Not relevant anymore.
| |
| 21 | |
| 22 AndroidStreamReaderURLRequestJob* AwRequestHandler::MaybeInterceptRequest( | |
| 23 net::URLRequest* request, | |
| 24 net::NetworkDelegate* network_delegate) { | |
| 25 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 26 // MaybeInterceptRequest can be called several times for the same request, | |
| 27 // for example because a call to URLRequestJob::NotifyRestartRequired has | |
| 28 // been made. | |
| 29 if (job_.get()) return nullptr; | |
|
mmenke
2015/09/29 15:56:05
nit: .get() not needed.
mmenke
2015/09/29 15:56:05
This should be split on to two lines.
mnaganov (inactive)
2015/09/29 23:45:35
Not relevant anymore.
mnaganov (inactive)
2015/09/29 23:45:35
Done.
| |
| 30 | |
| 31 if (!QueryForAwWebResourceResponse(request)) | |
| 32 return nullptr; | |
| 33 job_ = new AndroidStreamReaderURLRequestJob(request, network_delegate); | |
|
mmenke
2015/09/29 15:56:05
We're planning on getting rid of refcounting for U
mnaganov (inactive)
2015/09/29 23:45:35
Done. Now only a weak reference to the job is held
| |
| 34 return job_.get(); | |
| 35 } | |
| 36 | |
| 37 bool AwRequestHandler::QueryForAwWebResourceResponse(net::URLRequest* request) { | |
| 38 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 39 | |
| 40 int render_process_id, render_frame_id; | |
| 41 if (!content::ResourceRequestInfo::GetRenderFrameForRequest( | |
| 42 request, &render_process_id, &render_frame_id)) { | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 scoped_ptr<AwContentsIoThreadClient> io_thread_client = | |
| 47 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); | |
| 48 | |
| 49 if (!io_thread_client.get()) | |
| 50 return false; | |
| 51 | |
| 52 GURL referrer(request->referrer()); | |
| 53 if (referrer.is_valid() && | |
| 54 (!request->is_pending() || request->is_redirecting())) { | |
| 55 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kReferer, | |
| 56 referrer.spec(), true); | |
| 57 } | |
| 58 io_thread_client->ShouldInterceptRequestAsync( | |
| 59 request, | |
| 60 base::Bind(&AwRequestHandler::QueryForAwWebResourceResponseDone, this)); | |
| 61 return true; | |
| 62 } | |
| 63 | |
| 64 void AwRequestHandler::QueryForAwWebResourceResponseDone( | |
| 65 scoped_ptr<AwWebResourceResponse> response) { | |
| 66 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 67 if (!job_.get()) return; | |
|
mmenke
2015/09/29 15:56:05
job_ can't be NULL here - this should really just
mnaganov (inactive)
2015/09/29 23:45:35
Not relevant anymore.
| |
| 68 | |
| 69 if (response) { | |
| 70 // The job will own the AwWebResourceResponse. | |
| 71 AwWebResourceResponse::JobDeliverResponseFromEmbedder(job_.get(), | |
| 72 response.Pass()); | |
|
mmenke
2015/09/29 15:56:05
optional: This seems a bit roundabout. We're cal
mnaganov (inactive)
2015/09/29 23:45:35
Right. Perhaps there have been historical reasons,
| |
| 73 } else { | |
| 74 job_->DeliverResponseFromNetwork(); | |
|
mmenke
2015/09/29 15:56:05
BUG: The request could be cancelled by this point
mnaganov (inactive)
2015/09/29 23:45:35
Done.
| |
| 75 } | |
| 76 } | |
| 77 | |
| 78 } // namespace android_webview | |
| OLD | NEW |