Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
2012
nilesh
2012/05/25 23:10:22
Done.
| |
| 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_ | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
should this file go into content/browser/download/
nilesh
2012/05/25 23:10:22
We dont plan to have multiple files here.
Maybe co
| |
| 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 struct DownloadInfoAndroid; | |
| 31 | |
| 32 namespace content { | |
| 33 struct GlobalRequestID; | |
| 34 class RenderViewHost; | |
| 35 class WebContents; | |
| 36 } | |
| 37 | |
| 38 namespace net { | |
| 39 class URLRequest; | |
| 40 } | |
| 41 | |
| 42 class DownloadController : public content::DownloadItem::Observer { | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
code in src/content should be in the content names
nilesh
2012/05/25 23:10:22
Done.
| |
| 43 public: | |
| 44 static DownloadController* GetInstance(); | |
| 45 | |
| 46 // Called when DownloadController Java object is instantiated. | |
| 47 void Init(JNIEnv* env, jobject obj); | |
| 48 | |
| 49 // Starts a new download request with Android. Should be called on the | |
| 50 // UI thread. | |
| 51 void NewGetDownload(content::RenderViewHost* source, | |
| 52 int request_id); | |
| 53 | |
| 54 // Should be called when a POST download is started. Notifies the embedding | |
| 55 // app about the download. Called on the UI thread. | |
| 56 void OnPostDownloadStarted(content::WebContents* web_contents, | |
| 57 content::DownloadItem* download_item); | |
| 58 | |
| 59 // DownloadItem::Observer interface. | |
| 60 virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE; | |
| 61 virtual void OnDownloadOpened(content::DownloadItem* item) OVERRIDE { } | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
virtual methods can't be inlined, therefore, the b
nilesh
2012/05/25 23:10:22
Done.
| |
| 62 | |
| 63 private: | |
| 64 friend struct DefaultSingletonTraits<DownloadController>; | |
| 65 DownloadController(); | |
| 66 virtual ~DownloadController(); | |
| 67 | |
| 68 // Used to store all the information about an Android download. | |
| 69 struct DownloadInfoAndroid { | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
definitions come before ctor/dtor
nilesh
2012/05/25 23:10:22
Done.
| |
| 70 explicit DownloadInfoAndroid(net::URLRequest* request); | |
| 71 ~DownloadInfoAndroid() {} | |
| 72 | |
| 73 // The URL from which we are downloading. This is the final URL after any | |
| 74 // redirection by the server for |original_url_|. | |
| 75 GURL url; | |
| 76 // The original URL before any redirection by the server for this URL. | |
| 77 GURL original_url; | |
| 78 int64 total_bytes; | |
| 79 std::string content_disposition; | |
| 80 std::string original_mime_type; | |
| 81 | |
| 82 std::string user_agent; | |
| 83 std::string cookie; | |
| 84 | |
| 85 content::WebContents* web_contents; | |
| 86 // Default copy constructor is used for passing this struct by value. | |
| 87 }; | |
| 88 | |
| 89 void PrepareDownloadInfo(const content::GlobalRequestID& global_id, | |
| 90 int render_process_id, | |
| 91 int render_view_id); | |
| 92 | |
| 93 void OnCookieResponse(DownloadInfoAndroid info, | |
| 94 int render_process_id, | |
| 95 int render_view_id, | |
| 96 const std::string& cookie); | |
| 97 | |
| 98 void StartAndroidDownload(const DownloadInfoAndroid& info, | |
| 99 int render_process_id, | |
| 100 int render_view_id); | |
| 101 | |
| 102 jobject GetContentViewFromWebContents(content::WebContents* web_contents); | |
| 103 jobject GetContentView(int render_process_id, int render_view_id); | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
empty line between method decls and variables
nilesh
2012/05/25 23:10:22
Done.
| |
| 104 struct JavaObject; | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
type declarations come before methods
nilesh
2012/05/25 23:10:22
Done.
| |
| 105 JavaObject* java_object_; | |
| 106 | |
| 107 // Creates Java object if it is not created already and returns it. | |
| 108 JavaObject* java_object(); | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
methods before member variables
nilesh
2012/05/25 23:10:22
Done.
| |
| 109 }; | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
disallow copy/assign
nilesh
2012/05/25 23:10:22
Done.
| |
| 110 | |
| 111 bool RegisterDownloadController(JNIEnv* env); | |
|
jochen (gone - plz use gerrit)
2012/05/25 21:29:37
can this be a static method on DownloadController
nilesh
2012/05/25 23:10:22
Done.
| |
| 112 | |
| 113 #endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_H_ | |
| OLD | NEW |