Chromium Code Reviews| 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/net/aw_request_interceptor.h" | 5 #include "android_webview/browser/net/aw_request_interceptor.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "android_webview/browser/aw_contents_io_thread_client.h" | 9 #include "android_webview/browser/aw_contents_io_thread_client.h" |
| 10 #include "android_webview/browser/input_stream.h" | 10 #include "android_webview/browser/input_stream.h" |
| 11 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" | 11 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" |
| 12 #include "android_webview/browser/net/aw_web_resource_response.h" | 12 #include "android_webview/browser/net/aw_web_resource_response.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/supports_user_data.h" | 16 #include "base/supports_user_data.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/resource_request_info.h" | 18 #include "content/public/browser/resource_request_info.h" |
| 19 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
| 20 #include "net/url_request/url_request_job.h" | 20 #include "net/url_request/url_request_job.h" |
| 21 #include "url/url_constants.h" | |
| 21 | 22 |
| 22 namespace android_webview { | 23 namespace android_webview { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const void* const kRequestAlreadyHasJobDataKey = &kRequestAlreadyHasJobDataKey; | 27 const void* const kRequestAlreadyHasJobDataKey = &kRequestAlreadyHasJobDataKey; |
| 27 | 28 |
| 28 class StreamReaderJobDelegateImpl | 29 class StreamReaderJobDelegateImpl |
| 29 : public AndroidStreamReaderURLRequestJob::Delegate { | 30 : public AndroidStreamReaderURLRequestJob::Delegate { |
| 30 public: | 31 public: |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 Callback callback_; | 113 Callback callback_; |
| 113 base::WeakPtrFactory<ShouldInterceptRequestAdaptor> weak_factory_; | 114 base::WeakPtrFactory<ShouldInterceptRequestAdaptor> weak_factory_; |
| 114 | 115 |
| 115 DISALLOW_COPY_AND_ASSIGN(ShouldInterceptRequestAdaptor); | 116 DISALLOW_COPY_AND_ASSIGN(ShouldInterceptRequestAdaptor); |
| 116 }; | 117 }; |
| 117 | 118 |
| 118 std::unique_ptr<AwContentsIoThreadClient> GetCorrespondingIoThreadClient( | 119 std::unique_ptr<AwContentsIoThreadClient> GetCorrespondingIoThreadClient( |
| 119 net::URLRequest* request) { | 120 net::URLRequest* request) { |
| 120 if (content::ResourceRequestInfo::OriginatedFromServiceWorker(request)) | 121 if (content::ResourceRequestInfo::OriginatedFromServiceWorker(request)) |
| 121 return AwContentsIoThreadClient::GetServiceWorkerIoThreadClient(); | 122 return AwContentsIoThreadClient::GetServiceWorkerIoThreadClient(); |
| 122 | |
| 123 int render_process_id, render_frame_id; | 123 int render_process_id, render_frame_id; |
| 124 if (!content::ResourceRequestInfo::GetRenderFrameForRequest( | 124 if (!content::ResourceRequestInfo::GetRenderFrameForRequest( |
| 125 request, &render_process_id, &render_frame_id)) { | 125 request, &render_process_id, &render_frame_id)) { |
| 126 return nullptr; | 126 return nullptr; |
| 127 } | 127 } |
| 128 | 128 |
| 129 if (render_process_id == -1 || render_frame_id == -1) { | |
|
jam
2017/03/09 22:13:05
since this block (and rest of method) is duplicate
jam
2017/03/10 17:08:44
Ok ignore this comment, I looked through the usage
sgurun-gerrit only
2017/03/10 18:40:58
Acknowledged.
| |
| 130 const content::ResourceRequestInfo* resourceRequestInfo = | |
| 131 content::ResourceRequestInfo::ForRequest(request); | |
| 132 if (resourceRequestInfo == nullptr) { | |
| 133 return nullptr; | |
| 134 } | |
| 135 return AwContentsIoThreadClient::FromID( | |
| 136 resourceRequestInfo->GetFrameTreeNodeId()); | |
| 137 } | |
| 138 | |
| 129 return AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); | 139 return AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); |
| 130 } | 140 } |
| 131 | 141 |
| 132 } // namespace | 142 } // namespace |
| 133 | 143 |
| 134 AwRequestInterceptor::AwRequestInterceptor() {} | 144 AwRequestInterceptor::AwRequestInterceptor() {} |
| 135 | 145 |
| 136 AwRequestInterceptor::~AwRequestInterceptor() {} | 146 AwRequestInterceptor::~AwRequestInterceptor() {} |
| 137 | 147 |
| 138 net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest( | 148 net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest( |
| 139 net::URLRequest* request, | 149 net::URLRequest* request, |
| 140 net::NetworkDelegate* network_delegate) const { | 150 net::NetworkDelegate* network_delegate) const { |
| 141 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 151 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 142 | 152 |
| 143 // MaybeInterceptRequest can be called multiple times for the same request. | 153 // MaybeInterceptRequest can be called multiple times for the same request. |
| 144 if (request->GetUserData(kRequestAlreadyHasJobDataKey)) | 154 if (request->GetUserData(kRequestAlreadyHasJobDataKey)) |
| 145 return nullptr; | 155 return nullptr; |
| 146 | 156 |
| 157 if (request->url().SchemeIs(url::kBlobScheme)) { | |
|
jam
2017/03/09 22:13:05
comment?
sgurun-gerrit only
2017/03/10 18:40:58
Done.
| |
| 158 return nullptr; | |
| 159 } | |
| 160 | |
| 147 std::unique_ptr<AwContentsIoThreadClient> io_thread_client = | 161 std::unique_ptr<AwContentsIoThreadClient> io_thread_client = |
| 148 GetCorrespondingIoThreadClient(request); | 162 GetCorrespondingIoThreadClient(request); |
| 149 | 163 |
| 150 if (!io_thread_client) | 164 if (!io_thread_client) |
| 151 return nullptr; | 165 return nullptr; |
| 152 | 166 |
| 153 GURL referrer(request->referrer()); | 167 GURL referrer(request->referrer()); |
| 154 if (referrer.is_valid() && | 168 if (referrer.is_valid() && |
| 155 (!request->is_pending() || request->is_redirecting())) { | 169 (!request->is_pending() || request->is_redirecting())) { |
| 156 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kReferer, | 170 request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kReferer, |
| 157 referrer.spec(), true); | 171 referrer.spec(), true); |
| 158 } | 172 } |
| 159 request->SetUserData(kRequestAlreadyHasJobDataKey, | 173 request->SetUserData(kRequestAlreadyHasJobDataKey, |
| 160 new base::SupportsUserData::Data()); | 174 new base::SupportsUserData::Data()); |
| 161 return new AndroidStreamReaderURLRequestJob( | 175 return new AndroidStreamReaderURLRequestJob( |
| 162 request, network_delegate, | 176 request, network_delegate, |
| 163 base::MakeUnique<ShouldInterceptRequestAdaptor>( | 177 base::MakeUnique<ShouldInterceptRequestAdaptor>( |
| 164 std::move(io_thread_client)), | 178 std::move(io_thread_client)), |
| 165 true); | 179 true); |
| 166 } | 180 } |
| 167 | 181 |
| 168 } // namespace android_webview | 182 } // namespace android_webview |
| OLD | NEW |