-
Notifications
You must be signed in to change notification settings - Fork 215
/
EngineProvider.kt
86 lines (66 loc) · 3.18 KB
/
EngineProvider.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.vrbrowser.browser.engine
import android.content.Context
import org.mozilla.geckoview.*
import org.mozilla.vrbrowser.BuildConfig
import org.mozilla.vrbrowser.browser.SettingsStore
import org.mozilla.vrbrowser.crashreporting.CrashReporterService
object EngineProvider {
private val WEB_EXTENSIONS = arrayOf("webcompat_vimeo", "webcompat_youtube")
private var runtime: GeckoRuntime? = null
private var executor: GeckoWebExecutor? = null
private var client: GeckoViewFetchClient? = null
@Synchronized
fun getOrCreateRuntime(context: Context): GeckoRuntime {
if (runtime == null) {
val builder = GeckoRuntimeSettings.Builder()
builder.crashHandler(CrashReporterService::class.java)
builder.contentBlocking(ContentBlocking.Settings.Builder()
.antiTracking(ContentBlocking.AntiTracking.AD or ContentBlocking.AntiTracking.SOCIAL or ContentBlocking.AntiTracking.ANALYTIC)
.build())
builder.consoleOutput(SettingsStore.getInstance(context).isConsoleLogsEnabled)
builder.displayDensityOverride(SettingsStore.getInstance(context).displayDensity)
builder.remoteDebuggingEnabled(SettingsStore.getInstance(context).isRemoteDebuggingEnabled)
builder.displayDpiOverride(SettingsStore.getInstance(context).displayDpi)
builder.screenSizeOverride(SettingsStore.getInstance(context).maxWindowWidth,
SettingsStore.getInstance(context).maxWindowHeight)
builder.useMultiprocess(true)
if (SettingsStore.getInstance(context).transparentBorderWidth > 0) {
builder.useMaxScreenDepth(true)
}
if (BuildConfig.DEBUG) {
builder.arguments(arrayOf("-purgecaches"))
builder.debugLogging(true)
builder.aboutConfigEnabled(true)
} else {
builder.debugLogging(SettingsStore.getInstance(context).isDebugLoggingEnabled)
}
runtime = GeckoRuntime.create(context, builder.build())
for (extension in WEB_EXTENSIONS) {
val path = "resource://android/assets/web_extensions/$extension/"
runtime!!.registerWebExtension(WebExtension(path, runtime!!.webExtensionController))
}
}
return runtime!!
}
fun createGeckoWebExecutor(context: Context): GeckoWebExecutor {
return GeckoWebExecutor(getOrCreateRuntime(context))
}
fun getDefaultGeckoWebExecutor(context: Context): GeckoWebExecutor {
if (executor == null) {
executor = createGeckoWebExecutor(context)
}
return executor!!
}
fun createClient(context: Context): GeckoViewFetchClient {
return GeckoViewFetchClient(context)
}
fun getDefaultClient(context: Context): GeckoViewFetchClient {
if (client == null) {
client = createClient(context)
}
return client!!
}
}