File indexing completed on 2024-12-22 04:41:13

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #pragma once
0019 
0020 #include <QObject>
0021 #include "qmlcookie.h"
0022 
0023 /**
0024  * @brief The class exposing Cookies API to QML
0025  */
0026 class QmlCookies : public QObject
0027 {
0028     Q_OBJECT
0029 public:
0030     explicit QmlCookies(QObject *parent = nullptr);
0031     /**
0032      * @brief Get a cookie
0033      * @param A JavaScript object containing
0034      *        - name:
0035      *          String representing the name of the cookie
0036      *        - url:
0037      *          String representing the url of the cookie
0038      * @return Cookie of type [QmlCookie](@ref QmlCookie)
0039      *         if such cookie exists, else null
0040      */
0041     Q_INVOKABLE QmlCookie *get(const QVariantMap &map);
0042     /**
0043      * @brief Get all cookies matching a criteria
0044      * @param A JavaScript object containing
0045      *        - name:
0046      *          String representing the name of the cookie
0047      *        - url:
0048      *          String representing the url of the cookie
0049      *        - path:
0050      *          String representing the path of the cookie
0051      *        - secure:
0052      *          Bool representing if the cookie is secure
0053      *        - session:
0054      *          Bool representing if the cookie is a session cookie
0055      * @return List containing cookies, each of type [QmlCookie](@ref QmlCookie)
0056      */
0057     Q_INVOKABLE QList<QObject*> getAll(const QVariantMap &map);
0058     /**
0059      * @brief Set a cookie
0060      * @param A JavaScript object containing
0061      *        - name:
0062      *          String representing the name of the cookie
0063      *        - url:
0064      *          String representing the name of the cookie
0065      *        - path:
0066      *          String representing the path of the cookie
0067      *        - secure:
0068      *          Bool representing if the cookie is secure
0069      *        - expirationDate:
0070      *          A JavaScript Date object, representing the expiration date of the cookie
0071      *        - httpOnly:
0072      *          Bool representing if the cookie is httpOnly
0073      *        - value:
0074      *          String representing the value of the cookie
0075      */
0076     Q_INVOKABLE void set(const QVariantMap &map);
0077     /**
0078      * @brief Remove a cookie
0079      * @param A JavaScript object containing
0080      *        - name:
0081      *          String representing the name of the cookie
0082      *        - url:
0083      *          String representing the url of the cookie
0084      */
0085     Q_INVOKABLE void remove(const QVariantMap &map);
0086 Q_SIGNALS:
0087     /**
0088      * @brief The signal emitted when a cookie is added or removed
0089      * @param A JavaScript object containing
0090      *        - cookie:
0091      *          Object of type [QmlCookie](@ref QmlCookie), which is added or removed
0092      *        - removed:
0093      *          Bool representing if the cookie is removed
0094      */
0095     void changed(const QVariantMap &map);
0096 private:
0097     QNetworkCookie getNetworkCookie(const QVariantMap &map);
0098 };