mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Merge commit '330fed199d'
This commit is contained in:
commit
207c971358
3 changed files with 44 additions and 13 deletions
|
|
@ -254,16 +254,19 @@ private final class QuickShareToastScreenComponent: Component {
|
|||
|
||||
let contentSize = self.content.update(
|
||||
transition: transition,
|
||||
component: AnyComponent(MultilineTextComponent(text: .markdown(
|
||||
text: tooltipText,
|
||||
attributes: MarkdownAttributes(
|
||||
body: MarkdownAttributeSet(font: Font.regular(14.0), textColor: .white),
|
||||
bold: MarkdownAttributeSet(font: Font.semibold(14.0), textColor: environment.theme.list.itemAccentColor.withMultiplied(hue: 0.933, saturation: 0.61, brightness: 1.0)),
|
||||
link: MarkdownAttributeSet(font: Font.regular(14.0), textColor: .white),
|
||||
linkAttribute: { _ in return nil })
|
||||
))),
|
||||
component: AnyComponent(MultilineTextComponent(
|
||||
text: .markdown(
|
||||
text: tooltipText,
|
||||
attributes: MarkdownAttributes(
|
||||
body: MarkdownAttributeSet(font: Font.regular(14.0), textColor: .white),
|
||||
bold: MarkdownAttributeSet(font: Font.semibold(14.0), textColor: environment.theme.list.itemAccentColor.withMultiplied(hue: 0.933, saturation: 0.61, brightness: 1.0)),
|
||||
link: MarkdownAttributeSet(font: Font.regular(14.0), textColor: .white),
|
||||
linkAttribute: { _ in return nil })
|
||||
),
|
||||
maximumNumberOfLines: 2
|
||||
)),
|
||||
environment: {},
|
||||
containerSize: CGSize(width: availableContentSize.width - contentInsets.left - contentInsets.right - spacing - iconSize.width - actionButtonSize.width - 16.0 - 4.0, height: availableContentSize.height)
|
||||
containerSize: CGSize(width: availableContentSize.width - contentInsets.left - contentInsets.right - spacing - iconSize.width - actionButtonSize.width - 16.0 - 8.0, height: availableContentSize.height)
|
||||
)
|
||||
|
||||
var contentHeight: CGFloat = 0.0
|
||||
|
|
@ -313,7 +316,7 @@ private final class QuickShareToastScreenComponent: Component {
|
|||
|
||||
self.backgroundView.updateColor(color: UIColor(white: 0.0, alpha: 0.7), transition: transition.containedViewLayoutTransition)
|
||||
|
||||
self.backgroundView.update(size: backgroundFrame.size, cornerRadius: 14.0, transition: transition.containedViewLayoutTransition)
|
||||
self.backgroundView.update(size: backgroundFrame.size, cornerRadius: backgroundFrame.height * 0.5, transition: transition.containedViewLayoutTransition)
|
||||
transition.setFrame(view: self.backgroundView, frame: backgroundFrame)
|
||||
transition.setFrame(view: self.contentView, frame: CGRect(origin: .zero, size: backgroundFrame.size))
|
||||
|
||||
|
|
|
|||
|
|
@ -516,7 +516,12 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||
return
|
||||
}
|
||||
#endif*/
|
||||
self.webView?.bindTrustedOrigin(from: url)
|
||||
|
||||
if !"".isEmpty {
|
||||
self.webView?.bindTrustedOrigin(from: url)
|
||||
} else {
|
||||
self.webView?.setupEventProxySource()
|
||||
}
|
||||
self.webView?.load(URLRequest(url: url))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,19 @@ private func jsStringLiteral(_ value: String) -> String {
|
|||
return "\"\""
|
||||
}
|
||||
|
||||
private func eventProxySource(trustedOrigin: String) -> String {
|
||||
private func eventProxySource() -> String {
|
||||
return """
|
||||
(function() {
|
||||
var TelegramWebviewProxyProto = function() {};
|
||||
TelegramWebviewProxyProto.prototype.postEvent = function(eventName, eventData) {
|
||||
window.webkit.messageHandlers.performAction.postMessage({'eventName': eventName, 'eventData': eventData});
|
||||
};
|
||||
window.TelegramWebviewProxy = new TelegramWebviewProxyProto();
|
||||
})();
|
||||
"""
|
||||
}
|
||||
|
||||
private func securedEventProxySource(trustedOrigin: String) -> String {
|
||||
return """
|
||||
(function() {
|
||||
if (window.location.origin !== \(jsStringLiteral(trustedOrigin))) {
|
||||
|
|
@ -202,6 +214,7 @@ final class WebAppWebView: WKWebView {
|
|||
print()
|
||||
}
|
||||
|
||||
var useSecuredEventProxy = true
|
||||
func bindTrustedOrigin(from url: URL) {
|
||||
guard self.trustedOrigin == nil else {
|
||||
return
|
||||
|
|
@ -212,7 +225,14 @@ final class WebAppWebView: WKWebView {
|
|||
|
||||
self.trustedOrigin = origin
|
||||
|
||||
let eventProxyScript = WKUserScript(source: eventProxySource(trustedOrigin: origin), injectionTime: .atDocumentStart, forMainFrameOnly: true)
|
||||
let eventProxyScript = WKUserScript(source: securedEventProxySource(trustedOrigin: origin), injectionTime: .atDocumentStart, forMainFrameOnly: true)
|
||||
self.configuration.userContentController.addUserScript(eventProxyScript)
|
||||
}
|
||||
|
||||
func setupEventProxySource() {
|
||||
self.useSecuredEventProxy = false
|
||||
|
||||
let eventProxyScript = WKUserScript(source: eventProxySource(), injectionTime: .atDocumentStart, forMainFrameOnly: true)
|
||||
self.configuration.userContentController.addUserScript(eventProxyScript)
|
||||
}
|
||||
|
||||
|
|
@ -220,6 +240,9 @@ final class WebAppWebView: WKWebView {
|
|||
guard message.frameInfo.isMainFrame else {
|
||||
return false
|
||||
}
|
||||
if !self.useSecuredEventProxy {
|
||||
return true
|
||||
}
|
||||
guard let trustedOrigin = self.trustedOrigin else {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue