-
Notifications
You must be signed in to change notification settings - Fork 215
/
EngineProvider.kt
94 lines (75 loc) · 3.52 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
87
88
89
90
91
92
93
94
/* 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.ContentBlocking
import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.GeckoRuntimeSettings
import org.mozilla.geckoview.GeckoWebExecutor
import org.mozilla.vrbrowser.BuildConfig
import org.mozilla.vrbrowser.browser.SettingsStore
import org.mozilla.vrbrowser.browser.content.TrackingProtectionPolicy
import org.mozilla.vrbrowser.browser.content.TrackingProtectionStore
import org.mozilla.vrbrowser.crashreporting.CrashReporterService
object EngineProvider {
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()
val policy : TrackingProtectionPolicy = TrackingProtectionStore.getTrackingProtectionPolicy(context);
builder.crashHandler(CrashReporterService::class.java)
builder.contentBlocking(ContentBlocking.Settings.Builder()
.antiTracking(policy.antiTrackingPolicy)
.enhancedTrackingProtectionLevel(SettingsStore.getInstance(context).trackingProtectionLevel)
.build())
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)
builder.inputAutoZoomEnabled(false)
builder.doubleTapZoomingEnabled(false)
builder.debugLogging(SettingsStore.getInstance(context).isDebugLoggingEnabled)
builder.consoleOutput(SettingsStore.getInstance(context).isDebugLoggingEnabled)
if (SettingsStore.getInstance(context).transparentBorderWidth > 0) {
builder.useMaxScreenDepth(true)
}
if (BuildConfig.DEBUG) {
builder.arguments(arrayOf("-purgecaches"))
builder.aboutConfigEnabled(true)
}
runtime = GeckoRuntime.create(context, builder.build())
}
return runtime!!
}
@Synchronized
fun isRuntimeCreated(): Boolean {
return runtime != null
}
private fun createGeckoWebExecutor(context: Context): GeckoWebExecutor {
return GeckoWebExecutor(getOrCreateRuntime(context))
}
fun getDefaultGeckoWebExecutor(context: Context): GeckoWebExecutor {
if (executor == null) {
executor = createGeckoWebExecutor(context)
client?.let { it.executor = executor }
}
return executor!!
}
fun createClient(context: Context): GeckoViewFetchClient {
val client = GeckoViewFetchClient(context)
client.executor = executor
return client
}
fun getDefaultClient(context: Context): GeckoViewFetchClient {
if (client == null) {
client = createClient(context)
}
return client!!
}
}