Skip to content

Commit

Permalink
Refactor FXIOS-10467 - Remove force_cast violations from Frontend Fea…
Browse files Browse the repository at this point in the history
…tures & Content View (#23044)
  • Loading branch information
bmihai23 authored and Tushar Chitnavis committed Nov 14, 2024
1 parent 22d6a52 commit 93953f7
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 16 deletions.
23 changes: 18 additions & 5 deletions firefox-ios/Client/Frontend/Home/Pocket/PocketViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ class PocketViewModel {
private var pocketStoriesViewModels = [PocketStandardCellViewModel]()
private var wallpaperManager: WallpaperManager
private var prefs: Prefs
private let logger: Logger

init(pocketDataAdaptor: PocketDataAdaptor,
isZeroSearch: Bool = false,
theme: Theme,
prefs: Prefs,
wallpaperManager: WallpaperManager) {
wallpaperManager: WallpaperManager,
logger: Logger = DefaultLogger.shared) {
self.dataAdaptor = pocketDataAdaptor
self.isZeroSearch = isZeroSearch
self.theme = theme
self.prefs = prefs
self.wallpaperManager = wallpaperManager
self.logger = logger
}

// The dimension of a cell
Expand Down Expand Up @@ -208,15 +211,25 @@ extension PocketViewModel: HomepageSectionHandler {
recordSectionHasShown()

if isStoryCell(index: indexPath.row) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: LegacyPocketStandardCell.cellIdentifier,
for: indexPath) as! LegacyPocketStandardCell
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: LegacyPocketStandardCell.cellIdentifier,
for: indexPath) as? LegacyPocketStandardCell else {
logger.log("Failed to dequeue LegacyPocketStandardCell at indexPath: \(indexPath)",
level: .fatal,
category: .legacyHomepage)
return UICollectionViewCell()
}
let viewModel = pocketStoriesViewModels[indexPath.row]
viewModel.tag = indexPath.row
cell.configure(viewModel: viewModel, theme: theme)
return cell
} else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PocketDiscoverCell.cellIdentifier,
for: indexPath) as! PocketDiscoverCell
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PocketDiscoverCell.cellIdentifier,
for: indexPath) as? PocketDiscoverCell else {
logger.log("Failed to dequeue PocketDiscoverCell at indexPath: \(indexPath)",
level: .fatal,
category: .legacyHomepage)
return UICollectionViewCell()
}
cell.configure(text: .FirefoxHomepage.Pocket.DiscoverMore, theme: theme)
return cell
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,13 @@ class DownloadsPanel: UIViewController,

// MARK: - TableView Delegate / DataSource
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: TwoLineImageOverlayCell.cellIdentifier,
for: indexPath) as! TwoLineImageOverlayCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: TwoLineImageOverlayCell.cellIdentifier,
for: indexPath) as? TwoLineImageOverlayCell else {
logger.log("Failed to dequeue TwoLineImageOverlayCell at indexPath: \(indexPath)",
level: .fatal,
category: .library)
return UITableViewCell()
}

return configureDownloadedFile(cell, for: indexPath)
}
Expand Down
14 changes: 11 additions & 3 deletions firefox-ios/Client/Frontend/Library/Reader/ReaderPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class ReadingListPanel: UITableViewController,
var notificationCenter: NotificationProtocol
let windowUUID: WindowUUID
var currentWindowUUID: UUID? { windowUUID }
private let logger: Logger

private lazy var longPressRecognizer: UILongPressGestureRecognizer = {
return UILongPressGestureRecognizer(target: self, action: #selector(longPress))
Expand All @@ -188,12 +189,14 @@ class ReadingListPanel: UITableViewController,
profile: Profile,
windowUUID: WindowUUID,
themeManager: ThemeManager = AppContainer.shared.resolve(),
notificationCenter: NotificationProtocol = NotificationCenter.default
notificationCenter: NotificationProtocol = NotificationCenter.default,
logger: Logger = DefaultLogger.shared
) {
self.profile = profile
self.windowUUID = windowUUID
self.themeManager = themeManager
self.notificationCenter = notificationCenter
self.logger = logger
self.state = .readingList
super.init(nibName: nil, bundle: nil)

Expand Down Expand Up @@ -346,10 +349,15 @@ class ReadingListPanel: UITableViewController,
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(
guard let cell = tableView.dequeueReusableCell(
withIdentifier: "ReadingListTableViewCell",
for: indexPath
) as! ReadingListTableViewCell
) as? ReadingListTableViewCell else {
logger.log("Failed to dequeue ReadingListTableViewCell at indexPath: \(indexPath)",
level: .fatal,
category: .library)
return UITableViewCell()
}
if let record = records?[indexPath.row] {
cell.title = record.title
cell.url = URL(string: record.url, invalidCharacters: false)!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Common
import Foundation
import Shared
import WebKit
Expand All @@ -14,13 +15,15 @@ protocol FindInPageHelperDelegate: AnyObject {
class FindInPageHelper: TabContentScript {
weak var delegate: FindInPageHelperDelegate?
fileprivate weak var tab: Tab?
private let logger: Logger

class func name() -> String {
return "FindInPage"
}

required init(tab: Tab) {
required init(tab: Tab, logger: Logger = DefaultLogger.shared) {
self.tab = tab
self.logger = logger
}

func scriptMessageHandlerNames() -> [String]? {
Expand All @@ -31,7 +34,12 @@ class FindInPageHelper: TabContentScript {
_ userContentController: WKUserContentController,
didReceiveScriptMessage message: WKScriptMessage
) {
let data = message.body as! [String: Int]
guard let data = message.body as? [String: Int] else {
logger.log("Invalid data message body in FindInPageHelper: \(message.body)",
level: .fatal,
category: .library)
return
}

if let currentResult = data["currentResult"] {
delegate?.findInPageHelper(self, didUpdateCurrentResult: currentResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Common
import Foundation
import WebKit
import Shared

class LocalRequestHelper: TabContentScript {
private let logger: Logger

required init(logger: Logger = DefaultLogger.shared) {
self.logger = logger
}

func scriptMessageHandlerNames() -> [String]? {
return ["localRequestHelper"]
}
Expand All @@ -19,7 +26,12 @@ class LocalRequestHelper: TabContentScript {
let internalUrl = InternalURL(requestUrl)
else { return }

let params = message.body as! [String: String]
guard let params = message.body as? [String: String] else {
logger.log("Invalid data message body in LocalRequestHelper: \(message.body)",
level: .fatal,
category: .library)
return
}

guard let token = params["appIdToken"],
token == UserScriptManager.appIdToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,20 @@ class CertificatesViewController: UIViewController,
var themeObserver: NSObjectProtocol?
let windowUUID: WindowUUID
var currentWindowUUID: UUID? { return windowUUID }
private let logger: Logger

// MARK: - View Lifecycle

init(with viewModel: CertificatesModel,
windowUUID: WindowUUID,
and notificationCenter: NotificationProtocol = NotificationCenter.default,
themeManager: ThemeManager = AppContainer.shared.resolve()) {
themeManager: ThemeManager = AppContainer.shared.resolve(),
logger: Logger = DefaultLogger.shared) {
self.model = viewModel
self.windowUUID = windowUUID
self.notificationCenter = notificationCenter
self.themeManager = themeManager
self.logger = logger
super.init(nibName: nil, bundle: nil)
}

Expand Down Expand Up @@ -182,8 +185,13 @@ class CertificatesViewController: UIViewController,
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = tableView.dequeueReusableHeaderFooterView(
withIdentifier: CertificatesHeaderView.cellIdentifier) as! CertificatesHeaderView
guard let headerView = tableView.dequeueReusableHeaderFooterView(
withIdentifier: CertificatesHeaderView.cellIdentifier) as? CertificatesHeaderView else {
logger.log("Failed to dequeue CertificatesHeaderView with identifier \(CertificatesHeaderView.cellIdentifier)",
level: .fatal,
category: .certificate)
return UIView()
}
var items: [CertificatesHeaderItem] = []
for (index, certificate) in model.certificates.enumerated() {
let certificateValues = certificate.subject.description.getDictionary()
Expand Down

0 comments on commit 93953f7

Please sign in to comment.