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

Side by Side Diff: chrome/browser/ui/android/infobar/confirm_infobar.cc

Issue 24109002: [InfoBar] Upstram basic infobar flow for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@upstream_infobar_full
Patch Set: Fix License header in two more files Created 7 years, 3 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 (c) 2013 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/infobar/confirm_infobar.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/logging.h"
10 #include "chrome/browser/android/resource_mapper.h"
11 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
12 #include "jni/ConfirmInfoBarDelegate_jni.h"
13
14 using base::android::ConvertUTF16ToJavaString;
15 using base::android::ScopedJavaLocalRef;
16
17 // static
18 InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
19 return new ConfirmInfoBar(owner, this);
20 }
21
22 ConfirmInfoBar::ConfirmInfoBar(InfoBarService* owner, InfoBarDelegate* delegate)
23 : InfoBarAndroid(owner, delegate),
24 delegate_(delegate->AsConfirmInfoBarDelegate()),
25 java_confirm_delegate_() {}
26
27 ConfirmInfoBar::~ConfirmInfoBar() {}
28
29 ScopedJavaLocalRef<jobject> ConfirmInfoBar::CreateRenderInfoBar(JNIEnv* env) {
30 java_confirm_delegate_.Reset(Java_ConfirmInfoBarDelegate_create(env));
31 ScopedJavaLocalRef<jstring> ok_button_text =
32 ConvertUTF16ToJavaString(env, GetTextFor(InfoBarAndroid::ACTION_OK));
33 ScopedJavaLocalRef<jstring> cancel_button_text =
34 ConvertUTF16ToJavaString(env, GetTextFor(InfoBarAndroid::ACTION_CANCEL));
35 ScopedJavaLocalRef<jstring> message_text =
36 ConvertUTF16ToJavaString(env, GetMessage());
37
38 return Java_ConfirmInfoBarDelegate_showConfirmInfoBar(
39 env,
40 java_confirm_delegate_.obj(),
41 reinterpret_cast<jint>(this),
42 GetEnumeratedIconId(),
43 message_text.obj(),
44 ok_button_text.obj(),
45 cancel_button_text.obj());
46 }
47
48 void ConfirmInfoBar::ProcessButton(int action,
49 const std::string& action_value) {
50 DCHECK(action == InfoBarAndroid::ACTION_OK ||
51 action == InfoBarAndroid::ACTION_CANCEL);
52 if ((action == InfoBarAndroid::ACTION_OK) ? delegate_->Accept()
53 : delegate_->Cancel())
54 CloseInfoBar();
55 }
56
57 string16 ConfirmInfoBar::GetTextFor(ActionType action) {
58 int buttons = delegate_->GetButtons();
59 switch (action) {
60 case InfoBarAndroid::ACTION_OK:
61 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK)
62 return delegate_->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK);
63 break;
64 case InfoBarAndroid::ACTION_CANCEL:
65 if (buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL)
66 return delegate_->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL);
67 break;
68 default:
69 break;
70 }
71 return string16();
72 }
73
74 string16 ConfirmInfoBar::GetMessage() {
75 return delegate_->GetMessageText();
76 }
77
78 // -----------------------------------------------------------------------------
79 // Native JNI methods for confirm delegate.
80 // -----------------------------------------------------------------------------
81 bool RegisterConfirmInfoBarDelegate(JNIEnv* env) {
82 return RegisterNativesImpl(env);
83 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/android/infobar/confirm_infobar.h ('k') | chrome/browser/ui/android/infobar/infobar_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698