Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
android-components
Commits
788c945b
Commit
788c945b
authored
Jul 11, 2019
by
James Hugman
Committed by
jhugman
Jul 11, 2019
Browse files
Fixes #3725 - Intercept app-links with whitelisted schemes
parent
471f0cde
Changes
3
Hide whitespace changes
Inline
Side-by-side
components/feature/app-links/src/main/java/mozilla/components/feature/app/links/AppLinksFeature.kt
View file @
788c945b
...
...
@@ -40,7 +40,8 @@ class AppLinksFeature(
private
val
context
:
Context
,
private
val
sessionManager
:
SessionManager
,
private
val
sessionId
:
String
?
=
null
,
private
val
interceptLinkClicks
:
Boolean
=
true
,
private
val
interceptLinkClicks
:
Boolean
=
false
,
private
val
whitelistedSchemes
:
Set
<
String
>
=
setOf
(
"mailto"
,
"market"
,
"sms"
,
"tel"
),
private
val
fragmentManager
:
FragmentManager
?
=
null
,
private
var
dialog
:
RedirectDialogFragment
=
SimpleRedirectDialogFragment
.
newInstance
(),
private
val
useCases
:
AppLinksUseCases
=
AppLinksUseCases
(
context
)
...
...
@@ -62,7 +63,7 @@ class AppLinksFeature(
* Starts observing app links on the selected session.
*/
override
fun
start
()
{
if
(
interceptLinkClicks
)
{
if
(
interceptLinkClicks
||
whitelistedSchemes
.
isNotEmpty
()
)
{
observer
.
observeIdOrSelected
(
sessionId
)
}
findPreviousDialogFragment
()
?.
let
{
...
...
@@ -71,7 +72,7 @@ class AppLinksFeature(
}
override
fun
stop
()
{
if
(
interceptLinkClicks
)
{
if
(
interceptLinkClicks
||
whitelistedSchemes
.
isNotEmpty
()
)
{
observer
.
stop
()
}
}
...
...
@@ -97,6 +98,12 @@ class AppLinksFeature(
return
}
redirect
.
appIntent
?.
data
?.
scheme
?.
let
{
if
(!
interceptLinkClicks
&&
!
whitelistedSchemes
.
contains
(
it
))
{
return
}
}
val
doOpenApp
=
{
useCases
.
openAppLink
(
redirect
)
}
...
...
components/feature/app-links/src/test/java/mozilla/components/feature/app/links/AppLinksFeatureTest.kt
View file @
788c945b
...
...
@@ -93,7 +93,8 @@ class AppLinksFeatureTest {
mockContext
,
mockSessionManager
,
useCases
=
mockUseCases
,
interceptLinkClicks
=
false
interceptLinkClicks
=
false
,
whitelistedSchemes
=
setOf
()
)
subject
.
start
()
...
...
@@ -118,6 +119,28 @@ class AppLinksFeatureTest {
verifyNoMoreInteractions
(
mockOpenRedirect
)
}
@Test
fun
`it
tests
for
whitelisted
schemes
links
when
triggered
by
user
clicking
on
a
link`
()
{
val
whitelistedScheme
=
"whitelisted"
val
session
=
createSession
(
false
)
val
subject
=
AppLinksFeature
(
mockContext
,
mockSessionManager
,
interceptLinkClicks
=
false
,
whitelistedSchemes
=
setOf
(
whitelistedScheme
),
useCases
=
mockUseCases
)
val
url
=
"$whitelistedScheme://example.com"
val
whitelistedRedirect
=
AppLinkRedirect
(
Intent
.
parseUri
(
url
,
0
),
url
,
false
)
`when`
(
mockGetRedirect
.
invoke
(
url
)).
thenReturn
(
whitelistedRedirect
)
subject
.
handleLoadRequest
(
session
,
url
,
true
)
verify
(
mockGetRedirect
).
invoke
(
url
)
verify
(
mockOpenRedirect
).
invoke
(
whitelistedRedirect
)
}
@Test
fun
`when
valid
sessionId
is
provided
,
observe
its
session`
()
{
feature
=
AppLinksFeature
(
...
...
@@ -147,6 +170,21 @@ class AppLinksFeatureTest {
verify
(
mockSessionManager
).
register
(
feature
.
observer
)
}
@Test
fun
`when
a
whitelist
of
schemes
is
provided
,
observe
the
selected
session`
()
{
feature
=
AppLinksFeature
(
mockContext
,
sessionManager
=
mockSessionManager
,
useCases
=
mockUseCases
,
interceptLinkClicks
=
false
,
whitelistedSchemes
=
setOf
(
"whitelisted"
)
)
feature
.
start
()
verify
(
mockSessionManager
).
register
(
feature
.
observer
)
}
@Test
fun
`when
start
is
called
must
register
SessionManager
observers`
()
{
feature
.
start
()
...
...
docs/changelog.md
View file @
788c945b
...
...
@@ -18,6 +18,9 @@ permalink: /changelog/
*
**feature-downloads**
*
Added custom notification icon for
`FetchDownloadManager`
.
*
**feature-app-links**
*
Added whitelist for schemes of URLs to open with an external app. This defaults to
`mailto`
,
`market`
,
`sms`
and
`tel`
.
*
**feature-accounts**
*
⚠️
**This is a breaking change**
: Public API for interacting with
`FxaAccountManager`
and sync changes
*
`FxaAccountManager`
now has a new, simplified public API.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment