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

Side by Side Diff: android_webview/native/android_protocol_handler.cc

Issue 686343002: Add MaybeInterceptRedirect/Response to URLRequestInterceptor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests, removed DRP Created 6 years, 1 month 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/native/android_protocol_handler.h" 5 #include "android_webview/native/android_protocol_handler.h"
6 6
7 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" 7 #include "android_webview/browser/net/android_stream_reader_url_request_job.h"
8 #include "android_webview/browser/net/aw_url_request_job_factory.h" 8 #include "android_webview/browser/net/aw_url_request_job_factory.h"
9 #include "android_webview/common/url_constants.h" 9 #include "android_webview/common/url_constants.h"
10 #include "android_webview/native/input_stream_impl.h" 10 #include "android_webview/native/input_stream_impl.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 JNIEnv* env, 81 JNIEnv* env,
82 net::HttpResponseHeaders* headers) override; 82 net::HttpResponseHeaders* headers) override;
83 83
84 virtual ~AndroidStreamReaderURLRequestJobDelegateImpl(); 84 virtual ~AndroidStreamReaderURLRequestJobDelegateImpl();
85 }; 85 };
86 86
87 class AndroidRequestInterceptorBase : public net::URLRequestInterceptor { 87 class AndroidRequestInterceptorBase : public net::URLRequestInterceptor {
88 public: 88 public:
89 virtual net::URLRequestJob* MaybeInterceptRequest( 89 virtual net::URLRequestJob* MaybeInterceptRequest(
90 net::URLRequest* request, 90 net::URLRequest* request,
91 net::NetworkDelegate* network_delegate) const override; 91 net::NetworkDelegate* network_delegate) override;
92
93 virtual net::URLRequestJob* MaybeInterceptRedirect(
94 net::URLRequest* request,
95 net::NetworkDelegate* network_delegate,
96 const GURL& location) override;
97
98 virtual net::URLRequestJob* MaybeInterceptResponse(
99 net::URLRequest* request,
100 net::NetworkDelegate* network_delegate) override;
92 101
93 virtual bool ShouldHandleRequest(const net::URLRequest* request) const = 0; 102 virtual bool ShouldHandleRequest(const net::URLRequest* request) const = 0;
94 }; 103 };
95 104
96 class AssetFileRequestInterceptor : public AndroidRequestInterceptorBase { 105 class AssetFileRequestInterceptor : public AndroidRequestInterceptorBase {
97 public: 106 public:
98 AssetFileRequestInterceptor(); 107 AssetFileRequestInterceptor();
99 108
100 virtual ~AssetFileRequestInterceptor() override; 109 virtual ~AssetFileRequestInterceptor() override;
101 virtual bool ShouldHandleRequest( 110 virtual bool ShouldHandleRequest(
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 void AndroidStreamReaderURLRequestJobDelegateImpl::AppendResponseHeaders( 214 void AndroidStreamReaderURLRequestJobDelegateImpl::AppendResponseHeaders(
206 JNIEnv* env, 215 JNIEnv* env,
207 net::HttpResponseHeaders* headers) { 216 net::HttpResponseHeaders* headers) {
208 // no-op 217 // no-op
209 } 218 }
210 219
211 // AndroidRequestInterceptorBase ---------------------------------------------- 220 // AndroidRequestInterceptorBase ----------------------------------------------
212 221
213 net::URLRequestJob* AndroidRequestInterceptorBase::MaybeInterceptRequest( 222 net::URLRequestJob* AndroidRequestInterceptorBase::MaybeInterceptRequest(
214 net::URLRequest* request, 223 net::URLRequest* request,
215 net::NetworkDelegate* network_delegate) const { 224 net::NetworkDelegate* network_delegate) {
216 if (!ShouldHandleRequest(request)) 225 if (!ShouldHandleRequest(request))
217 return NULL; 226 return NULL;
218 227
219 // For WebViewClassic compatibility this job can only accept URLs that can be 228 // For WebViewClassic compatibility this job can only accept URLs that can be
220 // opened. URLs that cannot be opened should be resolved by the next handler. 229 // opened. URLs that cannot be opened should be resolved by the next handler.
221 // 230 //
222 // If a request is initially handled here but the job fails due to it being 231 // If a request is initially handled here but the job fails due to it being
223 // unable to open the InputStream for that request the request is marked as 232 // unable to open the InputStream for that request the request is marked as
224 // previously failed and restarted. 233 // previously failed and restarted.
225 // Restarting a request involves creating a new job for that request. This 234 // Restarting a request involves creating a new job for that request. This
226 // handler will ignore requests know to have previously failed to 1) prevent 235 // handler will ignore requests know to have previously failed to 1) prevent
227 // an infinite loop, 2) ensure that the next handler in line gets the 236 // an infinite loop, 2) ensure that the next handler in line gets the
228 // opportunity to create a job for the request. 237 // opportunity to create a job for the request.
229 if (HasRequestPreviouslyFailed(request)) 238 if (HasRequestPreviouslyFailed(request))
230 return NULL; 239 return NULL;
231 240
232 scoped_ptr<AndroidStreamReaderURLRequestJobDelegateImpl> reader_delegate( 241 scoped_ptr<AndroidStreamReaderURLRequestJobDelegateImpl> reader_delegate(
233 new AndroidStreamReaderURLRequestJobDelegateImpl()); 242 new AndroidStreamReaderURLRequestJobDelegateImpl());
234 243
235 return new AndroidStreamReaderURLRequestJob( 244 return new AndroidStreamReaderURLRequestJob(
236 request, network_delegate, reader_delegate.Pass()); 245 request, network_delegate, reader_delegate.Pass());
237 } 246 }
238 247
248 net::URLRequestJob* AndroidRequestInterceptorBase::MaybeInterceptRedirect(
249 net::URLRequest* request,
250 net::NetworkDelegate* network_delegate,
251 const GURL& location) {
252 return NULL;
253 }
254
255 net::URLRequestJob* AndroidRequestInterceptorBase::MaybeInterceptResponse(
256 net::URLRequest* request,
257 net::NetworkDelegate* network_delegate) {
258 return NULL;
259 }
260
239 // AssetFileRequestInterceptor ------------------------------------------------ 261 // AssetFileRequestInterceptor ------------------------------------------------
240 262
241 AssetFileRequestInterceptor::AssetFileRequestInterceptor() 263 AssetFileRequestInterceptor::AssetFileRequestInterceptor()
242 : asset_prefix_(std::string(url::kFileScheme) + 264 : asset_prefix_(std::string(url::kFileScheme) +
243 std::string(url::kStandardSchemeSeparator) + 265 std::string(url::kStandardSchemeSeparator) +
244 android_webview::kAndroidAssetPath), 266 android_webview::kAndroidAssetPath),
245 resource_prefix_(std::string(url::kFileScheme) + 267 resource_prefix_(std::string(url::kFileScheme) +
246 std::string(url::kStandardSchemeSeparator) + 268 std::string(url::kStandardSchemeSeparator) +
247 android_webview::kAndroidResourcePath) { 269 android_webview::kAndroidResourcePath) {
248 } 270 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 env, android_webview::kAndroidAssetPath).Release(); 339 env, android_webview::kAndroidAssetPath).Release();
318 } 340 }
319 341
320 static jstring GetAndroidResourcePath(JNIEnv* env, jclass /*clazz*/) { 342 static jstring GetAndroidResourcePath(JNIEnv* env, jclass /*clazz*/) {
321 // OK to release, JNI binding. 343 // OK to release, JNI binding.
322 return ConvertUTF8ToJavaString( 344 return ConvertUTF8ToJavaString(
323 env, android_webview::kAndroidResourcePath).Release(); 345 env, android_webview::kAndroidResourcePath).Release();
324 } 346 }
325 347
326 } // namespace android_webview 348 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698