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/renderer_host/auto_login_parser.h" | 15 #include "android_webview/browser/renderer_host/auto_login_parser.h" |
16 #include "android_webview/common/url_constants.h" | 16 #include "android_webview/common/url_constants.h" |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "components/navigation_interception/intercept_navigation_delegate.h" | 18 #include "components/navigation_interception/intercept_navigation_delegate.h" |
19 #include "components/web_restrictions/browser/web_restrictions_resource_throttle
.h" | 19 #include "components/web_restrictions/browser/web_restrictions_resource_throttle
.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/resource_controller.h" | 21 #include "content/public/browser/resource_controller.h" |
22 #include "content/public/browser/resource_dispatcher_host.h" | 22 #include "content/public/browser/resource_dispatcher_host.h" |
23 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 23 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
24 #include "content/public/browser/resource_request_info.h" | 24 #include "content/public/browser/resource_request_info.h" |
25 #include "content/public/browser/resource_throttle.h" | 25 #include "content/public/browser/resource_throttle.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; |
35 using content::BrowserThread; | 36 using content::BrowserThread; |
36 using content::ResourceType; | 37 using content::ResourceType; |
| 38 using content::WebContents; |
37 using navigation_interception::InterceptNavigationDelegate; | 39 using navigation_interception::InterceptNavigationDelegate; |
38 | 40 |
39 namespace { | 41 namespace { |
40 | 42 |
41 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate> | 43 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate> |
42 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER; | 44 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER; |
43 | 45 |
44 void SetCacheControlFlag( | 46 void SetCacheControlFlag( |
45 net::URLRequest* request, int flag) { | 47 net::URLRequest* request, int flag) { |
46 const int all_cache_control_flags = net::LOAD_BYPASS_CACHE | | 48 const int all_cache_control_flags = net::LOAD_BYPASS_CACHE | |
47 net::LOAD_VALIDATE_CACHE | | 49 net::LOAD_VALIDATE_CACHE | |
48 net::LOAD_PREFERRING_CACHE | | 50 net::LOAD_PREFERRING_CACHE | |
49 net::LOAD_ONLY_FROM_CACHE; | 51 net::LOAD_ONLY_FROM_CACHE; |
50 DCHECK_EQ((flag & all_cache_control_flags), flag); | 52 DCHECK_EQ((flag & all_cache_control_flags), flag); |
51 int load_flags = request->load_flags(); | 53 int load_flags = request->load_flags(); |
52 load_flags &= ~all_cache_control_flags; | 54 load_flags &= ~all_cache_control_flags; |
53 load_flags |= flag; | 55 load_flags |= flag; |
54 request->SetLoadFlags(load_flags); | 56 request->SetLoadFlags(load_flags); |
55 } | 57 } |
56 | 58 |
57 // Called when ResourceDispathcerHost detects a download request. | 59 // Called when ResourceDispathcerHost detects a download request. |
58 // The download is already cancelled when this is called, since | 60 // The download is already cancelled when this is called, since |
59 // relevant for DownloadListener is already extracted. | 61 // relevant for DownloadListener is already extracted. |
60 void DownloadStartingOnUIThread(int render_process_id, | 62 void DownloadStartingOnUIThread( |
61 int render_frame_id, | 63 const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
62 const GURL& url, | 64 const GURL& url, |
63 const std::string& user_agent, | 65 const std::string& user_agent, |
64 const std::string& content_disposition, | 66 const std::string& content_disposition, |
65 const std::string& mime_type, | 67 const std::string& mime_type, |
66 int64_t content_length) { | 68 int64_t content_length) { |
| 69 WebContents* web_contents = web_contents_getter.Run(); |
67 AwContentsClientBridgeBase* client = | 70 AwContentsClientBridgeBase* client = |
68 AwContentsClientBridgeBase::FromID(render_process_id, render_frame_id); | 71 AwContentsClientBridgeBase::FromWebContents(web_contents); |
69 if (!client) | 72 if (!client) |
70 return; | 73 return; |
71 client->NewDownload(url, user_agent, content_disposition, mime_type, | 74 client->NewDownload(url, user_agent, content_disposition, mime_type, |
72 content_length); | 75 content_length); |
73 } | 76 } |
74 | 77 |
75 } // namespace | 78 } // namespace |
76 | 79 |
77 namespace android_webview { | 80 namespace android_webview { |
78 | 81 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // POST request cannot be repeated in general, so prevent client from | 315 // POST request cannot be repeated in general, so prevent client from |
313 // retrying the same request, unless it is with a GET. | 316 // retrying the same request, unless it is with a GET. |
314 if ("GET" != request->method()) | 317 if ("GET" != request->method()) |
315 return; | 318 return; |
316 | 319 |
317 const content::ResourceRequestInfo* request_info = | 320 const content::ResourceRequestInfo* request_info = |
318 content::ResourceRequestInfo::ForRequest(request); | 321 content::ResourceRequestInfo::ForRequest(request); |
319 | 322 |
320 BrowserThread::PostTask( | 323 BrowserThread::PostTask( |
321 BrowserThread::UI, FROM_HERE, | 324 BrowserThread::UI, FROM_HERE, |
322 base::Bind(&DownloadStartingOnUIThread, request_info->GetChildID(), | 325 base::Bind(&DownloadStartingOnUIThread, |
323 request_info->GetRenderFrameID(), url, user_agent, | 326 request_info->GetWebContentsGetterForRequest(), url, |
324 content_disposition, mime_type, content_length)); | 327 user_agent, content_disposition, mime_type, content_length)); |
325 } | 328 } |
326 | 329 |
327 content::ResourceDispatcherHostLoginDelegate* | 330 content::ResourceDispatcherHostLoginDelegate* |
328 AwResourceDispatcherHostDelegate::CreateLoginDelegate( | 331 AwResourceDispatcherHostDelegate::CreateLoginDelegate( |
329 net::AuthChallengeInfo* auth_info, | 332 net::AuthChallengeInfo* auth_info, |
330 net::URLRequest* request) { | 333 net::URLRequest* request) { |
331 return new AwLoginDelegate(auth_info, request); | 334 return new AwLoginDelegate(auth_info, request); |
332 } | 335 } |
333 | 336 |
334 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol( | 337 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol( |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 net::HttpRequestHeaders headers; | 455 net::HttpRequestHeaders headers; |
453 headers.AddHeadersFromString(extra_headers); | 456 headers.AddHeadersFromString(extra_headers); |
454 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { | 457 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { |
455 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); | 458 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); |
456 } | 459 } |
457 } | 460 } |
458 } | 461 } |
459 } | 462 } |
460 | 463 |
461 } // namespace android_webview | 464 } // namespace android_webview |
OLD | NEW |