diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index 778585bee29f..9133e5230474 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -113,6 +113,28 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U Imported From Brave + + + Autoplay media + + + Autoplay + + + Ask when a site wants to autoplay media + + + Ask when a site wants to autoplay media (recommended) + + + Autoplay was blocked on this page + + + Always allow autoplay on $1mail.google.com + + + Continue blocking autoplay + diff --git a/browser/BUILD.gn b/browser/BUILD.gn index b375708580e0..6f603d262249 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -100,9 +100,11 @@ source_set("browser") { ] deps = [ + "autoplay", "//brave/components/brave_shields/browser:brave_shields", "extensions", "net", + "permissions", ] if (is_mac) { diff --git a/browser/autoplay/BUILD.gn b/browser/autoplay/BUILD.gn new file mode 100644 index 000000000000..33ff170171e6 --- /dev/null +++ b/browser/autoplay/BUILD.gn @@ -0,0 +1,12 @@ +import("//build/config/features.gni") + +source_set("autoplay") { + sources = [ + "autoplay_permission_context.cc", + "autoplay_permission_context.h", + ] + + deps = [ + "//chrome/browser", + ] +} diff --git a/browser/autoplay/autoplay_permission_context.cc b/browser/autoplay/autoplay_permission_context.cc new file mode 100644 index 000000000000..e150fb418218 --- /dev/null +++ b/browser/autoplay/autoplay_permission_context.cc @@ -0,0 +1,58 @@ +/* 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/autoplay/autoplay_permission_context.h" + +#include "chrome/browser/content_settings/tab_specific_content_settings.h" +#include "chrome/browser/permissions/permission_request_id.h" +#include "chrome/common/chrome_features.h" +#include "components/content_settings/core/common/content_settings_types.h" +#include "third_party/blink/public/mojom/feature_policy/feature_policy.mojom.h" + +AutoplayPermissionContext::AutoplayPermissionContext(Profile* profile) + : PermissionContextBase( + profile, + CONTENT_SETTINGS_TYPE_AUTOPLAY, + blink::mojom::FeaturePolicyFeature::kAutoplay) {} + +AutoplayPermissionContext::~AutoplayPermissionContext() = default; + +void AutoplayPermissionContext::UpdateTabContext( + const PermissionRequestID& id, + const GURL& requesting_frame, + bool allowed) { + TabSpecificContentSettings* content_settings = + TabSpecificContentSettings::GetForFrame(id.render_process_id(), + id.render_frame_id()); + if (!content_settings) + return; + + if (!allowed) { + content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_AUTOPLAY); + } +} + +void AutoplayPermissionContext::NotifyPermissionSet( + const PermissionRequestID& id, + const GURL& requesting_origin, + const GURL& embedding_origin, + const BrowserPermissionCallback& callback, + bool persist, + ContentSetting content_setting) { + PermissionContextBase::NotifyPermissionSet(id, requesting_origin, + embedding_origin, callback, + persist, content_setting); + // Ask -> Allow + if (persist && content_setting == CONTENT_SETTING_ALLOW) { + content::WebContents* web_contents = + content::WebContents::FromRenderFrameHost( + content::RenderFrameHost::FromID(id.render_process_id(), + id.render_frame_id())); + web_contents->GetController().Reload(content::ReloadType::NORMAL, false); + } +} + +bool AutoplayPermissionContext::IsRestrictedToSecureOrigins() const { + return false; +} diff --git a/browser/autoplay/autoplay_permission_context.h b/browser/autoplay/autoplay_permission_context.h new file mode 100644 index 000000000000..333a9552d9e2 --- /dev/null +++ b/browser/autoplay/autoplay_permission_context.h @@ -0,0 +1,32 @@ +/* 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/. */ + +#ifndef BRAVE_BROWSER_AUTOPLAY_AUTOPLAY_PERMISSION_CONTEXT_H_ +#define BRAVE_BROWSER_AUTOPLAY_AUTOPLAY_PERMISSION_CONTEXT_H_ + +#include "base/macros.h" +#include "chrome/browser/permissions/permission_context_base.h" + +class AutoplayPermissionContext : public PermissionContextBase { + public: + explicit AutoplayPermissionContext(Profile* profile); + ~AutoplayPermissionContext() override; + + private: + // PermissionContextBase: + void UpdateTabContext(const PermissionRequestID& id, + const GURL& requesting_frame, + bool allowed) override; + void NotifyPermissionSet(const PermissionRequestID& id, + const GURL& requesting_origin, + const GURL& embedding_origin, + const BrowserPermissionCallback& callback, + bool persist, + ContentSetting content_setting) override; + bool IsRestrictedToSecureOrigins() const override; + + DISALLOW_COPY_AND_ASSIGN(AutoplayPermissionContext); +}; + +#endif // BRAVE_BROWSER_AUTOPLAY_AUTOPLAY_PERMISSION_CONTEXT_H_ diff --git a/browser/autoplay/autoplay_permission_context_browsertest.cc b/browser/autoplay/autoplay_permission_context_browsertest.cc new file mode 100644 index 000000000000..d0930190794f --- /dev/null +++ b/browser/autoplay/autoplay_permission_context_browsertest.cc @@ -0,0 +1,457 @@ +/* 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 "base/path_service.h" +#include "brave/browser/brave_content_browser_client.h" +#include "brave/common/brave_paths.h" +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" +#include "chrome/common/chrome_content_client.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/render_frame_host.h" +#include "content/public/test/browser_test_utils.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" +#include "net/dns/mock_host_resolver.h" + +const char kVideoPlaying[] = "Video playing"; +const char kVideoPlayingDetect[] = + "window.domAutomationController.send(document.getElementById('status')." + "textContent);"; + +class AutoplayPermissionContextBrowserTest : public InProcessBrowserTest { + public: + void SetUpOnMainThread() override { + InProcessBrowserTest::SetUpOnMainThread(); + + content_client_.reset(new ChromeContentClient); + content::SetContentClient(content_client_.get()); + browser_content_client_.reset(new BraveContentBrowserClient()); + content::SetBrowserClientForTesting(browser_content_client_.get()); + + host_resolver()->AddRule("*", "127.0.0.1"); + content::SetupCrossSiteRedirector(embedded_test_server()); + + brave::RegisterPathProvider(); + base::FilePath test_data_dir; + base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); + test_data_dir = test_data_dir.AppendASCII("autoplay"); + embedded_test_server()->ServeFilesFromDirectory(test_data_dir); + + ASSERT_TRUE(embedded_test_server()->Start()); + + autoplay_method_url_ = + embedded_test_server()->GetURL("a.com", "/autoplay_by_method.html"); + autoplay_attr_url_ = + embedded_test_server()->GetURL("a.com", "/autoplay_by_attr.html"); + autoplay_method_muted_url_ = + embedded_test_server()->GetURL("a.com", "/autoplay_by_method_muted.html"); + autoplay_attr_muted_url_ = + embedded_test_server()->GetURL("a.com", "/autoplay_by_attr_muted.html"); + file_autoplay_method_url_ = + GURL("file://" + test_data_dir.AsUTF8Unsafe() + + "/autoplay_by_method.html"); + file_autoplay_attr_url_ = + GURL("file://" + test_data_dir.AsUTF8Unsafe() + + "/autoplay_by_attr.html"); + + GURL pattern_url = embedded_test_server()->GetURL("a.com", "/index.html"); + top_level_page_pattern_ = + ContentSettingsPattern::FromString(pattern_url.spec()); + } + + void TearDown() override { + browser_content_client_.reset(); + content_client_.reset(); + } + + const GURL& autoplay_method_url() { return autoplay_method_url_; } + const GURL& autoplay_attr_url() { return autoplay_attr_url_; } + const GURL& autoplay_method_muted_url() { return autoplay_method_muted_url_; } + const GURL& autoplay_attr_muted_url() { return autoplay_attr_muted_url_; } + const GURL& file_autoplay_method_url() { return file_autoplay_method_url_; } + const GURL& file_autoplay_attr_url() { return file_autoplay_attr_url_; } + + const ContentSettingsPattern& top_level_page_pattern() { + return top_level_page_pattern_; + } + + HostContentSettingsMap * content_settings() { + return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); + } + + void AllowAutoplay() { + content_settings()->SetContentSettingCustomScope( + top_level_page_pattern_, + ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, + std::string(), + CONTENT_SETTING_ALLOW); + } + + void BlockAutoplay() { + content_settings()->SetContentSettingCustomScope( + top_level_page_pattern_, + ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, + std::string(), + CONTENT_SETTING_BLOCK); + } + + void ResetAutoplayToDefault() { + content_settings()->SetContentSettingCustomScope( + top_level_page_pattern_, + ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, + std::string(), + CONTENT_SETTING_DEFAULT); + } + + content::WebContents* contents() { + return browser()->tab_strip_model()->GetActiveWebContents(); + } + + bool NavigateToURLUntilLoadStop(const GURL& url) { + ui_test_utils::NavigateToURL(browser(), url); + return WaitForLoadStop(contents()); + } + + void WaitForPlaying() { + std::string msg_from_renderer; + ASSERT_TRUE(ExecuteScriptAndExtractString(contents(), "notifyWhenPlaying();", + &msg_from_renderer)); + ASSERT_EQ("PLAYING", msg_from_renderer); + } + + private: + GURL autoplay_method_url_; + GURL autoplay_attr_url_; + GURL autoplay_method_muted_url_; + GURL autoplay_attr_muted_url_; + GURL file_autoplay_method_url_; + GURL file_autoplay_attr_url_; + ContentSettingsPattern top_level_page_pattern_; + std::unique_ptr content_client_; + std::unique_ptr browser_content_client_; +}; + +// Autoplay is ask by default +IN_PROC_BROWSER_TEST_F(AutoplayPermissionContextBrowserTest, AskByDefault) { + std::string result; + PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( + contents()); + + NavigateToURLUntilLoadStop(autoplay_method_url()); + EXPECT_TRUE(manager->IsBubbleVisible()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); + + result.clear(); + + NavigateToURLUntilLoadStop(autoplay_attr_url()); + EXPECT_TRUE(manager->IsBubbleVisible()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); + + // Muted version of above + result.clear(); + + NavigateToURLUntilLoadStop(autoplay_method_muted_url()); + EXPECT_TRUE(manager->IsBubbleVisible()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); + + result.clear(); + + NavigateToURLUntilLoadStop(autoplay_attr_muted_url()); + EXPECT_TRUE(manager->IsBubbleVisible()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); +} + +// Click allow from promt +IN_PROC_BROWSER_TEST_F(AutoplayPermissionContextBrowserTest, ClickAllow) { + std::string result; + PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( + contents()); + auto popup_prompt_factory = + std::make_unique(manager); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + popup_prompt_factory->set_response_type(PermissionRequestManager::ACCEPT_ALL); + + NavigateToURLUntilLoadStop(autoplay_method_url()); + EXPECT_TRUE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(1, popup_prompt_factory->TotalRequestCount()); + WaitForPlaying(); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); + + ResetAutoplayToDefault(); + popup_prompt_factory->ResetCounts(); + result.clear(); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_attr_url()); + EXPECT_TRUE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(1, popup_prompt_factory->TotalRequestCount()); + WaitForPlaying(); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); + + // Muted version of above + ResetAutoplayToDefault(); + popup_prompt_factory->ResetCounts(); + result.clear(); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_method_muted_url()); + EXPECT_TRUE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(1, popup_prompt_factory->TotalRequestCount()); + WaitForPlaying(); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); + + ResetAutoplayToDefault(); + popup_prompt_factory->ResetCounts(); + result.clear(); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_attr_muted_url()); + EXPECT_TRUE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(1, popup_prompt_factory->TotalRequestCount()); + WaitForPlaying(); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); +} + +// Click block from promt +IN_PROC_BROWSER_TEST_F(AutoplayPermissionContextBrowserTest, ClickBlock) { + std::string result; + PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( + contents()); + auto popup_prompt_factory = + std::make_unique(manager); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + popup_prompt_factory->set_response_type(PermissionRequestManager::DENY_ALL); + + NavigateToURLUntilLoadStop(autoplay_method_url()); + EXPECT_TRUE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(1, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); + + ResetAutoplayToDefault(); + popup_prompt_factory->ResetCounts(); + result.clear(); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_attr_url()); + EXPECT_TRUE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(1, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); + + // Muted version of above + ResetAutoplayToDefault(); + popup_prompt_factory->ResetCounts(); + result.clear(); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_method_muted_url()); + EXPECT_TRUE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(1, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); + + ResetAutoplayToDefault(); + popup_prompt_factory->ResetCounts(); + result.clear(); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_attr_muted_url()); + EXPECT_TRUE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(1, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); +} + +// Allow autoplay +IN_PROC_BROWSER_TEST_F(AutoplayPermissionContextBrowserTest, AllowAutoplay) { + std::string result; + AllowAutoplay(); + PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( + contents()); + auto popup_prompt_factory = + std::make_unique(manager); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_method_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + WaitForPlaying(); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); + + result.clear(); + + NavigateToURLUntilLoadStop(autoplay_attr_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + WaitForPlaying(); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); + + // Muted version of above + result.clear(); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_method_muted_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + WaitForPlaying(); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); + + result.clear(); + + NavigateToURLUntilLoadStop(autoplay_attr_muted_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + WaitForPlaying(); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); +} + +// Block autoplay +IN_PROC_BROWSER_TEST_F(AutoplayPermissionContextBrowserTest, BlockAutoplay) { + std::string result; + BlockAutoplay(); + PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( + contents()); + auto popup_prompt_factory = + std::make_unique(manager); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_method_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); + + result.clear(); + + NavigateToURLUntilLoadStop(autoplay_attr_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); + + // Muted version of above + result.clear(); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(autoplay_method_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); + + result.clear(); + + NavigateToURLUntilLoadStop(autoplay_attr_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_NE(result, kVideoPlaying); +} + +// Default allow autoplay on file urls +IN_PROC_BROWSER_TEST_F(AutoplayPermissionContextBrowserTest, FileAutoplay) { + std::string result; + PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( + contents()); + auto popup_prompt_factory = + std::make_unique(manager); + + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + + NavigateToURLUntilLoadStop(file_autoplay_method_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); + + result.clear(); + + NavigateToURLUntilLoadStop(file_autoplay_attr_url()); + EXPECT_FALSE(popup_prompt_factory->is_visible()); + EXPECT_FALSE(popup_prompt_factory->RequestTypeSeen( + PermissionRequestType::PERMISSION_AUTOPLAY)); + EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); + EXPECT_TRUE(ExecuteScriptAndExtractString(contents(), + kVideoPlayingDetect, &result)); + EXPECT_EQ(result, kVideoPlaying); +} diff --git a/browser/autoplay/autoplay_permission_context_unittest.cc b/browser/autoplay/autoplay_permission_context_unittest.cc new file mode 100644 index 000000000000..3bba7276b4cc --- /dev/null +++ b/browser/autoplay/autoplay_permission_context_unittest.cc @@ -0,0 +1,142 @@ +/* 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/autoplay/autoplay_permission_context.h" + +#include + +#include "base/bind.h" +#include "base/macros.h" +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" +#include "chrome/browser/permissions/permission_request_id.h" +#include "chrome/browser/permissions/permission_request_manager.h" +#include "chrome/test/base/chrome_render_view_host_test_harness.h" +#include "chrome/test/base/testing_profile.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" +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/web_contents.h" +#include "content/public/test/mock_render_process_host.h" +#include "content/public/test/web_contents_tester.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class AutoplayPermissionContextTest : public AutoplayPermissionContext { + public: + explicit AutoplayPermissionContextTest(Profile* profile) + : AutoplayPermissionContext(profile), + no_tab_reloaded_(false) {} + + ~AutoplayPermissionContextTest() override {} + + bool no_tab_reloaded() { return no_tab_reloaded_; } + + protected: + void NotifyPermissionSet(const PermissionRequestID& id, + const GURL& requesting_origin, + const GURL& embedder_origin, + const BrowserPermissionCallback& callback, + bool persist, + ContentSetting content_setting) override { + if (!(persist && content_setting == CONTENT_SETTING_ALLOW)) + no_tab_reloaded_ = true; + } + + private: + bool no_tab_reloaded_; +}; + +} // anonymous namespace + +class AutoplayPermissionContextTests : public ChromeRenderViewHostTestHarness { + protected: + AutoplayPermissionContextTests() = default; + + private: + // ChromeRenderViewHostTestHarness: + void SetUp() override { + ChromeRenderViewHostTestHarness::SetUp(); + PermissionRequestManager::CreateForWebContents(web_contents()); + } + + void TearDown() override { + ChromeRenderViewHostTestHarness::TearDown(); + } + + DISALLOW_COPY_AND_ASSIGN(AutoplayPermissionContextTests); +}; + +// Autoplay permission status should still be default(ask) even for +// insecure origin +TEST_F(AutoplayPermissionContextTests, TestInsecureQueryingUrl) { + AutoplayPermissionContextTest permission_context(profile()); + GURL insecure_url("http://www.example.com"); + GURL secure_url("https://www.example.com"); + + // Check that there is no saved content settings. + EXPECT_EQ(CONTENT_SETTING_ASK, + HostContentSettingsMapFactory::GetForProfile(profile()) + ->GetContentSetting( + insecure_url.GetOrigin(), insecure_url.GetOrigin(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); + EXPECT_EQ( + CONTENT_SETTING_ASK, + HostContentSettingsMapFactory::GetForProfile(profile()) + ->GetContentSetting(secure_url.GetOrigin(), insecure_url.GetOrigin(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); + EXPECT_EQ( + CONTENT_SETTING_ASK, + HostContentSettingsMapFactory::GetForProfile(profile()) + ->GetContentSetting(insecure_url.GetOrigin(), secure_url.GetOrigin(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); + + EXPECT_EQ(CONTENT_SETTING_ASK, + permission_context + .GetPermissionStatus(nullptr /* render_frame_host */, + insecure_url, insecure_url) + .content_setting); + + EXPECT_EQ(CONTENT_SETTING_ASK, + permission_context + .GetPermissionStatus(nullptr /* render_frame_host */, + insecure_url, secure_url) + .content_setting); +} + +// There is no way to generate a request that is automatically accepted in +// unittest by RequestPermission, so we test reverse cases here +TEST_F(AutoplayPermissionContextTests, TestNonAutoRefresh) { + AutoplayPermissionContextTest permission_context(profile()); + GURL url("https://www.example.com"); + content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); + + const PermissionRequestID id( + web_contents()->GetMainFrame()->GetProcess()->GetID(), + web_contents()->GetMainFrame()->GetRoutingID(), -1); + + // non persist allow + HostContentSettingsMapFactory::GetForProfile(profile())-> + SetContentSettingDefaultScope(url.GetOrigin(), url.GetOrigin(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string(), + CONTENT_SETTING_ALLOW); + permission_context.RequestPermission( + web_contents(), id, url, true, base::DoNothing()); + EXPECT_TRUE(permission_context.no_tab_reloaded()); + + // non persist block + HostContentSettingsMapFactory::GetForProfile(profile())-> + SetContentSettingDefaultScope(url.GetOrigin(), url.GetOrigin(), + CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string(), + CONTENT_SETTING_BLOCK); + permission_context.RequestPermission( + web_contents(), id, url, true, base::DoNothing()); + EXPECT_TRUE(permission_context.no_tab_reloaded()); + + // no ask case because CONTENT_SETTING_ASK will cause + // DCHECK(is_finished_) failed in `PermissionRequestImpl`. Every + // *permission_context_unittest.cc test CONTENT_SETTING_BLOCK case now if you + // change them to test CONTENT_SETTING_ASK, you will see the same crash stack. +} diff --git a/browser/permissions/BUILD.gn b/browser/permissions/BUILD.gn new file mode 100644 index 000000000000..36d283833cdd --- /dev/null +++ b/browser/permissions/BUILD.gn @@ -0,0 +1,14 @@ +import("//build/config/features.gni") + +source_set("permissions") { + sources = [ + "brave_permission_manager.cc", + "brave_permission_manager.h", + "brave_permission_manager_factory.cc", + "brave_permission_manager_factory.h", + ] + + deps = [ + "//chrome/browser", + ] +} diff --git a/browser/permissions/brave_permission_manager.cc b/browser/permissions/brave_permission_manager.cc new file mode 100644 index 000000000000..e37506336c95 --- /dev/null +++ b/browser/permissions/brave_permission_manager.cc @@ -0,0 +1,13 @@ +/* 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/permissions/brave_permission_manager.h" + +#include "brave/browser/autoplay/autoplay_permission_context.h" + +BravePermissionManager::BravePermissionManager(Profile* profile) + : PermissionManager(profile) { + permission_contexts_[CONTENT_SETTINGS_TYPE_AUTOPLAY] = + std::make_unique(profile); +} diff --git a/browser/permissions/brave_permission_manager.h b/browser/permissions/brave_permission_manager.h new file mode 100644 index 000000000000..f6990690085f --- /dev/null +++ b/browser/permissions/brave_permission_manager.h @@ -0,0 +1,18 @@ +/* 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/. */ + +#ifndef BRAVE_BROWSER_PERMISSION_BRAVE_PERMISSION_MANAGER_H_ +#define BRAVE_BROWSER_PERMISSION_BRAVE_PERMISSION_MANAGER_H_ + +#include "chrome/browser/permissions/permission_manager.h" + +class BravePermissionManager : public PermissionManager { + public: + explicit BravePermissionManager(Profile* profile); + + private: + DISALLOW_COPY_AND_ASSIGN(BravePermissionManager); +}; + +#endif // BRAVE_BROWSER_PERMISSION_BRAVE_PERMISSION_MANAGER_H_ diff --git a/browser/permissions/brave_permission_manager_factory.cc b/browser/permissions/brave_permission_manager_factory.cc new file mode 100644 index 000000000000..f84e491fcab9 --- /dev/null +++ b/browser/permissions/brave_permission_manager_factory.cc @@ -0,0 +1,34 @@ +/* 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/permissions/brave_permission_manager_factory.h" + +#include "brave/browser/permissions/brave_permission_manager.h" +#include "chrome/browser/permissions/permission_manager.h" +#include "chrome/browser/permissions/permission_manager.h" +#include "chrome/browser/profiles/profile.h" + +// static +PermissionManager* +BravePermissionManagerFactory::GetForProfile(Profile* profile) { + return static_cast( + GetInstance()->GetServiceForBrowserContext(profile, true)); +} + +// static +BravePermissionManagerFactory* BravePermissionManagerFactory::GetInstance() { + return base::Singleton::get(); +} + +BravePermissionManagerFactory::BravePermissionManagerFactory() + : PermissionManagerFactory() { +} + +BravePermissionManagerFactory::~BravePermissionManagerFactory() { +} + +KeyedService* BravePermissionManagerFactory::BuildServiceInstanceFor( + content::BrowserContext* context) const { + return new BravePermissionManager(Profile::FromBrowserContext(context)); +} diff --git a/browser/permissions/brave_permission_manager_factory.h b/browser/permissions/brave_permission_manager_factory.h new file mode 100644 index 000000000000..53e7092be569 --- /dev/null +++ b/browser/permissions/brave_permission_manager_factory.h @@ -0,0 +1,28 @@ +/* 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/. */ + +#ifndef BRAVE_BROWSER_PERMISSION_BRAVE_PERMISSION_MANAGER_FACTORR_H_ +#define BRAVE_BROWSER_PERMISSION_BRAVE_PERMISSION_MANAGER_FACTORR_H_ + +#include "chrome/browser/permissions/permission_manager_factory.h" + +class BravePermissionManagerFactory : public PermissionManagerFactory { + public: + static PermissionManager* GetForProfile(Profile* profile); + static BravePermissionManagerFactory* GetInstance(); + + private: + friend struct base::DefaultSingletonTraits; + + BravePermissionManagerFactory(); + ~BravePermissionManagerFactory() override; + + // BrowserContextKeyedBaseFactory methods: + KeyedService* BuildServiceInstanceFor( + content::BrowserContext* profile) const override; + + DISALLOW_COPY_AND_ASSIGN(BravePermissionManagerFactory); +}; + +#endif // BRAVE_BROWSER_PERMISSION_BRAVE_PERMISSION_MANAGER_FACTORR_H_ diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index cc2138ef5c4c..57e598f6a4e7 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -9,6 +9,10 @@ source_set("ui") { "brave_browser_content_setting_bubble_model_delegate.h", "brave_pages.cc", "brave_pages.h", + "content_settings/brave_autoplay_blocked_image_model.cc", + "content_settings/brave_autoplay_blocked_image_model.h", + "content_settings/brave_autoplay_content_setting_bubble_model.cc", + "content_settings/brave_autoplay_content_setting_bubble_model.h", "content_settings/brave_content_setting_bubble_model.cc", "content_settings/brave_content_setting_bubble_model.h", "content_settings/brave_content_setting_image_models.cc", diff --git a/browser/ui/content_settings/brave_autoplay_blocked_image_model.cc b/browser/ui/content_settings/brave_autoplay_blocked_image_model.cc new file mode 100644 index 000000000000..5671f51d4aa4 --- /dev/null +++ b/browser/ui/content_settings/brave_autoplay_blocked_image_model.cc @@ -0,0 +1,48 @@ +/* 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_autoplay_blocked_image_model.h" + +#include "brave/browser/ui/content_settings/brave_autoplay_content_setting_bubble_model.h" +#include "brave/grit/brave_generated_resources.h" +#include "chrome/app/vector_icons/vector_icons.h" +#include "content/public/browser/web_contents.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/gfx/paint_vector_icon.h" + +using content::WebContents; + +BraveAutoplayBlockedImageModel::BraveAutoplayBlockedImageModel() + : ContentSettingSimpleImageModel(ImageType::PLUGINS, + CONTENT_SETTINGS_TYPE_AUTOPLAY) {} + +void BraveAutoplayBlockedImageModel::UpdateFromWebContents( + WebContents* web_contents) { + set_visible(false); + if (!web_contents) + return; + + TabSpecificContentSettings* content_settings = + TabSpecificContentSettings::FromWebContents(web_contents); + if (!content_settings) + return; + if (!content_settings->IsContentBlocked(content_type())) + return; + + set_visible(true); + const gfx::VectorIcon* badge_id = &kBlockedBadgeIcon; + const gfx::VectorIcon* icon = &kExtensionIcon; + set_icon(*icon, *badge_id); + set_explanatory_string_id(IDS_BLOCKED_AUTOPLAY_TITLE); + set_tooltip(l10n_util::GetStringUTF16(IDS_BLOCKED_AUTOPLAY_TITLE)); +} + +ContentSettingBubbleModel* +BraveAutoplayBlockedImageModel::CreateBubbleModelImpl( + ContentSettingBubbleModel::Delegate* delegate, + WebContents* web_contents, + Profile* profile) { + return new BraveAutoplayContentSettingBubbleModel(delegate, + web_contents, profile); +} diff --git a/browser/ui/content_settings/brave_autoplay_blocked_image_model.h b/browser/ui/content_settings/brave_autoplay_blocked_image_model.h new file mode 100644 index 000000000000..91a54396d6cb --- /dev/null +++ b/browser/ui/content_settings/brave_autoplay_blocked_image_model.h @@ -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/. */ + +#ifndef BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_AUTOPLAY_BLOCKED_IMAGE_MODEL_H_ +#define BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_AUTOPLAY_BLOCKED_IMAGE_MODEL_H_ + +#include "chrome/browser/ui/content_settings/content_setting_image_model.h" + +class BraveAutoplayBlockedImageModel : public ContentSettingSimpleImageModel { + public: + BraveAutoplayBlockedImageModel(); + void UpdateFromWebContents(content::WebContents* web_contents) override; + ContentSettingBubbleModel* CreateBubbleModelImpl( + ContentSettingBubbleModel::Delegate* delegate, + content::WebContents* web_contents, + Profile* profile) override; + + private: + DISALLOW_COPY_AND_ASSIGN(BraveAutoplayBlockedImageModel); +}; + +#endif // BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_AUTOPLAY_BLOCKED_IMAGE_MODEL_H_ diff --git a/browser/ui/content_settings/brave_autoplay_blocked_image_model_browsertest.cc b/browser/ui/content_settings/brave_autoplay_blocked_image_model_browsertest.cc new file mode 100644 index 000000000000..3474b59af7dc --- /dev/null +++ b/browser/ui/content_settings/brave_autoplay_blocked_image_model_browsertest.cc @@ -0,0 +1,38 @@ +/* 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_autoplay_blocked_image_model.h" + +#include "chrome/browser/browser_process.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/test/base/in_process_browser_test.h" + +using content::WebContents; +using ImageType = ContentSettingImageModel::ImageType; + +typedef InProcessBrowserTest BraveAutoplayBlockedImageModelTest; + +IN_PROC_BROWSER_TEST_F(BraveAutoplayBlockedImageModelTest, CreateBubbleModel) { + WebContents* web_contents = + browser()->tab_strip_model()->GetActiveWebContents(); + TabSpecificContentSettings* content_settings = + TabSpecificContentSettings::FromWebContents(web_contents); + content_settings->BlockAllContentForTesting(); + + Profile* profile = browser()->profile(); + auto model = std::make_unique(); + std::unique_ptr bubble( + model->CreateBubbleModel(nullptr, web_contents, profile)); + + ContentSettingSimpleBubbleModel* simple_bubble = + bubble->AsSimpleBubbleModel(); + ASSERT_TRUE(simple_bubble); + EXPECT_EQ(static_cast(model.get()) + ->content_type(), + simple_bubble->content_type()); + EXPECT_EQ(ImageType::PLUGINS, model->image_type()); + EXPECT_EQ(CONTENT_SETTINGS_TYPE_AUTOPLAY, model->content_type()); +} diff --git a/browser/ui/content_settings/brave_autoplay_content_setting_bubble_model.cc b/browser/ui/content_settings/brave_autoplay_content_setting_bubble_model.cc new file mode 100644 index 000000000000..2364f0ca0c1b --- /dev/null +++ b/browser/ui/content_settings/brave_autoplay_content_setting_bubble_model.cc @@ -0,0 +1,113 @@ +/* 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_autoplay_content_setting_bubble_model.h" + +#include "base/strings/utf_string_conversions.h" +#include "brave/browser/brave_browser_process_impl.h" +#include "brave/browser/ui/brave_browser_content_setting_bubble_model_delegate.h" +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" +#include "chrome/browser/profiles/profile_manager.h" +#include "brave/grit/brave_generated_resources.h" +#include "chrome/grit/generated_resources.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_utils.h" +#include "components/url_formatter/elide_url.h" +#include "ui/base/l10n/l10n_util.h" + +using content_settings::SettingInfo; +using content_settings::SettingSource; +using content_settings::SETTING_SOURCE_USER; +using content_settings::SETTING_SOURCE_NONE; + +BraveAutoplayContentSettingBubbleModel::BraveAutoplayContentSettingBubbleModel( + Delegate* delegate, + WebContents* web_contents, + Profile* profile) + : ContentSettingSimpleBubbleModel(delegate, + web_contents, + profile, + CONTENT_SETTINGS_TYPE_AUTOPLAY), + block_setting_(CONTENT_SETTING_BLOCK) { + SetTitle(); + SetRadioGroup(); +} + +BraveAutoplayContentSettingBubbleModel::~BraveAutoplayContentSettingBubbleModel() {} + +void BraveAutoplayContentSettingBubbleModel::CommitChanges() { + if (settings_changed()) { + ContentSetting setting = selected_item() == kAllowButtonIndex + ? CONTENT_SETTING_ALLOW + : block_setting_; + SetNarrowestContentSetting(setting); + } +} + +bool BraveAutoplayContentSettingBubbleModel::settings_changed() const { + return selected_item() != bubble_content().radio_group.default_item; +} + +void BraveAutoplayContentSettingBubbleModel::SetTitle() { + set_title(l10n_util::GetStringUTF16(IDS_BLOCKED_AUTOPLAY_TITLE)); +} + +void BraveAutoplayContentSettingBubbleModel::SetRadioGroup() { + GURL url = web_contents()->GetURL(); + base::string16 display_host = url_formatter::FormatUrlForSecurityDisplay(url); + if (display_host.empty()) + display_host = base::ASCIIToUTF16(url.spec()); + + TabSpecificContentSettings* content_settings = + TabSpecificContentSettings::FromWebContents(web_contents()); + bool allowed = !content_settings->IsContentBlocked(content_type()); + DCHECK(!allowed || content_settings->IsContentAllowed(content_type())); + + RadioGroup radio_group; + radio_group.url = url; + base::string16 radio_allow_label = + l10n_util::GetStringFUTF16(IDS_BLOCKED_AUTOPLAY_UNBLOCK, display_host); + base::string16 radio_block_label = + l10n_util::GetStringUTF16(IDS_BLOCKED_AUTOPLAY_NO_ACTION); + radio_group.radio_items.push_back(radio_allow_label); + radio_group.radio_items.push_back(radio_block_label); + + ContentSetting setting; + SettingSource setting_source = SETTING_SOURCE_NONE; + + SettingInfo info; + HostContentSettingsMap* map = + HostContentSettingsMapFactory::GetForProfile(profile()); + std::unique_ptr value = + map->GetWebsiteSetting(url, url, content_type(), std::string(), &info); + setting = content_settings::ValueToContentSetting(value.get()); + setting_source = info.source; + + if (setting == CONTENT_SETTING_ALLOW) { + radio_group.default_item = kAllowButtonIndex; + // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. + } else { + radio_group.default_item = 1; + block_setting_ = setting; + } + + // Prevent creation of content settings for illegal urls like about:blank + bool is_valid = map->CanSetNarrowestContentSetting(url, url, content_type()); + + set_radio_group_enabled(is_valid && setting_source == SETTING_SOURCE_USER); + + set_radio_group(radio_group); +} + +void BraveAutoplayContentSettingBubbleModel::SetNarrowestContentSetting( + ContentSetting setting) { + if (!profile()) + return; + + auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); + map->SetNarrowestContentSetting(bubble_content().radio_group.url, + bubble_content().radio_group.url, + content_type(), setting); +} diff --git a/browser/ui/content_settings/brave_autoplay_content_setting_bubble_model.h b/browser/ui/content_settings/brave_autoplay_content_setting_bubble_model.h new file mode 100644 index 000000000000..e1f3dfbbce5f --- /dev/null +++ b/browser/ui/content_settings/brave_autoplay_content_setting_bubble_model.h @@ -0,0 +1,37 @@ +/* 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/. */ + +#ifndef BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_AUTOPLAY_CONTENT_SETTING_BUBBLE_MODEL_H_ +#define BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_AUTOPLAY_CONTENT_SETTING_BUBBLE_MODEL_H_ + +#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" + +class Profile; + +using content::WebContents; + +class BraveAutoplayContentSettingBubbleModel : public ContentSettingSimpleBubbleModel { + public: + BraveAutoplayContentSettingBubbleModel(Delegate* delegate, + WebContents* web_contents, + Profile* profile); + ~BraveAutoplayContentSettingBubbleModel() override; + + // ContentSettingSimpleBubbleModel: + void CommitChanges() override; + + protected: + bool settings_changed() const; + + private: + void SetTitle(); + void SetRadioGroup(); + void SetNarrowestContentSetting(ContentSetting setting); + + ContentSetting block_setting_; + + DISALLOW_COPY_AND_ASSIGN(BraveAutoplayContentSettingBubbleModel); +}; + +#endif // BRAVE_BROWSER_UI_CONTENT_SETTINGS_BRAVE_AUTOPLAY_CONTENT_SETTING_BUBBLE_MODEL_H_ diff --git a/browser/ui/content_settings/brave_content_setting_image_models.cc b/browser/ui/content_settings/brave_content_setting_image_models.cc index cf20eb1be86c..99a43d4ea83f 100644 --- a/browser/ui/content_settings/brave_content_setting_image_models.cc +++ b/browser/ui/content_settings/brave_content_setting_image_models.cc @@ -5,10 +5,13 @@ #include "brave/browser/ui/content_settings/brave_content_setting_image_models.h" #include "brave/browser/ui/content_settings/brave_widevine_blocked_image_model.h" +#include "brave/browser/ui/content_settings/brave_autoplay_blocked_image_model.h" void BraveGenerateContentSettingImageModels( std::vector>& result) { result.push_back(std::make_unique( BraveWidevineBlockedImageModel::ImageType::PLUGINS, CONTENT_SETTINGS_TYPE_PLUGINS)); + + result.push_back(std::make_unique()); } diff --git a/chromium_src/chrome/browser/budget_service/budget_service_impl.cc b/chromium_src/chrome/browser/budget_service/budget_service_impl.cc new file mode 100644 index 000000000000..69d87d7bce3d --- /dev/null +++ b/chromium_src/chrome/browser/budget_service/budget_service_impl.cc @@ -0,0 +1,2 @@ +#define PermissionManagerFactory BravePermissionManagerFactory +#include "../../../../../../chrome/browser/budget_service/budget_service_impl.cc" diff --git a/chromium_src/chrome/browser/notifications/notifier_state_tracker_factory.cc b/chromium_src/chrome/browser/notifications/notifier_state_tracker_factory.cc new file mode 100644 index 000000000000..1223e159d4ff --- /dev/null +++ b/chromium_src/chrome/browser/notifications/notifier_state_tracker_factory.cc @@ -0,0 +1,2 @@ +#define PermissionManagerFactory BravePermissionManagerFactory +#include "../../../../../../chrome/browser/notifications/notifier_state_tracker_factory.cc" diff --git a/chromium_src/chrome/browser/permissions/permission_manager.cc b/chromium_src/chrome/browser/permissions/permission_manager.cc new file mode 100644 index 000000000000..e5d1147c657a --- /dev/null +++ b/chromium_src/chrome/browser/permissions/permission_manager.cc @@ -0,0 +1,20 @@ +#include "brave/browser/autoplay/autoplay_permission_context.h" +#include "components/content_settings/core/common/content_settings.h" +#include "content/public/browser/permission_type.h" + +using content::PermissionType; + +namespace { + +ContentSettingsType PermissionTypeToContentSetting_ChromiumImpl(PermissionType permission); + +ContentSettingsType PermissionTypeToContentSetting(PermissionType permission) { + if (permission == PermissionType::AUTOPLAY) + return CONTENT_SETTINGS_TYPE_AUTOPLAY; + return PermissionTypeToContentSetting_ChromiumImpl(permission); +} + +} // namespace + +#define PermissionManagerFactory BravePermissionManagerFactory +#include "../../../../../chrome/browser/permissions/permission_manager.cc" diff --git a/chromium_src/chrome/browser/permissions/permission_request_impl.cc b/chromium_src/chrome/browser/permissions/permission_request_impl.cc new file mode 100644 index 000000000000..5419a8a50471 --- /dev/null +++ b/chromium_src/chrome/browser/permissions/permission_request_impl.cc @@ -0,0 +1,28 @@ +#include "chrome/browser/permissions/permission_request_impl.h" +#define GetIconId GetIconId_ChromiumImpl +#define GetMessageTextFragment GetMessageTextFragment_ChromiumImpl +#include "../../../../../chrome/browser/permissions/permission_request_impl.cc" +#undef GetMessageTextFragment +#undef GetIconId + +PermissionRequest::IconId PermissionRequestImpl::GetIconId() const { + switch (content_settings_type_) { + case CONTENT_SETTINGS_TYPE_AUTOPLAY: + return kExtensionIcon; + default: + break; + } + return GetIconId_ChromiumImpl(); +} + +base::string16 PermissionRequestImpl::GetMessageTextFragment() const { + int message_id; + switch (content_settings_type_) { + case CONTENT_SETTINGS_TYPE_AUTOPLAY: + message_id = IDS_AUTOPLAY_PERMISSION_FRAGMENT; + break; + default: + return GetMessageTextFragment_ChromiumImpl(); + } + return l10n_util::GetStringUTF16(message_id); +} diff --git a/chromium_src/chrome/browser/permissions/permission_uma_util.cc b/chromium_src/chrome/browser/permissions/permission_uma_util.cc new file mode 100644 index 000000000000..df8cb6ba3860 --- /dev/null +++ b/chromium_src/chrome/browser/permissions/permission_uma_util.cc @@ -0,0 +1,39 @@ +#include "chrome/browser/permissions/permission_util.h" + +#include "chrome/browser/permissions/permission_request.h" + +namespace { + +std::string GetPermissionRequestString_ChromiumImpl(PermissionRequestType type); +void BraveRecordPermissionAction (ContentSettingsType permission, + bool secure_origin, + PermissionAction action); + +std::string GetPermissionRequestString(PermissionRequestType type) { + if (type == PermissionRequestType::PERMISSION_AUTOPLAY) + return "Autoplay"; + return GetPermissionRequestString_ChromiumImpl(type); +} + +} // namespace + +#include "../../../../../chrome/browser/permissions/permission_uma_util.cc" + +namespace { + +void BraveRecordPermissionAction (ContentSettingsType permission, + bool secure_origin, + PermissionAction action) { + switch (permission) { + case CONTENT_SETTINGS_TYPE_AUTOPLAY: + PERMISSION_ACTION_UMA(secure_origin, "Permissions.Action.Autoplay", + "Permissions.Action.SecureOrigin.Autoplay", + "Permissions.Action.InsecureOrigin.Autoplay", + action); + break; + default: + break; + } +} + +} // namespace diff --git a/chromium_src/chrome/browser/permissions/permission_util.cc b/chromium_src/chrome/browser/permissions/permission_util.cc new file mode 100644 index 000000000000..1ffe3c921d08 --- /dev/null +++ b/chromium_src/chrome/browser/permissions/permission_util.cc @@ -0,0 +1,38 @@ +#include "chrome/browser/permissions/permission_util.h" +#define GetPermissionString GetPermissionString_ChromiumImpl +#define GetRequestType GetRequestType_ChromiumImpl +#define GetPermissionType GetPermissionType_ChromiumImpl +#define IsPermission IsPermission_ChromiumImpl +#include "../../../../../../chrome/browser/permissions/permission_util.cc" +#undef IsPermission +#undef GetPermissionType +#undef GetRequestType +#undef GetPermissionString + +std::string PermissionUtil::GetPermissionString( + ContentSettingsType content_type) { + if (content_type == CONTENT_SETTINGS_TYPE_AUTOPLAY) + return "Autoplay"; + return GetPermissionString_ChromiumImpl(content_type); +} + +PermissionRequestType PermissionUtil::GetRequestType(ContentSettingsType type) { + if (type == CONTENT_SETTINGS_TYPE_AUTOPLAY) + return PermissionRequestType::PERMISSION_AUTOPLAY; + return GetRequestType_ChromiumImpl(type); +} + +bool PermissionUtil::GetPermissionType(ContentSettingsType type, + PermissionType* out) { + if (type == CONTENT_SETTINGS_TYPE_AUTOPLAY) { + *out = PermissionType::AUTOPLAY; + return true; + } + return GetPermissionType_ChromiumImpl(type, out); +} + +bool PermissionUtil::IsPermission(ContentSettingsType type) { + if (type == CONTENT_SETTINGS_TYPE_AUTOPLAY) + return true; + return IsPermission_ChromiumImpl(type); +} diff --git a/chromium_src/chrome/browser/profiles/off_the_record_profile_impl.cc b/chromium_src/chrome/browser/profiles/off_the_record_profile_impl.cc new file mode 100644 index 000000000000..1a5a1353460c --- /dev/null +++ b/chromium_src/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -0,0 +1,2 @@ +#define PermissionManagerFactory BravePermissionManagerFactory +#include "../../../../../../chrome/browser/profiles/off_the_record_profile_impl.cc" diff --git a/chromium_src/chrome/browser/profiles/profile_impl.cc b/chromium_src/chrome/browser/profiles/profile_impl.cc new file mode 100644 index 000000000000..e33228146e76 --- /dev/null +++ b/chromium_src/chrome/browser/profiles/profile_impl.cc @@ -0,0 +1,2 @@ +#define PermissionManagerFactory BravePermissionManagerFactory +#include "../../../../../../chrome/browser/profiles/profile_impl.cc" diff --git a/chromium_src/chrome/browser/push_messaging/push_messaging_service_factory.cc b/chromium_src/chrome/browser/push_messaging/push_messaging_service_factory.cc new file mode 100644 index 000000000000..8bec7abf7375 --- /dev/null +++ b/chromium_src/chrome/browser/push_messaging/push_messaging_service_factory.cc @@ -0,0 +1,2 @@ +#define PermissionManagerFactory BravePermissionManagerFactory +#include "../../../../../../chrome/browser/push_messaging/push_messaging_service_factory.cc" diff --git a/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc b/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc new file mode 100644 index 000000000000..6bcb31b649d2 --- /dev/null +++ b/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc @@ -0,0 +1,40 @@ +#include "chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.h" +namespace settings { +void BraveAddLocalizedStrings(content::WebUIDataSource*, Profile*); +} // namespace settings +#include "../../../../../../chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc" + +namespace settings { + +#if !defined(OS_CHROMEOS) +void BraveAddImportDataStrings(content::WebUIDataSource* html_source) { + LocalizedString localized_strings[] = { + {"importCookies", IDS_SETTINGS_IMPORT_COOKIES_CHECKBOX} + }; + AddLocalizedStringsBulk(html_source, localized_strings, + arraysize(localized_strings)); +} +#endif + +void BraveAddCommonStrings(content::WebUIDataSource* html_source, Profile* profile) { + LocalizedString localized_strings[] = { + {"siteSettingsAutoplay", + IDS_SETTINGS_SITE_SETTINGS_AUTOPLAY}, + {"siteSettingsCategoryAutoplay", + IDS_SETTINGS_SITE_SETTINGS_AUTOPLAY}, + {"siteSettingsAutoplayAsk", + IDS_SETTINGS_SITE_SETTINGS_AUTOPLAY_ASK}, + {"siteSettingsAutoplayAskRecommended", + IDS_SETTINGS_SITE_SETTINGS_AUTOPLAY_ASK_RECOMMENDED} + }; + AddLocalizedStringsBulk(html_source, localized_strings, + arraysize(localized_strings)); +} + +void BraveAddLocalizedStrings(content::WebUIDataSource* html_source, + Profile* profile) { + BraveAddImportDataStrings(html_source); + BraveAddCommonStrings(html_source, profile); +} + +} // namespace settings diff --git a/chromium_src/chrome/browser/ui/webui/site_settings_helper.cc b/chromium_src/chrome/browser/ui/webui/site_settings_helper.cc new file mode 100644 index 000000000000..d2395f76ab5d --- /dev/null +++ b/chromium_src/chrome/browser/ui/webui/site_settings_helper.cc @@ -0,0 +1,29 @@ +#define HasRegisteredGroupName HasRegisteredGroupName_ChromiumImpl +#define ContentSettingsTypeFromGroupName ContentSettingsTypeFromGroupName_ChromiumImpl +#define ContentSettingsTypeToGroupName ContentSettingsTypeToGroupName_ChromiumImpl +#include "../../../../../../chrome/browser/ui/webui/site_settings_helper.cc" +#undef ContentSettingsTypeToGroupName +#undef ContentSettingsTypeFromGroupName +#undef HasRegisteredGroupName + +namespace site_settings { + +bool HasRegisteredGroupName(ContentSettingsType type) { + if (type == CONTENT_SETTINGS_TYPE_AUTOPLAY) + return true; + return HasRegisteredGroupName_ChromiumImpl(type); +} + +ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { + if (name == "autoplay") + return CONTENT_SETTINGS_TYPE_AUTOPLAY; + return ContentSettingsTypeFromGroupName_ChromiumImpl(name); +} + +std::string ContentSettingsTypeToGroupName(ContentSettingsType type) { + if (type == CONTENT_SETTINGS_TYPE_AUTOPLAY) + return "autoplay"; + return ContentSettingsTypeToGroupName_ChromiumImpl(type); +} + +} // namespace site_settings diff --git a/chromium_src/components/content_settings/core/browser/content_settings_registry.cc b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc new file mode 100644 index 000000000000..707ec98dab50 --- /dev/null +++ b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc @@ -0,0 +1,21 @@ +#include "../../../../../../components/content_settings/core/browser/content_settings_registry.cc" + +namespace content_settings { + +void ContentSettingsRegistry::BraveInit() { + // Add CONTENT_SETTING_ASK and make it default for autoplay + content_settings_info_.erase(CONTENT_SETTINGS_TYPE_AUTOPLAY); + website_settings_registry_->UnRegister(CONTENT_SETTINGS_TYPE_AUTOPLAY); + Register(CONTENT_SETTINGS_TYPE_AUTOPLAY, "autoplay", CONTENT_SETTING_ASK, + WebsiteSettingsInfo::UNSYNCABLE, WhitelistedSchemes(), + ValidSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK, + CONTENT_SETTING_ASK), + WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE, + WebsiteSettingsRegistry::DESKTOP | + WebsiteSettingsRegistry::PLATFORM_ANDROID, + ContentSettingsInfo::INHERIT_IN_INCOGNITO, + ContentSettingsInfo::PERSISTENT); + +} + +} // namespace content_settings diff --git a/chromium_src/content/child/runtime_features.cc b/chromium_src/content/child/runtime_features.cc new file mode 100644 index 000000000000..9abe9eb050dc --- /dev/null +++ b/chromium_src/content/child/runtime_features.cc @@ -0,0 +1,14 @@ +#define SetRuntimeFeaturesDefaultsAndUpdateFromArgs SetRuntimeFeaturesDefaultsAndUpdateFromArgs_ChromiumImpl +#include "../../../../content/child/runtime_features.cc" +#undef SetRuntimeFeaturesDefaultsAndUpdateFromArgs + +namespace content { + +void SetRuntimeFeaturesDefaultsAndUpdateFromArgs( + const base::CommandLine& command_line) { + SetRuntimeFeaturesDefaultsAndUpdateFromArgs_ChromiumImpl(command_line); + + WebRuntimeFeatures::EnableAutoplayMutedVideos(false); +} + +} // namespace content diff --git a/chromium_src/media/base/media_switches.cc b/chromium_src/media/base/media_switches.cc new file mode 100644 index 000000000000..bf29cc9a649b --- /dev/null +++ b/chromium_src/media/base/media_switches.cc @@ -0,0 +1,17 @@ +#define GetEffectiveAutoplayPolicy GetEffectiveAutoplayPolicy_ChromiumImpl +#include "../../../../media/base/media_switches.cc" +#undef GetEffectiveAutoplayPolicy + +namespace media { + +MEDIA_EXPORT +std::string GetEffectiveAutoplayPolicy(const base::CommandLine& command_line) { + // Return the autoplay policy set in the command line, if any. + if (!command_line.HasSwitch(switches::kAutoplayPolicy) && + base::FeatureList::IsEnabled(media::kUnifiedAutoplay)) + return switches::autoplay::kUserGestureRequiredPolicy; + + return GetEffectiveAutoplayPolicy_ChromiumImpl(command_line); +} + +} // namespace media diff --git a/patches/chrome-browser-content_settings-tab_specific_content_settings.cc.patch b/patches/chrome-browser-content_settings-tab_specific_content_settings.cc.patch new file mode 100644 index 000000000000..749773037236 --- /dev/null +++ b/patches/chrome-browser-content_settings-tab_specific_content_settings.cc.patch @@ -0,0 +1,20 @@ +diff --git a/chrome/browser/content_settings/tab_specific_content_settings.cc b/chrome/browser/content_settings/tab_specific_content_settings.cc +index 9b55a1a8927754b7a60a988465113e76e8f5ff63..a81b400eb397a3153616535263757a35dc1f7687 100644 +--- a/chrome/browser/content_settings/tab_specific_content_settings.cc ++++ b/chrome/browser/content_settings/tab_specific_content_settings.cc +@@ -270,6 +270,7 @@ bool TabSpecificContentSettings::IsContentBlocked( + content_type == CONTENT_SETTINGS_TYPE_ADS || + content_type == CONTENT_SETTINGS_TYPE_SOUND || + content_type == CONTENT_SETTINGS_TYPE_CLIPBOARD_READ || ++ content_type == CONTENT_SETTINGS_TYPE_AUTOPLAY || + content_type == CONTENT_SETTINGS_TYPE_SENSORS) { + const auto& it = content_settings_status_.find(content_type); + if (it != content_settings_status_.end()) +@@ -306,6 +307,7 @@ bool TabSpecificContentSettings::IsContentAllowed( + content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER && + content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX && + content_type != CONTENT_SETTINGS_TYPE_CLIPBOARD_READ && ++ content_type != CONTENT_SETTINGS_TYPE_AUTOPLAY && + content_type != CONTENT_SETTINGS_TYPE_SENSORS) { + return false; + } diff --git a/patches/chrome-browser-permissions-permission_manager.cc.patch b/patches/chrome-browser-permissions-permission_manager.cc.patch new file mode 100644 index 000000000000..1ed6f6112a25 --- /dev/null +++ b/patches/chrome-browser-permissions-permission_manager.cc.patch @@ -0,0 +1,21 @@ +diff --git a/chrome/browser/permissions/permission_manager.cc b/chrome/browser/permissions/permission_manager.cc +index c3e0e0bfecc85e5bbc36091c4c9f9454a1dfdc22..add6fa014288a8384fb3688f056994da9af988d2 100644 +--- a/chrome/browser/permissions/permission_manager.cc ++++ b/chrome/browser/permissions/permission_manager.cc +@@ -85,7 +85,7 @@ PermissionStatus ContentSettingToPermissionStatus(ContentSetting setting) { + } + + // Helper method to convert PermissionType to ContentSettingType. +-ContentSettingsType PermissionTypeToContentSetting(PermissionType permission) { ++ContentSettingsType PermissionTypeToContentSetting_ChromiumImpl(PermissionType permission) { + switch (permission) { + case PermissionType::MIDI: + return CONTENT_SETTINGS_TYPE_MIDI; +@@ -123,6 +123,7 @@ ContentSettingsType PermissionTypeToContentSetting(PermissionType permission) { + case PermissionType::PAYMENT_HANDLER: + return CONTENT_SETTINGS_TYPE_PAYMENT_HANDLER; + case PermissionType::NUM: ++ default: + // This will hit the NOTREACHED below. + break; + } diff --git a/patches/chrome-browser-permissions-permission_manager.h.patch b/patches/chrome-browser-permissions-permission_manager.h.patch new file mode 100644 index 000000000000..ff89027761af --- /dev/null +++ b/patches/chrome-browser-permissions-permission_manager.h.patch @@ -0,0 +1,12 @@ +diff --git a/chrome/browser/permissions/permission_manager.h b/chrome/browser/permissions/permission_manager.h +index beb9cae183d54a1296b6fc38a8a9d89a24566c5e..9633a76f39a64a7db08d4d6017b91984e542a368 100644 +--- a/chrome/browser/permissions/permission_manager.h ++++ b/chrome/browser/permissions/permission_manager.h +@@ -120,6 +120,7 @@ class PermissionManager : public KeyedService, + bool IsPermissionKillSwitchOn(ContentSettingsType); + + private: ++ friend class BravePermissionManager; + friend class PermissionManagerTest; + friend class GeolocationPermissionContextTests; + diff --git a/patches/chrome-browser-permissions-permission_manager_factory.h.patch b/patches/chrome-browser-permissions-permission_manager_factory.h.patch new file mode 100644 index 000000000000..c66a36788f5a --- /dev/null +++ b/patches/chrome-browser-permissions-permission_manager_factory.h.patch @@ -0,0 +1,12 @@ +diff --git a/chrome/browser/permissions/permission_manager_factory.h b/chrome/browser/permissions/permission_manager_factory.h +index be4990571b35bbdbd8c464c688d6050c0b9202c9..bce2e4efbcab5e366d8e57abe39ee9e4fd95704e 100644 +--- a/chrome/browser/permissions/permission_manager_factory.h ++++ b/chrome/browser/permissions/permission_manager_factory.h +@@ -23,6 +23,7 @@ class PermissionManagerFactory : public BrowserContextKeyedServiceFactory { + + private: + friend struct base::DefaultSingletonTraits; ++ friend class BravePermissionManagerFactory; + + PermissionManagerFactory(); + ~PermissionManagerFactory() override; diff --git a/patches/chrome-browser-permissions-permission_request.h.patch b/patches/chrome-browser-permissions-permission_request.h.patch new file mode 100644 index 000000000000..7da0b978d583 --- /dev/null +++ b/patches/chrome-browser-permissions-permission_request.h.patch @@ -0,0 +1,12 @@ +diff --git a/chrome/browser/permissions/permission_request.h b/chrome/browser/permissions/permission_request.h +index 61522a7ba2db7d5daf98f93bc378eac025b27215..2b509473cf0a927b6929ee616e745988268f319c 100644 +--- a/chrome/browser/permissions/permission_request.h ++++ b/chrome/browser/permissions/permission_request.h +@@ -45,6 +45,7 @@ enum class PermissionRequestType { + PERMISSION_CLIPBOARD_READ = 16, + PERMISSION_SECURITY_KEY_ATTESTATION = 17, + PERMISSION_PAYMENT_HANDLER = 18, ++ PERMISSION_AUTOPLAY = 19, + // NUM must be the last value in the enum. + NUM + }; diff --git a/patches/chrome-browser-permissions-permission_request_impl.h.patch b/patches/chrome-browser-permissions-permission_request_impl.h.patch new file mode 100644 index 000000000000..f610bae89e5e --- /dev/null +++ b/patches/chrome-browser-permissions-permission_request_impl.h.patch @@ -0,0 +1,17 @@ +diff --git a/chrome/browser/permissions/permission_request_impl.h b/chrome/browser/permissions/permission_request_impl.h +index aa7e4e1dde932f74ca5a7578deb30c94f05d5f40..febeb6be36fba688b93bbe8c1d572a8bf31626e9 100644 +--- a/chrome/browser/permissions/permission_request_impl.h ++++ b/chrome/browser/permissions/permission_request_impl.h +@@ -33,10 +33,12 @@ class PermissionRequestImpl : public PermissionRequest { + private: + // PermissionRequest: + IconId GetIconId() const override; ++ IconId GetIconId_ChromiumImpl() const; + #if defined(OS_ANDROID) + base::string16 GetMessageText() const override; + #endif + base::string16 GetMessageTextFragment() const override; ++ base::string16 GetMessageTextFragment_ChromiumImpl() const; + GURL GetOrigin() const override; + void PermissionGranted() override; + void PermissionDenied() override; diff --git a/patches/chrome-browser-permissions-permission_uma_util.cc.patch b/patches/chrome-browser-permissions-permission_uma_util.cc.patch new file mode 100644 index 000000000000..2103260280e3 --- /dev/null +++ b/patches/chrome-browser-permissions-permission_uma_util.cc.patch @@ -0,0 +1,23 @@ +diff --git a/chrome/browser/permissions/permission_uma_util.cc b/chrome/browser/permissions/permission_uma_util.cc +index 14efe3ccb3906516ba5c13a1c1ba78fb2ccd2d7d..cf3ac17e8b5e3c59a4c880ddc3861875dda1c3c8 100644 +--- a/chrome/browser/permissions/permission_uma_util.cc ++++ b/chrome/browser/permissions/permission_uma_util.cc +@@ -64,7 +64,7 @@ namespace { + + const int kPriorCountCap = 10; + +-std::string GetPermissionRequestString(PermissionRequestType type) { ++std::string GetPermissionRequestString_ChromiumImpl(PermissionRequestType type) { + switch (type) { + case PermissionRequestType::MULTIPLE: + return "AudioAndVideoCapture"; +@@ -401,6 +401,9 @@ void PermissionUmaUtil::RecordPermissionAction( + UMA_HISTOGRAM_ENUMERATION("Permissions.Action.PaymentHandler", action, + PermissionAction::NUM); + break; ++ case CONTENT_SETTINGS_TYPE_AUTOPLAY: ++ BraveRecordPermissionAction(permission, secure_origin, action); ++ break; + // The user is not prompted for these permissions, thus there is no + // permission action recorded for them. + default: diff --git a/patches/chrome-browser-permissions-permission_util.h.patch b/patches/chrome-browser-permissions-permission_util.h.patch new file mode 100644 index 000000000000..8e871a9b790e --- /dev/null +++ b/patches/chrome-browser-permissions-permission_util.h.patch @@ -0,0 +1,30 @@ +diff --git a/chrome/browser/permissions/permission_util.h b/chrome/browser/permissions/permission_util.h +index 7332efb056988779027f5b8abdcc253ef69c5c57..d29f1c65ab15df0f38110d8feddee1fa2fe1e4f9 100644 +--- a/chrome/browser/permissions/permission_util.h ++++ b/chrome/browser/permissions/permission_util.h +@@ -38,9 +38,11 @@ class PermissionUtil { + public: + // Returns the permission string for the given permission. + static std::string GetPermissionString(ContentSettingsType); ++ static std::string GetPermissionString_ChromiumImpl(ContentSettingsType); + + // Returns the request type corresponding to a permission type. + static PermissionRequestType GetRequestType(ContentSettingsType permission); ++ static PermissionRequestType GetRequestType_ChromiumImpl(ContentSettingsType permission); + + // Returns the gesture type corresponding to whether a permission request is + // made with or without a user gesture. +@@ -53,11 +55,13 @@ class PermissionUtil { + // histogram value to count permission request metrics. + static bool GetPermissionType(ContentSettingsType type, + content::PermissionType* out); ++ static bool GetPermissionType_ChromiumImpl(ContentSettingsType type, content::PermissionType* out); + + // Checks whether the given ContentSettingsType is a permission. Use this + // to determine whether a specific ContentSettingsType is supported by the + // PermissionManager. + static bool IsPermission(ContentSettingsType type); ++ static bool IsPermission_ChromiumImpl(ContentSettingsType type); + + // A scoped class that will check the current resolved content setting on + // construction and report a revocation metric accordingly if the revocation diff --git a/patches/chrome-browser-resources-settings-privacy_page-privacy_page.html.patch b/patches/chrome-browser-resources-settings-privacy_page-privacy_page.html.patch new file mode 100644 index 000000000000..e03a459900b5 --- /dev/null +++ b/patches/chrome-browser-resources-settings-privacy_page-privacy_page.html.patch @@ -0,0 +1,24 @@ +diff --git a/chrome/browser/resources/settings/privacy_page/privacy_page.html b/chrome/browser/resources/settings/privacy_page/privacy_page.html +index f14f0e747257429d4df1dc1eea95bcd930aba278..da6a83b4b20e13f6623213a8e2061c49dde5ba6e 100644 +--- a/chrome/browser/resources/settings/privacy_page/privacy_page.html ++++ b/chrome/browser/resources/settings/privacy_page/privacy_page.html +@@ -369,6 +369,19 @@ + + + ++ +