diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 4e8325566eb7..80fbac89a91f 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -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 */); diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 1f2646a92cd3..90b85ecde8b8 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -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