New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1317580 - Add additional deeplink support for FxA #2249

Merged
merged 4 commits into from Dec 13, 2016
Jump to file or symbol
Failed to load files and symbols.
+47 −5
Diff settings

Always

Just for now

@@ -257,9 +257,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
log.warning("Cannot handle \(components.scheme) URL scheme")
return false
}
// Extract optional FxA deep-linking options
let fxaQuery = url.getQuery()
let fxaParams: FxALaunchParams
fxaParams = FxALaunchParams(view: fxaQuery["fxa"], email: fxaQuery["email"], access_code: fxaQuery["access_code"])

This comment has been minimized.

@st3fan

st3fan Dec 13, 2016

Contributor

Will this crash if fxaQuery does not contain any of those fields?

This comment has been minimized.

@st3fan

st3fan Dec 13, 2016

Contributor

(Not sure if looking up an non existent entry will abort/crash or not)

This comment has been minimized.

@vbudhram

vbudhram Dec 13, 2016

Collaborator

Hey @st3fan, It doesn't appear so. I opened the following deep links in safari and got the following results. These seem to be correct.

  • firefox://?fxa=signin&email=test@email.com

Launches FxiOS, opens the FxA Content View Controller and prefills email.

  • firefox://?fxa=signin

Launches FxiOS, opens the FxA Content View Controller

  • firefox://

Launches FxiOS

This comment has been minimized.

@farhanpatel

farhanpatel Dec 13, 2016

Contributor

Yea it should be fine 👍 You've declared the launch params as optional so it shouldn't crash. They are allowed to be nil

if fxaParams.view != nil {
launchFxAFromURL(fxaParams)
return true
}
var url: String?
var isPrivate: Bool = false
for item in (components.queryItems ?? []) as [NSURLQueryItem] {
switch item.name {
case "url":
@@ -269,7 +280,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
default: ()
}
}
let params: LaunchParams
if let url = url, newURL = NSURL(string: url) {
@@ -288,6 +299,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}
func launchFxAFromURL(params: FxALaunchParams) {
guard params.view != nil else {
return
}
self.browserViewController.presentSignInViewController(params)
}
func launchFromURL(params: LaunchParams) {
let isPrivate = params.isPrivate ?? false
@@ -611,6 +629,12 @@ extension AppDelegate: MFMailComposeViewControllerDelegate {
}
}
struct FxALaunchParams {
var view: String?
var email: String?
var access_code: String?
}
struct LaunchParams {
let url: NSURL?
let isPrivate: Bool?
@@ -1968,11 +1968,13 @@ extension BrowserViewController: HomePanelViewControllerDelegate {
}
func homePanelViewControllerDidRequestToCreateAccount(homePanelViewController: HomePanelViewController) {
presentSignInViewController() // TODO UX Right now the flow for sign in and create account is the same
let fxaOptions = FxALaunchParams(view: "signup", email: nil, access_code: nil)
presentSignInViewController(fxaOptions) // TODO UX Right now the flow for sign in and create account is the same
}
func homePanelViewControllerDidRequestToSignIn(homePanelViewController: HomePanelViewController) {
presentSignInViewController() // TODO UX Right now the flow for sign in and create account is the same
let fxaOptions = FxALaunchParams(view: "signin", email: nil, access_code: nil)
presentSignInViewController(fxaOptions) // TODO UX Right now the flow for sign in and create account is the same
}
func homePanelViewControllerDidRequestToOpenInNewTab(url: NSURL, isPrivate: Bool) {
@@ -2837,7 +2839,7 @@ extension BrowserViewController: IntroViewControllerDelegate {
}
}
func presentSignInViewController() {
func presentSignInViewController(fxaOptions: FxALaunchParams) {
// Show the settings page if we have already signed in. If we haven't then show the signin page
let vcToPresent: UIViewController
if profile.hasAccount() {
@@ -2849,6 +2851,7 @@ extension BrowserViewController: IntroViewControllerDelegate {
let signInVC = FxAContentViewController()
signInVC.delegate = self
signInVC.url = profile.accountConfiguration.signInURL
signInVC.fxaOptions = fxaOptions
signInVC.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: #selector(BrowserViewController.dismissSignInViewController))
vcToPresent = signInVC
}
@@ -2864,7 +2867,8 @@ extension BrowserViewController: IntroViewControllerDelegate {
func introViewControllerDidRequestToLogin(introViewController: IntroViewController) {
introViewController.dismissViewControllerAnimated(true, completion: { () -> Void in
self.presentSignInViewController()
let fxaOptions = FxALaunchParams(view: "signup", email: nil, access_code: nil)
self.presentSignInViewController(fxaOptions)
})
}
}
@@ -22,6 +22,8 @@ protocol FxAContentViewControllerDelegate: class {
* fxa-content-server git repository.
*/
class FxAContentViewController: SettingsContentViewController, WKScriptMessageHandler {
var fxaOptions = FxALaunchParams()
private enum RemoteCommand: String {
case CanLinkAccount = "can_link_account"
case Loaded = "loaded"
@@ -112,6 +114,18 @@ class FxAContentViewController: SettingsContentViewController, WKScriptMessageHa
self.timer?.invalidate()
self.timer = nil
self.isLoaded = true
fillField("email", value: self.fxaOptions.email)
fillField("access_code", value: self.fxaOptions.access_code)
}
// Attempt to fill out a field in content view
private func fillField(className: String?, value: String?){
guard let name = className, let val = value else {
return
}
let script = "$('.\(name)').val('\(val)');";
webView.evaluateJavaScript(script, completionHandler: nil)
}
// Handle a message coming from the content server.
ProTip! Use n and p to navigate between commits in a pull request.