Skip to content

Commit

Permalink
Disable Flash by default and allow enabling with CTP
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed May 28, 2018
1 parent 2519846 commit fdd2652
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 0 deletions.
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ source_set("ui") {
"brave_browser_command_controller.h",
"brave_pages.cc",
"brave_pages.h",
"content_settings/brave_content_setting_bubble_model.cc",
"content_settings/brave_content_setting_bubble_model.h",
"toolbar/brave_app_menu_model.cc",
"toolbar/brave_app_menu_model.h",
"views/importer/brave_import_lock_dialog_view.cc",
Expand Down
65 changes: 65 additions & 0 deletions browser/ui/content_settings/brave_content_setting_bubble_model.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* 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/ui/content_settings/brave_content_setting_bubble_model.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/plugins/plugin_utils.h"
#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model_delegate.h"
#include "chrome/grit/generated_resources.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "ui/base/l10n/l10n_util.h"

BraveContentSettingPluginBubbleModel::BraveContentSettingPluginBubbleModel(
Delegate* delegate, content::WebContents* web_contents, Profile* profile)
: ContentSettingSimpleBubbleModel(delegate,
web_contents,
profile,
CONTENT_SETTINGS_TYPE_PLUGINS), profile_(profile) {
content_settings::SettingInfo info;
HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile);
GURL url = web_contents->GetURL();
std::unique_ptr<base::Value> value =
map->GetWebsiteSetting(url, url, content_type(), std::string(), &info);
// If the setting is not managed by the user, hide the "Manage" button.
if (info.source != content_settings::SETTING_SOURCE_USER)
set_manage_text_style(ContentSettingBubbleModel::ManageTextStyle::kNone);
set_custom_link(l10n_util::GetStringUTF16(IDS_BLOCKED_PLUGINS_LOAD_ALL));
set_custom_link_enabled(
web_contents &&
TabSpecificContentSettings::FromWebContents(web_contents)
->load_plugins_link_enabled());
set_show_learn_more(true);
}

void BraveContentSettingPluginBubbleModel::OnLearnMoreClicked() {
if (delegate())
delegate()->ShowLearnMorePage(CONTENT_SETTINGS_TYPE_PLUGINS);
}

void BraveContentSettingPluginBubbleModel::OnCustomLinkClicked() {
RunPluginsOnPage();
}

void BraveContentSettingPluginBubbleModel::RunPluginsOnPage() {
// Web contents can be NULL if the tab was closed while the plugins
// settings bubble is visible.
if (!web_contents())
return;

HostContentSettingsMap* map =
HostContentSettingsMapFactory::GetForProfile(profile_);
map->SetContentSettingDefaultScope(
web_contents()->GetURL(),
GURL(),
CONTENT_SETTINGS_TYPE_PLUGINS,
std::string(),
CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);

ChromeSubresourceFilterClient::FromWebContents(web_contents())
->OnReloadRequested();
}
23 changes: 23 additions & 0 deletions browser/ui/content_settings/brave_content_setting_bubble_model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* 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 "chrome/browser/ui/content_settings/content_setting_bubble_model.h"

class Profile;

class BraveContentSettingPluginBubbleModel : public ContentSettingSimpleBubbleModel {
public:
BraveContentSettingPluginBubbleModel(Delegate* delegate,
content::WebContents* web_contents,
Profile* profile);

private:
void OnLearnMoreClicked() override;
void OnCustomLinkClicked() override;

void RunPluginsOnPage();
Profile* profile_;

DISALLOW_COPY_AND_ASSIGN(BraveContentSettingPluginBubbleModel);
};
1 change: 1 addition & 0 deletions components/brave_shields/common/brave_shield_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const char kFingerprinting[] = "fingerprinting";
const char kBraveShields[] = "braveShields";
const char kReferrers[] = "referrers";
const char kCookies[] = "cookies";
const char kFlash[] = "adobe-flash-player";

} // brave_shields

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ BraveHostContentSettingsMap::BraveHostContentSettingsMap(
InitializeReferrerContentSetting();
InitializeCookieContentSetting();
InitializeBraveShieldsContentSetting();
InitializeFlashContentSetting();
}

BraveHostContentSettingsMap::~BraveHostContentSettingsMap() {
Expand Down Expand Up @@ -60,3 +61,14 @@ void BraveHostContentSettingsMap::InitializeBraveShieldsContentSetting() {
brave_shields::kBraveShields,
CONTENT_SETTING_ALLOW);
}

void BraveHostContentSettingsMap::InitializeFlashContentSetting() {
SetContentSettingCustomScope(
ContentSettingsPattern::Wildcard(),
ContentSettingsPattern::Wildcard(),
CONTENT_SETTINGS_TYPE_PLUGINS,
// One would think this should be brave_shields::kFlash; however, if you
// use it, it will always ask and click-to-play will not work.
std::string(),
CONTENT_SETTING_BLOCK);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BraveHostContentSettingsMap : public HostContentSettingsMap {
void InitializeReferrerContentSetting();
void InitializeCookieContentSetting();
void InitializeBraveShieldsContentSetting();
void InitializeFlashContentSetting();
~BraveHostContentSettingsMap() override;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
index 0e1bec53e5c64024528e949d8a7a51e3877f3056..e99590efc9a2c0850e4958a76bccda53a2a09a36 100644
--- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
+++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
@@ -15,6 +15,7 @@
#include "base/metrics/user_metrics.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "brave/browser/ui/content_settings/brave_content_setting_bubble_model.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/chrome_content_settings_utils.h"
@@ -1712,7 +1713,7 @@ ContentSettingBubbleModel*
profile, content_type);
}
if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
- return new ContentSettingPluginBubbleModel(delegate, web_contents, profile);
+ return new BraveContentSettingPluginBubbleModel(delegate, web_contents, profile);
}
if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
return new ContentSettingMixedScriptBubbleModel(delegate, web_contents,

0 comments on commit fdd2652

Please sign in to comment.