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

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

Issue 1001003004: [Android WebView] Implement a better OnReceivedError callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed the last comment Created 5 years, 9 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/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/aw_web_resource_response.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
29 } // namespace 29 } // namespace
30 30
31 AwRequestInterceptor::AwRequestInterceptor() { 31 AwRequestInterceptor::AwRequestInterceptor() {
32 } 32 }
33 33
34 AwRequestInterceptor::~AwRequestInterceptor() { 34 AwRequestInterceptor::~AwRequestInterceptor() {
35 } 35 }
36 36
37 scoped_ptr<AwWebResourceResponse> 37 scoped_ptr<AwWebResourceResponse>
38 AwRequestInterceptor::QueryForAwWebResourceResponse( 38 AwRequestInterceptor::QueryForAwWebResourceResponse(
39 const GURL& location,
40 net::URLRequest* request) const { 39 net::URLRequest* request) const {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
42 int render_process_id, render_frame_id; 41 int render_process_id, render_frame_id;
43 if (!ResourceRequestInfo::GetRenderFrameForRequest( 42 if (!ResourceRequestInfo::GetRenderFrameForRequest(
44 request, &render_process_id, &render_frame_id)) 43 request, &render_process_id, &render_frame_id))
45 return scoped_ptr<AwWebResourceResponse>(); 44 return scoped_ptr<AwWebResourceResponse>();
46 45
47 scoped_ptr<AwContentsIoThreadClient> io_thread_client = 46 scoped_ptr<AwContentsIoThreadClient> io_thread_client =
48 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); 47 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id);
49 48
50 if (!io_thread_client.get()) 49 if (!io_thread_client.get())
51 return scoped_ptr<AwWebResourceResponse>(); 50 return scoped_ptr<AwWebResourceResponse>();
52 51
53 return io_thread_client->ShouldInterceptRequest(location, request).Pass(); 52 return io_thread_client->ShouldInterceptRequest(request).Pass();
54 } 53 }
55 54
56 net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest( 55 net::URLRequestJob* AwRequestInterceptor::MaybeInterceptRequest(
57 net::URLRequest* request, 56 net::URLRequest* request,
58 net::NetworkDelegate* network_delegate) const { 57 net::NetworkDelegate* network_delegate) const {
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
60 59
61 // See if we've already found out the aw_web_resource_response for this 60 // See if we've already found out the aw_web_resource_response for this
62 // request. 61 // request.
63 // This is done not only for efficiency reasons, but also for correctness 62 // This is done not only for efficiency reasons, but also for correctness
64 // as it is possible for the Interceptor chain to be invoked more than once 63 // as it is possible for the Interceptor chain to be invoked more than once
65 // in which case we don't want to query the embedder multiple times. 64 // in which case we don't want to query the embedder multiple times.
66 // Note: The Interceptor chain is not invoked more than once if we create a 65 // Note: The Interceptor chain is not invoked more than once if we create a
67 // URLRequestJob in this method, so this is only caching negative hits. 66 // URLRequestJob in this method, so this is only caching negative hits.
68 if (request->GetUserData(kRequestAlreadyQueriedDataKey)) 67 if (request->GetUserData(kRequestAlreadyQueriedDataKey))
69 return NULL; 68 return NULL;
70 request->SetUserData(kRequestAlreadyQueriedDataKey, 69 request->SetUserData(kRequestAlreadyQueriedDataKey,
71 new base::SupportsUserData::Data()); 70 new base::SupportsUserData::Data());
72 71
73 scoped_ptr<AwWebResourceResponse> aw_web_resource_response = 72 scoped_ptr<AwWebResourceResponse> aw_web_resource_response =
74 QueryForAwWebResourceResponse(request->url(), request); 73 QueryForAwWebResourceResponse(request);
75 74
76 if (!aw_web_resource_response) 75 if (!aw_web_resource_response)
77 return NULL; 76 return NULL;
78 77
79 // The newly created job will own the AwWebResourceResponse. 78 // The newly created job will own the AwWebResourceResponse.
80 return AwWebResourceResponse::CreateJobFor( 79 return AwWebResourceResponse::CreateJobFor(
81 aw_web_resource_response.Pass(), request, network_delegate); 80 aw_web_resource_response.Pass(), request, network_delegate);
82 } 81 }
83 82
84 } // namespace android_webview 83 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698