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

[Brave News]: Advert chrome:// url fixes & Revert FeedNavigation heading change (uplift to 1.62.x) #21605

Merged
merged 1 commit into from
Jan 19, 2024
Merged
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
8 changes: 4 additions & 4 deletions components/brave_news/browser/resources/FeedNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Container = styled(Card)`
scrollbar-color: var(--bn-glass-10) var(--bn-glass-10);
`

const CustomButton = styled.button <{ selected?: boolean, faint?: boolean, large?: boolean, bold?: boolean }>`
const CustomButton = styled.button <{ selected?: boolean, faint?: boolean, bold?: boolean }>`
padding: ${spacing.m};
padding-left: ${PAD_LEFT};

Expand All @@ -46,7 +46,7 @@ const CustomButton = styled.button <{ selected?: boolean, faint?: boolean, large
width: 100%;

color: ${p => p.faint ? `var(--bn-glass-50)` : `var(--bn-glass-100)`};
font: ${p => font[p.large ? 'default' : 'small'][p.bold ? 'semibold' : 'regular']};
font: ${p => font.small[p.bold ? 'semibold' : 'regular']};
cursor: pointer;

&:hover {
Expand All @@ -72,7 +72,7 @@ const Section = styled.details`
align-items: center;
gap: ${spacing.m};
list-style: none;
font: ${font.default.semibold};
font: ${font.small.semibold};

cursor: pointer;

Expand Down Expand Up @@ -115,7 +115,7 @@ const PlaceholderMarker = <Icon />
export function Item(props: { id: FeedView, name: string }) {
const { feedView, setFeedView } = useBraveNews()
const topLevel = ['all', 'following'].includes(props.id)
return <CustomButton large={topLevel} selected={props.id === feedView} onClick={() => setFeedView(props.id)} bold={topLevel}>
return <CustomButton selected={props.id === feedView} onClick={() => setFeedView(props.id)} bold={topLevel}>
{props.name}
</CustomButton>
}
Expand Down
10 changes: 7 additions & 3 deletions components/brave_news/browser/resources/feed/Ad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import getBraveNewsController from '../shared/api';
import { useUnpaddedImageUrl } from '../shared/useUnpaddedImageUrl';
import { MetaInfoContainer } from './ArticleMetaRow';
import Card, { LargeImage, Title, braveNewsCardClickHandler } from './Card';
import { useBraveNews } from '../shared/Context';

interface Props {
info: FeedV2Ad
Expand Down Expand Up @@ -71,9 +72,12 @@ export const useVisibleFor = (callback: () => void, timeout: number) => {
}
}

const adTargetUrlAllowedSchemes = ['https:', 'chrome:', 'brave:']

export default function Advert(props: Props) {
const [advert, setAdvert] = React.useState<DisplayAd | null | undefined>(undefined)
const imageUrl = useUnpaddedImageUrl(advert?.image.paddedImageUrl?.url ?? advert?.image.imageUrl?.url)
const { openArticlesInNewTab } = useBraveNews()

const onDisplayAdViewed = React.useCallback(() => {
if (!advert) return
Expand All @@ -89,7 +93,7 @@ export default function Advert(props: Props) {

console.debug(`Brave News: Visited display ad: ${advert.uuid}`)
await getBraveNewsController().onDisplayAdVisit(advert.uuid, advert.creativeInstanceId)
braveNewsCardClickHandler(advert.targetUrl.url)(e);
braveNewsCardClickHandler(advert.targetUrl.url, adTargetUrlAllowedSchemes)(e);
}, [advert])

const { setElementRef: setTriggerRef } = useOnVisibleCallback(async () => {
Expand All @@ -114,12 +118,12 @@ export default function Advert(props: Props) {
return <Container ref={setAdEl} onClick={onDisplayAdVisited}>
<AdImage src={imageUrl} />
<MetaInfoContainer>
<BatAdLabel onClick={e => e.stopPropagation()} href="chrome://rewards">{getLocale('braveNewsAdvertBadge')}</BatAdLabel>
<BatAdLabel onClick={e => e.stopPropagation()} target={openArticlesInNewTab ? '_blank' : undefined} href="chrome://rewards">{getLocale('braveNewsAdvertBadge')}</BatAdLabel>
{' ' + advert.description}
</MetaInfoContainer>
<Title>
<SecureLink href={advert.targetUrl.url} onClick={e => {
<SecureLink allowedSchemes={adTargetUrlAllowedSchemes} href={advert.targetUrl.url} onClick={e => {
// preventDefault, so we go through onDisplayAdVisit and record the
// result.
e.preventDefault()
Expand Down
6 changes: 3 additions & 3 deletions components/brave_news/browser/resources/feed/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as React from 'react';
import { color, effect, font, radius, spacing } from '@brave/leo/tokens/css';
import styled from "styled-components";
import SecureLink, { SecureLinkProps, validateScheme } from '$web-common/SecureLink';
import SecureLink, { SecureLinkProps, defaultAllowedSchemes, validateScheme } from '$web-common/SecureLink';
import { configurationCache, useBraveNews } from '../shared/Context';

export const Header = styled.h2`
Expand Down Expand Up @@ -89,8 +89,8 @@ export default styled.div`
${p => p.onClick && 'cursor: pointer'}
`

export const braveNewsCardClickHandler = (href: string | undefined) => (e: React.MouseEvent) => {
validateScheme(href)
export const braveNewsCardClickHandler = (href: string | undefined, allowedSchemes: string[] = defaultAllowedSchemes) => (e: React.MouseEvent) => {
validateScheme(href, allowedSchemes)

if (configurationCache.value.openArticlesInNewTab || e.ctrlKey || e.metaKey || e.buttons & 4) {
window.open(href, '_blank', 'noopener noreferrer')
Expand Down