Skip to content

Commit

Permalink
Issue mozilla-mobile#1063: EngineView: Remove lifecycle extension met…
Browse files Browse the repository at this point in the history
…hods and replace with upstream implementation.
  • Loading branch information
pocmo committed Sep 10, 2018
1 parent 58273bb commit 4204beb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import android.view.View
import android.webkit.WebView
import mozilla.components.concept.engine.EngineView
import org.mozilla.focus.R
import org.mozilla.focus.ext.destroy
import org.mozilla.focus.ext.onStart
import org.mozilla.focus.ext.onStop
import org.mozilla.focus.ext.pauseTimers
import org.mozilla.focus.ext.resumeTimers
import org.mozilla.focus.locale.LocaleAwareFragment
import org.mozilla.focus.locale.LocaleManager
import java.util.Locale
Expand Down Expand Up @@ -51,24 +46,30 @@ abstract class EngineViewLifecycleFragment : LocaleAwareFragment() {

open fun onWebViewCreated(webView: EngineView) = Unit

override fun onPause() {
webView!!.pauseTimers()
super.onPause()
}

override fun onResume() {
webView!!.resumeTimers()
super.onResume()
}

override fun onStop() {
super.onStop()
webView!!.onStop() // internally calls WebView.onPause: see impl for details.

// NB: onStop unexpectedly calls onPause: see below.
//
// When the user says "Alexa pause [the video]", the Activity will be paused/resumed while
// Alexa handles the request. If the WebView is paused during video playback, the video will
// have poor behavior (on YouTube the screen goes black, may rebuffer, and may lose the voice
// command). Unfortunately, there does not appear to be any way to prevent this other than
// to not call WebView.onPause so we pause the WebView later, here in onStop, when it isn't
// affected by Alexa voice commands. Luckily, Alexa pauses the video for us. afaict, on
// Fire TV, `onPause` without `onStop` isn't called very often so I don't think there will
// be many side effects (#936).
//
// The problem is not reproducible when onPause is called here, even if pauseTimers is
// called in onPause.
webView!!.onPause() // internally calls WebView.onPause: see impl for details.
}

override fun onStart() {
super.onStart()
webView!!.onStart() // internally calls WebView.onResume: see impl for details.

// NB: onStart unexpectedly calls onResume: see onStop for details.
onResume()
}

override fun onDestroy() {
Expand All @@ -82,7 +83,7 @@ abstract class EngineViewLifecycleFragment : LocaleAwareFragment() {
//
// Note: Focus does this null check too.
if (webView != null) {
webView!!.destroy()
webView!!.onDestroy()
webView = null
}
}
Expand Down
30 changes: 0 additions & 30 deletions app/src/main/java/org/mozilla/focus/ext/EngineView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,36 +156,6 @@ fun EngineView.scrollByClamped(vx: Int, vy: Int) {
}
}

/**
* Forwarding lifecycle method to WebView.
*
* Component upstream issue:
* https://github.com/mozilla-mobile/android-components/issues/657
*/
fun EngineView.pauseTimers() = webView.pauseTimers()
fun EngineView.resumeTimers() = webView.resumeTimers()
fun EngineView.onStop() = webView.apply {
// NB: onStop unexpectedly calls onPause: see below.
//
// When the user says "Alexa pause [the video]", the Activity will be paused/resumed while
// Alexa handles the request. If the WebView is paused during video playback, the video will
// have poor behavior (on YouTube the screen goes black, may rebuffer, and may lose the voice
// command). Unfortunately, there does not appear to be any way to prevent this other than
// to not call WebView.onPause so we pause the WebView later, here in onStop, when it isn't
// affected by Alexa voice commands. Luckily, Alexa pauses the video for us. afaict, on
// Fire TV, `onPause` without `onStop` isn't called very often so I don't think there will
// be many side effects (#936).
//
// The problem is not reproducible when onPause is called here, even if pauseTimers is
// called in onPause.
onPause()
}
fun EngineView.onStart() = webView.apply {
// NB: onStart unexpectedly calls onResume: see onStop for details.
onResume()
}
fun EngineView.destroy() = webView.destroy()

val EngineView.focusedDOMElement: FocusedDOMElementCache
get() = getOrPutExtension(this).domElementCache

Expand Down

0 comments on commit 4204beb

Please sign in to comment.