| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/confirm_infobar.h" | 5 #include "chrome/browser/ui/android/infobars/confirm_infobar.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 ScopedJavaLocalRef<jobject> java_bitmap; | 61 ScopedJavaLocalRef<jobject> java_bitmap; |
| 62 if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID && | 62 if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID && |
| 63 !delegate->GetIcon().IsEmpty()) { | 63 !delegate->GetIcon().IsEmpty()) { |
| 64 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); | 64 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 std::vector<int> content_settings; | 67 std::vector<int> content_settings; |
| 68 if (delegate->AsPermissionInfobarDelegate()) { | 68 if (delegate->AsPermissionInfobarDelegate()) { |
| 69 content_settings.push_back( | 69 content_settings.push_back( |
| 70 delegate->AsPermissionInfobarDelegate()->content_setting()); | 70 delegate->AsPermissionInfobarDelegate()->content_setting()); |
| 71 } else if (delegate->AsMediaStreamInfoBarDelegateAndroid()) { | |
| 72 MediaStreamInfoBarDelegateAndroid* media_delegate = | |
| 73 delegate->AsMediaStreamInfoBarDelegateAndroid(); | |
| 74 if (media_delegate->IsRequestingVideoAccess()) { | |
| 75 content_settings.push_back( | |
| 76 ContentSettingsType::CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
| 77 } | |
| 78 if (media_delegate->IsRequestingMicrophoneAccess()) { | |
| 79 content_settings.push_back( | |
| 80 ContentSettingsType::CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
| 81 } | |
| 82 } | 71 } |
| 83 | 72 |
| 73 return Java_ConfirmInfoBar_create( |
| 74 env, GetWindowAndroid().obj(), GetEnumeratedIconId(), java_bitmap.obj(), |
| 75 message_text.obj(), link_text.obj(), ok_button_text.obj(), |
| 76 cancel_button_text.obj(), |
| 77 base::android::ToJavaIntArray(env, content_settings).obj()); |
| 78 } |
| 79 |
| 80 base::android::ScopedJavaLocalRef<jobject> ConfirmInfoBar::GetWindowAndroid() { |
| 84 content::WebContents* web_contents = | 81 content::WebContents* web_contents = |
| 85 InfoBarService::WebContentsFromInfoBar(this); | 82 InfoBarService::WebContentsFromInfoBar(this); |
| 86 DCHECK(web_contents); | 83 DCHECK(web_contents); |
| 87 content::ContentViewCore* cvc = | 84 content::ContentViewCore* cvc = |
| 88 content::ContentViewCore::FromWebContents(web_contents); | 85 content::ContentViewCore::FromWebContents(web_contents); |
| 89 DCHECK(cvc); | 86 DCHECK(cvc); |
| 90 base::android::ScopedJavaLocalRef<jobject> jwindow_android = | 87 return cvc->GetWindowAndroid()->GetJavaObject(); |
| 91 cvc->GetWindowAndroid()->GetJavaObject(); | |
| 92 | |
| 93 return Java_ConfirmInfoBar_create( | |
| 94 env, jwindow_android.obj(), GetEnumeratedIconId(), java_bitmap.obj(), | |
| 95 message_text.obj(), link_text.obj(), ok_button_text.obj(), | |
| 96 cancel_button_text.obj(), | |
| 97 base::android::ToJavaIntArray(env, content_settings).obj()); | |
| 98 } | 88 } |
| 99 | 89 |
| 100 void ConfirmInfoBar::OnLinkClicked(JNIEnv* env, | 90 void ConfirmInfoBar::OnLinkClicked(JNIEnv* env, |
| 101 const JavaParamRef<jobject>& obj) { | 91 const JavaParamRef<jobject>& obj) { |
| 102 if (!owner()) | 92 if (!owner()) |
| 103 return; // We're closing; don't call anything, it might access the owner. | 93 return; // We're closing; don't call anything, it might access the owner. |
| 104 | 94 |
| 105 if (GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB)) | 95 if (GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB)) |
| 106 RemoveSelf(); | 96 RemoveSelf(); |
| 107 } | 97 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 128 return (delegate->GetButtons() & button) ? | 118 return (delegate->GetButtons() & button) ? |
| 129 delegate->GetButtonLabel(button) : base::string16(); | 119 delegate->GetButtonLabel(button) : base::string16(); |
| 130 } | 120 } |
| 131 | 121 |
| 132 | 122 |
| 133 // Native JNI methods --------------------------------------------------------- | 123 // Native JNI methods --------------------------------------------------------- |
| 134 | 124 |
| 135 bool RegisterConfirmInfoBar(JNIEnv* env) { | 125 bool RegisterConfirmInfoBar(JNIEnv* env) { |
| 136 return RegisterNativesImpl(env); | 126 return RegisterNativesImpl(env); |
| 137 } | 127 } |
| OLD | NEW |