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_network_delegate.h" | 5 #include "android_webview/browser/net/aw_network_delegate.h" |
6 | 6 |
7 #include "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
8 #include "android_webview/browser/aw_contents_client_bridge_base.h" | |
8 #include "android_webview/browser/aw_contents_io_thread_client.h" | 9 #include "android_webview/browser/aw_contents_io_thread_client.h" |
9 #include "android_webview/browser/aw_cookie_access_policy.h" | 10 #include "android_webview/browser/aw_cookie_access_policy.h" |
11 #include "android_webview/browser/net/aw_web_resource_request.h" | |
10 #include "base/android/build_info.h" | 12 #include "base/android/build_info.h" |
11 #include "components/policy/core/browser/url_blacklist_manager.h" | 13 #include "components/policy/core/browser/url_blacklist_manager.h" |
12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/resource_request_info.h" | 15 #include "content/public/browser/resource_request_info.h" |
14 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
15 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
16 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
17 #include "net/proxy/proxy_info.h" | 19 #include "net/proxy/proxy_info.h" |
18 #include "net/proxy/proxy_server.h" | 20 #include "net/proxy/proxy_server.h" |
19 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
20 | 22 |
23 using android_webview::AwContentsClientBridgeBase; | |
boliu
2016/12/08 05:48:38
you could put the anonymous namespace *inside* the
sgurun-gerrit only
2016/12/08 21:56:46
Done.
| |
24 using android_webview::AwWebResourceRequest; | |
21 using content::BrowserThread; | 25 using content::BrowserThread; |
22 | 26 |
27 namespace { | |
28 | |
29 void OnReceivedHttpErrorOnUiThread( | |
30 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | |
31 AwWebResourceRequest* request, | |
32 scoped_refptr<const net::HttpResponseHeaders> original_response_headers) { | |
33 AwContentsClientBridgeBase* client = | |
34 AwContentsClientBridgeBase::FromWebContentsGetter(web_contents_getter); | |
35 if (!client) | |
36 return; | |
37 client->OnReceivedHttpError(*request, original_response_headers); | |
38 } | |
39 | |
40 } // namespace | |
41 | |
23 namespace android_webview { | 42 namespace android_webview { |
24 | 43 |
25 AwNetworkDelegate::AwNetworkDelegate() : url_blacklist_manager_(nullptr) { | 44 AwNetworkDelegate::AwNetworkDelegate() : url_blacklist_manager_(nullptr) { |
26 } | 45 } |
27 | 46 |
28 AwNetworkDelegate::~AwNetworkDelegate() { | 47 AwNetworkDelegate::~AwNetworkDelegate() { |
29 } | 48 } |
30 | 49 |
31 int AwNetworkDelegate::OnBeforeURLRequest( | 50 int AwNetworkDelegate::OnBeforeURLRequest( |
32 net::URLRequest* request, | 51 net::URLRequest* request, |
(...skipping 24 matching lines...) Expand all Loading... | |
57 net::URLRequest* request, | 76 net::URLRequest* request, |
58 const net::HttpRequestHeaders& headers) {} | 77 const net::HttpRequestHeaders& headers) {} |
59 | 78 |
60 int AwNetworkDelegate::OnHeadersReceived( | 79 int AwNetworkDelegate::OnHeadersReceived( |
61 net::URLRequest* request, | 80 net::URLRequest* request, |
62 const net::CompletionCallback& callback, | 81 const net::CompletionCallback& callback, |
63 const net::HttpResponseHeaders* original_response_headers, | 82 const net::HttpResponseHeaders* original_response_headers, |
64 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 83 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
65 GURL* allowed_unsafe_redirect_url) { | 84 GURL* allowed_unsafe_redirect_url) { |
66 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 85 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
67 int render_process_id, render_frame_id; | 86 if (original_response_headers->response_code() >= 400) { |
68 if (original_response_headers->response_code() >= 400 && | 87 const content::ResourceRequestInfo* request_info = |
69 content::ResourceRequestInfo::GetRenderFrameForRequest( | 88 content::ResourceRequestInfo::ForRequest(request); |
70 request, &render_process_id, &render_frame_id)) { | 89 std::unique_ptr<AwWebResourceRequest> web_request( |
71 std::unique_ptr<AwContentsIoThreadClient> io_thread_client = | 90 new AwWebResourceRequest(request)); |
72 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); | 91 // keep a ref before binding and posting to UI thread. |
73 if (io_thread_client.get()) { | 92 scoped_refptr<const net::HttpResponseHeaders> response_headers( |
74 io_thread_client->OnReceivedHttpError(request, original_response_headers); | 93 original_response_headers); |
75 } | 94 BrowserThread::PostTask( |
95 BrowserThread::UI, FROM_HERE, | |
96 base::Bind(&OnReceivedHttpErrorOnUiThread, | |
97 request_info->GetWebContentsGetterForRequest(), | |
98 base::Owned(web_request.release()), response_headers)); | |
boliu
2016/12/08 05:48:38
do MakeUnique<AwWebResourceRequest>(request) here,
sgurun-gerrit only
2016/12/08 21:56:46
Done.
| |
76 } | 99 } |
77 return net::OK; | 100 return net::OK; |
78 } | 101 } |
79 | 102 |
80 void AwNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, | 103 void AwNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, |
81 const GURL& new_location) { | 104 const GURL& new_location) { |
82 } | 105 } |
83 | 106 |
84 void AwNetworkDelegate::OnResponseStarted(net::URLRequest* request, | 107 void AwNetworkDelegate::OnResponseStarted(net::URLRequest* request, |
85 int net_error) {} | 108 int net_error) {} |
(...skipping 30 matching lines...) Expand all Loading... | |
116 cookie_line, | 139 cookie_line, |
117 options); | 140 options); |
118 } | 141 } |
119 | 142 |
120 bool AwNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, | 143 bool AwNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, |
121 const base::FilePath& path) const { | 144 const base::FilePath& path) const { |
122 return true; | 145 return true; |
123 } | 146 } |
124 | 147 |
125 } // namespace android_webview | 148 } // namespace android_webview |
OLD | NEW |