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

Commit

Permalink
pass web preference defaults to content settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Aug 5, 2016
1 parent 5fd24c7 commit c599e30
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browser_url_handler.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/site_instance.h"
#include "extensions/browser/extension_message_filter.h"
#include "extensions/browser/extension_registry.h"
Expand Down Expand Up @@ -195,6 +196,11 @@ void AtomBrowserClientExtensionsPart::RegisterProfilePrefs(
extension_l10n_util::CurrentLocaleOrDefault());
}

void AtomBrowserClientExtensionsPart::OverrideWebkitPrefs(
content::RenderViewHost* host, content::WebPreferences* prefs) {
host->Send(new AtomMsg_UpdateWebKitPrefs(*prefs));
}

void AtomBrowserClientExtensionsPart::RenderProcessWillLaunch(
content::RenderProcessHost* host) {
int id = host->GetID();
Expand Down
5 changes: 5 additions & 0 deletions atom/browser/extensions/atom_browser_client_extensions_part.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class BrowserURLHandler;
class ResourceContext;
class SiteInstance;
class RenderProcessHost;
class RenderViewHost;
struct WebPreferences;
}

namespace extensions {
Expand Down Expand Up @@ -53,6 +55,9 @@ class AtomBrowserClientExtensionsPart {

static void SetApplicationLocale(std::string);

void OverrideWebkitPrefs(content::RenderViewHost* host,
content::WebPreferences* prefs);

// // Helper function to call InfoMap::SetSigninProcess().
// static void SetSigninProcess(content::SiteInstance* site_instance);
void RenderProcessWillLaunch(content::RenderProcessHost* host);
Expand Down
2 changes: 2 additions & 0 deletions atom/common/api/api_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ IPC_MESSAGE_CONTROL1(AtomMsg_UpdatePreferences, base::ListValue)
// Update renderer content settings
IPC_MESSAGE_CONTROL1(AtomMsg_UpdateContentSettings, base::DictionaryValue)

// Update renderer content settings
IPC_MESSAGE_CONTROL1(AtomMsg_UpdateWebKitPrefs, content::WebPreferences)
21 changes: 19 additions & 2 deletions atom/renderer/content_settings_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ bool ContentSettingsManager::OnControlMessageReceived(
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ContentSettingsManager, message)
IPC_MESSAGE_HANDLER(AtomMsg_UpdateContentSettings, OnUpdateContentSettings)
IPC_MESSAGE_HANDLER(AtomMsg_UpdateWebKitPrefs, OnUpdateWebKitPrefs)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}

void ContentSettingsManager::OnUpdateWebKitPrefs(
const content::WebPreferences& web_preferences) {
web_preferences_ = content::WebPreferences(web_preferences);
}

void ContentSettingsManager::OnUpdateContentSettings(
const base::DictionaryValue& content_settings) {
content_settings_ = content_settings.CreateDeepCopy();
Expand All @@ -66,11 +72,22 @@ ContentSetting ContentSettingsManager::GetSetting(
GURL secondary_url,
std::string content_type,
bool incognito) {
bool default_value = true;
if (content_type == "cookies")
default_value = web_preferences_.cookie_enabled;
else if (content_type == "images")
default_value = web_preferences_.images_enabled;
else if (content_type == "javascript")
default_value = web_preferences_.javascript_enabled;
else if (content_type == "displayInsecureContent")
default_value = web_preferences_.allow_displaying_insecure_content;
else if (content_type == "runInsecureContent")
default_value = web_preferences_.allow_running_insecure_content;

return GetContentSettingFromRules(primary_url,
secondary_url,
content_type,
content_type != "runInsecureContent"
? true : false);
default_value);
}

std::vector<std::string> ContentSettingsManager::GetContentTypes() {
Expand Down
4 changes: 4 additions & 0 deletions atom/renderer/content_settings_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "atom/renderer/content_settings_observer.h"
#include "base/values.h"
#include "components/content_settings/core/common/content_settings.h"
#include "content/public/common/web_preferences.h"
#include "content/public/renderer/render_thread_observer.h"

#include "atom/common/native_mate_converters/gurl_converter.h"
Expand Down Expand Up @@ -76,11 +77,14 @@ class ContentSettingsManager : public content::RenderThreadObserver {
// content::RenderThreadObserver:
bool OnControlMessageReceived(const IPC::Message& message) override;

void OnUpdateWebKitPrefs(
const content::WebPreferences& web_preferences);
void OnUpdateContentSettings(
const base::DictionaryValue& content_settings);

ContentSettingsObserverList observers_;

content::WebPreferences web_preferences_;
std::unique_ptr<base::DictionaryValue> content_settings_;

DISALLOW_COPY_AND_ASSIGN(ContentSettingsManager);
Expand Down
3 changes: 3 additions & 0 deletions brave/browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ void BraveContentBrowserClient::OverrideWebkitPrefs(
// Custom preferences of guest page.
auto web_contents = content::WebContents::FromRenderViewHost(host);
atom::WebContentsPreferences::OverrideWebkitPrefs(web_contents, prefs);
#if defined(ENABLE_EXTENSIONS)
extensions_part_->OverrideWebkitPrefs(host, prefs);
#endif
}


Expand Down

1 comment on commit c599e30

@diracdeltas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.