| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/android/download/chrome_download_delegate.h" | 5 #include "chrome/browser/android/download/chrome_download_delegate.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <type_traits> | 10 #include <type_traits> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 ChromeDownloadDelegate::~ChromeDownloadDelegate() { | 77 ChromeDownloadDelegate::~ChromeDownloadDelegate() { |
| 78 JNIEnv* env = base::android::AttachCurrentThread(); | 78 JNIEnv* env = base::android::AttachCurrentThread(); |
| 79 env->DeleteGlobalRef(java_ref_); | 79 env->DeleteGlobalRef(java_ref_); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ChromeDownloadDelegate::SetJavaRef(JNIEnv* env, jobject jobj) { | 82 void ChromeDownloadDelegate::SetJavaRef(JNIEnv* env, jobject jobj) { |
| 83 java_ref_ = env->NewGlobalRef(jobj); | 83 java_ref_ = env->NewGlobalRef(jobj); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void ChromeDownloadDelegate::EnqueueDownloadManagerRequest( | |
| 87 const std::string& url, | |
| 88 const std::string& user_agent, | |
| 89 const base::string16& file_name, | |
| 90 const std::string& mime_type, | |
| 91 const std::string& cookie, | |
| 92 const std::string& referer) { | |
| 93 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 94 ScopedJavaLocalRef<jstring> jurl = | |
| 95 ConvertUTF8ToJavaString(env, url); | |
| 96 ScopedJavaLocalRef<jstring> juser_agent = | |
| 97 ConvertUTF8ToJavaString(env, user_agent); | |
| 98 ScopedJavaLocalRef<jstring> jmime_type = | |
| 99 ConvertUTF8ToJavaString(env, mime_type); | |
| 100 ScopedJavaLocalRef<jstring> jcookie = | |
| 101 ConvertUTF8ToJavaString(env, cookie); | |
| 102 ScopedJavaLocalRef<jstring> jreferer = | |
| 103 ConvertUTF8ToJavaString(env, referer); | |
| 104 ScopedJavaLocalRef<jstring> jfile_name = | |
| 105 base::android::ConvertUTF16ToJavaString(env, file_name); | |
| 106 Java_ChromeDownloadDelegate_enqueueAndroidDownloadManagerRequest( | |
| 107 env, java_ref_, jurl, juser_agent, jfile_name, jmime_type, jcookie, | |
| 108 jreferer); | |
| 109 } | |
| 110 | |
| 111 void Init(JNIEnv* env, | 86 void Init(JNIEnv* env, |
| 112 const JavaParamRef<jobject>& obj, | 87 const JavaParamRef<jobject>& obj, |
| 113 const JavaParamRef<jobject>& jweb_contents) { | 88 const JavaParamRef<jobject>& jweb_contents) { |
| 114 auto* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 89 auto* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
| 115 ChromeDownloadDelegate::CreateForWebContents(web_contents); | 90 ChromeDownloadDelegate::CreateForWebContents(web_contents); |
| 116 ChromeDownloadDelegate::FromWebContents(web_contents)->SetJavaRef(env, obj); | 91 ChromeDownloadDelegate::FromWebContents(web_contents)->SetJavaRef(env, obj); |
| 117 } | 92 } |
| 118 | 93 |
| 119 bool RegisterChromeDownloadDelegate(JNIEnv* env) { | 94 bool RegisterChromeDownloadDelegate(JNIEnv* env) { |
| 120 return RegisterNativesImpl(env); | 95 return RegisterNativesImpl(env); |
| 121 } | 96 } |
| 122 | 97 |
| 123 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeDownloadDelegate); | 98 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeDownloadDelegate); |
| OLD | NEW |