This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use GeckoWebExecutor for FxA Services
- Loading branch information
Showing
3 changed files
with
74 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/common/shared/org/mozilla/vrbrowser/browser/engine/EngineProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* 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 mozilla.components.concept.fetch.Client | ||
import org.mozilla.geckoview.ContentBlocking | ||
import org.mozilla.geckoview.GeckoRuntime | ||
import org.mozilla.geckoview.GeckoRuntimeSettings | ||
import org.mozilla.geckoview.WebExtension | ||
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 | ||
|
||
@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.autoplayDefault(if (SettingsStore.getInstance(context).isAutoplayEnabled) GeckoRuntimeSettings.AUTOPLAY_DEFAULT_ALLOWED else GeckoRuntimeSettings.AUTOPLAY_DEFAULT_BLOCKED) | ||
|
||
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).isDebugLogginEnabled) | ||
} | ||
|
||
runtime = GeckoRuntime.create(context, builder.build()) | ||
for (extension in WEB_EXTENSIONS) { | ||
val path = "resource://android/assets/web_extensions/$extension/" | ||
runtime!!.registerWebExtension(WebExtension(path)) | ||
} | ||
|
||
|
||
} | ||
|
||
return runtime!! | ||
} | ||
|
||
fun createClient(context: Context): Client { | ||
val runtime = getOrCreateRuntime(context) | ||
return GeckoViewFetchClient(context, runtime) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters