Skip to content

Commit

Permalink
[iOS] Adds Cookies to privacy screen
Browse files Browse the repository at this point in the history
 This CL creates the Cookies view controller & coordinator and adds
 Cookies to the Privacy screen. 4 options have also been added to the
 Privacy view controller.

 Bug: 1064961

Change-Id: I48534388d195f15ae199d63ef995668f0b43125b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2129708
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758791}
  • Loading branch information
Ewann authored and Commit Bot committed Apr 14, 2020
1 parent b99c852 commit 5e450e9
Show file tree
Hide file tree
Showing 20 changed files with 325 additions and 4 deletions.
24 changes: 24 additions & 0 deletions ios/chrome/app/strings/ios_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,30 @@ Handoff must also be enabled in the General section of Settings, and your device
</message>
<message name="IDS_IOS_OPTIONS_PRELOAD_WEBPAGES" desc="Title for opening the setting for if/when to preload webpages. [Length: 20em] [iOS only]">
Preload Webpages
</message>
<message name="IDS_IOS_OPTIONS_PRIVACY_COOKIES" desc="Title on Privacy screen to open Cookies">
Cookies
</message>
<message name="IDS_IOS_OPTIONS_PRIVACY_COOKIES_ALLOW_COOKIES_TITLE" desc="Option title to allow cookies">
Allow Cookies
</message>
<message name="IDS_IOS_OPTIONS_PRIVACY_COOKIES_ALLOW_COOKIES_DETAIL" desc="Option detail to allow cookies">
Sites will work normally
</message>
<message name="IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_ALL_COOKIES_TITLE" desc="Option title to block all cookies">
Block All Cookies (Not recommended)
</message>
<message name="IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_ALL_COOKIES_DETAIL" desc="Option detail to block all cookies">
Features on many sites may break
</message>
<message name="IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_THIRD_PARTY_COOKIES_TITLE" desc="Option title to block third party cookies">
Block Third-Party Cookies
</message>
<message name="IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_THIRD_PARTY_COOKIES_INCOGNITO_TITLE" desc="Option title to block third party cookies in incognito">
Block Third-Party Cookies in incognito
</message>
<message name="IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_THIRD_PARTY_COOKIES_DETAIL" desc="Option detail to block third party cookies">
Features on some sites may break
</message>
<message name="IDS_IOS_OPTIONS_PRIVACY_GOOGLE_SERVICES_FOOTER" desc="Footer to invite the user to open the Sync and Google Services settings.">
For more settings that relate to privacy, security, and data collection, see <ph name="BEGIN_LINK">BEGIN_LINK</ph>Sync and Google Services<ph name="END_LINK">END_LINK</ph>.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aea330bb9bdf26d2cd5b4fbbf38855d339559e1c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aea330bb9bdf26d2cd5b4fbbf38855d339559e1c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aea330bb9bdf26d2cd5b4fbbf38855d339559e1c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aea330bb9bdf26d2cd5b4fbbf38855d339559e1c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aea330bb9bdf26d2cd5b4fbbf38855d339559e1c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aea330bb9bdf26d2cd5b4fbbf38855d339559e1c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aea330bb9bdf26d2cd5b4fbbf38855d339559e1c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aea330bb9bdf26d2cd5b4fbbf38855d339559e1c
5 changes: 5 additions & 0 deletions ios/chrome/browser/ui/settings/privacy/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
source_set("privacy") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"cookies_coordinator.h",
"cookies_coordinator.mm",
"cookies_view_controller.h",
"cookies_view_controller.mm",
"handoff_table_view_controller.h",
"handoff_table_view_controller.mm",
"privacy_coordinator.h",
Expand All @@ -28,6 +32,7 @@ source_set("privacy") {
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/page_info:features",
"//ios/chrome/browser/ui/settings:constants",
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/settings/cells",
Expand Down
42 changes: 42 additions & 0 deletions ios/chrome/browser/ui/settings/privacy/cookies_coordinator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_COOKIES_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_COOKIES_COORDINATOR_H_

#import <Foundation/Foundation.h>

#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"

@class PrivacyCookiesCoordinator;

// Delegate that allows to dereference the PrivacyCookiesCoordinator.
@protocol PrivacyCookiesCoordinatorDelegate

// Called when the view controller is removed from navigation controller.
- (void)privacyCookiesCoordinatorViewControllerWasRemoved:
(PrivacyCookiesCoordinator*)coordinator;

@end
// The coordinator for the Cookies screen.
@interface PrivacyCookiesCoordinator : ChromeCoordinator

@property(nonatomic, weak) id<PrivacyCookiesCoordinatorDelegate> delegate;

- (instancetype)initWithBaseViewController:(UIViewController*)viewController
NS_UNAVAILABLE;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState:(ChromeBrowserState*)browserState
NS_UNAVAILABLE;
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browser:(Browser*)browser NS_UNAVAILABLE;

- (instancetype)initWithBaseNavigationController:
(UINavigationController*)navigationController
browser:(Browser*)browser
NS_DESIGNATED_INITIALIZER;

@end

#endif // IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_COOKIES_COORDINATOR_H_
56 changes: 56 additions & 0 deletions ios/chrome/browser/ui/settings/privacy/cookies_coordinator.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/ui/settings/privacy/cookies_coordinator.h"

#include "base/logging.h"
#import "ios/chrome/browser/ui/settings/privacy/cookies_view_controller.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

@interface PrivacyCookiesCoordinator () <
PrivacyCookiesViewControllerPresentationDelegate>

@property(nonatomic, strong) PrivacyCookiesViewController* viewController;

@end

@implementation PrivacyCookiesCoordinator

@synthesize baseNavigationController = _baseNavigationController;

- (instancetype)initWithBaseNavigationController:
(UINavigationController*)navigationController
browser:(Browser*)browser {
if ([super initWithBaseViewController:navigationController browser:browser]) {
_baseNavigationController = navigationController;
}
return self;
}

#pragma mark - ChromeCoordinator

- (void)start {
self.viewController = [[PrivacyCookiesViewController alloc]
initWithStyle:UITableViewStylePlain];
[self.baseNavigationController pushViewController:self.viewController
animated:YES];
self.viewController.presentationDelegate = self;
}

- (void)stop {
self.viewController = nil;
}

#pragma mark - PrivacyCookiesViewControllerPresentationDelegate

- (void)privacyCookiesViewControllerWasRemoved:
(PrivacyCookiesViewController*)controller {
DCHECK_EQ(self.viewController, controller);
[self.delegate privacyCookiesCoordinatorViewControllerWasRemoved:self];
}

@end
33 changes: 33 additions & 0 deletions ios/chrome/browser/ui/settings/privacy/cookies_view_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_COOKIES_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_COOKIES_VIEW_CONTROLLER_H_

#import <UIKit/UIKit.h>

#import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h"

@class PrivacyCookiesViewController;

// Delegate for presentation events related to
// PrivacyCookiesViewController.
@protocol PrivacyCookiesViewControllerPresentationDelegate

// Called when the view controller is removed from its parent.
- (void)privacyCookiesViewControllerWasRemoved:
(PrivacyCookiesViewController*)controller;

@end

// View Controller for displaying the Cookies screen.
@interface PrivacyCookiesViewController : SettingsRootTableViewController

// Presentation delegate.
@property(nonatomic, weak) id<PrivacyCookiesViewControllerPresentationDelegate>
presentationDelegate;

@end

#endif // IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_COOKIES_VIEW_CONTROLLER_H_
96 changes: 96 additions & 0 deletions ios/chrome/browser/ui/settings/privacy/cookies_view_controller.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/ui/settings/privacy/cookies_view_controller.h"

#import "ios/chrome/browser/ui/table_view/cells/table_view_multi_detail_text_item.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

namespace {

typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierContent = kSectionIdentifierEnumZero,
};

typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeAllowCookies = kItemTypeEnumZero,
ItemTypeBlockThirdPartyCookiesIncognito,
ItemTypeBlockThirdPartyCookies,
ItemTypeBlockAllCookies,
ItemTypeCookiesDescription,
};

} // namespace

@implementation PrivacyCookiesViewController

#pragma mark - UIViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.title = l10n_util::GetNSString(IDS_IOS_OPTIONS_PRIVACY_COOKIES);

[self loadModel];
// TODO(crbug.com/1064961): Implement this.
}

- (void)didMoveToParentViewController:(UIViewController*)parent {
[super didMoveToParentViewController:parent];
if (!parent) {
[self.presentationDelegate privacyCookiesViewControllerWasRemoved:self];
}
}

#pragma mark - ChromeTableViewController

- (void)loadModel {
[super loadModel];
[self.tableViewModel addSectionWithIdentifier:SectionIdentifierContent];

TableViewMultiDetailTextItem* allowCookies =
[[TableViewMultiDetailTextItem alloc] initWithType:ItemTypeAllowCookies];
allowCookies.text = l10n_util::GetNSString(
IDS_IOS_OPTIONS_PRIVACY_COOKIES_ALLOW_COOKIES_TITLE);
allowCookies.leadingDetailText = l10n_util::GetNSString(
IDS_IOS_OPTIONS_PRIVACY_COOKIES_ALLOW_COOKIES_DETAIL);
[self.tableViewModel addItem:allowCookies
toSectionWithIdentifier:SectionIdentifierContent];

TableViewMultiDetailTextItem* blockThirdPartyCookiesIncognito =
[[TableViewMultiDetailTextItem alloc]
initWithType:ItemTypeBlockThirdPartyCookiesIncognito];
blockThirdPartyCookiesIncognito.text = l10n_util::GetNSString(
IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_THIRD_PARTY_COOKIES_INCOGNITO_TITLE);
blockThirdPartyCookiesIncognito.leadingDetailText = l10n_util::GetNSString(
IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_THIRD_PARTY_COOKIES_DETAIL);
[self.tableViewModel addItem:blockThirdPartyCookiesIncognito
toSectionWithIdentifier:SectionIdentifierContent];

TableViewMultiDetailTextItem* blockThirdPartyCookies =
[[TableViewMultiDetailTextItem alloc]
initWithType:ItemTypeBlockThirdPartyCookies];
blockThirdPartyCookies.text = l10n_util::GetNSString(
IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_THIRD_PARTY_COOKIES_TITLE);
blockThirdPartyCookies.leadingDetailText = l10n_util::GetNSString(
IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_THIRD_PARTY_COOKIES_DETAIL);
[self.tableViewModel addItem:blockThirdPartyCookies
toSectionWithIdentifier:SectionIdentifierContent];

TableViewMultiDetailTextItem* blockAllCookies =
[[TableViewMultiDetailTextItem alloc]
initWithType:ItemTypeBlockAllCookies];
blockAllCookies.text = l10n_util::GetNSString(
IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_ALL_COOKIES_TITLE);
blockAllCookies.leadingDetailText = l10n_util::GetNSString(
IDS_IOS_OPTIONS_PRIVACY_COOKIES_BLOCK_ALL_COOKIES_DETAIL);
[self.tableViewModel addItem:blockAllCookies
toSectionWithIdentifier:SectionIdentifierContent];
}

@end
31 changes: 30 additions & 1 deletion ios/chrome/browser/ui/settings/privacy/privacy_coordinator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data/clear_browsing_data_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data/clear_browsing_data_ui_delegate.h"
#import "ios/chrome/browser/ui/settings/privacy/cookies_coordinator.h"
#import "ios/chrome/browser/ui/settings/privacy/handoff_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/privacy/privacy_navigation_commands.h"
#import "ios/chrome/browser/ui/settings/privacy/privacy_table_view_controller.h"
Expand All @@ -22,11 +23,13 @@

@interface PrivacyCoordinator () <
ClearBrowsingDataUIDelegate,
PrivacyCookiesCoordinatorDelegate,
PrivacyNavigationCommands,
PrivacyTableViewControllerPresentationDelegate>

@property(nonatomic, strong) id<ApplicationCommands> handler;
@property(nonatomic, strong) PrivacyTableViewController* viewController;
@property(nonatomic, strong) PrivacyCookiesCoordinator* cookiesCoordinator;

@end

Expand Down Expand Up @@ -63,6 +66,25 @@ - (void)start {

- (void)stop {
self.viewController = nil;
[self.cookiesCoordinator stop];
self.cookiesCoordinator = nil;
}

#pragma mark - PrivacyTableViewControllerPresentationDelegate

- (void)privacyTableViewControllerWasRemoved:
(PrivacyTableViewController*)controller {
DCHECK_EQ(self.viewController, controller);
[self.delegate privacyCoordinatorViewControllerWasRemoved:self];
}

#pragma mark - PrivacyCookiesCoordinatorDelegate

- (void)privacyCookiesCoordinatorViewControllerWasRemoved:
(PrivacyCookiesCoordinator*)coordinator {
DCHECK(self.cookiesCoordinator);
[coordinator stop];
coordinator = nil;
}

#pragma mark - PrivacyNavigationCommands
Expand All @@ -86,6 +108,14 @@ - (void)showClearBrowsingData {
animated:YES];
}

- (void)showCookies {
self.cookiesCoordinator = [[PrivacyCookiesCoordinator alloc]
initWithBaseNavigationController:self.baseNavigationController
browser:self.browser];
self.cookiesCoordinator.delegate = self;
[self.cookiesCoordinator start];
}

#pragma mark - PrivacyTableViewControllerPresentationDelegate

- (void)privacyTableViewControllerViewControllerWasRemoved:
Expand All @@ -107,5 +137,4 @@ - (void)dismissClearBrowsingData {
self.viewController.navigationController);
[navigationController closeSettings];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// Shows ClearBrowsingData screen.
- (void)showClearBrowsingData;

// Shows Cookies screen.
- (void)showCookies;

@end

#endif // IOS_CHROME_BROWSER_UI_SETTINGS_PRIVACY_PRIVACY_NAVIGATION_COMMANDS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern NSString* const kPrivacyTableViewId;
@protocol PrivacyTableViewControllerPresentationDelegate

// Called when the view controller is removed from its parent.
- (void)privacyTableViewControllerViewControllerWasRemoved:
- (void)privacyTableViewControllerWasRemoved:
(PrivacyTableViewController*)controller;

@end
Expand Down
Loading

0 comments on commit 5e450e9

Please sign in to comment.