OLD | NEW |
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 // DownloadController::NewGetDownload() => | 13 // DownloadControllerAndroid::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_H_ | 19 #ifndef CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_ |
20 #define CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_H_ | 20 #define CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_ |
21 | 21 |
22 #include <string> | 22 #include <string> |
23 | 23 |
24 #include "base/android/jni_helper.h" | 24 #include "base/android/jni_helper.h" |
25 #include "base/android/scoped_java_ref.h" | 25 #include "base/android/scoped_java_ref.h" |
26 #include "base/memory/singleton.h" | 26 #include "base/memory/singleton.h" |
| 27 #include "content/public/browser/android/download_controller_android.h" |
27 #include "content/public/browser/download_item.h" | 28 #include "content/public/browser/download_item.h" |
28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
29 #include "net/cookies/cookie_monster.h" | 30 #include "net/cookies/cookie_monster.h" |
30 | 31 |
31 namespace net { | 32 namespace net { |
32 class URLRequest; | 33 class URLRequest; |
33 } | 34 } |
34 | 35 |
35 namespace content { | 36 namespace content { |
36 struct GlobalRequestID; | 37 struct GlobalRequestID; |
37 class RenderViewHost; | 38 class RenderViewHost; |
38 class WebContents; | 39 class WebContents; |
39 | 40 |
40 class DownloadController : public DownloadItem::Observer { | 41 class DownloadControllerAndroidImpl : public DownloadControllerAndroid, |
| 42 public DownloadItem::Observer { |
41 public: | 43 public: |
| 44 static DownloadControllerAndroidImpl* GetInstance(); |
| 45 |
42 static bool RegisterDownloadController(JNIEnv* env); | 46 static bool RegisterDownloadController(JNIEnv* env); |
43 static DownloadController* GetInstance(); | |
44 | 47 |
45 // Called when DownloadController Java object is instantiated. | 48 // Called when DownloadController Java object is instantiated. |
46 void Init(JNIEnv* env, jobject obj); | 49 void Init(JNIEnv* env, jobject obj); |
47 | |
48 // Starts a new download request with Android. Should be called on the | |
49 // UI thread. | |
50 void CreateGETDownload(RenderViewHost* source, | |
51 int request_id); | |
52 | |
53 // Should be called when a POST download is started. Notifies the embedding | |
54 // app about the download. Called on the UI thread. | |
55 void OnPostDownloadStarted(WebContents* web_contents, | |
56 DownloadItem* download_item); | |
57 | |
58 // DownloadItem::Observer interface. | |
59 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE; | |
60 virtual void OnDownloadOpened(DownloadItem* item) OVERRIDE; | |
61 | |
62 private: | 50 private: |
63 // Used to store all the information about an Android download. | 51 // Used to store all the information about an Android download. |
64 struct DownloadInfoAndroid { | 52 struct DownloadInfoAndroid { |
65 explicit DownloadInfoAndroid(net::URLRequest* request); | 53 explicit DownloadInfoAndroid(net::URLRequest* request); |
66 ~DownloadInfoAndroid(); | 54 ~DownloadInfoAndroid(); |
67 | 55 |
68 // The URL from which we are downloading. This is the final URL after any | 56 // The URL from which we are downloading. This is the final URL after any |
69 // redirection by the server for |original_url_|. | 57 // redirection by the server for |original_url_|. |
70 GURL url; | 58 GURL url; |
71 // The original URL before any redirection by the server for this URL. | 59 // The original URL before any redirection by the server for this URL. |
72 GURL original_url; | 60 GURL original_url; |
73 int64 total_bytes; | 61 int64 total_bytes; |
74 std::string content_disposition; | 62 std::string content_disposition; |
75 std::string original_mime_type; | 63 std::string original_mime_type; |
76 std::string user_agent; | 64 std::string user_agent; |
77 std::string cookie; | 65 std::string cookie; |
78 std::string referer; | 66 std::string referer; |
79 | 67 |
80 WebContents* web_contents; | 68 WebContents* web_contents; |
81 // Default copy constructor is used for passing this struct by value. | 69 // Default copy constructor is used for passing this struct by value. |
82 }; | 70 }; |
| 71 struct JavaObject; |
| 72 friend struct DefaultSingletonTraits<DownloadControllerAndroidImpl>; |
| 73 DownloadControllerAndroidImpl(); |
| 74 virtual ~DownloadControllerAndroidImpl(); |
83 | 75 |
84 struct JavaObject; | 76 // DownloadControllerAndroid implementation. |
85 friend struct DefaultSingletonTraits<DownloadController>; | 77 virtual void CreateGETDownload(RenderViewHost* source, |
86 DownloadController(); | 78 int request_id) OVERRIDE; |
87 virtual ~DownloadController(); | 79 virtual void OnPostDownloadStarted(WebContents* web_contents, |
| 80 DownloadItem* download_item) OVERRIDE; |
| 81 |
| 82 // DownloadItem::Observer interface. |
| 83 virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE; |
| 84 virtual void OnDownloadOpened(DownloadItem* item) OVERRIDE; |
| 85 |
88 | 86 |
89 void PrepareDownloadInfo(const GlobalRequestID& global_id, | 87 void PrepareDownloadInfo(const GlobalRequestID& global_id, |
90 int render_process_id, | 88 int render_process_id, |
91 int render_view_id); | 89 int render_view_id); |
92 | 90 |
93 void CheckPolicyAndLoadCookies(const DownloadInfoAndroid& info, | 91 void CheckPolicyAndLoadCookies(const DownloadInfoAndroid& info, |
94 int render_process_id, | 92 int render_process_id, |
95 int render_view_id, | 93 int render_view_id, |
96 const GlobalRequestID& global_id, | 94 const GlobalRequestID& global_id, |
97 const net::CookieList& cookie_list); | 95 const net::CookieList& cookie_list); |
(...skipping 16 matching lines...) Expand all Loading... |
114 WebContents* web_contents); | 112 WebContents* web_contents); |
115 | 113 |
116 base::android::ScopedJavaLocalRef<jobject> GetContentView( | 114 base::android::ScopedJavaLocalRef<jobject> GetContentView( |
117 int render_process_id, int render_view_id); | 115 int render_process_id, int render_view_id); |
118 | 116 |
119 // Creates Java object if it is not created already and returns it. | 117 // Creates Java object if it is not created already and returns it. |
120 JavaObject* GetJavaObject(); | 118 JavaObject* GetJavaObject(); |
121 | 119 |
122 JavaObject* java_object_; | 120 JavaObject* java_object_; |
123 | 121 |
124 DISALLOW_COPY_AND_ASSIGN(DownloadController); | 122 DISALLOW_COPY_AND_ASSIGN(DownloadControllerAndroidImpl); |
125 }; | 123 }; |
126 | 124 |
127 } // namespace content | 125 } // namespace content |
128 | 126 |
129 #endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_H_ | 127 #endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_ |
OLD | NEW |