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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/pageinfo/WebsiteSettingsPopup.java

Issue 2682863002: [Android] Explicitly request all needed runtime permissions. (Closed)
Patch Set: 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 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 package org.chromium.chrome.browser.pageinfo; 5 package org.chromium.chrome.browser.pageinfo;
6 6
7 import android.animation.Animator; 7 import android.animation.Animator;
8 import android.animation.AnimatorListenerAdapter; 8 import android.animation.AnimatorListenerAdapter;
9 import android.animation.AnimatorSet; 9 import android.animation.AnimatorSet;
10 import android.animation.ObjectAnimator; 10 import android.animation.ObjectAnimator;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 * Whether to show a 'Details' link to the connection info popup. The link i s only shown for 519 * Whether to show a 'Details' link to the connection info popup. The link i s only shown for
520 * HTTPS connections. 520 * HTTPS connections.
521 */ 521 */
522 private boolean isConnectionDetailsLinkVisible() { 522 private boolean isConnectionDetailsLinkVisible() {
523 return mContentPublisher == null && !isShowingOfflinePage() && mParsedUr l != null 523 return mContentPublisher == null && !isShowingOfflinePage() && mParsedUr l != null
524 && mParsedUrl.getScheme() != null 524 && mParsedUrl.getScheme() != null
525 && mParsedUrl.getScheme().equals(UrlConstants.HTTPS_SCHE ME); 525 && mParsedUrl.getScheme().equals(UrlConstants.HTTPS_SCHE ME);
526 } 526 }
527 527
528 private boolean hasAndroidPermission(int contentSettingType) { 528 private boolean hasAndroidPermission(int contentSettingType) {
529 String androidPermission = PrefServiceBridge.getAndroidPermissionForCont entSetting( 529 String[] androidPermissions = PrefServiceBridge.getAndroidPermissionsFor ContentSetting(
530 contentSettingType); 530 contentSettingType);
531 return androidPermission == null || mWindowAndroid.hasPermission(android Permission); 531 if (androidPermissions == null) return true;
532 for (int i = 0; i < androidPermissions.length; i++) {
533 if (!mWindowAndroid.hasPermission(androidPermissions[i])) {
534 return false;
535 }
536 }
537 return true;
532 } 538 }
533 539
534 /** 540 /**
535 * Adds a new row for the given permission. 541 * Adds a new row for the given permission.
536 * 542 *
537 * @param name The title of the permission to display to the user. 543 * @param name The title of the permission to display to the user.
538 * @param type The ContentSettingsType of the permission. 544 * @param type The ContentSettingsType of the permission.
539 * @param currentSettingValue The ContentSetting value of the currently sele cted setting. 545 * @param currentSettingValue The ContentSetting value of the currently sele cted setting.
540 */ 546 */
541 @CalledByNative 547 @CalledByNative
(...skipping 30 matching lines...) Expand all
572 // permission_intent_override or permission_type. 578 // permission_intent_override or permission_type.
573 LocationUtils locationUtils = LocationUtils.getInstance(); 579 LocationUtils locationUtils = LocationUtils.getInstance();
574 if (permission.type == ContentSettingsType.CONTENT_SETTINGS_TYPE_GEO LOCATION 580 if (permission.type == ContentSettingsType.CONTENT_SETTINGS_TYPE_GEO LOCATION
575 && !locationUtils.isSystemLocationSettingEnabled()) { 581 && !locationUtils.isSystemLocationSettingEnabled()) {
576 warningTextResource = R.string.page_info_android_location_blocke d; 582 warningTextResource = R.string.page_info_android_location_blocke d;
577 permissionRow.setTag(R.id.permission_intent_override, 583 permissionRow.setTag(R.id.permission_intent_override,
578 locationUtils.getSystemLocationSettingsIntent()); 584 locationUtils.getSystemLocationSettingsIntent());
579 } else if (!hasAndroidPermission(permission.type)) { 585 } else if (!hasAndroidPermission(permission.type)) {
580 warningTextResource = R.string.page_info_android_permission_bloc ked; 586 warningTextResource = R.string.page_info_android_permission_bloc ked;
581 permissionRow.setTag(R.id.permission_type, 587 permissionRow.setTag(R.id.permission_type,
582 PrefServiceBridge.getAndroidPermissionForContentSetting( permission.type)); 588 PrefServiceBridge.getAndroidPermissionsForContentSetting (permission.type));
583 } 589 }
584 590
585 if (warningTextResource != 0) { 591 if (warningTextResource != 0) {
586 TextView permissionUnavailable = (TextView) permissionRow.findVi ewById( 592 TextView permissionUnavailable = (TextView) permissionRow.findVi ewById(
587 R.id.website_settings_permission_unavailable_message); 593 R.id.website_settings_permission_unavailable_message);
588 permissionUnavailable.setVisibility(View.VISIBLE); 594 permissionUnavailable.setVisibility(View.VISIBLE);
589 permissionUnavailable.setText(warningTextResource); 595 permissionUnavailable.setText(warningTextResource);
590 596
591 permissionIcon.setImageResource(R.drawable.exclamation_triangle) ; 597 permissionIcon.setImageResource(R.drawable.exclamation_triangle) ;
592 permissionIcon.setColorFilter(ApiCompatibilityUtils.getColor( 598 permissionIcon.setColorFilter(ApiCompatibilityUtils.getColor(
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 WebsiteSettingsAction.WEBSITE_SETTINGS_SECURITY_ DETAILS_OPENED); 771 WebsiteSettingsAction.WEBSITE_SETTINGS_SECURITY_ DETAILS_OPENED);
766 ConnectionInfoPopup.show(mContext, mTab.getWebContents() ); 772 ConnectionInfoPopup.show(mContext, mTab.getWebContents() );
767 } 773 }
768 } 774 }
769 }); 775 });
770 } else if (view.getId() == R.id.website_settings_permission_row) { 776 } else if (view.getId() == R.id.website_settings_permission_row) {
771 final Object intentOverride = view.getTag(R.id.permission_intent_ove rride); 777 final Object intentOverride = view.getTag(R.id.permission_intent_ove rride);
772 778
773 if (intentOverride == null && mWindowAndroid != null) { 779 if (intentOverride == null && mWindowAndroid != null) {
774 // Try and immediately request missing Android permissions where possible. 780 // Try and immediately request missing Android permissions where possible.
775 final String permissionType = (String) view.getTag(R.id.permissi on_type); 781 final String[] permissionType = (String[]) view.getTag(R.id.perm ission_type);
776 if (mWindowAndroid.canRequestPermission(permissionType)) { 782 for (int i = 0; i < permissionType.length; i++) {
777 final String[] permissionRequest = new String[] {permissionT ype}; 783 // If any permissions can be requested, attempt to request t hem all.
778 mWindowAndroid.requestPermissions(permissionRequest, new Per missionCallback() { 784 if (mWindowAndroid.canRequestPermission(permissionType[i])) {
mlamouri (slow - plz ping) 2017/02/10 14:09:04 for readability, what about an early `continue`? I
Ted C 2017/02/10 17:24:46 Done.
779 @Override 785 mWindowAndroid.requestPermissions(permissionType, new Pe rmissionCallback() {
780 public void onRequestPermissionsResult( 786 @Override
781 String[] permissions, int[] grantResults) { 787 public void onRequestPermissionsResult(
782 if (grantResults.length > 0 788 String[] permissions, int[] grantResults) {
783 && grantResults[0] == PackageManager.PERMISS ION_GRANTED) { 789 if (grantResults.length > 0
784 updatePermissionDisplay(); 790 && grantResults[0] == PackageManager.PER MISSION_GRANTED) {
mlamouri (slow - plz ping) 2017/02/10 14:09:04 What if there were multiple permissions? Does it s
Ted C 2017/02/10 17:24:46 Nice catch. Since each row can be tied to multipl
791 updatePermissionDisplay();
792 }
785 } 793 }
786 } 794 });
787 }); 795 return;
788 return; 796 }
789 } 797 }
790 } 798 }
791 799
792 runAfterDismiss(new Runnable() { 800 runAfterDismiss(new Runnable() {
793 @Override 801 @Override
794 public void run() { 802 public void run() {
795 Intent settingsIntent; 803 Intent settingsIntent;
796 if (intentOverride != null) { 804 if (intentOverride != null) {
797 settingsIntent = (Intent) intentOverride; 805 settingsIntent = (Intent) intentOverride;
798 } else { 806 } else {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 new WebsiteSettingsPopup(activity, tab, offlinePageCreationDate, content Publisher); 968 new WebsiteSettingsPopup(activity, tab, offlinePageCreationDate, content Publisher);
961 } 969 }
962 970
963 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents); 971 private static native long nativeInit(WebsiteSettingsPopup popup, WebContent s webContents);
964 972
965 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid); 973 private native void nativeDestroy(long nativeWebsiteSettingsPopupAndroid);
966 974
967 private native void nativeRecordWebsiteSettingsAction( 975 private native void nativeRecordWebsiteSettingsAction(
968 long nativeWebsiteSettingsPopupAndroid, int action); 976 long nativeWebsiteSettingsPopupAndroid, int action);
969 } 977 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698