| 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::NewGetDownload() => |
| 14 // DownloadController.newHttpGetDownload() => |
| 15 // DownloadListener.onDownloadStart() / |
| 16 // DownloadListener2.requestHttpGetDownload() |
| 17 // |
| 18 |
| 19 #ifndef CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_H_ |
| 20 #define CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_H_ |
| 21 #pragma once |
| 22 |
| 23 #include <string> |
| 24 |
| 25 #include "base/android/jni_helper.h" |
| 26 #include "base/memory/singleton.h" |
| 27 #include "content/public/browser/download_item.h" |
| 28 #include "googleurl/src/gurl.h" |
| 29 |
| 30 namespace net { |
| 31 class URLRequest; |
| 32 } |
| 33 |
| 34 namespace content { |
| 35 struct GlobalRequestID; |
| 36 class RenderViewHost; |
| 37 class WebContents; |
| 38 |
| 39 class DownloadController : public content::DownloadItem::Observer { |
| 40 public: |
| 41 static bool RegisterDownloadController(JNIEnv* env); |
| 42 static DownloadController* GetInstance(); |
| 43 |
| 44 // Called when DownloadController Java object is instantiated. |
| 45 void Init(JNIEnv* env, jobject obj); |
| 46 |
| 47 // Starts a new download request with Android. Should be called on the |
| 48 // UI thread. |
| 49 void NewGetDownload(content::RenderViewHost* source, |
| 50 int request_id); |
| 51 |
| 52 // Should be called when a POST download is started. Notifies the embedding |
| 53 // app about the download. Called on the UI thread. |
| 54 void OnPostDownloadStarted(content::WebContents* web_contents, |
| 55 content::DownloadItem* download_item); |
| 56 |
| 57 // DownloadItem::Observer interface. |
| 58 virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE; |
| 59 virtual void OnDownloadOpened(content::DownloadItem* item) OVERRIDE; |
| 60 |
| 61 private: |
| 62 // Used to store all the information about an Android download. |
| 63 struct DownloadInfoAndroid { |
| 64 explicit DownloadInfoAndroid(net::URLRequest* request); |
| 65 ~DownloadInfoAndroid() {} |
| 66 |
| 67 // The URL from which we are downloading. This is the final URL after any |
| 68 // redirection by the server for |original_url_|. |
| 69 GURL url; |
| 70 // The original URL before any redirection by the server for this URL. |
| 71 GURL original_url; |
| 72 int64 total_bytes; |
| 73 std::string content_disposition; |
| 74 std::string original_mime_type; |
| 75 |
| 76 std::string user_agent; |
| 77 std::string cookie; |
| 78 |
| 79 content::WebContents* web_contents; |
| 80 // Default copy constructor is used for passing this struct by value. |
| 81 }; |
| 82 |
| 83 struct JavaObject; |
| 84 friend struct DefaultSingletonTraits<DownloadController>; |
| 85 DownloadController(); |
| 86 virtual ~DownloadController(); |
| 87 |
| 88 void PrepareDownloadInfo(const content::GlobalRequestID& global_id, |
| 89 int render_process_id, |
| 90 int render_view_id); |
| 91 |
| 92 void OnCookieResponse(DownloadInfoAndroid info, |
| 93 int render_process_id, |
| 94 int render_view_id, |
| 95 const std::string& cookie); |
| 96 |
| 97 void StartAndroidDownload(const DownloadInfoAndroid& info, |
| 98 int render_process_id, |
| 99 int render_view_id); |
| 100 |
| 101 jobject GetContentViewFromWebContents(content::WebContents* web_contents); |
| 102 jobject GetContentView(int render_process_id, int render_view_id); |
| 103 |
| 104 // Creates Java object if it is not created already and returns it. |
| 105 JavaObject* java_object(); |
| 106 |
| 107 JavaObject* java_object_; |
| 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(DownloadController); |
| 110 }; |
| 111 |
| 112 } // namespace content |
| 113 |
| 114 #endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_H_ |
| OLD | NEW |