Index: chrome/browser/ui/android/infobars/permission_infobar.cc |
diff --git a/chrome/browser/ui/android/infobars/permission_infobar.cc b/chrome/browser/ui/android/infobars/permission_infobar.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3fafa3f5956186529508dca5f06373e3bf18f1d1 |
--- /dev/null |
+++ b/chrome/browser/ui/android/infobars/permission_infobar.cc |
@@ -0,0 +1,78 @@ |
+// Copyright 2016 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/infobars/permission_infobar.h" |
+ |
+#include <memory> |
+#include <utility> |
+#include <vector> |
+ |
+#include "base/android/jni_array.h" |
+#include "base/android/jni_string.h" |
+#include "base/memory/ptr_util.h" |
+#include "chrome/browser/permissions/permission_infobar_delegate.h" |
+#include "chrome/browser/ui/android/infobars/confirm_infobar.h" |
+#include "components/content_settings/core/common/content_settings_types.h" |
+#include "jni/PermissionInfoBar_jni.h" |
+#include "ui/gfx/android/java_bitmap.h" |
+#include "ui/gfx/image/image.h" |
+ |
+using base::android::ScopedJavaLocalRef; |
+ |
+std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( |
+ std::unique_ptr<PermissionInfobarDelegate> delegate) { |
+ return base::WrapUnique(new PermissionInfoBar(std::move(delegate))); |
+} |
+ |
+PermissionInfoBar::PermissionInfoBar( |
+ std::unique_ptr<PermissionInfobarDelegate> delegate) |
+ : ConfirmInfoBar(std::move(delegate)) {} |
+ |
+PermissionInfoBar::~PermissionInfoBar() = default; |
+ |
+PermissionInfobarDelegate* PermissionInfoBar::GetDelegate() { |
+ return delegate()->AsPermissionInfobarDelegate(); |
+} |
+ |
+ScopedJavaLocalRef<jobject> PermissionInfoBar::CreateRenderInfoBar( |
+ JNIEnv* env) { |
+ ScopedJavaLocalRef<jstring> ok_button_text = |
+ base::android::ConvertUTF16ToJavaString( |
+ env, GetTextFor(PermissionInfobarDelegate::BUTTON_OK)); |
+ ScopedJavaLocalRef<jstring> cancel_button_text = |
+ base::android::ConvertUTF16ToJavaString( |
+ env, GetTextFor(PermissionInfobarDelegate::BUTTON_CANCEL)); |
+ PermissionInfobarDelegate* delegate = GetDelegate(); |
+ ScopedJavaLocalRef<jstring> message_text = |
+ base::android::ConvertUTF16ToJavaString(env, delegate->GetMessageText()); |
+ ScopedJavaLocalRef<jstring> link_text = |
+ base::android::ConvertUTF16ToJavaString(env, delegate->GetLinkText()); |
+ |
+ ScopedJavaLocalRef<jobject> java_bitmap; |
+ if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID && |
+ !delegate->GetIcon().IsEmpty()) { |
+ java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); |
+ } |
+ |
+ std::vector<int> content_settings{delegate->content_setting()}; |
+ |
+ return Java_PermissionInfoBar_create( |
+ env, GetWindowAndroid().obj(), GetEnumeratedIconId(), java_bitmap.obj(), |
+ message_text.obj(), link_text.obj(), ok_button_text.obj(), |
+ cancel_button_text.obj(), |
+ base::android::ToJavaIntArray(env, content_settings).obj(), |
+ delegate->ShouldShowPersistenceToggle()); |
+} |
+ |
+void PermissionInfoBar::ProcessButton(int action) { |
+ // Check if the delegate asked us to display a persistence toggle. If so, |
+ // inform it of the toggle state. |
+ PermissionInfobarDelegate* delegate = GetDelegate(); |
+ if (delegate->ShouldShowPersistenceToggle()) { |
+ delegate->set_persist(Java_PermissionInfoBar_isPersistSwitchOn( |
+ base::android::AttachCurrentThread(), GetJavaInfoBar())); |
+ } |
+ |
+ ConfirmInfoBar::ProcessButton(action); |
+} |