Skip to content

Commit

Permalink
rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Jan 1, 2024
1 parent 129d140 commit 1c76ee2
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 12 deletions.
42 changes: 32 additions & 10 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
1DB9617B29F1D06D00CF5568 /* InternalUserDeciderMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DB9617929F1D06D00CF5568 /* InternalUserDeciderMock.swift */; };
1DB9618229F67F6100CF5568 /* FaviconNullStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DB9617F29F67F3E00CF5568 /* FaviconNullStore.swift */; };
1DB9618329F67F6200CF5568 /* FaviconNullStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DB9617F29F67F3E00CF5568 /* FaviconNullStore.swift */; };
1DC776322AF436C7002DF07B /* OnboardingSchemeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776312AF436C7002DF07B /* OnboardingSchemeHandler.swift */; };
1DC776332AF43812002DF07B /* OnboardingSchemeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776312AF436C7002DF07B /* OnboardingSchemeHandler.swift */; };
1DC776352AF43855002DF07B /* OnboardingSchemeHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776312AF436C7002DF07B /* OnboardingSchemeHandler.swift */; };
1DC776382AF4416A002DF07B /* OnboardingTabExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776372AF4416A002DF07B /* OnboardingTabExtension.swift */; };
1DC7763A2AF44255002DF07B /* OnboardingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776392AF44255002DF07B /* OnboardingManager.swift */; };
1DC7763B2AF445BD002DF07B /* OnboardingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776392AF44255002DF07B /* OnboardingManager.swift */; };
1DC7763D2AF445C0002DF07B /* OnboardingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776392AF44255002DF07B /* OnboardingManager.swift */; };
1DC776402AF445CB002DF07B /* OnboardingTabExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776372AF4416A002DF07B /* OnboardingTabExtension.swift */; };
1DC776412AF445CD002DF07B /* OnboardingTabExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776372AF4416A002DF07B /* OnboardingTabExtension.swift */; };
1DC776452AF4F1C6002DF07B /* OnboardingUserScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776442AF4F1C6002DF07B /* OnboardingUserScript.swift */; };
1DC776462AF4F1C6002DF07B /* OnboardingUserScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776442AF4F1C6002DF07B /* OnboardingUserScript.swift */; };
1DC776482AF4F1C6002DF07B /* OnboardingUserScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DC776442AF4F1C6002DF07B /* OnboardingUserScript.swift */; };
1DCFBC8A29ADF32B00313531 /* BurnerHomePageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DCFBC8929ADF32B00313531 /* BurnerHomePageView.swift */; };
1DCFBC8B29ADF32B00313531 /* BurnerHomePageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DCFBC8929ADF32B00313531 /* BurnerHomePageView.swift */; };
1DDF076328F815AD00EDFBE3 /* BWCommunicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1DDF075D28F815AD00EDFBE3 /* BWCommunicator.swift */; };
Expand Down Expand Up @@ -3199,6 +3211,10 @@
1DA6D0FF2A1FF9DC00540406 /* HTTPCookieTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPCookieTests.swift; sourceTree = "<group>"; };
1DB9617929F1D06D00CF5568 /* InternalUserDeciderMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InternalUserDeciderMock.swift; sourceTree = "<group>"; };
1DB9617F29F67F3E00CF5568 /* FaviconNullStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaviconNullStore.swift; sourceTree = "<group>"; };
1DC776312AF436C7002DF07B /* OnboardingSchemeHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingSchemeHandler.swift; sourceTree = "<group>"; };
1DC776372AF4416A002DF07B /* OnboardingTabExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingTabExtension.swift; sourceTree = "<group>"; };
1DC776392AF44255002DF07B /* OnboardingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingManager.swift; sourceTree = "<group>"; };
1DC776442AF4F1C6002DF07B /* OnboardingUserScript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingUserScript.swift; sourceTree = "<group>"; };
1DCFBC8929ADF32B00313531 /* BurnerHomePageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BurnerHomePageView.swift; sourceTree = "<group>"; };
1DDF075C28F815AD00EDFBE3 /* BWCredential.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BWCredential.swift; sourceTree = "<group>"; };
1DDF075D28F815AD00EDFBE3 /* BWCommunicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BWCommunicator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6193,6 +6209,9 @@
children = (
85707F2F276A7DB000DC0649 /* ViewModel */,
85B7184827677A9200B4277F /* View */,
1DC776312AF436C7002DF07B /* OnboardingSchemeHandler.swift */,
1DC776392AF44255002DF07B /* OnboardingManager.swift */,
1DC776442AF4F1C6002DF07B /* OnboardingUserScript.swift */,
);
path = Onboarding;
sourceTree = "<group>";
Expand Down Expand Up @@ -7660,6 +7679,7 @@
B66260E529ACAE4B00E9E3EE /* NavigationHotkeyHandler.swift */,
B66260DC29AC5D4300E9E3EE /* NavigationProtectionTabExtension.swift */,
B626A76C29928B1600053070 /* TestsClosureNavigationResponder.swift */,
1DC776372AF4416A002DF07B /* OnboardingTabExtension.swift */,
);
path = TabExtensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -8449,8 +8469,6 @@
buildRules = (
);
dependencies = (
B692D0DF2B209FB7003F2548 /* PBXTargetDependency */,
4B5F14FC2A15291D0060320F /* PBXTargetDependency */,
31C6E9AD2B0C07BA0086DC30 /* PBXTargetDependency */,
);
name = "DuckDuckGo Privacy Browser";
Expand Down Expand Up @@ -9322,6 +9340,7 @@
3706FAC0293F65D500E42796 /* DataTaskProviding.swift in Sources */,
3706FAC1293F65D500E42796 /* FeedbackViewController.swift in Sources */,
3706FAC2293F65D500E42796 /* FaviconSelector.swift in Sources */,
1DC7763B2AF445BD002DF07B /* OnboardingManager.swift in Sources */,
3706FAC3293F65D500E42796 /* AddEditFavoriteViewController.swift in Sources */,
B696AFFC2AC5924800C93203 /* FileLineError.swift in Sources */,
B6E1491129A5C30A00AAFBE8 /* FBProtectionTabExtension.swift in Sources */,
Expand Down Expand Up @@ -9377,6 +9396,7 @@
3706FAF3293F65D500E42796 /* LocalAuthenticationService.swift in Sources */,
1D36E659298AA3BA00AA485D /* InternalUserDeciderStore.swift in Sources */,
B6BCC5242AFCDABB002C5499 /* DataImportSourceViewModel.swift in Sources */,
1DC776332AF43812002DF07B /* OnboardingSchemeHandler.swift in Sources */,
3706FEBC293F6EFF00E42796 /* BWResponse.swift in Sources */,
3706FAF4293F65D500E42796 /* SafariBookmarksReader.swift in Sources */,
31C9ADE62AF0564500CEF57D /* WaitlistFeatureSetupHandler.swift in Sources */,
Expand All @@ -9392,6 +9412,7 @@
3706FAFA293F65D500E42796 /* CleanThisHistoryMenuItem.swift in Sources */,
1DA6D0FE2A1FF9A100540406 /* HTTPCookie.swift in Sources */,
3706FAFC293F65D500E42796 /* DownloadListItem.swift in Sources */,
1DC776462AF4F1C6002DF07B /* OnboardingUserScript.swift in Sources */,
3706FAFD293F65D500E42796 /* DownloadsPopover.swift in Sources */,
3706FAFE293F65D500E42796 /* SpacerNode.swift in Sources */,
3706FB00293F65D500E42796 /* PasswordManagementCreditCardModel.swift in Sources */,
Expand Down Expand Up @@ -9711,6 +9732,7 @@
3706FBF3293F65D500E42796 /* PseudoFolder.swift in Sources */,
3706FBF4293F65D500E42796 /* Visit.swift in Sources */,
3706FBF5293F65D500E42796 /* PixelDataStore.swift in Sources */,
1DC776402AF445CB002DF07B /* OnboardingTabExtension.swift in Sources */,
3706FBF6293F65D500E42796 /* Pixel.swift in Sources */,
3706FBF7293F65D500E42796 /* PixelEvent.swift in Sources */,
3706FBF8293F65D500E42796 /* TabBarFooter.swift in Sources */,
Expand Down Expand Up @@ -10368,6 +10390,7 @@
4B95794A2AC7AE700062CA31 /* TabIndex.swift in Sources */,
4B95794B2AC7AE700062CA31 /* SavePanelAccessoryView.swift in Sources */,
4B95794C2AC7AE700062CA31 /* TabLazyLoaderDataSource.swift in Sources */,
1DC776352AF43855002DF07B /* OnboardingSchemeHandler.swift in Sources */,
4B95794D2AC7AE700062CA31 /* LoginImport.swift in Sources */,
4B95794E2AC7AE700062CA31 /* JoinWaitlistView.swift in Sources */,
4B95794F2AC7AE700062CA31 /* LazyLoadable.swift in Sources */,
Expand Down Expand Up @@ -10947,6 +10970,7 @@
4B957B642AC7AE700062CA31 /* BackForwardListItem.swift in Sources */,
4B957B672AC7AE700062CA31 /* AtbAndVariantCleanup.swift in Sources */,
4B957B682AC7AE700062CA31 /* NibLoadable.swift in Sources */,
1DC776412AF445CD002DF07B /* OnboardingTabExtension.swift in Sources */,
4B957B692AC7AE700062CA31 /* FeedbackWindow.swift in Sources */,
4B957B6A2AC7AE700062CA31 /* WorkspaceProtocol.swift in Sources */,
4B957B6B2AC7AE700062CA31 /* RecentlyVisitedView.swift in Sources */,
Expand Down Expand Up @@ -10981,6 +11005,7 @@
4B957B842AC7AE700062CA31 /* SuggestionContainer.swift in Sources */,
4B957B852AC7AE700062CA31 /* FindInPageTabExtension.swift in Sources */,
4B957B862AC7AE700062CA31 /* HomePageViewController.swift in Sources */,
1DC7763D2AF445C0002DF07B /* OnboardingManager.swift in Sources */,
4B957B882AC7AE700062CA31 /* OperatingSystemVersionExtension.swift in Sources */,
4B957B892AC7AE700062CA31 /* ToggleableScrollView.swift in Sources */,
4B957B8A2AC7AE700062CA31 /* TabCleanupPreparer.swift in Sources */,
Expand Down Expand Up @@ -11040,6 +11065,7 @@
4B957BB92AC7AE700062CA31 /* SyncErrorHandler.swift in Sources */,
4BF0E50A2AD2551A00FFEC9E /* NetworkProtectionPixelEvent.swift in Sources */,
4B957BBA2AC7AE700062CA31 /* URLExtension.swift in Sources */,
1DC776482AF4F1C6002DF07B /* OnboardingUserScript.swift in Sources */,
4B957BBB2AC7AE700062CA31 /* Tab+UIDelegate.swift in Sources */,
1E2AE4C92ACB217800684E0A /* NetworkProtectionRemoteMessagingStorage.swift in Sources */,
4B957BBD2AC7AE700062CA31 /* NSStoryboardExtension.swift in Sources */,
Expand Down Expand Up @@ -11369,6 +11395,7 @@
37CD54CA27F2FDD100F1F7B9 /* AutofillPreferencesModel.swift in Sources */,
7BBD45B12A691AB500C83CA9 /* NetworkProtectionDebugUtilities.swift in Sources */,
B657841F25FA497600D8DB33 /* NSException+Catch.swift in Sources */,
1DC776382AF4416A002DF07B /* OnboardingTabExtension.swift in Sources */,
4BE65481271FCD4D008D1D63 /* PasswordManagementNoteModel.swift in Sources */,
3184AC6F288F2A1100C35E4B /* CookieNotificationAnimationModel.swift in Sources */,
4B9DB0382A983B24000927DB /* JoinedWaitlistView.swift in Sources */,
Expand Down Expand Up @@ -11565,6 +11592,7 @@
B64C853026943BC10048FEBE /* Permissions.xcdatamodeld in Sources */,
EE339228291BDEFD009F62C1 /* JSAlertController.swift in Sources */,
4B9DB04A2A983B24000927DB /* NotificationService.swift in Sources */,
1DC776452AF4F1C6002DF07B /* OnboardingUserScript.swift in Sources */,
3775912D29AAC72700E26367 /* SyncPreferences.swift in Sources */,
1DB9618329F67F6200CF5568 /* FaviconNullStore.swift in Sources */,
BB5789722B2CA70F0009DFE2 /* DataBrokerProtectionSubscriptionEventHandler.swift in Sources */,
Expand Down Expand Up @@ -11718,6 +11746,7 @@
AA6820EB25503D6A005ED0D5 /* Fire.swift in Sources */,
3158B1492B0BF73000AF130C /* DBPHomeViewController.swift in Sources */,
37445F9C2A1569F00029F789 /* SyncBookmarksAdapter.swift in Sources */,
1DC776322AF436C7002DF07B /* OnboardingSchemeHandler.swift in Sources */,
B6AAAC3E26048F690029438D /* RandomAccessCollectionExtension.swift in Sources */,
4B9292AF26670F5300AD2C21 /* NSOutlineViewExtensions.swift in Sources */,
AA585D82248FD31100E9A3E2 /* AppDelegate.swift in Sources */,
Expand All @@ -11736,6 +11765,7 @@
B65E6B9E26D9EC0800095F96 /* CircularProgressView.swift in Sources */,
AABEE69C24A902BB0043105B /* SuggestionContainer.swift in Sources */,
B6C00ECD292F89D9009C73A6 /* FindInPageTabExtension.swift in Sources */,
1DC7763A2AF44255002DF07B /* OnboardingManager.swift in Sources */,
85589E8327BBB8630038AD11 /* HomePageViewController.swift in Sources */,
B6A9E46B2614618A0067D1B9 /* OperatingSystemVersionExtension.swift in Sources */,
4BDFA4AE27BF19E500648192 /* ToggleableScrollView.swift in Sources */,
Expand Down Expand Up @@ -12103,10 +12133,6 @@
isa = PBXTargetDependency;
productRef = 4B4D60522A0B29CB00BCD287 /* NetworkProtection */;
};
4B5F14FC2A15291D0060320F /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = 4B5F14FB2A15291D0060320F /* InputFilesChecker */;
};
4B5F14FE2A1529230060320F /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = 4B5F14FD2A1529230060320F /* InputFilesChecker */;
Expand Down Expand Up @@ -12162,10 +12188,6 @@
isa = PBXTargetDependency;
productRef = B6080BAA2B20AF9200B418EF /* SwiftLintPlugin */;
};
B692D0DF2B209FB7003F2548 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = B692D0DE2B209FB7003F2548 /* SwiftLintPlugin */;
};
B69D06142A4C0AC50032D14D /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = B69D06132A4C0AC50032D14D /* SwiftLintPlugin */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ extension WKWebViewConfiguration {
if urlSchemeHandler(forURLScheme: DuckPlayer.duckPlayerScheme) == nil {
setURLSchemeHandler(DuckPlayerSchemeHandler(), forURLScheme: DuckPlayer.duckPlayerScheme)
}
if urlSchemeHandler(forURLScheme: OnboardingManager.urlScheme) == nil {
setURLSchemeHandler(OnboardingSchemeHandler(), forURLScheme: OnboardingManager.urlScheme)
}
}

let userContentController = UserContentController(assetsPublisher: contentBlocking.contentBlockingAssetsPublisher,
Expand Down
34 changes: 34 additions & 0 deletions DuckDuckGo/Onboarding/OnboardingManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// OnboardingManager.swift
//
// Copyright © 2023 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 Foundation

final class OnboardingManager {
static let urlScheme = "onboarding"

var isEnabled: Bool {
true
}
}

extension URL {

var isOnboardingScheme: Bool {
scheme == OnboardingManager.urlScheme
}
}
80 changes: 80 additions & 0 deletions DuckDuckGo/Onboarding/OnboardingSchemeHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// OnboardingSchemeHandler.swift
//
// Copyright © 2023 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 Foundation
import WebKit
import ContentScopeScripts

final class OnboardingSchemeHandler: NSObject, WKURLSchemeHandler {

func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
guard let requestURL = urlSchemeTask.request.url else {
assertionFailure("No URL for Privacy Debug Tools scheme handler")
return
}

guard let (response, data) = response(for: requestURL) else { return }

urlSchemeTask.didReceive(response)
urlSchemeTask.didReceive(data)
urlSchemeTask.didFinish()
}

func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {}

func response(for url: URL) -> (URLResponse, Data)? {
var fileName = "index"
var fileExtension = "html"
var directoryURL = URL(fileURLWithPath: "/pages/onboarding")
directoryURL.appendPathComponent(url.path)

if !directoryURL.pathExtension.isEmpty {
fileExtension = directoryURL.pathExtension
directoryURL.deletePathExtension()
fileName = directoryURL.lastPathComponent
directoryURL.deleteLastPathComponent()
}

print(directoryURL.path, fileName, fileExtension)

guard let file = ContentScopeScripts.Bundle.path(forResource: fileName, ofType: fileExtension, inDirectory: directoryURL.path) else {
assertionFailure("HTML template not found")
return nil
}

guard let data = try? Data(contentsOf: URL(fileURLWithPath: file)) else {
return nil
}

let mimeType: String? = {
switch fileExtension {
case "html": return "text/html"
case "css": return "text/css"
case "js": return "text/javascript"
case "png": return "image/png"
case "jpg", "jpeg": return "image/jpeg"
case "gif": return "image/gif"
case "svg": return "image/svg+xml"
default: return nil
}
}()

let response = URLResponse(url: url, mimeType: mimeType, expectedContentLength: data.count, textEncodingName: nil)
return (response, data)
}

}
Loading

0 comments on commit 1c76ee2

Please sign in to comment.