Skip to content

Commit

Permalink
Merge branch 'develop' into sam/bookmarks-phase-2-favicon-import
Browse files Browse the repository at this point in the history
* develop:
  Bump version to 0.28.9 and update embedded files
  BSK update for changed URL parameter API (#715)
  Improvements in CPM coverage (#707)
  Fix a couple calculations used for the bookmarks bar. (#713)
  Set version to 0.28.8
  Remove invalidate back item (#711)
  Set version to 0.28.7.
  Update the home page to preserve the scheme of the original URL. (#705)
  Add the bookmarks submenu to the browser's More menu (#684)
  Brad/referrer trimming (#682)
  Update BrowserServicesKit for iOS Remote Messaging support (#709)
  • Loading branch information
samsymons committed Sep 20, 2022
2 parents 6606534 + 923ed97 commit 24de70c
Show file tree
Hide file tree
Showing 31 changed files with 465 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Configuration/Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MARKETING_VERSION = 0.28.6
MARKETING_VERSION = 0.28.9

38 changes: 25 additions & 13 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
4BF01C00272AE74C00884A61 /* CountryList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BE65482271FCD53008D1D63 /* CountryList.swift */; };
4BF4951826C08395000547B8 /* ThirdPartyBrowserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BF4951726C08395000547B8 /* ThirdPartyBrowserTests.swift */; };
4BF4EA5027C71F26004E57C4 /* PasswordManagementListSectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BF4EA4F27C71F26004E57C4 /* PasswordManagementListSectionTests.swift */; };
4BF6961D28BE911100D402D4 /* RecentlyVisitedSiteModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BF6961C28BE911100D402D4 /* RecentlyVisitedSiteModelTests.swift */; };
7B1E819E27C8874900FF0E60 /* ContentOverlayPopover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1E819B27C8874900FF0E60 /* ContentOverlayPopover.swift */; };
7B1E819F27C8874900FF0E60 /* ContentOverlay.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7B1E819C27C8874900FF0E60 /* ContentOverlay.storyboard */; };
7B1E81A027C8874900FF0E60 /* ContentOverlayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B1E819D27C8874900FF0E60 /* ContentOverlayViewController.swift */; };
Expand Down Expand Up @@ -1116,6 +1117,7 @@
4BEF0E712766B11200AF7C58 /* MacWaitlistLockScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacWaitlistLockScreenViewModel.swift; sourceTree = "<group>"; };
4BF4951726C08395000547B8 /* ThirdPartyBrowserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThirdPartyBrowserTests.swift; sourceTree = "<group>"; };
4BF4EA4F27C71F26004E57C4 /* PasswordManagementListSectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PasswordManagementListSectionTests.swift; sourceTree = "<group>"; };
4BF6961C28BE911100D402D4 /* RecentlyVisitedSiteModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentlyVisitedSiteModelTests.swift; sourceTree = "<group>"; };
7B1E819B27C8874900FF0E60 /* ContentOverlayPopover.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentOverlayPopover.swift; sourceTree = "<group>"; };
7B1E819C27C8874900FF0E60 /* ContentOverlay.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = ContentOverlay.storyboard; sourceTree = "<group>"; };
7B1E819D27C8874900FF0E60 /* ContentOverlayViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentOverlayViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1623,7 +1625,7 @@
F41D174025CB131900472416 /* NSColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSColorExtension.swift; sourceTree = "<group>"; };
F44C130125C2DA0400426E3E /* NSAppearanceExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSAppearanceExtension.swift; sourceTree = "<group>"; };
F4A6198B283CFFBB007F2080 /* ContentScopeFeatureFlagging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentScopeFeatureFlagging.swift; sourceTree = "<group>"; };
FD23FD2A28816606007F6985 /* AutoconsentMessageProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AutoconsentMessageProtocolTests.swift; path = "Unit Tests/AutoconsentMessageProtocolTests.swift"; sourceTree = SOURCE_ROOT; };
FD23FD2A28816606007F6985 /* AutoconsentMessageProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AutoconsentMessageProtocolTests.swift; path = "Unit Tests/Autoconsent/AutoconsentMessageProtocolTests.swift"; sourceTree = SOURCE_ROOT; };
FD23FD2C2886A81D007F6985 /* AutoconsentManagement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoconsentManagement.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -2364,6 +2366,22 @@
path = Model;
sourceTree = "<group>";
};
4BF6961B28BE90E800D402D4 /* Home Page */ = {
isa = PBXGroup;
children = (
4BF6961C28BE911100D402D4 /* RecentlyVisitedSiteModelTests.swift */,
);
path = "Home Page";
sourceTree = "<group>";
};
4BF6962128C242E500D402D4 /* Autoconsent */ = {
isa = PBXGroup;
children = (
FD23FD2A28816606007F6985 /* AutoconsentMessageProtocolTests.swift */,
);
path = Autoconsent;
sourceTree = "<group>";
};
4BFD356E283ADE8B00CE9234 /* Bookmarks Bar */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2883,10 +2901,9 @@
AA585D93248FD31400E9A3E2 /* Unit Tests */ = {
isa = PBXGroup;
children = (
FD23FD29288165A8007F6985 /* Autoconsent */,
4B2CBF3F2767EEB2001DF04B /* Waitlist */,
B6A5A28C25B962CB00AA7ADA /* App */,
85F1B0C725EF9747004792B6 /* App Delegate */,
4BF6962128C242E500D402D4 /* Autoconsent */,
AA652CAB25DD820D009059CC /* Bookmarks */,
4B43468D285ED6BD00177407 /* Bookmarks Bar */,
AA92ACAE24EFE1F5005F41C9 /* Browser Tab */,
Expand All @@ -2902,6 +2919,7 @@
4B02199725E063DE00ED7DEA /* Fireproofing */,
B68172AC269EB415006D1092 /* Geolocation */,
AAEC74AE2642C47300C2EFBC /* History */,
4BF6961B28BE90E800D402D4 /* Home Page */,
378205F9283C275E00D1D4AA /* Menus */,
AA91F83627076ED100771A0D /* Navigation Bar */,
85F487B3276A8F1B003CE668 /* Onboarding */,
Expand All @@ -2910,11 +2928,12 @@
4B0511EE262CAEB300F6079C /* Preferences */,
AA7E9174286DAFB700AB6B62 /* Recently Closed */,
858A798626A99D9000A75A42 /* Secure Vault */,
3776582B27F7163B009A6B35 /* Website Breakage Report */,
B6DA440F2616C0F200DD1EC2 /* Statistics */,
AA63744E24C9BB4A00AB2AC4 /* Suggestions */,
AAC9C01224CAFBB700AD1325 /* Tab Bar */,
AA0877B626D515EE00B05660 /* User Agent */,
4B2CBF3F2767EEB2001DF04B /* Waitlist */,
3776582B27F7163B009A6B35 /* Website Breakage Report */,
AA585D96248FD31400E9A3E2 /* Info.plist */,
);
path = "Unit Tests";
Expand Down Expand Up @@ -4126,14 +4145,6 @@
path = fonts;
sourceTree = "<group>";
};
FD23FD29288165A8007F6985 /* Autoconsent */ = {
isa = PBXGroup;
children = (
FD23FD2A28816606007F6985 /* AutoconsentMessageProtocolTests.swift */,
);
path = Autoconsent;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -5005,6 +5016,7 @@
37534C9E28104D9B002621E7 /* TabLazyLoaderTests.swift in Sources */,
85F1B0C925EF9759004792B6 /* URLEventHandlerTests.swift in Sources */,
4B9292BD2667103100AD2C21 /* BookmarkOutlineViewDataSourceTests.swift in Sources */,
4BF6961D28BE911100D402D4 /* RecentlyVisitedSiteModelTests.swift in Sources */,
4BBF0917282DD6EF00EE1418 /* TemporaryFileHandlerTests.swift in Sources */,
B6A5A27925B93FFF00AA7ADA /* StateRestorationManagerTests.swift in Sources */,
4B9292BB2667103100AD2C21 /* BookmarkNodeTests.swift in Sources */,
Expand Down Expand Up @@ -6234,7 +6246,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 27.0.2;
version = 29.0.0;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
11 changes: 2 additions & 9 deletions DuckDuckGo/API/APIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,10 @@ enum APIRequest {
allowedQueryReservedCharacters: CharacterSet? = nil,
headers: HTTPHeaders = APIHeaders().defaultHeaders,
timeoutInterval: TimeInterval = 60.0) -> URLRequest {
let url = (try? parameters?.reduce(url) { partialResult, parameter in
try partialResult.appendingParameter(
name: parameter.key,
value: parameter.value,
allowedReservedCharacters: allowedQueryReservedCharacters
)
}) ?? url
var urlRequest = URLRequest(url: url)
let url = url.appendingParameters(parameters ?? [:], allowedReservedCharacters: allowedQueryReservedCharacters)
var urlRequest = URLRequest(url: url, timeoutInterval: timeoutInterval)
urlRequest.allHTTPHeaderFields = headers
urlRequest.httpMethod = method.rawValue
urlRequest.timeoutInterval = timeoutInterval
return urlRequest
}

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/Autoconsent/AutoconsentUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ extension AutoconsentUserScript {
let script = """
(() => {
try {
return !!(\(messageData.code))
return !!(\(messageData.code));
} catch (e) {
// ignore CSP errors
// ignore any errors
return;
}
})();
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/Autoconsent/autoconsent-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion DuckDuckGo/Autofill/ContentOverlayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public final class ContentOverlayViewController: NSViewController, EmailManagerR
completion: @escaping (Data?, Error?) -> Void) {
let currentQueue = OperationQueue.current

let finalURL = (try? url.appendingParameters(parameters ?? [:])) ?? url
let finalURL = url.appendingParameters(parameters ?? [:])

var request = URLRequest(url: finalURL, timeoutInterval: timeoutInterval)
request.allHTTPHeaderFields = headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ final class BookmarksBarViewController: NSViewController {

@objc
private func frameChangeNotification() {
viewModel.clipOrRestoreBookmarksBarItems()
refreshClippedIndicator()
// Wait until the frame change has taken effect for subviews before calculating changes to the list of items.
DispatchQueue.main.async {
self.viewModel.clipOrRestoreBookmarksBarItems()
self.refreshClippedIndicator()
}
}

override func removeFromParent() {
Expand Down Expand Up @@ -249,7 +252,7 @@ extension BookmarksBarViewController: BookmarksBarViewModelDelegate {

private func bookmarkFolderMenu(items: [NSMenuItem]) -> NSMenu {
let menu = NSMenu()
menu.items = items.isEmpty ? [NSMenuItem(title: UserText.bookmarksBarFolderEmpty, action: nil, target: nil, keyEquivalent: "")] : items
menu.items = items.isEmpty ? [NSMenuItem.empty] : items
return menu
}

Expand Down
17 changes: 11 additions & 6 deletions DuckDuckGo/Bookmarks Bar/View/BookmarksBarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,18 @@ final class BookmarksBarViewModel: NSObject {
}

if bookmarksBarItemsTotalWidth >= clipThreshold {
if clipLastBarItem() {
delegate?.bookmarksBarViewModelReloadedData()
while bookmarksBarItemsTotalWidth >= clipThreshold {
if !clipLastBarItem() {
// Short circuit the while loop in the case that clipping the last item doesn't succeed.
break
}
}
} else if let nextRestorableClippedItem = clippedItems.first {

delegate?.bookmarksBarViewModelReloadedData()
} else if !clippedItems.isEmpty {
var restoredItem = false

while true {
while let nextRestorableClippedItem = clippedItems.first {
if !restoreNextClippedItemToBookmarksBarIfPossible(item: nextRestorableClippedItem) {
break
}
Expand Down Expand Up @@ -223,11 +228,11 @@ final class BookmarksBarViewModel: NSObject {
textSizeCalculationLabel.stringValue = buttonTitle
textSizeCalculationLabel.sizeToFit()

let cappedTitleWidth = min(Constants.maximumButtonWidth, textSizeCalculationLabel.frame.width)
let cappedTitleWidth = ceil(min(Constants.maximumButtonWidth, textSizeCalculationLabel.frame.width))
let calculatedWidth = min(Constants.maximumButtonWidth, textSizeCalculationLabel.frame.width) + Constants.additionalItemWidth
collectionViewItemSizeCache[buttonTitle] = cappedTitleWidth

return calculatedWidth
return ceil(calculatedWidth)
}
}

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/Bookmarks/Model/PseudoFolder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import Foundation

final class PseudoFolder: Equatable {

static let favorites = PseudoFolder(id: UUID(), name: "Favorites", icon: NSImage(named: "FavoriteFilledBorder")!)
static let bookmarks = PseudoFolder(id: UUID(), name: "Bookmarks", icon: NSImage(named: "Folder")!)
static let favorites = PseudoFolder(id: UUID(), name: UserText.favorites, icon: NSImage(named: "FavoriteFilledBorder")!)
static let bookmarks = PseudoFolder(id: UUID(), name: UserText.bookmarks, icon: NSImage(named: "Folder")!)

let id: UUID
let name: String
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/Bookmarks/ViewModel/BookmarkViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ struct BookmarkViewModel {
if let bookmark = entity as? Bookmark {
let favicon = bookmark.favicon(.small)?.copy() as? NSImage
favicon?.size = NSSize.faviconSize
return favicon

return favicon ?? NSImage(named: "BookmarkDefaultFavicon")
} else if entity is BookmarkFolder {
return NSImage(named: "Folder")
} else {
Expand Down
20 changes: 20 additions & 0 deletions DuckDuckGo/Browser Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ final class Tab: NSObject, Identifiable, ObservableObject {
contentBlockingManager: ContentBlocking.shared.contentBlockingManager,
errorReporting: Self.debugEvents)
}()

lazy var referrerTrimming: ReferrerTrimming = {
ReferrerTrimming(privacyManager: ContentBlocking.shared.privacyConfigurationManager,
contentBlockingManager: ContentBlocking.shared.contentBlockingManager,
tld: TLD())
}()

@MainActor
private func reloadIfNeeded(shouldLoadInBackground: Bool = false) async {
Expand Down Expand Up @@ -1063,6 +1069,16 @@ extension Tab: WKNavigationDelegate {
if navigationAction.isTargetingMainFrame, navigationAction.request.mainDocumentURL?.host != lastUpgradedURL?.host {
lastUpgradedURL = nil
}

if navigationAction.isTargetingMainFrame, navigationAction.navigationType != .backForward {
if let newRequest = referrerTrimming.trimReferrer(forNavigation: navigationAction,
originUrl: webView.url ?? navigationAction.sourceFrame.webView?.url) {
defer {
webView.load(newRequest)
}
return .cancel
}
}

if navigationAction.isTargetingMainFrame {
if navigationAction.navigationType == .backForward,
Expand Down Expand Up @@ -1238,6 +1254,7 @@ extension Tab: WKNavigationDelegate {
resetDashboardInfo()
linkProtection.cancelOngoingExtraction()
linkProtection.setMainFrameUrl(webView.url)
referrerTrimming.onBeginNavigation(to: webView.url)
}

@MainActor
Expand All @@ -1247,6 +1264,7 @@ extension Tab: WKNavigationDelegate {
webViewDidFinishNavigationPublisher.send()
if isAMPProtectionExtracting { isAMPProtectionExtracting = false }
linkProtection.setMainFrameUrl(nil)
referrerTrimming.onFinishNavigation()
}

func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
Expand All @@ -1257,6 +1275,7 @@ extension Tab: WKNavigationDelegate {
isBeingRedirected = false
invalidateSessionStateData()
linkProtection.setMainFrameUrl(nil)
referrerTrimming.onFailedNavigation()
webViewDidFailNavigationPublisher.send()
}

Expand All @@ -1272,6 +1291,7 @@ extension Tab: WKNavigationDelegate {
self.error = error
isBeingRedirected = false
linkProtection.setMainFrameUrl(nil)
referrerTrimming.onFailedNavigation()
webViewDidFailNavigationPublisher.send()
}

Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Common/Extensions/NSMenuItemExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import Cocoa

extension NSMenuItem {

static var empty: NSMenuItem {
return NSMenuItem(title: UserText.bookmarksBarFolderEmpty, action: nil, target: nil, keyEquivalent: "")
}

convenience init(title string: String, action selector: Selector?, target: AnyObject?, keyEquivalent charCode: String) {
self.init(title: string, action: selector, keyEquivalent: charCode)
self.target = target
Expand Down
26 changes: 9 additions & 17 deletions DuckDuckGo/Common/Extensions/URLExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ extension URL {
return nil
}

do {
return try Self.duckDuckGo
.appendingParameter(name: DuckDuckGoParameters.search.rawValue, value: trimmedQuery)
} catch let error {
os_log("URL extension: %s", type: .error, error.localizedDescription)
return nil
}
return Self.duckDuckGo.appendingParameter(name: DuckDuckGoParameters.search.rawValue, value: trimmedQuery)
}

static func makeURL(from addressBarString: String) -> URL? {
Expand Down Expand Up @@ -130,26 +124,26 @@ extension URL {
return URL(string: Self.atb)!
}

static func searchAtb(atbWithVariant: String, setAtb: String) -> URL? {
return try? Self.initialAtb
static func searchAtb(atbWithVariant: String, setAtb: String) -> URL {
return Self.initialAtb
.appendingParameters([
DuckDuckGoParameters.ATB.atb: atbWithVariant,
DuckDuckGoParameters.ATB.setAtb: setAtb
])
}

static func appRetentionAtb(atbWithVariant: String, setAtb: String) -> URL? {
return try? Self.initialAtb
static func appRetentionAtb(atbWithVariant: String, setAtb: String) -> URL {
return Self.initialAtb
.appendingParameters([
DuckDuckGoParameters.ATB.activityType: DuckDuckGoParameters.ATB.appUsageValue,
DuckDuckGoParameters.ATB.atb: atbWithVariant,
DuckDuckGoParameters.ATB.setAtb: setAtb
])
}

static func exti(forAtb atb: String) -> URL? {
static func exti(forAtb atb: String) -> URL {
let extiUrl = URL(string: Self.exti)!
return try? extiUrl.appendingParameter(name: DuckDuckGoParameters.ATB.atb, value: atb)
return extiUrl.appendingParameter(name: DuckDuckGoParameters.ATB.atb, value: atb)
}

// MARK: - Components
Expand Down Expand Up @@ -290,15 +284,13 @@ extension URL {
absoluteString.starts(with: Self.duckDuckGo.absoluteString)
}

// swiftlint:disable unused_optional_binding
var isDuckDuckGoSearch: Bool {
if isDuckDuckGo, path.isEmpty || path == "/", let _ = try? getParameter(name: DuckDuckGoParameters.search.rawValue) {
if isDuckDuckGo, path.isEmpty || path == "/", getParameter(named: DuckDuckGoParameters.search.rawValue) != nil {
return true
}

return false
}
// swiftlint:enable unused_optional_binding

enum DuckDuckGoParameters: String {
case search = "q"
Expand All @@ -318,7 +310,7 @@ extension URL {

var searchQuery: String? {
guard isDuckDuckGoSearch else { return nil }
return try? getParameter(name: DuckDuckGoParameters.search.rawValue)
return getParameter(named: DuckDuckGoParameters.search.rawValue)
}

// MARK: - Punycode
Expand Down
Loading

0 comments on commit 24de70c

Please sign in to comment.