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 NTP Custom homepage ("super referral") #4866

Merged
merged 36 commits into from
Apr 17, 2020

Conversation

simonhong
Copy link
Member

@simonhong simonhong commented Mar 6, 2020

Resolves brave/brave-browser#8218

NTPBackgroundImagesServicemanages background provider(SI or SR).
By default, it registers SI component and SR component if it's super referral install.

It's global service because SI or SR component is browser-wide component and it manages their data itself. Which data should be used for webui or android NTP will be determined by ViewCounterService. ViewCounterService will provide proper data (SI or SR) to client (like webui) by checking current profile's preference.

NTPBackgroundImagesSource handles bg data request. It can handle SI and SR data simultaneously.
SI data's url starts with chrome://branded-wallpaper/sponsored-images/... and SR data is something like chrome://branded-wallpaper/super-referral/logo.png.
I think we can expand this in the future. For example, chrome://branded-wallpaper/default/wallpaper.jpg for default background.

To make SR data available quickly, SR data is cached. With this caching, client can get SR data
before component registration is ready. It's important because SR's NTP always should display its image.

In this PR, kNewTabPageSuperReferralThemesOption pref is added.
Client should use it as a switch for turn it on/off SR component in runtime in super referral installs.
If it's turned off, SI or default bg will be displayed. This can be changed in settings page.

Regarding to flags, existing New Tab Page Branded Wallpapers flag will act as a top level switch.
If it is off, SI and SR are all disabled.
If New Tab Page Branded Wallpapers feature switch is on, SI component is enabled by default.
New Enable Brave Custom Homepage is introduced for SR component. If this is on, SR component will be installed when current install comes from super referrer.

To test locally, we can pass different local test data by using ntp-sponsored-images-data-path and ntp-super-referral-data-path. Also can use demo components. It becomes available when demo flag is on.

Settings page with Super referral

Screen Shot 2020-03-26 at 2 25 00 PM

image

Settings page with non Super referral

Screen Shot 2020-03-26 at 2 26 54 PM

NTP Pages with Super referral

image

Submitter Checklist:

Test Plan:

Simply test with demo data => SR component test is not supported by Demo flag.
1. Launch browser with fresh profile
2. Turn on New Tab Page Demo Branded Wallpaper in brave://flags and relaunch
3. Open brave://components and check SI and SR component is registered (NTP Sponsored Images (DEMO) and NTP Super Referral (Technikke))
4. Open NTP and check SR is loaded. If top sites are visible, it means SR component is loaded
Note: With demo data, theme settings are not properly updated. To see the themes option change, please follow below step.

Check fresh install with super referrer

  1. Create empty profile dir
  2. Create promoCode text file in root profile dir and that file has TECHNIK string
  3. Launch Browser and check NTP Super Referrer (Technikke) component is registered in brave://components
  4. Load new tab and topsites are visible for every NTP loading
  5. Open settings page and check themes option is changed in appearance settings
  6. Click theme option and check new themes sub page.
  7. Check super referral bg is not displayed after selecting Brave default images option.

Check fresh install with non referrer

  1. Launch browser with clean profile
  2. Check NTP SI component is only registered

Two scenarios that check this change doesn't affect existing users

Scenario 1 (User has default code or non super referrer code)

  1. Create user dir with other builds
  2. Launch browser with this PR with created user data at step 1
  3. Check NTP Sponsored Images component is only registered

Scenario 2 (User has empty code because of 90 days passed)

  1. Copy old user data dir that used more than 90 days
  2. Start browser with that copied user dir
  3. Check NTP Sponsored Images component is only registered

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.

@simonhong simonhong added this to the 1.7.x - Nightly milestone Mar 6, 2020
@simonhong simonhong self-assigned this Mar 6, 2020
@simonhong simonhong force-pushed the ntp_super_referral_images branch 4 times, most recently from 7fe98a6 to 7c6dfeb Compare March 6, 2020 16:27
@simonhong simonhong marked this pull request as ready for review March 6, 2020 23:28
@simonhong simonhong force-pushed the ntp_super_referral_images branch 2 times, most recently from dadc4ef to ed7bcf0 Compare March 7, 2020 02:23
@simonhong simonhong added the CI/skip Do not run CI builds (except noplatform) label Mar 9, 2020
@simonhong simonhong force-pushed the ntp_super_referral_images branch from f25f3c5 to 1826181 Compare March 11, 2020 02:21
@simonhong
Copy link
Member Author

simonhong commented Mar 12, 2020

Note: This is not yet ready to review. This PR works well for fresh install but not work properly for existing users. Implementation should be slightly modified after fixing brave/brave-browser#8603

@simonhong simonhong requested a review from bsclifton March 12, 2020 06:21
@simonhong simonhong force-pushed the ntp_super_referral_images branch from bd0743a to 8a5aefb Compare March 12, 2020 11:57
@simonhong
Copy link
Member Author

Ready to review.

@simonhong simonhong removed the CI/skip Do not run CI builds (except noplatform) label Mar 12, 2020
@simonhong simonhong force-pushed the ntp_super_referral_images branch 2 times, most recently from 8022ac4 to 83226b8 Compare March 13, 2020 00:44
@simonhong simonhong added the CI/skip Do not run CI builds (except noplatform) label Mar 13, 2020
@simonhong simonhong force-pushed the ntp_super_referral_images branch from f6c73cd to bf9ea53 Compare March 16, 2020 01:20
@simonhong simonhong removed the CI/skip Do not run CI builds (except noplatform) label Mar 16, 2020
@simonhong simonhong requested a review from fmarier as a code owner March 17, 2020 00:40
@simonhong
Copy link
Member Author

simonhong commented Mar 17, 2020

NOTE: Need to rebase after #4807 is merged.

browser/BUILD.gn Outdated Show resolved Hide resolved
It should ignore for in-effective images data when it gets update.
W/o this, we could display SI data for super referral.
To do this, we should check existing install's promo code status properly.
at launching time. If referal code is empty and referral service's is not
initialized state, we should wait to get promo code.
If referal service has already initialized state at launch time, we can
set this is not SR install. SR is only effective for fresh install.
NTP displays SR data always. So, caching it and use it instead of using
data from component folder. If not, we have to wait to get SR data until
component is ready.
So far, current code only can recover fetching mapping table failure.
but browser can be crashed while waiting component fetching after
mapping table is downloaded. So, we should run recover logic if
browser doesn't finish initial component downloding due to crash.
Android needs super referrals code during the campaign to generate
QR code. Backend will clear it when campaign ends.
When registering demo, it skips some steps that sr component registration does.
It can ruins some preferences.
Instead of this, we can demo SR component easily by inserting promoCode file in
user data dir.
ViewCounterService will provide SR data even if NTPBGImages pref
is false.
Regardless of background image option, NTP will show SR images
if user choose SR theme in settings.
Use same manifest filename and determine it's SI or SR by its
contents.
And delete utils. APIs that in utils should be in service impl file.
@simonhong simonhong force-pushed the ntp_super_referral_images branch from caa2905 to a3eeb48 Compare April 17, 2020 05:10
@simonhong simonhong merged commit 24dc9ac into master Apr 17, 2020
@simonhong simonhong deleted the ntp_super_referral_images branch April 17, 2020 08:08
@simonhong
Copy link
Member Author

Filed f/u issue - brave/brave-browser#9289

@bsclifton
Copy link
Member

if/when uplifted, we'll need to grab this one too:
#5290

bsclifton pushed a commit that referenced this pull request Apr 20, 2020
Implement NTP Custom homepage ("super referral")
@GeetaSarvadnya
Copy link

GeetaSarvadnya commented Apr 22, 2020

Verification passed on

Brave 1.10.3 Chromium: 81.0.4044.113 (Official Build) nightly (64-bit)
Revision e3225dafb0475864a1812a374d73a92e391635ac-refs/branch-heads/4044@{#936}
OS Windows 10 OS Version 1803 (Build 17134.1006)

Check fresh install with super referrer

Check fresh install with non-referrer

  • Verified that NTP SI component is only registered in brave://components when non-referrer is used
    image

Two scenarios that check this change doesn't affect existing users
Scenario 1 (User has default code or non-super referrer code)

  • Created 1.7.x profile and moved profile to 1.10.x build which has referrer code, verified that NTP Sponsored Images component is only registered
    image

Scenario 2 (User has empty code because of 90 days passed)

  • Verified NTP Sponsored Images component is only registered

Verification PASSED on macOS 10.15.3 x64 using the following build:

Brave | 1.10.3 Chromium: 81.0.4044.113 (Official Build) nightly (64-bit)
-- | --
Revision | e3225dafb0475864a1812a374d73a92e391635ac-refs/branch-heads/4044@{#936}
OS | macOS Version 10.15.3 (Build 19D76)

Check fresh install with super referrer: - PASSED

  • ensured that TECHNIK images are being displayed whenever a NTP is opened while brave://settings/themes is set as Technikke
  • ensured that clicking on the TECHNIK logo opens https://brave.com/?from-super-referreer-demo (checked on the three different images)
  • ensured that the TECHNIK images are NOT being used in PB/Tor/Guest windows
  • ensured that you can unpin/remove the pre-set top tiles from the NTP
  • ensured that promoCode under brave://local-state appears as TECHNIK
"initialization": true,
"promo_code": "TECHNIK"

Screen Shot 2020-04-22 at 4 50 00 PM

Screen Shot 2020-04-22 at 4 50 25 PM

Screen Shot 2020-04-22 at 5 06 34 PM

Screen Shot 2020-04-22 at 4 51 50 PM

Screen Shot 2020-04-22 at 5 12 07 PM

Check fresh install with non referrer:

Ensured that installing Brave without a super referral promoCode uses the current NTP SI component and loads the correct images.

Screen Shot 2020-04-22 at 5 08 39 PM

Screen Shot 2020-04-22 at 5 09 14 PM

Scenario 1 (User has default code or non super referrer code)

  • used my personal profile which is using BRV001 (default Brave) as the promoCode and ensured that NTP Sponsored Images (CA) - Version: 1.0.34 was being used.
  • ensured that the current NTP SI were being downloaded/used.
"promo_code": "BRV001",
"timestamp": "13227605020492579"

Screen Shot 2020-04-22 at 5 20 57 PM

Screen Shot 2020-04-22 at 5 21 27 PM

Scenario 2 (User has empty code because of 90 days passed)

Used RED194 as the promoCode and ensured it's appearing under brave://local-state:

"initialization": true,
"promo_code": "RED194"

Moved the machines date ~90 days ahead and ensured that NTP Sponsored Images (CA) - Version: 1.0.34 was being used and promoCode was removed from brave://local-state. However, received the following error in the terminal which is expected as 30 days haven't technically passed on the server side, hence not receiving the +1 for a RED194 referral.

[82450:775:0901/172939.144138:ERROR:brave_referrals_service.cc(366)] Referral is not ready, please wait at least 30 days

Screen Shot 2020-04-22 at 5 35 09 PM

Screen Shot 2020-09-01 at 5 30 30 PM

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

Successfully merging this pull request may close these issues.

Desktop :: Implement Custom Homepage
9 participants