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 #include "content/browser/android/download_controller.h" | 5 #include "content/browser/android/download_controller.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "content/browser/android/content_view_core_impl.h" | |
13 #include "content/browser/download/download_item_impl.h" | 12 #include "content/browser/download/download_item_impl.h" |
14 #include "content/browser/renderer_host/render_process_host_impl.h" | 13 #include "content/browser/renderer_host/render_process_host_impl.h" |
15 #include "content/browser/renderer_host/render_view_host_delegate.h" | 14 #include "content/browser/renderer_host/render_view_host_delegate.h" |
16 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
17 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 16 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
18 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
19 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/global_request_id.h" | 19 #include "content/public/browser/global_request_id.h" |
21 #include "jni/download_controller_jni.h" | 20 #include "jni/download_controller_jni.h" |
22 #include "net/cookies/cookie_options.h" | 21 #include "net/cookies/cookie_options.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 211 |
213 void DownloadController::OnPostDownloadStarted( | 212 void DownloadController::OnPostDownloadStarted( |
214 WebContents* web_contents, | 213 WebContents* web_contents, |
215 DownloadItem* download_item) { | 214 DownloadItem* download_item) { |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
217 JNIEnv* env = AttachCurrentThread(); | 216 JNIEnv* env = AttachCurrentThread(); |
218 | 217 |
219 // Register for updates to the DownloadItem. | 218 // Register for updates to the DownloadItem. |
220 download_item->AddObserver(this); | 219 download_item->AddObserver(this); |
221 | 220 |
222 jobject view = GetContentViewCoreFromWebContents(web_contents); | 221 jobject view = GetContentViewFromWebContents(web_contents); |
223 if(!view) { | 222 if(!view) { |
224 // The view went away. Can't proceed. | 223 // The view went away. Can't proceed. |
225 return; | 224 return; |
226 } | 225 } |
227 | 226 |
228 Java_DownloadController_onHttpPostDownloadStarted( | 227 Java_DownloadController_onHttpPostDownloadStarted( |
229 env, GetJavaObject()->Controller(env).obj(), view); | 228 env, GetJavaObject()->Controller(env).obj(), view); |
230 } | 229 } |
231 | 230 |
232 void DownloadController::OnDownloadUpdated(DownloadItem* item) { | 231 void DownloadController::OnDownloadUpdated(DownloadItem* item) { |
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
234 | 233 |
235 if (item->GetState() != DownloadItem::COMPLETE) | 234 if (item->GetState() != DownloadItem::COMPLETE) |
236 return; | 235 return; |
237 | 236 |
238 // Call onHttpPostDownloadCompleted | 237 // Call onHttpPostDownloadCompleted |
239 JNIEnv* env = AttachCurrentThread(); | 238 JNIEnv* env = AttachCurrentThread(); |
240 ScopedJavaLocalRef<jstring> jurl = | 239 ScopedJavaLocalRef<jstring> jurl = |
241 ConvertUTF8ToJavaString(env, item->GetURL().spec()); | 240 ConvertUTF8ToJavaString(env, item->GetURL().spec()); |
242 ScopedJavaLocalRef<jstring> jcontent_disposition = | 241 ScopedJavaLocalRef<jstring> jcontent_disposition = |
243 ConvertUTF8ToJavaString(env, item->GetContentDisposition()); | 242 ConvertUTF8ToJavaString(env, item->GetContentDisposition()); |
244 ScopedJavaLocalRef<jstring> jmime_type = | 243 ScopedJavaLocalRef<jstring> jmime_type = |
245 ConvertUTF8ToJavaString(env, item->GetMimeType()); | 244 ConvertUTF8ToJavaString(env, item->GetMimeType()); |
246 ScopedJavaLocalRef<jstring> jpath = | 245 ScopedJavaLocalRef<jstring> jpath = |
247 ConvertUTF8ToJavaString(env, item->GetFullPath().value()); | 246 ConvertUTF8ToJavaString(env, item->GetFullPath().value()); |
248 | 247 |
249 jobject view_core = GetContentViewCoreFromWebContents(item->GetWebContents()); | 248 jobject view = GetContentViewFromWebContents(item->GetWebContents()); |
250 if (!view_core) { | 249 if(!view) { |
251 // We can get NULL WebContents from the DownloadItem. | 250 // We can get NULL WebContents from the DownloadItem. |
252 return; | 251 return; |
253 } | 252 } |
254 | 253 |
255 Java_DownloadController_onHttpPostDownloadCompleted(env, | 254 Java_DownloadController_onHttpPostDownloadCompleted(env, |
256 GetJavaObject()->Controller(env).obj(), view_core, jurl.obj(), | 255 GetJavaObject()->Controller(env).obj(), view, jurl.obj(), |
257 jcontent_disposition.obj(), jmime_type.obj(), jpath.obj(), | 256 jcontent_disposition.obj(), jmime_type.obj(), jpath.obj(), |
258 item->GetReceivedBytes(), true); | 257 item->GetReceivedBytes(), true); |
259 } | 258 } |
260 | 259 |
261 void DownloadController::OnDownloadOpened(DownloadItem* item) { | 260 void DownloadController::OnDownloadOpened(DownloadItem* item) { |
262 } | 261 } |
263 | 262 |
264 jobject DownloadController::GetContentView(int render_process_id, | 263 jobject DownloadController::GetContentView(int render_process_id, |
265 int render_view_id) { | 264 int render_view_id) { |
266 RenderViewHost* render_view_host = | 265 RenderViewHost* render_view_host = |
267 RenderViewHost::FromID(render_process_id, render_view_id); | 266 RenderViewHost::FromID(render_process_id, render_view_id); |
268 | 267 |
269 if (!render_view_host) | 268 if (!render_view_host) |
270 return NULL; | 269 return NULL; |
271 | 270 |
272 WebContents* web_contents = | 271 WebContents* web_contents = |
273 render_view_host->GetDelegate()->GetAsWebContents(); | 272 render_view_host->GetDelegate()->GetAsWebContents(); |
274 | 273 |
275 if (!web_contents) | 274 if (!web_contents) |
276 return NULL; | 275 return NULL; |
277 | 276 |
278 return GetContentViewCoreFromWebContents(web_contents); | 277 return GetContentViewFromWebContents(web_contents); |
279 } | 278 } |
280 | 279 |
281 jobject DownloadController::GetContentViewCoreFromWebContents( | 280 jobject DownloadController::GetContentViewFromWebContents( |
282 WebContents* web_contents) { | 281 WebContents* web_contents) { |
283 NOTIMPLEMENTED(); | 282 NOTIMPLEMENTED(); |
284 return NULL; | 283 return NULL; |
285 } | 284 } |
286 | 285 |
287 DownloadController::JavaObject* DownloadController::GetJavaObject() { | 286 DownloadController::JavaObject* DownloadController::GetJavaObject() { |
288 if (!java_object_) { | 287 if (!java_object_) { |
289 // Initialize Java DownloadController by calling | 288 // Initialize Java DownloadController by calling |
290 // DownloadController.getInstance(), which will call Init() | 289 // DownloadController.getInstance(), which will call Init() |
291 // if Java DownloadController is not instantiated already. | 290 // if Java DownloadController is not instantiated already. |
(...skipping 18 matching lines...) Expand all Loading... |
310 request->extra_request_headers().GetHeader( | 309 request->extra_request_headers().GetHeader( |
311 net::HttpRequestHeaders::kUserAgent, | 310 net::HttpRequestHeaders::kUserAgent, |
312 &user_agent); | 311 &user_agent); |
313 if (!request->url_chain().empty()) { | 312 if (!request->url_chain().empty()) { |
314 original_url = request->url_chain().front(); | 313 original_url = request->url_chain().front(); |
315 url = request->url_chain().back(); | 314 url = request->url_chain().back(); |
316 } | 315 } |
317 } | 316 } |
318 | 317 |
319 } // namespace content | 318 } // namespace content |
OLD | NEW |