-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathManagedPage.h
More file actions
101 lines (88 loc) · 3.39 KB
/
ManagedPage.h
File metadata and controls
101 lines (88 loc) · 3.39 KB
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
#ifndef MANAGED_PAGE_H
#define MANAGED_PAGE_H
#include <QWebPage>
#include <QString>
#include <QMap>
#include "EventAwareWidget.h"
class ManagedPage : public QWebPage {
private:
GTKControl *item;
public:
QMap<int, bool> responses;
bool ignoreNext;
QString userAgent;
ManagedPage(GTKControl *obj, QWidget *parent) : QWebPage(parent) {
item = obj;
ignoreNext = false;
}
QString userAgentForUrl(const QUrl& url) const {
if (userAgent.size())
return userAgent;
return QWebPage::userAgentForUrl(url);
}
virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest& request, NavigationType type) {
QUrl url = request.url();
if ((item->type == 1012) && (EVENT_REGISTERED(360))) {
QString surl = url.toString();
if (url.isLocalFile()) {
if (surl.indexOf(QString("file:///static/")) == 0)
surl = surl.remove(0, 15);
}
NOTIFY_EVENT(360, (char *)surl.toUtf8().constData());
if (responses.contains(360)) {
if (!responses[360])
return QWebPage::acceptNavigationRequest(frame, request, type);
return false;
}
} else
if ((item->type == 1001) && (EVENT_REGISTERED(350))) {
if (ignoreNext) {
ignoreNext = false;
return QWebPage::acceptNavigationRequest(frame, request, type);
}
QString surl = url.toString();
if (url.isLocalFile()) {
if (surl.indexOf(QString("file:///static/")) == 0)
surl = surl.remove(0, 15);
}
NOTIFY_EVENT(350, (char *)surl.toUtf8().constData());
if (responses.contains(350)) {
if (!responses[350])
return QWebPage::acceptNavigationRequest(frame, request, type);
return false;
}
} else {
if (responses.contains(360)) {
if (!responses[360])
return QWebPage::acceptNavigationRequest(frame, request, type);
return false;
}
}
return QWebPage::acceptNavigationRequest(frame, request, type);
}
virtual void javaScriptConsoleMessage(const QString& message, int lineNumber, const QString& sourceID) {
if (item->type == 1012) {
NOTIFY_EVENT(350, (char *)message.toUtf8().constData());
}
QWebPage::javaScriptConsoleMessage(message, lineNumber, sourceID);
}
virtual bool javaScriptPrompt(QWebFrame *frame, const QString& msg, const QString& defaultValue, QString *result) {
NOTIFY_EVENT(369, (char *)msg.toUtf8().constData());
if (responses.contains(369))
return responses[369];
return QWebPage::javaScriptPrompt(frame, msg, defaultValue, result);
}
virtual bool javaScriptConfirm(QWebFrame *frame, const QString& msg) {
NOTIFY_EVENT(370, (char *)msg.toUtf8().constData());
if (responses.contains(370))
return responses[370];
return QWebPage::javaScriptConfirm(frame, msg);
}
virtual void javaScriptAlert(QWebFrame *frame, const QString& msg) {
NOTIFY_EVENT(363, (char *)msg.toUtf8().constData());
QWebPage::javaScriptAlert(frame, msg);
}
~ManagedPage() {
}
};
#endif