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