Chromium Code Reviews| 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/permissions/grouped_permission_infobar_delegate.h" | 11 #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android .h" |
| 12 #include "jni/GroupedPermissionInfoBar_jni.h" | 12 #include "jni/GroupedPermissionInfoBar_jni.h" |
| 13 | 13 |
| 14 GroupedPermissionInfoBar::GroupedPermissionInfoBar( | 14 GroupedPermissionInfoBar::GroupedPermissionInfoBar( |
| 15 std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate) | 15 std::unique_ptr<GroupedPermissionInfoBarDelegate> delegate) |
| 16 : ConfirmInfoBar(std::move(delegate)) {} | 16 : ConfirmInfoBar(std::move(delegate)) {} |
| 17 | 17 |
| 18 GroupedPermissionInfoBar::~GroupedPermissionInfoBar() { | 18 GroupedPermissionInfoBar::~GroupedPermissionInfoBar() { |
| 19 } | 19 } |
| 20 | 20 |
| 21 bool GroupedPermissionInfoBar::Register(JNIEnv* env) { | 21 bool GroupedPermissionInfoBar::Register(JNIEnv* env) { |
| 22 return RegisterNativesImpl(env); | 22 return RegisterNativesImpl(env); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void GroupedPermissionInfoBar::SetPermissionState( | 25 void GroupedPermissionInfoBar::SetPermissionState( |
| 26 JNIEnv* env, | 26 JNIEnv* env, |
| 27 const base::android::JavaParamRef<jobject>& obj, | 27 const base::android::JavaParamRef<jobject>& obj, |
| 28 const base::android::JavaParamRef<jbooleanArray>& permissions) { | 28 const base::android::JavaParamRef<jbooleanArray>& permissions) { |
| 29 | 29 for (size_t i = 0; i < GetDelegate()->permission_count(); i++) { |
| 30 for (int i = 0; i < GetDelegate()->GetPermissionCount(); i++) { | 30 jboolean value; |
| 31 jboolean value; | 31 env->GetBooleanArrayRegion(permissions.obj(), i, 1, &value); |
| 32 env->GetBooleanArrayRegion(permissions.obj(), i, 1, &value); | 32 GetDelegate()->ToggleAccept(i, value); |
| 33 GetDelegate()->ToggleAccept(i, value); | |
| 34 } | 33 } |
|
Peter Kasting
2016/09/23 00:42:06
Nit: Longer-term consideration: Is this the only p
lshang
2016/09/27 01:50:43
This is for future work. We're planning to reuse P
| |
| 35 } | 34 } |
| 36 | 35 |
| 37 void GroupedPermissionInfoBar::ProcessButton(int action) { | 36 void GroupedPermissionInfoBar::ProcessButton(int action) { |
| 38 // Check if the delegate asked us to display a persistence toggle. If so, | 37 // Check if the delegate asked us to display a persistence toggle. If so, |
| 39 // inform it of the toggle state. | 38 // inform it of the toggle state. |
| 40 GroupedPermissionInfoBarDelegate* delegate = GetDelegate(); | 39 GroupedPermissionInfoBarDelegate* delegate = GetDelegate(); |
| 41 if (delegate->ShouldShowPersistenceToggle()) { | 40 if (delegate->ShouldShowPersistenceToggle()) { |
| 42 delegate->set_persist(Java_GroupedPermissionInfoBar_isPersistSwitchOn( | 41 delegate->set_persist(Java_GroupedPermissionInfoBar_isPersistSwitchOn( |
| 43 base::android::AttachCurrentThread(), GetJavaInfoBar())); | 42 base::android::AttachCurrentThread(), GetJavaInfoBar())); |
| 44 } | 43 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 57 base::android::ConvertUTF16ToJavaString( | 56 base::android::ConvertUTF16ToJavaString( |
| 58 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); | 57 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); |
| 59 base::android::ScopedJavaLocalRef<jstring> cancel_button_text = | 58 base::android::ScopedJavaLocalRef<jstring> cancel_button_text = |
| 60 base::android::ConvertUTF16ToJavaString( | 59 base::android::ConvertUTF16ToJavaString( |
| 61 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 60 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 62 | 61 |
| 63 std::vector<base::string16> permission_strings; | 62 std::vector<base::string16> permission_strings; |
| 64 std::vector<int> permission_icons; | 63 std::vector<int> permission_icons; |
| 65 std::vector<int> content_settings_types; | 64 std::vector<int> content_settings_types; |
| 66 | 65 |
| 67 for (int i = 0; i < delegate->GetPermissionCount(); i++) { | 66 for (size_t i = 0; i < delegate->permission_count(); i++) { |
| 68 permission_strings.push_back(delegate->GetMessageTextFragment(i)); | 67 permission_strings.push_back(delegate->GetMessageTextFragment(i)); |
| 69 permission_icons.push_back( | 68 permission_icons.push_back( |
| 70 ResourceMapper::MapFromChromiumId(delegate->GetIconIdForPermission(i))); | 69 ResourceMapper::MapFromChromiumId(delegate->GetIconIdForPermission(i))); |
| 71 content_settings_types.push_back(delegate->GetContentSettingType(i)); | 70 content_settings_types.push_back(delegate->GetContentSettingType(i)); |
| 72 } | 71 } |
|
Peter Kasting
2016/09/23 00:42:06
Nit: Similarly, if this is the only place we call
lshang
2016/09/27 01:50:43
Probably will also need to get info at specific po
Peter Kasting
2016/09/27 02:05:43
Seems reasonable to me to reevaluate then.
| |
| 73 | 72 |
| 74 return Java_GroupedPermissionInfoBar_create( | 73 return Java_GroupedPermissionInfoBar_create( |
| 75 env, message_text, ok_button_text, cancel_button_text, | 74 env, message_text, ok_button_text, cancel_button_text, |
| 76 base::android::ToJavaIntArray(env, permission_icons), | 75 base::android::ToJavaIntArray(env, permission_icons), |
| 77 base::android::ToJavaArrayOfStrings(env, permission_strings), | 76 base::android::ToJavaArrayOfStrings(env, permission_strings), |
| 78 GetWindowAndroid(), | 77 GetWindowAndroid(), |
| 79 base::android::ToJavaIntArray(env, content_settings_types), | 78 base::android::ToJavaIntArray(env, content_settings_types), |
| 80 delegate->ShouldShowPersistenceToggle()); | 79 delegate->ShouldShowPersistenceToggle()); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void GroupedPermissionInfoBar::SetJavaInfoBar( | 82 void GroupedPermissionInfoBar::SetJavaInfoBar( |
| 84 const base::android::JavaRef<jobject>& java_info_bar) { | 83 const base::android::JavaRef<jobject>& java_info_bar) { |
| 85 InfoBarAndroid::SetJavaInfoBar(java_info_bar); | 84 InfoBarAndroid::SetJavaInfoBar(java_info_bar); |
| 86 JNIEnv* env = base::android::AttachCurrentThread(); | 85 JNIEnv* env = base::android::AttachCurrentThread(); |
| 87 Java_GroupedPermissionInfoBar_setNativePtr(env, java_info_bar, | 86 Java_GroupedPermissionInfoBar_setNativePtr(env, java_info_bar, |
| 88 reinterpret_cast<intptr_t>(this)); | 87 reinterpret_cast<intptr_t>(this)); |
| 89 } | 88 } |
| 90 | 89 |
| 91 GroupedPermissionInfoBarDelegate* GroupedPermissionInfoBar::GetDelegate() { | 90 GroupedPermissionInfoBarDelegate* GroupedPermissionInfoBar::GetDelegate() { |
| 92 return static_cast<GroupedPermissionInfoBarDelegate*>(delegate()); | 91 return static_cast<GroupedPermissionInfoBarDelegate*>(delegate()); |
| 93 } | 92 } |
| 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 |