Issue #35: Integrate "engine" component.
parent
5392c3aa11
commit
6338501222
@ -0,0 +1,33 @@
|
||||
/* 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 mozilla.fenix.components
|
||||
|
||||
import android.content.Context
|
||||
import mozilla.components.browser.engine.gecko.GeckoEngine
|
||||
import mozilla.components.browser.session.SessionManager
|
||||
import mozilla.components.browser.session.SessionProvider
|
||||
import mozilla.components.concept.engine.Engine
|
||||
import mozilla.components.feature.session.SessionMapping
|
||||
import mozilla.components.feature.session.SessionUseCases
|
||||
import mozilla.fenix.components.session.DefaultSessionProvider
|
||||
import org.mozilla.geckoview.GeckoRuntime
|
||||
import org.mozilla.geckoview.GeckoRuntimeSettings
|
||||
|
||||
/**
|
||||
* Helper class for lazily instantiating components needed by the application.
|
||||
*/
|
||||
class Components(private val applicationContext: Context) {
|
||||
private val geckoRuntime by lazy {
|
||||
val settings = GeckoRuntimeSettings()
|
||||
GeckoRuntime.create(applicationContext, settings)
|
||||
}
|
||||
|
||||
val engine : Engine by lazy { GeckoEngine(geckoRuntime) }
|
||||
|
||||
private val sessionProvider: SessionProvider by lazy { DefaultSessionProvider() }
|
||||
val sessionManager by lazy { SessionManager(sessionProvider) }
|
||||
val sessionMapping by lazy { SessionMapping() }
|
||||
val sessionUseCases by lazy { SessionUseCases(sessionManager, engine, sessionMapping) }
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/* 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 mozilla.fenix.components
|
||||
|
||||
import android.arch.lifecycle.Lifecycle
|
||||
import android.arch.lifecycle.LifecycleObserver
|
||||
import android.arch.lifecycle.OnLifecycleEvent
|
||||
import mozilla.components.feature.session.SessionFeature
|
||||
|
||||
/**
|
||||
* LifecycleObserver implementation that will forward lifecycle callbacks to "feature" components.
|
||||
*/
|
||||
class FeatureLifecycleObserver(
|
||||
private val sessionFeature: SessionFeature
|
||||
): LifecycleObserver {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||
fun startFeatures() {
|
||||
sessionFeature.start()
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
||||
fun stopFeatures() {
|
||||
sessionFeature.stop()
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
/* 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 mozilla.fenix.components.session
|
||||
|
||||
import mozilla.components.browser.session.Session
|
||||
import mozilla.components.browser.session.SessionProvider
|
||||
|
||||
class DefaultSessionProvider: SessionProvider {
|
||||
override fun getInitialSessions(): Pair<List<Session>, Int> {
|
||||
// For now we start with a very simple session provider that will always start with a session
|
||||
// that contains mozilla.org.
|
||||
return Pair(listOf(Session("https://www.mozilla.org")), 0)
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/* 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 mozilla.fenix.ext
|
||||
|
||||
import android.content.Context
|
||||
import mozilla.fenix.components.Components
|
||||
import mozilla.fenix.FenixApplication
|
||||
|
||||
/**
|
||||
* Get the FenixApplication object from a context.
|
||||
*/
|
||||
val Context.application: FenixApplication
|
||||
get() = applicationContext as FenixApplication
|
||||
|
||||
/**
|
||||
* Get the components of this application.
|
||||
*/
|
||||
val Context.components: Components
|
||||
get() = application.components
|
Loading…
Reference in New Issue