Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(663)

Side by Side Diff: chrome/browser/ui/android/infobars/download_overwrite_infobar.cc

Issue 580043002: [Android] Prompt with infobar on filename conflict (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nits Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "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_overwrite_infobar_delegate.h"
13 #include "jni/DownloadOverwriteInfoBarDelegate_jni.h"
14
15 using chrome::android::DownloadOverwriteInfoBarDelegate;
16
17 // static
18 scoped_ptr<infobars::InfoBar> DownloadOverwriteInfoBar::CreateInfoBar(
19 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) {
20 return make_scoped_ptr(new DownloadOverwriteInfoBar(delegate.Pass()));
21 }
22
23 DownloadOverwriteInfoBar::~DownloadOverwriteInfoBar() {
24 }
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
25
26 DownloadOverwriteInfoBar::DownloadOverwriteInfoBar(
27 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate)
28 : InfoBarAndroid(delegate.Pass()), java_delegate_() {
29 }
30
31 ScopedJavaLocalRef<jobject> DownloadOverwriteInfoBar::CreateRenderInfoBar(
32 JNIEnv* env) {
33 java_delegate_.Reset(Java_DownloadOverwriteInfoBarDelegate_create(env));
34 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate();
35 base::FilePath suggested_download_path = delegate->suggested_download_path();
36 ScopedJavaLocalRef<jstring> j_file_name =
37 base::android::ConvertUTF8ToJavaString(
38 env, suggested_download_path.BaseName().value());
39 ScopedJavaLocalRef<jstring> j_dir_name =
40 base::android::ConvertUTF8ToJavaString(
41 env, suggested_download_path.DirName().BaseName().value());
42 ScopedJavaLocalRef<jstring> j_dir_full_path =
43 base::android::ConvertUTF8ToJavaString(
44 env, suggested_download_path.DirName().value());
45 return Java_DownloadOverwriteInfoBarDelegate_showDownloadOverwriteInfoBar(
46 env, java_delegate_.obj(), reinterpret_cast<intptr_t>(this),
47 j_file_name.obj(), j_dir_name.obj(), j_dir_full_path.obj());
48 }
49
50 void DownloadOverwriteInfoBar::ProcessButton(int action,
51 const std::string& action_value) {
52 if (!owner())
53 return; // We're closing; don't call anything, it might access the owner.
54
55 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate();
56 if (action == InfoBarAndroid::ACTION_OVERWRITE)
57 delegate->OverwriteExistingFile();
58 else if (action == InfoBarAndroid::ACTION_CREATE_NEW_FILE)
59 delegate->CreateNewFile();
60 else
61 DCHECK(false);
62
63 RemoveSelf();
64 }
65
66 DownloadOverwriteInfoBarDelegate* DownloadOverwriteInfoBar::GetDelegate() {
67 return static_cast<DownloadOverwriteInfoBarDelegate*>(delegate());
68 }
69
70 // Native JNI methods ---------------------------------------------------------
71
72 bool RegisterDownloadOverwriteInfoBarDelegate(JNIEnv* env) {
73 return RegisterNativesImpl(env);
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698