Skip to content

Commit

Permalink
Top autofill (#432)
Browse files Browse the repository at this point in the history
* Top autofill

* Change AutofillMessagingToChildDelegate passing to WebsiteAutofillUserScript

* BSK feedback

* Move interface

* Bump BSK to 10.0.2
  • Loading branch information
jonathanKingston authored Feb 25, 2022
1 parent 6a965c7 commit 2f3aeaa
Show file tree
Hide file tree
Showing 12 changed files with 448 additions and 60 deletions.
22 changes: 21 additions & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@
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 */; };
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 */; };
7B4CE8E726F02135009134B1 /* TabBarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4CE8E626F02134009134B1 /* TabBarTests.swift */; };
7BA4727D26F01BC400EAA165 /* CoreDataTestUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9292C42667104B00AD2C21 /* CoreDataTestUtilities.swift */; };
8511E18425F82B34002F516B /* 01_Fire_really_small.json in Resources */ = {isa = PBXBuildFile; fileRef = 8511E18325F82B34002F516B /* 01_Fire_really_small.json */; };
Expand Down Expand Up @@ -930,6 +933,9 @@
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>"; };
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>"; };
7B4CE8DA26F02108009134B1 /* UI Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "UI Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
7B4CE8DE26F02108009134B1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7B4CE8E626F02134009134B1 /* TabBarTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2025,6 +2031,16 @@
path = Model;
sourceTree = "<group>";
};
7B1E819A27C8874900FF0E60 /* Autofill */ = {
isa = PBXGroup;
children = (
7B1E819B27C8874900FF0E60 /* ContentOverlayPopover.swift */,
7B1E819C27C8874900FF0E60 /* ContentOverlay.storyboard */,
7B1E819D27C8874900FF0E60 /* ContentOverlayViewController.swift */,
);
path = Autofill;
sourceTree = "<group>";
};
7B4CE8DB26F02108009134B1 /* UI Tests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3330,6 +3346,7 @@
B31055BB27A1BA0E001AC618 /* Autoconsent */ = {
isa = PBXGroup;
children = (
7B1E819A27C8874900FF0E60 /* Autofill */,
B31055C327A1BA1D001AC618 /* autoconsent-bundle.js */,
B31055BD27A1BA1D001AC618 /* autoconsent.html */,
B31055C127A1BA1D001AC618 /* AutoconsentBackground.swift */,
Expand Down Expand Up @@ -3818,6 +3835,7 @@
AA3439712754D4E900B241FA /* dark-shield.json in Resources */,
B31055C827A1BA1D001AC618 /* background-bundle.js in Resources */,
B31055CB27A1BA1D001AC618 /* autoconsent-bundle.js in Resources */,
7B1E819F27C8874900FF0E60 /* ContentOverlay.storyboard in Resources */,
85A0117425AF2EDF00FA6A0C /* FindInPage.storyboard in Resources */,
AA80EC89256C49B8007083E7 /* Localizable.strings in Resources */,
B31055C627A1BA1D001AC618 /* userscript.js in Resources */,
Expand Down Expand Up @@ -4212,6 +4230,7 @@
B6830961274CDE99004B46BB /* FireproofDomainsContainer.swift in Sources */,
B65536AE2685E17200085A79 /* GeolocationService.swift in Sources */,
4B02198925E05FAC00ED7DEA /* FireproofingURLExtensions.swift in Sources */,
7B1E819E27C8874900FF0E60 /* ContentOverlayPopover.swift in Sources */,
4BA1A6A5258B07DF00F6F690 /* EncryptedValueTransformer.swift in Sources */,
4B92929F26670D2A00AD2C21 /* PasteboardBookmark.swift in Sources */,
856CADF0271710F400E79BB0 /* HoverUserScript.swift in Sources */,
Expand Down Expand Up @@ -4367,6 +4386,7 @@
B6AAAC3E26048F690029438D /* RandomAccessCollectionExtension.swift in Sources */,
4B9292AF26670F5300AD2C21 /* NSOutlineViewExtensions.swift in Sources */,
AA585D82248FD31100E9A3E2 /* AppDelegate.swift in Sources */,
7B1E81A027C8874900FF0E60 /* ContentOverlayViewController.swift in Sources */,
85B7184C27677C6500B4277F /* OnboardingViewController.swift in Sources */,
AA72D5F025FEA49900C77619 /* AddEditFavoriteWindow.swift in Sources */,
1456D6E124EFCBC300775049 /* TabBarCollectionView.swift in Sources */,
Expand Down Expand Up @@ -5499,7 +5519,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 10.0.1;
minimumVersion = 10.0.2;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/duckduckgo/BrowserServicesKit",
"state": {
"branch": null,
"revision": "183d4ac1258681724263e2b1d9cd2b65165ff43b",
"version": "10.0.1"
"revision": "b9c5cdb717c1d783e63e0fcfb16455f4db2a5d1a",
"version": "10.0.2"
}
},
{
Expand Down Expand Up @@ -63,6 +63,15 @@
"revision": "6b2aa2748a7881eebb9f84fb10c01293e15b52ca",
"version": "0.5.0"
}
},
{
"package": "TrackerRadarKit",
"repositoryURL": "https://github.com/duckduckgo/TrackerRadarKit.git",
"state": {
"branch": null,
"revision": "5f4caf35b8418700a48c64c7c61eb43308c8dacc",
"version": "1.0.3"
}
}
]
},
Expand Down
48 changes: 48 additions & 0 deletions DuckDuckGo/Autofill/ContentOverlay.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Window Controller-->
<scene sceneID="Yd1-AJ-Qv8">
<objects>
<windowController storyboardIdentifier="ContentOverlayWindowController" id="AYn-l1-ytb" sceneMemberID="viewController">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" hasShadow="NO" visibleAtLaunch="NO" appearanceType="aqua" frameAutosaveName="" animationBehavior="default" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="EcH-Hu-Dez">
<windowStyleMask key="styleMask" fullSizeContentView="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="2022" y="350" width="480" height="270"/>
<rect key="screenRect" x="1728" y="37" width="1920" height="1055"/>
<view key="contentView" id="94y-sJ-ZOB">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
</view>
<connections>
<outlet property="delegate" destination="AYn-l1-ytb" id="Rr5-bI-8Mg"/>
</connections>
</window>
<connections>
<segue destination="von-g3-QJ1" kind="relationship" relationship="window.shadowedContentViewController" id="nWM-ud-rJK"/>
</connections>
</windowController>
<customObject id="e7l-sk-SA9" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-324" y="1"/>
</scene>
<!--Content Overlay View Controller-->
<scene sceneID="ZEN-nM-P55">
<objects>
<viewController storyboardIdentifier="ContentOverlayViewController" id="von-g3-QJ1" customClass="ContentOverlayViewController" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" appearanceType="aqua" id="ct2-uy-dYM">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
</view>
</viewController>
<customObject id="KjB-z1-VQJ" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="409" y="1"/>
</scene>
</scenes>
</document>
96 changes: 96 additions & 0 deletions DuckDuckGo/Autofill/ContentOverlayPopover.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// ContentOverlayPopover.swift
//
// Copyright © 2022 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Cocoa
import WebKit
import BrowserServicesKit

public final class ContentOverlayPopover {

public var zoomFactor: CGFloat?
public weak var currentTabView: NSView?

public var viewController: ContentOverlayViewController
public var windowController: NSWindowController

public init(currentTabView: NSView) {
let storyboard = NSStoryboard(name: "ContentOverlay", bundle: Bundle.main)
viewController = storyboard.instantiateController(identifier: "ContentOverlayViewController")
windowController = storyboard.instantiateController(identifier: "ContentOverlayWindowController")
windowController.contentViewController = viewController
windowController.window?.hasShadow = true
windowController.window?.acceptsMouseMovedEvents = true
windowController.window?.ignoresMouseEvents = false

viewController.view.wantsLayer = true
if let layer = viewController.view.layer {
layer.masksToBounds = true
layer.cornerRadius = 6
layer.borderWidth = 0.5
layer.borderColor = CGColor.init(gray: 0, alpha: 0.3) // Looks a little lighter than 0.2 in the CSS
}
viewController.view.window?.backgroundColor = .clear
viewController.view.window?.acceptsMouseMovedEvents = true
viewController.view.window?.ignoresMouseEvents = false
self.currentTabView = currentTabView
}

public required init?(coder: NSCoder) {
fatalError("ContentOverlayPopover: Bad initializer")
}
}

// MARK: - WebsiteAutofillUserScriptDelegate
extension ContentOverlayPopover: ContentOverlayUserScriptDelegate {
public func websiteAutofillUserScriptCloseOverlay(_ websiteAutofillUserScript: WebsiteAutofillUserScript?) {
guard let windowController = windowController.window else {
return
}
if !windowController.isVisible { return }
// Reset window size on close to reduce flicker
viewController.requestResizeToSize(CGSize(width: 0, height: 0))
windowController.parent?.removeChildWindow(windowController)
windowController.orderOut(nil)
}

public func websiteAutofillUserScript(_ websiteAutofillUserScript: WebsiteAutofillUserScript,
willDisplayOverlayAtClick: NSPoint,
serializedInputContext: String,
inputPosition: CGRect) {
// Combines native click with offset of JS click.
let y = (willDisplayOverlayAtClick.y - (inputPosition.height - inputPosition.minY))
let x = (willDisplayOverlayAtClick.x - inputPosition.minX)
var rectWidth = inputPosition.width
// If the field is wider we want to left assign the rectangle anchoring
if inputPosition.width > 315 {
rectWidth = 315
}
let rect = NSRect(x: x, y: y, width: rectWidth, height: inputPosition.height)

// On open initialize to default size to reduce flicker
viewController.requestResizeToSize(CGSize(width: 0, height: 0))
viewController.autofillInterfaceToChild = websiteAutofillUserScript
viewController.setType(serializedInputContext: serializedInputContext, zoomFactor: zoomFactor)
if let overlayWindow = windowController.window, let currentTabViewWindow = currentTabView?.window {
currentTabViewWindow.addChildWindow(overlayWindow, ordered: .above)
let outRect = currentTabViewWindow.convertToScreen(rect)
overlayWindow.setFrameTopLeftPoint(NSPoint(x: outRect.minX, y: outRect.minY))
}
}

}
Loading

0 comments on commit 2f3aeaa

Please sign in to comment.