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

STP #403

Merged
merged 2 commits into from
Apr 18, 2019
Merged

STP #403

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ source_set("browser_process") {
"component_updater/brave_component_updater_configurator.h",
"component_updater/brave_crx_update_service.cc",
"component_updater/brave_crx_update_service.h",
"content_settings/brave_cookie_settings_factory.cc",
"content_settings/brave_cookie_settings_factory.h",
"geolocation/brave_geolocation_permission_context.cc",
"geolocation/brave_geolocation_permission_context.h",
"mac/sparkle_glue.mm",
Expand Down
127 changes: 61 additions & 66 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
#include "brave/browser/renderer_host/brave_navigation_ui_data.h"
#include "brave/browser/tor/tor_profile_service_factory.h"
#include "brave/common/brave_cookie_blocking.h"
#include "brave/common/webui_url_constants.h"
#include "brave/common/tor/tor_launcher.mojom.h"
#include "brave/common/tor/switches.h"
#include "brave/common/tor/tor_launcher.mojom.h"
#include "brave/common/webui_url_constants.h"
#include "brave/components/brave_ads/browser/buildflags/buildflags.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/components/brave_webtorrent/browser/content_browser_client_helper.h"
#include "brave/components/content_settings/core/browser/brave_cookie_settings.h"
Expand All @@ -48,11 +50,11 @@
#include "services/service_manager/public/cpp/manifest_builder.h"
#include "ui/base/l10n/l10n_util.h"

using brave_shields::BraveShieldsWebContentsObserver;
using content::BrowserThread;
using content::ContentBrowserClient;
using content::RenderFrameHost;
using content::WebContents;
using brave_shields::BraveShieldsWebContentsObserver;

#if BUILDFLAG(BRAVE_ADS_ENABLED)
#include "brave/components/services/bat_ads/public/interfaces/bat_ads.mojom.h"
Expand Down Expand Up @@ -90,15 +92,14 @@ bool HandleURLOverrideRewrite(GURL* url,
}

bool HandleURLReverseOverrideRewrite(GURL* url,
content::BrowserContext* browser_context) {
content::BrowserContext* browser_context) {
if (HandleURLOverrideRewrite(url, browser_context))
return true;

return false;
}

bool HandleURLRewrite(GURL* url,
content::BrowserContext* browser_context) {
bool HandleURLRewrite(GURL* url, content::BrowserContext* browser_context) {
if (HandleURLOverrideRewrite(url, browser_context))
return true;

Expand All @@ -109,13 +110,12 @@ bool HandleURLRewrite(GURL* url,

BraveContentBrowserClient::BraveContentBrowserClient(
ChromeFeatureListCreator* chrome_feature_list_creator)
: ChromeContentBrowserClient(chrome_feature_list_creator) {
}
: ChromeContentBrowserClient(chrome_feature_list_creator) {}

BraveContentBrowserClient::~BraveContentBrowserClient() {}

content::BrowserMainParts* BraveContentBrowserClient::CreateBrowserMainParts(
const content::MainFunctionParams& parameters) {
const content::MainFunctionParams& parameters) {
ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>(
ChromeContentBrowserClient::CreateBrowserMainParts(parameters));
main_parts->AddParts(new BraveBrowserMainExtraParts());
Expand All @@ -128,8 +128,7 @@ void BraveContentBrowserClient::BrowserURLHandlerCreated(
content::BrowserURLHandler::null_handler());
handler->AddHandlerPair(&webtorrent::HandleTorrentURLRewrite,
&webtorrent::HandleTorrentURLReverseRewrite);
handler->AddHandlerPair(&HandleURLRewrite,
&HandleURLReverseOverrideRewrite);
handler->AddHandlerPair(&HandleURLRewrite, &HandleURLReverseOverrideRewrite);
ChromeContentBrowserClient::BrowserURLHandlerCreated(handler);
}

Expand All @@ -141,7 +140,8 @@ bool BraveContentBrowserClient::AllowAccessCookie(
int render_frame_id) {
GURL tab_origin =
BraveShieldsWebContentsObserver::GetTabURLFromRenderFrameInfo(
render_process_id, render_frame_id, -1).GetOrigin();
render_process_id, render_frame_id, -1)
.GetOrigin();
ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
bool allow_brave_shields =
brave_shields::IsAllowContentSettingWithIOData(
Expand All @@ -156,16 +156,22 @@ bool BraveContentBrowserClient::AllowAccessCookie(
brave_shields::kCookies);
content_settings::BraveCookieSettings* cookie_settings =
(content_settings::BraveCookieSettings*)io_data->GetCookieSettings();
bool allow = !ShouldBlockCookie(allow_brave_shields, allow_1p_cookies,
allow_3p_cookies, first_party, url,
cookie_settings->GetAllowGoogleAuth()) &&
cookie_settings->IsCookieAccessAllowed(url, first_party, tab_origin);
bool allow =
!ShouldBlockCookie(allow_brave_shields, allow_1p_cookies,
allow_3p_cookies, first_party, url,
cookie_settings->GetAllowGoogleAuth()) &&
g_brave_browser_process->tracking_protection_service()->ShouldStoreState(
cookie_settings, io_data->GetHostContentSettingsMap(),
render_process_id, render_frame_id, url, first_party, tab_origin);
return allow;
}

bool BraveContentBrowserClient::AllowGetCookie(const GURL& url,
const GURL& first_party, const net::CookieList& cookie_list,
content::ResourceContext* context, int render_process_id,
bool BraveContentBrowserClient::AllowGetCookie(
const GURL& url,
const GURL& first_party,
const net::CookieList& cookie_list,
content::ResourceContext* context,
int render_process_id,
int render_frame_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
bool allow = AllowAccessCookie(url, first_party, context, render_process_id,
Expand All @@ -176,9 +182,12 @@ bool BraveContentBrowserClient::AllowGetCookie(const GURL& url,
return allow;
}

bool BraveContentBrowserClient::AllowSetCookie(const GURL& url,
const GURL& first_party, const net::CanonicalCookie& cookie,
content::ResourceContext* context, int render_process_id,
bool BraveContentBrowserClient::AllowSetCookie(
const GURL& url,
const GURL& first_party,
const net::CanonicalCookie& cookie,
content::ResourceContext* context,
int render_process_id,
int render_frame_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
bool allow = AllowAccessCookie(url, first_party, context, render_process_id,
Expand All @@ -197,17 +206,17 @@ BraveContentBrowserClient::AllowWebBluetooth(
}

bool BraveContentBrowserClient::HandleExternalProtocol(
const GURL& url,
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
int child_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,
ui::PageTransition page_transition,
bool has_user_gesture,
const std::string& method,
const net::HttpRequestHeaders& headers) {
const GURL& url,
content::ResourceRequestInfo::WebContentsGetter web_contents_getter,
int child_id,
content::NavigationUIData* navigation_data,
bool is_main_frame,
ui::PageTransition page_transition,
bool has_user_gesture,
const std::string& method,
const net::HttpRequestHeaders& headers) {
if (webtorrent::HandleMagnetProtocol(url, web_contents_getter,
page_transition, has_user_gesture)) {
page_transition, has_user_gesture)) {
return true;
}

Expand All @@ -217,28 +226,27 @@ bool BraveContentBrowserClient::HandleExternalProtocol(
}

void BraveContentBrowserClient::RegisterOutOfProcessServices(
OutOfProcessServiceMap* services) {
OutOfProcessServiceMap* services) {
ChromeContentBrowserClient::RegisterOutOfProcessServices(services);
(*services)[tor::mojom::kTorLauncherServiceName] = base::BindRepeating(
l10n_util::GetStringUTF16, IDS_UTILITY_PROCESS_TOR_LAUNCHER_NAME);
l10n_util::GetStringUTF16, IDS_UTILITY_PROCESS_TOR_LAUNCHER_NAME);
#if BUILDFLAG(BRAVE_ADS_ENABLED)
(*services)[bat_ads::mojom::kServiceName] = base::BindRepeating(
l10n_util::GetStringUTF16, IDS_SERVICE_BAT_ADS);
(*services)[bat_ads::mojom::kServiceName] =
base::BindRepeating(l10n_util::GetStringUTF16, IDS_SERVICE_BAT_ADS);
#endif
#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
(*services)[bat_ledger::mojom::kServiceName] = base::BindRepeating(
l10n_util::GetStringUTF16, IDS_UTILITY_PROCESS_LEDGER_NAME);
l10n_util::GetStringUTF16, IDS_UTILITY_PROCESS_LEDGER_NAME);
#endif
}

std::unique_ptr<content::NavigationUIData>
BraveContentBrowserClient::GetNavigationUIData(
content::NavigationHandle* navigation_handle) {
content::NavigationHandle* navigation_handle) {
std::unique_ptr<BraveNavigationUIData> navigation_ui_data =
std::make_unique<BraveNavigationUIData>(navigation_handle);
Profile* profile =
Profile::FromBrowserContext(navigation_handle->GetWebContents()
->GetBrowserContext());
std::make_unique<BraveNavigationUIData>(navigation_handle);
Profile* profile = Profile::FromBrowserContext(
navigation_handle->GetWebContents()->GetBrowserContext());
TorProfileServiceFactory::SetTorNavigationUIData(profile,
navigation_ui_data.get());
return std::move(navigation_ui_data);
Expand All @@ -259,11 +267,11 @@ void BraveContentBrowserClient::AdjustUtilityServiceProcessCommandLine(
const service_manager::Identity& identity,
base::CommandLine* command_line) {
ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine(
identity, command_line);
identity, command_line);

if (identity.name() == tor::mojom::kTorLauncherServiceName) {
base::FilePath path =
g_brave_browser_process->tor_client_updater()->GetExecutablePath();
g_brave_browser_process->tor_client_updater()->GetExecutablePath();
DCHECK(!path.empty());
command_line->AppendSwitchPath(tor::switches::kTorExecutablePath,
path.BaseName());
Expand All @@ -281,28 +289,15 @@ void BraveContentBrowserClient::MaybeHideReferrer(
}

Profile* profile = Profile::FromBrowserContext(browser_context);
const bool allow_referrers =
brave_shields::IsAllowContentSettingsForProfile(
profile,
document_url,
document_url,
CONTENT_SETTINGS_TYPE_PLUGINS,
brave_shields::kReferrers);
const bool shields_up =
brave_shields::IsAllowContentSettingsForProfile(
profile,
document_url,
GURL(),
CONTENT_SETTINGS_TYPE_PLUGINS,
brave_shields::kBraveShields);
brave_shields::ShouldSetReferrer(allow_referrers,
shields_up,
referrer->url,
document_url,
request_url,
request_url.GetOrigin(),
referrer->policy,
referrer);
const bool allow_referrers = brave_shields::IsAllowContentSettingsForProfile(
profile, document_url, document_url, CONTENT_SETTINGS_TYPE_PLUGINS,
brave_shields::kReferrers);
const bool shields_up = brave_shields::IsAllowContentSettingsForProfile(
profile, document_url, GURL(), CONTENT_SETTINGS_TYPE_PLUGINS,
brave_shields::kBraveShields);
brave_shields::ShouldSetReferrer(
jumde marked this conversation as resolved.
Show resolved Hide resolved
allow_referrers, shields_up, referrer->url, document_url, request_url,
request_url.GetOrigin(), referrer->policy, referrer);
}

GURL BraveContentBrowserClient::GetEffectiveURL(
Expand Down
14 changes: 13 additions & 1 deletion browser/brave_tab_helpers.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright (c) 2019 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/. */

Expand All @@ -7,13 +8,19 @@
#include "brave/browser/brave_drm_tab_helper.h"
#include "brave/components/brave_ads/browser/ads_tab_helper.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP
#include "content/public/browser/web_contents.h"

#if !defined(OS_ANDROID)
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
#include "brave/components/brave_rewards/browser/rewards_helper.h"
#endif
#if BUILDFLAG(BRAVE_STP_ENABLED)
#include "brave/components/brave_shields/browser/tracking_protection_helper.h"

using brave_shields::TrackingProtectionHelper;
#endif
// Add tab helpers here unless they are intended for android too
#endif

Expand All @@ -28,6 +35,11 @@ void AttachTabHelpers(content::WebContents* web_contents) {
#endif
// Add tab helpers here unless they are intended for android too
BraveDrmTabHelper::CreateForWebContents(web_contents);
#if BUILDFLAG(BRAVE_STP_ENABLED)
if (TrackingProtectionHelper::IsSmartTrackingProtectionEnabled()) {
brave_shields::TrackingProtectionHelper::CreateForWebContents(web_contents);
}
#endif
#endif

brave_ads::AdsTabHelper::CreateForWebContents(web_contents);
Expand Down
16 changes: 16 additions & 0 deletions browser/content_settings/brave_cookie_settings_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright (c) 2019 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/content_settings/brave_cookie_settings_factory.h"

#include "brave/components/content_settings/core/browser/brave_cookie_settings.h"
#include "content/public/browser/browser_thread.h"

// static
scoped_refptr<content_settings::BraveCookieSettings>
BraveCookieSettingsFactory::GetForProfile(Profile* profile) {
return static_cast<content_settings::BraveCookieSettings*>(
CookieSettingsFactory::GetForProfile(profile).get());
}
33 changes: 33 additions & 0 deletions browser/content_settings/brave_cookie_settings_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright (c) 2019 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_CONTENT_SETTINGS_BRAVE_COOKIE_SETTINGS_FACTORY_H_
#define BRAVE_BROWSER_CONTENT_SETTINGS_BRAVE_COOKIE_SETTINGS_FACTORY_H_

#include <string>

#include "chrome/browser/content_settings/cookie_settings_factory.h"

namespace content_settings {
class BraveCookieSettings;
}

class Profile;

class BraveCookieSettingsFactory : public CookieSettingsFactory {
public:
static scoped_refptr<content_settings::BraveCookieSettings> GetForProfile(
Profile* profile);

private:
friend struct base::DefaultSingletonTraits<BraveCookieSettingsFactory>;

BraveCookieSettingsFactory();
~BraveCookieSettingsFactory() override;

DISALLOW_COPY_AND_ASSIGN(BraveCookieSettingsFactory);
};

#endif // BRAVE_BROWSER_CONTENT_SETTINGS_BRAVE_COOKIE_SETTINGS_FACTORY_H_
13 changes: 13 additions & 0 deletions browser/renderer_host/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import("//brave/components/brave_shields/browser/buildflags/buildflags.gni")

source_set("renderer_host") {
sources = [
"brave_navigation_ui_data.cc",
"brave_navigation_ui_data.h",
]

public_deps = [
"//brave/components/brave_shields/browser/buildflags",
]

if (brave_stp_enabled) {
sources += [
"brave_render_message_filter.cc",
"brave_render_message_filter.h",
]
}

deps = [
"//brave/browser/tor",
"//chrome/browser",
Expand Down
Loading