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/renderer_host/aw_resource_dispatcher_host_dele gate.h" | 5 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele gate.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "android_webview/browser/aw_browser_context.h" | 10 #include "android_webview/browser/aw_browser_context.h" |
11 #include "android_webview/browser/aw_contents_client_bridge_base.h" | 11 #include "android_webview/browser/aw_contents_client_bridge_base.h" |
12 #include "android_webview/browser/aw_contents_io_thread_client.h" | 12 #include "android_webview/browser/aw_contents_io_thread_client.h" |
13 #include "android_webview/browser/aw_login_delegate.h" | 13 #include "android_webview/browser/aw_login_delegate.h" |
14 #include "android_webview/browser/aw_resource_context.h" | 14 #include "android_webview/browser/aw_resource_context.h" |
15 #include "android_webview/browser/net/aw_web_resource_request.h" | |
15 #include "android_webview/browser/renderer_host/auto_login_parser.h" | 16 #include "android_webview/browser/renderer_host/auto_login_parser.h" |
16 #include "android_webview/common/url_constants.h" | 17 #include "android_webview/common/url_constants.h" |
17 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
18 #include "components/navigation_interception/intercept_navigation_delegate.h" | 19 #include "components/navigation_interception/intercept_navigation_delegate.h" |
19 #include "components/web_restrictions/browser/web_restrictions_resource_throttle .h" | 20 #include "components/web_restrictions/browser/web_restrictions_resource_throttle .h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/resource_dispatcher_host.h" | 22 #include "content/public/browser/resource_dispatcher_host.h" |
22 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 23 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
23 #include "content/public/browser/resource_request_info.h" | 24 #include "content/public/browser/resource_request_info.h" |
24 #include "content/public/browser/resource_throttle.h" | 25 #include "content/public/browser/resource_throttle.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
28 #include "net/http/http_response_headers.h" | 29 #include "net/http/http_response_headers.h" |
29 #include "net/url_request/url_request.h" | 30 #include "net/url_request/url_request.h" |
30 #include "net/url_request/url_request_status.h" | 31 #include "net/url_request/url_request_status.h" |
31 #include "url/url_constants.h" | 32 #include "url/url_constants.h" |
32 | 33 |
33 using android_webview::AwContentsIoThreadClient; | 34 using android_webview::AwContentsIoThreadClient; |
34 using android_webview::AwContentsClientBridgeBase; | 35 using android_webview::AwContentsClientBridgeBase; |
36 using android_webview::AwWebResourceRequest; | |
35 using content::BrowserThread; | 37 using content::BrowserThread; |
36 using content::ResourceType; | 38 using content::ResourceType; |
37 using content::WebContents; | 39 using content::WebContents; |
38 using navigation_interception::InterceptNavigationDelegate; | 40 using navigation_interception::InterceptNavigationDelegate; |
39 | 41 |
40 namespace { | 42 namespace { |
41 | 43 |
42 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate> | 44 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate> |
43 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER; | 45 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER; |
44 | 46 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 const std::string& realm, | 79 const std::string& realm, |
78 const std::string& account, | 80 const std::string& account, |
79 const std::string& args) { | 81 const std::string& args) { |
80 AwContentsClientBridgeBase* client = | 82 AwContentsClientBridgeBase* client = |
81 AwContentsClientBridgeBase::FromWebContentsGetter(web_contents_getter); | 83 AwContentsClientBridgeBase::FromWebContentsGetter(web_contents_getter); |
82 if (!client) | 84 if (!client) |
83 return; | 85 return; |
84 client->NewLoginRequest(realm, account, args); | 86 client->NewLoginRequest(realm, account, args); |
85 } | 87 } |
86 | 88 |
89 void OnReceivedErrorOnUiThread( | |
90 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, | |
91 AwWebResourceRequest* request, | |
92 int error_code) { | |
93 AwContentsClientBridgeBase* client = | |
94 AwContentsClientBridgeBase::FromWebContentsGetter(web_contents_getter); | |
95 if (!client) { | |
96 DLOG(WARNING) << "io_client is null, onReceivedError dropped for " | |
97 << request->url; | |
98 return; | |
99 } | |
100 client->OnReceivedError(*request, error_code); | |
101 } | |
102 | |
87 } // namespace | 103 } // namespace |
88 | 104 |
89 namespace android_webview { | 105 namespace android_webview { |
90 | 106 |
91 // Calls through the IoThreadClient to check the embedders settings to determine | 107 // Calls through the IoThreadClient to check the embedders settings to determine |
92 // if the request should be cancelled. There may not always be an IoThreadClient | 108 // if the request should be cancelled. There may not always be an IoThreadClient |
93 // available for the |render_process_id|, |render_frame_id| pair (in the case of | 109 // available for the |render_process_id|, |render_frame_id| pair (in the case of |
94 // newly created pop up windows, for example) and in that case the request and | 110 // newly created pop up windows, for example) and in that case the request and |
95 // the client callbacks will be deferred the request until a client is ready. | 111 // the client callbacks will be deferred the request until a client is ready. |
96 class IoThreadClientThrottle : public content::ResourceThrottle { | 112 class IoThreadClientThrottle : public content::ResourceThrottle { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 content::ResourceContext* resource_context, | 294 content::ResourceContext* resource_context, |
279 content::ResourceResponse* response) { | 295 content::ResourceResponse* response) { |
280 AddExtraHeadersIfNeeded(request, resource_context); | 296 AddExtraHeadersIfNeeded(request, resource_context); |
281 } | 297 } |
282 | 298 |
283 void AwResourceDispatcherHostDelegate::RequestComplete( | 299 void AwResourceDispatcherHostDelegate::RequestComplete( |
284 net::URLRequest* request) { | 300 net::URLRequest* request) { |
285 if (request && !request->status().is_success()) { | 301 if (request && !request->status().is_success()) { |
286 const content::ResourceRequestInfo* request_info = | 302 const content::ResourceRequestInfo* request_info = |
287 content::ResourceRequestInfo::ForRequest(request); | 303 content::ResourceRequestInfo::ForRequest(request); |
288 std::unique_ptr<AwContentsIoThreadClient> io_client = | 304 |
289 AwContentsIoThreadClient::FromID(request_info->GetChildID(), | 305 std::unique_ptr<AwWebResourceRequest> web_request( |
290 request_info->GetRenderFrameID()); | 306 new AwWebResourceRequest(request)); |
291 if (io_client) { | 307 BrowserThread::PostTask( |
292 io_client->OnReceivedError(request); | 308 BrowserThread::UI, FROM_HERE, |
293 } else { | 309 base::Bind(&OnReceivedErrorOnUiThread, |
294 DLOG(WARNING) << "io_client is null, onReceivedError dropped for " << | 310 request_info->GetWebContentsGetterForRequest(), |
295 request->url(); | 311 base::Owned(web_request.release()), |
boliu
2016/12/08 05:48:38
ditto, use MakeUnique
sgurun-gerrit only
2016/12/08 21:56:46
stack allocated, copied
| |
296 } | 312 request->status().error())); |
297 } | 313 } |
298 } | 314 } |
299 | 315 |
300 | |
301 void AwResourceDispatcherHostDelegate::DownloadStarting( | 316 void AwResourceDispatcherHostDelegate::DownloadStarting( |
302 net::URLRequest* request, | 317 net::URLRequest* request, |
303 content::ResourceContext* resource_context, | 318 content::ResourceContext* resource_context, |
304 bool is_content_initiated, | 319 bool is_content_initiated, |
305 bool must_download, | 320 bool must_download, |
306 bool is_new_request, | 321 bool is_new_request, |
307 ScopedVector<content::ResourceThrottle>* throttles) { | 322 ScopedVector<content::ResourceThrottle>* throttles) { |
308 GURL url(request->url()); | 323 GURL url(request->url()); |
309 std::string user_agent; | 324 std::string user_agent; |
310 std::string content_disposition; | 325 std::string content_disposition; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 net::HttpRequestHeaders headers; | 479 net::HttpRequestHeaders headers; |
465 headers.AddHeadersFromString(extra_headers); | 480 headers.AddHeadersFromString(extra_headers); |
466 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { | 481 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { |
467 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); | 482 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); |
468 } | 483 } |
469 } | 484 } |
470 } | 485 } |
471 } | 486 } |
472 | 487 |
473 } // namespace android_webview | 488 } // namespace android_webview |
OLD | NEW |