-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Connect SDK] Add support for non-http/https pop-ups (ex. mailto) (#9679
) * Add pop-up supoort # Conflicts: # connect/src/main/java/com/stripe/android/connect/webview/StripeConnectWebViewContainerController.kt # Conflicts: # connect/src/main/java/com/stripe/android/connect/webview/StripeConnectWebViewContainer.kt # connect/src/main/java/com/stripe/android/connect/webview/StripeConnectWebViewContainerController.kt * Fix lint * Make class internal * Add tests, add intent interface * Cleanup merge conflicts * Update function with todos * Fix tests * PR feedback * PR feedback in Android * Add pop-up supoort # Conflicts: # connect/src/main/java/com/stripe/android/connect/webview/StripeConnectWebViewClient.kt * Fix lint * Add tests, add intent interface * Add initial mailto/non-https support * Fix merge conflicts * Fixup launcher * Delete unneeded web chrome client * Fix/add tests * Move to string res * Fix test
- Loading branch information
1 parent
7b8f59a
commit cb051e9
Showing
7 changed files
with
80 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 47 additions & 1 deletion
48
connect/src/main/java/com/stripe/android/connect/webview/StripeIntentLauncher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,65 @@ | ||
package com.stripe.android.connect.webview | ||
|
||
import android.content.ActivityNotFoundException | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import androidx.browser.customtabs.CustomTabsIntent | ||
import com.stripe.android.connect.R | ||
import com.stripe.android.core.BuildConfig | ||
import com.stripe.android.core.Logger | ||
|
||
internal interface StripeIntentLauncher { | ||
/** | ||
* Launches [uri] in a secure external Android Custom Tab. | ||
*/ | ||
fun launchSecureExternalWebTab(context: Context, uri: Uri) | ||
|
||
/** | ||
* Launches a uri with a mailto scheme. | ||
*/ | ||
fun launchEmailLink(context: Context, uri: Uri) | ||
|
||
/** | ||
* Launches [uri] with the system handler, allowing the system to choose how to open it. | ||
*/ | ||
fun launchUrlWithSystemHandler(context: Context, uri: Uri) | ||
} | ||
|
||
internal class StripeIntentLauncherImpl : StripeIntentLauncher { | ||
internal class StripeIntentLauncherImpl( | ||
private val toastManagerImpl: StripeToastManagerImpl = StripeToastManagerImpl(), | ||
private val logger: Logger = Logger.getInstance(enableLogging = BuildConfig.DEBUG) | ||
) : StripeIntentLauncher { | ||
|
||
override fun launchSecureExternalWebTab(context: Context, uri: Uri) { | ||
val customTabsIntent = CustomTabsIntent.Builder().build() | ||
customTabsIntent.launchUrl(context, uri) | ||
} | ||
|
||
override fun launchUrlWithSystemHandler(context: Context, uri: Uri) { | ||
val intent = Intent(Intent.ACTION_VIEW, uri).apply { | ||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
} | ||
|
||
try { | ||
context.startActivity(intent) | ||
} catch (e: ActivityNotFoundException) { | ||
logger.error("Failed to open URL with system handler: ${e.message}") | ||
toastManagerImpl.showToast(context, context.getString(R.string.stripe_failed_to_open_url, uri.toString())) | ||
} | ||
} | ||
|
||
override fun launchEmailLink(context: Context, uri: Uri) { | ||
val intent = Intent(Intent.ACTION_SENDTO, uri).apply { | ||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
} | ||
|
||
try { | ||
context.startActivity(intent) | ||
} catch (e: ActivityNotFoundException) { | ||
// log an error and fall back to a generic system handler | ||
logger.error("Failed to open URL with email handler: ${e.message}") | ||
launchUrlWithSystemHandler(context, uri) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters