Skip to content

Commit b5264cb

Browse files
committed
Disable Flash by default and allow enabling with CTP
Fix brave/brave-browser#30
1 parent ef95bd2 commit b5264cb

7 files changed

+125
-0
lines changed

browser/ui/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ source_set("ui") {
66
"brave_browser_command_controller.h",
77
"brave_pages.cc",
88
"brave_pages.h",
9+
"content_settings/brave_content_setting_bubble_model.cc",
10+
"content_settings/brave_content_setting_bubble_model.h",
911
"toolbar/brave_app_menu_model.cc",
1012
"toolbar/brave_app_menu_model.h",
1113
"views/importer/brave_import_lock_dialog_view.cc",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
#include "brave/browser/ui/content_settings/brave_content_setting_bubble_model.h"
6+
7+
#include "brave/components/brave_shields/common/brave_shield_constants.h"
8+
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
9+
#include "chrome/browser/plugins/plugin_utils.h"
10+
#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h"
11+
#include "chrome/browser/ui/content_settings/content_setting_bubble_model_delegate.h"
12+
#include "chrome/grit/generated_resources.h"
13+
#include "components/content_settings/core/browser/host_content_settings_map.h"
14+
#include "ui/base/l10n/l10n_util.h"
15+
16+
BraveContentSettingPluginBubbleModel::BraveContentSettingPluginBubbleModel(
17+
Delegate* delegate, content::WebContents* web_contents, Profile* profile)
18+
: ContentSettingSimpleBubbleModel(delegate,
19+
web_contents,
20+
profile,
21+
CONTENT_SETTINGS_TYPE_PLUGINS), profile_(profile) {
22+
content_settings::SettingInfo info;
23+
HostContentSettingsMap* map =
24+
HostContentSettingsMapFactory::GetForProfile(profile);
25+
GURL url = web_contents->GetURL();
26+
std::unique_ptr<base::Value> value =
27+
map->GetWebsiteSetting(url, url, content_type(), std::string(), &info);
28+
// If the setting is not managed by the user, hide the "Manage" button.
29+
if (info.source != content_settings::SETTING_SOURCE_USER)
30+
set_manage_text_style(ContentSettingBubbleModel::ManageTextStyle::kNone);
31+
set_custom_link(l10n_util::GetStringUTF16(IDS_BLOCKED_PLUGINS_LOAD_ALL));
32+
set_custom_link_enabled(
33+
web_contents &&
34+
TabSpecificContentSettings::FromWebContents(web_contents)
35+
->load_plugins_link_enabled());
36+
set_show_learn_more(true);
37+
}
38+
39+
void BraveContentSettingPluginBubbleModel::OnLearnMoreClicked() {
40+
if (delegate())
41+
delegate()->ShowLearnMorePage(CONTENT_SETTINGS_TYPE_PLUGINS);
42+
}
43+
44+
void BraveContentSettingPluginBubbleModel::OnCustomLinkClicked() {
45+
RunPluginsOnPage();
46+
}
47+
48+
void BraveContentSettingPluginBubbleModel::RunPluginsOnPage() {
49+
// Web contents can be NULL if the tab was closed while the plugins
50+
// settings bubble is visible.
51+
if (!web_contents())
52+
return;
53+
54+
HostContentSettingsMap* map =
55+
HostContentSettingsMapFactory::GetForProfile(profile_);
56+
map->SetContentSettingDefaultScope(
57+
web_contents()->GetURL(),
58+
GURL(),
59+
CONTENT_SETTINGS_TYPE_PLUGINS,
60+
std::string(),
61+
CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
62+
63+
ChromeSubresourceFilterClient::FromWebContents(web_contents())
64+
->OnReloadRequested();
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
6+
7+
class Profile;
8+
9+
class BraveContentSettingPluginBubbleModel : public ContentSettingSimpleBubbleModel {
10+
public:
11+
BraveContentSettingPluginBubbleModel(Delegate* delegate,
12+
content::WebContents* web_contents,
13+
Profile* profile);
14+
15+
private:
16+
void OnLearnMoreClicked() override;
17+
void OnCustomLinkClicked() override;
18+
19+
void RunPluginsOnPage();
20+
Profile* profile_;
21+
22+
DISALLOW_COPY_AND_ASSIGN(BraveContentSettingPluginBubbleModel);
23+
};

components/brave_shields/common/brave_shield_constants.h

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const char kFingerprinting[] = "fingerprinting";
1616
const char kBraveShields[] = "braveShields";
1717
const char kReferrers[] = "referrers";
1818
const char kCookies[] = "cookies";
19+
const char kFlash[] = "adobe-flash-player";
1920

2021
} // brave_shields
2122

components/content_settings/core/browser/brave_host_content_settings_map.cc

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ BraveHostContentSettingsMap::BraveHostContentSettingsMap(
1818
InitializeReferrerContentSetting();
1919
InitializeCookieContentSetting();
2020
InitializeBraveShieldsContentSetting();
21+
InitializeFlashContentSetting();
2122
}
2223

2324
BraveHostContentSettingsMap::~BraveHostContentSettingsMap() {
@@ -60,3 +61,14 @@ void BraveHostContentSettingsMap::InitializeBraveShieldsContentSetting() {
6061
brave_shields::kBraveShields,
6162
CONTENT_SETTING_ALLOW);
6263
}
64+
65+
void BraveHostContentSettingsMap::InitializeFlashContentSetting() {
66+
SetContentSettingCustomScope(
67+
ContentSettingsPattern::Wildcard(),
68+
ContentSettingsPattern::Wildcard(),
69+
CONTENT_SETTINGS_TYPE_PLUGINS,
70+
// One would think this should be brave_shields::kFlash; however, if you
71+
// use it, it will always ask and click-to-play will not work.
72+
std::string(),
73+
CONTENT_SETTING_BLOCK);
74+
}

components/content_settings/core/browser/brave_host_content_settings_map.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class BraveHostContentSettingsMap : public HostContentSettingsMap {
1818
void InitializeReferrerContentSetting();
1919
void InitializeCookieContentSetting();
2020
void InitializeBraveShieldsContentSetting();
21+
void InitializeFlashContentSetting();
2122
~BraveHostContentSettingsMap() override;
2223
};
2324

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
2+
index 0e1bec53e5c64024528e949d8a7a51e3877f3056..e99590efc9a2c0850e4958a76bccda53a2a09a36 100644
3+
--- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
4+
+++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc
5+
@@ -15,6 +15,7 @@
6+
#include "base/metrics/user_metrics.h"
7+
#include "base/stl_util.h"
8+
#include "base/strings/utf_string_conversions.h"
9+
+#include "brave/browser/ui/content_settings/brave_content_setting_bubble_model.h"
10+
#include "chrome/browser/browser_process.h"
11+
#include "chrome/browser/chrome_notification_types.h"
12+
#include "chrome/browser/content_settings/chrome_content_settings_utils.h"
13+
@@ -1712,7 +1713,7 @@ ContentSettingBubbleModel*
14+
profile, content_type);
15+
}
16+
if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
17+
- return new ContentSettingPluginBubbleModel(delegate, web_contents, profile);
18+
+ return new BraveContentSettingPluginBubbleModel(delegate, web_contents, profile);
19+
}
20+
if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
21+
return new ContentSettingMixedScriptBubbleModel(delegate, web_contents,

0 commit comments

Comments
 (0)