-
Notifications
You must be signed in to change notification settings - Fork 922
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix interstitial not showing deceptive site warning. Fix URLBar Eliding #26107
Conversation
19268ec
to
1664850
Compare
Copy code from #26099 and handle data, about, file, wss, etc schemes.
1664850
to
f6b7742
Compare
ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift
Outdated
Show resolved
Hide resolved
ios/brave-ios/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/CollapsedURLBarView.swift
Outdated
Show resolved
Hide resolved
URLFormatter.formatURLOrigin( | ||
forDisplayOmitSchemePathAndTrivialSubdomains: $0.absoluteString | ||
) | ||
if URLOrigin(url: $0).url == nil && URIFixup.getURL($0.absoluteString) == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are trying to check here? URLOrigin.url
being nil could mean the origin is opaque or it could mean the resulting GURL
is not valid (the origin itself doesn't have a valid scheme/host/port tuple), or even the GURL
to NSURL
conversion failed. Why are we then checking URIFixup
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by opaque? Like about:home?
The reason for the URIFixup is because if it returns null, it's not a valid URL at all. It also checks about: scheme URLs via the AutoCompleteClassifier which is what Chrome does. So it'll return nil for all about: URLs :)
ios/brave-ios/Sources/Brave/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift
Outdated
Show resolved
Hide resolved
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this all needed when we're already overriding the underlying drawText
method to adjust the visible rect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The underlying draw text does not properly handle right alignment in Arabic. I tested a mixed URL consisting of English and Arabic and the underlying code will always right align which is wrong if the domain itself is English (left aligned).
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic shouldn't go here, which is primarily for determining RTL language modes. Instead you should introduce a new variable that is set when text
is set that will store whether or not the underlying URL is a web scheme one. You're already doing that when you do URLOrigin(...).url
, you could store the origin and check the scheme directly instead in the drawText
override. This also may mean adjusting where the // Update clipping fade direction
logic goes which is usually set right below this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
if let text = text { | ||
isWebScheme = ["http", "https"].contains(URL(string: text)?.scheme ?? "") | ||
} else { | ||
isWebScheme = false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You set this after calling detectLanguageForNaturalDirectionClipping
which relies on it when updating the gradientLayer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably need to set this before updateText
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDIT: Fixed.
@@ -628,7 +634,7 @@ private class DisplayURLLabel: UILabel { | |||
super.layoutSubviews() | |||
|
|||
clippingFade.frame = .init( | |||
x: isRightToLeft ? bounds.width - 20 : 0, | |||
x: isRightToLeft && isWebScheme ? bounds.width - 20 : 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be isRightToLeft || !isWebScheme
since you want the clipping on the trailing edge if its not a web scheme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed everything: https://github.com/brave/internal/issues/1210#issuecomment-2427950790
and verified everything is working properly again.
So Arabic is displaying the URLs correctly, even if they contain RTL characters.
…ng (#26107) * Fix interstitial not showing deceptive site warning. Fix URLBar Eliding * Fix left-alignment and URL parsing for URL-Bar display * Left align URLs if they are NOT http/https. If the URL-Bar is RTL, then right align them.
…ng (#26107) * Fix interstitial not showing deceptive site warning. Fix URLBar Eliding * Fix left-alignment and URL parsing for URL-Bar display * Left align URLs if they are NOT http/https. If the URL-Bar is RTL, then right align them.
…ng (#26107) * Fix interstitial not showing deceptive site warning. Fix URLBar Eliding * Fix left-alignment and URL parsing for URL-Bar display * Left align URLs if they are NOT http/https. If the URL-Bar is RTL, then right align them.
Released in v1.73.37 |
Verification PASSED on
Verification notes can be found via https://github.com/brave/internal/issues/1210#issuecomment-2430624953. |
…ng (1.72.x) (#26150) Fix interstitial not showing deceptive site warning. Fix URLBar Eliding (#26107) * Fix interstitial not showing deceptive site warning. Fix URLBar Eliding * Fix left-alignment and URL parsing for URL-Bar display * Left align URLs if they are NOT http/https. If the URL-Bar is RTL, then right align them.
…ng (1.71.x) (#26149) Fix interstitial not showing deceptive site warning. Fix URLBar Eliding (#26107) * Fix interstitial not showing deceptive site warning. Fix URLBar Eliding * Fix left-alignment and URL parsing for URL-Bar display * Left align URLs if they are NOT http/https. If the URL-Bar is RTL, then right align them.
…ng (1.70.x) (#26148) Fix interstitial not showing deceptive site warning. Fix URLBar Eliding (#26107) * Fix interstitial not showing deceptive site warning. Fix URLBar Eliding * Fix left-alignment and URL parsing for URL-Bar display * Left align URLs if they are NOT http/https. If the URL-Bar is RTL, then right align them.
Resolves brave/brave-browser#41803
Resolves https://github.com/brave/internal/issues/1210
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: