Skip to content

Commit 3fd20c1

Browse files
MozLandorocketsrogerMike Taylor
committed
6374: For mozilla-mobile#5866: Don't crash when failed to launch new window request in custom tab r=jonalmeida a=rocketsroger 6387: Fixes mozilla-mobile#6386 - Import v9.0.0 sources r=jonalmeida a=miketaylr mozilla-mobile#6386 https://bugzilla.mozilla.org/show_bug.cgi?id=1624694 Co-authored-by: Roger Yang <[email protected]> Co-authored-by: Mike Taylor <[email protected]>
3 parents 311864c + 90be593 + 03ef464 commit 3fd20c1

File tree

16 files changed

+212
-181
lines changed

16 files changed

+212
-181
lines changed

components/feature/customtabs/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies {
3939
implementation project(':support-ktx')
4040
implementation project(':support-utils')
4141
implementation project(':ui-icons')
42+
implementation project(':lib-crash')
4243

4344
implementation Dependencies.androidx_core_ktx
4445
implementation Dependencies.kotlin_stdlib

components/feature/customtabs/src/main/java/mozilla/components/feature/customtabs/CustomTabWindowFeature.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
package mozilla.components.feature.customtabs
66

77
import android.app.Activity
8+
import android.content.ActivityNotFoundException
89
import androidx.annotation.VisibleForTesting
10+
import androidx.annotation.VisibleForTesting.PRIVATE
911
import androidx.browser.customtabs.CustomTabsIntent
1012
import androidx.core.net.toUri
1113
import kotlinx.coroutines.CoroutineScope
@@ -17,6 +19,7 @@ import mozilla.components.browser.state.selector.findCustomTab
1719
import mozilla.components.browser.state.state.CustomTabConfig
1820
import mozilla.components.browser.state.store.BrowserStore
1921
import mozilla.components.concept.engine.window.WindowRequest
22+
import mozilla.components.lib.crash.CrashReporter
2023
import mozilla.components.lib.state.ext.flowScoped
2124
import mozilla.components.support.base.feature.LifecycleAwareFeature
2225
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifChanged
@@ -29,7 +32,8 @@ const val SHORTCUT_CATEGORY = "mozilla.components.pwa.category.SHORTCUT"
2932
class CustomTabWindowFeature(
3033
private val activity: Activity,
3134
private val store: BrowserStore,
32-
private val sessionId: String
35+
private val sessionId: String,
36+
private val crashReporter: CrashReporter? = null
3337
) : LifecycleAwareFeature {
3438

3539
private var scope: CoroutineScope? = null
@@ -39,7 +43,7 @@ class CustomTabWindowFeature(
3943
* new custom tab with the same styling and layout
4044
*/
4145
@Suppress("ComplexMethod")
42-
@VisibleForTesting
46+
@VisibleForTesting(otherwise = PRIVATE)
4347
internal fun configToIntent(config: CustomTabConfig?): CustomTabsIntent {
4448
val intent = CustomTabsIntent.Builder().apply {
4549
setInstantAppsEnabled(false)
@@ -72,7 +76,11 @@ class CustomTabWindowFeature(
7276
val windowRequest = state.content.windowRequest
7377
if (windowRequest?.type == WindowRequest.Type.OPEN) {
7478
val intent = configToIntent(state.config)
75-
intent.launchUrl(activity, windowRequest.url.toUri())
79+
try {
80+
intent.launchUrl(activity, windowRequest.url.toUri())
81+
} catch (e: ActivityNotFoundException) {
82+
crashReporter?.submitCaughtException(e)
83+
}
7684
store.dispatch(ContentAction.ConsumeWindowRequestAction(sessionId))
7785
}
7886
}

components/feature/customtabs/src/test/java/mozilla/components/feature/customtabs/CustomTabWindowFeatureTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package mozilla.components.feature.customtabs
66

77
import android.app.Activity
8+
import android.content.ActivityNotFoundException
89
import android.graphics.Color
910
import androidx.test.ext.junit.runners.AndroidJUnit4
1011
import kotlinx.coroutines.test.TestCoroutineDispatcher
@@ -16,6 +17,7 @@ import mozilla.components.browser.state.state.CustomTabMenuItem
1617
import mozilla.components.browser.state.state.createCustomTab
1718
import mozilla.components.browser.state.store.BrowserStore
1819
import mozilla.components.concept.engine.window.WindowRequest
20+
import mozilla.components.lib.crash.CrashReporter
1921
import mozilla.components.support.test.any
2022
import mozilla.components.support.test.ext.joinBlocking
2123
import mozilla.components.support.test.mock
@@ -133,4 +135,19 @@ class CustomTabWindowFeatureTest {
133135
private fun assertEqualConfigs(expected: CustomTabConfig, actual: CustomTabConfig) {
134136
assertEquals(expected.copy(id = ""), actual.copy(id = ""))
135137
}
138+
139+
@Test
140+
fun `handles failed request to open window`() {
141+
val crashReporter: CrashReporter = mock()
142+
val feature = CustomTabWindowFeature(activity, store, sessionId, crashReporter)
143+
feature.start()
144+
145+
val windowRequest: WindowRequest = mock()
146+
val exception: ActivityNotFoundException = mock()
147+
whenever(windowRequest.type).thenReturn(WindowRequest.Type.OPEN)
148+
whenever(windowRequest.url).thenReturn("https://www.firefox.com")
149+
whenever(activity.startActivity(any(), any())).thenThrow(exception)
150+
store.dispatch(ContentAction.UpdateWindowRequestAction(sessionId, windowRequest)).joinBlocking()
151+
verify(crashReporter).submitCaughtException(exception)
152+
}
136153
}

components/feature/webcompat/src/main/assets/extensions/webcompat/about-compat/AboutCompat.jsm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ AboutCompat.prototype = {
2727
const channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo);
2828
channel.originalURI = aURI;
2929

30-
channel.owner = (Services.scriptSecurityManager.createContentPrincipal ||
31-
Services.scriptSecurityManager.createCodebasePrincipal)(
32-
uri,
33-
aLoadInfo.originAttributes
34-
);
30+
channel.owner = (
31+
Services.scriptSecurityManager.createContentPrincipal ||
32+
Services.scriptSecurityManager.createCodebasePrincipal
33+
)(uri, aLoadInfo.originAttributes);
3534
return channel;
3635
},
3736
};
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
[{
1+
[
2+
{
23
"namespace": "aboutCompat",
34
"description": "Enables the about:compat page"
4-
}]
5+
}
6+
]

components/feature/webcompat/src/main/assets/extensions/webcompat/data/injections.js

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
/* globals module, require */
88

99
// This is a hack for the tests.
10-
if (typeof getMatchPatternsForGoogleURL === "undefined") {
11-
var getMatchPatternsForGoogleURL = require("../lib/google");
10+
if (typeof InterventionHelpers === "undefined") {
11+
var InterventionHelpers = require("../lib/intervention_helpers");
1212
}
1313

1414
/**
@@ -112,28 +112,37 @@ const AVAILABLE_INJECTIONS = [
112112
},
113113
},
114114
{
115-
id: "bug1577245",
115+
id: "bug1623375",
116116
platform: "android",
117117
domain: "Salesforce communities",
118-
bug: "1577245",
118+
bug: "1623375",
119119
contentScripts: {
120-
matches: [
121-
"https://faq.usps.com/*",
122-
"https://help.duo.com/*",
123-
"https://my211.force.com/*",
124-
"https://support.paypay.ne.jp/*",
125-
"https://usps.force.com/*",
126-
"https://help.twitch.tv/*",
127-
"https://support.sonos.com/*",
128-
"https://us.community.sony.com/*",
129-
"https://help.shopee.ph/*",
130-
"https://exclusions.ustr.gov/*",
131-
"https://help.doordash.com/*",
132-
],
120+
matches: [].concat(
121+
[
122+
"https://faq.usps.com/*",
123+
"https://help.duo.com/*",
124+
"https://my211.force.com/*",
125+
"https://support.paypay.ne.jp/*",
126+
"https://usps.force.com/*",
127+
"https://help.twitch.tv/*",
128+
"https://support.sonos.com/*",
129+
"https://us.community.sony.com/*",
130+
"https://help.shopee.ph/*",
131+
"https://exclusions.ustr.gov/*",
132+
"https://help.doordash.com/*",
133+
"https://community.snowflake.com/*",
134+
"https://tivoidp.tivo.com/*",
135+
],
136+
InterventionHelpers.matchPatternsForTLDs(
137+
"*://support.ancestry.",
138+
"/*",
139+
["ca", "co.uk", "com", "com.au", "de", "fr", "it", "mx", "se"]
140+
)
141+
),
133142
js: [
134143
{
135144
file:
136-
"injections/js/bug1577245-salesforce-communities-hide-unsupported.js",
145+
"injections/js/bug1623375-salesforce-communities-hide-unsupported.js",
137146
},
138147
],
139148
},
@@ -152,20 +161,6 @@ const AVAILABLE_INJECTIONS = [
152161
],
153162
},
154163
},
155-
{
156-
id: "bug1518781",
157-
platform: "desktop",
158-
domain: "twitch.tv",
159-
bug: "1518781",
160-
contentScripts: {
161-
matches: ["*://*.twitch.tv/*"],
162-
css: [
163-
{
164-
file: "injections/css/bug1518781-twitch.tv-webkit-scrollbar.css",
165-
},
166-
],
167-
},
168-
},
169164
{
170165
id: "bug1551672",
171166
platform: "android",
@@ -184,7 +179,6 @@ const AVAILABLE_INJECTIONS = [
184179
bug: "1577870",
185180
data: {
186181
urls: [
187-
"https://*.linkedin.com/tscp-serving/dtag*",
188182
"https://ads-us.rd.linksynergy.com/as.php*",
189183
"https://www.office.com/logout?sid*",
190184
],
@@ -195,21 +189,6 @@ const AVAILABLE_INJECTIONS = [
195189
},
196190
customFunc: "noSniffFix",
197191
},
198-
{
199-
id: "bug1432935-discord",
200-
platform: "desktop",
201-
domain: "discordapp.com",
202-
bug: "1432935",
203-
contentScripts: {
204-
matches: ["*://discordapp.com/*"],
205-
css: [
206-
{
207-
file:
208-
"injections/css/bug1432935-discordapp.com-webkit-scorllbar-white-line.css",
209-
},
210-
],
211-
},
212-
},
213192
{
214193
id: "bug1561371",
215194
platform: "android",
@@ -341,20 +320,6 @@ const AVAILABLE_INJECTIONS = [
341320
],
342321
},
343322
},
344-
{
345-
id: "bug1575017",
346-
platform: "desktop",
347-
domain: "dunkindonuts.com",
348-
bug: "1575017",
349-
contentScripts: {
350-
matches: ["*://*.dunkindonuts.com/en/sign-in*"],
351-
css: [
352-
{
353-
file: "injections/css/bug1575017-dunkindonuts.com-flex-basis.css",
354-
},
355-
],
356-
},
357-
},
358323
{
359324
id: "bug1577270",
360325
platform: "android",
@@ -389,7 +354,10 @@ const AVAILABLE_INJECTIONS = [
389354
domain: "maps.google.com",
390355
bug: "1605611",
391356
contentScripts: {
392-
matches: getMatchPatternsForGoogleURL("www.google", "maps*"),
357+
matches: InterventionHelpers.matchPatternsForGoogle(
358+
"*://www.google.",
359+
"/maps*"
360+
),
393361
css: [
394362
{
395363
file: "injections/css/bug1605611-maps.google.com-directions-time.css",
@@ -459,6 +427,17 @@ const AVAILABLE_INJECTIONS = [
459427
],
460428
},
461429
},
430+
{
431+
id: "bug1622062",
432+
platform: "android",
433+
domain: "$.detectSwipe fix",
434+
bug: "1622062",
435+
data: {
436+
urls: ["https://eu.stemwijzer.nl/public/js/votematch.vendors.js"],
437+
types: ["script"],
438+
},
439+
customFunc: "detectSwipeFix",
440+
},
462441
];
463442

464443
module.exports = AVAILABLE_INJECTIONS;

0 commit comments

Comments
 (0)