Chromium Code Reviews| Index: chrome/browser/ui/android/infobars/download_overwrite_infobar.cc |
| diff --git a/chrome/browser/ui/android/infobars/download_overwrite_infobar.cc b/chrome/browser/ui/android/infobars/download_overwrite_infobar.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..92023c4d3b67ddcd950d5865dd136cac709d5225 |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/infobars/download_overwrite_infobar.cc |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h" |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_array.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/android/jni_weak_ref.h" |
| +#include "base/files/file_path.h" |
| +#include "chrome/browser/android/download_overwrite_infobar_delegate.h" |
| +#include "jni/DownloadOverwriteInfoBarDelegate_jni.h" |
| + |
| +using chrome::android::DownloadOverwriteInfoBarDelegate; |
| + |
| +// static |
| +scoped_ptr<infobars::InfoBar> DownloadOverwriteInfoBar::CreateInfoBar( |
| + scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) { |
| + return make_scoped_ptr(new DownloadOverwriteInfoBar(delegate.Pass())); |
| +} |
| + |
| +DownloadOverwriteInfoBar::~DownloadOverwriteInfoBar() { |
| +} |
|
qinmin
2015/02/20 01:00:40
nit: you can move this to the line above
Changwan Ryu
2015/02/23 06:50:37
This is the result of git cl format. It seems that
|
| + |
| +DownloadOverwriteInfoBar::DownloadOverwriteInfoBar( |
| + scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) |
| + : InfoBarAndroid(delegate.Pass()), java_delegate_() { |
| +} |
| + |
| +ScopedJavaLocalRef<jobject> DownloadOverwriteInfoBar::CreateRenderInfoBar( |
| + JNIEnv* env) { |
| + java_delegate_.Reset(Java_DownloadOverwriteInfoBarDelegate_create(env)); |
| + DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); |
| + base::FilePath suggested_download_path = delegate->suggested_download_path(); |
| + ScopedJavaLocalRef<jstring> j_file_name = |
| + base::android::ConvertUTF8ToJavaString( |
| + env, suggested_download_path.BaseName().value()); |
| + ScopedJavaLocalRef<jstring> j_dir_name = |
| + base::android::ConvertUTF8ToJavaString( |
| + env, suggested_download_path.DirName().BaseName().value()); |
| + ScopedJavaLocalRef<jstring> j_dir_full_path = |
| + base::android::ConvertUTF8ToJavaString( |
| + env, suggested_download_path.DirName().value()); |
| + return Java_DownloadOverwriteInfoBarDelegate_showDownloadOverwriteInfoBar( |
| + env, java_delegate_.obj(), reinterpret_cast<intptr_t>(this), |
| + j_file_name.obj(), j_dir_name.obj(), j_dir_full_path.obj()); |
| +} |
| + |
| +void DownloadOverwriteInfoBar::ProcessButton(int action, |
| + const std::string& action_value) { |
| + if (!owner()) |
| + return; // We're closing; don't call anything, it might access the owner. |
| + |
| + DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); |
| + if (action == InfoBarAndroid::ACTION_OVERWRITE) |
| + delegate->OverwriteExistingFile(); |
| + else if (action == InfoBarAndroid::ACTION_CREATE_NEW_FILE) |
| + delegate->CreateNewFile(); |
| + else |
| + DCHECK(false); |
| + |
| + RemoveSelf(); |
| +} |
| + |
| +DownloadOverwriteInfoBarDelegate* DownloadOverwriteInfoBar::GetDelegate() { |
| + return static_cast<DownloadOverwriteInfoBarDelegate*>(delegate()); |
| +} |
| + |
| +// Native JNI methods --------------------------------------------------------- |
| + |
| +bool RegisterDownloadOverwriteInfoBarDelegate(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |