2011-04-09 21:34:04 +04:00
|
|
|
/*
|
|
|
|
This file is part of the PhantomJS project from Ofi Labs.
|
|
|
|
|
|
|
|
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
2011-08-31 19:29:40 +04:00
|
|
|
Copyright (C) 2011 Ivan De Marino <ivan.de.marino@gmail.com>
|
2011-04-09 21:34:04 +04:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the <organization> nor the
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2011-04-09 22:49:22 +04:00
|
|
|
#ifndef WEBPAGE_H
|
|
|
|
#define WEBPAGE_H
|
|
|
|
|
2011-05-25 21:46:51 +04:00
|
|
|
#include <QMap>
|
|
|
|
#include <QVariantMap>
|
2011-09-15 08:41:26 +04:00
|
|
|
#include <QWebPage>
|
2011-04-08 17:30:50 +04:00
|
|
|
|
2011-09-15 10:46:01 +04:00
|
|
|
class Config;
|
2011-05-25 21:46:51 +04:00
|
|
|
class CustomPage;
|
2011-09-17 04:34:02 +04:00
|
|
|
class NetworkAccessManager;
|
2011-10-25 23:16:25 +04:00
|
|
|
class QWebInspector;
|
2011-05-28 07:37:36 +04:00
|
|
|
class Phantom;
|
2011-05-25 21:46:51 +04:00
|
|
|
|
|
|
|
class WebPage: public QObject
|
2011-04-08 17:30:50 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2011-05-25 21:46:51 +04:00
|
|
|
Q_PROPERTY(QString content READ content WRITE setContent)
|
2012-02-15 16:52:57 +04:00
|
|
|
Q_PROPERTY(QString plainText READ plainText)
|
2011-06-18 07:17:58 +04:00
|
|
|
Q_PROPERTY(QString libraryPath READ libraryPath WRITE setLibraryPath)
|
2011-05-25 21:46:51 +04:00
|
|
|
Q_PROPERTY(QVariantMap viewportSize READ viewportSize WRITE setViewportSize)
|
|
|
|
Q_PROPERTY(QVariantMap paperSize READ paperSize WRITE setPaperSize)
|
|
|
|
Q_PROPERTY(QVariantMap clipRect READ clipRect WRITE setClipRect)
|
2011-07-22 12:11:30 +04:00
|
|
|
Q_PROPERTY(QVariantMap scrollPosition READ scrollPosition WRITE setScrollPosition)
|
2011-05-25 21:46:51 +04:00
|
|
|
|
2011-04-08 17:30:50 +04:00
|
|
|
public:
|
2012-02-13 21:47:09 +04:00
|
|
|
WebPage(QObject *parent, const Config *config, const QUrl &baseUrl = QUrl());
|
2011-04-08 17:30:50 +04:00
|
|
|
|
2011-05-26 01:00:20 +04:00
|
|
|
QWebFrame *mainFrame();
|
|
|
|
|
2011-05-25 21:46:51 +04:00
|
|
|
QString content() const;
|
|
|
|
void setContent(const QString &content);
|
|
|
|
|
2012-02-15 16:52:57 +04:00
|
|
|
QString plainText() const;
|
|
|
|
|
2011-06-18 07:17:58 +04:00
|
|
|
QString libraryPath() const;
|
|
|
|
void setLibraryPath(const QString &dirPath);
|
2011-06-08 02:22:41 +04:00
|
|
|
|
2011-05-25 21:46:51 +04:00
|
|
|
void setViewportSize(const QVariantMap &size);
|
|
|
|
QVariantMap viewportSize() const;
|
|
|
|
|
|
|
|
void setClipRect(const QVariantMap &size);
|
|
|
|
QVariantMap clipRect() const;
|
|
|
|
|
2011-07-22 12:11:30 +04:00
|
|
|
void setScrollPosition(const QVariantMap &size);
|
|
|
|
QVariantMap scrollPosition() const;
|
|
|
|
|
2011-05-25 21:46:51 +04:00
|
|
|
void setPaperSize(const QVariantMap &size);
|
|
|
|
QVariantMap paperSize() const;
|
|
|
|
|
2011-10-25 23:16:25 +04:00
|
|
|
void showInspector(const int remotePort = -1);
|
|
|
|
|
2011-04-08 17:30:50 +04:00
|
|
|
public slots:
|
2011-05-28 12:38:11 +04:00
|
|
|
void openUrl(const QString &address, const QVariant &op, const QVariantMap &settings);
|
2011-08-24 05:53:53 +04:00
|
|
|
void release();
|
|
|
|
|
2011-05-25 21:46:51 +04:00
|
|
|
QVariant evaluate(const QString &code);
|
|
|
|
bool render(const QString &fileName);
|
2011-06-08 02:22:41 +04:00
|
|
|
bool injectJs(const QString &jsFilePath);
|
2011-06-09 19:11:39 +04:00
|
|
|
void _appendScriptElement(const QString &scriptUrl);
|
2011-06-05 11:28:14 +04:00
|
|
|
void uploadFile(const QString &selector, const QString &fileName);
|
2011-09-16 18:15:21 +04:00
|
|
|
void sendEvent(const QString &type, const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant());
|
2011-06-05 11:28:14 +04:00
|
|
|
|
2011-05-25 21:46:51 +04:00
|
|
|
signals:
|
2011-08-21 04:56:18 +04:00
|
|
|
void initialized();
|
2011-06-06 12:22:32 +04:00
|
|
|
void loadStarted();
|
2011-06-06 12:31:37 +04:00
|
|
|
void loadFinished(const QString &status);
|
2011-05-29 11:29:29 +04:00
|
|
|
void javaScriptAlertSent(const QString &msg);
|
2011-06-20 08:06:27 +04:00
|
|
|
void javaScriptConsoleMessageSent(const QString &message, int lineNumber, const QString &source);
|
2011-06-07 10:56:23 +04:00
|
|
|
void resourceRequested(const QVariant &req);
|
2011-06-08 12:01:30 +04:00
|
|
|
void resourceReceived(const QVariant &resource);
|
2011-04-08 17:30:50 +04:00
|
|
|
|
2011-05-25 21:46:51 +04:00
|
|
|
private slots:
|
|
|
|
void finish(bool ok);
|
2011-04-08 17:30:50 +04:00
|
|
|
|
|
|
|
private:
|
2011-05-25 21:46:51 +04:00
|
|
|
CustomPage *m_webPage;
|
2011-09-17 04:34:02 +04:00
|
|
|
NetworkAccessManager *m_networkAccessManager;
|
2011-05-25 21:46:51 +04:00
|
|
|
QWebFrame *m_mainFrame;
|
|
|
|
QRect m_clipRect;
|
2011-07-22 12:11:30 +04:00
|
|
|
QPoint m_scrollPosition;
|
2011-05-25 21:46:51 +04:00
|
|
|
QVariantMap m_paperSize; // For PDF output via render()
|
2011-06-18 07:17:58 +04:00
|
|
|
QString m_libraryPath;
|
2011-10-25 23:16:25 +04:00
|
|
|
QWebInspector* m_inspector;
|
2011-05-25 21:46:51 +04:00
|
|
|
|
2011-05-29 00:51:39 +04:00
|
|
|
QImage renderImage();
|
2011-05-25 21:46:51 +04:00
|
|
|
bool renderPdf(const QString &fileName);
|
2011-05-28 09:36:34 +04:00
|
|
|
void applySettings(const QVariantMap &defaultSettings);
|
2011-05-28 09:50:33 +04:00
|
|
|
QString userAgent() const;
|
2011-05-28 07:37:36 +04:00
|
|
|
|
2011-05-29 11:29:29 +04:00
|
|
|
void emitAlert(const QString &msg);
|
2011-06-20 08:06:27 +04:00
|
|
|
void emitConsoleMessage(const QString &msg, int lineNumber, const QString &source);
|
2011-05-29 08:16:18 +04:00
|
|
|
|
2011-05-28 07:37:36 +04:00
|
|
|
friend class Phantom;
|
2011-05-29 08:16:18 +04:00
|
|
|
friend class CustomPage;
|
2011-08-21 09:34:11 +04:00
|
|
|
|
2011-08-07 17:29:50 +04:00
|
|
|
QPoint m_mousePos;
|
2011-04-08 17:30:50 +04:00
|
|
|
};
|
2011-04-09 22:49:22 +04:00
|
|
|
|
|
|
|
#endif // WEBPAGE_H
|