Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 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/callback_helpers.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 const PermissionUpdatedCallback& callback) { | 29 const PermissionUpdatedCallback& callback) { |
| 30 DCHECK(ShouldShowPermissionInfobar(web_contents, content_settings_types)) | 30 DCHECK(ShouldShowPermissionInfobar(web_contents, content_settings_types)) |
| 31 << "Caller should check ShouldShowPermissionInfobar before creating the " | 31 << "Caller should check ShouldShowPermissionInfobar before creating the " |
| 32 << "infobar."; | 32 << "infobar."; |
| 33 | 33 |
| 34 content::ContentViewCore* cvc = | 34 content::ContentViewCore* cvc = |
| 35 content::ContentViewCore::FromWebContents(web_contents); | 35 content::ContentViewCore::FromWebContents(web_contents); |
| 36 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); | 36 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); |
| 37 | 37 |
| 38 std::vector<std::string> permissions; | 38 std::vector<std::string> permissions; |
| 39 int missing_permission_count = 0; | |
| 39 int message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; | 40 int message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; |
| 40 | 41 |
| 41 for (ContentSettingsType content_settings_type : content_settings_types) { | 42 for (ContentSettingsType content_settings_type : content_settings_types) { |
| 42 std::string android_permission = | 43 int previous_size = permissions.size(); |
| 43 PrefServiceBridge::GetAndroidPermissionForContentSetting( | 44 PrefServiceBridge::GetAndroidPermissionsForContentSetting( |
| 44 content_settings_type); | 45 content_settings_type, &permissions); |
| 45 | 46 |
| 46 if (!android_permission.empty() && | 47 if (missing_permission_count > 1) |
| 47 !window_android->HasPermission(android_permission)) { | 48 continue; |
| 48 permissions.push_back(android_permission); | |
| 49 | 49 |
| 50 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 50 for (auto it = permissions.begin() + previous_size; it != permissions.end(); |
| 51 message_id = IDS_INFOBAR_MISSING_LOCATION_PERMISSION_TEXT; | 51 ++it) { |
| 52 if (window_android->HasPermission(*it)) | |
| 53 continue; | |
| 54 | |
| 55 missing_permission_count++; | |
| 56 if (missing_permission_count > 1) { | |
| 57 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; | |
| 58 } else if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | |
| 59 message_id = IDS_INFOBAR_MISSING_LOCATION_PERMISSION_TEXT; | |
| 52 } else if (content_settings_type == | 60 } else if (content_settings_type == |
| 53 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 61 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 54 message_id = IDS_INFOBAR_MISSING_MICROPHONE_PERMISSION_TEXT; | 62 message_id = IDS_INFOBAR_MISSING_MICROPHONE_PERMISSION_TEXT; |
| 55 } else if (content_settings_type == | 63 } else if (content_settings_type == |
| 56 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 64 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 57 message_id = IDS_INFOBAR_MISSING_CAMERA_PERMISSION_TEXT; | 65 message_id = IDS_INFOBAR_MISSING_CAMERA_PERMISSION_TEXT; |
| 58 } else { | 66 } else { |
| 59 NOTREACHED(); | 67 NOTREACHED(); |
| 60 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; | 68 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; |
| 61 } | 69 } |
| 62 } | 70 } |
| 63 } | 71 } |
| 64 if (permissions.size() > 1) | |
| 65 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; | |
| 66 | 72 |
| 67 return PermissionUpdateInfoBarDelegate::Create( | 73 return PermissionUpdateInfoBarDelegate::Create( |
| 68 web_contents, permissions, message_id, callback); | 74 web_contents, permissions, message_id, callback); |
| 69 } | 75 } |
| 70 | 76 |
| 71 // static | 77 // static |
| 72 infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create( | 78 infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create( |
| 73 content::WebContents* web_contents, | 79 content::WebContents* web_contents, |
| 74 const std::vector<std::string>& android_permissions, | 80 const std::vector<std::string>& android_permissions, |
| 75 int permission_msg_id, | 81 int permission_msg_id, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 94 if (!web_contents) | 100 if (!web_contents) |
| 95 return false; | 101 return false; |
| 96 | 102 |
| 97 content::ContentViewCore* cvc = | 103 content::ContentViewCore* cvc = |
| 98 content::ContentViewCore::FromWebContents(web_contents); | 104 content::ContentViewCore::FromWebContents(web_contents); |
| 99 if (!cvc || !cvc->GetWindowAndroid()) | 105 if (!cvc || !cvc->GetWindowAndroid()) |
| 100 return false; | 106 return false; |
| 101 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); | 107 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); |
| 102 | 108 |
| 103 for (ContentSettingsType content_settings_type : content_settings_types) { | 109 for (ContentSettingsType content_settings_type : content_settings_types) { |
| 104 std::string android_permission = | 110 std::vector<std::string> android_permissions; |
| 105 PrefServiceBridge::GetAndroidPermissionForContentSetting( | 111 PrefServiceBridge::GetAndroidPermissionsForContentSetting( |
| 106 content_settings_type); | 112 content_settings_type, &android_permissions); |
| 107 | 113 |
| 108 if (!android_permission.empty() && | 114 for (auto android_permission : android_permissions) { |
|
tommi (sloooow) - chröme
2017/02/16 21:42:04
|const auto&| to avoid making copies
(please check
Ted C
2017/02/17 21:36:52
Done. I did a scan of the change and these two ar
| |
| 109 !window_android->HasPermission(android_permission)) { | 115 if (!window_android->HasPermission(android_permission)) |
| 110 return true; | 116 return true; |
| 111 } | 117 } |
| 112 } | 118 } |
| 113 | 119 |
| 114 return false; | 120 return false; |
| 115 } | 121 } |
| 116 | 122 |
| 117 // static | 123 // static |
| 118 bool PermissionUpdateInfoBarDelegate::RegisterPermissionUpdateInfoBarDelegate( | 124 bool PermissionUpdateInfoBarDelegate::RegisterPermissionUpdateInfoBarDelegate( |
| 119 JNIEnv* env) { | 125 JNIEnv* env) { |
| 120 return RegisterNativesImpl(env); | 126 return RegisterNativesImpl(env); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 } | 184 } |
| 179 | 185 |
| 180 bool PermissionUpdateInfoBarDelegate::Cancel() { | 186 bool PermissionUpdateInfoBarDelegate::Cancel() { |
| 181 base::ResetAndReturn(&callback_).Run(false); | 187 base::ResetAndReturn(&callback_).Run(false); |
| 182 return true; | 188 return true; |
| 183 } | 189 } |
| 184 | 190 |
| 185 void PermissionUpdateInfoBarDelegate::InfoBarDismissed() { | 191 void PermissionUpdateInfoBarDelegate::InfoBarDismissed() { |
| 186 base::ResetAndReturn(&callback_).Run(false); | 192 base::ResetAndReturn(&callback_).Run(false); |
| 187 } | 193 } |
| OLD | NEW |