mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] Improve loading URLs
This commit is contained in:
parent
798c9bc294
commit
4cc4e1c67d
@ -8,6 +8,8 @@ import androidx.annotation.VisibleForTesting
|
||||
import androidx.annotation.VisibleForTesting.PRIVATE
|
||||
import androidx.navigation.NavController
|
||||
import mozilla.appservices.places.BookmarkRoot
|
||||
import mozilla.components.concept.engine.EngineSession
|
||||
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags.Companion.ALLOW_JAVASCRIPT_URL
|
||||
import mozilla.components.concept.storage.BookmarkNode
|
||||
import org.mozilla.fenix.BrowserDirection
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
@ -47,7 +49,8 @@ class DefaultRecentBookmarksController(
|
||||
activity.openToBrowserAndLoad(
|
||||
searchTermOrURL = bookmark.url!!,
|
||||
newTab = true,
|
||||
from = BrowserDirection.FromHome
|
||||
from = BrowserDirection.FromHome,
|
||||
flags = EngineSession.LoadUrlFlags.select(ALLOW_JAVASCRIPT_URL)
|
||||
)
|
||||
activity.components.core.metrics.track(Event.BookmarkClicked)
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import androidx.navigation.NavDirections
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.appservices.places.BookmarkRoot
|
||||
import mozilla.components.concept.engine.EngineSession
|
||||
import mozilla.components.concept.engine.prompt.ShareData
|
||||
import mozilla.components.concept.storage.BookmarkNode
|
||||
import mozilla.components.feature.tabs.TabsUseCases
|
||||
@ -73,7 +74,14 @@ class DefaultBookmarkController(
|
||||
}
|
||||
|
||||
override fun handleBookmarkTapped(item: BookmarkNode) {
|
||||
openInNewTabAndShow(item.url!!, true, BrowserDirection.FromBookmarks, activity.browsingModeManager.mode)
|
||||
val flags = EngineSession.LoadUrlFlags.select(EngineSession.LoadUrlFlags.ALLOW_JAVASCRIPT_URL)
|
||||
openInNewTabAndShow(
|
||||
item.url!!,
|
||||
true,
|
||||
BrowserDirection.FromBookmarks,
|
||||
activity.browsingModeManager.mode,
|
||||
flags
|
||||
)
|
||||
}
|
||||
|
||||
override fun handleBookmarkExpand(folder: BookmarkNode) {
|
||||
@ -177,12 +185,13 @@ class DefaultBookmarkController(
|
||||
searchTermOrURL: String,
|
||||
newTab: Boolean,
|
||||
from: BrowserDirection,
|
||||
mode: BrowsingMode
|
||||
mode: BrowsingMode,
|
||||
flags: EngineSession.LoadUrlFlags = EngineSession.LoadUrlFlags.none()
|
||||
) {
|
||||
invokePendingDeletion.invoke()
|
||||
with(activity) {
|
||||
browsingModeManager.mode = mode
|
||||
openToBrowserAndLoad(searchTermOrURL, newTab, from)
|
||||
openToBrowserAndLoad(searchTermOrURL, newTab, from, flags = flags)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import androidx.appcompat.app.AlertDialog
|
||||
import androidx.navigation.NavController
|
||||
import mozilla.components.browser.state.search.SearchEngine
|
||||
import mozilla.components.browser.state.store.BrowserStore
|
||||
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags
|
||||
import mozilla.components.feature.tabs.TabsUseCases
|
||||
import mozilla.components.support.ktx.kotlin.isUrl
|
||||
import org.mozilla.fenix.BrowserDirection
|
||||
@ -36,7 +37,7 @@ interface SearchController {
|
||||
fun handleUrlCommitted(url: String, fromHomeScreen: Boolean = false)
|
||||
fun handleEditingCancelled()
|
||||
fun handleTextChanged(text: String)
|
||||
fun handleUrlTapped(url: String)
|
||||
fun handleUrlTapped(url: String, flags: LoadUrlFlags = LoadUrlFlags.none())
|
||||
fun handleSearchTermsTapped(searchTerms: String)
|
||||
fun handleSearchShortcutEngineSelected(searchEngine: SearchEngine)
|
||||
fun handleClickSearchEngineSettings()
|
||||
@ -145,13 +146,14 @@ class SearchDialogController(
|
||||
)
|
||||
}
|
||||
|
||||
override fun handleUrlTapped(url: String) {
|
||||
override fun handleUrlTapped(url: String, flags: LoadUrlFlags) {
|
||||
clearToolbarFocus()
|
||||
|
||||
activity.openToBrowserAndLoad(
|
||||
searchTermOrURL = url,
|
||||
newTab = fragmentStore.state.tabId == null,
|
||||
from = BrowserDirection.FromSearchDialog
|
||||
from = BrowserDirection.FromSearchDialog,
|
||||
flags = flags
|
||||
)
|
||||
|
||||
metrics.track(Event.EnteredUrl(false))
|
||||
|
@ -5,6 +5,7 @@
|
||||
package org.mozilla.fenix.search
|
||||
|
||||
import mozilla.components.browser.state.search.SearchEngine
|
||||
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags
|
||||
import org.mozilla.fenix.search.awesomebar.AwesomeBarInteractor
|
||||
import org.mozilla.fenix.search.toolbar.ToolbarInteractor
|
||||
|
||||
@ -29,8 +30,8 @@ class SearchDialogInteractor(
|
||||
searchController.handleTextChanged(text)
|
||||
}
|
||||
|
||||
override fun onUrlTapped(url: String) {
|
||||
searchController.handleUrlTapped(url)
|
||||
override fun onUrlTapped(url: String, flags: LoadUrlFlags) {
|
||||
searchController.handleUrlTapped(url, flags)
|
||||
}
|
||||
|
||||
override fun onSearchTermsTapped(searchTerms: String) {
|
||||
|
@ -5,6 +5,7 @@
|
||||
package org.mozilla.fenix.search.awesomebar
|
||||
|
||||
import mozilla.components.browser.state.search.SearchEngine
|
||||
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags
|
||||
|
||||
/**
|
||||
* Interface for the AwesomeBarView Interactor. This interface is implemented by objects that want
|
||||
@ -16,7 +17,7 @@ interface AwesomeBarInteractor {
|
||||
* Called whenever a suggestion containing a URL is tapped
|
||||
* @param url the url the suggestion was providing
|
||||
*/
|
||||
fun onUrlTapped(url: String)
|
||||
fun onUrlTapped(url: String, flags: LoadUrlFlags = LoadUrlFlags.none())
|
||||
|
||||
/**
|
||||
* Called whenever a search engine suggestion is tapped
|
||||
|
@ -61,7 +61,7 @@ class AwesomeBarView(
|
||||
flags: EngineSession.LoadUrlFlags,
|
||||
additionalHeaders: Map<String, String>?
|
||||
) {
|
||||
interactor.onUrlTapped(url)
|
||||
interactor.onUrlTapped(url, flags)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import mozilla.appservices.places.BookmarkRoot
|
||||
import mozilla.components.concept.engine.EngineSession
|
||||
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags.Companion.ALLOW_JAVASCRIPT_URL
|
||||
import mozilla.components.concept.storage.BookmarkNode
|
||||
import mozilla.components.concept.storage.BookmarkNodeType
|
||||
import mozilla.components.support.test.rule.MainCoroutineRule
|
||||
@ -92,6 +94,7 @@ class DefaultRecentBookmarksControllerTest {
|
||||
activity.openToBrowserAndLoad(
|
||||
searchTermOrURL = bookmark.url!!,
|
||||
newTab = true,
|
||||
flags = EngineSession.LoadUrlFlags.select(ALLOW_JAVASCRIPT_URL),
|
||||
from = BrowserDirection.FromHome
|
||||
)
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import io.mockk.verify
|
||||
import io.mockk.verifyOrder
|
||||
import kotlinx.coroutines.test.TestCoroutineScope
|
||||
import mozilla.appservices.places.BookmarkRoot
|
||||
import mozilla.components.concept.engine.EngineSession
|
||||
import mozilla.components.concept.storage.BookmarkNode
|
||||
import mozilla.components.concept.storage.BookmarkNodeType
|
||||
import mozilla.components.feature.tabs.TabsUseCases
|
||||
@ -111,6 +112,8 @@ class BookmarkControllerTest {
|
||||
@Test
|
||||
fun `handleBookmarkTapped should load the bookmark in a new tab`() {
|
||||
var invokePendingDeletionInvoked = false
|
||||
val flags = EngineSession.LoadUrlFlags.select(EngineSession.LoadUrlFlags.ALLOW_JAVASCRIPT_URL)
|
||||
|
||||
createController(
|
||||
invokePendingDeletion = {
|
||||
invokePendingDeletionInvoked = true
|
||||
@ -119,7 +122,12 @@ class BookmarkControllerTest {
|
||||
|
||||
assertTrue(invokePendingDeletionInvoked)
|
||||
verify {
|
||||
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
|
||||
homeActivity.openToBrowserAndLoad(
|
||||
item.url!!,
|
||||
true,
|
||||
BrowserDirection.FromBookmarks,
|
||||
flags = flags
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,6 +277,9 @@ class BookmarkControllerTest {
|
||||
@Test
|
||||
fun `handleBookmarkTapped should open the bookmark`() {
|
||||
var invokePendingDeletionInvoked = false
|
||||
val flags =
|
||||
EngineSession.LoadUrlFlags.select(EngineSession.LoadUrlFlags.ALLOW_JAVASCRIPT_URL)
|
||||
|
||||
createController(
|
||||
invokePendingDeletion = {
|
||||
invokePendingDeletionInvoked = true
|
||||
@ -277,7 +288,12 @@ class BookmarkControllerTest {
|
||||
|
||||
assertTrue(invokePendingDeletionInvoked)
|
||||
verify {
|
||||
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
|
||||
homeActivity.openToBrowserAndLoad(
|
||||
item.url!!,
|
||||
true,
|
||||
BrowserDirection.FromBookmarks,
|
||||
flags = flags
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import mozilla.components.browser.state.action.TabListAction
|
||||
import mozilla.components.browser.state.search.SearchEngine
|
||||
import mozilla.components.browser.state.state.BrowserState
|
||||
import mozilla.components.browser.state.store.BrowserStore
|
||||
import mozilla.components.concept.engine.EngineSession
|
||||
import mozilla.components.feature.tabs.TabsUseCases
|
||||
import mozilla.components.support.test.libstate.ext.waitUntilIdle
|
||||
import mozilla.components.support.test.middleware.CaptureActionsMiddleware
|
||||
@ -244,14 +245,17 @@ class SearchDialogControllerTest {
|
||||
@Test
|
||||
fun handleUrlTapped() {
|
||||
val url = "https://www.google.com/"
|
||||
val flags = EngineSession.LoadUrlFlags.all()
|
||||
|
||||
createController().handleUrlTapped(url, flags)
|
||||
createController().handleUrlTapped(url)
|
||||
|
||||
verify {
|
||||
activity.openToBrowserAndLoad(
|
||||
searchTermOrURL = url,
|
||||
newTab = false,
|
||||
from = BrowserDirection.FromSearchDialog
|
||||
from = BrowserDirection.FromSearchDialog,
|
||||
flags = flags
|
||||
)
|
||||
}
|
||||
verify { metrics.track(Event.EnteredUrl(false)) }
|
||||
|
Loading…
Reference in New Issue
Block a user