Skip to content

Commit

Permalink
Fix mozilla-mobile#6590: pass deeplink _utm params to fxa webview
Browse files Browse the repository at this point in the history
  • Loading branch information
garvankeeley committed Jun 11, 2020
1 parent c7a498f commit 8d77f28
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2097,10 +2097,10 @@ extension BrowserViewController {

/// This function is called to determine if FxA sign in flow or settings page should be shown
/// - Parameters:
/// - fxaOptions: FxALaunchParams from deeplink query
/// - deepLinkParams: FxALaunchParams from deeplink query
/// - flowType: FxAPageType is used to determine if email login, qr code login, or user settings page should be presented
/// - referringPage: ReferringPage enum is used to handle telemetry events correctly for the view event and the FxA sign in tap events, need to know which route we took to get to them
func getSignInOrFxASettingsVC(_ fxaOptions: FxALaunchParams? = nil, flowType: FxAPageType, referringPage: ReferringPage) -> UIViewController {
func getSignInOrFxASettingsVC(_ deepLinkParams: FxALaunchParams? = nil, flowType: FxAPageType, referringPage: ReferringPage) -> UIViewController {
// Show the settings page if we have already signed in. If we haven't then show the signin page
let parentType: FxASignInParentType
let object: UnifiedTelemetry.EventObject
Expand All @@ -2118,8 +2118,8 @@ extension BrowserViewController {
}

let signInVC = AppInfo.isChinaEdition ?
FxAWebViewController(pageType: .emailLoginFlow, profile: profile, dismissalStyle: .dismiss) :
FirefoxAccountSignInViewController(profile: profile, parentType: parentType)
FxAWebViewController(pageType: .emailLoginFlow, profile: profile, dismissalStyle: .dismiss, deepLinkParams: deepLinkParams) :
FirefoxAccountSignInViewController(profile: profile, parentType: parentType, deepLinkParams: deepLinkParams)
UnifiedTelemetry.recordEvent(category: .firefoxAccount, method: .view, object: object)
return signInVC
}
Expand Down
8 changes: 4 additions & 4 deletions Client/Frontend/Settings/AppSettingsOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class ConnectSetting: WithoutAccountSetting {

override func onClick(_ navigationController: UINavigationController?) {
let viewController = AppInfo.isChinaEdition ?
FxAWebViewController(pageType: .emailLoginFlow, profile: profile, dismissalStyle: .popToRootVC) :
FirefoxAccountSignInViewController(profile: profile, parentType: .settings)
FxAWebViewController(pageType: .emailLoginFlow, profile: profile, dismissalStyle: .popToRootVC, deepLinkParams: nil) :
FirefoxAccountSignInViewController(profile: profile, parentType: .settings, deepLinkParams: nil)
UnifiedTelemetry.recordEvent(category: .firefoxAccount, method: .view, object: .settings)
navigationController?.pushViewController(viewController, animated: true)
}
Expand Down Expand Up @@ -341,8 +341,8 @@ class AccountStatusSetting: WithAccountSetting {
override func onClick(_ navigationController: UINavigationController?) {
guard !profile.rustFxA.accountNeedsReauth() else {
let vc = AppInfo.isChinaEdition ?
FxAWebViewController(pageType: .emailLoginFlow, profile: profile, dismissalStyle: .popToRootVC) :
FirefoxAccountSignInViewController(profile: profile, parentType: .settings)
FxAWebViewController(pageType: .emailLoginFlow, profile: profile, dismissalStyle: .popToRootVC, deepLinkParams: nil) :
FirefoxAccountSignInViewController(profile: profile, parentType: .settings, deepLinkParams: nil)
UnifiedTelemetry.recordEvent(category: .firefoxAccount, method: .view, object: .settings)
navigationController?.pushViewController(vc, animated: true)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ManageFxAccountSetting: Setting {
}

override func onClick(_ navigationController: UINavigationController?) {
let viewController = FxAWebViewController(pageType: .settingsPage, profile: profile, dismissalStyle: .popToRootVC)
let viewController = FxAWebViewController(pageType: .settingsPage, profile: profile, dismissalStyle: .popToRootVC, deepLinkParams: nil)
navigationController?.pushViewController(viewController, animated: true)
}
}
Expand Down
12 changes: 8 additions & 4 deletions RustFxA/FirefoxAccountSignInViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,17 @@ class FirefoxAccountSignInViewController: UIViewController {
/// Dismissal style for FxAWebViewController
/// Changes based on whether or not this VC is launched from the app menu or settings
private let fxaDismissStyle: DismissType


private var deepLinkParams: FxALaunchParams?

// MARK: Init() and viewDidLoad()

/// - Parameters:
/// - profile: User Profile info
/// - parentType: FxASignInParentType is an enum parent page that presented this VC. Parameter used in telemetry button events.
init(profile: Profile, parentType: FxASignInParentType) {
/// - parameter: deepLinkParams: URL args passed in from deep link that propagate to FxA web view
init(profile: Profile, parentType: FxASignInParentType, deepLinkParams: FxALaunchParams?) {
self.deepLinkParams = deepLinkParams
self.profile = profile
switch parentType {
case .appMenu:
Expand Down Expand Up @@ -190,7 +194,7 @@ class FirefoxAccountSignInViewController: UIViewController {

/// Use email login button tapped
@objc func emailLoginTapped(_ sender: UIButton) {
let fxaWebVC = FxAWebViewController(pageType: .emailLoginFlow, profile: profile, dismissalStyle: fxaDismissStyle)
let fxaWebVC = FxAWebViewController(pageType: .emailLoginFlow, profile: profile, dismissalStyle: fxaDismissStyle, deepLinkParams: deepLinkParams)
UnifiedTelemetry.recordEvent(category: .firefoxAccount, method: .qrPairing, object: telemetryObject, extras: ["flow_type": "email"])
navigationController?.pushViewController(fxaWebVC, animated: true)
}
Expand All @@ -199,7 +203,7 @@ class FirefoxAccountSignInViewController: UIViewController {
// MARK: QRCodeViewControllerDelegate Functions
extension FirefoxAccountSignInViewController: QRCodeViewControllerDelegate {
func didScanQRCodeWithURL(_ url: URL) {
let vc = FxAWebViewController(pageType: .qrCode(url: url.absoluteString), profile: profile, dismissalStyle: fxaDismissStyle)
let vc = FxAWebViewController(pageType: .qrCode(url: url.absoluteString), profile: profile, dismissalStyle: fxaDismissStyle, deepLinkParams: deepLinkParams)
navigationController?.pushViewController(vc, animated: true)
}

Expand Down
27 changes: 23 additions & 4 deletions RustFxA/FxAWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ class FxAWebViewController: UIViewController, WKNavigationDelegate {
fileprivate let profile: Profile
/// Used to show a second WKWebView to browse help links.
fileprivate var helpBrowser: WKWebView?
fileprivate var deepLinkParams: FxALaunchParams?

/**
init() FxAWebView.
- parameter pageType: Specify login flow or settings page if already logged in.
- parameter profile: a Profile.
- parameter dismissalStyle: depending on how this was presented, it uses modal dismissal, or if part of a UINavigationController stack it will pop to the root.
- parameter: deepLinkParams: URL args passed in from deep link that propagate to FxA web view
*/
init(pageType: FxAPageType, profile: Profile, dismissalStyle: DismissType) {
init(pageType: FxAPageType, profile: Profile, dismissalStyle: DismissType, deepLinkParams: FxALaunchParams?) {
self.pageType = pageType
self.profile = profile
self.dismissType = dismissalStyle
self.deepLinkParams = deepLinkParams

let contentController = WKUserContentController()
if let path = Bundle.main.path(forResource: "FxASignIn", ofType: "js"), let source = try? String(contentsOfFile: path, encoding: .utf8) {
Expand Down Expand Up @@ -89,6 +92,22 @@ class FxAWebViewController: UIViewController, WKNavigationDelegate {
webView.navigationDelegate = self
view = webView

func makeRequest(_ url: URL) -> URLRequest {
if let query = deepLinkParams?.query {
let args = query.filter { $0.key.starts(with: "utm_") }.map {
return URLQueryItem(name: $0.key, value: $0.value)
}

var comp = URLComponents(url: url, resolvingAgainstBaseURL: false)
comp?.queryItems?.append(contentsOf: args)
if let url = comp?.url {
return URLRequest(url: url)
}
}

return URLRequest(url: url)
}

RustFirefoxAccounts.shared.accountManager.uponQueue(.main) { accountManager in
accountManager.getManageAccountURL(entrypoint: "ios_settings_manage") { [weak self] result in
guard let self = self else { return }
Expand All @@ -100,21 +119,21 @@ class FxAWebViewController: UIViewController, WKNavigationDelegate {
if case .success(let url) = result {
self?.baseURL = url
UnifiedTelemetry.recordEvent(category: .firefoxAccount, method: .emailLogin, object: .accountConnected)
self?.webView.load(URLRequest(url: url))
self?.webView.load(makeRequest(url))
}
}
case let .qrCode(url):
accountManager.beginPairingAuthentication(pairingUrl: url) { [weak self] result in
if case .success(let url) = result {
self?.baseURL = url
UnifiedTelemetry.recordEvent(category: .firefoxAccount, method: .qrPairing, object: .accountConnected)
self?.webView.load(URLRequest(url: url))
self?.webView.load(makeRequest(url))
}
}
case .settingsPage:
if case .success(let url) = result {
self.baseURL = url
self.webView.load(URLRequest(url: url))
self.webView.load(makeRequest(url))
}
}
}
Expand Down

0 comments on commit 8d77f28

Please sign in to comment.