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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/android/infobar/confirm_infobar.cc
diff --git a/chrome/browser/ui/android/infobar/confirm_infobar.cc b/chrome/browser/ui/android/infobar/confirm_infobar.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1a8554d07e063c14c2f5e38316bea05604a8f941
--- /dev/null
+++ b/chrome/browser/ui/android/infobar/confirm_infobar.cc
@@ -0,0 +1,83 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/android/infobar/confirm_infobar.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/logging.h"
+#include "chrome/browser/android/resource_mapper.h"
+#include "chrome/browser/infobars/confirm_infobar_delegate.h"
+#include "jni/ConfirmInfoBarDelegate_jni.h"
+
+using base::android::ConvertUTF16ToJavaString;
+using base::android::ScopedJavaLocalRef;
+
+// static
+InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
+ return new ConfirmInfoBar(owner, this);
+}
+
+ConfirmInfoBar::ConfirmInfoBar(InfoBarService* owner, InfoBarDelegate* delegate)
+ : InfoBarAndroid(owner, delegate),
+ delegate_(delegate->AsConfirmInfoBarDelegate()),
+ java_confirm_delegate_() {}
+
+ConfirmInfoBar::~ConfirmInfoBar() {}
+
+ScopedJavaLocalRef<jobject> ConfirmInfoBar::CreateRenderInfoBar(JNIEnv* env) {
+ java_confirm_delegate_.Reset(Java_ConfirmInfoBarDelegate_create(env));
+ ScopedJavaLocalRef<jstring> ok_button_text =
+ ConvertUTF16ToJavaString(env, GetTextFor(InfoBarAndroid::ACTION_OK));
+ ScopedJavaLocalRef<jstring> cancel_button_text =
+ ConvertUTF16ToJavaString(env, GetTextFor(InfoBarAndroid::ACTION_CANCEL));
+ ScopedJavaLocalRef<jstring> message_text =
+ ConvertUTF16ToJavaString(env, GetMessage());
+
+ return Java_ConfirmInfoBarDelegate_showConfirmInfoBar(
+ env,
+ java_confirm_delegate_.obj(),
+ reinterpret_cast<jint>(this),
+ GetEnumeratedIconId(),
+ message_text.obj(),
+ ok_button_text.obj(),
+ cancel_button_text.obj());
+}
+
+void ConfirmInfoBar::ProcessButton(int action,
+ const std::string& action_value) {
+ DCHECK(action == InfoBarAndroid::ACTION_OK ||
+ action == InfoBarAndroid::ACTION_CANCEL);
+ if ((action == InfoBarAndroid::ACTION_OK) ? delegate_->Accept()
+ : delegate_->Cancel())
+ CloseInfoBar();
+}
+
+string16 ConfirmInfoBar::GetTextFor(ActionType action) {
+ int buttons = delegate_->GetButtons();
+ switch (action) {
+ case InfoBarAndroid::ACTION_OK:
+ if (buttons & ConfirmInfoBarDelegate::BUTTON_OK)
+ return delegate_->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK);
+ break;
+ case InfoBarAndroid::ACTION_CANCEL:
+ if (buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL)
+ return delegate_->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL);
+ break;
+ default:
+ break;
+ }
+ return string16();
+}
+
+string16 ConfirmInfoBar::GetMessage() {
+ return delegate_->GetMessageText();
+}
+
+// -----------------------------------------------------------------------------
+// Native JNI methods for confirm delegate.
+// -----------------------------------------------------------------------------
+bool RegisterConfirmInfoBarDelegate(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
« 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