| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h" | 5 #include "chrome/browser/ui/android/infobars/grouped_permission_infobar.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "chrome/browser/android/resource_mapper.h" | 10 #include "chrome/browser/android/resource_mapper.h" |
| 11 #include "chrome/browser/android/tab_android.h" | 11 #include "chrome/browser/android/tab_android.h" |
| 12 #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android
.h" | 12 #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android
.h" |
| 13 #include "jni/GroupedPermissionInfoBar_jni.h" | 13 #include "jni/GroupedPermissionInfoBar_jni.h" |
| 14 | 14 |
| 15 GroupedPermissionInfoBar::GroupedPermissionInfoBar( | 15 GroupedPermissionInfoBar::GroupedPermissionInfoBar( |
| 16 std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate) | 16 std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate) |
| 17 : ConfirmInfoBar(std::move(delegate)) {} | 17 : ConfirmInfoBar(std::move(delegate)) {} |
| 18 | 18 |
| 19 GroupedPermissionInfoBar::~GroupedPermissionInfoBar() { | 19 GroupedPermissionInfoBar::~GroupedPermissionInfoBar() { |
| 20 } | 20 } |
| 21 | 21 |
| 22 bool GroupedPermissionInfoBar::Register(JNIEnv* env) { | |
| 23 return RegisterNativesImpl(env); | |
| 24 } | |
| 25 | |
| 26 void GroupedPermissionInfoBar::SetPermissionState( | |
| 27 JNIEnv* env, | |
| 28 const base::android::JavaParamRef<jobject>& obj, | |
| 29 const base::android::JavaParamRef<jbooleanArray>& permissions) { | |
| 30 for (size_t i = 0; i < GetDelegate()->PermissionCount(); i++) { | |
| 31 jboolean value; | |
| 32 env->GetBooleanArrayRegion(permissions.obj(), i, 1, &value); | |
| 33 GetDelegate()->ToggleAccept(i, value); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void GroupedPermissionInfoBar::ProcessButton(int action) { | 22 void GroupedPermissionInfoBar::ProcessButton(int action) { |
| 38 // Check if the delegate asked us to display a persistence toggle. If so, | 23 // Check if the delegate asked us to display a persistence toggle. If so, |
| 39 // inform it of the toggle state. | 24 // inform it of the toggle state. |
| 40 GroupedPermissionInfoBarDelegate* delegate = GetDelegate(); | 25 GroupedPermissionInfoBarDelegate* delegate = GetDelegate(); |
| 41 if (delegate->ShouldShowPersistenceToggle()) { | 26 if (delegate->ShouldShowPersistenceToggle()) { |
| 42 delegate->set_persist(Java_GroupedPermissionInfoBar_isPersistSwitchOn( | 27 delegate->set_persist(Java_GroupedPermissionInfoBar_isPersistSwitchOn( |
| 43 base::android::AttachCurrentThread(), GetJavaInfoBar())); | 28 base::android::AttachCurrentThread(), GetJavaInfoBar())); |
| 44 } | 29 } |
| 45 | 30 |
| 46 ConfirmInfoBar::ProcessButton(action); | 31 ConfirmInfoBar::ProcessButton(action); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 73 | 58 |
| 74 return Java_GroupedPermissionInfoBar_create( | 59 return Java_GroupedPermissionInfoBar_create( |
| 75 env, GetTab()->GetJavaObject(), | 60 env, GetTab()->GetJavaObject(), |
| 76 base::android::ToJavaIntArray(env, content_settings_types), message_text, | 61 base::android::ToJavaIntArray(env, content_settings_types), message_text, |
| 77 ok_button_text, cancel_button_text, | 62 ok_button_text, cancel_button_text, |
| 78 delegate->ShouldShowPersistenceToggle(), | 63 delegate->ShouldShowPersistenceToggle(), |
| 79 base::android::ToJavaArrayOfStrings(env, permission_strings), | 64 base::android::ToJavaArrayOfStrings(env, permission_strings), |
| 80 base::android::ToJavaIntArray(env, permission_icons)); | 65 base::android::ToJavaIntArray(env, permission_icons)); |
| 81 } | 66 } |
| 82 | 67 |
| 83 void GroupedPermissionInfoBar::SetJavaInfoBar( | |
| 84 const base::android::JavaRef<jobject>& java_info_bar) { | |
| 85 InfoBarAndroid::SetJavaInfoBar(java_info_bar); | |
| 86 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 87 Java_GroupedPermissionInfoBar_setNativePtr(env, java_info_bar, | |
| 88 reinterpret_cast<intptr_t>(this)); | |
| 89 } | |
| 90 | |
| 91 GroupedPermissionInfoBarDelegate* GroupedPermissionInfoBar::GetDelegate() { | 68 GroupedPermissionInfoBarDelegate* GroupedPermissionInfoBar::GetDelegate() { |
| 92 return static_cast<GroupedPermissionInfoBarDelegate*>(delegate()); | 69 return static_cast<GroupedPermissionInfoBarDelegate*>(delegate()); |
| 93 } | 70 } |
| OLD | NEW |