Skip to content

Commit

Permalink
Merge branch 'upstream_develop' into sam/merge-upstream-into-netp
Browse files Browse the repository at this point in the history
# By Sabrina Tardio (2) and Sam Symons (1)
# Via GitHub
* upstream_develop:
  Check that the source and target frame security origins are equal (#1207)
  Add activation points pixels (#1206)
  Add Login export links to settings and Autofill 3 dot menu (#1183)

# Conflicts:
#	DuckDuckGo/Menus/MainMenuActions.swift
#	DuckDuckGo/Statistics/PixelEvent.swift
#	DuckDuckGo/Statistics/PixelParameters.swift
#	UnitTests/Menus/Mocks/CapturingOptionsButtonMenuDelegate.swift
  • Loading branch information
samsymons committed May 19, 2023
2 parents df00058 + f034581 commit bd13366
Show file tree
Hide file tree
Showing 22 changed files with 205 additions and 28 deletions.
21 changes: 20 additions & 1 deletion DuckDuckGo/AppDelegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
private var appIconChanger: AppIconChanger!
private(set) var syncService: DDGSyncing!
private(set) var syncPersistence: SyncDataPersistor!
let bookmarksManager = LocalBookmarkManager.shared

#if !APPSTORE
var updateController: UpdateController!
Expand Down Expand Up @@ -157,7 +158,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel

HistoryCoordinator.shared.loadHistory()
PrivacyFeatures.httpsUpgrade.loadDataAsync()
LocalBookmarkManager.shared.loadBookmarks()
bookmarksManager.loadBookmarks()
FaviconManager.shared.loadFavicons()
ConfigurationManager.shared.start()
FileDownloadManager.shared.delegate = self
Expand Down Expand Up @@ -189,6 +190,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
urlEventHandler.applicationDidFinishLaunching()

subscribeToEmailProtectionStatusNotifications()
subscribeToDataImportCompleteNotification()

UserDefaultsWrapper<Any>.clearRemovedKeys()

Expand Down Expand Up @@ -343,14 +345,31 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel
object: nil)
}

private func subscribeToDataImportCompleteNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(dataImportCompleteNotification(_:)), name: .dataImportComplete, object: nil)
}

@objc private func emailDidSignInNotification(_ notification: Notification) {
Pixel.fire(.emailEnabled)
let repetition = Pixel.Event.Repetition(key: Pixel.Event.emailEnabledInitial.name)
// Temporary pixel for first time user enables email protection
if repetition == .initial {
Pixel.fire(.emailEnabledInitial)
}
}

@objc private func emailDidSignOutNotification(_ notification: Notification) {
Pixel.fire(.emailDisabled)
}

@objc private func dataImportCompleteNotification(_ notification: Notification) {
// Temporary pixel for first time user import data
let repetition = Pixel.Event.Repetition(key: Pixel.Event.importDataInitial.name)
if repetition == .initial {
Pixel.fire(.importDataInitial)
}
}

}

extension AppDelegate: AppUsageActivityMonitorDelegate {
Expand Down
5 changes: 2 additions & 3 deletions DuckDuckGo/Bookmarks/View/BookmarkOutlineViewCell.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down
13 changes: 8 additions & 5 deletions DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ struct UserText {
static let passwordManagementLock = NSLocalizedString("passsword.management.lock", value: "Lock", comment: "Lock Logins Vault menu")
static let passwordManagementUnlock = NSLocalizedString("passsword.management.unlock", value: "Unlock", comment: "Unlock Logins Vault menu")

static let importBrowserData = NSLocalizedString("import.browser.data", value: "Import Bookmarks and Passwords…", comment: "Opens Import Browser Data dialog")

// static let importBrowserData = NSLocalizedString("import.browser.data", value: "Import Bookmarks and Passwords…", comment: "Opens Import Browser Data dialog")
static let importBookmarks = NSLocalizedString("import.browser.data", value: "Import Bookmarks…", comment: "Opens Import Browser Data dialog")
static let importPasswords = NSLocalizedString("import.browser.data", value: "Import Passwords…", comment: "Opens Import Browser Data dialog")
static let exportLogins = NSLocalizedString("export.logins.data", value: "Export Passwords…", comment: "Opens Export Logins Data dialog")
static let exportBookmarks = NSLocalizedString("export.bookmarks.menu.item", value: "Export Bookmarks…", comment: "Export bookmarks menu item")
static let bookmarks = NSLocalizedString("bookmarks", value: "Bookmarks", comment: "Button for bookmarks")
static let favorites = NSLocalizedString("favorites", value: "Favorites", comment: "Title text for the Favorites menu item")
static let bookmarksOpenInNewTabs = NSLocalizedString("bookmarks.open.in.new.tabs", value: "Open in New Tabs", comment: "Open all bookmarks in folder in new tabs")
Expand Down Expand Up @@ -495,12 +498,12 @@ struct UserText {
static let downloadsActiveAlertMessageFormat = NSLocalizedString("downloads.active.alert.message.format", value: "Are you sure you want to quit? DuckDuckGo Privacy Browser is currently downloading “%@”%@. If you quit now DuckDuckGo Privacy Browser won’t finish downloading this file.", comment: "Alert text format when trying to quit application while file “filename”[, and others] are being downloaded")
static let downloadsActiveAlertMessageAndOthers = NSLocalizedString("downloads.active.alert.message.and.others", value: ", and other files", comment: "Alert text format element for “, and other files”")

static let exportLoginsFailedMessage = NSLocalizedString("export.logins.failed.message", value: "Failed to Export Logins", comment: "Alert title when exporting login data fails")
static let exportLoginsFailedMessage = NSLocalizedString("export.logins.failed.message", value: "Failed to Export Passwords", comment: "Alert title when exporting login data fails")
static let exportLoginsFailedInformative = NSLocalizedString("export.logins.failed.informative", value: "Please check that no file exists at the location you selected.", comment: "Alert message when exporting login data fails")
static let exportBookmarksFailedMessage = NSLocalizedString("export.bookmarks.failed.message", value: "Failed to Export Bookmarks", comment: "Alert title when exporting login data fails")
static let exportBookmarksFailedMessage = NSLocalizedString("export.bookmarks.failed.message", value: "Failed to Export Bookmarks", comment: "Alert title when exporting login data fails")
static let exportBookmarksFailedInformative = NSLocalizedString("export.bookmarks.failed.informative", value: "Please check that no file exists at the location you selected.", comment: "Alert message when exporting bookmarks fails")

static let exportLoginsFileNameSuffix = NSLocalizedString("export.logins.file.name.suffix", value: "Logins", comment: "The last part of the suggested file name for exporting logins")
static let exportLoginsFileNameSuffix = NSLocalizedString("export.logins.file.name.suffix", value: "Passwords", comment: "The last part of the suggested file name for exporting logins")
static let exportBookmarksFileNameSuffix = NSLocalizedString("export.bookmarks.file.name.suffix", value: "Bookmarks", comment: "The last part of the suggested file for exporting bookmarks")
static let exportLoginsWarning = NSLocalizedString("export.logins.warning", value: "This file contains your passwords in plain text and should be saved in a secure location and deleted when you are done.\nAnyone with access to this file will be able to read your passwords.", comment: "Warning text presented when exporting logins.")

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/HomePage/View/HomePage.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="NgM-AV-NvE">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="NgM-AV-NvE">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down
17 changes: 14 additions & 3 deletions DuckDuckGo/Menus/MainMenu.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<!--Application-->
<scene sceneID="JPo-4y-FX3">
<objects>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target">
<connections>
<outlet property="exportBookmarksMenuItem" destination="3K6-pB-Kea" id="0aB-uI-R6L"/>
</connections>
</customObject>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<customObject id="WIK-gq-Ncg" customClass="CopyHandler" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target"/>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
Expand Down Expand Up @@ -127,7 +131,7 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Export" id="SGe-jt-1so">
<items>
<menuItem title="Logins..." id="raM-fX-nRg">
<menuItem title="Passwords..." id="raM-fX-nRg">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="openExportLogins:" target="Ady-hI-5gd" id="MLl-kw-Su4"/>
Expand Down Expand Up @@ -550,12 +554,18 @@ CA
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="aPG-H0-BrG"/>
<menuItem title="Import Bookmarks and Passwords..." id="tNX-Bv-yM3" userLabel="Import Bookmarks...">
<menuItem title="Import Bookmarks" id="tNX-Bv-yM3" userLabel="Import Bookmarks...">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="openImportBrowserDataWindow:" target="Ady-hI-5gd" id="NdE-Lt-CL5"/>
</connections>
</menuItem>
<menuItem title="Export Bookmarks…" enabled="NO" id="3K6-pB-Kea">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="openExportBookmarks:" target="Ady-hI-5gd" id="h3L-FO-yq9"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="xsn-Ak-LSd"/>
<menuItem title="Favorites" image="Favorite" id="Y9I-ZC-gGg">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down Expand Up @@ -902,6 +912,7 @@ CQ
<outlet property="closeTabMenuItem" destination="DVo-aG-piG" id="Hr0-hn-2p1"/>
<outlet property="closeWindowMenuItem" destination="CzI-4o-2re" id="32H-X4-8Ub"/>
<outlet property="debugMenuItem" destination="ilv-5f-YpZ" id="4F7-9b-Mve"/>
<outlet property="exportBookmarksMenuItem" destination="3K6-pB-Kea" id="LbP-Ft-aAT"/>
<outlet property="favoriteThisPageMenuItem" destination="cHZ-Fb-aKU" id="uPM-LY-AmL"/>
<outlet property="favoritesMenuItem" destination="Y9I-ZC-gGg" id="zk1-XL-x3e"/>
<outlet property="forwardMenuItem" destination="Gbj-sV-aI3" id="54P-Ym-Ic2"/>
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Menus/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ final class MainMenu: NSMenu {
@IBOutlet weak var manageBookmarksMenuItem: NSMenuItem!
@IBOutlet weak var bookmarksMenuToggleBookmarksBarMenuItem: NSMenuItem?
@IBOutlet weak var importBookmarksMenuItem: NSMenuItem!
@IBOutlet weak var exportBookmarksMenuItem: NSMenuItem!
@IBOutlet weak var bookmarksMenuItem: NSMenuItem?
@IBOutlet weak var bookmarkThisPageMenuItem: NSMenuItem?
@IBOutlet weak var favoritesMenuItem: NSMenuItem?
Expand Down
33 changes: 33 additions & 0 deletions DuckDuckGo/Menus/MainMenuActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -942,10 +942,43 @@ extension AppDelegate: NSMenuItemValidation {
case #selector(AppDelegate.reopenAllWindowsFromLastSession(_:)):
return stateRestorationManager.canRestoreLastSessionState

// Enables and disables export bookmarks itemz
case #selector(AppDelegate.openExportBookmarks(_:)):
return bookmarksManager.list?.totalBookmarks != 0

// Enables and disables export passwords items
case #selector(AppDelegate.openExportLogins(_:)):
return areTherePasswords

default:
return true
}
}

private var areTherePasswords: Bool {
let vault = try? SecureVaultFactory.default.makeVault(errorReporter: SecureVaultErrorReporter.shared)
guard let vault else {
return false
}
let accounts = (try? vault.accounts()) ?? []
if !accounts.isEmpty {
return true
}
let cards = (try? vault.creditCards()) ?? []
if !cards.isEmpty {
return true
}
let notes = (try? vault.notes()) ?? []
if !notes.isEmpty {
return true
}
let identities = (try? vault.identities()) ?? []
if !identities.isEmpty {
return true
}
return false
}

}

extension MainViewController: FindInPageDelegate {
Expand Down
15 changes: 13 additions & 2 deletions DuckDuckGo/NavigationBar/View/MoreOptionsMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protocol OptionsButtonMenuDelegate: AnyObject {
func optionsButtonMenuRequestedToggleBookmarksBar(_ menu: NSMenu)
func optionsButtonMenuRequestedBookmarkManagementInterface(_ menu: NSMenu)
func optionsButtonMenuRequestedBookmarkImportInterface(_ menu: NSMenu)
func optionsButtonMenuRequestedBookmarkExportInterface(_ menu: NSMenu)
func optionsButtonMenuRequestedLoginsPopover(_ menu: NSMenu, selectedCategory: SecureVaultSorting.Category)
func optionsButtonMenuRequestedOpenExternalPasswordManager(_ menu: NSMenu)
func optionsButtonMenuRequestedNetworkProtectionPopover(_ menu: NSMenu)
Expand Down Expand Up @@ -160,6 +161,10 @@ final class MoreOptionsMenu: NSMenu {
actionDelegate?.optionsButtonMenuRequestedBookmarkImportInterface(self)
}

@objc func openBookmarkExportInterface(_ sender: NSMenuItem) {
actionDelegate?.optionsButtonMenuRequestedBookmarkExportInterface(self)
}

@objc func openDownloads(_ sender: NSMenuItem) {
actionDelegate?.optionsButtonMenuRequestedDownloadsPopover(self)
}
Expand Down Expand Up @@ -443,7 +448,8 @@ final class BookmarksSubMenu: NSMenu {
addItem(NSMenuItem.separator())
}

guard let entities = LocalBookmarkManager.shared.list?.topLevelEntities else {
let bookmarkManager = LocalBookmarkManager.shared
guard let entities = bookmarkManager.list?.topLevelEntities else {
return
}

Expand All @@ -454,8 +460,13 @@ final class BookmarksSubMenu: NSMenu {

addItem(NSMenuItem.separator())

addItem(withTitle: UserText.importBrowserData, action: #selector(MoreOptionsMenu.openBookmarkImportInterface(_:)), keyEquivalent: "")
addItem(withTitle: UserText.importBookmarks, action: #selector(MoreOptionsMenu.openBookmarkImportInterface(_:)), keyEquivalent: "")
.targetting(target)

let exportBookmarItem = NSMenuItem(title: UserText.exportBookmarks, action: #selector(MoreOptionsMenu.openBookmarkExportInterface(_:)), keyEquivalent: "")
exportBookmarItem.isEnabled = bookmarkManager.list?.totalBookmarks != 0
addItem(exportBookmarItem)

}

private func bookmarkMenuItems(from bookmarkViewModels: [BookmarkViewModel], topLevel: Bool = true) -> [NSMenuItem] {
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/NavigationBar/View/NavigationBar.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="o2v-eH-jTI">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="o2v-eH-jTI">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ extension NavigationBarViewController: OptionsButtonMenuDelegate {
DataImportViewController.show()
}

func optionsButtonMenuRequestedBookmarkExportInterface(_ menu: NSMenu) {
NSApp.sendAction(#selector(AppDelegate.openExportBookmarks(_:)), to: nil, from: nil)
}

func optionsButtonMenuRequestedLoginsPopover(_ menu: NSMenu, selectedCategory: SecureVaultSorting.Category) {
popovers.showPasswordManagementPopover(selectedCategory: selectedCategory,
usingView: passwordManagementButton,
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/Preferences/Model/AutofillPreferencesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ final class AutofillPreferencesModel: ObservableObject {
NSApp.sendAction(#selector(AppDelegate.openImportBrowserDataWindow(_:)), to: nil, from: nil)
}

func openExportLogins() {
NSApp.sendAction(#selector(AppDelegate.openExportLogins(_:)), to: nil, from: nil)
}

@MainActor
func showAutofillPopover(_ selectedCategory: SecureVaultSorting.Category = .allItems) {
guard let parentWindowController = WindowControllersManager.shared.lastKeyMainWindowController else { return }
Expand Down
17 changes: 16 additions & 1 deletion DuckDuckGo/Preferences/Model/DefaultBrowserPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,22 @@ struct SystemDefaultBrowserProvider: DefaultBrowserProvider {

final class DefaultBrowserPreferences: ObservableObject {

@Published private(set) var isDefault: Bool = false
@Published private(set) var isDefault: Bool = false {
didSet {
// Temporary pixel for first time user import data
#if DEBUG
if NSApp.isRunningUnitTests {
return
}
#endif
if isDefault {
let repetition = Pixel.Event.Repetition(key: Pixel.Event.setAsDefaultInitial.name)
if repetition == .initial {
Pixel.fire(.setAsDefaultInitial)
}
}
}
}
@Published private(set) var restorePreviousSession: Bool = false

init(defaultBrowserProvider: DefaultBrowserProvider = SystemDefaultBrowserProvider()) {
Expand Down
Loading

0 comments on commit bd13366

Please sign in to comment.