Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/permissions/permission_update_infobar_delegate_android.cc

Issue 2682863002: [Android] Explicitly request all needed runtime permissions. (Closed)
Patch Set: Address mlamouri@ comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
50 for (auto it = permissions.begin() + previous_size;
51 it != permissions.end();
52 ++it) {
53 if (window_android->HasPermission(*it))
54 continue;
55
56 missing_permission_count++;
57 if (missing_permission_count > 1) {
58 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT;
59 break;
mlamouri (slow - plz ping) 2017/02/13 11:58:01 nit: you could integrate this with the other condi
Ted C 2017/02/14 00:53:34 Done.
60 }
mlamouri (slow - plz ping) 2017/02/13 11:58:01 Here, if I understand correctly, you want to doubl
Ted C 2017/02/14 00:53:34 Yeah, this is a bit confusing, but it is actually
49 61
50 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 62 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
51 message_id = IDS_INFOBAR_MISSING_LOCATION_PERMISSION_TEXT; 63 message_id = IDS_INFOBAR_MISSING_LOCATION_PERMISSION_TEXT;
52 } else if (content_settings_type == 64 } else if (content_settings_type ==
53 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 65 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
54 message_id = IDS_INFOBAR_MISSING_MICROPHONE_PERMISSION_TEXT; 66 message_id = IDS_INFOBAR_MISSING_MICROPHONE_PERMISSION_TEXT;
55 } else if (content_settings_type == 67 } else if (content_settings_type ==
56 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 68 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
57 message_id = IDS_INFOBAR_MISSING_CAMERA_PERMISSION_TEXT; 69 message_id = IDS_INFOBAR_MISSING_CAMERA_PERMISSION_TEXT;
58 } else { 70 } else {
59 NOTREACHED(); 71 NOTREACHED();
60 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; 72 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT;
61 } 73 }
62 } 74 }
63 } 75 }
64 if (permissions.size() > 1)
65 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT;
66 76
67 return PermissionUpdateInfoBarDelegate::Create( 77 return PermissionUpdateInfoBarDelegate::Create(
68 web_contents, permissions, message_id, callback); 78 web_contents, permissions, message_id, callback);
69 } 79 }
70 80
71 // static 81 // static
72 infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create( 82 infobars::InfoBar* PermissionUpdateInfoBarDelegate::Create(
73 content::WebContents* web_contents, 83 content::WebContents* web_contents,
74 const std::vector<std::string>& android_permissions, 84 const std::vector<std::string>& android_permissions,
75 int permission_msg_id, 85 int permission_msg_id,
(...skipping 18 matching lines...) Expand all
94 if (!web_contents) 104 if (!web_contents)
95 return false; 105 return false;
96 106
97 content::ContentViewCore* cvc = 107 content::ContentViewCore* cvc =
98 content::ContentViewCore::FromWebContents(web_contents); 108 content::ContentViewCore::FromWebContents(web_contents);
99 if (!cvc || !cvc->GetWindowAndroid()) 109 if (!cvc || !cvc->GetWindowAndroid())
100 return false; 110 return false;
101 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); 111 ui::WindowAndroid* window_android = cvc->GetWindowAndroid();
102 112
103 for (ContentSettingsType content_settings_type : content_settings_types) { 113 for (ContentSettingsType content_settings_type : content_settings_types) {
104 std::string android_permission = 114 std::vector<std::string> android_permissions;
105 PrefServiceBridge::GetAndroidPermissionForContentSetting( 115 PrefServiceBridge::GetAndroidPermissionsForContentSetting(
106 content_settings_type); 116 content_settings_type, &android_permissions);
107 117
108 if (!android_permission.empty() && 118 for (auto android_permission : android_permissions) {
109 !window_android->HasPermission(android_permission)) { 119 if (!window_android->HasPermission(android_permission))
110 return true; 120 return true;
111 } 121 }
112 } 122 }
113 123
114 return false; 124 return false;
115 } 125 }
116 126
117 // static 127 // static
118 bool PermissionUpdateInfoBarDelegate::RegisterPermissionUpdateInfoBarDelegate( 128 bool PermissionUpdateInfoBarDelegate::RegisterPermissionUpdateInfoBarDelegate(
119 JNIEnv* env) { 129 JNIEnv* env) {
120 return RegisterNativesImpl(env); 130 return RegisterNativesImpl(env);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 188 }
179 189
180 bool PermissionUpdateInfoBarDelegate::Cancel() { 190 bool PermissionUpdateInfoBarDelegate::Cancel() {
181 base::ResetAndReturn(&callback_).Run(false); 191 base::ResetAndReturn(&callback_).Run(false);
182 return true; 192 return true;
183 } 193 }
184 194
185 void PermissionUpdateInfoBarDelegate::InfoBarDismissed() { 195 void PermissionUpdateInfoBarDelegate::InfoBarDismissed() {
186 base::ResetAndReturn(&callback_).Run(false); 196 base::ResetAndReturn(&callback_).Run(false);
187 } 197 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698