feat: add new imageAnimationPolicy webpref and webContents setter (#29095)
This commit is contained in:
parent
79cb5144ae
commit
8446ce1fc7
7 changed files with 51 additions and 0 deletions
|
@ -3142,6 +3142,13 @@ void WebContents::NotifyUserActivation() {
|
|||
blink::mojom::UserActivationNotificationType::kInteraction);
|
||||
}
|
||||
|
||||
void WebContents::SetImageAnimationPolicy(const std::string& new_policy) {
|
||||
auto* web_preferences = WebContentsPreferences::From(web_contents());
|
||||
web_preferences->preference()->SetKey(options::kImageAnimationPolicy,
|
||||
base::Value(new_policy));
|
||||
web_contents()->OnWebPreferencesChanged();
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> WebContents::TakeHeapSnapshot(
|
||||
v8::Isolate* isolate,
|
||||
const base::FilePath& file_path) {
|
||||
|
@ -3689,6 +3696,8 @@ v8::Local<v8::ObjectTemplate> WebContents::FillObjectTemplate(
|
|||
&WebContents::GetWebRTCIPHandlingPolicy)
|
||||
.SetMethod("_grantOriginAccess", &WebContents::GrantOriginAccess)
|
||||
.SetMethod("takeHeapSnapshot", &WebContents::TakeHeapSnapshot)
|
||||
.SetMethod("setImageAnimationPolicy",
|
||||
&WebContents::SetImageAnimationPolicy)
|
||||
.SetProperty("id", &WebContents::ID)
|
||||
.SetProperty("session", &WebContents::Session)
|
||||
.SetProperty("hostWebContents", &WebContents::HostWebContents)
|
||||
|
|
|
@ -419,6 +419,7 @@ class WebContents : public gin::Wrappable<WebContents>,
|
|||
void SetTemporaryZoomLevel(double level);
|
||||
void DoGetZoomLevel(
|
||||
electron::mojom::ElectronBrowser::DoGetZoomLevelCallback callback);
|
||||
void SetImageAnimationPolicy(const std::string& new_policy);
|
||||
|
||||
private:
|
||||
// Does not manage lifetime of |web_contents|.
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "shell/common/process_util.h"
|
||||
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
|
||||
#include "third_party/blink/public/mojom/v8_cache_options.mojom.h"
|
||||
#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom-blink.h" // nogncheck
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include "ui/gfx/switches.h"
|
||||
|
@ -109,6 +110,26 @@ bool GetAsAutoplayPolicy(const base::Value* val,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool GetImageAnimationPolicy(const base::Value* val,
|
||||
blink::mojom::ImageAnimationPolicy* out) {
|
||||
std::string policy;
|
||||
if (GetAsString(val, electron::options::kImageAnimationPolicy, &policy)) {
|
||||
if (policy == "animate") {
|
||||
*out = blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
|
||||
return true;
|
||||
} else if (policy == "animateOnce") {
|
||||
*out =
|
||||
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce;
|
||||
return true;
|
||||
} else if (policy == "noAnimation") {
|
||||
*out =
|
||||
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace electron {
|
||||
|
@ -367,6 +388,7 @@ void WebContentsPreferences::OverrideWebkitPrefs(
|
|||
prefs->javascript_enabled =
|
||||
IsEnabled(options::kJavaScript, true /* default_value */);
|
||||
prefs->images_enabled = IsEnabled(options::kImages, true /* default_value */);
|
||||
GetImageAnimationPolicy(&preference_, &prefs->animation_policy);
|
||||
prefs->text_areas_are_resizable =
|
||||
IsEnabled(options::kTextAreasAreResizable, true /* default_value */);
|
||||
prefs->navigate_on_drag_drop =
|
||||
|
|
|
@ -171,6 +171,9 @@ const char kJavaScript[] = "javascript";
|
|||
// Enables image support.
|
||||
const char kImages[] = "images";
|
||||
|
||||
// Image animation policy.
|
||||
const char kImageAnimationPolicy[] = "imageAnimationPolicy";
|
||||
|
||||
// Make TextArea elements resizable.
|
||||
const char kTextAreasAreResizable[] = "textAreasAreResizable";
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ extern const char kNodeIntegrationInSubFrames[];
|
|||
extern const char kDisableHtmlFullscreenWindowResize[];
|
||||
extern const char kJavaScript[];
|
||||
extern const char kImages[];
|
||||
extern const char kImageAnimationPolicy[];
|
||||
extern const char kTextAreasAreResizable[];
|
||||
extern const char kWebGL[];
|
||||
extern const char kNavigateOnDragDrop[];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue