Skip to content

Commit

Permalink
Refactor FXIOS-10205 [Swiftlint] Resolve 12 implicitly_unwrapped_opti…
Browse files Browse the repository at this point in the history
…onal violations in BrowserViewController and extensions (#23816)

* Resolve warnings in BrowserViewController

* Resolve warnings in BrowserViewController+WebViewDelegates.swift

---------

Co-authored-by: Marceau Tonelli <[email protected]>
  • Loading branch information
tonell-m and tonelli-m authored Dec 17, 2024
1 parent d9d0143 commit 8655453
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class BrowserCoordinator: BaseCoordinator,
return browserViewController.tabManager.selectedTab?.currentWebView()?.hasOnlySecureContent ?? false
}

guard let bar = browserViewController.urlBar else { return false }
guard let bar = browserViewController.legacyUrlBar else { return false }
return bar.locationView.hasSecureContent
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ extension BrowserViewController {

if isToolbarRefactorEnabled {
store.dispatch(ToolbarAction(windowUUID: windowUUID, actionType: ToolbarActionType.didStartEditingUrl))
} else {
urlBar.tabLocationViewDidTapLocation(urlBar.locationView)
} else if let legacyUrlBar {
legacyUrlBar.tabLocationViewDidTapLocation(legacyUrlBar.locationView)
}
}

Expand Down Expand Up @@ -421,7 +421,7 @@ extension BrowserViewController {

let isEditingText = tabManager.selectedTab?.isEditing ?? false

if !isToolbarRefactorEnabled, urlBar.inOverlayMode {
if !isToolbarRefactorEnabled, let legacyUrlBar, legacyUrlBar.inOverlayMode {
return commands + searchLocationCommands
} else if !isEditingText {
return commands + overridesTextEditing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ extension BrowserViewController: TabToolbarDelegate, PhotonActionSheetProtocol {
func dismissUrlBar() {
if isToolbarRefactorEnabled, addressToolbarContainer.inOverlayMode {
addressToolbarContainer.leaveOverlayMode(reason: .finished, shouldCancelLoading: false)
} else if !isToolbarRefactorEnabled, urlBar.inOverlayMode {
urlBar.leaveOverlayMode(reason: .finished, shouldCancelLoading: false)
} else if !isToolbarRefactorEnabled, let legacyUrlBar, legacyUrlBar.inOverlayMode {
legacyUrlBar.leaveOverlayMode(reason: .finished, shouldCancelLoading: false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ extension BrowserViewController: URLBarDelegate {

func locationActionsForURLBar() -> [AccessibleAction] {
if UIPasteboard.general.hasStrings {
return [pasteGoAction, pasteAction, copyAddressAction]
return [pasteGoAction, pasteAction, copyAddressAction].compactMap { $0 }
} else {
return [copyAddressAction]
return [copyAddressAction].compactMap { $0 }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ extension BrowserViewController: WKUIDelegate {

// MARK: - WKNavigationDelegate
extension BrowserViewController: WKNavigationDelegate {
func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation?) {
guard let tab = tabManager[webView] else { return }

if !tab.adsTelemetryUrlList.isEmpty,
Expand All @@ -389,7 +389,7 @@ extension BrowserViewController: WKNavigationDelegate {
}
}

func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation?) {
if tabManager.selectedTab?.webView !== webView { return }

updateFindInPageVisibility(isVisible: false)
Expand Down Expand Up @@ -703,8 +703,7 @@ extension BrowserViewController: WKNavigationDelegate {
// Open our helper and cancel this response from the webview.
if let downloadViewModel = downloadHelper.downloadViewModel(windowUUID: windowUUID,
okAction: downloadAction) {
let displayFrom = isToolbarRefactorEnabled ? addressToolbarContainer : urlBar!
presentSheetWith(viewModel: downloadViewModel, on: self, from: displayFrom)
presentSheetWith(viewModel: downloadViewModel, on: self, from: urlBarView)
}
decisionHandler(.cancel)
return
Expand Down Expand Up @@ -733,7 +732,7 @@ extension BrowserViewController: WKNavigationDelegate {
/// Tells the delegate that an error occurred during navigation.
func webView(
_ webView: WKWebView,
didFail navigation: WKNavigation!,
didFail navigation: WKNavigation?,
withError error: Error
) {
logger.log("Error occurred during navigation.",
Expand All @@ -751,7 +750,7 @@ extension BrowserViewController: WKNavigationDelegate {
/// Invoked when an error occurs while starting to load data for the main frame.
func webView(
_ webView: WKWebView,
didFailProvisionalNavigation navigation: WKNavigation!,
didFailProvisionalNavigation navigation: WKNavigation?,
withError error: Error
) {
logger.log("Error occurred during the early navigation process.",
Expand Down Expand Up @@ -795,7 +794,7 @@ extension BrowserViewController: WKNavigationDelegate {
)
store.dispatch(middlewareAction)
} else {
urlBar.currentURL = tab.url?.displayURL
legacyUrlBar?.currentURL = tab.url?.displayURL
}
}
return
Expand Down Expand Up @@ -896,7 +895,7 @@ extension BrowserViewController: WKNavigationDelegate {
}
}

func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation?) {
guard let tab = tabManager[webView],
let metadataManager = tab.metadataManager
else { return }
Expand Down Expand Up @@ -942,7 +941,7 @@ extension BrowserViewController: WKNavigationDelegate {
}
}

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation?) {
webviewTelemetry.stop()

if let tab = tabManager[webView],
Expand Down
Loading

0 comments on commit 8655453

Please sign in to comment.