Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Add support for missing events:
Browse files Browse the repository at this point in the history
- AllowDatabase
- AllowDOMStorage
- AllowIndexedDB

*Includes fixes from review feedback*

Fixes brave/browser-laptop#12463
Fixes brave/browser-laptop#14475

Possibly addresses brave/browser-laptop#10685
  • Loading branch information
bsclifton committed Jul 6, 2018
1 parent decbaec commit de28298
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 0 deletions.
2 changes: 2 additions & 0 deletions brave/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 2 additions & 0 deletions brave/browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()));

Expand Down
88 changes: 88 additions & 0 deletions brave/browser/renderer_host/brave_render_message_filter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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 <stdint.h>

#include <string>

#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/profiles/profile.h"
#include "chrome/common/render_messages.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"

using content::BrowserThread;

namespace {

const uint32_t kRenderFilteredMessageClasses[] = {
ChromeMsgStart,
};

} // namespace

BraveRenderMessageFilter::BraveRenderMessageFilter(int render_process_id,
Profile* profile)
: BrowserMessageFilter(kRenderFilteredMessageClasses,
arraysize(kRenderFilteredMessageClasses)),
render_process_id_(render_process_id),
profile_(profile) {
host_content_settings_map_ =
HostContentSettingsMapFactory::GetForProfile(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(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) {
ContentSetting setting = host_content_settings_map_->GetContentSetting(
origin_url, top_origin_url, CONTENT_SETTINGS_TYPE_COOKIES, "");
*allowed = setting == ContentSetting::CONTENT_SETTING_ALLOW;
}

void BraveRenderMessageFilter::OnAllowDOMStorage(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
bool local,
bool* allowed) {
ContentSetting setting = host_content_settings_map_->GetContentSetting(
origin_url, top_origin_url, CONTENT_SETTINGS_TYPE_COOKIES, "");
*allowed = setting == ContentSetting::CONTENT_SETTING_ALLOW;
}

void BraveRenderMessageFilter::OnAllowIndexedDB(int render_frame_id,
const GURL& origin_url,
const GURL& top_origin_url,
const base::string16& name,
bool* allowed) {
ContentSetting setting = host_content_settings_map_->GetContentSetting(
origin_url, top_origin_url, CONTENT_SETTINGS_TYPE_COOKIES, "");
*allowed = setting == ContentSetting::CONTENT_SETTING_ALLOW;
}

69 changes: 69 additions & 0 deletions brave/browser/renderer_host/brave_render_message_filter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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 <string>
#include <vector>

#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"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"

class GURL;
class Profile;

namespace content_settings {
class CookieSettings;
}

// 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>;

~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);

const int render_process_id_;

// The Profile associated with our renderer process. This should only be
// accessed on the UI thread!
Profile* profile_;

HostContentSettingsMap* host_content_settings_map_;

DISALLOW_COPY_AND_ASSIGN(BraveRenderMessageFilter);
};

#endif // BRAVE_BROWSER_RENDERER_HOST_BRAVE_RENDER_MESSAGE_FILTER_H_

0 comments on commit de28298

Please sign in to comment.