Skip to content

Commit

Permalink
implement Sec-GPC header and globalPrivacyControl JS API
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Oct 2, 2020
1 parent f4e20a3 commit ec4ccbb
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 2 deletions.
2 changes: 2 additions & 0 deletions browser/net/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ source_set("net") {
"brave_stp_util.h",
"brave_system_request_handler.cc",
"brave_system_request_handler.h",
"global_privacy_control_network_delegate_helper.cc",
"global_privacy_control_network_delegate_helper.h",
"resource_context_data.cc",
"resource_context_data.h",
"url_context.cc",
Expand Down
5 changes: 5 additions & 0 deletions browser/net/brave_request_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "brave/browser/net/brave_httpse_network_delegate_helper.h"
#include "brave/browser/net/brave_site_hacks_network_delegate_helper.h"
#include "brave/browser/net/brave_stp_util.h"
#include "brave/browser/net/global_privacy_control_network_delegate_helper.h"
#include "brave/browser/translate/buildflags/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_referrals/buildflags/buildflags.h"
Expand Down Expand Up @@ -100,6 +101,10 @@ void BraveRequestHandler::SetupCallbacks() {
base::Bind(brave::OnBeforeStartTransaction_SiteHacksWork);
before_start_transaction_callbacks_.push_back(start_transaction_callback);

start_transaction_callback =
base::Bind(brave::OnBeforeStartTransaction_GlobalPrivacyControlWork);
before_start_transaction_callbacks_.push_back(start_transaction_callback);

#if BUILDFLAG(ENABLE_BRAVE_REFERRALS)
start_transaction_callback =
base::Bind(brave::OnBeforeStartTransaction_ReferralsWork);
Expand Down
24 changes: 24 additions & 0 deletions browser/net/global_privacy_control_network_delegate_helper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/net/global_privacy_control_network_delegate_helper.h"

#include <memory>

#include "brave/common/network_constants.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_headers.h"

namespace brave {

int OnBeforeStartTransaction_GlobalPrivacyControlWork(
net::HttpRequestHeaders* headers,
const ResponseCallback& next_callback,
std::shared_ptr<BraveRequestInfo> ctx) {
headers->SetHeader(kSecGpcHeader, "1");
return net::OK;
}

} // namespace brave
22 changes: 22 additions & 0 deletions browser/net/global_privacy_control_network_delegate_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_NET_GLOBAL_PRIVACY_CONTROL_NETWORK_DELEGATE_HELPER_H_
#define BRAVE_BROWSER_NET_GLOBAL_PRIVACY_CONTROL_NETWORK_DELEGATE_HELPER_H_

#include <memory>

#include "brave/browser/net/url_context.h"

namespace brave {

int OnBeforeStartTransaction_GlobalPrivacyControlWork(
net::HttpRequestHeaders* headers,
const ResponseCallback& next_callback,
std::shared_ptr<BraveRequestInfo> ctx);

} // namespace brave

#endif // BRAVE_BROWSER_NET_GLOBAL_PRIVACY_CONTROL_NETWORK_DELEGATE_HELPER_H_
2 changes: 2 additions & 0 deletions common/network_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ const char kBraveServicesKeyHeader[] = "BraveServiceKey";

const char kBittorrentMimeType[] = "application/x-bittorrent";
const char kOctetStreamMimeType[] = "application/octet-stream";

const char kSecGpcHeader[] = "Sec-GPC";
2 changes: 2 additions & 0 deletions common/network_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ extern const char kBraveServicesKeyHeader[];

extern const char kBittorrentMimeType[];
extern const char kOctetStreamMimeType[];

extern const char kSecGpcHeader[];
#endif // BRAVE_COMMON_NETWORK_CONSTANTS_H_
8 changes: 6 additions & 2 deletions third_party/blink/renderer/includes.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ brave_blink_renderer_modules_visibility = [
]

brave_blink_sub_modules = [
"//brave/third_party/blink/renderer/modules/brave"
"//brave/third_party/blink/renderer/modules/brave",
"//brave/third_party/blink/renderer/modules/global_privacy_control"
]

# common includes which can help minimize patches for
# src/third_party/blink/renderer/modules/modules_idl_files.gni
brave_idl_imports = [ "//brave/third_party/blink/renderer/modules/brave/idls.gni" ]
brave_idl_imports = [
"//brave/third_party/blink/renderer/modules/brave/idls.gni",
"//brave/third_party/blink/renderer/modules/global_privacy_control/idls.gni"
]
13 changes: 13 additions & 0 deletions third_party/blink/renderer/modules/global_privacy_control/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import("//third_party/blink/renderer/modules/modules.gni")

blink_modules_sources("global_privacy_control") {
sources = [
"navigator_global_privacy_control.cc",
"navigator_global_privacy_control.h",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2020 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

modules_dependency_idl_files = [ "navigator_global_privacy_control.idl" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/third_party/blink/renderer/modules/global_privacy_control/navigator_global_privacy_control.h"

#include "third_party/blink/renderer/core/frame/navigator.h"

namespace blink {

NavigatorGlobalPrivacyControl::
NavigatorGlobalPrivacyControl(Navigator& navigator) // NOLINT
: Supplement<Navigator>(navigator) {}

// static
const char NavigatorGlobalPrivacyControl::kSupplementName[] =
"NavigatorGlobalPrivacyControl";

NavigatorGlobalPrivacyControl&
NavigatorGlobalPrivacyControl::From(Navigator& navigator) {
NavigatorGlobalPrivacyControl* supplement =
Supplement<Navigator>::From<NavigatorGlobalPrivacyControl>(navigator);
if (!supplement) {
supplement = MakeGarbageCollected<NavigatorGlobalPrivacyControl>(navigator);
ProvideTo(navigator, supplement);
}
return *supplement;
}

bool NavigatorGlobalPrivacyControl::
globalPrivacyControl(blink::Navigator& navigator) { // NOLINT
return true;
}

void NavigatorGlobalPrivacyControl::Trace(blink::Visitor* visitor) const {
Supplement<Navigator>::Trace(visitor);
}

} // namespace blink
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2020 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef BRAVE_THIRD_PARTY_BLINK_RENDERER_MODULES_GLOBAL_PRIVACY_CONTROL_NAVIGATOR_GLOBAL_PRIVACY_CONTROL_H_
#define BRAVE_THIRD_PARTY_BLINK_RENDERER_MODULES_GLOBAL_PRIVACY_CONTROL_NAVIGATOR_GLOBAL_PRIVACY_CONTROL_H_

#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h"

namespace blink {

class Navigator;

class NavigatorGlobalPrivacyControl final
: public GarbageCollected<NavigatorGlobalPrivacyControl>,
public Supplement<Navigator>,
public NameClient {

public:
static const char kSupplementName[];

static NavigatorGlobalPrivacyControl& From(Navigator&);
static bool globalPrivacyControl(blink::Navigator&);

explicit NavigatorGlobalPrivacyControl(Navigator&);

void Trace(blink::Visitor*) const override;
const char* NameInHeapSnapshot() const override {
return "NavigatorGlobalPrivacyControl";
}
};

} // namespace blink

#endif // BRAVE_THIRD_PARTY_BLINK_RENDERER_MODULES_GLOBAL_PRIVACY_CONTROL_NAVIGATOR_GLOBAL_PRIVACY_CONTROL_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
[
ImplementedAs=NavigatorGlobalPrivacyControl
] partial interface Navigator {
readonly attribute boolean globalPrivacyControl;
};

0 comments on commit ec4ccbb

Please sign in to comment.