-
Notifications
You must be signed in to change notification settings - Fork 893
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 Global Privacy Control #6743
Conversation
28786c4
to
979f35b
Compare
third_party/blink/renderer/modules/global_privacy_control/navigator_global_privacy_control.idl
Show resolved
Hide resolved
e1ec07f
to
3231ede
Compare
patches/content-browser-loader-browser_initiated_resource_request.cc.patch
Outdated
Show resolved
Hide resolved
patches/content-renderer-loader-web_worker_fetch_context_impl.cc.patch
Outdated
Show resolved
Hide resolved
patches/content-renderer-service_worker-service_worker_fetch_context_impl.cc.patch
Outdated
Show resolved
Hide resolved
static const char kSupplementName[]; | ||
|
||
static NavigatorGlobalPrivacyControl& From(Navigator&); | ||
static bool globalPrivacyControl(blink::Navigator&) { return true; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid inline methods
3231ede
to
73b3f84
Compare
73b3f84
to
c88878f
Compare
browser/net/brave_request_handler.cc
Outdated
@@ -100,6 +103,12 @@ void BraveRequestHandler::SetupCallbacks() { | |||
base::Bind(brave::OnBeforeStartTransaction_SiteHacksWork); | |||
before_start_transaction_callbacks_.push_back(start_transaction_callback); | |||
|
|||
if (base::FeatureList::IsEnabled(features::kGlobalPrivacyControl)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to encapsulate feature checks inside the relevant code, so rather than conditionally including the helper, you should always include it and conditionally add the header inside it
common/brave_features.cc
Outdated
@@ -19,4 +19,7 @@ const base::Feature kBraveRewards{"BraveRewards", | |||
#endif | |||
#endif // defined(OS_ANDROID) | |||
|
|||
const base::Feature kGlobalPrivacyControl{"GlobalPrivacyControl", | |||
base::FEATURE_ENABLED_BY_DEFAULT}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want this enabled by default in nightly, right? You can check the release channel in BraveMainDelegate::BasicStartupComplete
and conditionally add it to the list of enabled features
static const char kSupplementName[]; | ||
|
||
static NavigatorGlobalPrivacyControl& From(Navigator&); | ||
static bool globalPrivacyControl(blink::Navigator&); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have tests for the api and also for the header
63840c0
to
634bea3
Compare
const ResponseCallback& next_callback, | ||
std::shared_ptr<BraveRequestInfo> ctx) { | ||
if (base::FeatureList::IsEnabled(features::kGlobalPrivacyControl)) { | ||
headers->SetHeader(kSecGpcHeader, "1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need it for all requests, or just for navigations/downloads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to @pes10k about this as it's not currently described anywhere - he will try to get that clarified in the spec but there shouldn't be any harm in doing it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just heard back, its intended to be on every request
common/brave_features.cc
Outdated
@@ -19,4 +19,7 @@ const base::Feature kBraveRewards{"BraveRewards", | |||
#endif | |||
#endif // defined(OS_ANDROID) | |||
|
|||
const base::Feature kGlobalPrivacyControl{"GlobalPrivacyControl", | |||
base::FEATURE_DISABLED_BY_DEFAULT}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format
@@ -19,4 +19,7 @@ const base::Feature kBraveRewards{"BraveRewards", | |||
#endif | |||
#endif // defined(OS_ANDROID) | |||
|
|||
const base::Feature kGlobalPrivacyControl{"GlobalPrivacyControl", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a comment, link to the spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spec is currently not public, so there isn't a stable URL for it at the moment unfortunately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps just a comment or link to a wiki on brave-browser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment from the spec
namespace blink { | ||
|
||
NavigatorGlobalPrivacyControl:: | ||
NavigatorGlobalPrivacyControl(Navigator& navigator) // NOLINT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious - why this is NOLINT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint asks for const Navigator&
but then it doesn't match the IDL generated header.
|
||
std::unique_ptr<net::test_server::HttpResponse> HandleRequest( | ||
const net::test_server::HttpRequest& request) { | ||
auto http_response = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you really need to craft responses, the same can be achieved with RegisterRequestMonitor
- e.g. see BraveContentSettingsAgentImplBrowserTest
. Also this callback is called on IO thread, so acess to header_result_
should be guarded
IN_PROC_BROWSER_TEST_F(GlobalPrivacyControlNetworkDelegateBrowserTest, | ||
IncludesSecGPCHeader) { | ||
const GURL target = https_server().GetURL("example.com", "/index.html"); | ||
ui_test_utils::UrlLoadObserver load_complete( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for observers, just ui_test_utils::NavigateToURL
load_complete.Wait(); | ||
|
||
bool as_expected = false; | ||
ASSERT_TRUE(ExecuteScriptAndExtractBool( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK this is deprecated in favor of EvalJs
browser()->tab_strip_model()->GetActiveWebContents(), | ||
"window.domAutomationController.send(navigator.globalPrivacyControl)", | ||
&as_expected)); | ||
EXPECT_EQ(as_expected, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXPECT_TRUE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't use EXPECT_TRUE
with EvalJs
, so I'm leaving EXPECT_EQ
here
EXPECT_EQ(as_expected, true); | ||
} | ||
|
||
class DisabledGlobalPrivacyControlNetworkDelegateBrowserTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mb just disable feature in the test itself?
634bea3
to
4d179b3
Compare
4d179b3
to
4eabf46
Compare
* 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/. */ | ||
|
||
#include <map> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed now
|
||
if (request.headers.find("Sec-GPC") == request.headers.end()) { | ||
header_result_ = GPCHeaderResult::NO_HEADER; | ||
} else if (request.headers.at("Sec-GPC") != "1") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably should use kSecGpcHeader
from network_constants.h
void HandleRequest(const net::test_server::HttpRequest& request) { | ||
base::AutoLock auto_lock(header_result_lock_); | ||
|
||
if (request.headers.find("Sec-GPC") == request.headers.end()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super small nit:
auto it = request.headers.find("Sec-GPC");
if (it == request.headers.end()) {
... }
else if (it->second != "1") {
... }
else {
... }
#include "net/test/embedded_test_server/http_request.h" | ||
#include "net/test/embedded_test_server/http_response.h" | ||
|
||
enum GPCHeaderResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum class
, also I think preferable naming for constants is kOk
, kNoRequest
, etc
4eabf46
to
4e06a9f
Compare
|
||
bool NavigatorGlobalPrivacyControl:: | ||
globalPrivacyControl(blink::Navigator& navigator) { // NOLINT | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we want to check base::FeatureList::IsEnabled
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbondy I discussed this with @iefremov and @bridiver in DMs - there isn't a way to gate the presence of the IDL-generated API by a feature flag. We've decided it's fine since this is purely a new API and shouldn't break webcompat anywhere. And if it has to exist, better to just always return true
rather than false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
4e06a9f
to
798d7f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Resolves brave/brave-browser#11917
Submitter Checklist:
npm run lint
,npm run gn_check
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
This feature is gated in Nightly, so these tests will not work in Release or Beta.
Sec-GPC
headerWith the Network tab of the Developer Tools open, navigate to an HTTPS webpage of your choice. Choose a few requests at random and verify that the "Sec-GPC" header is set and has a value of "1".
globalPrivacyControl
APIOpen the Console in the Developer Tools, and verify that the following Javascript evaluates to
true
:Reviewer Checklist:
After-merge Checklist:
changes has landed on.