OLD | NEW |
---|---|
(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 base::android::ConvertUTF8ToJavaString; | |
Peter Kasting
2014/10/24 01:32:23
Nit: I believe at least this statement can be omit
Changwan Ryu
2014/10/27 06:40:04
Done.
| |
15 using chrome::android::DownloadOverwriteInfoBarDelegate; | |
16 | |
17 // static | |
18 scoped_ptr<infobars::InfoBar> DownloadOverwriteInfoBar::CreateInfoBar( | |
19 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) { | |
20 return scoped_ptr<infobars::InfoBar>( | |
Peter Kasting
2014/10/24 01:32:22
Nit: Can use make_scoped_ptr, I think?
Changwan Ryu
2014/10/27 06:40:04
Done.
| |
21 new DownloadOverwriteInfoBar(delegate.Pass())); | |
22 } | |
23 | |
24 DownloadOverwriteInfoBar::~DownloadOverwriteInfoBar() { | |
25 } | |
26 | |
27 DownloadOverwriteInfoBar::DownloadOverwriteInfoBar( | |
28 scoped_ptr<DownloadOverwriteInfoBarDelegate> delegate) | |
29 : InfoBarAndroid(delegate.PassAs<infobars::InfoBarDelegate>()), | |
Peter Kasting
2014/10/24 01:32:22
Nit: Can just use Pass() now
Changwan Ryu
2014/10/27 06:40:04
Done.
| |
30 java_delegate_() { | |
31 } | |
32 | |
33 ScopedJavaLocalRef<jobject> DownloadOverwriteInfoBar::CreateRenderInfoBar( | |
34 JNIEnv* env) { | |
35 java_delegate_.Reset(Java_DownloadOverwriteInfoBarDelegate_create(env)); | |
36 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); | |
37 ScopedJavaLocalRef<jstring> j_file_name = | |
38 ConvertUTF8ToJavaString(env, delegate->GetFileName()); | |
39 ScopedJavaLocalRef<jstring> j_dir_name = | |
40 ConvertUTF8ToJavaString(env, delegate->GetDirName()); | |
41 ScopedJavaLocalRef<jstring> j_dir_full_path = | |
42 ConvertUTF8ToJavaString(env, delegate->GetDirFullPath()); | |
43 return Java_DownloadOverwriteInfoBarDelegate_showDownloadOverwriteInfoBar( | |
44 env, java_delegate_.obj(), reinterpret_cast<intptr_t>(this), | |
45 j_file_name.obj(), j_dir_name.obj(), j_dir_full_path.obj()); | |
46 } | |
47 | |
48 void DownloadOverwriteInfoBar::ProcessButton( | |
49 int action, const std::string& action_value) { | |
Peter Kasting
2014/10/24 01:32:22
Nit: More typical wrapping:
void DownloadOverwrit
Changwan Ryu
2014/10/27 06:40:04
Done.
| |
50 if (!owner()) | |
51 return; // We're closing; don't call anything, it might access the owner. | |
52 | |
53 DownloadOverwriteInfoBarDelegate* delegate = GetDelegate(); | |
54 if (action == InfoBarAndroid::ACTION_OK) { | |
Peter Kasting
2014/10/24 01:32:22
Nit: {} unnecessary
Changwan Ryu
2014/10/27 06:40:04
Done.
| |
55 delegate->Accept(); | |
56 } else if (action == InfoBarAndroid::ACTION_CANCEL) { | |
57 delegate->Cancel(); | |
58 } else { | |
59 DCHECK_EQ(InfoBarAndroid::ACTION_NONE, action); | |
Peter Kasting
2014/10/24 01:32:22
When is this arm reached? On clicking the close b
Changwan Ryu
2014/10/27 06:40:04
Actually it shouldn't be reached. Changed as DCHEC
| |
60 } | |
61 | |
62 RemoveSelf(); | |
63 } | |
64 | |
65 DownloadOverwriteInfoBarDelegate* DownloadOverwriteInfoBar::GetDelegate() { | |
66 return delegate()->AsDownloadOverwriteInfoBarDelegate(); | |
Peter Kasting
2014/10/24 01:32:23
Just static-cast here, since you know the type of
Changwan Ryu
2014/10/27 06:40:04
Fixed to static-cast.
| |
67 } | |
68 | |
69 // Native JNI methods --------------------------------------------------------- | |
70 | |
71 bool RegisterDownloadOverwriteInfoBarDelegate(JNIEnv* env) { | |
72 return RegisterNativesImpl(env); | |
73 } | |
OLD | NEW |