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

Side by Side Diff: android_webview/browser/aw_request_handler.cc

Issue 1350553005: [Android WebView] Call shouldInterceptRequest on a background thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final version? Created 5 years, 2 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
OLDNEW
(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 }
21
22 AndroidStreamReaderURLRequestJob* AwRequestHandler::MaybeInterceptRequest(
23 net::URLRequest* request,
24 net::NetworkDelegate* network_delegate) {
25 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
26 if (job_.get()) return nullptr;
boliu 2015/09/28 23:26:28 This probably deserves a comment. I think this is
mnaganov (inactive) 2015/09/29 00:14:06 Done.
27
28 if (!QueryForAwWebResourceResponse(request))
29 return nullptr;
30 job_ = new AndroidStreamReaderURLRequestJob(request, network_delegate);
31 return job_.get();
32 }
33
34 bool AwRequestHandler::QueryForAwWebResourceResponse(net::URLRequest* request) {
35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
36
37 int render_process_id, render_frame_id;
38 if (!content::ResourceRequestInfo::GetRenderFrameForRequest(
39 request, &render_process_id, &render_frame_id)) {
40 return false;
41 }
42
43 scoped_ptr<AwContentsIoThreadClient> io_thread_client =
44 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id);
45
46 if (!io_thread_client.get())
47 return false;
48
49 GURL referrer(request->referrer());
50 if (referrer.is_valid() &&
51 (!request->is_pending() || request->is_redirecting())) {
52 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kReferer,
53 referrer.spec(), true);
54 }
55 io_thread_client->ShouldInterceptRequestAsync(
56 request,
57 base::Bind(&AwRequestHandler::QueryForAwWebResourceResponseDone, this));
58 return true;
59 }
60
61 void AwRequestHandler::QueryForAwWebResourceResponseDone(
62 scoped_ptr<AwWebResourceResponse> response) {
63 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
64 if (!job_.get()) return;
65
66 if (response) {
67 // The job will own the AwWebResourceResponse.
68 AwWebResourceResponse::JobDeliverResponseFromEmbedder(job_.get(),
69 response.Pass());
70 } else {
71 job_->DeliverResponseFromNetwork();
72 }
73 }
74
75 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698