| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_BASE_H_ |
| 6 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_BASE_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "content/public/browser/download_item.h" |
| 12 #include "content/public/common/context_menu_params.h" |
| 13 #include "net/http/http_content_disposition.h" |
| 14 #include "net/http/http_request_headers.h" |
| 15 #include "net/http/http_response_headers.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 namespace net { |
| 19 class URLRequest; |
| 20 } |
| 21 |
| 22 namespace content { |
| 23 class DownloadItem; |
| 24 class WebContents; |
| 25 } |
| 26 |
| 27 // Used to store all the information about an Android download. |
| 28 struct DownloadInfo { |
| 29 explicit DownloadInfo(const net::URLRequest* request); |
| 30 DownloadInfo(const DownloadInfo& other); |
| 31 ~DownloadInfo(); |
| 32 |
| 33 // The URL from which we are downloading. This is the final URL after any |
| 34 // redirection by the server for |original_url_|. |
| 35 GURL url; |
| 36 // The original URL before any redirection by the server for this URL. |
| 37 GURL original_url; |
| 38 int64_t total_bytes; |
| 39 std::string content_disposition; |
| 40 std::string original_mime_type; |
| 41 std::string user_agent; |
| 42 std::string cookie; |
| 43 std::string referer; |
| 44 bool has_user_gesture; |
| 45 |
| 46 content::WebContents* web_contents; |
| 47 // Default copy constructor is used for passing this struct by value. |
| 48 }; |
| 49 |
| 50 // Interface to request GET downloads and send notifications for POST |
| 51 // downloads. |
| 52 class DownloadControllerBase : public content::DownloadItem::Observer { |
| 53 public: |
| 54 // Returns the singleton instance of the DownloadControllerBase. |
| 55 static DownloadControllerBase* Get(); |
| 56 |
| 57 // Called to set the DownloadControllerBase instance. |
| 58 static void SetDownloadControllerBase( |
| 59 DownloadControllerBase* download_controller); |
| 60 |
| 61 // Starts a new download request with Android. Should be called on the |
| 62 // UI thread. |
| 63 virtual void CreateGETDownload(int render_process_id, int render_view_id, |
| 64 bool must_download, |
| 65 const DownloadInfo& info) = 0; |
| 66 |
| 67 // Should be called when a download is started. It can be either a GET |
| 68 // request with authentication or a POST request. Notifies the embedding |
| 69 // app about the download. Should be called on the UI thread. |
| 70 virtual void OnDownloadStarted(content::DownloadItem* download_item) = 0; |
| 71 |
| 72 // Called when a download is initiated by context menu. |
| 73 virtual void StartContextMenuDownload( |
| 74 const content::ContextMenuParams& params, |
| 75 content::WebContents* web_contents, |
| 76 bool is_link, const std::string& extra_headers) = 0; |
| 77 |
| 78 // Called when a dangerous download item is verified or rejected. |
| 79 virtual void DangerousDownloadValidated(content::WebContents* web_contents, |
| 80 const std::string& download_guid, |
| 81 bool accept) = 0; |
| 82 |
| 83 // Callback when user permission prompt finishes. Args: whether file access |
| 84 // permission is acquired. |
| 85 typedef base::Callback<void(bool)> AcquireFileAccessPermissionCallback; |
| 86 |
| 87 // Called to prompt the user for file access permission. When finished, |
| 88 // |callback| will be executed. |
| 89 virtual void AcquireFileAccessPermission( |
| 90 content::WebContents* web_contents, |
| 91 const AcquireFileAccessPermissionCallback& callback) = 0; |
| 92 |
| 93 // Called by unit test to approve or disapprove file access request. |
| 94 virtual void SetApproveFileAccessRequestForTesting(bool approve) {} |
| 95 |
| 96 // Called to set the default download file name if it cannot be resolved |
| 97 // from url and content disposition |
| 98 virtual void SetDefaultDownloadFileName(const std::string& file_name) {} |
| 99 |
| 100 protected: |
| 101 ~DownloadControllerBase() override {} |
| 102 static DownloadControllerBase* download_controller_; |
| 103 }; |
| 104 |
| 105 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_BASE_H_ |
| OLD | NEW |