diff --git a/brave/browser/BUILD.gn b/brave/browser/BUILD.gn index 87ce63aa12..ead7f6fd62 100644 --- a/brave/browser/BUILD.gn +++ b/brave/browser/BUILD.gn @@ -35,6 +35,8 @@ source_set("browser") { "password_manager/brave_password_manager_client.cc", "renderer_preferences_helper.h", "renderer_preferences_helper.cc", + "renderer_host/brave_render_message_filter.h", + "renderer_host/brave_render_message_filter.cc", ] public_deps = [ diff --git a/brave/browser/brave_content_browser_client.cc b/brave/browser/brave_content_browser_client.cc index 2b7d3e5034..447fe4c74f 100644 --- a/brave/browser/brave_content_browser_client.cc +++ b/brave/browser/brave_content_browser_client.cc @@ -19,6 +19,7 @@ #include "base/strings/utf_string_conversions.h" #include "brave/browser/notifications/platform_notification_service_impl.h" #include "brave/browser/password_manager/brave_password_manager_client.h" +#include "brave/browser/renderer_host/brave_render_message_filter.h" #include "brave/grit/brave_resources.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/cache_stats_recorder.h" @@ -449,6 +450,7 @@ void BraveContentBrowserClient::RenderProcessWillLaunch( int id = host->GetID(); Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); + host->AddFilter(new BraveRenderMessageFilter(id, profile)); host->AddFilter(new printing::PrintingMessageFilter(id, profile)); host->AddFilter(new TtsMessageFilter(host->GetBrowserContext())); diff --git a/brave/browser/renderer_host/brave_render_message_filter.cc b/brave/browser/renderer_host/brave_render_message_filter.cc new file mode 100644 index 0000000000..231708250a --- /dev/null +++ b/brave/browser/renderer_host/brave_render_message_filter.cc @@ -0,0 +1,107 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "brave/browser/renderer_host/brave_render_message_filter.h" + +#include + +#include + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/logging.h" +#include "base/macros.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/metrics/chrome_metrics_service_accessor.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/common/render_messages.h" + +using content::BrowserThread; + +namespace { + +const uint32_t kRenderFilteredMessageClasses[] = { + ChromeMsgStart, NetworkHintsMsgStart, +}; + +} // namespace + +BraveRenderMessageFilter::BraveRenderMessageFilter(int render_process_id, + Profile* profile) + : BrowserMessageFilter(kRenderFilteredMessageClasses, + arraysize(kRenderFilteredMessageClasses)), + render_process_id_(render_process_id), + profile_(profile) { +} + +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_DELAY_REPLY( + ChromeViewHostMsg_RequestFileSystemAccessSync, + OnRequestFileSystemAccessSync) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RequestFileSystemAccessAsync, + OnRequestFileSystemAccessAsync) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowIndexedDB, OnAllowIndexedDB) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; +} + +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 = true; +} + +void BraveRenderMessageFilter::OnAllowDOMStorage(int render_frame_id, + const GURL& origin_url, + const GURL& top_origin_url, + bool local, + bool* allowed) { + *allowed = true; +} + +void BraveRenderMessageFilter::OnRequestFileSystemAccessSync( + int render_frame_id, + const GURL& origin_url, + const GURL& top_origin_url, + IPC::Message* reply_msg) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + + + ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg, + true); + Send(reply_msg); +} + +void BraveRenderMessageFilter::OnRequestFileSystemAccessAsync( + int render_frame_id, + int request_id, + const GURL& origin_url, + const GURL& top_origin_url) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + + Send(new ChromeViewMsg_RequestFileSystemAccessAsyncResponse( + render_frame_id, request_id, true)); +} + +void BraveRenderMessageFilter::OnAllowIndexedDB(int render_frame_id, + const GURL& origin_url, + const GURL& top_origin_url, + const base::string16& name, + bool* allowed) { + *allowed = true; +} + diff --git a/brave/browser/renderer_host/brave_render_message_filter.h b/brave/browser/renderer_host/brave_render_message_filter.h new file mode 100644 index 0000000000..df5d1d6551 --- /dev/null +++ b/brave/browser/renderer_host/brave_render_message_filter.h @@ -0,0 +1,70 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BRAVE_BROWSER_RENDERER_HOST_BRAVE_RENDER_MESSAGE_FILTER_H_ +#define BRAVE_BROWSER_RENDERER_HOST_BRAVE_RENDER_MESSAGE_FILTER_H_ + +#include +#include + +#include "base/callback.h" +#include "base/macros.h" +#include "base/sequenced_task_runner_helpers.h" +#include "content/public/browser/browser_message_filter.h" +#include "content/public/browser/browser_thread.h" +#include "extensions/buildflags/buildflags.h" +#include "ppapi/buildflags/buildflags.h" + +class GURL; +class Profile; + +// This class filters out incoming Chrome-specific IPC messages for the renderer +// process on the IPC thread. +class BraveRenderMessageFilter : public content::BrowserMessageFilter { + public: + BraveRenderMessageFilter(int render_process_id, Profile* profile); + + bool OnMessageReceived(const IPC::Message& message) override; + + private: + friend class content::BrowserThread; + friend class base::DeleteHelper; + + ~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 OnRequestFileSystemAccessSync(int render_frame_id, + const GURL& origin_url, + const GURL& top_origin_url, + IPC::Message* message); + void OnRequestFileSystemAccessAsync(int render_frame_id, + int request_id, + const GURL& origin_url, + const GURL& top_origin_url); + void OnAllowIndexedDB(int render_frame_id, + const GURL& origin_url, + const GURL& top_origin_url, + const base::string16& name, + bool* allowed); + + const int render_process_id_; + + // The Profile associated with our renderer process. This should only be + // accessed on the UI thread! + Profile* profile_; + + DISALLOW_COPY_AND_ASSIGN(BraveRenderMessageFilter); +}; + +#endif // BRAVE_BROWSER_RENDERER_HOST_BRAVE_RENDER_MESSAGE_FILTER_H_