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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/intercept_download_resource_throttle.h"
7 #include "content/public/browser/android/download_controller_android.h"
8 #include "content/public/browser/resource_controller.h"
9 #include "net/http/http_request_headers.h"
10 #include "net/url_request/url_request.h"
14 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle(
15 net::URLRequest* request,
16 int render_process_id,
20 render_process_id_(render_process_id),
21 render_view_id_(render_view_id),
22 request_id_(request_id) {
25 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() {
28 void InterceptDownloadResourceThrottle::WillStartRequest(bool* defer) {
29 ProcessDownloadRequest();
32 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) {
33 ProcessDownloadRequest();
36 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() {
37 if (request_->method() != net::HttpRequestHeaders::kGetMethod ||
38 request_->response_info().did_use_http_auth)
41 if (request_->url_chain().empty())
44 GURL url = request_->url_chain().back();
45 if (!url.SchemeIsHTTPOrHTTPS())
48 content::DownloadControllerAndroid::Get()->CreateGETDownload(
49 render_process_id_, render_view_id_, request_id_);
50 controller()->Cancel();