Skip to content

Commit

Permalink
EngineViewPresenter: Only subscribe to SessionManager if not tracking…
Browse files Browse the repository at this point in the history
… a fixed session.

This fixes the following reference browser issue:
mozilla-mobile/reference-browser#534

Related to mozilla-mobile#1943
  • Loading branch information
pocmo committed Feb 6, 2019
1 parent f7a7acf commit dc2525c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Expand Up @@ -24,19 +24,20 @@ class EngineViewPresenter(
val session = if (sessionId != null) {
sessionManager.findSessionById(sessionId)
} else {
sessionManager.register(this)
sessionManager.selectedSession
}

session?.let { renderSession(it) }

sessionManager.register(this)
}

/**
* Stop presenter from updating view.
*/
fun stop() {
sessionManager.unregister(this)
if (sessionId == null) {
sessionManager.unregister(this)
}
}

/**
Expand Down
Expand Up @@ -10,6 +10,7 @@ import mozilla.components.concept.engine.EngineView
import org.junit.Test
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.verify

Expand Down Expand Up @@ -46,4 +47,17 @@ class EngineViewPresenterTest {
engineViewPresenter.stop()
verify(sessionManager).unregister(engineViewPresenter)
}

@Test
fun `Presenter does not register or unregister if presenting fixed session`() {
val sessionId = "just-a-test"

val engineViewPresenter = EngineViewPresenter(sessionManager, engineView, sessionId)

engineViewPresenter.start()
verify(sessionManager, never()).register(engineViewPresenter)

engineViewPresenter.stop()
verify(sessionManager, never()).unregister(engineViewPresenter)
}
}
11 changes: 11 additions & 0 deletions docs/changelog.md
Expand Up @@ -13,6 +13,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)

* **feature-session**
* Fixed an issue causing `EngineViewPresenter` to render a selected `Session` even though it was configured to show a fixed `Session`. This issue caused a crash (`IllegalStateException: Display already acquired`) in the [Reference Browser](https://github.com/mozilla-mobile/reference-browser) when a "Custom Tab" and the "Browser" tried to render the same `Session`.

# 0.41.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v0.40.0...v0.41.0)
Expand All @@ -30,6 +33,7 @@ permalink: /changelog/

* **feature-browser**
* Added `BrowserToolbar` attributes to color the menu.

```xml
<mozilla.components.browser.toolbar.BrowserToolbar
android:id="@+id/toolbar"
Expand All @@ -50,6 +54,7 @@ permalink: /changelog/
* **feature-downloads**
* ⚠️ **This is a breaking API change!**
* The required permissions are now passed to the `onNeedToRequestPermissions` callback.

```kotlin
downloadsFeature = DownloadsFeature(
requireContext(),
Expand All @@ -60,20 +65,24 @@ permalink: /changelog/
}
)
```

* Removed the `onPermissionsGranted` method in favour of `onPermissionsResult` which handles both granted and denied permissions. This method should be invoked from `onRequestPermissionsResult`:

```kotlin
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
when (requestCode) {
REQUEST_CODE_DOWNLOAD_PERMISSIONS -> downloadsFeature.onPermissionsResult(permissions, grantResults)
}
}
```

* Fixed Downloads feature to work with Custom Tabs by passing in the session ID when applicable.

* **feature-prompts**
* ⚠️ **This is a breaking API change!**
* These change are similar to the ones for feature-downloads above and aim to provide a consistent way of handling permission requests.
* The required permissions are now passed to the `onNeedToRequestPermissions` callback.

```kotlin
promptFeature = PromptFeature(
fragment = this,
Expand All @@ -84,7 +93,9 @@ permalink: /changelog/
}
)
```

* Renamed `onRequestsPermissionsResult` to `onPermissionResult` and allow applications to specify the permission request code. This method should be invoked from `onRequestPermissionsResult`:

```kotlin
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
when (requestCode) {
Expand Down

0 comments on commit dc2525c

Please sign in to comment.