diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController.swift index 19473ce92b2..aad493e6677 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController.swift @@ -14,7 +14,6 @@ import CoreData import StoreKit import BraveUI import NetworkExtension -import FeedKit import SwiftUI import class Combine.AnyCancellable import BraveWallet @@ -1217,7 +1216,7 @@ public class BrowserViewController: UIViewController { /// Whether or not to show the playlist onboarding callout this session var shouldShowPlaylistOnboardingThisSession = true - fileprivate func showQueuedAlertIfAvailable() { + public func showQueuedAlertIfAvailable() { if let queuedAlertInfo = tabManager.selectedTab?.dequeueJavascriptAlertPrompt() { let alertController = queuedAlertInfo.alertController() alertController.delegate = self @@ -2117,240 +2116,6 @@ public class BrowserViewController: UIViewController { topToolbar.didClickCancel() } } - - func makeShareActivities(for url: URL, tab: Tab?, sourceView: UIView?, sourceRect: CGRect, arrowDirection: UIPopoverArrowDirection) -> [UIActivity] { - var activities = [UIActivity]() - - // Adding SendTabToSelfActivity conditionally to show device selection screen - if !privateBrowsingManager.isPrivateBrowsing, !url.isLocal, !InternalURL.isValid(url: url), !url.isReaderModeURL, - braveCore.syncAPI.isSendTabToSelfVisible { - let sendTabToSelfActivity = SendTabToSelfActivity() { [weak self] in - guard let self = self else { return } - - let deviceList = self.braveCore.sendTabAPI.getListOfSyncedDevices() - let dataSource = SendableTabInfoDataSource( - with: deviceList, - displayTitle: tab?.displayTitle ?? "", - sendableURL: url) - - let controller = SendTabToSelfController(sendTabAPI: self.braveCore.sendTabAPI, dataSource: dataSource) - - controller.sendWebSiteHandler = { [weak self] dataSource in - guard let self = self else { return } - - self.present( - SendTabProcessController(type: .progress, data: dataSource, sendTabAPI: self.braveCore.sendTabAPI), - animated: true, - completion: nil) - } - self.present(controller, animated: true, completion: nil) - } - - activities.append(sendTabToSelfActivity) - } - - if let tab = self.tabManager.selectedTab, tab.secureContentState.shouldDisplayWarning { - if tab.readerModeAvailableOrActive { - // If the reader mode button is occluded due to a secure content state warning add it as an activity - activities.append( - BasicMenuActivity( - title: Strings.toggleReaderMode, - braveSystemImage: "leo.product.speedreader", - callback: { [weak self] in - self?.toggleReaderMode() - } - ) - ) - } - // Any other buttons on the leading side of the location view should be added here as well - } - - let findInPageActivity = FindInPageActivity() { [unowned self] in - if #available(iOS 16.0, *), let findInteraction = self.tabManager.selectedTab?.webView?.findInteraction { - findInteraction.searchText = "" - findInteraction.presentFindNavigator(showingReplace: false) - } else { - self.updateFindInPageVisibility(visible: true) - } - } - - let pageZoomActivity = PageZoomActivity() { [unowned self] in - self.displayPageZoom(visible: true) - } - - activities.append(contentsOf: [findInPageActivity, pageZoomActivity]) - - // These actions don't apply if we're sharing a temporary document - if !url.isFileURL { - // We don't allow to have 2 same favorites. - if !FavoritesHelper.isAlreadyAdded(url) { - activities.append( - AddToFavoritesActivity() { [weak self, weak tab] in - guard let self = self else { return } - - FavoritesHelper.add(url: url, title: tab?.displayTitle) - // Handle App Rating - // Check for review condition after adding a favorite - AppReviewManager.shared.handleAppReview(for: .revised, using: self) - }) - } - - activities.append( - RequestDesktopSiteActivity(tab: tab) { [weak tab] in - tab?.switchUserAgent() - }) - - if Preferences.BraveNews.isEnabled.value, let metadata = tab?.pageMetadata, - !metadata.feeds.isEmpty { - let feeds: [RSSFeedLocation] = metadata.feeds.compactMap { feed in - guard let url = URL(string: feed.href) else { return nil } - return RSSFeedLocation(title: feed.title, url: url) - } - if !feeds.isEmpty { - let addToBraveNews = AddFeedToBraveNewsActivity() { [weak self] in - guard let self = self else { return } - let controller = BraveNewsAddSourceResultsViewController( - dataSource: self.feedDataSource, - searchedURL: url, - rssFeedLocations: feeds, - sourcesAdded: nil - ) - let container = UINavigationController(rootViewController: controller) - let idiom = UIDevice.current.userInterfaceIdiom - container.modalPresentationStyle = idiom == .phone ? .pageSheet : .formSheet - self.present(container, animated: true) - } - activities.append(addToBraveNews) - } - } - - if let webView = tab?.webView, tab?.temporaryDocument == nil { - let createPDFActivity = CreatePDFActivity() { - webView.createPDF { [weak self] result in - dispatchPrecondition(condition: .onQueue(.main)) - guard let self = self else { - return - } - switch result { - case .success(let pdfData): - // Create a valid filename - let validFilenameSet = CharacterSet(charactersIn: ":/") - .union(.newlines) - .union(.controlCharacters) - .union(.illegalCharacters) - let filename = webView.title?.components(separatedBy: validFilenameSet).joined() - let url = URL(fileURLWithPath: NSTemporaryDirectory()) - .appendingPathComponent("\(filename ?? "Untitled").pdf") - do { - try pdfData.write(to: url) - let pdfActivityController = UIActivityViewController(activityItems: [url], applicationActivities: nil) - if let popoverPresentationController = pdfActivityController.popoverPresentationController { - popoverPresentationController.sourceView = sourceView - popoverPresentationController.sourceRect = sourceRect - popoverPresentationController.permittedArrowDirections = arrowDirection - popoverPresentationController.delegate = self - } - self.present(pdfActivityController, animated: true) - } catch { - Logger.module.error("Failed to write PDF to disk: \(error.localizedDescription, privacy: .public)") - } - - case .failure(let error): - Logger.module.error("Failed to create PDF with error: \(error.localizedDescription)") - } - } - } - activities.append(createPDFActivity) - } - - } else { - // Check if it's a feed, url is a temp document file URL - if let selectedTab = tabManager.selectedTab, - (selectedTab.mimeType == "application/xml" || selectedTab.mimeType == "application/json"), - let tabURL = selectedTab.url { - - let parser = FeedParser(URL: url) - if case .success(let feed) = parser.parse() { - let addToBraveNews = AddFeedToBraveNewsActivity() { [weak self] in - guard let self = self else { return } - let controller = BraveNewsAddSourceResultsViewController( - dataSource: self.feedDataSource, - searchedURL: tabURL, - rssFeedLocations: [.init(title: feed.title, url: tabURL)], - sourcesAdded: nil - ) - let container = UINavigationController(rootViewController: controller) - let idiom = UIDevice.current.userInterfaceIdiom - container.modalPresentationStyle = idiom == .phone ? .pageSheet : .formSheet - self.present(container, animated: true) - } - activities.append(addToBraveNews) - } - } - } - - if let webView = tabManager.selectedTab?.webView, - evaluateWebsiteSupportOpenSearchEngine(webView) { - let addSearchEngineActivity = AddSearchEngineActivity() { [weak self] in - self?.addCustomSearchEngineForFocusedElement() - } - - activities.append(addSearchEngineActivity) - } - - if let secureState = tabManager.selectedTab?.secureContentState, secureState != .missingSSL && secureState != .unknown { - let displayCertificateActivity = BasicMenuActivity(title: Strings.displayCertificate, braveSystemImage: "leo.lock.plain") { [weak self] in - self?.displayPageCertificateInfo() - } - activities.append(displayCertificateActivity) - } - - activities.append(ReportWebCompatibilityIssueActivity() { [weak self] in - self?.showSubmitReportView(for: url) - }) - - return activities - } - - func presentActivityViewController(_ url: URL, tab: Tab? = nil, sourceView: UIView?, sourceRect: CGRect, arrowDirection: UIPopoverArrowDirection) { - let activities: [UIActivity] = makeShareActivities( - for: url, - tab: tab, - sourceView: sourceView, - sourceRect: sourceRect, - arrowDirection: arrowDirection - ) - - let controller = ShareExtensionHelper.makeActivityViewController( - selectedURL: url, - selectedTab: tab, - applicationActivities: activities - ) - - controller.completionWithItemsHandler = { [weak self] _, _, _, _ in - self?.cleanUpCreateActivity() - } - - if let popoverPresentationController = controller.popoverPresentationController { - popoverPresentationController.sourceView = sourceView - popoverPresentationController.sourceRect = sourceRect - popoverPresentationController.permittedArrowDirections = arrowDirection - popoverPresentationController.delegate = self - } - - present(controller, animated: true, completion: nil) - } - - private func cleanUpCreateActivity() { - // After dismissing, check to see if there were any prompts we queued up - showQueuedAlertIfAvailable() - - // Usually the popover delegate would handle nil'ing out the references we have to it - // on the BVC when displaying as a popover but the delegate method doesn't seem to be - // invoked on iOS 10. See Bug 1297768 for additional details. - displayedPopoverController = nil - updateDisplayedPopoverProperties = nil - } func displayPageZoom(visible: Bool) { if !visible || pageZoomBar != nil { diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ShareActivity.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ShareActivity.swift new file mode 100644 index 00000000000..256fc0c5618 --- /dev/null +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+ShareActivity.swift @@ -0,0 +1,332 @@ +// 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 os.log +import Preferences +import Shared +import BraveCore +import BraveNews +import Growth +import FeedKit + +extension BrowserViewController { + func makeShareActivities(for url: URL, tab: Tab?, sourceView: UIView?, sourceRect: CGRect, arrowDirection: UIPopoverArrowDirection) -> [UIActivity] { + var activities = [UIActivity]() + + // Copy Clean URL Activity + if !url.isLocal, !InternalURL.isValid(url: url), !url.isReaderModeURL { + let cleanedURL = URLSanitizerServiceFactory.get( + privateMode: tab?.isPrivate ?? true)?.sanitizeURL(url) ?? url + + activities.append( + BasicMenuActivity( + title: Strings.copyCleanLink, + braveSystemImage: "leo.broom", + callback: { + UIPasteboard.general.url = cleanedURL + } + ) + ) + } + + // Send Tab To Self Activity - Show device selection screen + if braveCore.syncAPI.isSendTabToSelfVisible, !privateBrowsingManager.isPrivateBrowsing, + !url.isLocal, !InternalURL.isValid(url: url), !url.isReaderModeURL { + activities.append( + BasicMenuActivity( + title: Strings.OpenTabs.sendWebsiteShareActionTitle, + braveSystemImage: "leo.smartphone.laptop", + callback: { [weak self] in + guard let self = self else { return } + + let deviceList = self.braveCore.sendTabAPI.getListOfSyncedDevices() + let dataSource = SendableTabInfoDataSource( + with: deviceList, + displayTitle: tab?.displayTitle ?? "", + sendableURL: url) + + let controller = SendTabToSelfController(sendTabAPI: self.braveCore.sendTabAPI, dataSource: dataSource) + + controller.sendWebSiteHandler = { [weak self] dataSource in + guard let self = self else { return } + + self.present( + SendTabProcessController(type: .progress, data: dataSource, sendTabAPI: self.braveCore.sendTabAPI), + animated: true, + completion: nil) + } + self.present(controller, animated: true, completion: nil) + } + ) + ) + } + + // Toogle Reader Mode Activity + // If the reader mode button is occluded due to a secure content state warning add it as an activity + if let tab = tabManager.selectedTab, tab.secureContentState.shouldDisplayWarning { + if tab.readerModeAvailableOrActive { + activities.append( + BasicMenuActivity( + title: Strings.toggleReaderMode, + braveSystemImage: "leo.product.speedreader", + callback: { [weak self] in + self?.toggleReaderMode() + } + ) + ) + } + // Any other buttons on the leading side of the location view should be added here as well + } + + // Find In Page Activity + activities.append( + BasicMenuActivity( + title: Strings.findInPage, + braveSystemImage: "leo.search", + callback: { [weak self] in + guard let self = self else { return } + + if #available(iOS 16.0, *), let findInteraction = self.tabManager.selectedTab?.webView?.findInteraction { + findInteraction.searchText = "" + findInteraction.presentFindNavigator(showingReplace: false) + } else { + self.updateFindInPageVisibility(visible: true) + } + } + ) + ) + + // Page Zoom Activity + activities.append( + BasicMenuActivity( + title: Strings.PageZoom.settingsTitle, + braveSystemImage: "leo.font.size", + callback: { [weak self] in + guard let self = self else { return } + + self.displayPageZoom(visible: true) + } + ) + ) + + // Activities when scheme is not `file + // These actions don't apply if we're sharing a temporary document + if !url.isFileURL { + // Add to Favourites Activity + // We don't allow to have 2 same favorites. + if !FavoritesHelper.isAlreadyAdded(url) { + activities.append( + BasicMenuActivity( + title: Strings.addToFavorites, + braveSystemImage: "leo.widget.generic", + callback: { [weak self] in + guard let self = self else { return } + + FavoritesHelper.add(url: url, title: tab?.displayTitle) + // Handle App Rating + // Check for review condition after adding a favorite + AppReviewManager.shared.handleAppReview(for: .revised, using: self) + } + ) + ) + } + + // Request Desktop Site Activity + activities.append( + BasicMenuActivity( + title: tab?.isDesktopSite == true ? Strings.appMenuViewMobileSiteTitleString : Strings.appMenuViewDesktopSiteTitleString, + braveSystemImage: tab?.isDesktopSite == true ? "leo.smartphone" : "leo.monitor", + callback: { + tab?.switchUserAgent() + } + ) + ) + + // Add Feed To Brave News Activity + if Preferences.BraveNews.isEnabled.value, let metadata = tab?.pageMetadata, + !metadata.feeds.isEmpty { + let feeds: [RSSFeedLocation] = metadata.feeds.compactMap { feed in + guard let url = URL(string: feed.href) else { return nil } + return RSSFeedLocation(title: feed.title, url: url) + } + if !feeds.isEmpty { + activities.append( + BasicMenuActivity( + title: Strings.BraveNews.addSourceShareTitle, + braveSystemImage: "leo.rss", + callback: { [weak self] in + guard let self = self else { return } + let controller = BraveNewsAddSourceResultsViewController( + dataSource: self.feedDataSource, + searchedURL: url, + rssFeedLocations: feeds, + sourcesAdded: nil + ) + let container = UINavigationController(rootViewController: controller) + let idiom = UIDevice.current.userInterfaceIdiom + container.modalPresentationStyle = idiom == .phone ? .pageSheet : .formSheet + self.present(container, animated: true) + } + ) + ) + } + } + + // Create PDF Activity + if let webView = tab?.webView, tab?.temporaryDocument == nil { + activities.append( + BasicMenuActivity( + title: Strings.createPDF, + braveSystemImage: "leo.file", + callback: { + webView.createPDF { [weak self] result in + dispatchPrecondition(condition: .onQueue(.main)) + guard let self = self else { + return + } + switch result { + case .success(let pdfData): + // Create a valid filename + let validFilenameSet = CharacterSet(charactersIn: ":/") + .union(.newlines) + .union(.controlCharacters) + .union(.illegalCharacters) + let filename = webView.title?.components(separatedBy: validFilenameSet).joined() + let url = URL(fileURLWithPath: NSTemporaryDirectory()) + .appendingPathComponent("\(filename ?? "Untitled").pdf") + do { + try pdfData.write(to: url) + let pdfActivityController = UIActivityViewController(activityItems: [url], applicationActivities: nil) + if let popoverPresentationController = pdfActivityController.popoverPresentationController { + popoverPresentationController.sourceView = sourceView + popoverPresentationController.sourceRect = sourceRect + popoverPresentationController.permittedArrowDirections = arrowDirection + popoverPresentationController.delegate = self + } + self.present(pdfActivityController, animated: true) + } catch { + Logger.module.error("Failed to write PDF to disk: \(error.localizedDescription, privacy: .public)") + } + + case .failure(let error): + Logger.module.error("Failed to create PDF with error: \(error.localizedDescription)") + } + } + } + ) + ) + } + } else { + // Add Feed To Brave News Activity + // Check if it's a feed, url is a temp document file URL + if let selectedTab = tabManager.selectedTab, + (selectedTab.mimeType == "application/xml" || selectedTab.mimeType == "application/json"), + let tabURL = selectedTab.url { + + let parser = FeedParser(URL: url) + if case .success(let feed) = parser.parse() { + activities.append( + BasicMenuActivity( + title: Strings.BraveNews.addSourceShareTitle, + braveSystemImage: "leo.rss", + callback: { [weak self] in + guard let self = self else { return } + let controller = BraveNewsAddSourceResultsViewController( + dataSource: self.feedDataSource, + searchedURL: tabURL, + rssFeedLocations: [.init(title: feed.title, url: tabURL)], + sourcesAdded: nil + ) + let container = UINavigationController(rootViewController: controller) + let idiom = UIDevice.current.userInterfaceIdiom + container.modalPresentationStyle = idiom == .phone ? .pageSheet : .formSheet + self.present(container, animated: true) + + } + ) + ) + } + } + } + + // Add Search Engine Activity + if let webView = tabManager.selectedTab?.webView, + evaluateWebsiteSupportOpenSearchEngine(webView) { + + activities.append( + BasicMenuActivity( + title: Strings.CustomSearchEngine.customEngineNavigationTitle, + braveSystemImage: "leo.search.zoom-in", + callback: { [weak self] in + self?.addCustomSearchEngineForFocusedElement() + } + ) + ) + } + + // Display Certificate Activity + if let secureState = tabManager.selectedTab?.secureContentState, secureState != .missingSSL && secureState != .unknown { + activities.append( + BasicMenuActivity( + title: Strings.displayCertificate, + braveSystemImage: "leo.lock.plain") { [weak self] in + self?.displayPageCertificateInfo() + } + ) + } + + // Report Web-compat Issue Actibity + activities.append( + BasicMenuActivity( + title: Strings.Shields.reportABrokenSite, + braveSystemImage: "leo.warning.triangle-outline") { [weak self] in + self?.showSubmitReportView(for: url) + } + ) + + return activities + } + + func presentActivityViewController(_ url: URL, tab: Tab? = nil, sourceView: UIView?, sourceRect: CGRect, arrowDirection: UIPopoverArrowDirection) { + let activities: [UIActivity] = makeShareActivities( + for: url, + tab: tab, + sourceView: sourceView, + sourceRect: sourceRect, + arrowDirection: arrowDirection + ) + + let controller = ShareExtensionHelper.makeActivityViewController( + selectedURL: url, + selectedTab: tab, + applicationActivities: activities + ) + + controller.completionWithItemsHandler = { [weak self] _, _, _, _ in + self?.cleanUpCreateActivity() + } + + if let popoverPresentationController = controller.popoverPresentationController { + popoverPresentationController.sourceView = sourceView + popoverPresentationController.sourceRect = sourceRect + popoverPresentationController.permittedArrowDirections = arrowDirection + popoverPresentationController.delegate = self + } + + present(controller, animated: true, completion: nil) + } + + private func cleanUpCreateActivity() { + // After dismissing, check to see if there were any prompts we queued up + showQueuedAlertIfAvailable() + + // Usually the popover delegate would handle nil'ing out the references we have to it + // on the BVC when displaying as a popover but the delegate method doesn't seem to be + // invoked on iOS 10. See Bug 1297768 for additional details. + displayedPopoverController = nil + updateDisplayedPopoverProperties = nil + } +} diff --git a/Sources/Brave/Frontend/Share/AddFeedToBraveNewsActivity.swift b/Sources/Brave/Frontend/Share/AddFeedToBraveNewsActivity.swift deleted file mode 100644 index a9de45e5873..00000000000 --- a/Sources/Brave/Frontend/Share/AddFeedToBraveNewsActivity.swift +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2021 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 Shared -import UIKit -import SwiftUI - -class AddFeedToBraveNewsActivity: UIActivity, MenuActivity { - fileprivate let callback: () -> Void - - init(callback: @escaping () -> Void) { - self.callback = callback - } - - override var activityTitle: String? { - return Strings.BraveNews.addSourceShareTitle - } - - override var activityImage: UIImage? { - UIImage(braveSystemNamed: "leo.rss")?.applyingSymbolConfiguration(.init(scale: .large)) - } - - var menuImage: Image { - Image(braveSystemName: "leo.rss") - } - - override func perform() { - callback() - activityDidFinish(true) - } - - override func canPerform(withActivityItems activityItems: [Any]) -> Bool { - return true - } -} diff --git a/Sources/Brave/Frontend/Share/AddSearchEngineActivity.swift b/Sources/Brave/Frontend/Share/AddSearchEngineActivity.swift deleted file mode 100644 index bcb3df79b76..00000000000 --- a/Sources/Brave/Frontend/Share/AddSearchEngineActivity.swift +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2021 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 Shared -import UIKit -import SwiftUI - -class AddSearchEngineActivity: UIActivity, MenuActivity { - fileprivate let callback: () -> Void - - init(callback: @escaping () -> Void) { - self.callback = callback - } - - override var activityTitle: String? { - return Strings.CustomSearchEngine.customEngineNavigationTitle - } - - override var activityImage: UIImage? { - return UIImage(braveSystemNamed: "leo.search.zoom-in")?.applyingSymbolConfiguration(.init(scale: .large)) - } - - var menuImage: Image { - Image(braveSystemName: "leo.search.zoom-in") - } - - override func perform() { - callback() - activityDidFinish(true) - } - - override func canPerform(withActivityItems activityItems: [Any]) -> Bool { - return true - } -} diff --git a/Sources/Brave/Frontend/Share/AddToFavoritesActivity.swift b/Sources/Brave/Frontend/Share/AddToFavoritesActivity.swift deleted file mode 100644 index 1f3abd3e7a4..00000000000 --- a/Sources/Brave/Frontend/Share/AddToFavoritesActivity.swift +++ /dev/null @@ -1,37 +0,0 @@ -/* 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 Shared -import UIKit -import SwiftUI - -class AddToFavoritesActivity: UIActivity, MenuActivity { - fileprivate let callback: () -> Void - - init(callback: @escaping () -> Void) { - self.callback = callback - } - - override var activityTitle: String? { - return Strings.addToFavorites - } - - override var activityImage: UIImage? { - return UIImage(braveSystemNamed: "leo.widget.generic")?.applyingSymbolConfiguration(.init(scale: .large)) - } - - var menuImage: Image { - Image(braveSystemName: "leo.widget.generic") - } - - override func perform() { - callback() - activityDidFinish(true) - } - - override func canPerform(withActivityItems activityItems: [Any]) -> Bool { - return true - } -} diff --git a/Sources/Brave/Frontend/Share/CreatePDFActivity.swift b/Sources/Brave/Frontend/Share/CreatePDFActivity.swift deleted file mode 100644 index e84edde04d8..00000000000 --- a/Sources/Brave/Frontend/Share/CreatePDFActivity.swift +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2020 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 Shared -import WebKit -import os.log -import SwiftUI - -/// An activity that will create a PDF of a given web page -class CreatePDFActivity: UIActivity, MenuActivity { - private let callback: () -> Void - - init(callback: @escaping () -> Void) { - self.callback = callback - super.init() - } - - override var activityTitle: String? { - Strings.createPDF - } - - override var activityImage: UIImage? { - UIImage(braveSystemNamed: "leo.file")?.applyingSymbolConfiguration(.init(scale: .large)) - } - - var menuImage: Image { - Image(braveSystemName: "leo.file") - } - - override func perform() { - callback() - activityDidFinish(true) - } - - override func canPerform(withActivityItems activityItems: [Any]) -> Bool { - return true - } -} diff --git a/Sources/Brave/Frontend/Share/FindInPageActivity.swift b/Sources/Brave/Frontend/Share/FindInPageActivity.swift deleted file mode 100644 index 7ac45be1882..00000000000 --- a/Sources/Brave/Frontend/Share/FindInPageActivity.swift +++ /dev/null @@ -1,37 +0,0 @@ -/* 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 Shared -import UIKit -import SwiftUI - -class FindInPageActivity: UIActivity, MenuActivity { - fileprivate let callback: () -> Void - - init(callback: @escaping () -> Void) { - self.callback = callback - } - - override var activityTitle: String? { - return Strings.findInPage - } - - override var activityImage: UIImage? { - return UIImage(braveSystemNamed: "leo.search")?.applyingSymbolConfiguration(.init(scale: .large)) - } - - var menuImage: Image { - Image(braveSystemName: "leo.search") - } - - override func perform() { - callback() - activityDidFinish(true) - } - - override func canPerform(withActivityItems activityItems: [Any]) -> Bool { - return true - } -} diff --git a/Sources/Brave/Frontend/Share/PageZoomActivity.swift b/Sources/Brave/Frontend/Share/PageZoomActivity.swift deleted file mode 100644 index 9ebbc2c780e..00000000000 --- a/Sources/Brave/Frontend/Share/PageZoomActivity.swift +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022 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 Shared -import UIKit -import SwiftUI - -class PageZoomActivity: UIActivity, MenuActivity { - fileprivate let callback: () -> Void - - init(callback: @escaping () -> Void) { - self.callback = callback - } - - override var activityTitle: String? { - return Strings.PageZoom.settingsTitle - } - - override var activityImage: UIImage? { - return UIImage(braveSystemNamed: "leo.font.size")?.applyingSymbolConfiguration(.init(scale: .large)) - } - - var menuImage: Image { - Image(braveSystemName: "leo.font.size") - } - - override func perform() { - callback() - activityDidFinish(true) - } - - override func canPerform(withActivityItems activityItems: [Any]) -> Bool { - return true - } -} diff --git a/Sources/Brave/Frontend/Share/ReportWebcompatIssueActivity.swift b/Sources/Brave/Frontend/Share/ReportWebcompatIssueActivity.swift deleted file mode 100644 index 8f75685aca5..00000000000 --- a/Sources/Brave/Frontend/Share/ReportWebcompatIssueActivity.swift +++ /dev/null @@ -1,42 +0,0 @@ -// 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 https://mozilla.org/MPL/2.0/. - -import Foundation -import Strings -import UIKit -import SwiftUI - -class ReportWebCompatibilityIssueActivity: UIActivity, MenuActivity { - private let callback: () -> Void - - init(callback: @escaping () -> Void) { - self.callback = callback - } - - override var activityTitle: String? { - Strings.Shields.reportABrokenSite - } - - private var imageName: String { - "leo.warning.triangle-outline" - } - - override var activityImage: UIImage? { - UIImage(braveSystemNamed: imageName)?.applyingSymbolConfiguration(.init(scale: .large)) - } - - var menuImage: Image { - Image(braveSystemName: imageName) - } - - override func perform() { - callback() - activityDidFinish(true) - } - - override func canPerform(withActivityItems activityItems: [Any]) -> Bool { - return true - } -} diff --git a/Sources/Brave/Frontend/Share/RequestDesktopSiteActivity.swift b/Sources/Brave/Frontend/Share/RequestDesktopSiteActivity.swift deleted file mode 100644 index eac3379a432..00000000000 --- a/Sources/Brave/Frontend/Share/RequestDesktopSiteActivity.swift +++ /dev/null @@ -1,43 +0,0 @@ -/* 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 Shared -import UIKit -import SwiftUI - -class RequestDesktopSiteActivity: UIActivity, MenuActivity { - private weak var tab: Tab? - fileprivate let callback: () -> Void - - init(tab: Tab?, callback: @escaping () -> Void) { - self.tab = tab - self.callback = callback - } - - override var activityTitle: String? { - tab?.isDesktopSite == true ? Strings.appMenuViewMobileSiteTitleString : Strings.appMenuViewDesktopSiteTitleString - } - - private var imageName: String { - tab?.isDesktopSite == true ? "leo.smartphone" : "leo.monitor" - } - - override var activityImage: UIImage? { - UIImage(braveSystemNamed: imageName)?.applyingSymbolConfiguration(.init(scale: .large)) - } - - var menuImage: Image { - Image(braveSystemName: imageName) - } - - override func perform() { - callback() - activityDidFinish(true) - } - - override func canPerform(withActivityItems activityItems: [Any]) -> Bool { - return true - } -} diff --git a/Sources/Brave/Frontend/Share/SendTabToSelfActivity.swift b/Sources/Brave/Frontend/Share/SendTabToSelfActivity.swift deleted file mode 100644 index 6d280cc7c79..00000000000 --- a/Sources/Brave/Frontend/Share/SendTabToSelfActivity.swift +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022 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 Shared -import UIKit -import SwiftUI - -class SendTabToSelfActivity: UIActivity, MenuActivity { - fileprivate let callback: () -> Void - - init(callback: @escaping () -> Void) { - self.callback = callback - } - - override var activityTitle: String? { - return Strings.OpenTabs.sendWebsiteShareActionTitle - } - - override var activityImage: UIImage? { - return UIImage(braveSystemNamed: "leo.smartphone.laptop")?.applyingSymbolConfiguration(.init(scale: .large)) - } - - var menuImage: Image { - Image(braveSystemName: "leo.smartphone.laptop") - } - - override func perform() { - callback() - activityDidFinish(true) - } - - override func canPerform(withActivityItems activityItems: [Any]) -> Bool { - return true - } -}