From 0e3965632aa40c1533711ad726642aa64de40226 Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Tue, 29 Jan 2019 12:04:57 -0800 Subject: [PATCH] Closes #270: Integrate browser-storage-sync for history storage and toolbar autocompletion --- app/build.gradle | 1 + .../java/org/mozilla/fenix/browser/BrowserFragment.kt | 3 ++- .../main/java/org/mozilla/fenix/components/Core.kt | 11 ++++++++++- .../fenix/components/toolbar/ToolbarIntegration.kt | 3 +++ .../java/org/mozilla/fenix/search/SearchFragment.kt | 4 +++- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4db6d45f4..ff14564bd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -90,6 +90,7 @@ dependencies { implementation Deps.mozilla_browser_domains implementation Deps.mozilla_browser_engine_gecko_nightly implementation Deps.mozilla_browser_session + implementation Deps.mozilla_browser_storage_sync implementation Deps.mozilla_browser_toolbar implementation Deps.mozilla_feature_awesomebar diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index 90df6b7a8..32e0e9dad 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -52,7 +52,8 @@ class BrowserFragment : Fragment() { ToolbarIntegration( requireContext(), toolbar, - requireComponents.toolbar.shippedDomainsProvider + requireComponents.toolbar.shippedDomainsProvider, + requireComponents.core.historyStorage ) ) diff --git a/app/src/main/java/org/mozilla/fenix/components/Core.kt b/app/src/main/java/org/mozilla/fenix/components/Core.kt index 64d94503a..5ae0c27cd 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Core.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Core.kt @@ -11,9 +11,11 @@ import mozilla.components.browser.engine.gecko.GeckoEngine import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.storage.SessionStorage +import mozilla.components.browser.storage.sync.PlacesHistoryStorage import mozilla.components.concept.engine.DefaultSettings import mozilla.components.concept.engine.Engine import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy +import mozilla.components.feature.session.HistoryDelegate import java.util.concurrent.TimeUnit /** @@ -31,7 +33,8 @@ class Core(private val context: Context) { val defaultSettings = DefaultSettings( remoteDebuggingEnabled = false, testingModeEnabled = false, - trackingProtectionPolicy = createTrackingProtectionPolicy(prefs) + trackingProtectionPolicy = createTrackingProtectionPolicy(prefs), + historyTrackingDelegate = HistoryDelegate(historyStorage) ) GeckoEngine(context, defaultSettings) } @@ -60,6 +63,12 @@ class Core(private val context: Context) { } } + /** + * The storage component to persist browsing history (with the exception of + * private sessions). + */ + val historyStorage by lazy { PlacesHistoryStorage(context) } + /** * Constructs a [TrackingProtectionPolicy] based on current preferences. * diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt index e61c920ef..6eef8ea8c 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarIntegration.kt @@ -13,6 +13,7 @@ import androidx.navigation.Navigation import androidx.navigation.fragment.FragmentNavigator import mozilla.components.browser.domains.autocomplete.DomainAutocompleteProvider import mozilla.components.browser.toolbar.BrowserToolbar +import mozilla.components.concept.storage.HistoryStorage import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature import mozilla.components.feature.toolbar.ToolbarFeature import org.mozilla.fenix.R @@ -23,6 +24,7 @@ class ToolbarIntegration( context: Context, toolbar: BrowserToolbar, domainAutocompleteProvider: DomainAutocompleteProvider, + historyStorage: HistoryStorage, sessionId: String? = null ) : LifecycleObserver { init { @@ -50,6 +52,7 @@ class ToolbarIntegration( ToolbarAutocompleteFeature(toolbar).apply { addDomainProvider(domainAutocompleteProvider) + addHistoryStorageProvider(historyStorage) } } diff --git a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt index 5b8d5c4ab..62fabd4d2 100644 --- a/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/search/SearchFragment.kt @@ -48,7 +48,9 @@ class SearchFragment : Fragment() { ToolbarIntegration( requireContext(), toolbar, - ShippedDomainsProvider().also { it.initialize(requireContext()) }) + ShippedDomainsProvider().also { it.initialize(requireContext()) }, + requireComponents.core.historyStorage + ) ) awesomeBarFeature = AwesomeBarFeature(awesomeBar, toolbar, null, onEditComplete = ::userDidSearch)