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