Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Applications
fenix
Commits
2d873071
Commit
2d873071
authored
Feb 18, 2021
by
Christian Sadilek
Browse files
Remove remaining usages of Session[Manager] in BrowserFragment
parent
c9b8f57f
Changes
5
Show whitespace changes
Inline
Side-by-side
app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt
View file @
2d873071
...
...
@@ -38,13 +38,15 @@ import kotlinx.coroutines.flow.mapNotNull
import
kotlinx.coroutines.launch
import
kotlinx.coroutines.withContext
import
mozilla.appservices.places.BookmarkRoot
import
mozilla.components.browser.session.Session
import
mozilla.components.browser.state.action.ContentAction
import
mozilla.components.browser.state.selector.findCustomTab
import
mozilla.components.browser.state.selector.findCustomTabOrSelectedTab
import
mozilla.components.browser.state.selector.findTab
import
mozilla.components.browser.state.selector.findTabOrCustomTab
import
mozilla.components.browser.state.selector.findTabOrCustomTabOrSelectedTab
import
mozilla.components.browser.state.selector.getNormalOrPrivateTabs
import
mozilla.components.browser.state.selector.selectedTab
import
mozilla.components.browser.state.state.CustomTabSessionState
import
mozilla.components.browser.state.state.SessionState
import
mozilla.components.browser.state.state.TabSessionState
import
mozilla.components.browser.state.state.content.DownloadState
...
...
@@ -254,7 +256,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
@CallSuper
internal
open
fun
initializeUI
(
view
:
View
,
tab
:
SessionState
)
{
val
context
=
requireContext
()
val
sessionManager
=
context
.
components
.
core
.
sessionManager
val
store
=
context
.
components
.
core
.
store
val
activity
=
requireActivity
()
as
HomeActivity
...
...
@@ -350,7 +351,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
container
=
view
.
browserLayout
,
toolbarPosition
=
context
.
settings
().
toolbarPosition
,
interactor
=
browserInteractor
,
customTabSession
=
customTabSessionId
?.
let
{
s
essionManager
.
findSessionById
(
it
)
},
customTabSession
=
customTabSessionId
?.
let
{
s
tore
.
state
.
findCustomTab
(
it
)
},
lifecycleOwner
=
viewLifecycleOwner
)
...
...
@@ -551,7 +552,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
val
directions
=
NavGraphDirections
.
actionGlobalShareFragment
(
data
=
arrayOf
(
shareData
),
showPage
=
true
,
sessionId
=
get
SessionById
()
?.
id
sessionId
=
get
CurrentTab
()
?.
id
)
findNavController
().
navigate
(
directions
)
}
...
...
@@ -585,14 +586,14 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
searchFeature
.
set
(
feature
=
SearchFeature
(
store
,
customTabSessionId
)
{
request
,
tabId
->
val
parentSession
=
s
essionManager
.
findSessionById
(
tabId
)
val
parentSession
=
s
tore
.
state
.
findTabOrCustomTab
(
tabId
)
val
useCase
=
if
(
request
.
isPrivate
)
{
requireComponents
.
useCases
.
searchUseCases
.
newPrivateTabSearch
}
else
{
requireComponents
.
useCases
.
searchUseCases
.
newTabSearch
}
if
(
parentSession
?.
isCustomTabSession
()
==
tru
e
)
{
if
(
parentSession
is
CustomTabSession
Stat
e
)
{
useCase
.
invoke
(
request
.
query
)
requireActivity
().
startActivity
(
openInFenixIntent
)
}
else
{
...
...
@@ -1016,7 +1017,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
final
override
fun
onViewStateRestored
(
savedInstanceState
:
Bundle
?)
{
super
.
onViewStateRestored
(
savedInstanceState
)
savedInstanceState
?.
getString
(
KEY_CUSTOM_TAB_SESSION_ID
)
?.
let
{
if
(
requireComponents
.
core
.
s
essionManager
.
findSessionById
(
it
)
?.
c
ustomTab
Config
!=
null
)
{
if
(
requireComponents
.
core
.
s
tore
.
state
.
findC
ustomTab
(
it
)
!=
null
)
{
customTabSessionId
=
it
}
}
...
...
@@ -1054,22 +1055,18 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
* or if it has a parent session and no more history
*/
protected
open
fun
removeSessionIfNeeded
():
Boolean
{
get
SessionById
()
?.
let
{
session
->
get
CurrentTab
()
?.
let
{
session
->
return
if
(
session
.
source
==
SessionState
.
Source
.
ACTION_VIEW
)
{
activity
?.
finish
()
requireComponents
.
useCases
.
tabsUseCases
.
removeTab
(
session
.
id
)
true
}
else
{
if
(
session
.
hasParentSession
)
{
// The removeTab use case does not currently select a parent session, so
// we are using sessionManager.remove
requireComponents
.
core
.
sessionManager
.
remove
(
session
,
selectParentIfExists
=
true
)
val
hasParentSession
=
session
is
TabSessionState
&&
session
.
parentId
!=
null
if
(
hasParentSession
)
{
requireComponents
.
useCases
.
tabsUseCases
.
removeTab
(
session
.
id
,
selectParentIfExists
=
true
)
}
// We want to return to home if this session didn't have a parent session to select.
val
goToOverview
=
!
session
.
hasParentSession
val
goToOverview
=
!
hasParentSession
!
goToOverview
}
}
...
...
@@ -1134,19 +1131,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
(
activity
as
HomeActivity
).
browsingModeManager
.
mode
=
sessionMode
}
/**
* Returns the current session.
*/
protected
fun
getSessionById
():
Session
?
{
val
sessionManager
=
requireComponents
.
core
.
sessionManager
val
localCustomTabId
=
customTabSessionId
return
if
(
localCustomTabId
!=
null
)
{
sessionManager
.
findSessionById
(
localCustomTabId
)
}
else
{
sessionManager
.
selectedSession
}
}
@VisibleForTesting
internal
fun
getCurrentTab
():
SessionState
?
{
return
requireComponents
.
core
.
store
.
state
.
findCustomTabOrSelectedTab
(
customTabSessionId
)
...
...
app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
View file @
2d873071
...
...
@@ -84,7 +84,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
visible
=
{
readerModeAvailable
},
selected
=
get
SessionById
()
?.
let
{
selected
=
get
CurrentTab
()
?.
let
{
activity
?.
components
?.
core
?.
store
?.
state
?.
findTab
(
it
.
id
)
?.
readerState
?.
active
}
?:
false
,
listener
=
browserInteractor
::
onReaderModePressed
...
...
app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt
View file @
2d873071
...
...
@@ -16,8 +16,8 @@ import androidx.lifecycle.LifecycleOwner
import
kotlinx.android.extensions.LayoutContainer
import
kotlinx.coroutines.ExperimentalCoroutinesApi
import
mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
import
mozilla.components.browser.session.Session
import
mozilla.components.browser.state.selector.selectedTab
import
mozilla.components.browser.state.state.CustomTabSessionState
import
mozilla.components.browser.state.state.ExternalAppType
import
mozilla.components.browser.toolbar.BrowserToolbar
import
mozilla.components.browser.toolbar.behavior.BrowserToolbarBehavior
...
...
@@ -52,7 +52,7 @@ class BrowserToolbarView(
private
val
container
:
ViewGroup
,
private
val
toolbarPosition
:
ToolbarPosition
,
private
val
interactor
:
BrowserToolbarViewInteractor
,
private
val
customTabSession
:
Session
?,
private
val
customTabSession
:
CustomTab
Session
State
?,
private
val
lifecycleOwner
:
LifecycleOwner
)
:
LayoutContainer
{
...
...
@@ -78,8 +78,8 @@ class BrowserToolbarView(
@VisibleForTesting
internal
val
isPwaTabOrTwaTab
:
Boolean
get
()
=
customTabSession
?.
c
ustomTabC
onfig
?.
externalAppType
==
ExternalAppType
.
PROGRESSIVE_WEB_APP
||
customTabSession
?.
c
ustomTabC
onfig
?.
externalAppType
==
ExternalAppType
.
TRUSTED_WEB_ACTIVITY
get
()
=
customTabSession
?.
config
?.
externalAppType
==
ExternalAppType
.
PROGRESSIVE_WEB_APP
||
customTabSession
?.
config
?.
externalAppType
==
ExternalAppType
.
TRUSTED_WEB_ACTIVITY
init
{
val
isCustomTabSession
=
customTabSession
!=
null
...
...
@@ -185,7 +185,7 @@ class BrowserToolbarView(
view
,
menuToolbar
,
customTabSession
.
id
,
isPrivate
=
customTabSession
.
private
isPrivate
=
customTabSession
.
content
.
private
)
}
else
{
DefaultToolbarIntegration
(
...
...
app/src/main/java/org/mozilla/fenix/utils/ToolbarPopupWindow.kt
View file @
2d873071
...
...
@@ -15,8 +15,8 @@ import androidx.annotation.VisibleForTesting
import
androidx.core.view.isVisible
import
com.google.android.material.snackbar.Snackbar
import
kotlinx.android.synthetic.main.browser_toolbar_popup_window.view.*
import
mozilla.components.browser.session.Session
import
mozilla.components.browser.state.selector.selectedTab
import
mozilla.components.browser.state.state.CustomTabSessionState
import
mozilla.components.browser.state.store.BrowserStore
import
org.mozilla.fenix.R
import
org.mozilla.fenix.components.FenixSnackbar
...
...
@@ -27,7 +27,7 @@ import java.lang.ref.WeakReference
object
ToolbarPopupWindow
{
fun
show
(
view
:
WeakReference
<
View
>,
customTabSession
:
Session
?
=
null
,
customTabSession
:
CustomTab
Session
State
?
=
null
,
handlePasteAndGo
:
(
String
)
->
Unit
,
handlePaste
:
(
String
)
->
Unit
,
copyVisible
:
Boolean
=
true
...
...
@@ -101,10 +101,10 @@ object ToolbarPopupWindow {
@VisibleForTesting
internal
fun
getUrlForClipboard
(
store
:
BrowserStore
,
customTabSession
:
Session
?
=
null
customTabSession
:
CustomTab
Session
State
?
=
null
):
String
?
{
return
if
(
customTabSession
!=
null
)
{
customTabSession
.
url
customTabSession
.
content
.
url
}
else
{
val
selectedTab
=
store
.
state
.
selectedTab
selectedTab
?.
readerState
?.
activeUrl
?:
selectedTab
?.
content
?.
url
...
...
app/src/test/java/org/mozilla/fenix/utils/ToolbarPopupWindowTest.kt
View file @
2d873071
...
...
@@ -4,11 +4,10 @@
package
org.mozilla.fenix.utils
import
io.mockk.every
import
io.mockk.mockk
import
mozilla.components.browser.session.Session
import
mozilla.components.browser.state.state.BrowserState
import
mozilla.components.browser.state.state.ReaderState
import
mozilla.components.browser.state.state.createCustomTab
import
mozilla.components.browser.state.state.createTab
import
mozilla.components.browser.state.store.BrowserStore
import
org.junit.Assert.assertEquals
...
...
@@ -21,8 +20,7 @@ class ToolbarPopupWindowTest {
@Test
fun
getUrlForClipboard
()
{
val
customTabSession
:
Session
=
mockk
()
every
{
customTabSession
.
url
}
returns
"https://mozilla.org"
val
customTabSession
=
createCustomTab
(
"https://mozilla.org"
)
// Custom tab
assertEquals
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment