Commit 176d6a25 authored by ekager's avatar ekager
Browse files

For #6757 - Adds firstContentfulPaint callback and var to session

parent df2b7c35
......@@ -7,6 +7,7 @@ package mozilla.components.browser.engine.gecko
import android.content.Context
import android.graphics.Bitmap
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting
import androidx.core.view.ViewCompat
......@@ -67,6 +68,10 @@ class GeckoEngineView @JvmOverloads constructor(
rebind()
}
override fun onFirstContentfulPaint() {
visibility = View.VISIBLE
}
override fun onAppPermissionRequest(permissionRequest: PermissionRequest) = Unit
override fun onContentPermissionRequest(permissionRequest: PermissionRequest) = Unit
}
......
......@@ -600,6 +600,7 @@ class GeckoEngineSession(
override fun onFirstContentfulPaint(session: GeckoSession) {
firstContentfulPaint = true
notifyObservers { onFirstContentfulPaint() }
}
override fun onContextMenu(
......
......@@ -7,6 +7,7 @@ package mozilla.components.browser.engine.gecko
import android.content.Context
import android.graphics.Bitmap
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting
import androidx.core.view.ViewCompat
......@@ -67,6 +68,10 @@ class GeckoEngineView @JvmOverloads constructor(
rebind()
}
override fun onFirstContentfulPaint() {
visibility = View.VISIBLE
}
override fun onAppPermissionRequest(permissionRequest: PermissionRequest) = Unit
override fun onContentPermissionRequest(permissionRequest: PermissionRequest) = Unit
}
......
......@@ -7,6 +7,7 @@ package mozilla.components.browser.engine.gecko
import android.content.Context
import android.graphics.Bitmap
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.VisibleForTesting
import androidx.core.view.ViewCompat
......@@ -67,6 +68,10 @@ class GeckoEngineView @JvmOverloads constructor(
rebind()
}
override fun onFirstContentfulPaint() {
visibility = View.VISIBLE
}
override fun onAppPermissionRequest(permissionRequest: PermissionRequest) = Unit
override fun onContentPermissionRequest(permissionRequest: PermissionRequest) = Unit
}
......
......@@ -46,6 +46,10 @@ internal class EngineObserver(
session.searchTerms = ""
}
override fun onFirstContentfulPaint() {
store?.dispatch(ContentAction.UpdateFirstContentfulPaintStateAction(session.id, true))
}
override fun onLocationChange(url: String) {
if (!isUrlSame(session.url, url)) {
session.title = ""
......
......@@ -500,6 +500,20 @@ class EngineObserverTest {
))
}
@Test
fun engineObserverHandlesFirstContentfulPaint() {
val session = Session("")
val store = mock(BrowserStore::class.java)
whenever(store.state).thenReturn(mock())
val observer = EngineObserver(session, store)
observer.onFirstContentfulPaint()
verify(store).dispatch(ContentAction.UpdateFirstContentfulPaintStateAction(
session.id,
true
))
}
@Test
fun `onMediaAdded will subscribe to media and add it to store`() {
val store = BrowserStore()
......
......@@ -266,6 +266,14 @@ sealed class ContentAction : BrowserAction() {
*/
data class UpdateBackNavigationStateAction(val sessionId: String, val canGoBack: Boolean) : ContentAction()
/**
* Updates the [ContentState] of the given [sessionId] to indicate whether the first contentful paint has happened.
*/
data class UpdateFirstContentfulPaintStateAction(
val sessionId: String,
val firstContentfulPaint: Boolean
) : ContentAction()
/**
* Updates the [ContentState] of the given [sessionId] to indicate whether or not a forward navigation is possible.
*/
......
......@@ -117,6 +117,9 @@ internal object ContentStateReducer {
is ContentAction.RemoveWebAppManifestAction -> updateContentState(state, action.sessionId) {
it.copy(webAppManifest = null)
}
is ContentAction.UpdateFirstContentfulPaintStateAction -> updateContentState(state, action.sessionId) {
it.copy(firstContentfulPaint = action.firstContentfulPaint)
}
}
}
}
......
......@@ -39,6 +39,7 @@ import mozilla.components.concept.engine.window.WindowRequest
* @property canGoBack whether or not there's an history item to navigate back to.
* @property canGoForward whether or not there's an history item to navigate forward to.
* @property webAppManifest the Web App Manifest for the currently visited page (or null).
* @property firstContentfulPaint whether or not the first contentful paint has happened.
*/
data class ContentState(
val url: String,
......@@ -60,5 +61,6 @@ data class ContentState(
val layoutInDisplayCutoutMode: Int = 0,
val canGoBack: Boolean = false,
val canGoForward: Boolean = false,
val webAppManifest: WebAppManifest? = null
val webAppManifest: WebAppManifest? = null,
val firstContentfulPaint: Boolean = false
)
......@@ -49,6 +49,10 @@ abstract class EngineSession(
*/
fun onExcludedOnTrackingProtectionChange(excluded: Boolean) = Unit
/**
* Event to indicate that this session has had it's first engine contentful paint of page content.
*/
fun onFirstContentfulPaint() = Unit
fun onLongPress(hitResult: HitResult) = Unit
fun onDesktopModeChange(enabled: Boolean) = Unit
fun onFind(text: String) = Unit
......
......@@ -12,6 +12,9 @@ permalink: /changelog/
* [Gecko](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Gecko.kt)
* [Configuration](https://github.com/mozilla-mobile/android-components/blob/master/buildSrc/src/main/java/Config.kt)
* **browser-state**
* Adds `firstContentfulPaint` to `ContentState` to know if first contentful paint has happened.
* **service-glean**
* ⚠️ **This is a breaking change**: Glean's configuration now requires explicitly setting an http client. Users need to pass one at construction.
A default `lib-fetch-httpurlconnection` implementation is available.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment