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

Side by Side Diff: content/browser/android/download_controller_android_impl.h

Issue 1217223006: Prompt user for file access permission before download starts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing asanka's comments Created 5 years, 5 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 //
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 static DownloadControllerAndroidImpl* GetInstance(); 47 static DownloadControllerAndroidImpl* GetInstance();
48 48
49 static bool RegisterDownloadController(JNIEnv* env); 49 static bool RegisterDownloadController(JNIEnv* env);
50 50
51 // Called when DownloadController Java object is instantiated. 51 // Called when DownloadController Java object is instantiated.
52 void Init(JNIEnv* env, jobject obj); 52 void Init(JNIEnv* env, jobject obj);
53 53
54 // Removes a deferred download from |deferred_downloads_|. 54 // Removes a deferred download from |deferred_downloads_|.
55 void CancelDeferredDownload(DeferredDownloadObserver* observer); 55 void CancelDeferredDownload(DeferredDownloadObserver* observer);
56 56
57 // DownloadControllerAndroid implementation.
58 void AcquireFileAccessPermission(
59 WebContents* web_contents,
60 const AcquireFileAccessPermissionCallback& callback) override;
61
57 private: 62 private:
58 // Used to store all the information about an Android download. 63 // Used to store all the information about an Android download.
59 struct DownloadInfoAndroid { 64 struct DownloadInfoAndroid {
60 explicit DownloadInfoAndroid(net::URLRequest* request); 65 explicit DownloadInfoAndroid(net::URLRequest* request);
61 ~DownloadInfoAndroid(); 66 ~DownloadInfoAndroid();
62 67
63 // The URL from which we are downloading. This is the final URL after any 68 // The URL from which we are downloading. This is the final URL after any
64 // redirection by the server for |original_url_|. 69 // redirection by the server for |original_url_|.
65 GURL url; 70 GURL url;
66 // The original URL before any redirection by the server for this URL. 71 // The original URL before any redirection by the server for this URL.
67 GURL original_url; 72 GURL original_url;
68 int64 total_bytes; 73 int64 total_bytes;
69 std::string content_disposition; 74 std::string content_disposition;
70 std::string original_mime_type; 75 std::string original_mime_type;
71 std::string user_agent; 76 std::string user_agent;
72 std::string cookie; 77 std::string cookie;
73 std::string referer; 78 std::string referer;
74 bool has_user_gesture; 79 bool has_user_gesture;
75 80
76 WebContents* web_contents; 81 WebContents* web_contents;
77 // Default copy constructor is used for passing this struct by value. 82 // Default copy constructor is used for passing this struct by value.
78 }; 83 };
79 struct JavaObject; 84 struct JavaObject;
80 friend struct DefaultSingletonTraits<DownloadControllerAndroidImpl>; 85 friend struct DefaultSingletonTraits<DownloadControllerAndroidImpl>;
81 DownloadControllerAndroidImpl(); 86 DownloadControllerAndroidImpl();
82 ~DownloadControllerAndroidImpl() override; 87 ~DownloadControllerAndroidImpl() override;
83 88
89 // Helper method for implementing AcquireFileAccessPermission().
90 bool HasFileAccessPermission(
91 base::android::ScopedJavaLocalRef<jobject> j_content_view_core);
92 void PromptUserForPermission(
93 WebContents* web_contents,
94 const AcquireFileAccessPermissionCallback& callback);
95
84 // DownloadControllerAndroid implementation. 96 // DownloadControllerAndroid implementation.
85 void CreateGETDownload(int render_process_id, 97 void CreateGETDownload(int render_process_id,
86 int render_view_id, 98 int render_view_id,
87 int request_id) override; 99 int request_id) override;
88 void OnDownloadStarted(DownloadItem* download_item) override; 100 void OnDownloadStarted(DownloadItem* download_item) override;
89 void StartContextMenuDownload(const ContextMenuParams& params, 101 void StartContextMenuDownload(const ContextMenuParams& params,
90 WebContents* web_contents, 102 WebContents* web_contents,
91 bool is_link, 103 bool is_link,
92 const std::string& extra_headers) override; 104 const std::string& extra_headers) override;
93 void DangerousDownloadValidated(WebContents* web_contents, 105 void DangerousDownloadValidated(WebContents* web_contents,
(...skipping 15 matching lines...) Expand all
109 const GetDownloadInfoCB& callback, 121 const GetDownloadInfoCB& callback,
110 const GlobalRequestID& global_id); 122 const GlobalRequestID& global_id);
111 void OnCookieResponse(DownloadInfoAndroid info, 123 void OnCookieResponse(DownloadInfoAndroid info,
112 const GetDownloadInfoCB& callback, 124 const GetDownloadInfoCB& callback,
113 const std::string& cookie); 125 const std::string& cookie);
114 void StartDownloadOnUIThread(const GetDownloadInfoCB& callback, 126 void StartDownloadOnUIThread(const GetDownloadInfoCB& callback,
115 const DownloadInfoAndroid& info); 127 const DownloadInfoAndroid& info);
116 void StartAndroidDownload(int render_process_id, 128 void StartAndroidDownload(int render_process_id,
117 int render_view_id, 129 int render_view_id,
118 const DownloadInfoAndroid& info); 130 const DownloadInfoAndroid& info);
131 void StartAndroidDownloadInternal(int render_process_id,
132 int render_view_id,
133 const DownloadInfoAndroid& info,
134 bool allowed);
119 135
120 // The download item contains dangerous file types. 136 // The download item contains dangerous file types.
121 void OnDangerousDownload(DownloadItem *item); 137 void OnDangerousDownload(DownloadItem *item);
122 138
123 base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents( 139 base::android::ScopedJavaLocalRef<jobject> GetContentViewCoreFromWebContents(
124 WebContents* web_contents); 140 WebContents* web_contents);
125 141
126 WebContents* GetWebContents(int render_process_id, int render_view_id); 142 WebContents* GetWebContents(int render_process_id, int render_view_id);
127 143
128 // Creates Java object if it is not created already and returns it. 144 // Creates Java object if it is not created already and returns it.
129 JavaObject* GetJavaObject(); 145 JavaObject* GetJavaObject();
130 146
131 JavaObject* java_object_; 147 JavaObject* java_object_;
132 148
133 ScopedVector<DeferredDownloadObserver> deferred_downloads_; 149 ScopedVector<DeferredDownloadObserver> deferred_downloads_;
134 150
135 DISALLOW_COPY_AND_ASSIGN(DownloadControllerAndroidImpl); 151 DISALLOW_COPY_AND_ASSIGN(DownloadControllerAndroidImpl);
136 }; 152 };
137 153
138 } // namespace content 154 } // namespace content
139 155
140 #endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_ 156 #endif // CONTENT_BROWSER_ANDROID_DOWNLOAD_CONTROLLER_ANDROID_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698