Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/android/infobars/permission_group_infobar_android.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/android/jni_array.h" | |
| 9 #include "base/android/jni_string.h" | |
| 10 #include "base/android/scoped_java_ref.h" | |
| 11 #include "chrome/browser/android/permissions/permission_group_infobar_delegate_a ndroid.h" | |
| 12 #include "chrome/browser/infobars/infobar_service.h" | |
| 13 #include "chrome/grit/generated_resources.h" | |
| 14 #include "content/public/browser/android/content_view_core.h" | |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 #include "jni/PermissionGroupInfoBarAndroid_jni.h" | |
| 17 #include "ui/android/window_android.h" | |
| 18 #include "ui/base/l10n/l10n_util.h" | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 std::string GetPermissionMessage(ContentSettingsType type) { | |
| 23 int message_id; | |
| 24 switch (type) { | |
| 25 case ContentSettingsType::CONTENT_SETTINGS_TYPE_GEOLOCATION: | |
| 26 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT; | |
| 27 break; | |
| 28 case ContentSettingsType::CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | |
| 29 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT; | |
| 30 break; | |
| 31 case ContentSettingsType::CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | |
| 32 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT; | |
| 33 break; | |
| 34 default: | |
|
Lalit Maganti
2015/09/28 12:41:25
Added the cases back in as discussed.
| |
| 35 NOTREACHED(); | |
| 36 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT; | |
| 37 break; | |
| 38 } | |
| 39 return l10n_util::GetStringUTF8(message_id); | |
| 40 } | |
| 41 | |
| 42 } // anonymous namespace | |
| 43 | |
| 44 PermissionGroupInfoBarAndroid::PermissionGroupInfoBarAndroid( | |
| 45 scoped_ptr<PermissionGroupInfoBarDelegateAndroid> delegate, | |
| 46 std::vector<int> permission_types) | |
| 47 : ConfirmInfoBar(delegate.Pass()), | |
| 48 permission_types_(permission_types) { | |
| 49 } | |
| 50 | |
| 51 PermissionGroupInfoBarAndroid::~PermissionGroupInfoBarAndroid() { | |
| 52 if (java_infobar_.is_null()) | |
| 53 return; | |
| 54 | |
| 55 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 56 Java_PermissionGroupInfoBarAndroid_onNativeDestroyed( | |
| 57 env, java_infobar_.obj()); | |
| 58 java_infobar_.Reset(); | |
| 59 } | |
| 60 | |
| 61 PermissionGroupInfoBarDelegateAndroid* | |
| 62 PermissionGroupInfoBarAndroid::GetDelegate() { | |
| 63 return static_cast<PermissionGroupInfoBarDelegateAndroid*>(delegate()); | |
| 64 } | |
| 65 | |
| 66 void PermissionGroupInfoBarAndroid::OnCheckedStateUpdate( | |
| 67 JNIEnv* env, | |
| 68 jobject obj, | |
| 69 jbooleanArray raw_checked_states) { | |
| 70 jint array_size = env->GetArrayLength(raw_checked_states); | |
| 71 jboolean* states_ptr = env->GetBooleanArrayElements( | |
| 72 raw_checked_states, NULL); | |
| 73 | |
| 74 GetDelegate()->OnCheckedStateUpdate(states_ptr, array_size); | |
| 75 } | |
| 76 | |
| 77 base::android::ScopedJavaLocalRef<jobject> | |
| 78 PermissionGroupInfoBarAndroid::CreateRenderInfoBar(JNIEnv* env) { | |
| 79 content::WebContents* web_contents = | |
| 80 InfoBarService::WebContentsFromInfoBar(this); | |
| 81 DCHECK(web_contents); | |
| 82 content::ContentViewCore* cvc = | |
| 83 content::ContentViewCore::FromWebContents(web_contents); | |
| 84 DCHECK(cvc); | |
| 85 | |
| 86 // Convert the types to their string representations. | |
| 87 std::vector<std::string> permission_messages; | |
| 88 for (int permission : permission_types_) { | |
| 89 permission_messages.push_back( | |
| 90 GetPermissionMessage(static_cast<ContentSettingsType>(permission))); | |
| 91 } | |
| 92 | |
| 93 base::android::ScopedJavaLocalRef<jobject> jwindow_android = | |
| 94 cvc->GetWindowAndroid()->GetJavaObject(); | |
| 95 base::android::ScopedJavaLocalRef<jstring> jtitle_message = | |
| 96 base::android::ConvertUTF16ToJavaString( | |
| 97 env, GetDelegate()->GetMessageText()); | |
| 98 base::android::ScopedJavaLocalRef<jobjectArray> jpermission_messages = | |
| 99 base::android::ToJavaArrayOfStrings(env, permission_messages); | |
| 100 base::android::ScopedJavaLocalRef<jintArray> jtypes = | |
| 101 base::android::ToJavaIntArray(env, permission_types_); | |
| 102 | |
| 103 base::android::ScopedJavaLocalRef<jobject> infobar; | |
| 104 infobar.Reset(Java_PermissionGroupInfoBarAndroid_createInfoBar(env, | |
| 105 reinterpret_cast<intptr_t>(this), | |
| 106 jwindow_android.obj(), | |
| 107 jtitle_message.obj(), | |
| 108 jpermission_messages.obj(), | |
| 109 jtypes.obj())); | |
| 110 java_infobar_.Reset(env, infobar.obj()); | |
| 111 return infobar; | |
| 112 } | |
| 113 | |
| 114 // Native JNI methods --------------------------------------------------------- | |
| 115 | |
| 116 bool RegisterPermissionGroupInfoBarAndroid(JNIEnv* env) { | |
| 117 return RegisterNativesImpl(env); | |
| 118 } | |
| OLD | NEW |