diff --git a/third_party/blink/renderer/build/scripts/templates/internal_settings_generated.cc.tmpl b/third_party/blink/renderer/build/scripts/templates/internal_settings_generated.cc.tmpl index e6e4336a365c39..9fec270f45db42 100644 --- a/third_party/blink/renderer/build/scripts/templates/internal_settings_generated.cc.tmpl +++ b/third_party/blink/renderer/build/scripts/templates/internal_settings_generated.cc.tmpl @@ -10,31 +10,38 @@ namespace blink { -InternalSettingsGenerated::InternalSettingsGenerated(Page* page) - : page_(page) - {% for setting in settings if setting.type|to_idl_type %} - , {{setting.name}}_(page->GetSettings().Get{{setting.name.to_upper_camel_case()}}()) - {% endfor %} -{ +InternalSettingsGenerated::InternalSettingsGenerated(Page& page) + : InternalSettingsPageSupplementBase(page) { +{% for setting in settings %} + backup_.Set{{setting.name.to_upper_camel_case()}}( + GetSettings().Get{{setting.name.to_upper_camel_case()}}()); +{% endfor %} } InternalSettingsGenerated::~InternalSettingsGenerated() {} -void InternalSettingsGenerated::resetToConsistentState() { - {% for setting in settings if setting.type|to_idl_type %} - page_->GetSettings().Set{{setting.name.to_upper_camel_case()}}({{setting.name}}_); - {% endfor %} +void InternalSettingsGenerated::ResetToConsistentState() { +{% for setting in settings %} + GetSettings().Set{{setting.name.to_upper_camel_case()}}( + backup_.Get{{setting.name.to_upper_camel_case()}}()); +{% endfor %} } {% for setting in settings if setting.type|to_idl_type %} -void InternalSettingsGenerated::set{{setting.name.to_upper_camel_case()}}({{setting.type|to_passing_type}} {{setting.name}}) { - page_->GetSettings().Set{{setting.name.to_upper_camel_case()}}({{setting.name}}); +void InternalSettingsGenerated::set{{setting.name.to_upper_camel_case()}}( + {{setting.type|to_passing_type}} {{setting.name}}) { + GetSettings().Set{{setting.name.to_upper_camel_case()}}({{setting.name}}); } {% endfor %} void InternalSettingsGenerated::Trace(Visitor* visitor) const { - visitor->Trace(page_); ScriptWrappable::Trace(visitor); + InternalSettingsPageSupplementBase::Trace(visitor); +} + +Settings& InternalSettingsGenerated::GetSettings() { + CHECK(GetSupplementable()); + return GetSupplementable()->GetSettings(); } } // namespace blink diff --git a/third_party/blink/renderer/build/scripts/templates/internal_settings_generated.h.tmpl b/third_party/blink/renderer/build/scripts/templates/internal_settings_generated.h.tmpl index b010c7760bee49..2fa84ff90e7a24 100644 --- a/third_party/blink/renderer/build/scripts/templates/internal_settings_generated.h.tmpl +++ b/third_party/blink/renderer/build/scripts/templates/internal_settings_generated.h.tmpl @@ -7,6 +7,8 @@ #define {{header_guard}} #include "base/memory/scoped_refptr.h" +#include "third_party/blink/renderer/core/frame/settings.h" +#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/heap/garbage_collected.h" #include "third_party/blink/renderer/platform/heap/member.h" @@ -15,27 +17,31 @@ namespace blink { -class Page; - -class InternalSettingsGenerated : public ScriptWrappable { +class InternalSettingsGenerated : public ScriptWrappable, + public InternalSettingsPageSupplementBase { DEFINE_WRAPPERTYPEINFO(); public: - explicit InternalSettingsGenerated(Page*); + explicit InternalSettingsGenerated(Page&); virtual ~InternalSettingsGenerated(); - void resetToConsistentState(); + {% for setting in settings if setting.type|to_idl_type %} void set{{setting.name.to_upper_camel_case()}}({{setting.type|to_passing_type}} {{setting.name}}); {% endfor %} void Trace(Visitor*) const override; - private: - Member page_; + protected: + Settings& GetSettings(); - {% for setting in settings if setting.type|to_idl_type %} - {{setting.type}} {{setting.name}}_; - {% endfor %} + // Resets all settings to be the initial state when this is constructed. + // This also includes settings without an idl type (thus without an + // automatically generated setter method in this class), in case the settings + // are changed by custom methods defined in InternalSettings. + void ResetToConsistentState(); + + private: + Settings backup_; }; } // namespace blink diff --git a/third_party/blink/renderer/core/frame/settings.h b/third_party/blink/renderer/core/frame/settings.h index c7803c88e32ed1..78b587e4fede53 100644 --- a/third_party/blink/renderer/core/frame/settings.h +++ b/third_party/blink/renderer/core/frame/settings.h @@ -56,6 +56,9 @@ class CORE_EXPORT Settings { public: Settings(); + + // Default copy and assignment are forbidden because SettingsDelegate only + // supports 1:1 relationship with Settings. Settings(const Settings&) = delete; Settings& operator=(const Settings&) = delete; diff --git a/third_party/blink/renderer/core/testing/internal_settings.cc b/third_party/blink/renderer/core/testing/internal_settings.cc index 97337d0b5e8451..efcc05499fac9b 100644 --- a/third_party/blink/renderer/core/testing/internal_settings.cc +++ b/third_party/blink/renderer/core/testing/internal_settings.cc @@ -32,65 +32,11 @@ #include "third_party/blink/renderer/platform/supplementable.h" #include "third_party/blink/renderer/platform/text/locale_to_script_mapping.h" -#define InternalSettingsGuardForSettingsReturn(returnValue) \ - if (!settings()) { \ - exceptionState.throwDOMException( \ - InvalidAccessError, "The settings object cannot be obtained."); \ - return returnValue; \ - } - -#define InternalSettingsGuardForSettings() \ - if (!GetSettings()) { \ - exception_state.ThrowDOMException( \ - DOMExceptionCode::kInvalidAccessError, \ - "The settings object cannot be obtained."); \ - return; \ - } - -#define InternalSettingsGuardForPage() \ - if (!page()) { \ - exceptionState.throwDOMException(InvalidAccessError, \ - "The page object cannot be obtained."); \ - return; \ - } - namespace blink { using mojom::blink::HoverType; using mojom::blink::PointerType; -InternalSettings::Backup::Backup(Settings* settings) - : original_editing_behavior_(settings->GetEditingBehaviorType()), - original_text_autosizing_enabled_(settings->GetTextAutosizingEnabled()), - original_text_autosizing_window_size_override_( - settings->GetTextAutosizingWindowSizeOverride()), - original_accessibility_font_scale_factor_( - settings->GetAccessibilityFontScaleFactor()), - original_media_type_override_(settings->GetMediaTypeOverride()), - original_display_mode_override_(settings->GetDisplayModeOverride()), - original_mock_gesture_tap_highlights_enabled_( - settings->GetMockGestureTapHighlightsEnabled()), - images_enabled_(settings->GetImagesEnabled()), - default_video_poster_url_(settings->GetDefaultVideoPosterURL()), - original_image_animation_policy_(settings->GetImageAnimationPolicy()) {} - -void InternalSettings::Backup::RestoreTo(Settings* settings) { - settings->SetEditingBehaviorType(original_editing_behavior_); - settings->SetTextAutosizingEnabled(original_text_autosizing_enabled_); - settings->SetTextAutosizingWindowSizeOverride( - original_text_autosizing_window_size_override_); - settings->SetAccessibilityFontScaleFactor( - original_accessibility_font_scale_factor_); - settings->SetMediaTypeOverride(original_media_type_override_); - settings->SetDisplayModeOverride(original_display_mode_override_); - settings->SetMockGestureTapHighlightsEnabled( - original_mock_gesture_tap_highlights_enabled_); - settings->SetImagesEnabled(images_enabled_); - settings->SetDefaultVideoPosterURL(default_video_poster_url_); - settings->GetGenericFontFamilySettings().Reset(); - settings->SetImageAnimationPolicy(original_image_animation_policy_); -} - InternalSettings* InternalSettings::From(Page& page) { InternalSettings* supplement = Supplement::From(page); if (!supplement) { @@ -100,170 +46,92 @@ InternalSettings* InternalSettings::From(Page& page) { return supplement; } -InternalSettings::~InternalSettings() = default; - InternalSettings::InternalSettings(Page& page) - : InternalSettingsGenerated(&page), - InternalSettingsPageSupplementBase(page), - backup_(&page.GetSettings()) {} - -void InternalSettings::ResetToConsistentState() { - backup_.RestoreTo(GetSettings()); - backup_ = Backup(GetSettings()); - backup_.original_text_autosizing_enabled_ = - GetSettings()->GetTextAutosizingEnabled(); - - InternalSettingsGenerated::resetToConsistentState(); -} - -Settings* InternalSettings::GetSettings() const { - if (!GetPage()) - return nullptr; - return &GetPage()->GetSettings(); -} - -void InternalSettings::setHideScrollbars(bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetHideScrollbars(enabled); -} - -void InternalSettings::setMockGestureTapHighlightsEnabled( - bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetMockGestureTapHighlightsEnabled(enabled); -} + : InternalSettingsGenerated(page), + generic_font_family_settings_backup_( + GetSettings().GetGenericFontFamilySettings()) {} -void InternalSettings::setViewportEnabled(bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetViewportEnabled(enabled); -} +InternalSettings::~InternalSettings() = default; -void InternalSettings::setViewportMetaEnabled(bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetViewportMetaEnabled(enabled); +void InternalSettings::ResetToConsistentState() { + InternalSettingsGenerated::ResetToConsistentState(); + GetSettings().GetGenericFontFamilySettings() = + generic_font_family_settings_backup_; } void InternalSettings::setViewportStyle(const String& style, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - if (EqualIgnoringASCIICase(style, "default")) - GetSettings()->SetViewportStyle(mojom::blink::ViewportStyle::kDefault); - else if (EqualIgnoringASCIICase(style, "mobile")) - GetSettings()->SetViewportStyle(mojom::blink::ViewportStyle::kMobile); - else if (EqualIgnoringASCIICase(style, "television")) - GetSettings()->SetViewportStyle(mojom::blink::ViewportStyle::kTelevision); - else + if (EqualIgnoringASCIICase(style, "default")) { + GetSettings().SetViewportStyle(mojom::blink::ViewportStyle::kDefault); + } else if (EqualIgnoringASCIICase(style, "mobile")) { + GetSettings().SetViewportStyle(mojom::blink::ViewportStyle::kMobile); + } else if (EqualIgnoringASCIICase(style, "television")) { + GetSettings().SetViewportStyle(mojom::blink::ViewportStyle::kTelevision); + } else { exception_state.ThrowDOMException( DOMExceptionCode::kSyntaxError, "The viewport style type provided ('" + style + "') is invalid."); + } } -void InternalSettings::setStandardFontFamily(const AtomicString& family, - const String& script, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); +void InternalSettings::SetFontFamily( + const AtomicString& family, + const String& script, + bool (GenericFontFamilySettings::*update_method)(const AtomicString&, + UScriptCode)) { UScriptCode code = ScriptNameToCode(script); - if (code == USCRIPT_INVALID_CODE) + if (code == USCRIPT_INVALID_CODE) { return; - if (GetSettings()->GetGenericFontFamilySettings().UpdateStandard(family, - code)) - GetSettings()->NotifyGenericFontFamilyChange(); + } + if ((GetSettings().GetGenericFontFamilySettings().*update_method)(family, + code)) { + GetSettings().NotifyGenericFontFamilyChange(); + } +} + +void InternalSettings::setStandardFontFamily(const AtomicString& family, + const String& script) { + SetFontFamily(family, script, &GenericFontFamilySettings::UpdateStandard); } void InternalSettings::setSerifFontFamily(const AtomicString& family, - const String& script, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - UScriptCode code = ScriptNameToCode(script); - if (code == USCRIPT_INVALID_CODE) - return; - if (GetSettings()->GetGenericFontFamilySettings().UpdateSerif(family, code)) - GetSettings()->NotifyGenericFontFamilyChange(); + const String& script) { + SetFontFamily(family, script, &GenericFontFamilySettings::UpdateSerif); } void InternalSettings::setSansSerifFontFamily(const AtomicString& family, - const String& script, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - UScriptCode code = ScriptNameToCode(script); - if (code == USCRIPT_INVALID_CODE) - return; - if (GetSettings()->GetGenericFontFamilySettings().UpdateSansSerif(family, - code)) - GetSettings()->NotifyGenericFontFamilyChange(); + const String& script) { + SetFontFamily(family, script, &GenericFontFamilySettings::UpdateSansSerif); } void InternalSettings::setFixedFontFamily(const AtomicString& family, - const String& script, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - UScriptCode code = ScriptNameToCode(script); - if (code == USCRIPT_INVALID_CODE) - return; - if (GetSettings()->GetGenericFontFamilySettings().UpdateFixed(family, code)) - GetSettings()->NotifyGenericFontFamilyChange(); + const String& script) { + SetFontFamily(family, script, &GenericFontFamilySettings::UpdateFixed); } void InternalSettings::setCursiveFontFamily(const AtomicString& family, - const String& script, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - UScriptCode code = ScriptNameToCode(script); - if (code == USCRIPT_INVALID_CODE) - return; - if (GetSettings()->GetGenericFontFamilySettings().UpdateCursive(family, code)) - GetSettings()->NotifyGenericFontFamilyChange(); + const String& script) { + SetFontFamily(family, script, &GenericFontFamilySettings::UpdateCursive); } void InternalSettings::setFantasyFontFamily(const AtomicString& family, - const String& script, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - UScriptCode code = ScriptNameToCode(script); - if (code == USCRIPT_INVALID_CODE) - return; - if (GetSettings()->GetGenericFontFamilySettings().UpdateFantasy(family, code)) - GetSettings()->NotifyGenericFontFamilyChange(); + const String& script) { + SetFontFamily(family, script, &GenericFontFamilySettings::UpdateFantasy); } void InternalSettings::setMathFontFamily(const AtomicString& family, - const String& script, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - // It is not clear whether math fonts really require one setting per script. - // However, given that other generic font families behave that way and that - // this per-script configuration is exposed by various public APIs, it seems - // best to do that for math font family too. - UScriptCode code = ScriptNameToCode(script); - if (code == USCRIPT_INVALID_CODE) - return; - if (GetSettings()->GetGenericFontFamilySettings().UpdateMath(family, code)) - GetSettings()->NotifyGenericFontFamilyChange(); -} - -void InternalSettings::setTextAutosizingEnabled( - bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetTextAutosizingEnabled(enabled); + const String& script) { + SetFontFamily(family, script, &GenericFontFamilySettings::UpdateMath); } -void InternalSettings::setTextAutosizingWindowSizeOverride( - int width, - int height, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetTextAutosizingWindowSizeOverride(gfx::Size(width, height)); +void InternalSettings::setTextAutosizingWindowSizeOverride(int width, + int height) { + GetSettings().SetTextAutosizingWindowSizeOverride(gfx::Size(width, height)); } void InternalSettings::setTextTrackKindUserPreference( const String& preference, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); String token = preference.StripWhiteSpace(); TextTrackKindUserPreference user_preference = TextTrackKindUserPreference::kDefault; @@ -281,39 +149,25 @@ void InternalSettings::setTextTrackKindUserPreference( return; } - GetSettings()->SetTextTrackKindUserPreference(user_preference); -} - -void InternalSettings::setMediaTypeOverride(const String& media_type, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetMediaTypeOverride(media_type); -} - -void InternalSettings::setAccessibilityFontScaleFactor( - float font_scale_factor, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetAccessibilityFontScaleFactor(font_scale_factor); + GetSettings().SetTextTrackKindUserPreference(user_preference); } void InternalSettings::setEditingBehavior(const String& editing_behavior, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); if (EqualIgnoringASCIICase(editing_behavior, "win")) { - GetSettings()->SetEditingBehaviorType( + GetSettings().SetEditingBehaviorType( mojom::EditingBehavior::kEditingWindowsBehavior); } else if (EqualIgnoringASCIICase(editing_behavior, "mac")) { - GetSettings()->SetEditingBehaviorType( + GetSettings().SetEditingBehaviorType( mojom::EditingBehavior::kEditingMacBehavior); } else if (EqualIgnoringASCIICase(editing_behavior, "unix")) { - GetSettings()->SetEditingBehaviorType( + GetSettings().SetEditingBehaviorType( mojom::EditingBehavior::kEditingUnixBehavior); } else if (EqualIgnoringASCIICase(editing_behavior, "android")) { - GetSettings()->SetEditingBehaviorType( + GetSettings().SetEditingBehaviorType( mojom::EditingBehavior::kEditingAndroidBehavior); } else if (EqualIgnoringASCIICase(editing_behavior, "chromeos")) { - GetSettings()->SetEditingBehaviorType( + GetSettings().SetEditingBehaviorType( mojom::EditingBehavior::kEditingChromeOSBehavior); } else { exception_state.ThrowDOMException(DOMExceptionCode::kSyntaxError, @@ -322,29 +176,9 @@ void InternalSettings::setEditingBehavior(const String& editing_behavior, } } -void InternalSettings::setImagesEnabled(bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetImagesEnabled(enabled); -} - -void InternalSettings::setDefaultVideoPosterURL( - const String& url, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetDefaultVideoPosterURL(url); -} - -void InternalSettings::Trace(Visitor* visitor) const { - InternalSettingsGenerated::Trace(visitor); - Supplement::Trace(visitor); -} - void InternalSettings::setAvailablePointerTypes( const String& pointers, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - // Allow setting multiple pointer types by passing comma seperated list // ("coarse,fine"). Vector tokens; @@ -368,14 +202,12 @@ void InternalSettings::setAvailablePointerTypes( } } - GetSettings()->SetAvailablePointerTypes(pointer_types); + GetSettings().SetAvailablePointerTypes(pointer_types); } void InternalSettings::setDisplayModeOverride(const String& display_mode, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); String token = display_mode.StripWhiteSpace(); - auto mode = blink::mojom::DisplayMode::kBrowser; if (token == "browser") { mode = blink::mojom::DisplayMode::kBrowser; @@ -392,14 +224,12 @@ void InternalSettings::setDisplayModeOverride(const String& display_mode, return; } - GetSettings()->SetDisplayModeOverride(mode); + GetSettings().SetDisplayModeOverride(mode); } void InternalSettings::setPrimaryPointerType(const String& pointer, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); String token = pointer.StripWhiteSpace(); - PointerType type = PointerType::kPointerNone; if (token == "coarse") { type = PointerType::kPointerCoarseType; @@ -414,13 +244,11 @@ void InternalSettings::setPrimaryPointerType(const String& pointer, return; } - GetSettings()->SetPrimaryPointerType(type); + GetSettings().SetPrimaryPointerType(type); } void InternalSettings::setAvailableHoverTypes(const String& types, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - // Allow setting multiple hover types by passing comma seperated list // ("on-demand,none"). Vector tokens; @@ -441,14 +269,12 @@ void InternalSettings::setAvailableHoverTypes(const String& types, } } - GetSettings()->SetAvailableHoverTypes(hover_types); + GetSettings().SetAvailableHoverTypes(hover_types); } void InternalSettings::setPrimaryHoverType(const String& type, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); String token = type.StripWhiteSpace(); - HoverType hover_type = HoverType::kHoverNone; if (token == "none") { hover_type = HoverType::kHoverNone; @@ -461,21 +287,20 @@ void InternalSettings::setPrimaryHoverType(const String& type, return; } - GetSettings()->SetPrimaryHoverType(hover_type); + GetSettings().SetPrimaryHoverType(hover_type); } void InternalSettings::setImageAnimationPolicy( const String& policy, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); if (EqualIgnoringASCIICase(policy, "allowed")) { - GetSettings()->SetImageAnimationPolicy( + GetSettings().SetImageAnimationPolicy( mojom::blink::ImageAnimationPolicy::kImageAnimationPolicyAllowed); } else if (EqualIgnoringASCIICase(policy, "once")) { - GetSettings()->SetImageAnimationPolicy( + GetSettings().SetImageAnimationPolicy( mojom::blink::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce); } else if (EqualIgnoringASCIICase(policy, "none")) { - GetSettings()->SetImageAnimationPolicy( + GetSettings().SetImageAnimationPolicy( mojom::blink::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation); } else { exception_state.ThrowDOMException( @@ -485,29 +310,8 @@ void InternalSettings::setImageAnimationPolicy( } } -void InternalSettings::SetDnsPrefetchLogging(bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetLogDnsPrefetchAndPreconnect(enabled); -} - -void InternalSettings::SetPreloadLogging(bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetLogPreload(enabled); -} - -void InternalSettings::setPresentationReceiver( - bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetPresentationReceiver(enabled); -} - void InternalSettings::setAutoplayPolicy(const String& policy_str, ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - AutoplayPolicy::Type policy = AutoplayPolicy::Type::kNoUserGestureRequired; if (policy_str == "no-user-gesture-required") { policy = AutoplayPolicy::Type::kNoUserGestureRequired; @@ -521,21 +325,11 @@ void InternalSettings::setAutoplayPolicy(const String& policy_str, "The autoplay policy ('" + policy_str + ")' is invalid."); } - GetSettings()->SetAutoplayPolicy(policy); + GetSettings().SetAutoplayPolicy(policy); } -void InternalSettings::setUniversalAccessFromFileURLs( - bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetAllowUniversalAccessFromFileURLs(enabled); -} - -void InternalSettings::setPreferCompositingToLCDTextEnabled( - bool enabled, - ExceptionState& exception_state) { - InternalSettingsGuardForSettings(); - GetSettings()->SetPreferCompositingToLCDTextForTesting(enabled); +void InternalSettings::setPreferCompositingToLCDTextEnabled(bool enabled) { + GetSettings().SetPreferCompositingToLCDTextForTesting(enabled); } } // namespace blink diff --git a/third_party/blink/renderer/core/testing/internal_settings.h b/third_party/blink/renderer/core/testing/internal_settings.h index 430af896a1b2ed..de4069c520b50a 100644 --- a/third_party/blink/renderer/core/testing/internal_settings.h +++ b/third_party/blink/renderer/core/testing/internal_settings.h @@ -27,46 +27,21 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TESTING_INTERNAL_SETTINGS_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_TESTING_INTERNAL_SETTINGS_H_ -#include "third_party/blink/public/mojom/manifest/display_mode.mojom-shared.h" -#include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom-blink.h" -#include "third_party/blink/renderer/core/page/page.h" +#include + #include "third_party/blink/renderer/core/testing/internal_settings_generated.h" -#include "third_party/blink/renderer/platform/heap/garbage_collected.h" -#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" +#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" -#include "ui/gfx/geometry/size.h" namespace blink { class ExceptionState; -class Page; -class Settings; +class GenericFontFamilySettings; -class InternalSettings final : public InternalSettingsGenerated, - public InternalSettingsPageSupplementBase { +class InternalSettings final : public InternalSettingsGenerated { DEFINE_WRAPPERTYPEINFO(); public: - class Backup { - DISALLOW_NEW(); - - public: - explicit Backup(Settings*); - void RestoreTo(Settings*); - - bool original_overlay_scrollbars_enabled_; - mojom::EditingBehavior original_editing_behavior_; - bool original_text_autosizing_enabled_; - gfx::Size original_text_autosizing_window_size_override_; - float original_accessibility_font_scale_factor_; - String original_media_type_override_; - blink::mojom::DisplayMode original_display_mode_override_; - bool original_mock_gesture_tap_highlights_enabled_; - bool images_enabled_; - String default_video_poster_url_; - mojom::blink::ImageAnimationPolicy original_image_animation_policy_; - }; - static InternalSettings* From(Page&); explicit InternalSettings(Page&); @@ -74,64 +49,35 @@ class InternalSettings final : public InternalSettingsGenerated, void ResetToConsistentState(); - void setStandardFontFamily(const AtomicString& family, - const String& script, - ExceptionState&); - void setSerifFontFamily(const AtomicString& family, - const String& script, - ExceptionState&); - void setSansSerifFontFamily(const AtomicString& family, - const String& script, - ExceptionState&); - void setFixedFontFamily(const AtomicString& family, - const String& script, - ExceptionState&); - void setCursiveFontFamily(const AtomicString& family, - const String& script, - ExceptionState&); - void setFantasyFontFamily(const AtomicString& family, - const String& script, - ExceptionState&); - void setMathFontFamily(const AtomicString& family, - const String& script, - ExceptionState&); - void setDefaultVideoPosterURL(const String& url, ExceptionState&); + void setStandardFontFamily(const AtomicString& family, const String& script); + void setSerifFontFamily(const AtomicString& family, const String& script); + void setSansSerifFontFamily(const AtomicString& family, const String& script); + void setFixedFontFamily(const AtomicString& family, const String& script); + void setCursiveFontFamily(const AtomicString& family, const String& script); + void setFantasyFontFamily(const AtomicString& family, const String& script); + void setMathFontFamily(const AtomicString& family, const String& script); + void setTextAutosizingWindowSizeOverride(int width, int height); void setEditingBehavior(const String&, ExceptionState&); - void setImagesEnabled(bool, ExceptionState&); - void setMediaTypeOverride(const String& media_type, ExceptionState&); void setDisplayModeOverride(const String& display_mode, ExceptionState&); - void setHideScrollbars(bool, ExceptionState&); - void setMockGestureTapHighlightsEnabled(bool, ExceptionState&); - void setTextAutosizingEnabled(bool, ExceptionState&); void setTextTrackKindUserPreference(const String& preference, ExceptionState&); - void setAccessibilityFontScaleFactor(float font_scale_factor, - ExceptionState&); - void setTextAutosizingWindowSizeOverride(int width, - int height, - ExceptionState&); - void setViewportEnabled(bool, ExceptionState&); - void setViewportMetaEnabled(bool, ExceptionState&); void setViewportStyle(const String& preference, ExceptionState&); - void setPresentationReceiver(bool, ExceptionState&); void setAutoplayPolicy(const String&, ExceptionState&); - void setUniversalAccessFromFileURLs(bool, ExceptionState&); void setImageAnimationPolicy(const String&, ExceptionState&); void setAvailablePointerTypes(const String&, ExceptionState&); void setPrimaryPointerType(const String&, ExceptionState&); void setAvailableHoverTypes(const String&, ExceptionState&); void setPrimaryHoverType(const String&, ExceptionState&); - void SetDnsPrefetchLogging(bool, ExceptionState&); - void SetPreloadLogging(bool, ExceptionState&); - void setPreferCompositingToLCDTextEnabled(bool, ExceptionState&); - - void Trace(Visitor*) const override; + void setPreferCompositingToLCDTextEnabled(bool); private: - Settings* GetSettings() const; - Page* GetPage() const { return GetSupplementable(); } + void SetFontFamily( + const AtomicString& family, + const String& script, + bool (GenericFontFamilySettings::*update_method)(const AtomicString&, + UScriptCode)); - Backup backup_; + GenericFontFamilySettings generic_font_family_settings_backup_; }; } // namespace blink diff --git a/third_party/blink/renderer/core/testing/internal_settings.idl b/third_party/blink/renderer/core/testing/internal_settings.idl index 9a6ea9406d5888..ecc58e3d1a323b 100644 --- a/third_party/blink/renderer/core/testing/internal_settings.idl +++ b/third_party/blink/renderer/core/testing/internal_settings.idl @@ -24,36 +24,31 @@ */ interface InternalSettings : InternalSettingsGenerated { - // All methods which access Page::settings() can raise an exception - // when the page cannot be accessed. (Such as during page tear-down.) - [RaisesException] void setHideScrollbars(boolean enabled); - [RaisesException] void setMockGestureTapHighlightsEnabled(boolean enabled); - [RaisesException] void setStandardFontFamily(DOMString family, DOMString script); - [RaisesException] void setSerifFontFamily(DOMString family, DOMString script); - [RaisesException] void setSansSerifFontFamily(DOMString family, DOMString script); - [RaisesException] void setFixedFontFamily(DOMString family, DOMString script); - [RaisesException] void setCursiveFontFamily(DOMString family, DOMString script); - [RaisesException] void setFantasyFontFamily(DOMString family, DOMString script); - [RaisesException] void setMathFontFamily(DOMString family, DOMString script); - [RaisesException] void setTextAutosizingEnabled(boolean enabled); - [RaisesException] void setTextAutosizingWindowSizeOverride(long width, long height); + // Only methods that are not automatically generated in + // InternalSettingsGenerated need to be defined here. + // For example, the setting editingBehaviorType is of type + // mojom::EditingBehavior which is not an idl type so + // InternalSettingsGenerated doesn't have setEditingBehaviorType. + // setEditingBehavior() defined here accepts a DOMString parameter which + // will be converted to an enum value passed to + // Settings::SetEditingBehaviorType(). + void setStandardFontFamily(DOMString family, DOMString script); + void setSerifFontFamily(DOMString family, DOMString script); + void setSansSerifFontFamily(DOMString family, DOMString script); + void setFixedFontFamily(DOMString family, DOMString script); + void setCursiveFontFamily(DOMString family, DOMString script); + void setFantasyFontFamily(DOMString family, DOMString script); + void setMathFontFamily(DOMString family, DOMString script); + void setTextAutosizingWindowSizeOverride(long width, long height); [RaisesException] void setTextTrackKindUserPreference(DOMString preference); - [RaisesException] void setAccessibilityFontScaleFactor(float fontScaleFactor); - [RaisesException] void setMediaTypeOverride(DOMString mediaTypeOverride); [RaisesException] void setDisplayModeOverride(DOMString displayModeOverride); [RaisesException] void setEditingBehavior(DOMString behavior); - [RaisesException] void setImagesEnabled(boolean enabled); - [RaisesException] void setDefaultVideoPosterURL(DOMString poster); - [RaisesException] void setViewportEnabled(boolean enabled); - [RaisesException] void setViewportMetaEnabled(boolean enabled); [RaisesException] void setViewportStyle(DOMString style); [RaisesException] void setAvailablePointerTypes(DOMString pointers); [RaisesException] void setPrimaryPointerType(DOMString pointer); [RaisesException] void setAvailableHoverTypes(DOMString types); [RaisesException] void setPrimaryHoverType(DOMString type); [RaisesException] void setImageAnimationPolicy(DOMString policy); - [RaisesException] void setPresentationReceiver(boolean enabled); [RaisesException] void setAutoplayPolicy(DOMString policy); - [RaisesException] void setUniversalAccessFromFileURLs(boolean enabled); - [RaisesException] void setPreferCompositingToLCDTextEnabled(boolean enabled); + void setPreferCompositingToLCDTextEnabled(boolean enabled); }; diff --git a/third_party/blink/web_tests/http/tests/security/agent-universal-access.html b/third_party/blink/web_tests/http/tests/security/agent-universal-access.html index 0ab51e27ba57d5..47590321518325 100644 --- a/third_party/blink/web_tests/http/tests/security/agent-universal-access.html +++ b/third_party/blink/web_tests/http/tests/security/agent-universal-access.html @@ -12,7 +12,7 @@ // Android webview) has been set. The agents on the two iframes will // be different but access should still be allowed. async_test(t => { - internals.settings.setUniversalAccessFromFileURLs(true); + internals.settings.setAllowUniversalAccessFromFileURLs(true); // create same origin iframe let iframe = document.createElement('iframe'); @@ -29,7 +29,7 @@ t.add_cleanup(() => { document.body.removeChild(iframe); - internals.settings.setUniversalAccessFromFileURLs(false); + internals.settings.setAllowUniversalAccessFromFileURLs(false); }); }, 'Same-origin documents must share the same agent.');