Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / android / infobars / download_overwrite_infobar.cc
bloba5da96935be3dc757dc2a598a4f7a2de0325099f
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, reinterpret_cast<intptr_t>(this), j_file_name.obj(),
44 j_dir_name.obj(), j_dir_full_path.obj()));
45 return java_infobar;
48 void DownloadOverwriteInfoBar::ProcessButton(int action,
49 const std::string& action_value) {
50 if (!owner())
51 return; // We're closing; don't call anything, it might access the owner.
53 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate();
54 if (action == InfoBarAndroid::ACTION_OVERWRITE)
55 delegate->OverwriteExistingFile();
56 else if (action == InfoBarAndroid::ACTION_CREATE_NEW_FILE)
57 delegate->CreateNewFile();
58 else
59 DCHECK(false);
61 RemoveSelf();
64 DownloadOverwriteInfoBarDelegate* DownloadOverwriteInfoBar::GetDelegate() {
65 return static_cast<DownloadOverwriteInfoBarDelegate*>(delegate());
68 // Native JNI methods ---------------------------------------------------------
70 bool RegisterDownloadOverwriteInfoBarDelegate(JNIEnv* env) {
71 return RegisterNativesImpl(env);