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 21 matching lines...) Expand all Loading... | |
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 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; | 39 int message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; |
40 | 40 |
41 for (ContentSettingsType content_settings_type : content_settings_types) { | 41 for (ContentSettingsType content_settings_type : content_settings_types) { |
42 std::string android_permission = | 42 int previous_size = permissions.size(); |
43 PrefServiceBridge::GetAndroidPermissionForContentSetting( | 43 PrefServiceBridge::GetAndroidPermissionsForContentSetting( |
44 content_settings_type); | 44 content_settings_type, &permissions); |
45 | 45 |
46 if (!android_permission.empty() && | 46 for (auto it = permissions.begin() + previous_size; |
47 !window_android->HasPermission(android_permission)) { | 47 it != permissions.end(); |
48 permissions.push_back(android_permission); | 48 ++it) { |
49 | 49 if (!window_android->HasPermission(*it)) { |
mlamouri (slow - plz ping)
2017/02/10 14:09:04
style/nit:
```
if (window_android->HasPermission(*
Ted C
2017/02/10 17:24:46
Done.
| |
50 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 50 if (content_settings_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
51 message_id = IDS_INFOBAR_MISSING_LOCATION_PERMISSION_TEXT; | 51 message_id = IDS_INFOBAR_MISSING_LOCATION_PERMISSION_TEXT; |
52 } else if (content_settings_type == | 52 } else if (content_settings_type == |
53 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 53 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
54 message_id = IDS_INFOBAR_MISSING_MICROPHONE_PERMISSION_TEXT; | 54 message_id = IDS_INFOBAR_MISSING_MICROPHONE_PERMISSION_TEXT; |
55 } else if (content_settings_type == | 55 } else if (content_settings_type == |
56 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 56 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
57 message_id = IDS_INFOBAR_MISSING_CAMERA_PERMISSION_TEXT; | 57 message_id = IDS_INFOBAR_MISSING_CAMERA_PERMISSION_TEXT; |
58 } else { | 58 } else { |
59 NOTREACHED(); | 59 NOTREACHED(); |
60 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; | 60 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; |
61 } | |
mlamouri (slow - plz ping)
2017/02/10 14:09:04
This is a bit confusing: we write a `message_id` b
Ted C
2017/02/10 17:24:46
Definitely right. Moved it around a bit to exit e
| |
61 } | 62 } |
62 } | 63 } |
63 } | 64 } |
64 if (permissions.size() > 1) | 65 if (permissions.size() > 1) |
65 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; | 66 message_id = IDS_INFOBAR_MISSING_MULTIPLE_PERMISSIONS_TEXT; |
66 | 67 |
67 return PermissionUpdateInfoBarDelegate::Create( | 68 return PermissionUpdateInfoBarDelegate::Create( |
68 web_contents, permissions, message_id, callback); | 69 web_contents, permissions, message_id, callback); |
69 } | 70 } |
70 | 71 |
(...skipping 23 matching lines...) Expand all Loading... | |
94 if (!web_contents) | 95 if (!web_contents) |
95 return false; | 96 return false; |
96 | 97 |
97 content::ContentViewCore* cvc = | 98 content::ContentViewCore* cvc = |
98 content::ContentViewCore::FromWebContents(web_contents); | 99 content::ContentViewCore::FromWebContents(web_contents); |
99 if (!cvc || !cvc->GetWindowAndroid()) | 100 if (!cvc || !cvc->GetWindowAndroid()) |
100 return false; | 101 return false; |
101 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); | 102 ui::WindowAndroid* window_android = cvc->GetWindowAndroid(); |
102 | 103 |
103 for (ContentSettingsType content_settings_type : content_settings_types) { | 104 for (ContentSettingsType content_settings_type : content_settings_types) { |
104 std::string android_permission = | 105 std::vector<std::string> android_permissions; |
105 PrefServiceBridge::GetAndroidPermissionForContentSetting( | 106 PrefServiceBridge::GetAndroidPermissionsForContentSetting( |
106 content_settings_type); | 107 content_settings_type, &android_permissions); |
107 | 108 |
108 if (!android_permission.empty() && | 109 for (auto android_permission : android_permissions) { |
109 !window_android->HasPermission(android_permission)) { | 110 if (!window_android->HasPermission(android_permission)) |
110 return true; | 111 return true; |
111 } | 112 } |
112 } | 113 } |
113 | 114 |
114 return false; | 115 return false; |
115 } | 116 } |
116 | 117 |
117 // static | 118 // static |
118 bool PermissionUpdateInfoBarDelegate::RegisterPermissionUpdateInfoBarDelegate( | 119 bool PermissionUpdateInfoBarDelegate::RegisterPermissionUpdateInfoBarDelegate( |
119 JNIEnv* env) { | 120 JNIEnv* env) { |
120 return RegisterNativesImpl(env); | 121 return RegisterNativesImpl(env); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 } | 179 } |
179 | 180 |
180 bool PermissionUpdateInfoBarDelegate::Cancel() { | 181 bool PermissionUpdateInfoBarDelegate::Cancel() { |
181 base::ResetAndReturn(&callback_).Run(false); | 182 base::ResetAndReturn(&callback_).Run(false); |
182 return true; | 183 return true; |
183 } | 184 } |
184 | 185 |
185 void PermissionUpdateInfoBarDelegate::InfoBarDismissed() { | 186 void PermissionUpdateInfoBarDelegate::InfoBarDismissed() { |
186 base::ResetAndReturn(&callback_).Run(false); | 187 base::ResetAndReturn(&callback_).Run(false); |
187 } | 188 } |
OLD | NEW |