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

[NTP Next] Add updated NTP with background support #26408

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zenparsing
Copy link
Collaborator

@zenparsing zenparsing commented Nov 6, 2024

Resolves brave/brave-browser#42298

new_tab_next

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:

@github-actions github-actions bot added CI/storybook-url Deploy storybook and provide a unique URL for each build CI/run-upstream-tests Run upstream unit and browser tests on Linux and Windows (otherwise only on Linux) labels Nov 6, 2024
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@zenparsing zenparsing force-pushed the ksmith-ntp-update branch 9 times, most recently from a4056cc to 9a7f7aa Compare November 13, 2024 16:23
@zenparsing zenparsing force-pushed the ksmith-ntp-update branch 7 times, most recently from 03bf3b2 to e9bef8c Compare November 21, 2024 17:42
@zenparsing zenparsing marked this pull request as ready for review November 21, 2024 20:05
@zenparsing zenparsing requested review from a team and bridiver as code owners November 21, 2024 20:05
@zenparsing zenparsing requested a review from petemill November 22, 2024 01:45
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

import("//mojo/public/tools/bindings/mojom.gni")
Copy link
Collaborator

Choose a reason for hiding this comment

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

you don't need a common directory here since this is browser process only, just put everything in the root. Also there is inconsistent naming here, sometimes brave_new_tab and sometimes new_tab_page in other places. brave_new_tab_page is probably best I think

Copy link
Collaborator

Choose a reason for hiding this comment

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

also not really sure that it makes sense to put any of this code in components unless. I would just put this code in brave/browser/ui/webui/brave_new_tab_page and put the resources in brave/browser/resources/brave_new_tab_page to match upstream

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've moved all of the code out of components as suggested - thanks! Naming is TBD.

Copy link
Collaborator Author

@zenparsing zenparsing Nov 27, 2024

Choose a reason for hiding this comment

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

I've updated the folder names, file names, and namespace name. I think naming is in a good place now.

Copy link
Collaborator Author

@zenparsing zenparsing Nov 27, 2024

Choose a reason for hiding this comment

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

I've moved the resource code back into components/brave_new_tab, as the suggested change resulted in naming conflicts with the existing NTP. Follow-up issue created here: brave/brave-browser#42563

@zenparsing zenparsing force-pushed the ksmith-ntp-update branch 7 times, most recently from 070de76 to c71be60 Compare November 30, 2024 17:37

} // namespace

NewTabPageUI::NewTabPageUI(content::WebUI* web_ui)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe you haven't got back to this yet, but as discussed this should be new_tab_page/brave_new_tab_* with no namespace. The existing file/directory is already correct (for some reason I thought it was different) so the flag should be internal to it as is normally the case for this kind of thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Follow up issue for folders/namespacing: brave/brave-browser#42563

Copy link
Contributor

github-actions bot commented Dec 2, 2024

Chromium major version is behind target branch (131.0.6778.85 vs 132.0.6834.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 Dec 2, 2024
@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 Dec 2, 2024
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

This is looking great @zenparsing - awesome work 😄

Sorry its taken so long to review!

interface NewTabPage {

// Called when a background-related profile preference has been updated.
OnBackgroundPrefsUpdated();
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey do you think it would be useful to pass the change in here? At the moment, when you change something there are quite a few mojom round trips:

  1. Send a message to update the pref
  2. Receive a notification it changed from the pref handler
  3. Send a new message to the tab handler asking about the new values
  4. Receive the result

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right - this can be optimized. The easiest next step would be to provide the pref name (as an enum value perhaps?) and let the front end decide what to update. I think we should leave this optimization for later, since it will take some thinking through (and it's hard to tell whether it's worth it).

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, happy to leave this for now. One thing to keep in mind is that it does somewhat simplify the mojom interface, as you no longer need to provide getters for any of the values (you just fire the change listener when its added). I've found the pattern makes it a bit easier to reason about where stuff comes from.

If you didn't want to add a separate listener for each different channel, you could just add all the fields into the callback

OnBackgroundPrefsUpdates(Thing1 thing1, Thing2 thing2, ..., ThingN thingN)

and you can simplify some of your initialization logic (instead, we just add ourselves as a listener and are notified of the current state + any changes that happen later).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see that we've been moving some mojo interfaces toward a push-only API. I think that the most flexible setup is a hybrid where data is pulled and update notifications are pushed. It does require more round-trips and possibly more interface methods, however. I'll keep this in mind as we move through the project - the hybrid approach is not yet set-in-stone.

components/brave_new_tab/new_tab_page.mojom Show resolved Hide resolved
components/brave_new_tab/new_tab_page.mojom Outdated Show resolved Hide resolved
components/brave_new_tab/resources/new_tab_page.tsx Outdated Show resolved Hide resolved
@zenparsing zenparsing force-pushed the ksmith-ntp-update branch 2 times, most recently from 364c32b to e3f3e20 Compare December 10, 2024 23:10
@zenparsing zenparsing force-pushed the ksmith-ntp-update branch 3 times, most recently from 53a5151 to 4af2b2b Compare December 12, 2024 14:00
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

Hey @zenparsing, the PR is looking great - I'm approving

Do you mind updating & resolving (with whatever you decide) these comment threads:

Thanks for all the work you've put into this! I'm going to be on PTO for a few weeks so probably best to reach out to @petemill if anything comes up 😄

@zenparsing zenparsing force-pushed the ksmith-ntp-update branch 2 times, most recently from 62b662e to ba30e79 Compare December 17, 2024 19:36
Copy link
Contributor

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

Description

This PR introduces a new version of the New Tab Page (NTP) for Brave Browser. It includes a redesigned UI with customizable background options, including Brave backgrounds, custom user backgrounds, solid colors, and gradient backgrounds. The PR also adds support for sponsored images and implements a settings panel for managing these background options.

Possible Issues

  1. The new NTP implementation might not have feature parity with the existing one, potentially leading to user confusion or missing functionality.
  2. Performance implications of loading and rendering background images, especially for users with slower devices or connections, should be carefully considered.

Security Hotspots

  1. URL sanitization in url_sanitizer.ts: Ensure that all external URLs (e.g., for background image links) are properly sanitized to prevent potential XSS or other injection attacks.
  2. Custom background image handling: Validate and sanitize user-uploaded images to prevent malicious file uploads or execution.
Changes

Changes

  1. browser/brave_content_browser_client.cc:

    • Added binding for the new NewTabPageHandler.
  2. browser/brave_profile_prefs.cc:

    • Updated NTP preferences registration to use new brave_new_tab::prefs.
  3. browser/new_tab/:

    • Modified new_tab_shows_options.cc and new_tab_shows_options.h to use the new brave_new_tab::prefs.
  4. browser/ui/webui/brave_new_tab/:

    • Added new files for handling the new NTP UI, including background_adapter.cc, custom_image_chooser.cc, new_tab_page_handler.cc, new_tab_page_ui.cc, and update_observer.cc.
  5. components/brave_new_tab/:

    • Added new directory with files for the new NTP implementation, including models, features, and preferences.
  6. components/brave_new_tab/resources/:

    • Added new React components, styles, and utilities for the redesigned NTP UI.
  7. components/brave_new_tab_ui/:

    • Updated build files and renamed some resources to avoid conflicts with the new implementation.
  8. components/constants/pref_names.h:

    • Removed kNewTabPageShowsOptions constant.
  9. components/resources/:

    • Updated build files and resource packs to include the new NTP resources.
sequenceDiagram
    participant User
    participant NTP as New Tab Page
    participant Handler as NewTabPageHandler
    participant Model as NewTabModel
    participant BG as BackgroundAdapter

    User->>NTP: Open New Tab
    NTP->>Handler: Initialize
    Handler->>Model: Create NewTabModel
    Model->>BG: Get background info
    BG-->>Model: Return background data
    Model-->>NTP: Update UI with background
    NTP->>User: Display New Tab Page
    User->>NTP: Interact with settings
    NTP->>Handler: Update preferences
    Handler->>Model: Update state
    Model->>BG: Apply changes
    BG-->>Model: Confirm changes
    Model-->>NTP: Reflect updated state
    NTP->>User: Show updated New Tab Page
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/run-upstream-tests Run upstream unit and browser tests on Linux and Windows (otherwise only on Linux) 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.

[NTP Next] Add initial version and feature flag for new NTP
10 participants