| 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 <utility> | |
| 8 | |
| 9 #include "base/android/jni_android.h" | |
| 10 #include "base/android/jni_array.h" | |
| 11 #include "base/android/jni_string.h" | |
| 12 #include "base/android/jni_weak_ref.h" | |
| 13 #include "base/files/file_path.h" | |
| 14 #include "base/memory/ptr_util.h" | |
| 15 #include "chrome/browser/android/download/download_overwrite_infobar_delegate.h" | |
| 16 #include "jni/DownloadOverwriteInfoBar_jni.h" | |
| 17 | |
| 18 using base::android::ScopedJavaLocalRef; | |
| 19 using chrome::android::DownloadOverwriteInfoBarDelegate; | |
| 20 | |
| 21 // static | |
| 22 std::unique_ptr<infobars::InfoBar> DownloadOverwriteInfoBar::CreateInfoBar( | |
| 23 std::unique_ptr<DownloadOverwriteInfoBarDelegate> delegate) { | |
| 24 return base::WrapUnique(new DownloadOverwriteInfoBar(std::move(delegate))); | |
| 25 } | |
| 26 | |
| 27 DownloadOverwriteInfoBar::~DownloadOverwriteInfoBar() { | |
| 28 } | |
| 29 | |
| 30 DownloadOverwriteInfoBar::DownloadOverwriteInfoBar( | |
| 31 std::unique_ptr<DownloadOverwriteInfoBarDelegate> delegate) | |
| 32 : InfoBarAndroid(std::move(delegate)) {} | |
| 33 | |
| 34 base::android::ScopedJavaLocalRef<jobject> | |
| 35 DownloadOverwriteInfoBar::CreateRenderInfoBar(JNIEnv* env) { | |
| 36 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); | |
| 37 | |
| 38 ScopedJavaLocalRef<jstring> j_file_name = | |
| 39 base::android::ConvertUTF8ToJavaString(env, delegate->GetFileName()); | |
| 40 ScopedJavaLocalRef<jstring> j_dir_name = | |
| 41 base::android::ConvertUTF8ToJavaString(env, delegate->GetDirName()); | |
| 42 ScopedJavaLocalRef<jstring> j_dir_full_path = | |
| 43 base::android::ConvertUTF8ToJavaString(env, delegate->GetDirFullPath()); | |
| 44 base::android::ScopedJavaLocalRef<jobject> java_infobar( | |
| 45 Java_DownloadOverwriteInfoBar_createInfoBar(env, j_file_name, j_dir_name, | |
| 46 j_dir_full_path)); | |
| 47 return java_infobar; | |
| 48 } | |
| 49 | |
| 50 void DownloadOverwriteInfoBar::ProcessButton(int action) { | |
| 51 if (!owner()) | |
| 52 return; // We're closing; don't call anything, it might access the owner. | |
| 53 | |
| 54 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); | |
| 55 if (action == InfoBarAndroid::ACTION_OVERWRITE) { | |
| 56 if (delegate->OverwriteExistingFile()) | |
| 57 RemoveSelf(); | |
| 58 } else if (action == InfoBarAndroid::ACTION_CREATE_NEW_FILE) { | |
| 59 if (delegate->CreateNewFile()) | |
| 60 RemoveSelf(); | |
| 61 } else { | |
| 62 CHECK(false); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 DownloadOverwriteInfoBarDelegate* DownloadOverwriteInfoBar::GetDelegate() { | |
| 67 return static_cast<DownloadOverwriteInfoBarDelegate*>(delegate()); | |
| 68 } | |
| OLD | NEW |