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