This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
140 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import UIKit | ||
import Strings | ||
|
||
extension UIAction { | ||
static func makePasteAndGoAction(pasteCallback: @escaping (String) -> Void) -> UIAction { | ||
return UIAction( | ||
identifier: .pasteAndGo, | ||
handler: UIAction.deferredActionHandler { _ in | ||
if let pasteboardContents = UIPasteboard.general.string { | ||
pasteCallback(pasteboardContents) | ||
} | ||
} | ||
) | ||
} | ||
|
||
static func makePasteAction(pasteCallback: @escaping (String) -> Void) -> UIAction { | ||
return UIAction( | ||
identifier: .paste, | ||
handler: UIAction.deferredActionHandler { _ in | ||
if let pasteboardContents = UIPasteboard.general.string { | ||
pasteCallback(pasteboardContents) | ||
} | ||
} | ||
) | ||
} | ||
|
||
static func makeCopyAction(for url: URL) -> UIAction { | ||
return UIAction( | ||
title: Strings.copyLinkActionTitle, | ||
image: UIImage(systemName: "doc.on.doc"), | ||
handler: UIAction.deferredActionHandler { _ in | ||
UIPasteboard.general.url = url as URL | ||
} | ||
) | ||
} | ||
|
||
static func makeCleanCopyAction(for url: URL, isPrivateMode: Bool) -> UIAction { | ||
return UIAction( | ||
title: Strings.copyCleanLink, | ||
image: UIImage(systemName: "doc.on.doc"), | ||
handler: UIAction.deferredActionHandler { _ in | ||
let cleanedURL = CleanURLService.shared.cleanup(url: url, isPrivateMode: isPrivateMode) | ||
UIPasteboard.general.url = cleanedURL | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2023 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import Foundation | ||
import BraveCore | ||
|
||
/// A helper class that helps us clean urls for "clean copy" feature | ||
class CleanURLService { | ||
public static let shared = CleanURLService() | ||
|
||
private lazy var urlSanitizerService = URLSanitizerServiceFactory.get(privateMode: false) | ||
private lazy var privateURLSanitizerService = URLSanitizerServiceFactory.get(privateMode: true) | ||
|
||
/// Initialize this instance with a network manager | ||
init() {} | ||
|
||
/// Cleanup the url using the stored matcher | ||
func cleanup(url: URL, isPrivateMode: Bool) -> URL { | ||
if isPrivateMode { | ||
return privateURLSanitizerService?.sanitizeURL(url) ?? url | ||
} else { | ||
return urlSanitizerService?.sanitizeURL(url) ?? url | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters