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

New Tab Page WebUI: Use Profile Preferences to store page options instead of localStorage #2831

Merged
merged 3 commits into from
Jun 29, 2019

Conversation

petemill
Copy link
Member

@petemill petemill commented Jun 28, 2019

This follow-up is required along with this PR:

Fix brave/brave-browser#5064
Fix brave/brave-browser#2848

This is created as a PR on top of master and does not include the extra preferences from #2762 since it has not been merged yet.

This allows:

  • Surfacing these preferences outside of the NTP
  • Syncing / migrating the preferences
  • Making the change immediately for all open NTP tabs

Use FireWebUIListener to push data to javascript event subscribers.
Still uses render_view_host->SetWebUIProperty (like the existing NTP data), which we may port in the future to a DataSource Dictionary like the other WebUI in chromium.

Provides any data retrieved or updated to redux store via redux action, but does not use redux actions to ask for a data change.

Also includes

Refactor NTP WebUI backend

Focus on the MessageHandler in order to use FireWebUIListener and follow chromium best practice for setting data and events

TS types for NTP actions

Small change for intellisense™ and action parameter type checking

Submitter Checklist:

Test Plan:

  1. Open multiple windows with NTP visible in each.
  2. Toggle each of the settings
  3. Expected: settings change and widgets show/hide in current window and other windows
  4. (optional) Go to profile directory, open up the Default/Preferences file and look for brave.new_tab_page.show_background_image and either true/false (depending on what you set in the UI)

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

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.

C++ looks good to me with trivial nits. 👍
Will toss other changes to FE experts.

public:
explicit BraveNewTabMessageHandler(BraveNewTabUI* web_ui);
~BraveNewTabMessageHandler() override;
void OnStatsChanged();
Copy link
Member

Choose a reason for hiding this comment

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

nit: These three callback methods can be in private section.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for spotting, this is fixed now. It was left over from a previous strategy.

browser/ui/webui/brave_new_tab_ui.h Outdated Show resolved Hide resolved
@bsclifton bsclifton added this to the 0.69.x - Nightly milestone Jun 28, 2019
bsclifton
bsclifton previously approved these changes Jun 28, 2019
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Code looks great (see nits by @simonhong) - I verified the functionality works as expected and even cracked open the Default/Preferences file to verify the new setting by hand

Really nice work on this one! 😻

@bsclifton
Copy link
Member

There is a browser test failure here:

02:50:13  [  FAILED  ] BraveNewTabUIBrowserTest.BraveNewTabIsDefault, where TypeParam =  and GetParam() =  (529 ms)
02:50:13  [231/231] BraveNewTabUIBrowserTest.BraveNewTabIsDefault (650 ms)
02:50:13  1 test failed:
02:50:13      BraveNewTabUIBrowserTest.BraveNewTabIsDefault (../../brave/browser/ui/webui/brave_new_tab_ui_browsertest.cc:74)

Copy link
Contributor

@cezaraugusto cezaraugusto left a comment

Choose a reason for hiding this comment

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

left some code comments

components/brave_new_tab_ui/brave_new_tab.tsx Outdated Show resolved Hide resolved
components/brave_new_tab_ui/actions/new_tab_actions.ts Outdated Show resolved Hide resolved
petemill added 3 commits June 28, 2019 14:12
… MessageHandler

Following best practices from chromium webui documentation, move towards using DataSource keys for the initial page data, and FireWebUIListener for updating data.
We're still manually setting data on the render_host in the WebUIController, but this refactor allows us to use FireWebUIListener now, and move towards using DataSource for that data in the future. MessageHandler allows us to use an established JS lifecycle to ensure that data is only sent to the correct contexts at the correct time.

Use FireWebUIListener for 'stats-updated' instead of expecting a global 'statsUpdated' function to exist (which was causing some JS errors).
…tead of localStorage

This allows:
- Surfacing these preferences outside of the NTP
- Syncing / migrating the preferences
- Making the change immediately for all open NTP

Use FireWebUIListener to push data to javascript event subscribers.
Still uses render_view_host->SetWebUIProperty (like the existing NTP data), which we may port in the future to a DataSource Dictionary like the other WebUI in chromium.

Provides any data retreived or updated to redux store via redux action, but does not use redux actions to ask for a data change.

Fix brave/brave-browser#5064
@petemill
Copy link
Member Author

I guess this also fixes brave/brave-browser#2848 since the static global function call new_tab_page.statsUpdated is removed in favor of event subscription via FireWebUIListener("stats-updated")

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

++

Copy link
Contributor

@cezaraugusto cezaraugusto left a comment

Choose a reason for hiding this comment

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

nailed it. +1000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants