Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge #4276 #4281 #4294
Browse files Browse the repository at this point in the history
4276: Add blog posting explaining browser-state plans. [ci skip] r=csadilek,Amejia481 a=pocmo

I wanted to write this blog posting for quite a while. There's much more to say but this can be follow-up postings. :)

4281: Move intent related code from browser-session to feature-intent. r=csadilek a=pocmo

In preparation for #4279 and #4257. :)



4294: Issue #4284: Add DownloadState to browser-state. r=csadilek a=pocmo

First steps for #4284. State is not synchronized between `browser-state` and `browser-session` yet. I need to figure out how to deal with the `Consumable<Download>`in `Session`. We already did that when we prototyped this earlier this year. I think that's the reason we introduced `Consumable.onConsume`.



Co-authored-by: Sebastian Kaspari <s.kaspari@gmail.com>
  • Loading branch information
MozLando and pocmo committed Sep 3, 2019
4 parents 648ed1c + 5dc78f6 + 75986cc + 49f0532 commit 4acb705
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 389 deletions.
Expand Up @@ -12,6 +12,7 @@ import mozilla.components.browser.state.state.SecurityInfoState
import mozilla.components.browser.state.state.SessionState
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.state.TrackingProtectionState
import mozilla.components.browser.state.state.content.DownloadState
import mozilla.components.concept.engine.content.blocking.Tracker
import mozilla.components.lib.state.Action

Expand Down Expand Up @@ -166,6 +167,16 @@ sealed class ContentAction : BrowserAction() {
* Updates the thumbnail of the [ContentState] with the given [sessionId].
*/
data class UpdateThumbnailAction(val sessionId: String, val thumbnail: Bitmap) : ContentAction()

/**
* Updates the [DownloadState] of the [ContentState] with the given [sessionId].
*/
data class UpdateDownloadAction(val sessionId: String, val download: DownloadState) : ContentAction()

/**
* Removes the [DownloadState] of the [ContentState] with the given [sessionId].
*/
data class ConsumeDownloadAction(val sessionId: String, val download: DownloadState) : ContentAction()
}

/**
Expand Down
Expand Up @@ -45,6 +45,16 @@ internal object ContentStateReducer {
is ContentAction.UpdateThumbnailAction -> updateContentState(state, action.sessionId) {
it.copy(thumbnail = action.thumbnail)
}
is ContentAction.UpdateDownloadAction -> updateContentState(state, action.sessionId) {
it.copy(download = action.download)
}
is ContentAction.ConsumeDownloadAction -> updateContentState(state, action.sessionId) {
if (action.download == it.download) {
it.copy(download = null)
} else {
it
}
}
}
}
}
Expand Down
Expand Up @@ -5,6 +5,7 @@
package mozilla.components.browser.state.state

import android.graphics.Bitmap
import mozilla.components.browser.state.state.content.DownloadState

/**
* Value type that represents the state of the content within a [SessionState].
Expand All @@ -21,6 +22,7 @@ import android.graphics.Bitmap
* @property thumbnail the last generated [Bitmap] of this session's content, to
* be used as a preview in e.g. a tab switcher.
* @property icon the icon of the page currently loaded by this session.
* @property download Last unhandled download request.
*/
data class ContentState(
val url: String,
Expand All @@ -31,5 +33,6 @@ data class ContentState(
val searchTerms: String = "",
val securityInfo: SecurityInfoState = SecurityInfoState(),
val thumbnail: Bitmap? = null,
val icon: Bitmap? = null
val icon: Bitmap? = null,
val download: DownloadState? = null
)
@@ -0,0 +1,28 @@
/* 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.components.browser.state.state.content

import android.os.Environment

/**
* Value type that represents a download request.
*
* @property url The full url to the content that should be downloaded.
* @property fileName A canonical filename for this download.
* @property contentType Content type (MIME type) to indicate the media type of the download.
* @property contentLength The file size reported by the server.
* @property userAgent The user agent to be used for the download.
* @property destinationDirectory The matching destination directory for this type of download.
* @property referrerUrl The site that linked to this download.
*/
data class DownloadState(
val url: String,
val fileName: String? = null,
val contentType: String? = null,
val contentLength: Long? = null,
val userAgent: String? = null,
val destinationDirectory: String = Environment.DIRECTORY_DOWNLOADS,
val referrerUrl: String? = null
)
Expand Up @@ -9,10 +9,12 @@ import mozilla.components.browser.state.selector.findCustomTab
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.SecurityInfoState
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.state.content.DownloadState
import mozilla.components.browser.state.state.createCustomTab
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.test.ext.joinBlocking
import mozilla.components.support.test.mock
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotEquals
Expand Down Expand Up @@ -251,4 +253,42 @@ class ContentActionTest {
assertNotEquals("I am a custom tab", tab.content.title)
assertNotEquals("I am a custom tab", otherTab.content.title)
}

@Test
fun `UpdateDownloadAction updates download`() {
assertNull(tab.content.download)

val download1: DownloadState = mock()

store.dispatch(
ContentAction.UpdateDownloadAction(tab.id, download1)
).joinBlocking()

assertEquals(download1, tab.content.download)

val download2: DownloadState = mock()

store.dispatch(
ContentAction.UpdateDownloadAction(tab.id, download2)
).joinBlocking()

assertEquals(download2, tab.content.download)
}

@Test
fun `ConsumeDownloadAction removes download`() {
val download: DownloadState = mock()

store.dispatch(
ContentAction.UpdateDownloadAction(tab.id, download)
).joinBlocking()

assertEquals(download, tab.content.download)

store.dispatch(
ContentAction.ConsumeDownloadAction(tab.id, download)
).joinBlocking()

assertNull(tab.content.download)
}
}
1 change: 1 addition & 0 deletions components/feature/customtabs/build.gradle
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation project(':concept-engine')
implementation project(':concept-fetch')
implementation project(':feature-session')
implementation project(':feature-intent')
implementation project(':support-base')
implementation project(':support-ktx')
implementation project(':support-utils')
Expand Down
Expand Up @@ -9,9 +9,9 @@ import android.content.Intent.ACTION_VIEW
import android.content.res.Resources
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.intent.IntentProcessor
import mozilla.components.browser.session.intent.putSessionId
import mozilla.components.concept.engine.EngineSession
import mozilla.components.feature.intent.ext.putSessionId
import mozilla.components.feature.intent.processing.IntentProcessor
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.support.utils.SafeIntent
import mozilla.components.support.utils.toSafeIntent
Expand Down
Expand Up @@ -12,10 +12,10 @@ import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.Session.Source
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.intent.EXTRA_SESSION_ID
import mozilla.components.concept.engine.Engine
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags
import mozilla.components.feature.intent.ext.EXTRA_SESSION_ID
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.support.test.any
import mozilla.components.support.test.mock
Expand Down
1 change: 0 additions & 1 deletion components/feature/intent/build.gradle
Expand Up @@ -26,7 +26,6 @@ android {
dependencies {
implementation project(':concept-engine')
implementation project(':browser-session')
implementation project(':feature-customtabs')
implementation project(':feature-search')
implementation project(':feature-session')
implementation project(':support-utils')
Expand Down

This file was deleted.

Expand Up @@ -2,7 +2,7 @@
* 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.components.browser.session.intent
package mozilla.components.feature.intent.ext

import android.content.Intent
import mozilla.components.support.utils.SafeIntent
Expand Down
Expand Up @@ -2,7 +2,7 @@
* 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.components.browser.session.intent
package mozilla.components.feature.intent.processing

import android.content.Intent

Expand Down
Expand Up @@ -2,7 +2,7 @@
* 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.components.feature.intent
package mozilla.components.feature.intent.processing

import android.content.Intent
import android.content.Intent.ACTION_SEND
Expand All @@ -11,7 +11,6 @@ import android.content.Intent.EXTRA_TEXT
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.Session.Source
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.intent.IntentProcessor
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags
import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
Expand Down

0 comments on commit 4acb705

Please sign in to comment.