forked from nedrysoft/regex101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RegExUrlSchemeHandler.h
125 lines (113 loc) · 4.84 KB
/
RegExUrlSchemeHandler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (C) 2020 Adrian Carpenter
*
* This file is part of a regex101.com offline application.
*
* https://github.com/fizzyade/regex101
*
* =====================================================================
* The regex101 web content is owned and used with permission from
* Firas Dib at regex101.com. This application is an unofficial
* tool to provide an offline application version of the website.
* =====================================================================
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REGEXURLSCHEMEHANDLER_H
#define REGEXURLSCHEMEHANDLER_H
#include <QWebEngineUrlSchemeHandler>
#include <QWebEngineProfile>
namespace Nedrysoft {
/**
* @brief RegExUrlSchemeHandler class
*
* @details This class provides a custom scheme implementation that allows content to be
* displayed in a web page from a local data source. This class is used in conjunction
* with the RefExUrlRequestInterceptor and RegExApiEndpoint classes to provide
* a full implementation.
*/
class RegExUrlSchemeHandler :
public QWebEngineUrlSchemeHandler
{
private:
Q_OBJECT
public:
/**
* @brief Constructs a URL scheme handler.
*
* @param[in] resourceRootFolder is the root path of the internal web content.
*/
RegExUrlSchemeHandler(QString resourceRootFolder);
/**
* @brief requestStarted
*
* @details This function is called when a request is made to the custom scheme,
* the job includes information about the request and functions to
* tell the web engine whether or not the request was successful.
*
* @param[in] request is the information about the request job.
*/
void requestStarted(QWebEngineUrlRequestJob *request);
/**
* @brief registerScheme
*
* @details Registers the custom scheme with the web engine.
*
* @note This must be called before the QApplication is instantiated.
*/
static void registerScheme();
/**
* @brief name
*
* @details Returns the name used for the scheme.
*
* @returns The name of the scheme.
*/
static QString name();
/**
* @brief scheme
*
* @details Returns the scheme.
*
* @returns the scheme.
*/
static QString scheme();
/**
* @brief root
*
* @details Returns the scheme root url.
*
* @returns the root url.
*/
static QString root();
protected:
/**
* @brief setInitialState
*
* @details Creates the initial state information that is set in the html file, this includes
* information such as settings as well as information about the current regular expression.
*
* @param[in] fileContent is the html file content which the initial state is to be added to.
* @param[in] requestUrl is the URL, the html is avaialble on multiple endpoints and this parameter
* is used to populate the initial state correctly.
*
* @returns the modified html file ready to be served.
*/
QString setInitialState(QString fileContent, QUrl requestUrl);
private:
QString m_resourceRootFolder; //! string that contains the root folder where web is served from
QString m_injectedJavascript; //! string that contains the javascript to replace storage and fetch apis
};
}
#endif // REGEXURLSCHEMEHANDLER_H