From b14b83e7373dc07e7a31f534223f648e5f8cfbbc Mon Sep 17 00:00:00 2001 From: Soner YUKSEL Date: Fri, 27 Oct 2023 11:06:09 -0400 Subject: [PATCH] Fix #8305 - Ref #8297: Allow Syncing All History - Update brave-core to 1.60.105 (#8306) --- .../Browser/BrowserViewController.swift | 49 +++++++------------ .../BrowserViewController+BraveTalk.swift | 2 +- .../BrowserViewController+IPFSScheme.swift | 6 +-- .../BrowserViewController+Menu.swift | 2 +- .../BrowserViewController+ReaderMode.swift | 18 ------- ...rowserViewController+ToolbarDelegate.swift | 35 ++++++------- ...Controller+UIDropInteractionDelegate.swift | 2 +- ...rViewController+WKNavigationDelegate.swift | 14 ++---- .../BrowserViewController+Wallet.swift | 2 +- ...rowserViewController+Web3NameService.swift | 12 ++--- .../Bookmarks/BookmarksViewController.swift | 2 +- .../Menu/HistoryViewController.swift | 14 ++++-- .../Toolbars/ToolbarUrlActionsDelegate.swift | 2 +- .../History/HistoryAPIExtensions.swift | 4 +- .../Internal/Web3IPFSScriptHandler.swift | 7 ++- .../Web3NameServiceScriptHandler.swift | 7 ++- .../Shortcuts/ActivityShortcutManager.swift | 2 +- Sources/Shared/Extensions/URLExtensions.swift | 13 ----- .../NSURLExtensionsTests.swift | 25 ---------- package-lock.json | 12 ++--- package.json | 2 +- 21 files changed, 79 insertions(+), 153 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController.swift index cd57eae1d476..5164079761db 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController.swift @@ -193,7 +193,6 @@ public class BrowserViewController: UIViewController { var addToPlayListActivityItem: (enabled: Bool, item: PlaylistInfo?)? // A boolean to determine If AddToListActivity should be added var openInPlaylistActivityItem: (enabled: Bool, item: PlaylistInfo?)? // A boolean to determine if OpenInPlaylistActivity should be shown - var typedNavigation = [URL: VisitType]() var navigationToolbar: ToolbarProtocol { return toolbar ?? topToolbar } @@ -263,8 +262,6 @@ public class BrowserViewController: UIViewController { /// The currently open WalletStore weak var walletStore: WalletStore? - var lastEnteredURLVisitType: VisitType = .unknown - var processAddressBarTask: Task<(), Never>? var topToolbarDidPressReloadTask: Task<(), Never>? @@ -1579,7 +1576,7 @@ public class BrowserViewController: UIViewController { UIApplication.shared.shortcutItems = Preferences.Privacy.privateBrowsingOnly.value ? [privateTabItem, scanQRCodeItem] : [newTabItem, privateTabItem, scanQRCodeItem] } - func finishEditingAndSubmit(_ url: URL, visitType: VisitType) { + func finishEditingAndSubmit(_ url: URL) { if url.isBookmarklet { topToolbar.leaveOverlayMode() @@ -1591,7 +1588,7 @@ public class BrowserViewController: UIViewController { // Disable any sort of privileged execution contexts // IE: The user must explicitly tap a bookmark they have saved. // Block all other contexts such as redirects, downloads, embed, linked, etc.. - if visitType == .bookmark, let webView = tab.webView, let code = url.bookmarkletCodeComponent { + if let webView = tab.webView, let code = url.bookmarkletCodeComponent { webView.evaluateSafeJavaScript( functionName: code, contentWorld: .bookmarkletSandbox, @@ -1612,13 +1609,11 @@ public class BrowserViewController: UIViewController { tab.loadRequest(URLRequest(url: url)) - // Recording the last Visit Type for the url submitted - lastEnteredURLVisitType = visitType updateWebViewPageZoom(tab: tab) } } - func showIPFSInterstitialPage(originalURL: URL, visitType: VisitType) { + func showIPFSInterstitialPage(originalURL: URL) { topToolbar.leaveOverlayMode() guard let tab = tabManager.selectedTab, let encodedURL = originalURL.absoluteString.addingPercentEncoding(withAllowedCharacters: .alphanumerics), let internalUrl = URL(string: "\(InternalURL.baseUrl)/\(IPFSSchemeHandler.path)?url=\(encodedURL)") else { @@ -1626,12 +1621,11 @@ public class BrowserViewController: UIViewController { } let scriptHandler = tab.getContentScript(name: Web3IPFSScriptHandler.scriptName) as? Web3IPFSScriptHandler scriptHandler?.originalURL = originalURL - scriptHandler?.visitType = visitType tab.webView?.load(PrivilegedRequest(url: internalUrl) as URLRequest) } - func showWeb3ServiceInterstitialPage(service: Web3Service, originalURL: URL, visitType: VisitType = .unknown) { + func showWeb3ServiceInterstitialPage(service: Web3Service, originalURL: URL) { topToolbar.leaveOverlayMode() guard let tab = tabManager.selectedTab, @@ -1641,7 +1635,6 @@ public class BrowserViewController: UIViewController { } let scriptHandler = tab.getContentScript(name: Web3NameServiceScriptHandler.scriptName) as? Web3NameServiceScriptHandler scriptHandler?.originalURL = originalURL - scriptHandler?.visitType = visitType tab.webView?.load(PrivilegedRequest(url: internalUrl) as URLRequest) } @@ -1960,7 +1953,7 @@ public class BrowserViewController: UIViewController { if let url = url { // If only empty tab present, the url will open in existing tab if tabManager.isBrowserEmptyForCurrentMode { - finishEditingAndSubmit(url, visitType: .link) + finishEditingAndSubmit(url) return } request = isPrivileged ? PrivilegedRequest(url: url) as URLRequest : URLRequest(url: url) @@ -2371,16 +2364,8 @@ public class BrowserViewController: UIViewController { // Only add history of a url which is not a localhost url if !url.isReaderModeURL { - // The visitType is checked If it is "typed" or not to determine the History object we are adding - // should be synced or not. This limitation exists on browser side so we are aligning with this if !tab.isPrivate { - if let visitType = typedNavigation.first(where: { - $0.key.typedDisplayString == url.typedDisplayString - })?.value, visitType == .typed { - braveCore.historyAPI.add(url: url, title: tab.title, dateAdded: Date()) - } else { - braveCore.historyAPI.add(url: url, title: tab.title, dateAdded: Date(), isURLTyped: false) - } + braveCore.historyAPI.add(url: url, title: tab.title, dateAdded: Date()) } // Saving Tab. @@ -2823,7 +2808,7 @@ extension BrowserViewController: TabDelegate { } func reloadIPFSSchemeUrl(_ url: URL) { - handleIPFSSchemeURL(url, visitType: .unknown) + handleIPFSSchemeURL(url) } func didReloadTab(_ tab: Tab) { @@ -2860,11 +2845,11 @@ extension BrowserViewController: TabDelegate { extension BrowserViewController: SearchViewControllerDelegate { func searchViewController(_ searchViewController: SearchViewController, didSubmit query: String, braveSearchPromotion: Bool) { topToolbar.leaveOverlayMode() - processAddressBar(text: query, visitType: .typed, isBraveSearchPromotion: braveSearchPromotion) + processAddressBar(text: query, isBraveSearchPromotion: braveSearchPromotion) } func searchViewController(_ searchViewController: SearchViewController, didSelectURL url: URL) { - finishEditingAndSubmit(url, visitType: .typed) + finishEditingAndSubmit(url) } func searchViewController(_ searchViewController: SearchViewController, didSelectOpenTab tabInfo: (id: UUID?, url: URL)) { @@ -2958,15 +2943,15 @@ extension BrowserViewController: ToolbarUrlActionsDelegate { func openInNewTab(_ url: URL, isPrivate: Bool) { topToolbar.leaveOverlayMode() - select(url, visitType: .unknown, action: .openInNewTab(isPrivate: isPrivate)) + select(url, action: .openInNewTab(isPrivate: isPrivate)) } func copy(_ url: URL) { - select(url, visitType: .unknown, action: .copy) + select(url, action: .copy) } func share(_ url: URL) { - select(url, visitType: .unknown, action: .share) + select(url, action: .share) } func batchOpen(_ urls: [URL]) { @@ -2974,14 +2959,14 @@ extension BrowserViewController: ToolbarUrlActionsDelegate { self.tabManager.addTabsForURLs(urls, zombie: false, isPrivate: tabIsPrivate) } - func select(url: URL, visitType: VisitType) { - select(url, visitType: visitType, action: .openInCurrentTab) + func select(url: URL) { + select(url, action: .openInCurrentTab) } - private func select(_ url: URL, visitType: VisitType, action: ToolbarURLAction) { + private func select(_ url: URL, action: ToolbarURLAction) { switch action { case .openInCurrentTab: - finishEditingAndSubmit(url, visitType: visitType) + finishEditingAndSubmit(url) updateURLBarWalletButton() case .openInNewTab(let isPrivate): let tab = tabManager.addTab(PrivilegedRequest(url: url) as URLRequest, afterTab: tabManager.selectedTab, isPrivate: isPrivate) @@ -3034,7 +3019,7 @@ extension BrowserViewController: NewTabPageDelegate { if inNewTab { tabManager.addTabAndSelect(isPrivate: isPrivate) } - processAddressBar(text: input, visitType: .bookmark) + processAddressBar(text: input) } func handleFavoriteAction(favorite: Favorite, action: BookmarksAction) { diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+BraveTalk.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+BraveTalk.swift index 12ccc958ff77..329af376b77e 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+BraveTalk.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+BraveTalk.swift @@ -26,7 +26,7 @@ extension BrowserViewController { var components = URLComponents() components.host = currentHost components.scheme = url.scheme - self.select(url: components.url!, visitType: .link) + self.select(components.url!) } } ) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+IPFSScheme.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+IPFSScheme.swift index 43d0d3425000..4deba64e7137 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+IPFSScheme.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+IPFSScheme.swift @@ -10,12 +10,12 @@ import BraveCore import Data extension BrowserViewController: Web3IPFSScriptHandlerDelegate { - func web3IPFSDecisionHandler(_ proceed: Bool, originalURL: URL, visitType: VisitType) { + func web3IPFSDecisionHandler(_ proceed: Bool, originalURL: URL) { if proceed { if let resolvedUrl = braveCore.ipfsAPI.resolveGatewayUrl(for: originalURL) { - finishEditingAndSubmit(resolvedUrl, visitType: visitType) + finishEditingAndSubmit(resolvedUrl) } else { - finishEditingAndSubmit(originalURL, visitType: visitType) + finishEditingAndSubmit(originalURL) } Preferences.Wallet.resolveIPFSResources.value = Preferences.Wallet.Web3IPFSOption.enabled.rawValue } else { diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Menu.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Menu.swift index 4706260789e5..73fc4630d9ff 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Menu.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Menu.swift @@ -108,7 +108,7 @@ extension BrowserViewController { guard let url = URL(string: "https://talk.brave.com/") else { return } self.popToBVC() - self.finishEditingAndSubmit(url, visitType: .typed) + self.finishEditingAndSubmit(url) } } diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ReaderMode.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ReaderMode.swift index 820038d36a82..dc6496044928 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ReaderMode.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ReaderMode.swift @@ -7,20 +7,6 @@ import Shared import WebKit import Storage -// MARK: VisitType - -enum VisitType: Int { - case unknown - /// Transition type where user followed a link and got a new top-level window - case link - /// Transition type where user typed the page's URL in the URL bar or selected it from URL bar autocomplete results. - case typed - - /// Transition type where user opened a link from bookmarks. - case bookmark - case download -} - // MARK: - ReaderModeDelegate extension BrowserViewController: ReaderModeScriptHandlerDelegate { @@ -211,8 +197,4 @@ extension BrowserViewController { ReaderModeStyleViewController(selectedStyle: readerModeStyle), didConfigureStyle: readerModeStyle) } - - func recordNavigationInTab(_ url: URL, visitType: VisitType) { - typedNavigation[url] = visitType - } } diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift index c200fcbf2d4a..ce645e8fcd2f 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift @@ -123,7 +123,7 @@ extension BrowserViewController: TopToolbarDelegate { func topToolbarDidPressReload(_ topToolbar: TopToolbarView) { if let url = topToolbar.currentURL { if url.isIPFSScheme { - if !handleIPFSSchemeURL(url, visitType: .unknown) { + if !handleIPFSSchemeURL(url) { tabManager.selectedTab?.reload() } } else if let decentralizedDNSHelper = decentralizedDNSHelperFor(url: topToolbar.currentURL) { @@ -138,7 +138,7 @@ extension BrowserViewController: TopToolbarDelegate { showWeb3ServiceInterstitialPage(service: service, originalURL: url) case let .load(resolvedURL): if resolvedURL.isIPFSScheme { - handleIPFSSchemeURL(resolvedURL, visitType: .unknown) + handleIPFSSchemeURL(resolvedURL) } else { tabManager.selectedTab?.loadRequest(URLRequest(url: resolvedURL)) } @@ -279,16 +279,13 @@ extension BrowserViewController: TopToolbarDelegate { } func topToolbar(_ topToolbar: TopToolbarView, didSubmitText text: String) { - // TopToolBar Submit Text is Typed URL Visit Type - // This visit type will be used while adding History - // And it will determine either to sync the data or not - processAddressBar(text: text, visitType: .typed) + processAddressBar(text: text) } - func processAddressBar(text: String, visitType: VisitType, isBraveSearchPromotion: Bool = false) { + func processAddressBar(text: String, isBraveSearchPromotion: Bool = false) { processAddressBarTask?.cancel() processAddressBarTask = Task { @MainActor in - if !isBraveSearchPromotion, await submitValidURL(text, visitType: visitType) { + if !isBraveSearchPromotion, await submitValidURL(text) { return } else { // We couldn't build a URL, so pass it on to the search engine. @@ -302,7 +299,7 @@ extension BrowserViewController: TopToolbarDelegate { } @discardableResult - func handleIPFSSchemeURL(_ url: URL, visitType: VisitType) -> Bool { + func handleIPFSSchemeURL(_ url: URL) -> Bool { guard !privateBrowsingManager.isPrivateBrowsing else { topToolbar.leaveOverlayMode() if let errorPageHelper = tabManager.selectedTab?.getContentScript(name: ErrorPageHelper.scriptName) as? ErrorPageHelper, let webView = tabManager.selectedTab?.webView { @@ -317,11 +314,11 @@ extension BrowserViewController: TopToolbarDelegate { switch ipfsPref { case .ask: - showIPFSInterstitialPage(originalURL: url, visitType: visitType) + showIPFSInterstitialPage(originalURL: url) return true case .enabled: if let resolvedUrl = braveCore.ipfsAPI.resolveGatewayUrl(for: url) { - finishEditingAndSubmit(resolvedUrl, visitType: visitType) + finishEditingAndSubmit(resolvedUrl) return true } case .disabled: @@ -335,9 +332,9 @@ extension BrowserViewController: TopToolbarDelegate { return false } - @MainActor func submitValidURL(_ text: String, visitType: VisitType) async -> Bool { + @MainActor func submitValidURL(_ text: String) async -> Bool { if let url = URL(string: text), url.isIPFSScheme { - return handleIPFSSchemeURL(url, visitType: visitType) + return handleIPFSSchemeURL(url) } else if let fixupURL = URIFixup.getURL(text) { // Do not allow users to enter URLs with the following schemes. // Instead, submit them to the search engine like Chrome-iOS does. @@ -352,13 +349,13 @@ extension BrowserViewController: TopToolbarDelegate { guard !Task.isCancelled else { return true } // user pressed stop, or typed new url switch result { case let .loadInterstitial(service): - showWeb3ServiceInterstitialPage(service: service, originalURL: fixupURL, visitType: visitType) + showWeb3ServiceInterstitialPage(service: service, originalURL: fixupURL) return true case let .load(resolvedURL): if resolvedURL.isIPFSScheme { - return handleIPFSSchemeURL(resolvedURL, visitType: visitType) + return handleIPFSSchemeURL(resolvedURL) } else { - finishEditingAndSubmit(resolvedURL, visitType: visitType) + finishEditingAndSubmit(resolvedURL) return true } case .none: @@ -367,7 +364,7 @@ extension BrowserViewController: TopToolbarDelegate { } // The user entered a URL, so use it. - finishEditingAndSubmit(fixupURL, visitType: visitType) + finishEditingAndSubmit(fixupURL) return true } } @@ -390,7 +387,7 @@ extension BrowserViewController: TopToolbarDelegate { if let searchURL = engine.searchURLForQuery(text, isBraveSearchPromotion: isBraveSearchPromotion) { // We couldn't find a matching search keyword, so do a search query. - finishEditingAndSubmit(searchURL, visitType: .typed) + finishEditingAndSubmit(searchURL) } else { // We still don't have a valid URL, so something is broken. Give up. print("Error handling URL entry: \"\(text)\".") @@ -723,7 +720,7 @@ extension BrowserViewController: TopToolbarDelegate { let submitSearch = { [weak self] (text: String) in if let fixupURL = URIFixup.getURL(text) { - self?.finishEditingAndSubmit(fixupURL, visitType: .unknown) + self?.finishEditingAndSubmit(fixupURL) return } diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+UIDropInteractionDelegate.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+UIDropInteractionDelegate.swift index fa384161b6ff..ad116bfa5f03 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+UIDropInteractionDelegate.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+UIDropInteractionDelegate.swift @@ -26,7 +26,7 @@ extension BrowserViewController: UIDropInteractionDelegate { return } - self.finishEditingAndSubmit(url, visitType: .typed) + self.finishEditingAndSubmit(url) } } } diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift index a348ab3d391c..e9e5bbb862a0 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift @@ -204,7 +204,7 @@ extension BrowserViewController: WKNavigationDelegate { // handles IPFS URL schemes if requestURL.isIPFSScheme { if navigationAction.targetFrame?.isMainFrame == true { - handleIPFSSchemeURL(requestURL, visitType: .link) + handleIPFSSchemeURL(requestURL) } return (.cancel, preferences) } @@ -220,11 +220,11 @@ extension BrowserViewController: WKNavigationDelegate { } switch result { case let .loadInterstitial(service): - showWeb3ServiceInterstitialPage(service: service, originalURL: requestURL, visitType: .link) + showWeb3ServiceInterstitialPage(service: service, originalURL: requestURL) return (.cancel, preferences) case let .load(resolvedURL): if resolvedURL.isIPFSScheme { - handleIPFSSchemeURL(resolvedURL, visitType: .link) + handleIPFSSchemeURL(resolvedURL) return (.cancel, preferences) } else { // non-ipfs, treat as normal url / link tapped requestURL = resolvedURL @@ -513,13 +513,7 @@ extension BrowserViewController: WKNavigationDelegate { tab.mimeType = response.mimeType } - - // Record the navigation visit type for the URL after navigation actions - // this is done in decidePolicyFor to handle all the cases like redirects etc. - if let url = responseURL, let tab = tab, !url.isReaderModeURL, !url.isFileURL, url.isWebPage(), !tab.isPrivate { - recordNavigationInTab(url, visitType: lastEnteredURLVisitType) - } - + // If none of our helpers are responsible for handling this response, // just let the webview handle it as normal. return .allow diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift index 4e5de27fec78..558babd9f37c 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift @@ -135,7 +135,7 @@ extension BrowserViewController: BraveWalletDelegate { self.dismiss(animated: true) } if let url = tabManager.selectedTab?.url, InternalURL.isValid(url: url) { - select(url: destinationURL, visitType: .link) + select(url: destinationURL) } else { _ = tabManager.addTabAndSelect( URLRequest(url: destinationURL), diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Web3NameService.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Web3NameService.swift index ceaf74520875..2f4d46865306 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Web3NameService.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Web3NameService.swift @@ -23,11 +23,11 @@ extension BrowserViewController: Web3NameServiceScriptHandlerDelegate { ) } - func web3NameServiceDecisionHandler(_ proceed: Bool, web3Service: Web3Service, originalURL: URL, visitType: VisitType) { + func web3NameServiceDecisionHandler(_ proceed: Bool, web3Service: Web3Service, originalURL: URL) { let isPrivateMode = privateBrowsingManager.isPrivateBrowsing guard let rpcService = BraveWallet.JsonRpcServiceFactory.get(privateMode: isPrivateMode), let decentralizedDNSHelper = self.decentralizedDNSHelperFor(url: originalURL) else { - finishEditingAndSubmit(originalURL, visitType: visitType) + finishEditingAndSubmit(originalURL) return } Task { @MainActor in @@ -45,16 +45,16 @@ extension BrowserViewController: Web3NameServiceScriptHandlerDelegate { switch result { case let .load(resolvedURL): if resolvedURL.isIPFSScheme { - handleIPFSSchemeURL(resolvedURL, visitType: visitType) + handleIPFSSchemeURL(resolvedURL) } else { - finishEditingAndSubmit(resolvedURL, visitType: visitType) + finishEditingAndSubmit(resolvedURL) } case let .loadInterstitial(service): // ENS interstitial -> ENS Offchain interstitial possible - showWeb3ServiceInterstitialPage(service: service, originalURL: originalURL, visitType: visitType) + showWeb3ServiceInterstitialPage(service: service, originalURL: originalURL) case .none: // failed to resolve domain or disabled - finishEditingAndSubmit(originalURL, visitType: visitType) + finishEditingAndSubmit(originalURL) } } } diff --git a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift index 781000adbe04..d1be03526b96 100644 --- a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift +++ b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift @@ -489,7 +489,7 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco ActivityShortcutManager.shared.donateCustomIntent(for: .openBookmarks, with: url.absoluteString) } - self.toolbarUrlActionsDelegate?.select(url: url, visitType: .bookmark) + self.toolbarUrlActionsDelegate?.select(url: url) } if presentingViewController is MenuViewController { diff --git a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/HistoryViewController.swift b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/HistoryViewController.swift index 6e1d956fa929..e9d19de77914 100644 --- a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/HistoryViewController.swift +++ b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/HistoryViewController.swift @@ -188,8 +188,11 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol UIAlertAction( title: Strings.History.historyClearActionTitle, style: .destructive, handler: { [weak self] _ in - guard let self = self else { return } - + guard let self = self, let allHistoryItems = historyFRC?.fetchedObjects else { + return + } + + // Deleting Local History self.historyAPI.deleteAll { // Clearing Tab History with entire history entry self.tabManager.clearTabHistory() { @@ -199,6 +202,11 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol // Clearing History should clear Recently Closed RecentlyClosed.removeAll() } + + // Asking Sync Engine To Remove Visits + for historyItems in allHistoryItems { + self.historyAPI.removeHistory(historyItems) + } })) alert.addAction(UIAlertAction(title: Strings.cancelButtonTitle, style: .cancel, handler: nil)) @@ -266,7 +274,7 @@ class HistoryViewController: SiteTableViewController, ToolbarUrlActionsProtocol } dismiss(animated: true) { - self.toolbarUrlActionsDelegate?.select(url: url, visitType: .typed) + self.toolbarUrlActionsDelegate?.select(url: url) } } diff --git a/Sources/Brave/Frontend/Browser/Toolbars/ToolbarUrlActionsDelegate.swift b/Sources/Brave/Frontend/Browser/Toolbars/ToolbarUrlActionsDelegate.swift index c335986dea2b..39f20ca03094 100644 --- a/Sources/Brave/Frontend/Browser/Toolbars/ToolbarUrlActionsDelegate.swift +++ b/Sources/Brave/Frontend/Browser/Toolbars/ToolbarUrlActionsDelegate.swift @@ -10,5 +10,5 @@ protocol ToolbarUrlActionsDelegate: AnyObject { func copy(_ url: URL) func share(_ url: URL) func batchOpen(_ urls: [URL]) - func select(url: URL, visitType: VisitType) + func select(url: URL) } diff --git a/Sources/Brave/Frontend/Sync/BraveCore/History/HistoryAPIExtensions.swift b/Sources/Brave/Frontend/Sync/BraveCore/History/HistoryAPIExtensions.swift index a14dd6621013..0234dfd91352 100644 --- a/Sources/Brave/Frontend/Sync/BraveCore/History/HistoryAPIExtensions.swift +++ b/Sources/Brave/Frontend/Sync/BraveCore/History/HistoryAPIExtensions.swift @@ -15,9 +15,9 @@ extension BraveHistoryAPI { // MARK: Internal - func add(url: URL, title: String, dateAdded: Date, isURLTyped: Bool = true) { + func add(url: URL, title: String, dateAdded: Date) { let historyNode = HistoryNode(url: url, title: title, dateAdded: dateAdded) - addHistory(historyNode, isURLTyped: isURLTyped) + addHistory(historyNode) } func frc() -> HistoryV2FetchResultsController? { diff --git a/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Internal/Web3IPFSScriptHandler.swift b/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Internal/Web3IPFSScriptHandler.swift index 3326fa877b37..b47fa8023a0b 100644 --- a/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Internal/Web3IPFSScriptHandler.swift +++ b/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Internal/Web3IPFSScriptHandler.swift @@ -9,13 +9,12 @@ import WebKit import os.log protocol Web3IPFSScriptHandlerDelegate: AnyObject { - func web3IPFSDecisionHandler(_ proceed: Bool, originalURL: URL, visitType: VisitType) + func web3IPFSDecisionHandler(_ proceed: Bool, originalURL: URL) } class Web3IPFSScriptHandler: TabContentScript { weak var delegate: Web3IPFSScriptHandlerDelegate? var originalURL: URL? - var visitType: VisitType = .unknown fileprivate weak var tab: Tab? required init(tab: Tab) { @@ -36,9 +35,9 @@ class Web3IPFSScriptHandler: TabContentScript { } if params["type"] == "IPFSDisable" { - delegate?.web3IPFSDecisionHandler(false, originalURL: originalURL, visitType: visitType) + delegate?.web3IPFSDecisionHandler(false, originalURL: originalURL) } else if params["type"] == "IPFSProceed" { - delegate?.web3IPFSDecisionHandler(true, originalURL: originalURL, visitType: visitType) + delegate?.web3IPFSDecisionHandler(true, originalURL: originalURL) } else { assertionFailure("Invalid message: \(message.body)") } diff --git a/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Internal/Web3NameServiceScriptHandler.swift b/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Internal/Web3NameServiceScriptHandler.swift index f86bbd35c929..0bc53b285384 100644 --- a/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Internal/Web3NameServiceScriptHandler.swift +++ b/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Internal/Web3NameServiceScriptHandler.swift @@ -9,7 +9,7 @@ import os.log import BraveWallet protocol Web3NameServiceScriptHandlerDelegate: AnyObject { - func web3NameServiceDecisionHandler(_ proceed: Bool, web3Service: Web3Service, originalURL: URL, visitType: VisitType) + func web3NameServiceDecisionHandler(_ proceed: Bool, web3Service: Web3Service, originalURL: URL) } class Web3NameServiceScriptHandler: TabContentScript { @@ -26,7 +26,6 @@ class Web3NameServiceScriptHandler: TabContentScript { weak var delegate: Web3NameServiceScriptHandlerDelegate? var originalURL: URL? - var visitType: VisitType = .unknown fileprivate weak var tab: Tab? required init(tab: Tab) { @@ -49,11 +48,11 @@ class Web3NameServiceScriptHandler: TabContentScript { if params[ParamKey.buttonType.rawValue] == ParamValue.disable.rawValue, let serviceId = params[ParamKey.serviceId.rawValue], let service = Web3Service(rawValue: serviceId) { - delegate?.web3NameServiceDecisionHandler(false, web3Service: service, originalURL: originalURL, visitType: visitType) + delegate?.web3NameServiceDecisionHandler(false, web3Service: service, originalURL: originalURL) } else if params[ParamKey.buttonType.rawValue] == ParamValue.proceed.rawValue, let serviceId = params[ParamKey.serviceId.rawValue], let service = Web3Service(rawValue: serviceId) { - delegate?.web3NameServiceDecisionHandler(true, web3Service: service, originalURL: originalURL, visitType: visitType) + delegate?.web3NameServiceDecisionHandler(true, web3Service: service, originalURL: originalURL) } else { assertionFailure("Invalid message: \(message.body)") } diff --git a/Sources/Brave/Shortcuts/ActivityShortcutManager.swift b/Sources/Brave/Shortcuts/ActivityShortcutManager.swift index 3649fc7e95b2..cf3ba8a86d5f 100644 --- a/Sources/Brave/Shortcuts/ActivityShortcutManager.swift +++ b/Sources/Brave/Shortcuts/ActivityShortcutManager.swift @@ -165,7 +165,7 @@ public class ActivityShortcutManager: NSObject { } else { let controller = NewsSettingsViewController(dataSource: bvc.feedDataSource, openURL: { url in bvc.dismiss(animated: true) - bvc.select(url: url, visitType: .link) + bvc.select(url) }) controller.viewDidDisappear = { if Preferences.Review.braveNewsCriteriaPassed.value { diff --git a/Sources/Shared/Extensions/URLExtensions.swift b/Sources/Shared/Extensions/URLExtensions.swift index cc4213f2fe0a..e06d3695dfa9 100644 --- a/Sources/Shared/Extensions/URLExtensions.swift +++ b/Sources/Shared/Extensions/URLExtensions.swift @@ -129,19 +129,6 @@ extension URL { } } - /// String suitable to detect the URL navigation type - /// This will return URL as a string without the scheme or ending "/" suffix limitation - /// This will be used as a key while storing navigation type of url before it is added to history - public var typedDisplayString: String { - var urlString = self.schemelessAbsoluteString - - if urlString.hasSuffix("/") { - urlString.removeLast() - } - - return urlString - } - public var displayURL: URL? { if self.absoluteString.starts(with: "blob:") { return self.havingRemovedAuthorisationComponents() diff --git a/Tests/BraveSharedTests/NSURLExtensionsTests.swift b/Tests/BraveSharedTests/NSURLExtensionsTests.swift index 23c0dcddb3c0..0e93d4356108 100644 --- a/Tests/BraveSharedTests/NSURLExtensionsTests.swift +++ b/Tests/BraveSharedTests/NSURLExtensionsTests.swift @@ -727,31 +727,6 @@ class NSURLExtensionsTests: XCTestCase { XCTAssertNil($0.bookmarkletCodeComponent) } } - - func testTypedDisplayString() { - func checkDisplayURLString(testURL: URL?, displayString: String) { - if let actual = testURL?.typedDisplayString { - XCTAssertEqual(actual, displayString) - } else { - XCTFail("Actual url is nil") - } - } - - let urlMap = [ - URL(string: "https://www.youtube.com"): "www.youtube.com", - URL(string: "http://google.com"): "google.com", - URL(string: "www.brave.com"): "www.brave.com", - URL(string: "http://brave.com/foo/"): "brave.com/foo", - URL(string: "http://brave.com/foo"): "brave.com/foo", - URL(string: "blob://http://brave.com/foo"): "http://brave.com/foo", - URL(string: "file:///Users/brave/documents/foo.txt"): "/Users/brave/documents/foo.txt", - URL(string: "file://http://brave.com/foo.txt"): "http://brave.com/foo.txt" - ] - - urlMap.forEach { - checkDisplayURLString(testURL: $0, displayString: $1) - } - } func testDisplayString() { func checkDisplayURLString(testURL: URL?, displayString: String) { diff --git a/package-lock.json b/package-lock.json index 1ef901893854..c182d536a84d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MPL-2.0", "dependencies": { "@mozilla/readability": "^0.4.2", - "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.60.104/brave-core-ios-1.60.104.tgz", + "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.60.105/brave-core-ios-1.60.105.tgz", "leo": "github:brave/leo#7f2dfddb70aff1501ef5a2f3c640a8c74a7343ee", "leo-sf-symbols": "github:brave/leo-sf-symbols#d6056328b8d6ef06e68996ff02a22e06f52590c3", "page-metadata-parser": "^1.1.3", @@ -493,9 +493,9 @@ } }, "node_modules/brave-core-ios": { - "version": "1.60.104", - "resolved": "https://github.com/brave/brave-browser/releases/download/v1.60.104/brave-core-ios-1.60.104.tgz", - "integrity": "sha512-EwGu7HZ/7plhpkunyfFFDEyjxPhy1vhgVZjY3yAd3MhIW1t1E2zIWM6ivSHfEnLR4KdyqYKxnYj5Yl44zLkNsw==", + "version": "1.60.105", + "resolved": "https://github.com/brave/brave-browser/releases/download/v1.60.105/brave-core-ios-1.60.105.tgz", + "integrity": "sha512-hejokYx3wTkR2iPeQVKWfYKAd4BqADQR4CRbE8ToWFHLqq2reVrghrIRaIjOXDIAJQU/lBzYr3fOq+YqjFcZLg==", "license": "ISC" }, "node_modules/browserslist": { @@ -3171,8 +3171,8 @@ } }, "brave-core-ios": { - "version": "https://github.com/brave/brave-browser/releases/download/v1.60.104/brave-core-ios-1.60.104.tgz", - "integrity": "sha512-EwGu7HZ/7plhpkunyfFFDEyjxPhy1vhgVZjY3yAd3MhIW1t1E2zIWM6ivSHfEnLR4KdyqYKxnYj5Yl44zLkNsw==" + "version": "https://github.com/brave/brave-browser/releases/download/v1.60.105/brave-core-ios-1.60.105.tgz", + "integrity": "sha512-hejokYx3wTkR2iPeQVKWfYKAd4BqADQR4CRbE8ToWFHLqq2reVrghrIRaIjOXDIAJQU/lBzYr3fOq+YqjFcZLg==" }, "browserslist": { "version": "4.17.1", diff --git a/package.json b/package.json index 7c09b80ecb8f..8649768d7216 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "license": "MPL-2.0", "dependencies": { "@mozilla/readability": "^0.4.2", - "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.60.104/brave-core-ios-1.60.104.tgz", + "brave-core-ios": "https://github.com/brave/brave-browser/releases/download/v1.60.105/brave-core-ios-1.60.105.tgz", "leo": "github:brave/leo#7f2dfddb70aff1501ef5a2f3c640a8c74a7343ee", "leo-sf-symbols": "github:brave/leo-sf-symbols#d6056328b8d6ef06e68996ff02a22e06f52590c3", "page-metadata-parser": "^1.1.3",