Skip to content

Commit

Permalink
1. Moved logic for ShouldStoreState to `tracking_protection_service…
Browse files Browse the repository at this point in the history
….cc`.

2. Invoking super OnAllow functions from BraveRenderMessageFilter.
3. Using chromium src redefine for BraveRenderMessageFilter
  • Loading branch information
jumde committed Sep 27, 2018
1 parent 01e7476 commit 0577615
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 73 deletions.
65 changes: 23 additions & 42 deletions browser/renderer_host/brave_render_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@

#include "brave/browser/brave_browser_process_impl.h"
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/render_messages.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "content/public/browser/browser_thread.h"

using content::BrowserThread;

BraveRenderMessageFilter::BraveRenderMessageFilter(int render_process_id,
Profile* profile)
: ChromeRenderMessageFilter(render_process_id, profile),
host_content_settings_map_(HostContentSettingsMapFactory::GetForProfile(profile)),
weak_factory_(this) {
host_content_settings_map_(HostContentSettingsMapFactory::GetForProfile(profile)) {
}

BraveRenderMessageFilter::~BraveRenderMessageFilter() {}
Expand All @@ -39,62 +34,48 @@ bool BraveRenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
return ChromeRenderMessageFilter::OnMessageReceived(message);
}

bool BraveRenderMessageFilter::ShouldStoreState(const GURL& origin_url,
const GURL& top_origin_url) {
CHECK(g_brave_browser_process->tracking_protection_service()->IsInitialized());

bool allow_brave_shields = brave_shields::IsAllowContentSetting(
host_content_settings_map_, top_origin_url, top_origin_url, CONTENT_SETTINGS_TYPE_PLUGINS,
brave_shields::kBraveShields);

bool allow_trackers = brave_shields::IsAllowContentSetting(
host_content_settings_map_, top_origin_url, top_origin_url, CONTENT_SETTINGS_TYPE_PLUGINS,
brave_shields::kTrackers);

return !(allow_brave_shields && !allow_trackers &&
!g_brave_browser_process->tracking_protection_service()->ShouldStoreState(origin_url)) &&
cookie_settings_->IsCookieAccessAllowed(origin_url, top_origin_url);;
}

void BraveRenderMessageFilter::OnAllowDatabase(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
const base::string16& name,
const base::string16& display_name,
bool* allowed) {
*allowed = ShouldStoreState(origin_url, top_origin_url);

BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
render_process_id_, render_frame_id, origin_url, name,
display_name, !*allowed));
CHECK(g_brave_browser_process->tracking_protection_service()->IsInitialized());
*allowed = g_brave_browser_process->tracking_protection_service()->ShouldStoreState(host_content_settings_map_,
origin_url, top_origin_url);

if (*allowed) {
ChromeRenderMessageFilter::OnAllowDatabase(render_frame_id, origin_url, top_origin_url,
name, display_name, allowed);
}
}

void BraveRenderMessageFilter::OnAllowDOMStorage(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
bool local,
bool* allowed) {
*allowed = ShouldStoreState(origin_url, top_origin_url);
CHECK(g_brave_browser_process->tracking_protection_service()->IsInitialized());
*allowed = g_brave_browser_process->tracking_protection_service()->ShouldStoreState(host_content_settings_map_,
origin_url, top_origin_url);

if (*allowed) {
ChromeRenderMessageFilter::OnAllowDOMStorage(render_frame_id, origin_url, top_origin_url,
local, allowed);
}

BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&TabSpecificContentSettings::DOMStorageAccessed,
render_process_id_, render_frame_id, origin_url, local,
!*allowed));
}

void BraveRenderMessageFilter::OnAllowIndexedDB(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
const base::string16& name,
bool* allowed) {
*allowed = ShouldStoreState(origin_url, top_origin_url);
CHECK(g_brave_browser_process->tracking_protection_service()->IsInitialized());
*allowed = g_brave_browser_process->tracking_protection_service()->ShouldStoreState(host_content_settings_map_,
origin_url, top_origin_url);

BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
render_process_id_, render_frame_id, origin_url, name,
!*allowed));
if (*allowed) {
ChromeRenderMessageFilter::OnAllowIndexedDB(render_frame_id, origin_url, top_origin_url, name, allowed);
}
}
7 changes: 3 additions & 4 deletions browser/renderer_host/brave_render_message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
#define BRAVE_BROWSER_RENDERER_HOST_BRAVE_RENDER_MESSAGE_FILTER_H_

#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/browser_message_filter.h"

class HostContentSettingsMap;

class BraveRenderMessageFilter : public ChromeRenderMessageFilter {
public:
using ChromeRenderMessageFilter::ChromeRenderMessageFilter;
BraveRenderMessageFilter(int render_process_id, Profile* profile);
bool OnMessageReceived(const IPC::Message& message) override;

Expand Down Expand Up @@ -38,10 +40,7 @@ class BraveRenderMessageFilter : public ChromeRenderMessageFilter {
const base::string16& name,
bool* allowed);

bool ShouldStoreState(const GURL& origin_url, const GURL& top_origin_url);

HostContentSettingsMap *host_content_settings_map_;
base::WeakPtrFactory<BraveRenderMessageFilter> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(BraveRenderMessageFilter);
};
Expand Down
5 changes: 5 additions & 0 deletions chromium_src/chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

#include "build/build_config.h" // For OS_MACOSX

#include "brave/browser/renderer_host/brave_render_message_filter.h"
#include "../../../../chrome/browser/renderer_host/chrome_render_message_filter.h"
#undef ChromeRenderMessageFilter
#define ChromeRenderMessageFilter BraveRenderMessageFilter

#if defined(OS_MACOSX)
#include "brave/browser/brave_browser_main_parts_mac.h"
#undef ChromeBrowserMainPartsMac
Expand Down
25 changes: 20 additions & 5 deletions components/brave_shields/browser/tracking_protection_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/browser/dat_file_util.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/vendor/tracking-protection/TPParser.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"

#define NAVIGATION_TRACKERS_FILE "TrackingProtection.dat"
#define STORAGE_TRACKERS_FILE "StorageTrackingProtection.dat"
Expand Down Expand Up @@ -90,15 +93,27 @@ bool TrackingProtectionService::ShouldStartRequest(const GURL& url,
return false;
}

bool TrackingProtectionService::ShouldStoreState(const GURL& url) {
bool TrackingProtectionService::ShouldStoreState(HostContentSettingsMap* map, const GURL& top_origin_url,
const GURL& origin_url) {

if (!first_party_storage_trackers_initailized_) {
LOG(ERROR) << "First party storage trackers not initialized";
return true;
}
}
std::string host = origin_url.host();

std::string host = url.host();
return !(std::find(first_party_storage_trackers_.begin(), first_party_storage_trackers_.end(), host)
!= first_party_storage_trackers_.end());
bool allow_brave_shields = IsAllowContentSetting(
map, top_origin_url, origin_url, CONTENT_SETTINGS_TYPE_PLUGINS,
brave_shields::kBraveShields);

bool allow_trackers = IsAllowContentSetting(
map, top_origin_url, origin_url, CONTENT_SETTINGS_TYPE_PLUGINS,
brave_shields::kTrackers);

bool denyStorage = std::find(first_party_storage_trackers_.begin(), first_party_storage_trackers_.end(), host)
!= first_party_storage_trackers_.end();

return !(allow_brave_shields && !allow_trackers && denyStorage);
}

void TrackingProtectionService::ParseStorageTrackersData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "content/public/common/resource_type.h"

class CTPParser;
class HostContentSettingsMap;
class TrackingProtectionServiceTest;

namespace brave_shields {
Expand All @@ -45,7 +46,8 @@ class TrackingProtectionService : public BaseBraveShieldsService {
bool ShouldStartRequest(const GURL& spec,
content::ResourceType resource_type,
const std::string& tab_host) override;
bool ShouldStoreState(const GURL& url);
bool ShouldStoreState(HostContentSettingsMap* map,
const GURL& top_origin_url, const GURL& origin_url);

protected:
bool Init() override;
Expand Down
21 changes: 0 additions & 21 deletions patches/chrome-browser-chrome_content_browser_client.cc.patch

This file was deleted.

0 comments on commit 0577615

Please sign in to comment.