0

[DownloadRestrictions] Block save to file downloads.

This CL blocks downloads to files if the download restriction policy is
set to restrict downloads on all files. In addition, it changes the
default location of the checkmark from the files destination to the
drive destination.

Screenshot: https://screenshot.googleplex.com/BX6YccfJvk4UsYg.png

Bug: chromium:379352316
Change-Id: If7b0e3ecb871f361185c2f17d80f735924387acf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6040114
Commit-Queue: Cheick Cisse <cheickcisse@google.com>
Reviewed-by: Dominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: Quentin Pubert <qpubert@google.com>
Cr-Commit-Position: refs/heads/main@{#1388224}
This commit is contained in:
Cheick Cisse
2024-11-26 15:00:24 +00:00
committed by Chromium LUCI CQ
parent 04a7ee38d3
commit 8a9da18e6d
7 changed files with 73 additions and 3 deletions

@ -13,6 +13,7 @@ source_set("ui_bundled") {
":file_destination_picker",
":util",
"//base",
"//components/policy/core/common",
"//components/strings:components_strings_grit",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/account_picker/ui_bundled",
@ -57,6 +58,7 @@ source_set("file_destination_picker") {
]
deps = [
":file_destination_picker_constants",
"//components/strings",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/shared/ui/symbols",
"//ios/chrome/browser/shared/ui/table_view:utils",
@ -125,6 +127,7 @@ source_set("eg2_tests") {
deps = [
":file_destination_picker_constants",
"//components/policy:policy_code_generate",
"//components/policy/core/common",
"//ios/chrome/app/strings",
"//ios/chrome/browser/account_picker/ui_bundled/account_picker_confirmation:constants",
"//ios/chrome/browser/account_picker/ui_bundled/account_picker_screen:account_picker_screen",

@ -16,6 +16,9 @@
- (void)fileDestinationPicker:(UIViewController*)picker
didSelectDestination:(FileDestination)destination;
// Called to check whether or not downloads to the file should be blocked.
- (bool)shouldBlockDownloadToFile;
@end
#endif // IOS_CHROME_BROWSER_SAVE_TO_DRIVE_UI_BUNDLED_FILE_DESTINATION_PICKER_ACTION_DELEGATE_H_

@ -9,6 +9,8 @@
// Accessibility identifiers for file destination picker table view cells.
extern NSString* const kFileDestinationPickerFilesAccessibilityIdentifier;
extern NSString* const
kFileDestinationPickerDownloadRestrictionFilesAccessibilityIdentifier;
extern NSString* const kFileDestinationPickerDriveAccessibilityIdentifier;
#endif // IOS_CHROME_BROWSER_SAVE_TO_DRIVE_UI_BUNDLED_FILE_DESTINATION_PICKER_CONSTANTS_H_

@ -6,5 +6,9 @@
NSString* const kFileDestinationPickerFilesAccessibilityIdentifier =
@"kFileDestinationPickerFilesAccessibilityIdentifier";
NSString* const
kFileDestinationPickerDownloadRestrictionFilesAccessibilityIdentifier =
@"kFileDestinationPickerDownloadRestrictionFilesAccessibilityIdentifie"
@"r";
NSString* const kFileDestinationPickerDriveAccessibilityIdentifier =
@"kFileDestinationPickerDriveAccessibilityIdentifier";

@ -4,6 +4,7 @@
#import "ios/chrome/browser/save_to_drive/ui_bundled/file_destination_picker_view_controller.h"
#import "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/save_to_drive/ui_bundled/file_destination_picker_action_delegate.h"
#import "ios/chrome/browser/save_to_drive/ui_bundled/file_destination_picker_constants.h"
#import "ios/chrome/browser/shared/ui/symbols/symbols.h"
@ -175,13 +176,26 @@ using FileDestinationPickerDataSourceSnapshot =
destination == FileDestination::kFiles
? l10n_util::GetNSString(IDS_IOS_DOWNLOAD_MANAGER_DOWNLOAD_TO_FILES)
: l10n_util::GetNSString(IDS_IOS_DOWNLOAD_MANAGER_DOWNLOAD_TO_DRIVE);
// Checks if download should be restricted.
if ([self.actionDelegate shouldBlockDownloadToFile] &&
destination == FileDestination::kFiles) {
cell.userInteractionEnabled = NO;
cell.textLabel.enabled = NO;
cell.detailTextLabel.text =
l10n_util::GetNSString(IDS_POLICY_DOWNLOAD_STATUS_BLOCKED_ORGANIZATION);
cell.detailTextLabel.enabled = NO;
}
cell.accessoryType = selected ? UITableViewCellAccessoryCheckmark
: UITableViewCellAccessoryNone;
cell.backgroundColor = [UIColor colorNamed:kGroupedSecondaryBackgroundColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessibilityIdentifier =
destination == FileDestination::kFiles
? kFileDestinationPickerFilesAccessibilityIdentifier
? [self.actionDelegate shouldBlockDownloadToFile]
? kFileDestinationPickerDownloadRestrictionFilesAccessibilityIdentifier
: kFileDestinationPickerFilesAccessibilityIdentifier
: kFileDestinationPickerDriveAccessibilityIdentifier;
cell.useCustomSeparator = NO;
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, kSeparatorInset, 0, 0)];

@ -5,6 +5,7 @@
#import "base/strings/stringprintf.h"
#import "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#import "components/policy/core/common/policy_pref_names.h"
#import "components/policy/policy_constants.h"
#import "ios/chrome/browser/account_picker/ui_bundled/account_picker_confirmation/account_picker_confirmation_screen_constants.h"
#import "ios/chrome/browser/account_picker/ui_bundled/account_picker_screen/account_picker_screen_constants.h"
@ -63,6 +64,15 @@ id<GREYMatcher> FileDestinationFilesButton() {
grey_interactable(), nil);
}
// Matcher for "Files" with subtitle "Blocked by your organization" destination
// button in File destination picker UI.
id<GREYMatcher> FileDestinationDownloadRestrictionFilesButton() {
return grey_allOf(
grey_accessibilityID(
kFileDestinationPickerDownloadRestrictionFilesAccessibilityIdentifier),
grey_interactable(), nil);
}
// Matcher for "Drive" destination button in File destination picker UI.
id<GREYMatcher> FileDestinationDriveButton() {
return grey_allOf(
@ -177,6 +187,29 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse(
kWaitForDownloadTimeout];
}
// Tests that when the user is signed-in, the destination "Files" shows a
// subtitle regarding download restrictions.
- (void)testDownloadRestrictionToFiles {
[ChromeEarlGrey
setIntegerValue:static_cast<int>(policy::DownloadRestriction::ALL_FILES)
forUserPref:policy::policy_prefs::kDownloadRestrictions];
// Sign-in.
FakeSystemIdentity* fakeIdentity = [FakeSystemIdentity fakeIdentity1];
[SigninEarlGrey signinWithFakeIdentity:fakeIdentity];
// Load a page with a download button and tap the download button.
[ChromeEarlGrey loadURL:self.testServer->GetURL("/")];
[ChromeEarlGrey waitForWebStateContainingText:"Download"];
[ChromeEarlGrey tapWebStateElementWithID:@"download"];
// Check that the "Save in" button is presented and tap it.
[ChromeEarlGrey waitForUIElementToAppearWithMatcher:SaveEllipsisButton()];
[[EarlGrey selectElementWithMatcher:SaveEllipsisButton()]
performAction:grey_tap()];
// Wait for the account picker to appear with download restrictions on files.
[ChromeEarlGrey waitForUIElementToAppearWithMatcher:AccountPicker()];
[ChromeEarlGrey waitForUIElementToAppearWithMatcher:
FileDestinationDownloadRestrictionFilesButton()];
}
// Tests that when the user is signed-in, they can choose "Drive" as destination
// for their download in the file destination picker, tap "Save" in the account
// picker. Tests that after a few seconds, the file has been downloaded

@ -6,6 +6,7 @@
#import "base/metrics/histogram_functions.h"
#import "base/strings/sys_string_conversions.h"
#import "components/policy/core/common/policy_pref_names.h"
#import "components/prefs/pref_service.h"
#import "ios/chrome/browser/account_picker/ui_bundled/account_picker_coordinator.h"
#import "ios/chrome/browser/download/model/download_manager_tab_helper.h"
@ -96,7 +97,9 @@ void StorageQuotaCompletionHelper(__weak SaveToDriveMediator* mediator,
_prefService = prefService;
_driveService = driveService;
_accountManagerService = accountManagerService;
_fileDestination = FileDestination::kFiles;
_fileDestination = [self shouldBlockDownloadToFile]
? FileDestination::kDrive
: FileDestination::kFiles;
}
return self;
}
@ -238,6 +241,12 @@ void StorageQuotaCompletionHelper(__weak SaveToDriveMediator* mediator,
[self updateConsumersAnimated:YES];
}
- (bool)shouldBlockDownloadToFile {
return static_cast<policy::DownloadRestriction>(_prefService->GetInteger(
policy::policy_prefs::kDownloadRestrictions)) ==
policy::DownloadRestriction::ALL_FILES;
}
#pragma mark - Private
// Updates consumers.
@ -266,7 +275,9 @@ void StorageQuotaCompletionHelper(__weak SaveToDriveMediator* mediator,
} else {
// Otherwise, clear any memorized GAIA ID from prefs.
_prefService->ClearPref(prefs::kIosSaveToDriveDefaultGaiaId);
_fileDestination = FileDestination::kFiles;
_fileDestination = [self shouldBlockDownloadToFile]
? FileDestination::kDrive
: FileDestination::kFiles;
}
}