forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#35: Integrate "engine" component.
- Loading branch information
Showing
9 changed files
with
142 additions
and
17 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) } | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/mozilla/fenix/components/FeatureLifecycleObserver.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,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() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/mozilla/fenix/components/session/DefaultSessionProvider.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,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) | ||
} | ||
} |
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,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 |
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