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.
AC WebExtensions + WebCompat + FxAWebChannels
- Loading branch information
Showing
31 changed files
with
1,252 additions
and
106 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
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
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
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
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
77 changes: 77 additions & 0 deletions
77
app/src/common/shared/org/mozilla/vrbrowser/browser/adapter/ComponentsAdapter.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,77 @@ | ||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | ||
* 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.adapter | ||
|
||
import mozilla.components.browser.state.action.EngineAction | ||
import mozilla.components.browser.state.action.TabListAction | ||
import mozilla.components.browser.state.state.ContentState | ||
import mozilla.components.browser.state.state.EngineState | ||
import mozilla.components.browser.state.state.ReaderState | ||
import mozilla.components.browser.state.state.TabSessionState | ||
import mozilla.components.browser.state.store.BrowserStore | ||
import org.mozilla.geckoview.GeckoSession | ||
import org.mozilla.vrbrowser.browser.components.GeckoEngineSession | ||
import org.mozilla.vrbrowser.browser.engine.Session | ||
|
||
class ComponentsAdapter private constructor( | ||
val store: BrowserStore = BrowserStore() | ||
) { | ||
companion object { | ||
private val instance: ComponentsAdapter = ComponentsAdapter() | ||
|
||
@JvmStatic | ||
fun get(): ComponentsAdapter = instance | ||
} | ||
|
||
fun addSession(session: Session) { | ||
store.dispatch(TabListAction.AddTabAction( | ||
tab = session.toTabSessionState() | ||
)) | ||
} | ||
|
||
fun removeSession(id: String) { | ||
store.dispatch(TabListAction.RemoveTabAction( | ||
tabId = id | ||
)) | ||
} | ||
|
||
fun selectSession(session: Session) { | ||
store.dispatch(TabListAction.SelectTabAction( | ||
tabId = session.id | ||
)) | ||
} | ||
|
||
fun link(tabId: String, geckoSession: GeckoSession) { | ||
store.dispatch(EngineAction.LinkEngineSessionAction( | ||
tabId, | ||
GeckoEngineSession(geckoSession) | ||
)) | ||
} | ||
|
||
fun unlink(tabId: String) { | ||
store.dispatch(EngineAction.UnlinkEngineSessionAction( | ||
tabId | ||
)) | ||
} | ||
} | ||
|
||
private fun Session.toTabSessionState(): TabSessionState { | ||
return TabSessionState( | ||
id = id, | ||
content = ContentState( | ||
url = currentUri, | ||
private = isPrivateMode, | ||
title = currentTitle | ||
), | ||
parentId = null, | ||
extensionState = emptyMap(), | ||
readerState = ReaderState(), | ||
engineState = EngineState( | ||
GeckoEngineSession(geckoSession), | ||
null | ||
) | ||
) | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/common/shared/org/mozilla/vrbrowser/browser/components/GeckoEngineSession.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,45 @@ | ||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | ||
* 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.components | ||
|
||
import mozilla.components.concept.engine.EngineSession | ||
import mozilla.components.concept.engine.EngineSessionState | ||
import mozilla.components.concept.engine.Settings | ||
import org.json.JSONObject | ||
import org.mozilla.geckoview.GeckoSession | ||
import org.mozilla.vrbrowser.browser.engine.SessionStore | ||
|
||
class GeckoEngineSession( | ||
val geckoSession: GeckoSession | ||
): EngineSession() { | ||
constructor() : | ||
this(SessionStore.get().createSession(false, false).geckoSession) | ||
|
||
override fun loadUrl(url: String, parent: EngineSession?, flags: LoadUrlFlags, additionalHeaders: Map<String, String>?) { | ||
geckoSession.loadUri(url) | ||
} | ||
|
||
override val settings: Settings = object : Settings() {} | ||
override fun clearFindMatches() = Unit | ||
override fun disableTrackingProtection() = Unit | ||
override fun enableTrackingProtection(policy: TrackingProtectionPolicy) = Unit | ||
override fun exitFullScreenMode() = Unit | ||
override fun findAll(text: String) = Unit | ||
override fun findNext(forward: Boolean) = Unit | ||
override fun goBack() = Unit | ||
override fun goForward() = Unit | ||
override fun loadData(data: String, mimeType: String, encoding: String) = Unit | ||
override fun recoverFromCrash(): Boolean = true | ||
override fun reload() = Unit | ||
override fun restoreState(state: EngineSessionState) = true | ||
override fun saveState(): EngineSessionState = DummyEngineSessionState() | ||
override fun stopLoading() = Unit | ||
override fun toggleDesktopMode(enable: Boolean, reload: Boolean) = Unit | ||
} | ||
|
||
private class DummyEngineSessionState : EngineSessionState { | ||
override fun toJSON(): JSONObject = JSONObject() | ||
} |
71 changes: 71 additions & 0 deletions
71
app/src/common/shared/org/mozilla/vrbrowser/browser/components/GeckoResult.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,71 @@ | ||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- | ||
* 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.components | ||
|
||
import kotlinx.coroutines.CompletableDeferred | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.CoroutineStart | ||
import kotlinx.coroutines.Deferred | ||
import kotlinx.coroutines.launch | ||
import mozilla.components.concept.engine.CancellableOperation | ||
import org.mozilla.geckoview.GeckoResult | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.resumeWithException | ||
import kotlin.coroutines.suspendCoroutine | ||
|
||
/** | ||
* Wait for a GeckoResult to be complete in a co-routine. | ||
*/ | ||
suspend fun <T> GeckoResult<T>.await() = suspendCoroutine<T?> { continuation -> | ||
then({ | ||
continuation.resume(it) | ||
GeckoResult<Void>() | ||
}, { | ||
continuation.resumeWithException(it) | ||
GeckoResult<Void>() | ||
}) | ||
} | ||
|
||
/** | ||
* Converts a [GeckoResult] to a [CancellableOperation]. | ||
*/ | ||
fun <T> GeckoResult<T>.asCancellableOperation(): CancellableOperation { | ||
val geckoResult = this | ||
return object : CancellableOperation { | ||
override fun cancel(): Deferred<Boolean> { | ||
val result = CompletableDeferred<Boolean>() | ||
geckoResult.cancel().then({ | ||
result.complete(it ?: false) | ||
GeckoResult<Void>() | ||
}, { throwable -> | ||
result.completeExceptionally(throwable) | ||
GeckoResult<Void>() | ||
}) | ||
return result | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Create a GeckoResult from a co-routine. | ||
*/ | ||
@Suppress("TooGenericExceptionCaught") | ||
fun <T> CoroutineScope.launchGeckoResult( | ||
context: CoroutineContext = EmptyCoroutineContext, | ||
start: CoroutineStart = CoroutineStart.DEFAULT, | ||
block: suspend CoroutineScope.() -> T | ||
) = GeckoResult<T>().apply { | ||
launch(context, start) { | ||
try { | ||
val value = block() | ||
complete(value) | ||
} catch (exception: Throwable) { | ||
completeExceptionally(exception) | ||
} | ||
} | ||
} |
Oops, something went wrong.