File indexing completed on 2024-04-28 15:29:20

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2010 David Faure <faure@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KPARTS_HTMLSETTINGSINTERFACE_H
0009 #define KPARTS_HTMLSETTINGSINTERFACE_H
0010 
0011 #include <kparts/kparts_export.h>
0012 
0013 #include <QObject>
0014 
0015 class QString;
0016 
0017 namespace KParts
0018 {
0019 /**
0020  * @class HtmlSettingsInterface htmlsettingsinterface.h <KParts/HtmlSettingsInterface>
0021  *
0022  * @short An interface for modifying the settings of browser engines.
0023  *
0024  *  This interface provides a generic means for querying or changing the
0025  *  settings of browser engines that implement it.
0026  *
0027  *  To use this class simply cast an instance of the HTMLExtension object
0028  *  using qobject_cast<KParts::HtmlSettingsInterface>.
0029  *
0030  *  Example:
0031  *  @code
0032  *  KParts::HTMLExtension* extension = KParts::HTMLExtension::childObject(part);
0033  *  KParts::HtmlSettingsInterface* settings = qobject_cast&lt;KParts::HtmlSettingsInterface&gt;(extension);
0034  *  const bool autoLoadImages = settings->attribute(KParts::AutoLoadImages);
0035  *  @endcode
0036  *
0037  *  @since 4.8.1
0038  */
0039 class KPARTS_EXPORT HtmlSettingsInterface
0040 {
0041 public:
0042     /**
0043      * Settings attribute types.
0044      */
0045     enum HtmlSettingsType {
0046         AutoLoadImages,
0047         DnsPrefetchEnabled,
0048         JavaEnabled,
0049         JavascriptEnabled,
0050         MetaRefreshEnabled,
0051         PluginsEnabled,
0052         PrivateBrowsingEnabled,
0053         OfflineStorageDatabaseEnabled,
0054         OfflineWebApplicationCacheEnabled,
0055         LocalStorageEnabled,
0056         UserDefinedStyleSheetURL,
0057     };
0058 
0059     /**
0060      * This enum specifies whether Java/JavaScript execution is allowed.
0061      *
0062      * @since 4.8.2
0063      */
0064     enum JavaScriptAdvice {
0065         JavaScriptDunno = 0,
0066         JavaScriptAccept,
0067         JavaScriptReject,
0068     };
0069 
0070     /**
0071      * This enum specifies the policy for window.open
0072      *
0073      * @since 4.8.2
0074      */
0075     enum JSWindowOpenPolicy {
0076         JSWindowOpenAllow = 0,
0077         JSWindowOpenAsk,
0078         JSWindowOpenDeny,
0079         JSWindowOpenSmart,
0080     };
0081 
0082     /**
0083      * This enum specifies the policy for window.status and .defaultStatus
0084      *
0085      * @since 4.8.2
0086      */
0087     enum JSWindowStatusPolicy {
0088         JSWindowStatusAllow = 0,
0089         JSWindowStatusIgnore,
0090     };
0091 
0092     /**
0093      * This enum specifies the policy for window.moveBy and .moveTo
0094      *
0095      * @since 4.8.2
0096      */
0097     enum JSWindowMovePolicy {
0098         JSWindowMoveAllow = 0,
0099         JSWindowMoveIgnore,
0100     };
0101 
0102     /**
0103      * This enum specifies the policy for window.resizeBy and .resizeTo
0104      *
0105      * @since 4.8.2
0106      */
0107     enum JSWindowResizePolicy {
0108         JSWindowResizeAllow = 0,
0109         JSWindowResizeIgnore,
0110     };
0111 
0112     /**
0113      * This enum specifies the policy for window.focus
0114      *
0115      * @since 4.8.2
0116      */
0117     enum JSWindowFocusPolicy {
0118         JSWindowFocusAllow = 0,
0119         JSWindowFocusIgnore,
0120     };
0121 
0122     /**
0123      * Destructor
0124      */
0125     virtual ~HtmlSettingsInterface()
0126     {
0127     }
0128 
0129     /**
0130      * Returns the value of the browser engine's attribute @p type.
0131      */
0132     virtual QVariant htmlSettingsProperty(HtmlSettingsType type) const = 0;
0133 
0134     /**
0135      * Sets the value of the browser engine's attribute @p type to @p value.
0136      */
0137     virtual bool setHtmlSettingsProperty(HtmlSettingsType type, const QVariant &value) = 0;
0138 
0139     /**
0140      * A convenience function that returns the javascript advice for @p text.
0141      *
0142      * If text is not either "accept" or "reject", this function returns
0143      * @ref JavaScriptDunno.
0144      *
0145      *  @since 4.8.2
0146      */
0147     static JavaScriptAdvice textToJavascriptAdvice(const QString &text);
0148 
0149     /**
0150      * A convenience function Returns the text for the given JavascriptAdvice @p advice.
0151      *
0152      * If @p advice is not either JavaScriptAccept or JavaScriptReject, this
0153      * function returns a NULL string.
0154      *
0155      *  @since 4.8.2
0156      */
0157     static const char *javascriptAdviceToText(JavaScriptAdvice advice);
0158 
0159     /**
0160      * A convenience function that splits @p text into @p domain, @p javaAdvice
0161      * and @p jScriptAdvice.
0162      *
0163      * If @p text is empty or does not contain the proper delimiter (':'), this
0164      * function will set @p domain to @p text and the other two parameters to
0165      * JavaScriptDunno.
0166      *
0167      *  @since 4.8.2
0168      */
0169     static void splitDomainAdvice(const QString &text, QString &domain, JavaScriptAdvice &javaAdvice, JavaScriptAdvice &javaScriptAdvice);
0170 };
0171 
0172 } // namespace KParts
0173 
0174 Q_DECLARE_INTERFACE(KParts::HtmlSettingsInterface, "org.kde.KParts.HtmlSettingsInterface")
0175 
0176 #endif /* KPARTS_HTMLSETTINGSINTERFACE_H */