Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/android/download/download_controller.h

Issue 2014803002: Move DownloadControllerAndroid from content/ to chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reverted ResourceDispatcherHost Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 // This class pairs with DownloadController on Java side to forward requests 5 // This class pairs with DownloadController on Java side to forward requests
6 // for GET downloads to the current DownloadListener. POST downloads are 6 // for GET downloads to the current DownloadListener. POST downloads are
7 // handled on the native side. 7 // handled on the native side.
8 // 8 //
9 // Both classes are Singleton classes. C++ object owns Java object. 9 // Both classes are Singleton classes. C++ object owns Java object.
10 // 10 //
11 // Call sequence 11 // Call sequence
12 // GET downloads: 12 // GET downloads:
13 // DownloadControllerAndroid::CreateGETDownload() => 13 // DownloadController::CreateGETDownload() =>
14 // DownloadController.newHttpGetDownload() => 14 // DownloadController.newHttpGetDownload() =>
15 // DownloadListener.onDownloadStart() / 15 // DownloadListener.onDownloadStart() /
16 // DownloadListener2.requestHttpGetDownload() 16 // DownloadListener2.requestHttpGetDownload()
17 // 17 //
18 18
19 #ifndef CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_ 19 #ifndef CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_
20 #define CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_ 20 #define CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_
21
22 #include <stdint.h>
21 23
22 #include <string> 24 #include <string>
23 25
24 #include <stdint.h>
25
26 #include "base/android/jni_weak_ref.h" 26 #include "base/android/jni_weak_ref.h"
27 #include "base/android/scoped_java_ref.h" 27 #include "base/android/scoped_java_ref.h"
28 #include "base/callback.h" 28 #include "base/callback.h"
29 #include "base/macros.h" 29 #include "base/macros.h"
30 #include "base/memory/scoped_vector.h" 30 #include "base/memory/scoped_vector.h"
31 #include "base/memory/singleton.h" 31 #include "base/memory/singleton.h"
32 #include "content/public/browser/android/download_controller_android.h" 32 #include "chrome/browser/android/download/download_controller_base.h"
33 #include "chrome/browser/ui/android/view_android_helper.h"
33 #include "net/cookies/cookie_monster.h" 34 #include "net/cookies/cookie_monster.h"
34 #include "url/gurl.h" 35 #include "url/gurl.h"
35 36
36 namespace net { 37 namespace net {
37 class URLRequest; 38 class URLRequest;
38 } 39 }
39 40
41 namespace ui {
42 class WindowAndroid;
43 }
44
40 namespace content { 45 namespace content {
41 struct GlobalRequestID;
42 class DeferredDownloadObserver;
43 class RenderViewHost; 46 class RenderViewHost;
44 class WebContents; 47 class WebContents;
48 }
45 49
46 class DownloadControllerAndroidImpl : public DownloadControllerAndroid { 50 class DownloadController : public DownloadControllerBase {
47 public: 51 public:
48 static DownloadControllerAndroidImpl* GetInstance(); 52 static DownloadController* GetInstance();
49 53
50 static bool RegisterDownloadController(JNIEnv* env); 54 static bool RegisterDownloadController(JNIEnv* env);
51 55
52 // Called when DownloadController Java object is instantiated. 56 // Called when DownloadController Java object is instantiated.
53 void Init(JNIEnv* env, jobject obj); 57 void Init(JNIEnv* env, jobject obj);
54 58
55 // Removes a deferred download from |deferred_downloads_|. 59 // DownloadControllerBase implementation.
56 void CancelDeferredDownload(DeferredDownloadObserver* observer);
57
58 // DownloadControllerAndroid implementation.
59 void AcquireFileAccessPermission( 60 void AcquireFileAccessPermission(
60 WebContents* web_contents, 61 content::WebContents* web_contents,
61 const AcquireFileAccessPermissionCallback& callback) override; 62 const AcquireFileAccessPermissionCallback& callback) override;
62 void SetDefaultDownloadFileName(const std::string& file_name) override; 63 void SetDefaultDownloadFileName(const std::string& file_name) override;
63 64
64 private: 65 private:
65 // Used to store all the information about an Android download. 66 // Used to store all the information about an Android download.
66 struct DownloadInfoAndroid { 67 struct DownloadInfo {
67 explicit DownloadInfoAndroid(net::URLRequest* request); 68 explicit DownloadInfo(const net::URLRequest* request);
68 DownloadInfoAndroid(const DownloadInfoAndroid& other); 69 DownloadInfo(const DownloadInfo& other);
69 ~DownloadInfoAndroid(); 70 ~DownloadInfo();
70 71
71 // The URL from which we are downloading. This is the final URL after any 72 // The URL from which we are downloading. This is the final URL after any
72 // redirection by the server for |original_url_|. 73 // redirection by the server for |original_url_|.
73 GURL url; 74 GURL url;
74 // The original URL before any redirection by the server for this URL. 75 // The original URL before any redirection by the server for this URL.
75 GURL original_url; 76 GURL original_url;
76 int64_t total_bytes; 77 int64_t total_bytes;
77 std::string content_disposition; 78 std::string content_disposition;
78 std::string original_mime_type; 79 std::string original_mime_type;
79 std::string user_agent; 80 std::string user_agent;
80 std::string cookie; 81 std::string cookie;
81 std::string referer; 82 std::string referer;
82 bool has_user_gesture; 83 bool has_user_gesture;
83 84
84 WebContents* web_contents; 85 content::WebContents* web_contents;
85 // Default copy constructor is used for passing this struct by value. 86 // Default copy constructor is used for passing this struct by value.
86 }; 87 };
87 struct JavaObject; 88 struct JavaObject;
88 friend struct base::DefaultSingletonTraits<DownloadControllerAndroidImpl>; 89 friend struct base::DefaultSingletonTraits<DownloadController>;
89 DownloadControllerAndroidImpl(); 90 DownloadController();
90 ~DownloadControllerAndroidImpl() override; 91 ~DownloadController() override;
91 92
92 // Helper method for implementing AcquireFileAccessPermission(). 93 // Helper method for implementing AcquireFileAccessPermission().
93 bool HasFileAccessPermission( 94 bool HasFileAccessPermission(ui::WindowAndroid* window_android);
94 base::android::ScopedJavaLocalRef<jobject> j_content_view_core);
95 95
96 // DownloadControllerAndroid implementation. 96 // DownloadControllerBase implementation.
97 void CreateGETDownload(int render_process_id, 97 void CreateGETDownload(int render_process_id,
98 int render_view_id, 98 int render_view_id,
99 int request_id, 99 const net::URLRequest* request,
100 bool must_download) override; 100 bool must_download) override;
101 void OnDownloadStarted(DownloadItem* download_item) override; 101 void OnDownloadStarted(content::DownloadItem* download_item) override;
102 void StartContextMenuDownload(const ContextMenuParams& params, 102 void StartContextMenuDownload(const content::ContextMenuParams& params,
103 WebContents* web_contents, 103 content::WebContents* web_contents,
104 bool is_link, 104 bool is_link,
105 const std::string& extra_headers) override; 105 const std::string& extra_headers) override;
106 void DangerousDownloadValidated(WebContents* web_contents, 106 void DangerousDownloadValidated(content::WebContents* web_contents,
107 const std::string& download_guid, 107 const std::string& download_guid,
108 bool accept) override; 108 bool accept) override;
109 109
110 // DownloadItem::Observer interface. 110 // DownloadItem::Observer interface.
111 void OnDownloadUpdated(DownloadItem* item) override; 111 void OnDownloadUpdated(content::DownloadItem* item) override;
112 112
113 typedef base::Callback<void(const DownloadInfoAndroid&)> 113 typedef base::Callback<void(const DownloadInfo&)>
114 GetDownloadInfoCB; 114 GetDownloadInfoCB;
115 void PrepareDownloadInfo(const GlobalRequestID& global_id, 115 void PrepareDownloadInfo(const net::URLRequest* request,
116 const GetDownloadInfoCB& callback); 116 const GetDownloadInfoCB& callback);
117 void CheckPolicyAndLoadCookies(const DownloadInfoAndroid& info, 117 void CheckPolicyAndLoadCookies(const DownloadInfo& info,
118 const GetDownloadInfoCB& callback, 118 const GetDownloadInfoCB& callback,
119 const GlobalRequestID& global_id, 119 const net::URLRequest* request,
120 const net::CookieList& cookie_list); 120 const net::CookieList& cookie_list);
121 void DoLoadCookies(const DownloadInfoAndroid& info, 121 void DoLoadCookies(const DownloadInfo& info,
122 const GetDownloadInfoCB& callback, 122 const GetDownloadInfoCB& callback,
123 const GlobalRequestID& global_id); 123 const net::URLRequest* request);
124 void OnCookieResponse(DownloadInfoAndroid info, 124 void OnCookieResponse(DownloadInfo info,
125 const GetDownloadInfoCB& callback, 125 const GetDownloadInfoCB& callback,
126 const std::string& cookie); 126 const std::string& cookie);
127 void StartDownloadOnUIThread(const GetDownloadInfoCB& callback, 127 void StartDownloadOnUIThread(const GetDownloadInfoCB& callback,
128 const DownloadInfoAndroid& info); 128 const DownloadInfo& info);
129 void StartAndroidDownload(int render_process_id, 129 void StartAndroidDownload(int render_process_id,
130 int render_view_id, 130 int render_view_id,
131 bool must_download, 131 bool must_download,
132 const DownloadInfoAndroid& info); 132 const DownloadInfo& info);
133 void StartAndroidDownloadInternal(int render_process_id, 133 void StartAndroidDownloadInternal(int render_process_id,
134 int render_view_id, 134 int render_view_id,
135 bool must_download, 135 bool must_download,
136 const DownloadInfoAndroid& info, 136 const DownloadInfo& info,
137 bool allowed); 137 bool allowed);
138 138
139 // The download item contains dangerous file types. 139 // The download item contains dangerous file types.
140 void OnDangerousDownload(DownloadItem *item); 140 void OnDangerousDownload(content::DownloadItem *item);
141 141
142 base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents( 142 base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents(
143 WebContents* web_contents); 143 content::WebContents* web_contents);
144 144
145 // Creates Java object if it is not created already and returns it. 145 // Creates Java object if it is not created already and returns it.
146 JavaObject* GetJavaObject(); 146 JavaObject* GetJavaObject();
147 147
148 JavaObject* java_object_; 148 JavaObject* java_object_;
149 149
150 std::string default_file_name_; 150 std::string default_file_name_;
151 151
152 ScopedVector<DeferredDownloadObserver> deferred_downloads_; 152 DISALLOW_COPY_AND_ASSIGN(DownloadController);
153
154 DISALLOW_COPY_AND_ASSIGN(DownloadControllerAndroidImpl);
155 }; 153 };
156 154
157 } // namespace content 155 #endif // CHROME_BROWSER_ANDROID_DOWNLOAD_DOWNLOAD_CONTROLLER_H_
158
159 #endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698