Skip to content

Commit

Permalink
QR Code Login (mozilla-mobile#6650)
Browse files Browse the repository at this point in the history
* New FirefoxAccountSignInViewController for QR Code Sign In and Email Sign In/Sign Up

* Update telemetry to match new requirements.
  • Loading branch information
kaylagalway committed May 21, 2020
1 parent db72376 commit a5b94d1
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 66 deletions.
12 changes: 8 additions & 4 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,14 @@
C8E18F22222EE11B00E30E52 /* MozillaAppServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EBCF403C221CBC9A00B38F28 /* MozillaAppServices.framework */; };
C8E2E80C23D20FB3005AACE6 /* Avatar.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8E2E80823D20FB3005AACE6 /* Avatar.swift */; };
C8E2E80D23D20FB3005AACE6 /* RustFirefoxAccounts.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8E2E80923D20FB3005AACE6 /* RustFirefoxAccounts.swift */; };
C8E2E80E23D20FD2005AACE6 /* FxAWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8E2E80723D20FB3005AACE6 /* FxAWebView.swift */; };
C8E2E80E23D20FD2005AACE6 /* FxAWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8E2E80723D20FB3005AACE6 /* FxAWebViewController.swift */; };
C8EB60C41F1FB12500F9B5B3 /* navigationDelegate.html in Resources */ = {isa = PBXBuildFile; fileRef = C8EB60C31F1FB12500F9B5B3 /* navigationDelegate.html */; };
C8EB60DC1F1FB9AD00F9B5B3 /* NavigationDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8EB60DB1F1FB9AD00F9B5B3 /* NavigationDelegateTests.swift */; };
C8F457A81F1FD75A000CB895 /* BrowserViewController+WebViewDelegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8F457A71F1FD75A000CB895 /* BrowserViewController+WebViewDelegates.swift */; };
C8F457AA1F1FDD9B000CB895 /* BrowserViewController+KeyCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8F457A91F1FDD9B000CB895 /* BrowserViewController+KeyCommands.swift */; };
C8FB0C75232151BA00031088 /* AppMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8FB0C74232151BA00031088 /* AppMenu.swift */; };
C8FB0C782321523D00031088 /* PageActionMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8FB0C772321523D00031088 /* PageActionMenu.swift */; };
CDB3BE8724746787009320EE /* FirefoxAccountSignInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB3BE8624746787009320EE /* FirefoxAccountSignInViewController.swift */; };
CE7F11941F3CEEC800ABFC0B /* RemoteDevices.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE7F115E1F3CCEF900ABFC0B /* RemoteDevices.swift */; };
CEFA977E1FAA6B490016F365 /* SyncContentSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEFA977D1FAA6B490016F365 /* SyncContentSettingsViewController.swift */; };
D006F2E32283307B0004D3AB /* KIF.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7B604F981C494F74006EEEC3 /* KIF.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -1491,7 +1492,7 @@
C8DFFE482294AAB600296DB1 /* NetworkUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkUtils.swift; sourceTree = "<group>"; };
C8E18F1D222EDE4400E30E52 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
C8E18F1F222EDED000E30E52 /* SafariServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SafariServices.framework; path = System/Library/Frameworks/SafariServices.framework; sourceTree = SDKROOT; };
C8E2E80723D20FB3005AACE6 /* FxAWebView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FxAWebView.swift; sourceTree = "<group>"; };
C8E2E80723D20FB3005AACE6 /* FxAWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FxAWebViewController.swift; sourceTree = "<group>"; };
C8E2E80823D20FB3005AACE6 /* Avatar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Avatar.swift; sourceTree = "<group>"; };
C8E2E80923D20FB3005AACE6 /* RustFirefoxAccounts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RustFirefoxAccounts.swift; sourceTree = "<group>"; };
C8EB60C31F1FB12500F9B5B3 /* navigationDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = navigationDelegate.html; sourceTree = "<group>"; };
Expand All @@ -1500,6 +1501,7 @@
C8F457A91F1FDD9B000CB895 /* BrowserViewController+KeyCommands.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BrowserViewController+KeyCommands.swift"; sourceTree = "<group>"; };
C8FB0C74232151BA00031088 /* AppMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppMenu.swift; sourceTree = "<group>"; };
C8FB0C772321523D00031088 /* PageActionMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageActionMenu.swift; sourceTree = "<group>"; };
CDB3BE8624746787009320EE /* FirefoxAccountSignInViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirefoxAccountSignInViewController.swift; sourceTree = "<group>"; };
CE7F115E1F3CCEF900ABFC0B /* RemoteDevices.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoteDevices.swift; sourceTree = "<group>"; };
CEFA977D1FAA6B490016F365 /* SyncContentSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncContentSettingsViewController.swift; sourceTree = "<group>"; };
D000661320472890009BA6F6 /* __firefox__.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = __firefox__.js; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2715,9 +2717,10 @@
isa = PBXGroup;
children = (
EB07F85E240D695F00924860 /* PushNotificationSetup.swift */,
C8E2E80723D20FB3005AACE6 /* FxAWebView.swift */,
C8E2E80723D20FB3005AACE6 /* FxAWebViewController.swift */,
C8E2E80823D20FB3005AACE6 /* Avatar.swift */,
C8E2E80923D20FB3005AACE6 /* RustFirefoxAccounts.swift */,
CDB3BE8624746787009320EE /* FirefoxAccountSignInViewController.swift */,
);
path = RustFxA;
sourceTree = "<group>";
Expand Down Expand Up @@ -5126,6 +5129,7 @@
C4EFEECF1CEBB6F2009762A4 /* BackForwardTableViewCell.swift in Sources */,
2C49854E206173C800893DAE /* photon-colors.swift in Sources */,
EBA3B2C32268F16300728BDB /* PhotonActionSheetCell.swift in Sources */,
CDB3BE8724746787009320EE /* FirefoxAccountSignInViewController.swift in Sources */,
D0EAE0E2228B3762001C875A /* DrawerViewController.swift in Sources */,
E689C7301E0C7617008BAADB /* NSAttributedStringExtensions.swift in Sources */,
D0C95E0E200FD3B200E4E51C /* PrintHelper.swift in Sources */,
Expand Down Expand Up @@ -5174,7 +5178,7 @@
E63ED7D81BFCD9990097D08E /* LoginTableViewCell.swift in Sources */,
66CE54A820FCF6CF00CC310B /* WebsiteDataManagementViewController.swift in Sources */,
C8FB0C75232151BA00031088 /* AppMenu.swift in Sources */,
C8E2E80E23D20FD2005AACE6 /* FxAWebView.swift in Sources */,
C8E2E80E23D20FD2005AACE6 /* FxAWebViewController.swift in Sources */,
3BB50E201D627539004B33DF /* FirefoxHomeViewController.swift in Sources */,
F84B22241A09122500AAB793 /* LibraryViewController.swift in Sources */,
39455F771FC83F430088A22C /* TabEventHandler.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "qr-code-icon-white.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
15 changes: 15 additions & 0 deletions Client/Assets/Images.xcassets/qr-scan.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "qr-scan.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
34 changes: 34 additions & 0 deletions Client/Extensions/UIViewControllerExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,37 @@ enum NavigationItemText {
}
}
}

extension UIViewController {
/// This presents a View Controller with a bar button item that can be used to dismiss the VC
/// - Parameters:
/// - navItemLocation: Define whether dismiss bar button item should be on the right or left of the navigation bar
/// - navItemText: Define whether bar button item text should be "Done" or "Close"
/// - vcBeingPresented: ViewController to present with this bar button item
/// - topTabsVisible: If tabs of browser should still be visible. iPad only.
func presentThemedViewController(navItemLocation: NavigationItemLocation, navItemText: NavigationItemText, vcBeingPresented: UIViewController, topTabsVisible: Bool) {
let vcToPresent = vcBeingPresented
let buttonItem = UIBarButtonItem(title: navItemText.localizedString(), style: .plain, target: self, action: #selector(dismissVC))
switch navItemLocation {
case .Left:
vcToPresent.navigationItem.leftBarButtonItem = buttonItem
case .Right:
vcToPresent.navigationItem.rightBarButtonItem = buttonItem
}
let themedNavigationController = ThemedNavigationController(rootViewController: vcToPresent)
themedNavigationController.navigationBar.isTranslucent = false
if topTabsVisible {
themedNavigationController.preferredContentSize = CGSize(width: ViewControllerConsts.PreferredSize.IntroViewController.width, height: ViewControllerConsts.PreferredSize.IntroViewController.height)
themedNavigationController.modalPresentationStyle = .formSheet
} else {
themedNavigationController.modalPresentationStyle = .fullScreen
}
self.present(themedNavigationController, animated: true, completion: nil)
}

@objc func dismissVC() {
self.dismiss(animated: true, completion: nil)
}
}


28 changes: 5 additions & 23 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ extension BrowserViewController {
settingsTableViewController.profile = self.profile
settingsTableViewController.tabManager = self.tabManager
settingsTableViewController.settingsDelegate = self
self.presentThemedViewController(navItemLocation: .Left, navItemText: .Close, vcBeingPresented: settingsTableViewController)
self.presentThemedViewController(navItemLocation: .Left, navItemText: .Close, vcBeingPresented: settingsTableViewController, topTabsVisible: self.topTabsVisible)
}
}
present(etpCoverSheetViewController, animated: true, completion: nil)
Expand Down Expand Up @@ -2090,7 +2090,9 @@ extension BrowserViewController {
func getSignInOrFxASettingsVC(_ fxaOptions: FxALaunchParams? = nil, flowType: FxAPageType) -> UIViewController {
// Show the settings page if we have already signed in. If we haven't then show the signin page
guard profile.hasSyncableAccount() else {
return FxAWebView(pageType: flowType, profile: profile, dismissalStyle: .dismiss)
let signInVC = FirefoxAccountSignInViewController(profile: profile, parentType: .appMenu)
UnifiedTelemetry.recordEvent(category: .firefoxAccount, method: .view, object: .appMenu)
return signInVC
}

let settingsTableViewController = SyncContentSettingsViewController()
Expand All @@ -2100,7 +2102,7 @@ extension BrowserViewController {

func presentSignInViewController(_ fxaOptions: FxALaunchParams? = nil, flowType: FxAPageType = .emailLoginFlow) {
let vcToPresent = getSignInOrFxASettingsVC(fxaOptions, flowType: flowType)
presentThemedViewController(navItemLocation: .Left, navItemText: .Close, vcBeingPresented: vcToPresent)
presentThemedViewController(navItemLocation: .Left, navItemText: .Close, vcBeingPresented: vcToPresent, topTabsVisible: true)
}

@objc func dismissSignInViewController() {
Expand Down Expand Up @@ -2312,26 +2314,6 @@ extension BrowserViewController {
LeanPlumClient.shared.track(event: .saveImage)
}
}

func presentThemedViewController(navItemLocation: NavigationItemLocation, navItemText: NavigationItemText, vcBeingPresented: UIViewController) {
let vcToPresent = vcBeingPresented
let buttonItem = UIBarButtonItem(title: navItemText.localizedString(), style: .plain, target: self, action: #selector(dismissSignInViewController))
switch navItemLocation {
case .Left:
vcToPresent.navigationItem.leftBarButtonItem = buttonItem
case .Right:
vcToPresent.navigationItem.rightBarButtonItem = buttonItem
}
let themedNavigationController = ThemedNavigationController(rootViewController: vcToPresent)
themedNavigationController.navigationBar.isTranslucent = false
if topTabsVisible {
themedNavigationController.preferredContentSize = CGSize(width: ViewControllerConsts.PreferredSize.IntroViewController.width, height: ViewControllerConsts.PreferredSize.IntroViewController.height)
themedNavigationController.modalPresentationStyle = .formSheet
} else {
themedNavigationController.modalPresentationStyle = .fullScreen
}
self.present(themedNavigationController, animated: true, completion: nil)
}
}

extension BrowserViewController: KeyboardHelperDelegate {
Expand Down
4 changes: 2 additions & 2 deletions Client/Frontend/Intro/IntroViewControllerV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class IntroViewControllerV2: UIViewController {
}
// Sign up button closure
introWelcomeSyncV1Views.signUpClosure = {
self.didFinishClosure?(self, .signUpFlow)
self.didFinishClosure?(self, .emailLoginFlow)
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ class IntroViewControllerV2: UIViewController {
}
// Sign-up browsing button action
syncCard.signUp = {
self.didFinishClosure?(self, .signUpFlow)
self.didFinishClosure?(self, .emailLoginFlow)
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions Client/Frontend/Settings/AppSettingsOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class ConnectSetting: WithoutAccountSetting {
override var accessibilityIdentifier: String? { return "SignInToSync" }

override func onClick(_ navigationController: UINavigationController?) {
let viewController = FxAWebView(pageType: .emailLoginFlow, profile: profile, dismissalStyle: .popToRootVC)
let viewController = FirefoxAccountSignInViewController(profile: profile, parentType: .settings)
UnifiedTelemetry.recordEvent(category: .firefoxAccount, method: .view, object: .settings)
navigationController?.pushViewController(viewController, animated: true)
}

Expand Down Expand Up @@ -336,8 +337,9 @@ class AccountStatusSetting: WithAccountSetting {

override func onClick(_ navigationController: UINavigationController?) {
guard !profile.rustFxA.accountNeedsReauth() else {
let view = FxAWebView(pageType: .emailLoginFlow, profile: profile, dismissalStyle: .popToRootVC)
navigationController?.pushViewController(view, animated: true)
let vc = FirefoxAccountSignInViewController(profile: profile, parentType: .settings)
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 = FxAWebView(pageType: .settingsPage, profile: profile, dismissalStyle: .popToRootVC)
let viewController = FxAWebViewController(pageType: .settingsPage, profile: profile, dismissalStyle: .popToRootVC)
navigationController?.pushViewController(viewController, animated: true)
}
}
Expand Down Expand Up @@ -56,6 +56,7 @@ class DisconnectSetting: Setting {
alertController.addAction(
UIAlertAction(title: Strings.SettingsDisconnectDestructiveAction, style: .destructive) { (action) in
self.profile.removeAccount()
UnifiedTelemetry.recordEvent(category: .firefoxAccount, method: .settings, object: .accountDisconnected)
LeanPlumClient.shared.set(attributes: [LPAttributeKey.signedInSync: self.profile.hasAccount()])

// If there is more than one view controller in the navigation controller, we can pop.
Expand Down
5 changes: 5 additions & 0 deletions Client/Helpers/DynamicFontHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class DynamicFontHelper: NSObject {
let size = min(deviceFontSize, 18)
return UIFont.boldSystemFont(ofSize: size)
}

var LargeSizeHeavyFontAS: UIFont {
let size = min(deviceFontSize + 2, 20)
return UIFont.systemFont(ofSize: size, weight: UIFont.Weight.heavy)
}

var SmallSizeHeavyWeightAS: UIFont {
let size = min(deviceFontSize, 16)
Expand Down
9 changes: 9 additions & 0 deletions Client/Telemetry/UnifiedTelemetry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ extension UnifiedTelemetry {
case appExtensionAction = "app-extension-action"
case prompt = "prompt"
case enrollment = "enrollment"
case firefoxAccount = "firefox_account"
}

public enum EventMethod: String {
Expand All @@ -173,6 +174,9 @@ extension UnifiedTelemetry {
case translate = "translate"
case view = "view"
case applicationOpenUrl = "application-open-url"
case emailLogin = "email"
case qrPairing = "pairing"
case settings = "settings"
}

public enum EventObject: String {
Expand Down Expand Up @@ -212,6 +216,11 @@ extension UnifiedTelemetry {
case tabToolbar = "tab-toolbar"
case experimentEnrollment = "experiment-enrollment"
case chinaServerSwitch = "china-server-switch"
case accountConnected = "connected"
case accountDisconnected = "disconnected"
case appMenu = "app_menu"
case settings = "settings"
case onboarding = "onboarding"
}

public enum EventValue: String {
Expand Down

0 comments on commit a5b94d1

Please sign in to comment.