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

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: addressed comments and added 'create new file' behavior Created 6 years, 1 month 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 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 chrome::android::DownloadOverwriteInfoBarDelegate;
15
16 // static
17 scoped_ptr<infobars::InfoBar> DownloadOverwriteInfoBar::CreateInfoBar(
18 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) {
19 return make_scoped_ptr(new DownloadOverwriteInfoBar(delegate.Pass()));
20 }
21
22 DownloadOverwriteInfoBar::~DownloadOverwriteInfoBar() {
23 }
24
25 DownloadOverwriteInfoBar::DownloadOverwriteInfoBar(
26 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate)
27 : InfoBarAndroid(delegate.Pass()),
28 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 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 return Java_DownloadOverwriteInfoBarDelegate_showDownloadOverwriteInfoBar(
42 env,
43 java_delegate_.obj(),
44 reinterpret_cast<intptr_t>(this),
45 j_file_name.obj(),
46 j_dir_name.obj(),
47 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->AcceptOverwrite();
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