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

[ads] RichNTT: Android #27645

Merged
merged 1 commit into from
Feb 27, 2025
Merged

[ads] RichNTT: Android #27645

merged 1 commit into from
Feb 27, 2025

Conversation

aseren
Copy link
Collaborator

@aseren aseren commented Feb 13, 2025

The PR introduces NewTabTakeover WebUI which does the following:

  • retrieves sponsored wallpaper information via mojom
  • displays rich media using <SponsoredRichMediaBackground> react component
  • sends events from rich media NTT via mojom channel
  • has an url: chrome://new-tab-takeover

NewTabTakeover webUI is loaded on Android NTP using ThinWebView wrapped inside FrameLayout.

Currently NewTabTakeover web ui is used on Android only, because Desktop implementation uses New Tab Page Web UI and doesn't need additional WebUI.

Security review: https://github.com/brave/reviews/issues/1795
Desktop implementation was done in: #27466

Resolves brave/brave-browser#43513

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Test the functionality basing on RichNTT spec: https://docs.google.com/document/d/14kFstJbrsYZyFmZcTAQac195riiinQoVAU1Dzk1e2dE/edit?tab=t.0#heading=h.skhkv2wammbc

Copy link
Contributor

Chromium major version is behind target branch (133.0.6943.54 vs 134.0.6998.15). Please rebase.

@github-actions github-actions bot added the chromium-version-mismatch The Chromium version on the PR branch does not match the version on the target branch label Feb 18, 2025
@aseren aseren changed the title WIP: Rich ntt on Android WIP: Rich NTT on Android Feb 18, 2025
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Feb 18, 2025
@aseren aseren force-pushed the issues/43513 branch 4 times, most recently from 8e189c5 to 42569fa Compare February 20, 2025 20:04
@aseren aseren changed the title WIP: Rich NTT on Android Rich NTT on Android Feb 20, 2025
@aseren aseren changed the title Rich NTT on Android [ads] RichNTT: Android Feb 20, 2025
@aseren aseren force-pushed the issues/43513 branch 2 times, most recently from fbb6db3 to 0ef68e4 Compare February 20, 2025 22:09
@github-actions github-actions bot removed the chromium-version-mismatch The Chromium version on the PR branch does not match the version on the target branch label Feb 20, 2025
@aseren aseren force-pushed the issues/43513 branch 2 times, most recently from 4c02a83 to 78d1c83 Compare February 21, 2025 15:18
@aseren aseren force-pushed the issues/43513 branch 4 times, most recently from 380b677 to 89049cb Compare February 21, 2025 16:25
@aseren aseren marked this pull request as ready for review February 21, 2025 16:27
@aseren aseren requested review from a team, deeppandya and bridiver as code owners February 21, 2025 16:28
@tmancey tmancey self-requested a review February 25, 2025 19:38
@tmancey
Copy link
Collaborator

tmancey commented Feb 25, 2025

Approved (see comments). Thanks

@tmancey
Copy link
Collaborator

tmancey commented Feb 26, 2025

@bridiver on desktop, we use a Web UI to display new tab pages. On Android, however, there is no Web UI implementation. Instead, Android overlays a native view over a web contents view.

The native view displays the background image, Brave Stats, and Brave News. When the user navigates to a URL, the native view is hidden, revealing the web contents view and its HTML content.

To display rich media HTML alongside Brave Stats and Brave News, we use a ThinWebView to render the HTML behind these overlays.

cc @SergeyZhukovsky @deeppandya @aseren

@tmancey tmancey enabled auto-merge (squash) February 26, 2025 15:07
@tmancey tmancey disabled auto-merge February 26, 2025 15:57
@aseren aseren requested a review from ShivanKaul February 26, 2025 16:09
@aseren aseren force-pushed the issues/43513 branch 2 times, most recently from 4a589a5 to deadbd5 Compare February 26, 2025 18:21
@tmancey tmancey enabled auto-merge (squash) February 26, 2025 18:30
@@ -0,0 +1,16 @@
# Copyright (c) 2025 The Brave Authors. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to components/new_tab_takeover directory

@aseren aseren disabled auto-merge February 27, 2025 01:10
Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code owner ok

@aseren aseren requested a review from a team as a code owner February 27, 2025 17:21
@aseren aseren enabled auto-merge (squash) February 27, 2025 17:22
Copy link
Contributor

[puLL-Merge] - brave/brave-core@27645

Here's my review of the PR:

Description

This PR adds support for rich media wallpapers in Brave's New Tab Page on Android. It introduces a new WebUI component called "New Tab Takeover" that can display HTML content behind the standard New Tab Page overlays (Brave Stats and Brave News). The motivation is to enable more interactive sponsored content in the wallpaper area.

Security Hotspots

  1. Untrusted Content: The rich media content loads in an untrusted context (chrome-untrusted://), but care should be taken to ensure proper sandboxing and CSP restrictions are in place.

  2. Touch Event Pass-through: The PR routes touch events to the rich media WebView when the user taps outside recycler view items. This could potentially allow unintended interactions if not properly bounded.

Changes

Changes

By filename:

android/brave_java_sources.gni:

  • Added new SponsoredRichMediaWebView.java source

BraveNewTabPageLayout.java:

  • Added rich media WebView support
  • Added touch event handling for rich media content
  • Added background frame layout for rich media

SponsoredRichMediaWebView.java:

  • New class to handle rich media WebView initialization and loading

new_tab_takeover/ (new directory):

  • New WebUI implementation for rich media content
  • React components for rendering rich media
  • Mojo interfaces for communication between Java and WebUI

ntp_background_images/:

  • Added rich media wallpaper type support
  • Added tests for wallpaper parsing
  • Updated CSP to allow framing from new WebUI

The key flow is that when a rich media wallpaper is detected, a WebView is initialized to load and display the content, while maintaining the standard NTP UI overlays.```mermaid
sequenceDiagram
BraveNewTabPageLayout->>+SponsoredRichMediaWebView: initialize()
SponsoredRichMediaWebView->>+WebContents: create()
WebContents-->>-SponsoredRichMediaWebView: web_contents
SponsoredRichMediaWebView->>+ThinWebView: create()
ThinWebView-->>-SponsoredRichMediaWebView: web_view
SponsoredRichMediaWebView->>WebContents: loadUrl(chrome://new-tab-takeover)
NewTabTakeoverUI->>NewTabTakeoverMojom: getCurrentWallpaper()
NewTabTakeoverMojom-->>NewTabTakeoverUI: wallpaper info
NewTabTakeoverUI->>SponsoredRichMediaWebView: render rich media content

</details>

<!-- Generated by claude-3-5-sonnet-20241022 -->

@aseren aseren disabled auto-merge February 27, 2025 19:59
@aseren aseren merged commit eb47721 into master Feb 27, 2025
20 checks passed
@aseren aseren deleted the issues/43513 branch February 27, 2025 22:22
@github-actions github-actions bot added this to the 1.78.x - Nightly milestone Feb 27, 2025
@brave-builds
Copy link
Collaborator

Released in v1.78.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ads] RichNTT: Android
9 participants