| 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 #ifndef CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ | 5 #ifndef CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ |
| 6 #define CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ | 6 #define CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 | 11 |
| 12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "gfx/native_widget_types.h" | 14 #include "gfx/native_widget_types.h" |
| 15 #include "net/base/file_stream.h" | 15 #include "net/base/file_stream.h" |
| 16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 17 | 17 |
| 18 // The PluginDownloadUrlHelper is used to handle one download URL request | 18 // The PluginDownloadUrlHelper is used to handle one download URL request |
| 19 // from the plugin. Each download request is handled by a new instance | 19 // from the plugin. Each download request is handled by a new instance |
| 20 // of this class. | 20 // of this class. |
| 21 class PluginDownloadUrlHelper : public URLRequest::Delegate { | 21 class PluginDownloadUrlHelper : public net::URLRequest::Delegate { |
| 22 static const int kDownloadFileBufferSize = 32768; | 22 static const int kDownloadFileBufferSize = 32768; |
| 23 public: | 23 public: |
| 24 // The delegate receives notification about the status of downloads | 24 // The delegate receives notification about the status of downloads |
| 25 // initiated. | 25 // initiated. |
| 26 class DownloadDelegate { | 26 class DownloadDelegate { |
| 27 public: | 27 public: |
| 28 virtual ~DownloadDelegate() {} | 28 virtual ~DownloadDelegate() {} |
| 29 | 29 |
| 30 virtual void OnDownloadCompleted(const FilePath& download_path, | 30 virtual void OnDownloadCompleted(const FilePath& download_path, |
| 31 bool success) {} | 31 bool success) {} |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 PluginDownloadUrlHelper(const std::string& download_url, | 34 PluginDownloadUrlHelper(const std::string& download_url, |
| 35 int source_pid, gfx::NativeWindow caller_window, | 35 int source_pid, gfx::NativeWindow caller_window, |
| 36 PluginDownloadUrlHelper::DownloadDelegate* delegate); | 36 PluginDownloadUrlHelper::DownloadDelegate* delegate); |
| 37 ~PluginDownloadUrlHelper(); | 37 ~PluginDownloadUrlHelper(); |
| 38 | 38 |
| 39 void InitiateDownload(URLRequestContext* request_context); | 39 void InitiateDownload(URLRequestContext* request_context); |
| 40 | 40 |
| 41 // URLRequest::Delegate | 41 // net::URLRequest::Delegate |
| 42 virtual void OnAuthRequired(URLRequest* request, | 42 virtual void OnAuthRequired(net::URLRequest* request, |
| 43 net::AuthChallengeInfo* auth_info); | 43 net::AuthChallengeInfo* auth_info); |
| 44 virtual void OnSSLCertificateError(URLRequest* request, | 44 virtual void OnSSLCertificateError(net::URLRequest* request, |
| 45 int cert_error, | 45 int cert_error, |
| 46 net::X509Certificate* cert); | 46 net::X509Certificate* cert); |
| 47 virtual void OnResponseStarted(URLRequest* request); | 47 virtual void OnResponseStarted(net::URLRequest* request); |
| 48 virtual void OnReadCompleted(URLRequest* request, int bytes_read); | 48 virtual void OnReadCompleted(net::URLRequest* request, int bytes_read); |
| 49 | 49 |
| 50 void OnDownloadCompleted(URLRequest* request); | 50 void OnDownloadCompleted(net::URLRequest* request); |
| 51 | 51 |
| 52 protected: | 52 protected: |
| 53 void DownloadCompletedHelper(bool success); | 53 void DownloadCompletedHelper(bool success); |
| 54 | 54 |
| 55 // The download file request initiated by the plugin. | 55 // The download file request initiated by the plugin. |
| 56 URLRequest* download_file_request_; | 56 net::URLRequest* download_file_request_; |
| 57 // Handle to the downloaded file. | 57 // Handle to the downloaded file. |
| 58 scoped_ptr<net::FileStream> download_file_; | 58 scoped_ptr<net::FileStream> download_file_; |
| 59 // The full path of the downloaded file. | 59 // The full path of the downloaded file. |
| 60 FilePath download_file_path_; | 60 FilePath download_file_path_; |
| 61 // The buffer passed off to URLRequest::Read. | 61 // The buffer passed off to net::URLRequest::Read. |
| 62 scoped_refptr<net::IOBuffer> download_file_buffer_; | 62 scoped_refptr<net::IOBuffer> download_file_buffer_; |
| 63 // TODO(port): this comment doesn't describe the situation on Posix. | 63 // TODO(port): this comment doesn't describe the situation on Posix. |
| 64 // The window handle for sending the WM_COPYDATA notification, | 64 // The window handle for sending the WM_COPYDATA notification, |
| 65 // indicating that the download completed. | 65 // indicating that the download completed. |
| 66 gfx::NativeWindow download_file_caller_window_; | 66 gfx::NativeWindow download_file_caller_window_; |
| 67 | 67 |
| 68 std::string download_url_; | 68 std::string download_url_; |
| 69 int download_source_child_unique_id_; | 69 int download_source_child_unique_id_; |
| 70 | 70 |
| 71 PluginDownloadUrlHelper::DownloadDelegate* delegate_; | 71 PluginDownloadUrlHelper::DownloadDelegate* delegate_; |
| 72 | 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper); | 73 DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 #endif // OS_WIN | 76 #endif // OS_WIN |
| 77 | 77 |
| 78 #endif // CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ | 78 #endif // CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ |
| 79 | 79 |
| 80 | 80 |
| OLD | NEW |