Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Use GeckoWebExecutor for FxA Services
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Nov 4, 2019
1 parent 8f26d45 commit 6ef86e1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import org.mozilla.geckoview.AllowOrDeny
import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoSession
import org.mozilla.vrbrowser.R
import org.mozilla.vrbrowser.browser.engine.EngineProvider
import org.mozilla.vrbrowser.browser.engine.GeckoViewFetchClient
import org.mozilla.vrbrowser.browser.engine.SessionStore

class Services(context: Context, places: Places): GeckoSession.NavigationDelegate {
Expand All @@ -44,7 +46,7 @@ class Services(context: Context, places: Places): GeckoSession.NavigationDelegat
// This makes bookmarks storage accessible to background sync workers.
init {
RustLog.enable()
RustHttpConfig.setClient(lazy { HttpURLConnectionClient() })
RustHttpConfig.setClient(lazy { EngineProvider.createClient(context) })

// Make sure we get logs out of our android-components.
Log.addSink(AndroidLogSink())
Expand Down
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,20 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.mozilla.geckoview.ContentBlocking;
import org.mozilla.geckoview.GeckoRuntime;
import org.mozilla.geckoview.GeckoRuntimeSettings;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.WebExtension;
import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.VRBrowserApplication;
import org.mozilla.vrbrowser.browser.BookmarksStore;
import org.mozilla.vrbrowser.browser.HistoryStore;
import org.mozilla.vrbrowser.browser.PermissionDelegate;
import org.mozilla.vrbrowser.browser.Services;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.crashreporting.CrashReporterService;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class SessionStore implements GeckoSession.PermissionDelegate {

private static final String[] WEB_EXTENSIONS = new String[] {
"webcompat_vimeo",
"webcompat_youtube"
};

private static SessionStore mInstance;

public static SessionStore get() {
Expand All @@ -58,48 +46,10 @@ private SessionStore() {
public void setContext(Context context, Bundle aExtras) {
mContext = context;

if (mRuntime == null) {
// FIXME: Once GeckoView has a prefs API
SessionUtils.vrPrefsWorkAround(context, aExtras);

GeckoRuntimeSettings.Builder runtimeSettingsBuilder = new GeckoRuntimeSettings.Builder();
runtimeSettingsBuilder.crashHandler(CrashReporterService.class);
runtimeSettingsBuilder.contentBlocking((new ContentBlocking.Settings.Builder()
.antiTracking(ContentBlocking.AntiTracking.AD | ContentBlocking.AntiTracking.SOCIAL| ContentBlocking.AntiTracking.ANALYTIC))
.build());
runtimeSettingsBuilder.consoleOutput(SettingsStore.getInstance(context).isConsoleLogsEnabled());
runtimeSettingsBuilder.displayDensityOverride(SettingsStore.getInstance(context).getDisplayDensity());
runtimeSettingsBuilder.remoteDebuggingEnabled(SettingsStore.getInstance(context).isRemoteDebuggingEnabled());
runtimeSettingsBuilder.displayDpiOverride(SettingsStore.getInstance(context).getDisplayDpi());
runtimeSettingsBuilder.screenSizeOverride(SettingsStore.getInstance(context).getMaxWindowWidth(),
SettingsStore.getInstance(context).getMaxWindowHeight());
runtimeSettingsBuilder.autoplayDefault(SettingsStore.getInstance(mContext).isAutoplayEnabled() ? GeckoRuntimeSettings.AUTOPLAY_DEFAULT_ALLOWED : GeckoRuntimeSettings.AUTOPLAY_DEFAULT_BLOCKED);

if (SettingsStore.getInstance(context).getTransparentBorderWidth() > 0) {
runtimeSettingsBuilder.useMaxScreenDepth(true);
}

if (BuildConfig.DEBUG) {
runtimeSettingsBuilder.arguments(new String[] { "-purgecaches" });
runtimeSettingsBuilder.debugLogging(true);
runtimeSettingsBuilder.aboutConfigEnabled(true);
} else {
runtimeSettingsBuilder.debugLogging(SettingsStore.getInstance(context).isDebugLogginEnabled());
}

mRuntime = GeckoRuntime.create(context, runtimeSettingsBuilder.build());
for (String extension: WEB_EXTENSIONS) {
String path = "resource://android/assets/web_extensions/" + extension + "/";
mRuntime.registerWebExtension(new WebExtension(path));
}

} else {
mRuntime.attachTo(context);
}
}
mRuntime = EngineProvider.INSTANCE.getOrCreateRuntime(context);

public GeckoRuntime getRuntime() {
return mRuntime;
// FIXME: Once GeckoView has a prefs API
SessionUtils.vrPrefsWorkAround(context, aExtras);
}

public void initializeServices() {
Expand Down

0 comments on commit 6ef86e1

Please sign in to comment.