[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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 3 times, most recently from ba30e79 to a5f16d0 Compare December 20, 2024 17:42
Copy link
Contributor
github-actions bot commented Jan 2, 2025

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

Description

This PR implements a new version of the New Tab Page (NTP) for the Brave browser. It introduces a more modular and React-based approach to the NTP UI, with improved background image handling, settings management, and overall user experience. The changes include new components for background selection, settings panels, and a redesigned layout.

Changes

Changes

  1. browser/about_flags.cc:

    • Added a new feature flag for the updated NTP.
  2. browser/brave_content_browser_client.cc:

    • Registered the new NTP UI interface binder.
  3. browser/brave_profile_prefs.cc:

    • Updated preference registration for the new NTP.
  4. browser/extensions/api/settings_private/brave_prefs_util.cc:

    • Updated preference handling for the new NTP.
  5. browser/new_tab/:

    • Modified existing NTP-related files to work with the new implementation.
  6. browser/ui/webui/brave_new_tab/:

    • Added new files for the updated NTP UI implementation, including handlers, adapters, and UI components.
  7. browser/ui/webui/brave_web_ui_controller_factory.cc:

    • Updated to use the new NTP UI when the feature flag is enabled.
  8. components/brave_new_tab/:

    • Added new files for the NTP model, features, and preferences.
  9. components/brave_new_tab/resources/:

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

    • Modified existing files to accommodate the new NTP implementation.
  11. Various other files:

    • Updated build configurations, resource packs, and string definitions to support the new NTP implementation.
sequenceDiagram
    participant User
    participant BraveNewTabUI
    participant NewTabPageHandler
    participant BackgroundAdapter
    participant NewTabModel
    participant BackgroundService

    User->>BraveNewTabUI: Open New Tab
    BraveNewTabUI->>NewTabPageHandler: Initialize
    NewTabPageHandler->>BackgroundAdapter: Get background data
    BackgroundAdapter->>BackgroundService: Fetch backgrounds
    BackgroundService-->>BackgroundAdapter: Return backgrounds
    BackgroundAdapter-->>NewTabPageHandler: Background data
    NewTabPageHandler->>NewTabModel: Update state
    NewTabModel-->>BraveNewTabUI: Render updated UI
    BraveNewTabUI-->>User: Display New Tab Page

    User->>BraveNewTabUI: Change background
    BraveNewTabUI->>NewTabPageHandler: Select background
    NewTabPageHandler->>BackgroundAdapter: Update background
    BackgroundAdapter->>BackgroundService: Save preference
    BackgroundService-->>BackgroundAdapter: Confirm update
    BackgroundAdapter-->>NewTabPageHandler: Update complete
    NewTabPageHandler->>NewTabModel: Update state
    NewTabModel-->>BraveNewTabUI: Render updated UI
    BraveNewTabUI-->>User: Display updated background
Loading

Possible Issues

  1. The new implementation relies heavily on React and modern web technologies, which may impact performance on older devices.
  2. The feature flag approach may lead to maintenance of two separate NTP implementations for a period of time.

Security Hotspots

  1. browser/ui/webui/brave_new_tab/background_adapter.cc:

    • Ensure proper sanitization of user-supplied background image URLs to prevent potential XSS attacks.
  2. components/brave_new_tab/resources/lib/url_sanitizer.ts:

    • Verify that the URL sanitization logic is robust and covers all potential edge cases.

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