This repository was archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Closes #2267 AC WebExtensions + WebCompat + FxAWebChannels #3498
Merged
bluemarvin
merged 2 commits into
MozillaReality:master
from
keianhzo:v11/fxa_webchannels
Jun 23, 2020
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
|
keianhzo marked this conversation as resolved.
|
||
| } | ||
|
|
||
| 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 hidden or 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 | ||
|
keianhzo marked this conversation as resolved.
|
||
|
|
||
| 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) | ||
|
keianhzo marked this conversation as resolved.
|
||
|
|
||
| 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.