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

Side by Side Diff: android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.cc

Issue 2425423004: Move NewDownload out of AwContentsIoThreadClientImpl to AwContentsClientBridge (Closed)
Patch Set: changed "even if" to "unless" Created 4 years, 2 months 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/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_io_thread_client.h" 12 #include "android_webview/browser/aw_contents_io_thread_client.h"
12 #include "android_webview/browser/aw_login_delegate.h" 13 #include "android_webview/browser/aw_login_delegate.h"
13 #include "android_webview/browser/aw_resource_context.h" 14 #include "android_webview/browser/aw_resource_context.h"
14 #include "android_webview/browser/renderer_host/auto_login_parser.h" 15 #include "android_webview/browser/renderer_host/auto_login_parser.h"
15 #include "android_webview/common/url_constants.h" 16 #include "android_webview/common/url_constants.h"
16 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
17 #include "components/navigation_interception/intercept_navigation_delegate.h" 18 #include "components/navigation_interception/intercept_navigation_delegate.h"
18 #include "components/web_restrictions/browser/web_restrictions_resource_throttle .h" 19 #include "components/web_restrictions/browser/web_restrictions_resource_throttle .h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/resource_controller.h" 21 #include "content/public/browser/resource_controller.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 "net/base/load_flags.h" 26 #include "net/base/load_flags.h"
26 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
27 #include "net/http/http_response_headers.h" 28 #include "net/http/http_response_headers.h"
28 #include "net/url_request/url_request.h" 29 #include "net/url_request/url_request.h"
29 #include "net/url_request/url_request_status.h" 30 #include "net/url_request/url_request_status.h"
30 #include "url/url_constants.h" 31 #include "url/url_constants.h"
31 32
32 using android_webview::AwContentsIoThreadClient; 33 using android_webview::AwContentsIoThreadClient;
34 using android_webview::AwContentsClientBridgeBase;
33 using content::BrowserThread; 35 using content::BrowserThread;
34 using content::ResourceType; 36 using content::ResourceType;
35 using navigation_interception::InterceptNavigationDelegate; 37 using navigation_interception::InterceptNavigationDelegate;
36 38
37 namespace { 39 namespace {
38 40
39 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate> 41 base::LazyInstance<android_webview::AwResourceDispatcherHostDelegate>
40 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER; 42 g_webview_resource_dispatcher_host_delegate = LAZY_INSTANCE_INITIALIZER;
41 43
42 void SetCacheControlFlag( 44 void SetCacheControlFlag(
43 net::URLRequest* request, int flag) { 45 net::URLRequest* request, int flag) {
44 const int all_cache_control_flags = net::LOAD_BYPASS_CACHE | 46 const int all_cache_control_flags = net::LOAD_BYPASS_CACHE |
45 net::LOAD_VALIDATE_CACHE | 47 net::LOAD_VALIDATE_CACHE |
46 net::LOAD_PREFERRING_CACHE | 48 net::LOAD_PREFERRING_CACHE |
47 net::LOAD_ONLY_FROM_CACHE; 49 net::LOAD_ONLY_FROM_CACHE;
48 DCHECK_EQ((flag & all_cache_control_flags), flag); 50 DCHECK_EQ((flag & all_cache_control_flags), flag);
49 int load_flags = request->load_flags(); 51 int load_flags = request->load_flags();
50 load_flags &= ~all_cache_control_flags; 52 load_flags &= ~all_cache_control_flags;
51 load_flags |= flag; 53 load_flags |= flag;
52 request->SetLoadFlags(load_flags); 54 request->SetLoadFlags(load_flags);
53 } 55 }
54 56
57 // Called when ResourceDispathcerHost detects a download request.
58 // The download is already cancelled when this is called, since
59 // relevant for DownloadListener is already extracted.
60 void DownloadStartingOnUIThread(int render_process_id,
61 int render_frame_id,
62 const GURL& url,
63 const std::string& user_agent,
64 const std::string& content_disposition,
65 const std::string& mime_type,
66 int64_t content_length) {
67 AwContentsClientBridgeBase* client =
68 AwContentsClientBridgeBase::FromID(render_process_id, render_frame_id);
69 if (!client)
70 return;
71 client->NewDownload(url, user_agent, content_disposition, mime_type,
72 content_length);
73 }
74
55 } // namespace 75 } // namespace
56 76
57 namespace android_webview { 77 namespace android_webview {
58 78
59 // Calls through the IoThreadClient to check the embedders settings to determine 79 // Calls through the IoThreadClient to check the embedders settings to determine
60 // if the request should be cancelled. There may not always be an IoThreadClient 80 // if the request should be cancelled. There may not always be an IoThreadClient
61 // available for the |render_process_id|, |render_frame_id| pair (in the case of 81 // available for the |render_process_id|, |render_frame_id| pair (in the case of
62 // newly created pop up windows, for example) and in that case the request and 82 // newly created pop up windows, for example) and in that case the request and
63 // the client callbacks will be deferred the request until a client is ready. 83 // the client callbacks will be deferred the request until a client is ready.
64 class IoThreadClientThrottle : public content::ResourceThrottle { 84 class IoThreadClientThrottle : public content::ResourceThrottle {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 ScopedVector<content::ResourceThrottle>* throttles) { 293 ScopedVector<content::ResourceThrottle>* throttles) {
274 GURL url(request->url()); 294 GURL url(request->url());
275 std::string user_agent; 295 std::string user_agent;
276 std::string content_disposition; 296 std::string content_disposition;
277 std::string mime_type; 297 std::string mime_type;
278 int64_t content_length = request->GetExpectedContentSize(); 298 int64_t content_length = request->GetExpectedContentSize();
279 299
280 request->extra_request_headers().GetHeader( 300 request->extra_request_headers().GetHeader(
281 net::HttpRequestHeaders::kUserAgent, &user_agent); 301 net::HttpRequestHeaders::kUserAgent, &user_agent);
282 302
283
284 net::HttpResponseHeaders* response_headers = request->response_headers(); 303 net::HttpResponseHeaders* response_headers = request->response_headers();
285 if (response_headers) { 304 if (response_headers) {
286 response_headers->GetNormalizedHeader("content-disposition", 305 response_headers->GetNormalizedHeader("content-disposition",
287 &content_disposition); 306 &content_disposition);
288 response_headers->GetMimeType(&mime_type); 307 response_headers->GetMimeType(&mime_type);
289 } 308 }
290 309
291 request->Cancel(); 310 request->Cancel();
292 311
312 // POST request cannot be repeated in general, so prevent client from
313 // retrying the same request, unless it is with a GET.
314 if ("GET" != request->method())
315 return;
316
293 const content::ResourceRequestInfo* request_info = 317 const content::ResourceRequestInfo* request_info =
294 content::ResourceRequestInfo::ForRequest(request); 318 content::ResourceRequestInfo::ForRequest(request);
295 319
296 // TODO(jam): http://crbug.com/645983 we will need to make this map work with 320 BrowserThread::PostTask(
297 // both RFH IDs and FTN IDs. 321 BrowserThread::UI, FROM_HERE,
298 std::unique_ptr<AwContentsIoThreadClient> io_client = 322 base::Bind(&DownloadStartingOnUIThread, request_info->GetChildID(),
299 AwContentsIoThreadClient::FromID(request_info->GetChildID(), 323 request_info->GetRenderFrameID(), url, user_agent,
jam 2016/10/20 18:15:22 To make this code work with PlzNavigate, use GetWe
sgurun-gerrit only 2016/10/20 18:33:26 will do, thanks!
300 request_info->GetRenderFrameID()); 324 content_disposition, mime_type, content_length));
301
302 // POST request cannot be repeated in general, so prevent client from
303 // retrying the same request, even if it is with a GET.
304 if ("GET" == request->method() && io_client) {
305 io_client->NewDownload(url,
306 user_agent,
307 content_disposition,
308 mime_type,
309 content_length);
310 }
311 } 325 }
312 326
313 content::ResourceDispatcherHostLoginDelegate* 327 content::ResourceDispatcherHostLoginDelegate*
314 AwResourceDispatcherHostDelegate::CreateLoginDelegate( 328 AwResourceDispatcherHostDelegate::CreateLoginDelegate(
315 net::AuthChallengeInfo* auth_info, 329 net::AuthChallengeInfo* auth_info,
316 net::URLRequest* request) { 330 net::URLRequest* request) {
317 return new AwLoginDelegate(auth_info, request); 331 return new AwLoginDelegate(auth_info, request);
318 } 332 }
319 333
320 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol( 334 bool AwResourceDispatcherHostDelegate::HandleExternalProtocol(
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 net::HttpRequestHeaders headers; 452 net::HttpRequestHeaders headers;
439 headers.AddHeadersFromString(extra_headers); 453 headers.AddHeadersFromString(extra_headers);
440 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { 454 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) {
441 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); 455 request->SetExtraRequestHeaderByName(it.name(), it.value(), false);
442 } 456 }
443 } 457 }
444 } 458 }
445 } 459 }
446 460
447 } // namespace android_webview 461 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698