-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
262 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* 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/renderer_host/brave_render_message_filter.h" | ||
|
||
#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) { | ||
} | ||
|
||
BraveRenderMessageFilter::~BraveRenderMessageFilter() {} | ||
|
||
bool BraveRenderMessageFilter::OnMessageReceived(const IPC::Message& message) { | ||
bool handled = true; | ||
IPC_BEGIN_MESSAGE_MAP(BraveRenderMessageFilter, message) | ||
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDatabase, OnAllowDatabase); | ||
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDOMStorage, OnAllowDOMStorage); | ||
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowIndexedDB, OnAllowIndexedDB); | ||
IPC_MESSAGE_UNHANDLED(handled = false) | ||
IPC_END_MESSAGE_MAP() | ||
|
||
if (handled) return true; | ||
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)); | ||
} | ||
|
||
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); | ||
|
||
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); | ||
|
||
BrowserThread::PostTask( | ||
BrowserThread::UI, FROM_HERE, | ||
base::Bind(&TabSpecificContentSettings::IndexedDBAccessed, | ||
render_process_id_, render_frame_id, origin_url, name, | ||
!*allowed)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* 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_RENDERER_HOST_BRAVE_RENDER_MESSAGE_FILTER_H_ | ||
#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 BraveRenderMessageFilter : public ChromeRenderMessageFilter { | ||
public: | ||
BraveRenderMessageFilter(int render_process_id, Profile* profile); | ||
bool OnMessageReceived(const IPC::Message& message) override; | ||
|
||
private: | ||
friend class base::DeleteHelper<BraveRenderMessageFilter>; | ||
|
||
~BraveRenderMessageFilter() override; | ||
|
||
void 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); | ||
|
||
void OnAllowDOMStorage(int render_frame_id, | ||
const GURL& origin_url, | ||
const GURL& top_origin_url, | ||
bool local, | ||
bool* allowed); | ||
|
||
void OnAllowIndexedDB(int render_frame_id, | ||
const GURL& origin_url, | ||
const GURL& top_origin_url, | ||
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); | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_RENDERER_HOST_BRAVE_RENDER_MESSAGE_FILTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
patches/chrome-browser-chrome_content_browser_client.cc.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc | ||
index a85e9d9c17ef8bfcc89f96376675932e656dab03..3bee18f4f26d4a8ac7eaa2cff6c79395aabbcba6 100644 | ||
--- a/chrome/browser/chrome_content_browser_client.cc | ||
+++ b/chrome/browser/chrome_content_browser_client.cc | ||
@@ -29,6 +29,7 @@ | ||
#include "base/strings/utf_string_conversions.h" | ||
#include "base/sys_info.h" | ||
#include "base/threading/thread_task_runner_handle.h" | ||
+#include "brave/browser/renderer_host/brave_render_message_filter.h" | ||
#include "build/build_config.h" | ||
#include "chrome/browser/after_startup_task_utils.h" | ||
#include "chrome/browser/browser_about_handler.h" | ||
@@ -1262,7 +1263,7 @@ void ChromeContentBrowserClient::RenderProcessWillLaunch( | ||
service_manager::mojom::ServiceRequest* service_request) { | ||
int id = host->GetID(); | ||
Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | ||
- host->AddFilter(new ChromeRenderMessageFilter(id, profile)); | ||
+ host->AddFilter(new BraveRenderMessageFilter(id, profile)); | ||
#if BUILDFLAG(ENABLE_EXTENSIONS) | ||
host->AddFilter(new cast::CastTransportHostFilter(profile)); | ||
#endif |
20 changes: 20 additions & 0 deletions
20
patches/chrome-browser-renderer_host-chrome_render_message_filter.h.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.h b/chrome/browser/renderer_host/chrome_render_message_filter.h | ||
index e1ce2f28510360f9d3e5cefd5c0fdd74e48d61da..5972976ad1fc1b467ba830e7ddf048515a638c0e 100644 | ||
--- a/chrome/browser/renderer_host/chrome_render_message_filter.h | ||
+++ b/chrome/browser/renderer_host/chrome_render_message_filter.h | ||
@@ -18,6 +18,7 @@ | ||
|
||
class GURL; | ||
class Profile; | ||
+class BraveRenderMessageFilter; | ||
|
||
namespace chrome_browser_net { | ||
class Predictor; | ||
@@ -47,6 +48,7 @@ class ChromeRenderMessageFilter : public content::BrowserMessageFilter { | ||
content::BrowserThread::ID* thread) override; | ||
|
||
private: | ||
+ friend class BraveRenderMessageFilter; | ||
friend class content::BrowserThread; | ||
friend class base::DeleteHelper<ChromeRenderMessageFilter>; | ||
|