feat: allow setting autoplayPolicy in webPreferences (#16396)
This commit is contained in:
parent
1fe4b3fa28
commit
6d4480ea6b
2 changed files with 32 additions and 1 deletions
|
@ -73,6 +73,29 @@ bool GetAsInteger(const base::Value* val,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool GetAsAutoplayPolicy(const base::Value* val,
|
||||
const base::StringPiece& path,
|
||||
content::AutoplayPolicy* out) {
|
||||
std::string policy_str;
|
||||
if (GetAsString(val, path, &policy_str)) {
|
||||
if (policy_str == "no-user-gesture-required") {
|
||||
*out = content::AutoplayPolicy::kNoUserGestureRequired;
|
||||
return true;
|
||||
} else if (policy_str == "user-gesture-required") {
|
||||
*out = content::AutoplayPolicy::kUserGestureRequired;
|
||||
return true;
|
||||
} else if (policy_str == "user-gesture-required-for-cross-origin") {
|
||||
*out = content::AutoplayPolicy::kUserGestureRequiredForCrossOrigin;
|
||||
return true;
|
||||
} else if (policy_str == "document-user-activation-required") {
|
||||
*out = content::AutoplayPolicy::kDocumentUserActivationRequired;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace atom {
|
||||
|
@ -360,7 +383,10 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
|||
IsEnabled("textAreasAreResizable", true /* default_value */);
|
||||
prefs->navigate_on_drag_drop =
|
||||
IsEnabled("navigateOnDragDrop", false /* default_value */);
|
||||
prefs->autoplay_policy = content::AutoplayPolicy::kNoUserGestureRequired;
|
||||
if (!GetAsAutoplayPolicy(&preference_, "autoplayPolicy",
|
||||
&prefs->autoplay_policy)) {
|
||||
prefs->autoplay_policy = content::AutoplayPolicy::kNoUserGestureRequired;
|
||||
}
|
||||
|
||||
// Check if webgl should be enabled.
|
||||
bool is_webgl_enabled = IsEnabled("webgl", true /* default_value */);
|
||||
|
|
|
@ -371,6 +371,11 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
|||
English and not localized.
|
||||
* `navigateOnDragDrop` Boolean (optional) - Whether dragging and dropping a
|
||||
file or link onto the page causes a navigation. Default is `false`.
|
||||
* `autoplayPolicy` String (optional) - Autoplay policy to apply to
|
||||
content in the window, can be `no-user-gesture-required`,
|
||||
`user-gesture-required`, `user-gesture-required-for-cross-origin`,
|
||||
`document-user-activation-required`. Defaults to
|
||||
`no-user-gesture-required`.
|
||||
|
||||
When setting minimum or maximum window size with `minWidth`/`maxWidth`/
|
||||
`minHeight`/`maxHeight`, it only constrains the users. It won't prevent you from
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue