| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/plugin_download_helper.h" | 5 #include "chrome/browser/plugin_download_helper.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 PluginDownloadUrlHelper::~PluginDownloadUrlHelper() { | 29 PluginDownloadUrlHelper::~PluginDownloadUrlHelper() { |
| 30 if (download_file_request_) { | 30 if (download_file_request_) { |
| 31 delete download_file_request_; | 31 delete download_file_request_; |
| 32 download_file_request_ = NULL; | 32 download_file_request_ = NULL; |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 void PluginDownloadUrlHelper::InitiateDownload( | 36 void PluginDownloadUrlHelper::InitiateDownload( |
| 37 URLRequestContext* request_context) { | 37 URLRequestContext* request_context) { |
| 38 download_file_request_ = new URLRequest(GURL(download_url_), this); | 38 download_file_request_ = new net::URLRequest(GURL(download_url_), this); |
| 39 chrome_browser_net::SetOriginProcessUniqueIDForRequest( | 39 chrome_browser_net::SetOriginProcessUniqueIDForRequest( |
| 40 download_source_child_unique_id_, download_file_request_); | 40 download_source_child_unique_id_, download_file_request_); |
| 41 download_file_request_->set_context(request_context); | 41 download_file_request_->set_context(request_context); |
| 42 download_file_request_->Start(); | 42 download_file_request_->Start(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void PluginDownloadUrlHelper::OnAuthRequired( | 45 void PluginDownloadUrlHelper::OnAuthRequired( |
| 46 URLRequest* request, | 46 net::URLRequest* request, |
| 47 net::AuthChallengeInfo* auth_info) { | 47 net::AuthChallengeInfo* auth_info) { |
| 48 URLRequest::Delegate::OnAuthRequired(request, auth_info); | 48 net::URLRequest::Delegate::OnAuthRequired(request, auth_info); |
| 49 DownloadCompletedHelper(false); | 49 DownloadCompletedHelper(false); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void PluginDownloadUrlHelper::OnSSLCertificateError( | 52 void PluginDownloadUrlHelper::OnSSLCertificateError( |
| 53 URLRequest* request, | 53 net::URLRequest* request, |
| 54 int cert_error, | 54 int cert_error, |
| 55 net::X509Certificate* cert) { | 55 net::X509Certificate* cert) { |
| 56 URLRequest::Delegate::OnSSLCertificateError(request, cert_error, cert); | 56 net::URLRequest::Delegate::OnSSLCertificateError(request, cert_error, cert); |
| 57 DownloadCompletedHelper(false); | 57 DownloadCompletedHelper(false); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void PluginDownloadUrlHelper::OnResponseStarted(URLRequest* request) { | 60 void PluginDownloadUrlHelper::OnResponseStarted(net::URLRequest* request) { |
| 61 if (!download_file_->IsOpen()) { | 61 if (!download_file_->IsOpen()) { |
| 62 // This is safe because once the temp file has been safely created, an | 62 // This is safe because once the temp file has been safely created, an |
| 63 // attacker can't drop a symlink etc into place. | 63 // attacker can't drop a symlink etc into place. |
| 64 file_util::CreateTemporaryFile(&download_file_path_); | 64 file_util::CreateTemporaryFile(&download_file_path_); |
| 65 download_file_->Open(download_file_path_, | 65 download_file_->Open(download_file_path_, |
| 66 base::PLATFORM_FILE_CREATE_ALWAYS | | 66 base::PLATFORM_FILE_CREATE_ALWAYS | |
| 67 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE); | 67 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE); |
| 68 if (!download_file_->IsOpen()) { | 68 if (!download_file_->IsOpen()) { |
| 69 NOTREACHED(); | 69 NOTREACHED(); |
| 70 OnDownloadCompleted(request); | 70 OnDownloadCompleted(request); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 84 OnDownloadCompleted(request); | 84 OnDownloadCompleted(request); |
| 85 } | 85 } |
| 86 } else if (bytes_read == 0) { | 86 } else if (bytes_read == 0) { |
| 87 OnDownloadCompleted(request); | 87 OnDownloadCompleted(request); |
| 88 } else { | 88 } else { |
| 89 OnReadCompleted(request, bytes_read); | 89 OnReadCompleted(request, bytes_read); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 void PluginDownloadUrlHelper::OnReadCompleted(URLRequest* request, | 94 void PluginDownloadUrlHelper::OnReadCompleted(net::URLRequest* request, |
| 95 int bytes_read) { | 95 int bytes_read) { |
| 96 DCHECK(download_file_->IsOpen()); | 96 DCHECK(download_file_->IsOpen()); |
| 97 | 97 |
| 98 if (bytes_read == 0) { | 98 if (bytes_read == 0) { |
| 99 OnDownloadCompleted(request); | 99 OnDownloadCompleted(request); |
| 100 return; | 100 return; |
| 101 } | 101 } |
| 102 | 102 |
| 103 int request_bytes_read = bytes_read; | 103 int request_bytes_read = bytes_read; |
| 104 | 104 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 122 OnDownloadCompleted(request); | 122 OnDownloadCompleted(request); |
| 123 } | 123 } |
| 124 break; | 124 break; |
| 125 } else if (request_bytes_read == 0) { | 125 } else if (request_bytes_read == 0) { |
| 126 OnDownloadCompleted(request); | 126 OnDownloadCompleted(request); |
| 127 break; | 127 break; |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 void PluginDownloadUrlHelper::OnDownloadCompleted(URLRequest* request) { | 132 void PluginDownloadUrlHelper::OnDownloadCompleted(net::URLRequest* request) { |
| 133 bool success = true; | 133 bool success = true; |
| 134 if (!request->status().is_success()) { | 134 if (!request->status().is_success()) { |
| 135 success = false; | 135 success = false; |
| 136 } else if (!download_file_->IsOpen()) { | 136 } else if (!download_file_->IsOpen()) { |
| 137 success = false; | 137 success = false; |
| 138 } | 138 } |
| 139 | 139 |
| 140 DownloadCompletedHelper(success); | 140 DownloadCompletedHelper(success); |
| 141 } | 141 } |
| 142 | 142 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 // Don't access any members after this. | 182 // Don't access any members after this. |
| 183 delete this; | 183 delete this; |
| 184 } | 184 } |
| 185 | 185 |
| 186 #endif // OS_WIN | 186 #endif // OS_WIN |
| 187 | 187 |
| 188 | 188 |
| 189 | 189 |
| 190 | 190 |
| OLD | NEW |