OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" | |
6 | |
7 #include "base/android/jni_android.h" | |
8 #include "base/android/jni_array.h" | |
9 #include "base/android/jni_string.h" | |
10 #include "base/android/jni_weak_ref.h" | |
11 #include "base/files/file_path.h" | |
12 #include "chrome/browser/android/download/download_overwrite_infobar_delegate.h" | |
13 #include "jni/DownloadOverwriteInfoBarDelegate_jni.h" | |
14 | |
15 using chrome::android::DownloadOverwriteInfoBarDelegate; | |
16 | |
17 // static | |
18 scoped_ptr<infobars::InfoBar> DownloadOverwriteInfoBar::CreateInfoBar( | |
19 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) { | |
20 return make_scoped_ptr(new DownloadOverwriteInfoBar(delegate.Pass())); | |
21 } | |
22 | |
23 DownloadOverwriteInfoBar::~DownloadOverwriteInfoBar() { | |
24 } | |
25 | |
26 DownloadOverwriteInfoBar::DownloadOverwriteInfoBar( | |
27 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) | |
28 : InfoBarAndroid(delegate.Pass()), java_delegate_() { | |
29 } | |
30 | |
31 ScopedJavaLocalRef<jobject> DownloadOverwriteInfoBar::CreateRenderInfoBar( | |
32 JNIEnv* env) { | |
33 java_delegate_.Reset(Java_DownloadOverwriteInfoBarDelegate_create(env)); | |
Ted C
2015/02/26 00:57:56
I find it quite odd that the infobar creates the j
Changwan Ryu
2015/03/02 14:46:37
Done.
| |
34 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); | |
35 ScopedJavaLocalRef<jstring> j_file_name = | |
36 base::android::ConvertUTF8ToJavaString(env, delegate->GetFileName()); | |
37 ScopedJavaLocalRef<jstring> j_dir_name = | |
38 base::android::ConvertUTF8ToJavaString(env, delegate->GetDirName()); | |
39 ScopedJavaLocalRef<jstring> j_dir_full_path = | |
40 base::android::ConvertUTF8ToJavaString(env, delegate->GetDirFullPath()); | |
41 return Java_DownloadOverwriteInfoBarDelegate_showDownloadOverwriteInfoBar( | |
42 env, java_delegate_.obj(), reinterpret_cast<intptr_t>(this), | |
43 j_file_name.obj(), j_dir_name.obj(), j_dir_full_path.obj()); | |
44 } | |
45 | |
46 void DownloadOverwriteInfoBar::ProcessButton(int action, | |
47 const std::string& action_value) { | |
48 if (!owner()) | |
49 return; // We're closing; don't call anything, it might access the owner. | |
50 | |
51 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); | |
52 if (action == InfoBarAndroid::ACTION_OVERWRITE) | |
53 delegate->OverwriteExistingFile(); | |
54 else if (action == InfoBarAndroid::ACTION_CREATE_NEW_FILE) | |
55 delegate->CreateNewFile(); | |
56 else | |
57 DCHECK(false); | |
58 | |
59 RemoveSelf(); | |
60 } | |
61 | |
62 DownloadOverwriteInfoBarDelegate* DownloadOverwriteInfoBar::GetDelegate() { | |
63 return static_cast<DownloadOverwriteInfoBarDelegate*>(delegate()); | |
64 } | |
65 | |
66 // Native JNI methods --------------------------------------------------------- | |
67 | |
68 bool RegisterDownloadOverwriteInfoBarDelegate(JNIEnv* env) { | |
69 return RegisterNativesImpl(env); | |
70 } | |
OLD | NEW |