Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit 188c140

Browse files
committed
Issue #1303: Move CustomTabService to new feature component: feature-customtabs.
1 parent ae0b2d9 commit 188c140

File tree

9 files changed

+158
-36
lines changed

9 files changed

+158
-36
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ _Combined components to implement feature-specific use cases._
9797

9898
*[**Awesomebar**](components/feature/awesomebar/README.md) - A component that connects a [concept-awesomebar](components/concept/awesomebar/README.md) implementation to a [concept-toolbar](components/concept/toolbar/README.md) implementation and provides implementations of various suggestion providers.
9999

100+
* 🔴 [**Custom Tabs**](components/feature/customtabs/README.md) - A component for providing [Custom Tabs](https://developer.chrome.com/multidevice/android/customtabs) functionality in browsers.
101+
100102
*[**Downloads**](components/feature/downloads/README.md) - A component to perform downloads using the [Android downloads manager](https://developer.android.com/reference/android/app/DownloadManager).
101103

102104
* 🔴 [**Intent**](components/feature/intent/README.md) - A component that provides intent processing functionality by combining various other feature modules.

components/browser/session/src/main/java/mozilla/components/browser/session/tab/CustomTabsService.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# [Android Components](../../../README.md) > Feature > Custom Tabs
2+
3+
A component for providing [Custom Tabs](https://developer.chrome.com/multidevice/android/customtabs) functionality in browsers.
4+
5+
## Usage
6+
7+
### Setting up the dependency
8+
9+
Use Gradle to download the library from [maven.mozilla.org](https://maven.mozilla.org/) ([Setup repository](../../../README.md#maven-repository)):
10+
11+
```Groovy
12+
implementation "org.mozilla.components:feature-customtabs:{latest-version}"
13+
```
14+
15+
## License
16+
17+
This Source Code Form is subject to the terms of the Mozilla Public
18+
License, v. 2.0. If a copy of the MPL was not distributed with this
19+
file, You can obtain one at http://mozilla.org/MPL/2.0/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
apply plugin: 'com.android.library'
6+
apply plugin: 'kotlin-android'
7+
8+
android {
9+
compileSdkVersion Config.compileSdkVersion
10+
11+
defaultConfig {
12+
minSdkVersion Config.minSdkVersion
13+
targetSdkVersion Config.targetSdkVersion
14+
}
15+
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
}
23+
24+
dependencies {
25+
implementation Deps.kotlin_stdlib
26+
27+
implementation Deps.support_customtabs
28+
29+
testImplementation project(':support-test')
30+
31+
testImplementation Deps.testing_junit
32+
testImplementation Deps.testing_robolectric
33+
testImplementation Deps.testing_mockito
34+
}
35+
36+
apply from: '../../../publish.gradle'
37+
ext.configurePublish(Config.componentsGroupId, archivesBaseName, gradle.componentDescriptions[archivesBaseName])
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- This Source Code Form is subject to the terms of the Mozilla Public
2+
- License, v. 2.0. If a copy of the MPL was not distributed with this
3+
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
4+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
5+
package="mozilla.components.feature.customtabs" />
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
package mozilla.components.feature.customtabs
6+
7+
import android.app.Service
8+
import android.net.Uri
9+
import android.os.Bundle
10+
import android.support.customtabs.CustomTabsSessionToken
11+
12+
/**
13+
* [Service] providing Custom Tabs related functionality.
14+
*/
15+
class CustomTabsService : android.support.customtabs.CustomTabsService() {
16+
override fun warmup(flags: Long): Boolean {
17+
return true
18+
}
19+
20+
override fun requestPostMessageChannel(sessionToken: CustomTabsSessionToken?, postMessageOrigin: Uri?): Boolean {
21+
return false
22+
}
23+
24+
override fun newSession(sessionToken: CustomTabsSessionToken?): Boolean {
25+
return true
26+
}
27+
28+
override fun extraCommand(commandName: String?, args: Bundle?): Bundle? {
29+
return null
30+
}
31+
32+
override fun mayLaunchUrl(
33+
sessionToken: CustomTabsSessionToken?,
34+
url: Uri?,
35+
extras: Bundle?,
36+
otherLikelyBundles: MutableList<Bundle>?
37+
): Boolean {
38+
return true
39+
}
40+
41+
override fun postMessage(sessionToken: CustomTabsSessionToken?, message: String?, extras: Bundle?): Int {
42+
return 0
43+
}
44+
45+
override fun validateRelationship(
46+
sessionToken: CustomTabsSessionToken?,
47+
relation: Int,
48+
origin: Uri?,
49+
extras: Bundle?
50+
): Boolean {
51+
return false
52+
}
53+
54+
override fun updateVisuals(sessionToken: CustomTabsSessionToken?, bundle: Bundle?): Boolean {
55+
return false
56+
}
57+
}
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ package mozilla.components.browser.session.tab
77
import android.content.Intent
88
import android.net.Uri
99
import android.os.Bundle
10+
import android.os.IBinder
1011
import android.support.customtabs.ICustomTabsCallback
1112
import android.support.customtabs.ICustomTabsService
13+
import mozilla.components.feature.customtabs.CustomTabsService
14+
import mozilla.components.support.test.mock
1215
import org.junit.Assert.assertEquals
1316
import org.junit.Assert.assertFalse
1417
import org.junit.Assert.assertNotNull
1518
import org.junit.Assert.assertNull
1619
import org.junit.Assert.assertTrue
1720
import org.junit.Test
1821
import org.junit.runner.RunWith
22+
import org.mockito.Mockito.doReturn
1923
import org.mockito.Mockito.mock
2024
import org.robolectric.RobolectricTestRunner
2125

@@ -29,20 +33,24 @@ class CustomTabsServiceTest {
2933
assertNotNull(customTabsServiceStub)
3034

3135
val stub = customTabsServiceStub as ICustomTabsService.Stub
36+
37+
val callback = mock(ICustomTabsCallback::class.java)
38+
doReturn(mock<IBinder>()).`when`(callback).asBinder()
39+
3240
assertTrue(stub.warmup(123))
33-
assertTrue(stub.newSession(mock(ICustomTabsCallback::class.java)))
41+
assertTrue(stub.newSession(callback))
3442
assertNull(stub.extraCommand("", mock(Bundle::class.java)))
3543
assertFalse(stub.updateVisuals(mock(ICustomTabsCallback::class.java), mock(Bundle::class.java)))
3644
assertFalse(stub.requestPostMessageChannel(mock(ICustomTabsCallback::class.java), mock(Uri::class.java)))
3745
assertEquals(0, stub.postMessage(mock(ICustomTabsCallback::class.java), "", mock(Bundle::class.java)))
3846
assertFalse(stub.validateRelationship(
39-
mock(ICustomTabsCallback::class.java),
40-
0,
41-
mock(Uri::class.java),
42-
mock(Bundle::class.java)))
47+
mock(ICustomTabsCallback::class.java),
48+
0,
49+
mock(Uri::class.java),
50+
mock(Bundle::class.java)))
4351
assertTrue(stub.mayLaunchUrl(
44-
mock(ICustomTabsCallback::class.java),
45-
mock(Uri::class.java),
46-
mock(Bundle::class.java), emptyList<Bundle>()))
52+
mock(ICustomTabsCallback::class.java),
53+
mock(Uri::class.java),
54+
mock(Bundle::class.java), emptyList<Bundle>()))
4755
}
4856
}

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ setupProject(':concept-storage', 'components/concept/storage', 'An abstract defi
4040
////////////////////////////////////////////////////////////////////////////////////////////////////
4141

4242
setupProject(':feature-awesomebar', 'components/feature/awesomebar', 'Component connecting a concept-toolbar with a concept-awesomebar.')
43+
setupProject(':feature-customtabs', 'components/feature/customtabs', 'Component for providing custom tabs functionality.')
4344
setupProject(':feature-intent', 'components/feature/intent', 'Combining various feature components for intent processing.')
4445
setupProject(':feature-search', 'components/feature/search', 'Feature implementation connecting an engine implementation with the search module.')
4546
setupProject(':feature-session', 'components/feature/session', 'Feature implementation connecting an engine implementation with the session module.')

0 commit comments

Comments
 (0)