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

Implement Gradient background for NTP #14783

Merged
merged 7 commits into from
Aug 25, 2022
Merged

Implement Gradient background for NTP #14783

merged 7 commits into from
Aug 25, 2022

Conversation

sangwoo108
Copy link
Contributor

  • Reuse most of components used for Solid color background

Resolves brave/brave-browser#24889

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • 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, npm run lint, 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 the CI/storybook-url Deploy storybook and provide a unique URL for each build label Aug 23, 2022
@sangwoo108 sangwoo108 requested review from fallaciousreasoning and petemill and removed request for fallaciousreasoning August 23, 2022 23:17
@sangwoo108 sangwoo108 added CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS labels Aug 23, 2022
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 mostly LGTM. I have one question though - could we get away without adding a new background type to the backend? Maybe instead of having separate UseSolidColorBackground and UseGradientColorBackground we could just have a UseColorBackground which stores anything which can be assigned to background in the CSS?

We could still have a separate gradient and solid section in the UI but they'd write to the same pref. What do you think?

Thinking about it we might even be able to set it to url('data:...') but that might not work in WebUI.

It'd just reduce the number of branches we have to worry about here 😆

* Reuse most of components used for Solid color background
Copy link
Contributor Author

@sangwoo108 sangwoo108 left a comment

Choose a reason for hiding this comment

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

Could we get away without adding a new background type to the backend?

Yeah, that sounds good! Let me try again :)

Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

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

++ 👍🏼

@sangwoo108
Copy link
Contributor Author

sangwoo108 commented Aug 24, 2022

One thing I'm concerned about storing css value into pref is if it could be a vulnerability for attackers to change NTP background or inject their css our NTP background - I know almost nothing about security, though. If so, we might have to keep the backend types as is, and store pref only when it's compliant with the format.

@fallaciousreasoning
Copy link
Contributor

Oh yeah, good call! I didn't think of that

@petemill
Copy link
Member

petemill commented Aug 24, 2022

One thing I'm concerned about storing css value into pref is if it could be a vulnerability for attackers to change NTP background or inject their css our NTP background - I know almost nothing about security, though. If so, we might have to keep the backend types as is, and store pref only when it's compliant with the format.

How about instead storing the index of the gradient in a fixed array, as a key? We can do the same for the background color. It seems strange to me to store the full code values in pref, which we can do simply because css is a dynamic language (sort of). Storing index would help with e.g. android and iOS using the same pref value.

edit: or if we're worried about using indexes because we may want to insert new items in the middle, then assigning a key to each value, e.g.:

const backgroundValues = { 
  red1: '#3C790B', 
  gradientA: 'linear-gradient(125.83deg, #392DD1 0%, #A91B78 99.09%)'
}

I'm happy if you want to combine colors and gradients, or keep them separate, internally.

@sangwoo108
Copy link
Contributor Author

How about instead storing the index of the gradient in a fixed array, as a key? ... if we're worried about using indexes because we may want to insert new items in the middle,

Yeah, from my experience, when we store index of a preset, we have migration issue in case we change the preset(add, remove, reorder, etc ...).

To give a name to each value and store the name sounds cool. I've used "https://colornamer.robertcooper.me/" once to name colors, I think we can use this this time too.

@sangwoo108
Copy link
Contributor Author

Update: security team confirmed that it's okay as is. I'd like to refactor as @fallaciousreasoning suggested :) @petemill Please let me know if you think storing key instead of value is desirable.

@brave-builds
Copy link
Collaborator

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

We don't have to keep both of them.
They're not that diffrent.
@sangwoo108
Copy link
Contributor Author

@simonhong @fallaciousreasoning @petemill Merged two prefs and paths. Could you check this again, please?

@brave-builds
Copy link
Collaborator

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

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.

Still LGTM

@@ -20,15 +20,18 @@ class GURL;

namespace ntp_background_images {

// TODO(sko) Rename this to NTPCustomBackgroundService. It's dealing with
Copy link
Member

Choose a reason for hiding this comment

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

FYI: Upstream has that class already :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, dear.. Let me think about better name

@brave-builds
Copy link
Collaborator

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

@sangwoo108 sangwoo108 merged commit 31f1b86 into master Aug 25, 2022
@sangwoo108 sangwoo108 deleted the sko/gradient branch August 25, 2022 08:34
@github-actions github-actions bot added this to the 1.45.x - Nightly milestone Aug 25, 2022
@sangwoo108
Copy link
Contributor Author

sangwoo108 commented Aug 25, 2022

Thank you all for reviewing this! It was really helpful, as always :)

@GeetaSarvadnya
Copy link

GeetaSarvadnya commented Sep 14, 2022

Verification PASSED on

Brave | 1.45.44 Chromium: 105.0.5195.102 (Official Build) nightly (64-bit)
-- | --
Revision | 4c16f5ffcc2da70ee2600d5db77bed423ac03a5a-refs/branch-heads/5195_55@{#4}
OS | Windows 10 Version 21H2 (Build 19044.1889)

1. Gradients

  • Confirmed that user can select the gradient background for NTP
  • Confirmed that user can choose the induvidual gradient background via NTP
  • Confirmed that same gradient background is shown on each the NTP when the induvidual gradient background is selected
  • Confirmed that the differenet gradient background is shown on each the NTP when Refresh on every new tab switch is ON
  • Confirmed that on each gradient background color, the NTP stats (Cards, clock, Top sites, Brave stats etc) are shown clearly/correctly
  • Confirmed that selected gradient background retained on the NTP after the browser restart
  • Confirmed that Check mark is shown on the selected gradient bg color
  • Confirmed that selected gradient background retained across all the tabs and windows in Regular window
  • Confirmed that selected gradient background retained only for the Profile 1
  • Confirmed that user has provision to select the different gradient background colors for multiple profiles
  • Confirmed that selecting gradient background doesn't impact the NTP SI show on NTP
  • Confirmed that NTP SI are shown in the order 2, 4, 8 tabs
Example Example Example Example Example
image image image image image

2. Solid colors

  • Confirmed that user can select the solid background for NTP
  • Confirmed that user can choose the induvidual solid background via NTP
  • Confirmed that same solid background is shown on each the NTP when the induvidual solid background is selected
  • Confirmed that the differenet solid background is shown on each the NTP when Refresh on every new tab switch is ON
  • Confirmed that on each solid background color, the NTP stats (Cards, clock, Top sites, Brave stats etc) are shown clearly/correctly
  • Confirmed that selected solid background retained on the NTP after the browser restart
  • Confirmed that Check mark is shown on the selected solid bg color
  • Confirmed that selected solid background retained across all the tabs and windows in Regular window
  • Confirmed that selected solid background retained only for the Profile 1
  • Confirmed that user has provision to select the different solid background colors for multiple profiles
  • Confirmed that selecting solid background doesn't impact the NTP SI show on NTP
  • Confirmed that NTP SI are shown in the order 2, 4, 8 tabs
Example Example Example Example Example
image image image image image

Regression on NTP

  • Ensured Tops sites can be edit/delete via NTP
  • Ensured that NTP stats can be hidden/shown
  • Ensured that a site can be added via NTP
  • Ensured NTP Widget cards can be added/removed
  • Ensured NTP SI works as expected
  • Ensured that click on settings (bookmarks, history, settings and brave talk) shortcuts works as expected
  • Ensured that the existing features upload your own and Brave background works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gradient background option for NTP
6 participants