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

Side by Side Diff: android_webview/browser/net/aw_network_delegate.cc

Issue 2579533003: Reland Move onReceivedError and onReceivedHttpError out of AwContentsIoThreadClientImpl (Closed)
Patch Set: Added null checks and some service worker tests Created 4 years 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/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 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 DLOG(WARNING) << "client is null, onReceivedHttpError dropped for "
37 << request.url;
38 return;
39 }
40 client->OnReceivedHttpError(request, original_response_headers);
41 }
42
43 } // namespace
44
25 AwNetworkDelegate::AwNetworkDelegate() : url_blacklist_manager_(nullptr) { 45 AwNetworkDelegate::AwNetworkDelegate() : url_blacklist_manager_(nullptr) {
26 } 46 }
27 47
28 AwNetworkDelegate::~AwNetworkDelegate() { 48 AwNetworkDelegate::~AwNetworkDelegate() {
29 } 49 }
30 50
31 int AwNetworkDelegate::OnBeforeURLRequest( 51 int AwNetworkDelegate::OnBeforeURLRequest(
32 net::URLRequest* request, 52 net::URLRequest* request,
33 const net::CompletionCallback& callback, 53 const net::CompletionCallback& callback,
34 GURL* new_url) { 54 GURL* new_url) {
(...skipping 22 matching lines...) Expand all
57 net::URLRequest* request, 77 net::URLRequest* request,
58 const net::HttpRequestHeaders& headers) {} 78 const net::HttpRequestHeaders& headers) {}
59 79
60 int AwNetworkDelegate::OnHeadersReceived( 80 int AwNetworkDelegate::OnHeadersReceived(
61 net::URLRequest* request, 81 net::URLRequest* request,
62 const net::CompletionCallback& callback, 82 const net::CompletionCallback& callback,
63 const net::HttpResponseHeaders* original_response_headers, 83 const net::HttpResponseHeaders* original_response_headers,
64 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, 84 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
65 GURL* allowed_unsafe_redirect_url) { 85 GURL* allowed_unsafe_redirect_url) {
66 DCHECK_CURRENTLY_ON(BrowserThread::IO); 86 DCHECK_CURRENTLY_ON(BrowserThread::IO);
67 int render_process_id, render_frame_id; 87 if (original_response_headers->response_code() >= 400) {
68 if (original_response_headers->response_code() >= 400 && 88 const content::ResourceRequestInfo* request_info =
69 content::ResourceRequestInfo::GetRenderFrameForRequest( 89 content::ResourceRequestInfo::ForRequest(request);
70 request, &render_process_id, &render_frame_id)) { 90 // A request info may not exist for requests not originating from content.
71 std::unique_ptr<AwContentsIoThreadClient> io_thread_client = 91 if (request_info == nullptr)
72 AwContentsIoThreadClient::FromID(render_process_id, render_frame_id); 92 return net::OK;
73 if (io_thread_client.get()) { 93 // keep a ref before binding and posting to UI thread.
74 io_thread_client->OnReceivedHttpError(request, original_response_headers); 94 scoped_refptr<const net::HttpResponseHeaders> response_headers(
75 } 95 original_response_headers);
96 BrowserThread::PostTask(
97 BrowserThread::UI, FROM_HERE,
98 base::Bind(&OnReceivedHttpErrorOnUiThread,
99 request_info->GetWebContentsGetterForRequest(),
100 AwWebResourceRequest(*request), response_headers));
76 } 101 }
77 return net::OK; 102 return net::OK;
78 } 103 }
79 104
80 void AwNetworkDelegate::OnBeforeRedirect(net::URLRequest* request, 105 void AwNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
81 const GURL& new_location) { 106 const GURL& new_location) {
82 } 107 }
83 108
84 void AwNetworkDelegate::OnResponseStarted(net::URLRequest* request, 109 void AwNetworkDelegate::OnResponseStarted(net::URLRequest* request,
85 int net_error) {} 110 int net_error) {}
(...skipping 30 matching lines...) Expand all
116 cookie_line, 141 cookie_line,
117 options); 142 options);
118 } 143 }
119 144
120 bool AwNetworkDelegate::OnCanAccessFile(const net::URLRequest& request, 145 bool AwNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
121 const base::FilePath& path) const { 146 const base::FilePath& path) const {
122 return true; 147 return true;
123 } 148 }
124 149
125 } // namespace android_webview 150 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698