| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/android/resource_mapper.h" | 14 #include "chrome/browser/android/resource_mapper.h" |
| 15 #include "chrome/browser/infobars/infobar_service.h" | 15 #include "chrome/browser/infobars/infobar_service.h" |
| 16 #include "chrome/browser/media/media_stream_infobar_delegate_android.h" |
| 16 #include "chrome/browser/permissions/permission_infobar_delegate.h" | 17 #include "chrome/browser/permissions/permission_infobar_delegate.h" |
| 17 #include "components/content_settings/core/common/content_settings_types.h" | 18 #include "components/content_settings/core/common/content_settings_types.h" |
| 18 #include "components/infobars/core/confirm_infobar_delegate.h" | 19 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 19 #include "content/public/browser/android/content_view_core.h" | 20 #include "content/public/browser/android/content_view_core.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 #include "jni/ConfirmInfoBarDelegate_jni.h" | 22 #include "jni/ConfirmInfoBarDelegate_jni.h" |
| 22 #include "ui/android/window_android.h" | 23 #include "ui/android/window_android.h" |
| 23 #include "ui/gfx/android/java_bitmap.h" | 24 #include "ui/gfx/android/java_bitmap.h" |
| 24 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
| 25 | 26 |
| 26 #if defined(OS_ANDROID) | |
| 27 #include "chrome/browser/media/media_stream_infobar_delegate_android.h" | |
| 28 #endif | |
| 29 | |
| 30 // InfoBarService ------------------------------------------------------------- | 27 // InfoBarService ------------------------------------------------------------- |
| 31 | 28 |
| 32 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( | 29 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( |
| 33 scoped_ptr<ConfirmInfoBarDelegate> delegate) { | 30 scoped_ptr<ConfirmInfoBarDelegate> delegate) { |
| 34 return make_scoped_ptr(new ConfirmInfoBar(delegate.Pass())); | 31 return make_scoped_ptr(new ConfirmInfoBar(delegate.Pass())); |
| 35 } | 32 } |
| 36 | 33 |
| 37 | 34 |
| 38 // ConfirmInfoBar ------------------------------------------------------------- | 35 // ConfirmInfoBar ------------------------------------------------------------- |
| 39 | 36 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 54 base::android::ConvertUTF16ToJavaString( | 51 base::android::ConvertUTF16ToJavaString( |
| 55 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 52 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 56 ConfirmInfoBarDelegate* delegate = GetDelegate(); | 53 ConfirmInfoBarDelegate* delegate = GetDelegate(); |
| 57 base::android::ScopedJavaLocalRef<jstring> message_text = | 54 base::android::ScopedJavaLocalRef<jstring> message_text = |
| 58 base::android::ConvertUTF16ToJavaString( | 55 base::android::ConvertUTF16ToJavaString( |
| 59 env, delegate->GetMessageText()); | 56 env, delegate->GetMessageText()); |
| 60 base::android::ScopedJavaLocalRef<jstring> link_text = | 57 base::android::ScopedJavaLocalRef<jstring> link_text = |
| 61 base::android::ConvertUTF16ToJavaString( | 58 base::android::ConvertUTF16ToJavaString( |
| 62 env, delegate->GetLinkText()); | 59 env, delegate->GetLinkText()); |
| 63 | 60 |
| 61 for (const auto& detail : delegate->GetDetails()) { |
| 62 Java_ConfirmInfoBarDelegate_addDetail( |
| 63 env, java_confirm_delegate_.obj(), |
| 64 ResourceMapper::MapFromChromiumId(detail.icon_id), |
| 65 base::android::ConvertUTF16ToJavaString(env, detail.label).obj(), |
| 66 base::android::ConvertUTF16ToJavaString(env, detail.sub_label).obj()); |
| 67 } |
| 68 |
| 69 for (const auto& description : delegate->GetDescriptions()) { |
| 70 Java_ConfirmInfoBarDelegate_addDescription( |
| 71 env, java_confirm_delegate_.obj(), |
| 72 base::android::ConvertUTF16ToJavaString(env, description.text).obj()); |
| 73 for (const auto& link : description.links) { |
| 74 Java_ConfirmInfoBarDelegate_addLinkToLastDescription( |
| 75 env, java_confirm_delegate_.obj(), link.start, link.end, |
| 76 base::android::ConvertUTF8ToJavaString(env, link.url.spec()).obj()); |
| 77 } |
| 78 } |
| 79 |
| 64 ScopedJavaLocalRef<jobject> java_bitmap; | 80 ScopedJavaLocalRef<jobject> java_bitmap; |
| 65 if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID && | 81 if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID && |
| 66 !delegate->GetIcon().IsEmpty()) { | 82 !delegate->GetIcon().IsEmpty()) { |
| 67 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); | 83 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); |
| 68 } | 84 } |
| 69 | 85 |
| 70 std::vector<int> content_settings; | 86 std::vector<int> content_settings; |
| 71 if (delegate->AsPermissionInfobarDelegate()) { | 87 if (delegate->AsPermissionInfobarDelegate()) { |
| 72 content_settings.push_back( | 88 content_settings.push_back( |
| 73 delegate->AsPermissionInfobarDelegate()->content_setting()); | 89 delegate->AsPermissionInfobarDelegate()->content_setting()); |
| 74 #if defined(OS_ANDROID) | |
| 75 } else if (delegate->AsMediaStreamInfoBarDelegateAndroid()) { | 90 } else if (delegate->AsMediaStreamInfoBarDelegateAndroid()) { |
| 76 MediaStreamInfoBarDelegateAndroid* media_delegate = | 91 MediaStreamInfoBarDelegateAndroid* media_delegate = |
| 77 delegate->AsMediaStreamInfoBarDelegateAndroid(); | 92 delegate->AsMediaStreamInfoBarDelegateAndroid(); |
| 78 if (media_delegate->IsRequestingVideoAccess()) { | 93 if (media_delegate->IsRequestingVideoAccess()) { |
| 79 content_settings.push_back( | 94 content_settings.push_back( |
| 80 ContentSettingsType::CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 95 ContentSettingsType::CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 81 } | 96 } |
| 82 if (media_delegate->IsRequestingMicrophoneAccess()) { | 97 if (media_delegate->IsRequestingMicrophoneAccess()) { |
| 83 content_settings.push_back( | 98 content_settings.push_back( |
| 84 ContentSettingsType::CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 99 ContentSettingsType::CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 85 } | 100 } |
| 86 #endif | |
| 87 } | 101 } |
| 88 | 102 |
| 89 content::WebContents* web_contents = | 103 content::WebContents* web_contents = |
| 90 InfoBarService::WebContentsFromInfoBar(this); | 104 InfoBarService::WebContentsFromInfoBar(this); |
| 91 DCHECK(web_contents); | 105 DCHECK(web_contents); |
| 92 content::ContentViewCore* cvc = | 106 content::ContentViewCore* cvc = |
| 93 content::ContentViewCore::FromWebContents(web_contents); | 107 content::ContentViewCore::FromWebContents(web_contents); |
| 94 DCHECK(cvc); | 108 DCHECK(cvc); |
| 95 base::android::ScopedJavaLocalRef<jobject> jwindow_android = | 109 base::android::ScopedJavaLocalRef<jobject> jwindow_android = |
| 96 cvc->GetWindowAndroid()->GetJavaObject(); | 110 cvc->GetWindowAndroid()->GetJavaObject(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return (delegate->GetButtons() & button) ? | 148 return (delegate->GetButtons() & button) ? |
| 135 delegate->GetButtonLabel(button) : base::string16(); | 149 delegate->GetButtonLabel(button) : base::string16(); |
| 136 } | 150 } |
| 137 | 151 |
| 138 | 152 |
| 139 // Native JNI methods --------------------------------------------------------- | 153 // Native JNI methods --------------------------------------------------------- |
| 140 | 154 |
| 141 bool RegisterConfirmInfoBarDelegate(JNIEnv* env) { | 155 bool RegisterConfirmInfoBarDelegate(JNIEnv* env) { |
| 142 return RegisterNativesImpl(env); | 156 return RegisterNativesImpl(env); |
| 143 } | 157 } |
| OLD | NEW |