Skip to content

Commit

Permalink
Merge pull request brave#23969 from brave/ios/bugfix/action-extension…
Browse files Browse the repository at this point in the history
…-file
  • Loading branch information
soner-yuksel authored Jun 28, 2024
2 parents 0b08de5 + e702542 commit 70203ed
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ class ActionToBraveViewController: UIViewController {
for item in extensionContext?.inputItems as? [NSExtensionItem] ?? [] {
for provider in item.attachments ?? [] {

// Opening browser with search url
if provider.hasItemConformingToTypeIdentifier(UTType.text.identifier) {
loadAttachmentFor(type: .query, using: provider)
break
}

// Opening browser with site
if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
loadAttachmentFor(type: .url, using: provider)
break
} else {
// Opening browser with search url
loadAttachmentFor(type: .query, using: provider)
break
}
}
}
Expand Down
24 changes: 20 additions & 4 deletions ios/brave-ios/App/iOS/Delegates/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,36 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
return
}

contexts.forEach({
for context in contexts {
guard
let routerpath = NavigationPath(
url: $0.url,
url: context.url,
isPrivateBrowsing: scene.browserViewController?.privateBrowsingManager.isPrivateBrowsing
== true
)
else {
Logger.module.error("[SCENE] - Invalid Navigation Path: \($0.url)")
Logger.module.error("[SCENE] - Invalid Navigation Path: \(context.url)")
return
}

if case .url(let navigationPathURL, _) = routerpath, let pathURL = navigationPathURL,
pathURL.isFileURL
{
defer {
pathURL.stopAccessingSecurityScopedResource()
}

let canAccessFileURL = pathURL.startAccessingSecurityScopedResource()

if !canAccessFileURL {
//File can not be accessed pass the url text to search engine
scene.browserViewController?.submitSearchText(pathURL.absoluteString)
continue
}
}

scene.browserViewController?.handleNavigationPath(path: routerpath)
})
}
}

func scene(_ scene: UIScene, didUpdate userActivity: NSUserActivity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,34 +395,6 @@ extension BrowserViewController: TopToolbarDelegate {
return false
}

func submitSearchText(_ text: String, isBraveSearchPromotion: Bool = false) {
var engine = profile.searchEngines.defaultEngine(
forType: privateBrowsingManager.isPrivateBrowsing ? .privateMode : .standard
)

if isBraveSearchPromotion {
let braveSearchEngine = profile.searchEngines.orderedEngines.first {
$0.shortName == OpenSearchEngine.EngineNames.brave
}

if let searchEngine = braveSearchEngine {
engine = searchEngine
}
}

if let searchURL = engine.searchURLForQuery(
text,
isBraveSearchPromotion: isBraveSearchPromotion
) {
// We couldn't find a matching search keyword, so do a search query.
finishEditingAndSubmit(searchURL)
} else {
// We still don't have a valid URL, so something is broken. Give up.
print("Error handling URL entry: \"\(text)\".")
assertionFailure("Couldn't generate search URL: \(text)")
}
}

func topToolbarDidEnterOverlayMode(_ topToolbar: TopToolbarView) {
updateTabsBarVisibility()
displayFavoritesController()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3455,6 +3455,34 @@ extension BrowserViewController {
NavigationPath.handle(nav: path, with: self)
}
}

public func submitSearchText(_ text: String, isBraveSearchPromotion: Bool = false) {
var engine = profile.searchEngines.defaultEngine(
forType: privateBrowsingManager.isPrivateBrowsing ? .privateMode : .standard
)

if isBraveSearchPromotion {
let braveSearchEngine = profile.searchEngines.orderedEngines.first {
$0.shortName == OpenSearchEngine.EngineNames.brave
}

if let searchEngine = braveSearchEngine {
engine = searchEngine
}
}

if let searchURL = engine.searchURLForQuery(
text,
isBraveSearchPromotion: isBraveSearchPromotion
) {
// We couldn't find a matching search keyword, so do a search query.
finishEditingAndSubmit(searchURL)
} else {
// We still don't have a valid URL, so something is broken. Give up.
print("Error handling URL entry: \"\(text)\".")
assertionFailure("Couldn't generate search URL: \(text)")
}
}
}

extension BrowserViewController {
Expand Down
5 changes: 1 addition & 4 deletions ios/brave-ios/Sources/Brave/Frontend/Browser/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,8 @@ class Tab: NSObject {
if let webView = webView {
lastRequest = request
sslPinningError = nil
if let url = request.url {
if url.isFileURL, request.isPrivileged {
return webView.loadFileURL(url, allowingReadAccessTo: url)
}

if let url = request.url {
// Donate Custom Intent Open Website
if url.isSecureWebPage(), !isPrivate {
ActivityShortcutManager.shared.donateCustomIntent(
Expand Down

0 comments on commit 70203ed

Please sign in to comment.