| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 // This class pairs with DownloadController on Java side to forward requests |
| 6 // for GET downloads to the current DownloadListener. POST downloads are |
| 7 // handled on the native side. |
| 8 // |
| 9 // Both classes are Singleton classes. C++ object owns Java object. |
| 10 // |
| 11 // Call sequence |
| 12 // GET downloads: |
| 13 // DownloadController::CreateGETDownload() => |
| 14 // DownloadController.newHttpGetDownload() => |
| 15 // DownloadListener.onDownloadStart() / |
| 16 // DownloadListener2.requestHttpGetDownload() |
| 17 // |
| 18 |
| 19 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ |
| 20 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ |
| 21 |
| 22 #include "base/android/scoped_java_ref.h" |
| 23 #include "base/memory/singleton.h" |
| 24 #include "chrome/browser/android/download/download_controller_base.h" |
| 25 |
| 26 namespace net { |
| 27 class URLRequest; |
| 28 } |
| 29 |
| 30 namespace ui { |
| 31 class WindowAndroid; |
| 32 } |
| 33 |
| 34 namespace content { |
| 35 class WebContents; |
| 36 } |
| 37 |
| 38 class DownloadController : public DownloadControllerBase { |
| 39 public: |
| 40 static DownloadController* GetInstance(); |
| 41 |
| 42 static bool RegisterDownloadController(JNIEnv* env); |
| 43 |
| 44 // Called when DownloadController Java object is instantiated. |
| 45 void Init(JNIEnv* env, jobject obj); |
| 46 |
| 47 // DownloadControllerBase implementation. |
| 48 void AcquireFileAccessPermission( |
| 49 content::WebContents* web_contents, |
| 50 const AcquireFileAccessPermissionCallback& callback) override; |
| 51 void SetDefaultDownloadFileName(const std::string& file_name) override; |
| 52 |
| 53 private: |
| 54 struct JavaObject; |
| 55 friend struct base::DefaultSingletonTraits<DownloadController>; |
| 56 DownloadController(); |
| 57 ~DownloadController() override; |
| 58 |
| 59 // Helper method for implementing AcquireFileAccessPermission(). |
| 60 bool HasFileAccessPermission(ui::WindowAndroid* window_android); |
| 61 |
| 62 // DownloadControllerBase implementation. |
| 63 void CreateGETDownload(int render_process_id, |
| 64 int render_view_id, |
| 65 bool must_download, |
| 66 const DownloadInfo& info) override; |
| 67 void OnDownloadStarted(content::DownloadItem* download_item) override; |
| 68 void StartContextMenuDownload(const content::ContextMenuParams& params, |
| 69 content::WebContents* web_contents, |
| 70 bool is_link, |
| 71 const std::string& extra_headers) override; |
| 72 void DangerousDownloadValidated(content::WebContents* web_contents, |
| 73 const std::string& download_guid, |
| 74 bool accept) override; |
| 75 |
| 76 // DownloadItem::Observer interface. |
| 77 void OnDownloadUpdated(content::DownloadItem* item) override; |
| 78 |
| 79 void StartAndroidDownload(int render_process_id, |
| 80 int render_view_id, |
| 81 bool must_download, |
| 82 const DownloadInfo& info); |
| 83 void StartAndroidDownloadInternal(int render_process_id, |
| 84 int render_view_id, |
| 85 bool must_download, |
| 86 const DownloadInfo& info, |
| 87 bool allowed); |
| 88 |
| 89 // The download item contains dangerous file types. |
| 90 void OnDangerousDownload(content::DownloadItem *item); |
| 91 |
| 92 base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents( |
| 93 content::WebContents* web_contents); |
| 94 |
| 95 // Creates Java object if it is not created already and returns it. |
| 96 JavaObject* GetJavaObject(); |
| 97 |
| 98 JavaObject* java_object_; |
| 99 |
| 100 std::string default_file_name_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(DownloadController); |
| 103 }; |
| 104 |
| 105 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_ |
| OLD | NEW |