| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/permissions/permission_update_infobar_delegate_android.
h" | 5 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.
h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/callback_helpers.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/android/preferences/pref_service_bridge.h" | 12 #include "chrome/browser/android/preferences/pref_service_bridge.h" |
| 12 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/grit/chromium_strings.h" | 14 #include "chrome/grit/chromium_strings.h" |
| 14 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 15 #include "chrome/grit/theme_resources.h" | 16 #include "chrome/grit/theme_resources.h" |
| 16 #include "components/infobars/core/infobar.h" | 17 #include "components/infobars/core/infobar.h" |
| 17 #include "content/public/browser/android/content_view_core.h" | 18 #include "content/public/browser/android/content_view_core.h" |
| 18 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 19 #include "jni/PermissionUpdateInfoBarDelegate_jni.h" | 20 #include "jni/PermissionUpdateInfoBarDelegate_jni.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 70 } |
| 70 | 71 |
| 71 // static | 72 // static |
| 72 bool PermissionUpdateInfoBarDelegate::RegisterPermissionUpdateInfoBarDelegate( | 73 bool PermissionUpdateInfoBarDelegate::RegisterPermissionUpdateInfoBarDelegate( |
| 73 JNIEnv* env) { | 74 JNIEnv* env) { |
| 74 return RegisterNativesImpl(env); | 75 return RegisterNativesImpl(env); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void PermissionUpdateInfoBarDelegate::OnPermissionResult( | 78 void PermissionUpdateInfoBarDelegate::OnPermissionResult( |
| 78 JNIEnv* env, jobject obj, jboolean all_permissions_granted) { | 79 JNIEnv* env, jobject obj, jboolean all_permissions_granted) { |
| 79 callback_.Run(all_permissions_granted); | 80 base::ResetAndReturn(&callback_).Run(all_permissions_granted); |
| 80 infobar()->RemoveSelf(); | 81 infobar()->RemoveSelf(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 PermissionUpdateInfoBarDelegate::PermissionUpdateInfoBarDelegate( | 84 PermissionUpdateInfoBarDelegate::PermissionUpdateInfoBarDelegate( |
| 84 content::WebContents* web_contents, | 85 content::WebContents* web_contents, |
| 85 const std::vector<ContentSettingsType>& content_settings_types, | 86 const std::vector<ContentSettingsType>& content_settings_types, |
| 86 const PermissionUpdatedCallback& callback) | 87 const PermissionUpdatedCallback& callback) |
| 87 : ConfirmInfoBarDelegate(), | 88 : ConfirmInfoBarDelegate(), |
| 88 content_settings_types_(content_settings_types), | 89 content_settings_types_(content_settings_types), |
| 89 callback_(callback) { | 90 callback_(callback) { |
| 90 std::vector<int> content_settings_type_values; | 91 std::vector<int> content_settings_type_values; |
| 91 for (ContentSettingsType type : content_settings_types) | 92 for (ContentSettingsType type : content_settings_types) |
| 92 content_settings_type_values.push_back(type); | 93 content_settings_type_values.push_back(type); |
| 93 | 94 |
| 94 JNIEnv* env = base::android::AttachCurrentThread(); | 95 JNIEnv* env = base::android::AttachCurrentThread(); |
| 95 java_delegate_.Reset(Java_PermissionUpdateInfoBarDelegate_create( | 96 java_delegate_.Reset(Java_PermissionUpdateInfoBarDelegate_create( |
| 96 env, | 97 env, |
| 97 reinterpret_cast<intptr_t>(this), | 98 reinterpret_cast<intptr_t>(this), |
| 98 web_contents->GetJavaWebContents().obj(), | 99 web_contents->GetJavaWebContents().obj(), |
| 99 base::android::ToJavaIntArray(env, content_settings_type_values).obj())); | 100 base::android::ToJavaIntArray(env, content_settings_type_values).obj())); |
| 100 | 101 |
| 101 content::ContentViewCore* cvc = | 102 content::ContentViewCore* cvc = |
| 102 content::ContentViewCore::FromWebContents(web_contents); | 103 content::ContentViewCore::FromWebContents(web_contents); |
| 103 window_android_ = cvc->GetWindowAndroid(); | 104 window_android_ = cvc->GetWindowAndroid(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 PermissionUpdateInfoBarDelegate::~PermissionUpdateInfoBarDelegate() { | 107 PermissionUpdateInfoBarDelegate::~PermissionUpdateInfoBarDelegate() { |
| 107 Java_PermissionUpdateInfoBarDelegate_onNativeDestroyed( | 108 Java_PermissionUpdateInfoBarDelegate_onNativeDestroyed( |
| 108 base::android::AttachCurrentThread(), java_delegate_.obj()); | 109 base::android::AttachCurrentThread(), java_delegate_.obj()); |
| 110 |
| 111 if (!callback_.is_null()) |
| 112 callback_.Run(false); |
| 109 } | 113 } |
| 110 | 114 |
| 111 int PermissionUpdateInfoBarDelegate::GetIconId() const { | 115 int PermissionUpdateInfoBarDelegate::GetIconId() const { |
| 112 return IDR_INFOBAR_WARNING; | 116 return IDR_INFOBAR_WARNING; |
| 113 } | 117 } |
| 114 | 118 |
| 115 base::string16 PermissionUpdateInfoBarDelegate::GetMessageText() const { | 119 base::string16 PermissionUpdateInfoBarDelegate::GetMessageText() const { |
| 116 int missing_permission_count = 0; | 120 int missing_permission_count = 0; |
| 117 int message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; | 121 int message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; |
| 118 | 122 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return l10n_util::GetStringUTF16(IDS_INFOBAR_UPDATE_PERMISSIONS_BUTTON_TEXT); | 164 return l10n_util::GetStringUTF16(IDS_INFOBAR_UPDATE_PERMISSIONS_BUTTON_TEXT); |
| 161 } | 165 } |
| 162 | 166 |
| 163 bool PermissionUpdateInfoBarDelegate::Accept() { | 167 bool PermissionUpdateInfoBarDelegate::Accept() { |
| 164 Java_PermissionUpdateInfoBarDelegate_requestPermissions( | 168 Java_PermissionUpdateInfoBarDelegate_requestPermissions( |
| 165 base::android::AttachCurrentThread(), java_delegate_.obj()); | 169 base::android::AttachCurrentThread(), java_delegate_.obj()); |
| 166 return false; | 170 return false; |
| 167 } | 171 } |
| 168 | 172 |
| 169 bool PermissionUpdateInfoBarDelegate::Cancel() { | 173 bool PermissionUpdateInfoBarDelegate::Cancel() { |
| 170 callback_.Run(false); | 174 base::ResetAndReturn(&callback_).Run(false); |
| 171 return true; | 175 return true; |
| 172 } | 176 } |
| 177 |
| 178 void PermissionUpdateInfoBarDelegate::InfoBarDismissed() { |
| 179 base::ResetAndReturn(&callback_).Run(false); |
| 180 } |
| OLD | NEW |