-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from brave/autoplay-rebase
Enable granular control of autoplay
- Loading branch information
Showing
65 changed files
with
1,908 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import("//build/config/features.gni") | ||
|
||
source_set("autoplay") { | ||
sources = [ | ||
"autoplay_permission_context.cc", | ||
"autoplay_permission_context.h", | ||
] | ||
|
||
deps = [ | ||
"//chrome/browser", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |
Oops, something went wrong.