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

Expose way for sites to determine if browser is Brave #4721

Merged
merged 2 commits into from
Mar 5, 2020

Conversation

bsclifton
Copy link
Member

@bsclifton bsclifton commented Feb 24, 2020

Fixes brave/brave-browser#8216

Submitter Checklist:

Test Plan:

  1. See Desktop :: Implement "Enabling Sites to Determine Brave" Spec brave-browser#8216
  2. npm run test -- brave_browser_tests --filter=NavigatorGetBraveDetectedTest.*

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.

@bsclifton bsclifton added this to the 1.7.x - Nightly milestone Feb 24, 2020
@bsclifton bsclifton self-assigned this Feb 24, 2020
test/BUILD.gn Outdated Show resolved Hide resolved
@bsclifton bsclifton requested a review from petemill February 24, 2020 07:28
@bsclifton
Copy link
Member Author

@iefremov iefremov self-requested a review February 24, 2020 08:17
@jumde
Copy link
Contributor

jumde commented Feb 24, 2020

Two questions: I'm running a build to confirm

  1. Are we enabling any Client Hints with this change?
  2. Is Brave being appended to the user agent (navigator.userAgent).

@bsclifton
Copy link
Member Author

@jumde answers:

  1. No - client hints is not enabled. It remains off by default. We'd need to modify src/brave/app/brave_main_delegate.cc to add kUserAgentClientHint
  2. Actual user agent is NOT modified (ex: navigator.userAgent)

@bsclifton
Copy link
Member Author

Needs some patch cleanup and need to modify test plan (will do that later tonite)

@bsclifton
Copy link
Member Author

Ready for review 😄 I'd love to further clean up patches, but need help in order to do so
cc: @bridiver @petemill @pes10k @jumde

@pes10k
Copy link
Contributor

pes10k commented Feb 29, 2020

@bsclifton sure happy to help. What would be most helpful?

@bsclifton
Copy link
Member Author

@pes10k mostly just looking at the code to see if the approach taken looks good 😄 I guess we went over it together, so you can share some notes and approve/deny based on that (just to have something formal on GitHub)

@pes10k
Copy link
Contributor

pes10k commented Mar 2, 2020

@bsclifton made a tiny suggestion, hope its helpful. Otherwise, LGTM!

@@ -4,3 +4,4 @@
import("//brave/brave_repack_locales.gni")
import("//brave/build/features.gni")
import("//brave/net/sources.gni")
import("//brave/third_party/blink/renderer/includes.gni")
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe modules.gni ?

Copy link
Member Author

Choose a reason for hiding this comment

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

considered that- but it also includes core changes

Copy link
Collaborator

Choose a reason for hiding this comment

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

but its purpose is to make modules work. If nothing else config.gni would be a better choice, but it can be a follow-up

@bsclifton
Copy link
Member Author

Ready for re-review 😄👍

@pes10k
Copy link
Contributor

pes10k commented Mar 3, 2020

wunderbar, lgtm!

Copy link
Contributor

@pes10k pes10k left a comment

Choose a reason for hiding this comment

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

lgtm!

@bsclifton
Copy link
Member Author

Only CI failure was during Publish xUnit test result report - (1.5 sec in self) on macOS:
https://ci.brave.com/job/brave-browser-build-pr/job/bsc-detect-brave/15/execution/node/641/log/

All builds / tests / create_dists / etc worked great 😄👍

ui_test_utils::NavigateToURL(browser(), url);
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_EQ(true, EvalJs(
Copy link
Contributor

Choose a reason for hiding this comment

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

EXPECT_TRUE(EvalJs(contents, "getBraveDetected()"));

Copy link
Member Author

@bsclifton bsclifton Mar 5, 2020

Choose a reason for hiding this comment

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

I tried to do this when you had shared feedback before; it's causing a problem though:

../../third_party/googletest/src/googletest/include/gtest/gtest.h:299:9: error: no viable conversion from 'const content::EvalJsResult' to 'bool'

Not sure why comparison with EXPECT_EQ is handled differently than EXPECT_TRUE?

Copy link
Collaborator

Choose a reason for hiding this comment

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

From browser_test_utils.h:

//      For boolean results, note that EXPECT_TRUE(..) and EXPECT_FALSE()
//      won't compile; use EXPECT_EQ(true, ...) instead. This is intentional,
//      since EXPECT_TRUE() could be read ambiguously as either "expect
//      successful execution", "expect truthy value of any type", or "expect
//      boolean value 'true'".

Copy link
Member Author

Choose a reason for hiding this comment

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

ah- thanks, @zenparsing! 😄

@kjozwiak
Copy link
Member

kjozwiak commented Mar 6, 2020

Verification PASSED on macOS 10.15.3 x64 using the following build:

Brave | 1.7.47 Chromium: 80.0.3987.132 (Official Build) nightly (64-bit)
-- | --
Revision | fcea73228632975e052eb90fcf6cd1752d3b42b4-refs/branch-heads/3987@{#974}
OS | macOS Version 10.15.3 (Build 19D76)

Screen Shot 2020-03-05 at 8 20 37 PM

@Nathan13888
Copy link

How could this be disabled?

@bridiver
Copy link
Collaborator

How could this be disabled?

We have discussed some options including that it may be disabled when shields are down and I would personally be in favor of a feature flag or pref. Cc @pes10k

@Nathan13888
Copy link

Agreed. A feature flag would be more modular and obvious to configure. Using a feature flag would also allow for the feature to be disabled by default too.

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 "Enabling Sites to Determine Brave" Spec
8 participants