| 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 "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/android/resource_mapper.h" | 11 #include "chrome/browser/android/resource_mapper.h" |
| 11 #include "chrome/browser/permissions/grouped_permission_infobar_delegate.h" | 12 #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android
.h" |
| 12 #include "jni/GroupedPermissionInfoBar_jni.h" | 13 #include "jni/GroupedPermissionInfoBar_jni.h" |
| 13 | 14 |
| 15 std::unique_ptr<infobars::InfoBar> CreateGroupedPermissionInfoBar( |
| 16 std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate) { |
| 17 return base::WrapUnique(new GroupedPermissionInfoBar(std::move(delegate))); |
| 18 } |
| 19 |
| 14 GroupedPermissionInfoBar::GroupedPermissionInfoBar( | 20 GroupedPermissionInfoBar::GroupedPermissionInfoBar( |
| 15 std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate) | 21 std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate) |
| 16 : ConfirmInfoBar(std::move(delegate)) {} | 22 : ConfirmInfoBar(std::move(delegate)) {} |
| 17 | 23 |
| 18 GroupedPermissionInfoBar::~GroupedPermissionInfoBar() { | 24 GroupedPermissionInfoBar::~GroupedPermissionInfoBar() { |
| 19 } | 25 } |
| 20 | 26 |
| 21 bool GroupedPermissionInfoBar::Register(JNIEnv* env) { | 27 bool GroupedPermissionInfoBar::Register(JNIEnv* env) { |
| 22 return RegisterNativesImpl(env); | 28 return RegisterNativesImpl(env); |
| 23 } | 29 } |
| 24 | 30 |
| 25 void GroupedPermissionInfoBar::SetPermissionState( | 31 void GroupedPermissionInfoBar::SetPermissionState( |
| 26 JNIEnv* env, | 32 JNIEnv* env, |
| 27 const base::android::JavaParamRef<jobject>& obj, | 33 const base::android::JavaParamRef<jobject>& obj, |
| 28 const base::android::JavaParamRef<jbooleanArray>& permissions) { | 34 const base::android::JavaParamRef<jbooleanArray>& permissions) { |
| 29 | 35 for (size_t i = 0; i < GetDelegate()->GetPermissionCount(); i++) { |
| 30 for (int i = 0; i < GetDelegate()->GetPermissionCount(); i++) { | 36 jboolean value; |
| 31 jboolean value; | 37 env->GetBooleanArrayRegion(permissions.obj(), i, 1, &value); |
| 32 env->GetBooleanArrayRegion(permissions.obj(), i, 1, &value); | 38 GetDelegate()->ToggleAccept(i, value); |
| 33 GetDelegate()->ToggleAccept(i, value); | |
| 34 } | 39 } |
| 35 } | 40 } |
| 36 | 41 |
| 37 void GroupedPermissionInfoBar::ProcessButton(int action) { | 42 void GroupedPermissionInfoBar::ProcessButton(int action) { |
| 38 // Check if the delegate asked us to display a persistence toggle. If so, | 43 // Check if the delegate asked us to display a persistence toggle. If so, |
| 39 // inform it of the toggle state. | 44 // inform it of the toggle state. |
| 40 GroupedPermissionInfoBarDelegate* delegate = GetDelegate(); | 45 GroupedPermissionInfoBarDelegate* delegate = GetDelegate(); |
| 41 if (delegate->ShouldShowPersistenceToggle()) { | 46 if (delegate->ShouldShowPersistenceToggle()) { |
| 42 delegate->set_persist(Java_GroupedPermissionInfoBar_isPersistSwitchOn( | 47 delegate->set_persist(Java_GroupedPermissionInfoBar_isPersistSwitchOn( |
| 43 base::android::AttachCurrentThread(), GetJavaInfoBar())); | 48 base::android::AttachCurrentThread(), GetJavaInfoBar())); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 57 base::android::ConvertUTF16ToJavaString( | 62 base::android::ConvertUTF16ToJavaString( |
| 58 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); | 63 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); |
| 59 base::android::ScopedJavaLocalRef<jstring> cancel_button_text = | 64 base::android::ScopedJavaLocalRef<jstring> cancel_button_text = |
| 60 base::android::ConvertUTF16ToJavaString( | 65 base::android::ConvertUTF16ToJavaString( |
| 61 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 66 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 62 | 67 |
| 63 std::vector<base::string16> permission_strings; | 68 std::vector<base::string16> permission_strings; |
| 64 std::vector<int> permission_icons; | 69 std::vector<int> permission_icons; |
| 65 std::vector<int> content_settings_types; | 70 std::vector<int> content_settings_types; |
| 66 | 71 |
| 67 for (int i = 0; i < delegate->GetPermissionCount(); i++) { | 72 for (size_t i = 0; i < delegate->GetPermissionCount(); i++) { |
| 68 permission_strings.push_back(delegate->GetMessageTextFragment(i)); | 73 permission_strings.push_back(delegate->GetMessageTextFragment(i)); |
| 69 permission_icons.push_back( | 74 permission_icons.push_back( |
| 70 ResourceMapper::MapFromChromiumId(delegate->GetIconIdForPermission(i))); | 75 ResourceMapper::MapFromChromiumId(delegate->GetIconIdForPermission(i))); |
| 71 content_settings_types.push_back(delegate->GetContentSettingType(i)); | 76 content_settings_types.push_back(delegate->GetContentSettingType(i)); |
| 72 } | 77 } |
| 73 | 78 |
| 74 return Java_GroupedPermissionInfoBar_create( | 79 return Java_GroupedPermissionInfoBar_create( |
| 75 env, message_text, ok_button_text, cancel_button_text, | 80 env, message_text, ok_button_text, cancel_button_text, |
| 76 base::android::ToJavaIntArray(env, permission_icons), | 81 base::android::ToJavaIntArray(env, permission_icons), |
| 77 base::android::ToJavaArrayOfStrings(env, permission_strings), | 82 base::android::ToJavaArrayOfStrings(env, permission_strings), |
| 78 GetWindowAndroid(), | 83 GetWindowAndroid(), |
| 79 base::android::ToJavaIntArray(env, content_settings_types), | 84 base::android::ToJavaIntArray(env, content_settings_types), |
| 80 delegate->ShouldShowPersistenceToggle()); | 85 delegate->ShouldShowPersistenceToggle()); |
| 81 } | 86 } |
| 82 | 87 |
| 83 void GroupedPermissionInfoBar::SetJavaInfoBar( | 88 void GroupedPermissionInfoBar::SetJavaInfoBar( |
| 84 const base::android::JavaRef<jobject>& java_info_bar) { | 89 const base::android::JavaRef<jobject>& java_info_bar) { |
| 85 InfoBarAndroid::SetJavaInfoBar(java_info_bar); | 90 InfoBarAndroid::SetJavaInfoBar(java_info_bar); |
| 86 JNIEnv* env = base::android::AttachCurrentThread(); | 91 JNIEnv* env = base::android::AttachCurrentThread(); |
| 87 Java_GroupedPermissionInfoBar_setNativePtr(env, java_info_bar, | 92 Java_GroupedPermissionInfoBar_setNativePtr(env, java_info_bar, |
| 88 reinterpret_cast<intptr_t>(this)); | 93 reinterpret_cast<intptr_t>(this)); |
| 89 } | 94 } |
| 90 | 95 |
| 91 GroupedPermissionInfoBarDelegate* GroupedPermissionInfoBar::GetDelegate() { | 96 GroupedPermissionInfoBarDelegate* GroupedPermissionInfoBar::GetDelegate() { |
| 92 return static_cast<GroupedPermissionInfoBarDelegate*>(delegate()); | 97 return static_cast<GroupedPermissionInfoBarDelegate*>(delegate()); |
| 93 } | 98 } |
| 94 | |
| 95 std::unique_ptr<infobars::InfoBar> | |
| 96 GroupedPermissionInfoBarDelegate::CreateInfoBar( | |
| 97 infobars::InfoBarManager* infobar_manager, | |
| 98 std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate) { | |
| 99 return std::unique_ptr<infobars::InfoBar>( | |
| 100 new GroupedPermissionInfoBar(std::move(delegate))); | |
| 101 } | |
| OLD | NEW |