Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / android / infobars / download_overwrite_infobar.cc
blob4c58a0e1eee510efb9865d5f24684d4f86775ebf
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.
5 #include "chrome/browser/ui/android/infobars/download_overwrite_infobar.h"
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/DownloadOverwriteInfoBar_jni.h"
15 using chrome::android::DownloadOverwriteInfoBarDelegate;
17 // static
18 scoped_ptr<infobars::InfoBar> DownloadOverwriteInfoBar::CreateInfoBar(
19 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) {
20 return make_scoped_ptr(new DownloadOverwriteInfoBar(delegate.Pass()));
23 DownloadOverwriteInfoBar::~DownloadOverwriteInfoBar() {
26 DownloadOverwriteInfoBar::DownloadOverwriteInfoBar(
27 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate)
28 : InfoBarAndroid(delegate.Pass()) {
31 base::android::ScopedJavaLocalRef<jobject>
32 DownloadOverwriteInfoBar::CreateRenderInfoBar(JNIEnv* env) {
33 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 base::android::ScopedJavaLocalRef<jobject> java_infobar(
42 Java_DownloadOverwriteInfoBar_createInfoBar(
43 env, j_file_name.obj(), j_dir_name.obj(), j_dir_full_path.obj()));
44 return java_infobar;
47 void DownloadOverwriteInfoBar::ProcessButton(int action,
48 const std::string& action_value) {
49 if (!owner())
50 return; // We're closing; don't call anything, it might access the owner.
52 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate();
53 if (action == InfoBarAndroid::ACTION_OVERWRITE) {
54 if (delegate->OverwriteExistingFile())
55 RemoveSelf();
56 } else if (action == InfoBarAndroid::ACTION_CREATE_NEW_FILE) {
57 if (delegate->CreateNewFile())
58 RemoveSelf();
59 } else {
60 CHECK(false);
64 DownloadOverwriteInfoBarDelegate* DownloadOverwriteInfoBar::GetDelegate() {
65 return static_cast<DownloadOverwriteInfoBarDelegate*>(delegate());
68 // Native JNI methods ---------------------------------------------------------
70 bool RegisterDownloadOverwriteInfoBarDelegate(JNIEnv* env) {
71 return RegisterNativesImpl(env);