-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix brave/brave-ios#8516: Add Open in Brave to iOS Share Sheet Action…
… (Action Extension) (brave/brave-ios#8682)
- Loading branch information
1 parent
1e11607
commit 939d2a4
Showing
25 changed files
with
752 additions
and
1 deletion.
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,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>BRAVE_URL_SCHEME</key> | ||
<string>$(BRAVE_URL_SCHEME)</string> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>Open in Brave</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>XPC!</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>$(BRAVE_VERSION)</string> | ||
<key>CFBundleVersion</key> | ||
<string>$(BRAVE_BUILD_ID)</string> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionAttributes</key> | ||
<dict> | ||
<key>NSExtensionActivationRule</key> | ||
<dict> | ||
<key>NSExtensionActivationSupportsText</key> | ||
<true/> | ||
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key> | ||
<integer>1</integer> | ||
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key> | ||
<integer>1</integer> | ||
</dict> | ||
</dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.ui-services</string> | ||
<key>NSExtensionPrincipalClass</key> | ||
<string>ActionExtension.ActionToBraveViewController</string> | ||
</dict> | ||
</dict> | ||
</plist> |
14 changes: 14 additions & 0 deletions
14
...tionExtension/ActionExtensionIcons.xcassets/ActionExtensionIcons.appiconset/Contents.json
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,14 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "brave-icon-outline.png", | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+28.8 KB
...nExtensionIcons.xcassets/ActionExtensionIcons.appiconset/brave-icon-outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions
6
App/ActionExtension/ActionExtensionIcons.xcassets/Contents.json
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
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,118 @@ | ||
// Copyright 2024 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 MobileCoreServices | ||
import UniformTypeIdentifiers | ||
|
||
class ActionToBraveViewController: UIViewController { | ||
|
||
private enum SchemeType { | ||
case url, query | ||
} | ||
|
||
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
|
||
// Get the item[s] for handling from the extension context | ||
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 | ||
} | ||
} | ||
} | ||
} | ||
|
||
func done() { | ||
// Return any edited content to the host app, in this case empty | ||
extensionContext?.completeRequest(returningItems: [], completionHandler: nil) | ||
} | ||
|
||
private func loadAttachmentFor(type: SchemeType, using provider: NSItemProvider) { | ||
let typeIdentifier: String = type == .query ? UTType.text.identifier : UTType.url.identifier | ||
|
||
provider.loadItem(forTypeIdentifier: typeIdentifier) { item, error in | ||
DispatchQueue.main.async { | ||
|
||
guard let schemeUrl = self.constructSchemeURL(for: type, with: item) else { | ||
self.done() | ||
return | ||
} | ||
|
||
self.openBrowser(with: schemeUrl) | ||
} | ||
} | ||
} | ||
|
||
private func constructSchemeURL(for schemeType: SchemeType, with item: NSSecureCoding?) -> URL? { | ||
switch schemeType { | ||
case .query: | ||
guard let item = item as? String else { | ||
return nil | ||
} | ||
|
||
return createURL(for: .query, with: item) | ||
|
||
case .url: | ||
// The first URL found within item url absolute string | ||
guard let item = (item as? URL)?.absoluteString, | ||
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue), | ||
let match = detector.firstMatch(in: item, options: [], range: NSRange(location: 0, length: item.count)), | ||
let range = Range(match.range, in: item), | ||
let queryURL = URL(string: String(item[range]))?.absoluteString else { | ||
return nil | ||
} | ||
|
||
return createURL(for: .url, with: queryURL) | ||
} | ||
|
||
} | ||
|
||
private func createURL(for schemeType: SchemeType, with value: String) -> URL? { | ||
var queryItem: URLQueryItem | ||
var components = URLComponents() | ||
components.scheme = Bundle.main.infoDictionary?["BRAVE_URL_SCHEME"] as? String ?? "brave" | ||
|
||
switch schemeType { | ||
case .query: | ||
queryItem = URLQueryItem(name: "q", value: value) | ||
components.host = "search" | ||
case .url: | ||
queryItem = URLQueryItem(name: "url", value: value) | ||
components.host = "open-url" | ||
} | ||
|
||
components.queryItems = [queryItem] | ||
return components.url | ||
} | ||
|
||
private func openBrowser(with url: URL) { | ||
var responder = self as UIResponder? | ||
|
||
while let currentResponder = responder { | ||
let selector = sel_registerName("openURL:") | ||
if currentResponder.responds(to: selector) { | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 0) { | ||
Thread.detachNewThreadSelector(selector, toTarget: currentResponder, with: (url as NSURL)) | ||
} | ||
} | ||
responder = currentResponder.next | ||
} | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { | ||
self.done() | ||
} | ||
} | ||
} |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "In Brave öffnen"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Open in Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Abrir en Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Ouvrir dans Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Buka di Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Apri con Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Brave で開く"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Brave에서 열기"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Buka dalam Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Åpne i Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Otwórz w Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Abrir no Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Открыть в Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Öppna i Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Brave ile Aç"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "Відкрити в Brave"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "以 Brave 開啟"; |
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,2 @@ | ||
/* Bundle display name */ | ||
"CFBundleDisplayName" = "在 Brave 中打开"; |
Oops, something went wrong.