OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "chrome/browser/android/download_overwrite_infobar_delegate.h" |
| 12 #include "jni/DownloadOverwriteInfoBarDelegate_jni.h" |
| 13 |
| 14 using base::android::ConvertUTF8ToJavaString; |
| 15 using chrome::android::DownloadOverwriteInfoBarDelegate; |
| 16 |
| 17 // static |
| 18 scoped_ptr<infobars::InfoBar> DownloadOverwriteInfoBar::CreateInfoBar( |
| 19 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) { |
| 20 return scoped_ptr<infobars::InfoBar>( |
| 21 new DownloadOverwriteInfoBar(delegate.Pass())); |
| 22 } |
| 23 |
| 24 DownloadOverwriteInfoBar::DownloadOverwriteInfoBar( |
| 25 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) |
| 26 : InfoBarAndroid(delegate.PassAs<infobars::InfoBarDelegate>()), |
| 27 java_delegate_() { |
| 28 } |
| 29 |
| 30 DownloadOverwriteInfoBar::~DownloadOverwriteInfoBar() { |
| 31 } |
| 32 |
| 33 ScopedJavaLocalRef<jobject> DownloadOverwriteInfoBar::CreateRenderInfoBar( |
| 34 JNIEnv* env) { |
| 35 java_delegate_.Reset(Java_DownloadOverwriteInfoBarDelegate_create(env)); |
| 36 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); |
| 37 ScopedJavaLocalRef<jstring> j_file_name = |
| 38 ConvertUTF8ToJavaString(env, delegate->GetFileName()); |
| 39 ScopedJavaLocalRef<jstring> j_dir_name = |
| 40 ConvertUTF8ToJavaString(env, delegate->GetDirName()); |
| 41 ScopedJavaLocalRef<jstring> j_dir_full_path = |
| 42 ConvertUTF8ToJavaString(env, delegate->GetDirFullPath()); |
| 43 return Java_DownloadOverwriteInfoBarDelegate_showDownloadOverwriteInfoBar( |
| 44 env, java_delegate_.obj(), reinterpret_cast<intptr_t>(this), |
| 45 j_file_name.obj(), j_dir_name.obj(), j_dir_full_path.obj()); |
| 46 } |
| 47 |
| 48 void DownloadOverwriteInfoBar::ProcessButton( |
| 49 int action, const std::string& action_value) { |
| 50 if (!owner()) |
| 51 return; // We're closing; don't call anything, it might access the owner. |
| 52 |
| 53 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); |
| 54 if (action == InfoBarAndroid::ACTION_OK) { |
| 55 delegate->Accept(); |
| 56 } else if (action == InfoBarAndroid::ACTION_CANCEL) { |
| 57 delegate->Cancel(); |
| 58 } else { |
| 59 DCHECK_EQ(InfoBarAndroid::ACTION_NONE, action); |
| 60 } |
| 61 |
| 62 RemoveSelf(); |
| 63 } |
| 64 |
| 65 DownloadOverwriteInfoBarDelegate* DownloadOverwriteInfoBar::GetDelegate() { |
| 66 return delegate()->AsDownloadOverwriteInfoBarDelegate(); |
| 67 } |
| 68 |
| 69 // Native JNI methods --------------------------------------------------------- |
| 70 |
| 71 bool RegisterDownloadOverwriteInfoBarDelegate(JNIEnv* env) { |
| 72 return RegisterNativesImpl(env); |
| 73 } |
OLD | NEW |