Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interstitial not showing deceptive site warning. Fix URLBar Eliding #26107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,15 @@ public class BrowserViewController: UIViewController {
if !title.isEmpty && title != tab.lastTitle {
navigateInTab(tab: tab)
tabsBar.updateSelectedTabTitle()

if let url = webView.url,
webView.responds(to: Selector(("_safeBrowsingWarning")))
&& webView.value(forKey: "_safeBrowsingWarning") != nil
{
tab.url = url // We can update the URL whenever showing an interstitial warning
updateToolbarCurrentURL(url.displayURL)
updateInContentHomePanel(url)
}
}
case .canGoBack, .canGoForward:
guard tab === tabManager.selectedTab else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,7 @@ extension TabManager: WKNavigationDelegate {
}

func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
print("HERE!!!")
}

/// Called when the WKWebView's content process has gone away. If this happens for the currently selected tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class CollapsedURLBarView: UIView {
Strings.PageSecurityView.signIntoWebsiteURLBarTitle
} else {
URLFormatter.formatURLOrigin(
forDisplayOmitSchemePathAndTrivialSubdomains: $0.absoluteString
forDisplayOmitSchemePathAndTrivialSubdomains: $0.scheme != "http"
|| $0.scheme != "https"
? URLOrigin(url: $0).url?.absoluteString ?? $0.absoluteString : $0.absoluteString
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class TabLocationView: UIView {

private let placeholderLabel = UILabel().then {
$0.text = Strings.tabToolbarSearchAddressPlaceholderText
$0.setContentHuggingPriority(.defaultHigh, for: .horizontal)
$0.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
$0.isHidden = true
$0.adjustsFontSizeToFitWidth = true
$0.minimumScaleFactor = 0.5
Expand Down Expand Up @@ -450,23 +452,30 @@ class TabLocationView: UIView {
}

private func updateURLBarWithText() {
if let url = url, let internalURL = InternalURL(url), internalURL.isBasicAuthURL {
urlDisplayLabel.text = Strings.PageSecurityView.signIntoWebsiteURLBarTitle
} else {
// Matches LocationBarModelImpl::GetFormattedURL in Chromium (except for omitHTTP)
// components/omnibox/browser/location_bar_model_impl.cc
// TODO: Export omnibox related APIs and use directly
if let url = url {
urlDisplayLabel.text = URLFormatter.formatURL(
url.scheme == "blob" ? URLOrigin(url: url).url?.absoluteString ?? "" : url.absoluteString,
formatTypes: [
.trimAfterHost, .omitHTTP, .omitHTTPS, .omitTrivialSubdomains, .omitDefaults,
],
unescapeOptions: .normal
)
if let url = url {
if let internalURL = InternalURL(url), internalURL.isBasicAuthURL {
urlDisplayLabel.text = Strings.PageSecurityView.signIntoWebsiteURLBarTitle
} else {
urlDisplayLabel.text = ""
// Matches LocationBarModelImpl::GetFormattedURL in Chromium (except for omitHTTP)
// components/omnibox/browser/location_bar_model_impl.cc
// TODO: Export omnibox related APIs and use directly

// If we can't parse the origin and the URL can't be classified via AutoCompleteClassifier
// the URL is likely a broken deceptive URL. Example: `about:blank#https://apple.com`
if URLOrigin(url: url).url == nil && URIFixup.getURL(url.absoluteString) == nil {
urlDisplayLabel.text = ""
} else {
urlDisplayLabel.text = URLFormatter.formatURL(
URLOrigin(url: url).url?.absoluteString ?? url.absoluteString,
formatTypes: [
.trimAfterHost, .omitHTTPS, .omitTrivialSubdomains,
],
unescapeOptions: .normal
)
}
}
} else {
urlDisplayLabel.text = ""
}

reloadButton.isHidden = url == nil
Expand Down Expand Up @@ -529,7 +538,8 @@ private class DisplayURLLabel: UILabel {

override init(frame: CGRect) {
super.init(frame: frame)

self.semanticContentAttribute = .forceLeftToRight
self.textAlignment = .left
addSubview(clippingFade)
}

Expand All @@ -538,23 +548,51 @@ private class DisplayURLLabel: UILabel {

override var font: UIFont! {
didSet {
updateTextSize(from: text)
updateText()
updateTextSize()
}
}

override var text: String? {
didSet {
clippingFade.isHidden = true
if oldValue != text {
updateTextSize(from: text)
updateText()
updateTextSize()
detectLanguageForNaturalDirectionClipping()
}
setNeedsDisplay()
}
}

private func updateTextSize(from value: String?) {
textSize = (value as? NSString)?.size(withAttributes: [.font: font!]) ?? .zero
private func updateText() {
if let text = text {
let attributedString = NSMutableAttributedString(string: text)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = .byClipping
paragraphStyle.baseWritingDirection = .leftToRight

if let font = font {
attributedString.addAttribute(
.font,
value: font,
range: NSRange(location: 0, length: attributedString.length)
)
}

attributedString.addAttribute(
.paragraphStyle,
value: paragraphStyle,
range: NSRange(location: 0, length: attributedString.length)
)
self.attributedText = attributedString
} else {
self.attributedText = nil
}
}

private func updateTextSize() {
textSize = attributedText?.size() ?? .zero
setNeedsLayout()
setNeedsDisplay()
}
Expand All @@ -565,7 +603,7 @@ private class DisplayURLLabel: UILabel {
case .arabic, .hebrew, .persian, .urdu:
isRightToLeft = true
default:
isRightToLeft = false
isRightToLeft = ["http", "https"].contains(URL(string: text)?.scheme ?? "") // Only left-align if the scheme is not http/https.
}
// Update clipping fade direction
clippingFade.gradientLayer.startPoint = .init(x: isRightToLeft ? 1 : 0, y: 0.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class AutocompleteTextField: UITextField, UITextFieldDelegate {
init(privateBrowsingManager: PrivateBrowsingManager) {
self.privateBrowsingManager = privateBrowsingManager
super.init(frame: .zero)
self.semanticContentAttribute = .forceLeftToRight
self.textAlignment = .left

super.delegate = self
super.addTarget(
Expand Down
Loading