Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FXIOS-6662 [v117] Handle ETP coordinator transitioning Delegate #15568

Merged
2 changes: 1 addition & 1 deletion Client/Coordinators/BaseCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Common
import Foundation

open class BaseCoordinator: Coordinator {
open class BaseCoordinator: NSObject, Coordinator {
lmarceau marked this conversation as resolved.
Show resolved Hide resolved
var savedRoute: Route?
var id = UUID()
var childCoordinators: [Coordinator] = []
Expand Down
17 changes: 5 additions & 12 deletions Client/Coordinators/Browser/BrowserCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,18 +314,11 @@ class BrowserCoordinator: BaseCoordinator,
}
}

private func showETPMenu() {
let navigationController = DismissableNavigationViewController()
navigationController.modalPresentationStyle = .formSheet
let etpRouter = DefaultRouter(navigationController: navigationController)
let enhancedTrackingProtectionCoordinator = EnhancedTrackingProtectionCoordinator(router: etpRouter)
private func showETPMenu(sourceView: UIView) {
let enhancedTrackingProtectionCoordinator = EnhancedTrackingProtectionCoordinator(router: router)
enhancedTrackingProtectionCoordinator.parentCoordinator = self
add(child: enhancedTrackingProtectionCoordinator)
enhancedTrackingProtectionCoordinator.start()

router.present(navigationController) { [weak self] in
self?.didFinishEnhancedTrackingProtection(from: enhancedTrackingProtectionCoordinator)
}
enhancedTrackingProtectionCoordinator.start(sourceView: sourceView)
}

// MARK: - SettingsCoordinatorDelegate
Expand Down Expand Up @@ -383,8 +376,8 @@ class BrowserCoordinator: BaseCoordinator,
showLibrary(with: homepanelSection)
}

func showEnhancedTrackingProtection() {
showETPMenu()
func showEnhancedTrackingProtection(sourceView: UIView) {
showETPMenu(sourceView: sourceView)
}

func showShareExtension(url: URL, sourceView: UIView, toastContainer: UIView, popoverArrowDirection: UIPopoverArrowDirection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protocol BrowserNavigationHandler: AnyObject {
func show(settings: Route.SettingsSection)

/// Asks to show a enhancedTrackingProtection page, can be a general enhancedTrackingProtection page or a child page
func showEnhancedTrackingProtection()
func showEnhancedTrackingProtection(sourceView: UIView)

/// Shows the specified section of the home panel.
///
Expand Down
22 changes: 20 additions & 2 deletions Client/Coordinators/EnhancedTrackingProtectionCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ class EnhancedTrackingProtectionCoordinator: BaseCoordinator,
enhancedTrackingProtectionMenuVC.enhancedTrackingProtectionMenuDelegate = self
}

func start() {
router.push(enhancedTrackingProtectionMenuVC)
func start(sourceView: UIView) {
if UIDevice.current.userInterfaceIdiom == .phone {
enhancedTrackingProtectionMenuVC.modalPresentationStyle = .custom
enhancedTrackingProtectionMenuVC.transitioningDelegate = self
} else {
enhancedTrackingProtectionMenuVC.asPopover = true
enhancedTrackingProtectionMenuVC.modalPresentationStyle = .popover
enhancedTrackingProtectionMenuVC.popoverPresentationController?.sourceView = sourceView
enhancedTrackingProtectionMenuVC.popoverPresentationController?.permittedArrowDirections = .up
}
router.present(enhancedTrackingProtectionMenuVC, animated: true, completion: nil)
}

// MARK: - EnhancedTrackingProtectionMenuDelegate
Expand All @@ -56,3 +65,12 @@ class EnhancedTrackingProtectionCoordinator: BaseCoordinator,
parentCoordinator?.didFinishEnhancedTrackingProtection(from: self)
}
}

extension EnhancedTrackingProtectionCoordinator: UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
let globalETPStatus = FirefoxTabContentBlocker.isTrackingProtectionEnabled(prefs: profile.prefs)
return SlideOverPresentationController(presentedViewController: presented,
presenting: presenting,
withGlobalETPStatus: globalETPStatus)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ extension BrowserViewController: URLBarDelegate {
TelemetryWrapper.recordEvent(category: .action, method: .press, object: .trackingProtectionMenu)
if CoordinatorFlagManager.isEtpCoordinatorEnabled {
DispatchQueue.main.async {
self.navigationHandler?.showEnhancedTrackingProtection()
self.navigationHandler?.showEnhancedTrackingProtection(sourceView: urlBar.locationView.trackingProtectionButton)
}
} else {
self.legacyShowEnhancedTrackingProtection(viewModel: etpViewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,12 @@ final class BrowserCoordinatorTests: XCTestCase {

func testShowEnhancedTrackingProtection() throws {
let subject = createSubject()
subject.showEnhancedTrackingProtection()
subject.showEnhancedTrackingProtection(sourceView: UIView())

XCTAssertEqual(subject.childCoordinators.count, 1)
XCTAssertNotNil(subject.childCoordinators[0] as? EnhancedTrackingProtectionCoordinator)
let presentedVC = try XCTUnwrap(mockRouter.presentedViewController as? DismissableNavigationViewController)
XCTAssertEqual(mockRouter.presentCalled, 1)
XCTAssertTrue(presentedVC.topViewController is EnhancedTrackingProtectionMenuVC)
XCTAssertTrue(mockRouter.presentedViewController is EnhancedTrackingProtectionMenuVC)
}

func testShowShareExtension() {
Expand Down Expand Up @@ -658,7 +657,7 @@ final class BrowserCoordinatorTests: XCTestCase {
let subject = createSubject(isSettingsCoordinatorEnabled: true)
subject.browserHasLoaded()

subject.showEnhancedTrackingProtection()
subject.showEnhancedTrackingProtection(sourceView: UIView())
let etpCoordinator = subject.childCoordinators[0] as! EnhancedTrackingProtectionCoordinator
subject.didFinishEnhancedTrackingProtection(from: etpCoordinator)

Expand Down