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

Side by Side Diff: android_webview/browser/net/aw_request_interceptor.cc

Issue 1350553005: [Android WebView] Call shouldInterceptRequest on a background thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed indent in AwStreamReaderJobDelegateImpl 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
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_request_interceptor.h" 5 #include "android_webview/browser/net/aw_request_interceptor.h"
6 6
7 #include "android_webview/browser/aw_contents_io_thread_client.h" 7 #include "android_webview/browser/aw_contents_io_thread_client.h"
8 #include "android_webview/browser/aw_web_resource_response.h" 8 #include "android_webview/browser/net/aw_stream_reader_job_delegate_impl.h"
9 #include "base/android/jni_string.h" 9 #include "base/supports_user_data.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/resource_request_info.h" 11 #include "content/public/browser/resource_request_info.h"
14 #include "net/url_request/url_request.h"
15 #include "net/url_request/url_request_context.h"
16 #include "net/url_request/url_request_context_getter.h"
17 #include "net/url_request/url_request_job.h" 12 #include "net/url_request/url_request_job.h"
18 13
19 using content::BrowserThread;
20 using content::RenderViewHost;
21 using content::ResourceRequestInfo;
22
23 namespace android_webview { 14 namespace android_webview {
24 15
25 namespace { 16 namespace {
26 17
27 const void* const kRequestAlreadyQueriedDataKey = 18 const void* const kRequestAlreadyHasJobDataKey = &kRequestAlreadyHasJobDataKey;
28 &kRequestAlreadyQueriedDataKey;
29 19
30 } // namespace 20 } // namespace
31 21
32 AwRequestInterceptor::AwRequestInterceptor() { 22 AwRequestInterceptor::AwRequestInterceptor() {
33 } 23 }
34 24
35 AwRequestInterceptor::~AwRequestInterceptor() { 25 AwRequestInterceptor::~AwRequestInterceptor() {
36 } 26 }
37 27
38 scoped_ptr<AwWebResourceResponse> 28 net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest(
39 AwRequestInterceptor::QueryForAwWebResourceResponse( 29 net::URLRequest* request,
40 net::URLRequest* request) const { 30 net::NetworkDelegate* network_delegate) const {
41 DCHECK_CURRENTLY_ON(BrowserThread::IO); 31 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
32
33 if (request->GetUserData(kRequestAlreadyHasJobDataKey))
34 return nullptr;
35
42 int render_process_id, render_frame_id; 36 int render_process_id, render_frame_id;
43 if (!ResourceRequestInfo::GetRenderFrameForRequest( 37 if (!content::ResourceRequestInfo::GetRenderFrameForRequest(
44 request, &render_process_id, &render_frame_id)) 38 request, &render_process_id, &render_frame_id)) {
45 return scoped_ptr<AwWebResourceResponse>(); 39 return nullptr;
40 }
46 41
47 scoped_ptr<AwContentsIoThreadClient> io_thread_client = 42 scoped_ptr<AwContentsIoThreadClient> io_thread_client =
48 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); 43 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id);
49 44
50 if (!io_thread_client.get()) 45 if (!io_thread_client)
51 return scoped_ptr<AwWebResourceResponse>(); 46 return nullptr;
52 47
53 GURL referrer(request->referrer()); 48 GURL referrer(request->referrer());
54 if (referrer.is_valid() && 49 if (referrer.is_valid() &&
55 (!request->is_pending() || request->is_redirecting())) { 50 (!request->is_pending() || request->is_redirecting())) {
56 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kReferer, 51 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kReferer,
57 referrer.spec(), true); 52 referrer.spec(), true);
58 } 53 }
59 return io_thread_client->ShouldInterceptRequest(request).Pass(); 54 AndroidStreamReaderURLRequestJob* job =
60 } 55 new AndroidStreamReaderURLRequestJob(request, network_delegate);
61 56 request->SetUserData(kRequestAlreadyHasJobDataKey,
62 net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest(
63 net::URLRequest* request,
64 net::NetworkDelegate* network_delegate) const {
65 DCHECK_CURRENTLY_ON(BrowserThread::IO);
66
67 // See if we've already found out the aw_web_resource_response for this
boliu 2015/09/30 00:43:20 keep this comment?
mnaganov (inactive) 2015/09/30 18:05:30 Well, it's not valid anymore -- we now always crea
boliu 2015/09/30 18:06:19 Right, that part :p
68 // request.
69 // This is done not only for efficiency reasons, but also for correctness
70 // as it is possible for the Interceptor chain to be invoked more than once
71 // in which case we don't want to query the embedder multiple times.
72 // Note: The Interceptor chain is not invoked more than once if we create a
73 // URLRequestJob in this method, so this is only caching negative hits.
74 if (request->GetUserData(kRequestAlreadyQueriedDataKey))
75 return NULL;
76 request->SetUserData(kRequestAlreadyQueriedDataKey,
77 new base::SupportsUserData::Data()); 57 new base::SupportsUserData::Data());
78 58 io_thread_client->ShouldInterceptRequestAsync(
79 scoped_ptr<AwWebResourceResponse> aw_web_resource_response = 59 request, job->GetWebResourceResponseCallback());
80 QueryForAwWebResourceResponse(request); 60 return job;
81
82 if (!aw_web_resource_response)
83 return NULL;
84
85 // The newly created job will own the AwWebResourceResponse.
86 return AwWebResourceResponse::CreateJobFor(
87 aw_web_resource_response.Pass(), request, network_delegate);
88 } 61 }
89 62
90 } // namespace android_webview 63 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698