Skip to content

Commit

Permalink
Bugfix FXIOS-7880 [v121] Save/Update Login Snackbar - White buttons a…
Browse files Browse the repository at this point in the history
…nd white text (#17625) (#17638)

* Conform to Themeable

* Correct spelling

* Remove conformance to Themeable

(cherry picked from commit 1a03173)

Co-authored-by: PARAIPAN SORIN <[email protected]>
  • Loading branch information
mergify[bot] and PARAIPAN9 authored Dec 6, 2023
1 parent 93b0aad commit 2b78a10
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
8 changes: 6 additions & 2 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,11 @@ extension BrowserViewController: LegacyTabDelegate {

// only add the logins helper if the tab is not a private browsing tab
if !tab.isPrivate {
let logins = LoginsHelper(tab: tab, profile: profile)
let logins = LoginsHelper(
tab: tab,
profile: profile,
theme: themeManager.currentTheme
)
tab.addContentScript(logins, name: LoginsHelper.name())
}

Expand Down Expand Up @@ -2091,7 +2095,7 @@ extension BrowserViewController: LegacyTabDelegate {
// the selected Tab, do nothing right now. If/when the Tab gets
// selected later, we will show the SnackBar at that time.
guard tab == tabManager.selectedTab else { return }

bar.applyTheme(theme: themeManager.currentTheme)
bottomContentStackView.addArrangedViewToBottom(bar, completion: {
self.view.layoutIfNeeded()
})
Expand Down
34 changes: 25 additions & 9 deletions Client/Frontend/TabContentsScripts/LoginsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@ import Storage
import WebKit

class LoginsHelper: TabContentScript {
fileprivate weak var tab: Tab?
fileprivate let profile: Profile
fileprivate var snackBar: SnackBar?
private weak var tab: Tab?
private let profile: Profile
private let theme: Theme
private var snackBar: SnackBar?

// Exposed for mocking purposes
var logins: RustLogins {
return profile.logins
}

class func name() -> String {
return "LoginsHelper"
String(describing: self)
}

required init(tab: Tab, profile: Profile) {
required init(tab: Tab, profile: Profile, theme: Theme) {
self.tab = tab
self.profile = profile
self.theme = theme
}

func scriptMessageHandlerName() -> String? {
return "loginsManagerMessageHandler"
}

fileprivate func getOrigin(_ uriString: String, allowJS: Bool = false) -> String? {
private func getOrigin(_ uriString: String, allowJS: Bool = false) -> String? {
guard let uri = URL(string: uriString, invalidCharacters: false),
let scheme = uri.scheme, !scheme.isEmpty,
let host = uri.host
Expand Down Expand Up @@ -156,7 +158,7 @@ class LoginsHelper: TabContentScript {
}
}

fileprivate func promptSave(_ login: LoginEntry) {
private func promptSave(_ login: LoginEntry) {
guard login.isValid.isSuccess else { return }

let promptMessage: String
Expand Down Expand Up @@ -185,12 +187,14 @@ class LoginsHelper: TabContentScript {
self.sendLoginsSavedTelemetry()
_ = self.profile.logins.addLogin(login: login)
}

applyTheme(for: dontSave, save)
snackBar?.addButton(dontSave)
snackBar?.addButton(save)
tab?.addSnackbar(snackBar!)
}

fileprivate func promptUpdateFromLogin(login old: LoginRecord, toLogin new: LoginEntry) {
private func promptUpdateFromLogin(login old: LoginRecord, toLogin new: LoginEntry) {
guard new.isValid.isSuccess else { return }

let formatted: String
Expand All @@ -216,12 +220,14 @@ class LoginsHelper: TabContentScript {
self.sendLoginsModifiedTelemetry()
_ = self.profile.logins.updateLogin(id: old.id, login: new)
}

applyTheme(for: dontSave, update)
snackBar?.addButton(dontSave)
snackBar?.addButton(update)
tab?.addSnackbar(snackBar!)
}

fileprivate func requestLogins(_ request: [String: Any], url: URL) {
private func requestLogins(_ request: [String: Any], url: URL) {
guard let requestId = request["requestId"] as? String,
// Even though we don't currently use these two fields,
// verify that they were received as additional confirmation
Expand Down Expand Up @@ -256,6 +262,16 @@ class LoginsHelper: TabContentScript {
}
}

// MARK: Theming System
private func applyTheme(for views: UIView...) {
views.forEach { view in
if let view = view as? ThemeApplicable {
view.applyTheme(theme: theme)
}
}
}

// MARK: - Telemetry
private func sendLoginsModifiedTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .change,
Expand Down

0 comments on commit 2b78a10

Please sign in to comment.