| // Copyright 2018 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/browser_container/browser_container_coordinator.h" |
| |
| #import <Availability.h> |
| |
| #include "base/check.h" |
| #import "ios/chrome/browser/main/browser.h" |
| #import "ios/chrome/browser/overlays/public/overlay_presenter.h" |
| #import "ios/chrome/browser/screen_time/features.h" |
| #import "ios/chrome/browser/ui/browser_container/browser_container_mediator.h" |
| #import "ios/chrome/browser/ui/browser_container/browser_container_view_controller.h" |
| #import "ios/chrome/browser/ui/overlays/overlay_container_coordinator.h" |
| #include "url/gurl.h" |
| |
| #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 |
| #import "ios/chrome/browser/ui/screen_time/screen_time_coordinator.h" |
| #endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 |
| |
| #if !defined(__has_feature) || !__has_feature(objc_arc) |
| #error "This file requires ARC support." |
| #endif |
| |
| @interface BrowserContainerCoordinator () |
| // Whether the coordinator is started. |
| @property(nonatomic, assign, getter=isStarted) BOOL started; |
| // Redefine property as readwrite. |
| @property(nonatomic, strong, readwrite) |
| BrowserContainerViewController* viewController; |
| // The mediator used to configure the BrowserContainerConsumer. |
| @property(nonatomic, strong) BrowserContainerMediator* mediator; |
| // The overlay container coordinator for OverlayModality::kWebContentArea. |
| @property(nonatomic, strong) |
| OverlayContainerCoordinator* webContentAreaOverlayContainerCoordinator; |
| // The coodinator that manages ScreenTime. |
| @property(nonatomic, strong) ChromeCoordinator* screenTimeCoordinator; |
| @end |
| |
| @implementation BrowserContainerCoordinator |
| |
| #pragma mark - ChromeCoordinator |
| |
| - (void)start { |
| if (self.started) |
| return; |
| self.started = YES; |
| DCHECK(self.browser); |
| DCHECK(!_viewController); |
| self.viewController = [[BrowserContainerViewController alloc] init]; |
| self.webContentAreaOverlayContainerCoordinator = |
| [[OverlayContainerCoordinator alloc] |
| initWithBaseViewController:self.viewController |
| browser:self.browser |
| modality:OverlayModality::kWebContentArea]; |
| [self.webContentAreaOverlayContainerCoordinator start]; |
| self.viewController.webContentsOverlayContainerViewController = |
| self.webContentAreaOverlayContainerCoordinator.viewController; |
| OverlayPresenter* overlayPresenter = OverlayPresenter::FromBrowser( |
| self.browser, OverlayModality::kWebContentArea); |
| self.mediator = [[BrowserContainerMediator alloc] |
| initWithWebStateList:self.browser->GetWebStateList() |
| webContentAreaOverlayPresenter:overlayPresenter]; |
| self.mediator.consumer = self.viewController; |
| |
| [self setUpScreenTimeIfEnabled]; |
| |
| [super start]; |
| } |
| |
| - (void)stop { |
| if (!self.started) |
| return; |
| self.started = NO; |
| [self.webContentAreaOverlayContainerCoordinator stop]; |
| [self.screenTimeCoordinator stop]; |
| self.viewController = nil; |
| self.mediator = nil; |
| [super stop]; |
| } |
| |
| #pragma mark - Private methods |
| |
| // Sets up the ScreenTime coordinator, which installs and manages the ScreenTime |
| // blocking view. |
| - (void)setUpScreenTimeIfEnabled { |
| if (!IsScreenTimeIntegrationEnabled()) |
| return; |
| |
| #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 |
| if (@available(iOS 14, *)) { |
| ScreenTimeCoordinator* screenTimeCoordinator = |
| [[ScreenTimeCoordinator alloc] |
| initWithBaseViewController:self.viewController |
| browser:self.browser]; |
| [screenTimeCoordinator start]; |
| self.viewController.screenTimeViewController = |
| screenTimeCoordinator.viewController; |
| self.screenTimeCoordinator = screenTimeCoordinator; |
| } |
| #endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 |
| } |
| |
| @end |