Files
tubestation/mobile/android/android-components/components/browser/engine-system
Sebastian Kaspari 7647c16b8f [components] Refactor EngineSessionHolder to keep a reference to an EngineSession or EngineSessionState.
The main change here is that EngineSessionHolder can now hold an EngineState and this state
is used when we need to create an EngineSession (which will clear the state). This has the
following advantages:

* When restoring we can just attach the EngineState and do not need to create the
  EngineSession immediately. With that we do not load all the EngineSessions and everything
  at once. Initially only the selected EngineSession will be created and loaded. That will
  make the restore faster and use less resources when restoring a lot of sessions.

* (Not in this commit, for a follow-up) It allows us to close EngineSession instances and
  just keep the EngineState around until we need the EngineSession again. That's something
  we could do in low memory situations or when there are just too many sessions/tabs open
  to be performant (e.g. only keep the last recently used EngineSession instances around).
2018-12-19 11:30:07 +01:00
..

Android Components > Browser > Engine-System

Engine implementation based on the system's WebView.

Usage

See concept-engine for a documentation of the abstract engine API this component implements.

Setting up the dependency

Use Gradle to download the library from maven.mozilla.org (Setup repository):

implementation "org.mozilla.components:browser-engine-system:{latest-version}"

Initializing

It is recommended t create only one SystemEngine instance per app.

// Create default settings (optional) and enable tracking protection for all future sessions.
val defaultSettings = DefaultSettings().apply {
    trackingProtectionPolicy = EngineSession.TrackingProtectionPolicy.all()
}

// Create an engine instance to be used by other components.
val engine = SystemEngine(defaultSettings)

Integration

Usually it is not needed to interact with the Engine component directly. The browser-session component will take care of making the state accessible and link a Session to an EngineSession internally. The feature-session component will provide "use cases" to perform actions like loading URLs and takes care of rendering the selected Session on an EngineView.

View

SystemEngineView is the Gecko-based implementation of EngineView in order to render web content.

<mozilla.components.browser.engine.system.SystemEngineView
    android:id="@+id/engineView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

SystemEngineView can render any SystemEngineSession using the render() method.

val engineSession = engine.createSession()
val engineView = view.findViewById<SystemEngineView>(R.id.engineView)
engineView.render(engineSession)

License

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/