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>
|
2012-04-11 17:23:25 +04:00
|
|
|
#include <QWebFrame>
|
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;
|
2012-05-12 04:32:16 +04:00
|
|
|
class WebpageCallbacks;
|
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
|
|
|
|
2012-12-29 20:23:10 +04:00
|
|
|
class WebPage : public QObject, public QWebFrame::PrintCallback
|
2011-04-08 17:30:50 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2012-09-26 04:09:32 +04:00
|
|
|
Q_PROPERTY(QString title READ title)
|
|
|
|
Q_PROPERTY(QString frameTitle READ frameTitle)
|
2011-05-25 21:46:51 +04:00
|
|
|
Q_PROPERTY(QString content READ content WRITE setContent)
|
2012-09-06 08:14:59 +04:00
|
|
|
Q_PROPERTY(QString frameContent READ frameContent WRITE setFrameContent)
|
|
|
|
Q_PROPERTY(QString url READ url)
|
|
|
|
Q_PROPERTY(QString frameUrl READ frameUrl)
|
2013-02-23 02:41:01 +04:00
|
|
|
Q_PROPERTY(bool loading READ loading)
|
|
|
|
Q_PROPERTY(int loadingProgress READ loadingProgress)
|
2012-09-27 02:08:55 +04:00
|
|
|
Q_PROPERTY(bool canGoBack READ canGoBack)
|
|
|
|
Q_PROPERTY(bool canGoForward READ canGoForward)
|
2012-02-15 16:52:57 +04:00
|
|
|
Q_PROPERTY(QString plainText READ plainText)
|
2012-09-06 08:14:59 +04:00
|
|
|
Q_PROPERTY(QString framePlainText READ framePlainText)
|
2011-06-18 07:17:58 +04:00
|
|
|
Q_PROPERTY(QString libraryPath READ libraryPath WRITE setLibraryPath)
|
2012-05-19 17:04:01 +04:00
|
|
|
Q_PROPERTY(QString offlineStoragePath READ offlineStoragePath)
|
|
|
|
Q_PROPERTY(int offlineStorageQuota READ offlineStorageQuota)
|
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)
|
2012-06-15 10:51:42 +04:00
|
|
|
Q_PROPERTY(bool navigationLocked READ navigationLocked WRITE setNavigationLocked)
|
2012-02-19 12:46:08 +04:00
|
|
|
Q_PROPERTY(QVariantMap customHeaders READ customHeaders WRITE setCustomHeaders)
|
2012-06-01 18:06:48 +04:00
|
|
|
Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
|
2012-06-14 11:43:20 +04:00
|
|
|
Q_PROPERTY(QVariantList cookies READ cookies WRITE setCookies)
|
2012-07-05 04:21:15 +04:00
|
|
|
Q_PROPERTY(QString windowName READ windowName)
|
|
|
|
Q_PROPERTY(QObjectList pages READ pages)
|
|
|
|
Q_PROPERTY(QStringList pagesWindowName READ pagesWindowName)
|
2012-07-27 20:13:43 +04:00
|
|
|
Q_PROPERTY(bool ownsPages READ ownsPages WRITE setOwnsPages)
|
2012-07-12 04:38:45 +04:00
|
|
|
Q_PROPERTY(QStringList framesName READ framesName)
|
|
|
|
Q_PROPERTY(QString frameName READ frameName)
|
|
|
|
Q_PROPERTY(int framesCount READ framesCount)
|
2012-09-16 20:57:56 +04:00
|
|
|
Q_PROPERTY(QString focusedFrameName READ focusedFrameName)
|
2011-05-25 21:46:51 +04:00
|
|
|
|
2011-04-08 17:30:50 +04:00
|
|
|
public:
|
2012-07-05 04:21:15 +04:00
|
|
|
WebPage(QObject *parent, const QUrl &baseUrl = QUrl());
|
2012-07-25 03:10:23 +04:00
|
|
|
virtual ~WebPage();
|
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;
|
2012-09-06 08:14:59 +04:00
|
|
|
QString frameContent() const;
|
2011-05-25 21:46:51 +04:00
|
|
|
void setContent(const QString &content);
|
2012-09-06 08:14:59 +04:00
|
|
|
void setFrameContent(const QString &content);
|
|
|
|
|
2012-09-26 04:09:32 +04:00
|
|
|
QString title() const;
|
|
|
|
QString frameTitle() const;
|
|
|
|
|
2012-09-06 08:14:59 +04:00
|
|
|
QString url() const;
|
|
|
|
QString frameUrl() const;
|
2011-05-25 21:46:51 +04:00
|
|
|
|
2013-02-23 02:41:01 +04:00
|
|
|
bool loading() const;
|
|
|
|
int loadingProgress() const;
|
|
|
|
|
2012-02-15 16:52:57 +04:00
|
|
|
QString plainText() const;
|
2012-09-06 08:14:59 +04:00
|
|
|
QString framePlainText() const;
|
2012-02-15 16:52:57 +04:00
|
|
|
|
2011-06-18 07:17:58 +04:00
|
|
|
QString libraryPath() const;
|
|
|
|
void setLibraryPath(const QString &dirPath);
|
2011-06-08 02:22:41 +04:00
|
|
|
|
2012-05-19 17:04:01 +04:00
|
|
|
QString offlineStoragePath() const;
|
|
|
|
|
|
|
|
int offlineStorageQuota() const;
|
|
|
|
|
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;
|
|
|
|
|
2012-06-15 10:51:42 +04:00
|
|
|
void setNavigationLocked(bool lock);
|
|
|
|
bool navigationLocked();
|
|
|
|
|
2012-02-19 12:46:08 +04:00
|
|
|
void setCustomHeaders(const QVariantMap &headers);
|
|
|
|
QVariantMap customHeaders() const;
|
|
|
|
|
2011-10-25 23:16:25 +04:00
|
|
|
void showInspector(const int remotePort = -1);
|
|
|
|
|
2012-04-11 17:23:25 +04:00
|
|
|
QString footer(int page, int numPages);
|
|
|
|
qreal footerHeight() const;
|
|
|
|
QString header(int page, int numPages);
|
|
|
|
qreal headerHeight() const;
|
|
|
|
|
2012-06-01 18:06:48 +04:00
|
|
|
void setZoomFactor(qreal zoom);
|
|
|
|
qreal zoomFactor() const;
|
|
|
|
|
2012-07-05 04:21:15 +04:00
|
|
|
/**
|
|
|
|
* Value of <code>"window.name"</code> within the main page frame.
|
|
|
|
*
|
|
|
|
* It's just a convenience method for
|
|
|
|
* <code>"page.evaluate('return window.name;')"</code>
|
|
|
|
*
|
|
|
|
* @brief windowName
|
|
|
|
* @return Returns the value of <code>'window.name'</code>
|
|
|
|
* within the current frame
|
|
|
|
*/
|
|
|
|
QString windowName() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of (Child) Pages that this page has currently open.
|
|
|
|
* A page opens chilp pages when using <code>"window.open()"</code>.
|
|
|
|
* If a child page spontaneously closes
|
|
|
|
* (i.e. a call to <code>"window.close()"<code>) or it's manually closed
|
|
|
|
* (i.e. "page.pages[i].release()"), the page is automatically removed by
|
|
|
|
* this array.
|
|
|
|
*
|
|
|
|
* NOTE: The ownership of this array is held by the Page: it's not adviced
|
|
|
|
* to have a "long running reference" to this array, as it might change.
|
2012-07-27 20:13:43 +04:00
|
|
|
* NOTE: If "ownsPages()" is "false", the page will create pages but not
|
|
|
|
* hold any ownership to it. Resource management is than left to the user.
|
2012-07-05 04:21:15 +04:00
|
|
|
*
|
|
|
|
* @brief pages
|
|
|
|
* @return List (JS Array) containing the Pages that this page
|
|
|
|
* has currently open.
|
|
|
|
*/
|
|
|
|
QObjectList pages() const;
|
|
|
|
/**
|
|
|
|
* Returns a list of (Child) Pages <code>"window.name"</code>.
|
|
|
|
*
|
|
|
|
* NOTE: When a page is opened with <code>"window.open"</code>, a window
|
|
|
|
* <code>"name"</code> might be provided as second parameter.
|
|
|
|
* This provides a useful list of those.
|
2012-07-27 20:13:43 +04:00
|
|
|
* NOTE: If "ownsPages()" is "false", the page will create pages but not
|
|
|
|
* hold any ownership of it. Resource management is than left to the user.
|
2012-07-05 04:21:15 +04:00
|
|
|
*
|
|
|
|
* @brief pagesWindowName
|
|
|
|
* @return List (JS Array) containing the <code>'window.name'</code>(s) of
|
|
|
|
* Pages that this page has currently open.
|
|
|
|
*/
|
|
|
|
QStringList pagesWindowName() const;
|
|
|
|
|
2012-07-27 20:13:43 +04:00
|
|
|
/**
|
|
|
|
* Returns "true" if it owns the pages it creates (and keeps them in "pages[]").
|
|
|
|
* Default value is "true". Can be changed using {@link setOwnsPages()}.
|
|
|
|
*
|
|
|
|
* @brief ownsPages()
|
|
|
|
* @return "true" if it owns the pages it creates in "pages[]", "false" otherwise.
|
|
|
|
*/
|
|
|
|
bool ownsPages() const;
|
|
|
|
/**
|
|
|
|
* Set if, from now on, it should own the pages it creates in "pages[]".
|
|
|
|
* Default value is "true".
|
|
|
|
*
|
|
|
|
* NOTE: When switching from "false" to "true", only the pages created
|
|
|
|
* from that point on will be owned. It's NOT retroactive.
|
|
|
|
*
|
|
|
|
* @brief setOwnsPages
|
|
|
|
* @param owns "true" to make it own the pages it creates in "pages[]", "false" otherwise.
|
|
|
|
*/
|
|
|
|
void setOwnsPages(const bool owns);
|
|
|
|
|
2012-07-12 04:38:45 +04:00
|
|
|
/**
|
|
|
|
* Returns the number of Child Frames inside the Current Frame.
|
|
|
|
* NOTE: The Current Frame changes when focus moves (via API or JS) to a specific child frame.
|
|
|
|
*
|
|
|
|
* @brief framesCount
|
|
|
|
* @return Number of Frames inside the Current Frame
|
|
|
|
*/
|
|
|
|
int framesCount() const;
|
|
|
|
/**
|
|
|
|
* Returns a list of (Child) Frames name.
|
|
|
|
* NOTE: The Current Frame changes when focus moves (via API or JS) to a specific child frame.
|
|
|
|
*
|
|
|
|
* @brief framesName
|
|
|
|
* @return List (JS Array) containing the names of the Child Frames inside the Current Frame (if any)
|
|
|
|
*/
|
|
|
|
QStringList framesName() const;
|
|
|
|
/**
|
|
|
|
* Returns the name of the (Current) Frame
|
|
|
|
*
|
|
|
|
* @brief frameName
|
|
|
|
* @return Name of the Current Frame
|
|
|
|
*/
|
|
|
|
QString frameName() const;
|
2012-09-16 20:57:56 +04:00
|
|
|
/**
|
|
|
|
* Returns the currently focused Frame's name.
|
|
|
|
*
|
|
|
|
* @brief focusedFrameName
|
|
|
|
* @return Frame
|
|
|
|
*/
|
|
|
|
QString focusedFrameName() const;
|
2012-07-12 04:38:45 +04:00
|
|
|
|
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();
|
2012-07-25 03:10:23 +04:00
|
|
|
void close();
|
2011-08-24 05:53:53 +04:00
|
|
|
|
2012-04-11 10:52:56 +04:00
|
|
|
QVariant evaluateJavaScript(const QString &code);
|
2013-01-10 08:07:32 +04:00
|
|
|
bool render(const QString &fileName, const QVariantMap &map = QVariantMap());
|
2012-06-18 05:22:43 +04:00
|
|
|
/**
|
|
|
|
* Render the page as base-64 encoded string.
|
|
|
|
* Default image format is "png".
|
|
|
|
*
|
|
|
|
* To choose a different format, pass a string with it's name.
|
|
|
|
* Available formats are the one supported by Qt QImageWriter class:
|
|
|
|
* @link http://qt-project.org/doc/qt-4.8/qimagewriter.html#supportedImageFormats.
|
|
|
|
*
|
|
|
|
* @brief renderBase64
|
|
|
|
* @param format String containing one of the supported types
|
|
|
|
* @return Rendering base-64 encoded of the page if the given format is supported, otherwise an empty string
|
|
|
|
*/
|
|
|
|
QString renderBase64(const QByteArray &format = "png");
|
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);
|
2012-05-12 04:32:16 +04:00
|
|
|
QObject *_getGenericCallback();
|
2012-10-29 04:30:23 +04:00
|
|
|
QObject *_getFilePickerCallback();
|
2012-05-12 04:32:16 +04:00
|
|
|
QObject *_getJsConfirmCallback();
|
|
|
|
QObject *_getJsPromptCallback();
|
2012-12-09 14:52:52 +04:00
|
|
|
void _uploadFile(const QString &selector, const QStringList &fileNames);
|
2012-10-23 22:11:26 +04:00
|
|
|
void sendEvent(const QString &type, const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), const QString &mouseButton = QString(), const QVariant &modifierArg = QVariant());
|
2011-06-05 11:28:14 +04:00
|
|
|
|
2012-12-07 21:54:55 +04:00
|
|
|
void setContent(const QString &content, const QString &baseUrl);
|
2012-07-05 04:21:15 +04:00
|
|
|
/**
|
|
|
|
* Returns a Child Page that matches the given <code>"window.name"</code>.
|
|
|
|
* This utility method is faster than accessing the
|
|
|
|
* <code>"windowName"</code> property of every <code>"page.pages"</code>
|
|
|
|
* and try to match.
|
|
|
|
*
|
|
|
|
* @brief getPage
|
|
|
|
* @param windowName
|
|
|
|
* @return Returns the page that matches <code>'window.name'</code>,
|
|
|
|
* or NULL if none is found
|
|
|
|
*/
|
|
|
|
QObject *getPage(const QString &windowName) const;
|
|
|
|
|
2012-05-30 15:28:20 +04:00
|
|
|
/**
|
|
|
|
* Returns the number of Child Frames inside the Current Frame.
|
|
|
|
* NOTE: The Current Frame changes when focus moves (via API or JS) to a specific child frame.
|
2012-07-12 04:38:45 +04:00
|
|
|
*
|
|
|
|
* @deprecated
|
2012-05-30 15:28:20 +04:00
|
|
|
* @brief childFramesCount
|
|
|
|
* @return Number of Frames inside the Current Frame
|
|
|
|
*/
|
2012-07-05 04:21:15 +04:00
|
|
|
int childFramesCount() const;
|
2012-05-30 15:28:20 +04:00
|
|
|
/**
|
|
|
|
* Returns a list of Child Frames name.
|
|
|
|
* NOTE: The Current Frame changes when focus moves (via API or JS) to a specific child frame.
|
2012-07-12 04:38:45 +04:00
|
|
|
*
|
|
|
|
* @deprecated
|
2012-05-30 15:28:20 +04:00
|
|
|
* @brief childFramesName
|
|
|
|
* @return List (JS Array) containing the names of the Child Frames inside the Current Frame (if any)
|
|
|
|
*/
|
2012-07-05 04:21:15 +04:00
|
|
|
QStringList childFramesName() const;
|
2012-05-30 15:28:20 +04:00
|
|
|
/**
|
|
|
|
* Switches focus from the Current Frame to a Child Frame, identified by it's name.
|
2012-07-12 04:38:45 +04:00
|
|
|
*
|
|
|
|
* @brief switchToFrame
|
|
|
|
* @param frameName Name of the Child frame
|
|
|
|
* @return "true" if the frame was found, "false" otherwise
|
|
|
|
*/
|
|
|
|
bool switchToFrame(const QString &frameName);
|
|
|
|
/**
|
|
|
|
* Switches focus from the Current Frame to a Child Frame, identified by it's name.
|
|
|
|
*
|
|
|
|
* @deprecated
|
2012-05-30 15:28:20 +04:00
|
|
|
* @brief switchToChildFrame
|
|
|
|
* @param frameName Name of the Child frame
|
|
|
|
* @return "true" if the frame was found, "false" otherwise
|
|
|
|
*/
|
|
|
|
bool switchToChildFrame(const QString &frameName);
|
|
|
|
/**
|
|
|
|
* Switches focus from the Current Frame to a Child Frame, identified by it positional order.
|
2012-07-12 04:38:45 +04:00
|
|
|
*
|
|
|
|
* @brief switchToFrame
|
|
|
|
* @param framePosition Position of the Frame inside the Child Frames array (i.e. "window.frames[i]")
|
|
|
|
* @return "true" if the frame was found, "false" otherwise
|
|
|
|
*/
|
|
|
|
bool switchToFrame(const int framePosition);
|
|
|
|
/**
|
|
|
|
* Switches focus from the Current Frame to a Child Frame, identified by it positional order.
|
|
|
|
*
|
|
|
|
* @deprecated
|
2012-05-30 15:28:20 +04:00
|
|
|
* @brief switchToChildFrame
|
|
|
|
* @param framePosition Position of the Frame inside the Child Frames array (i.e. "window.frames[i]")
|
|
|
|
* @return "true" if the frame was found, "false" otherwise
|
|
|
|
*/
|
|
|
|
bool switchToChildFrame(const int framePosition);
|
|
|
|
/**
|
|
|
|
* Switches focus to the Main Frame within this Page.
|
2012-07-12 04:38:45 +04:00
|
|
|
*
|
2012-05-30 15:28:20 +04:00
|
|
|
* @brief switchToMainFrame
|
|
|
|
*/
|
|
|
|
void switchToMainFrame();
|
|
|
|
/**
|
|
|
|
* Switches focus to the Parent Frame of the Current Frame (if it exists).
|
2012-07-12 04:38:45 +04:00
|
|
|
*
|
2012-05-30 15:28:20 +04:00
|
|
|
* @brief switchToParentFrame
|
|
|
|
* @return "true" if the Current Frame is not a Main Frame, "false" otherwise (i.e. there is no parent frame to switch to)
|
|
|
|
*/
|
|
|
|
bool switchToParentFrame();
|
2012-09-16 20:57:56 +04:00
|
|
|
/**
|
|
|
|
* Switches to the currently focused frame, as per QWebPage. This is the frame whose
|
|
|
|
* window element was last focus()ed, and is currently the target of key events.
|
|
|
|
*
|
|
|
|
* @brief switchToFocusedFrame
|
|
|
|
*/
|
|
|
|
void switchToFocusedFrame();
|
2012-05-30 15:28:20 +04:00
|
|
|
/**
|
|
|
|
* Returns the name of the Current Frame (if it has one)
|
2012-07-12 04:38:45 +04:00
|
|
|
*
|
|
|
|
* @deprecated
|
2012-05-30 15:28:20 +04:00
|
|
|
* @brief currentFrameName
|
|
|
|
* @return Name of the Current Frame
|
|
|
|
*/
|
2012-07-05 04:21:15 +04:00
|
|
|
QString currentFrameName() const;
|
2012-05-30 15:28:20 +04:00
|
|
|
|
2012-09-06 10:33:18 +04:00
|
|
|
/**
|
|
|
|
* Allows to set cookies by this Page, at the current URL.
|
|
|
|
* This means that loading new URLs, causes the cookies to change dynamically
|
|
|
|
* as in a normal desktop browser.
|
|
|
|
*
|
|
|
|
* Cookies are expected in the format:
|
|
|
|
* <pre>
|
|
|
|
* {
|
|
|
|
* "name" : "cookie name (string)",
|
|
|
|
* "value" : "cookie value (string)",
|
|
|
|
* "domain" : "cookie domain (string)",
|
|
|
|
* "path" : "cookie path (string, optional)",
|
|
|
|
* "httponly" : "http only cookie (boolean, optional)",
|
|
|
|
* "secure" : "secure cookie (boolean, optional)",
|
|
|
|
* "expires" : "expiration date (string, GMT format, optional)"
|
|
|
|
* }
|
|
|
|
* </pre>
|
|
|
|
* @brief setCookies
|
|
|
|
* @param cookies Expects a QList of QVariantMaps
|
2012-09-09 15:24:15 +04:00
|
|
|
* @return Boolean "true" if at least 1 cookie was set
|
2012-09-06 10:33:18 +04:00
|
|
|
*/
|
2012-09-09 15:24:15 +04:00
|
|
|
bool setCookies(const QVariantList &cookies);
|
2012-09-06 10:33:18 +04:00
|
|
|
/**
|
|
|
|
* Cookies visible by this Page, at the current URL.
|
|
|
|
*
|
|
|
|
* @see WebPage::setCookies for details on the format
|
|
|
|
* @brief cookies
|
|
|
|
* @return QList of QVariantMap cookies visible to this Page, at the current URL.
|
|
|
|
*/
|
2012-06-14 11:43:20 +04:00
|
|
|
QVariantList cookies() const;
|
2012-09-06 10:33:18 +04:00
|
|
|
/**
|
|
|
|
* Add a Cookie in QVariantMap format
|
|
|
|
* @see WebPage::setCookies for details on the format
|
|
|
|
* @brief addCookie
|
|
|
|
* @param cookie Cookie in QVariantMap format
|
2012-09-09 15:24:15 +04:00
|
|
|
* @return Boolean "true" if cookie was added
|
2012-09-06 10:33:18 +04:00
|
|
|
*/
|
2012-09-09 15:24:15 +04:00
|
|
|
bool addCookie(const QVariantMap &cookie);
|
2012-09-06 10:33:18 +04:00
|
|
|
/**
|
|
|
|
* Delete cookie by name from the ones visible by this Page, at the current URL
|
|
|
|
* @brief deleteCookie
|
|
|
|
* @param cookieName Name of the Cookie to delete
|
2012-09-09 15:24:15 +04:00
|
|
|
* @return Boolean "true" if cookie was deleted
|
2012-09-06 10:33:18 +04:00
|
|
|
*/
|
2012-09-09 15:24:15 +04:00
|
|
|
bool deleteCookie(const QString &cookieName);
|
2012-09-06 10:33:18 +04:00
|
|
|
/**
|
|
|
|
* Delete All Cookies visible by this Page, at the current URL
|
|
|
|
* @brief clearCookies
|
2012-09-09 15:24:15 +04:00
|
|
|
* @return Boolean "true" if cookies were deleted
|
2012-09-06 10:33:18 +04:00
|
|
|
*/
|
2012-09-09 15:24:15 +04:00
|
|
|
bool clearCookies();
|
2012-06-14 11:43:20 +04:00
|
|
|
|
2012-09-27 02:08:55 +04:00
|
|
|
/**
|
|
|
|
* Checks if this Page can go back in the Navigation History
|
|
|
|
* @brief canGoBack
|
|
|
|
* @return "true" if it can, "false" otherwise
|
|
|
|
*/
|
|
|
|
bool canGoBack();
|
|
|
|
/**
|
|
|
|
* Goes back in the Navigation History
|
2012-11-18 04:08:54 +04:00
|
|
|
* @brief goBack
|
2012-09-27 02:08:55 +04:00
|
|
|
* @return "true" if it does go back in the Navigation History, "false" otherwise
|
|
|
|
*/
|
2012-11-18 04:08:54 +04:00
|
|
|
bool goBack();
|
2012-09-27 02:08:55 +04:00
|
|
|
/**
|
|
|
|
* Checks if this Page can go forward in the Navigation History (i.e. next URL)
|
|
|
|
* @brief canGoForward
|
|
|
|
* @return "true" if it can, "false" otherwise
|
|
|
|
*/
|
|
|
|
bool canGoForward();
|
|
|
|
/**
|
|
|
|
* Goes forward in the Navigation History
|
2012-11-18 04:08:54 +04:00
|
|
|
* @brief goForward
|
2012-09-27 02:08:55 +04:00
|
|
|
* @return "true" if it does go forward in the Navigation History, "false" otherwise
|
|
|
|
*/
|
2012-11-18 04:08:54 +04:00
|
|
|
bool goForward();
|
|
|
|
/**
|
|
|
|
* Go to the page identified by its relative location to the current page.
|
|
|
|
* For example '-1' for the previous page or 1 for the next page.
|
|
|
|
*
|
|
|
|
* Modelled after JavaScript "window.go(num)" method:
|
|
|
|
* {@see https://developer.mozilla.org/en-US/docs/DOM/window.history#Syntax}.
|
|
|
|
* @brief go
|
|
|
|
* @param historyRelativeIndex
|
|
|
|
* @return "true" if it does go forward/backgward in the Navigation History, "false" otherwise
|
|
|
|
*/
|
|
|
|
bool go(int historyRelativeIndex);
|
2012-09-27 02:08:55 +04:00
|
|
|
/**
|
|
|
|
* Reload current page
|
|
|
|
* @brief reload
|
|
|
|
*/
|
|
|
|
void reload();
|
|
|
|
/**
|
|
|
|
* Stop loading page (if the page is loading)
|
|
|
|
*
|
|
|
|
* NOTE: This method does nothing when page is not actually loading.
|
|
|
|
* It's effect can be applied in that very short window of time between
|
|
|
|
* "onLoadStarted" and "onLoadFinished".
|
|
|
|
*
|
|
|
|
* @brief stop
|
|
|
|
*/
|
|
|
|
void stop();
|
|
|
|
|
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);
|
2012-03-19 02:22:02 +04:00
|
|
|
void javaScriptConsoleMessageSent(const QString &message);
|
2012-06-16 22:44:43 +04:00
|
|
|
void javaScriptErrorSent(const QString &msg, const QString &stack);
|
2013-01-02 15:41:56 +04:00
|
|
|
void resourceRequested(const QVariant &requestData, QObject *request);
|
2011-06-08 12:01:30 +04:00
|
|
|
void resourceReceived(const QVariant &resource);
|
2013-01-18 12:37:22 +04:00
|
|
|
void resourceError(const QVariant &errorData);
|
2012-06-15 10:51:42 +04:00
|
|
|
void urlChanged(const QUrl &url);
|
|
|
|
void navigationRequested(const QUrl &url, const QString &navigationType, bool navigationLocked, bool isMainFrame);
|
2012-07-05 04:21:15 +04:00
|
|
|
void rawPageCreated(QObject *page);
|
2012-07-25 03:10:23 +04:00
|
|
|
void closing(QObject *page);
|
2011-04-08 17:30:50 +04:00
|
|
|
|
2011-05-25 21:46:51 +04:00
|
|
|
private slots:
|
|
|
|
void finish(bool ok);
|
2012-09-26 12:56:27 +04:00
|
|
|
void setupFrame(QWebFrame *frame = NULL);
|
2013-02-23 02:41:01 +04:00
|
|
|
void updateLoadingProgress(int progress);
|
2011-04-08 17:30:50 +04:00
|
|
|
|
A REPL for PhantomJS
This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252)
The commit is composed of 12 squashed commits:
commit efdc6ba4f143c30a690fd97d92d80fa412e79999
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Mon Feb 27 00:19:36 2012 +0000
Pretty-pringing and Completion Caching done!
* This completes pretty-printing for the result of evaluated
* expressions in the REPL.
* Also, now we cache the "possible completions", to speed things up
* a bit (nothing fancy though).
* Minor tweaks to the internal doc and the way we "mock"
* pretty-printing for QObjects/REPLCompletanle
* All tests passing :)
commit 1f9ef690e112a535b431fca409b77bb9c09d1c70
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Sun Feb 26 22:35:00 2012 +0000
Moving most of REPL shim JavaScritp code in a separate file. Way
easier to work on.
commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Sat Feb 25 20:25:18 2012 +0000
Initialisation of the Completions is now done in a pure virtual.
This means that every REPLCompletable object will ACTUALLY register
completion strings, ONLY if we are running a REPL
and that object is ACTUALLY created.
Otherwise, why bother?
Adding completions for all exposed REPLCompletable objects
Also, fixed an issue with _getCompletions()
commit 412c3778fb04aa1c7379f8e760afce702b0428dd
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Tue Feb 21 00:49:17 2012 +0000
Few more tweaks to the REPL:
- Now 'phantom' is the first QObject with proper completion
- No repetition in QObject completions
- LVAL of any user expression is now correctly prettified and
printed
Major things left to do:
- Cache completions (using QCache?)
- Add completions for the other QObject
- When the LVAL of a user expression is a QObject, print what's
expected, not the QObject "real" structure
commit 46f04713c8165d898055e15478bb31403f8c93f1
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Tue Feb 7 10:13:23 2012 -0800
Pretty-print expressions result
Still not done though: there are issues with the NON-Native JS
objects.
commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Fri Feb 3 00:22:52 2012 -0800
Introducing REPLCompletable.
This class should be inherited by any JavaScript-exposed QObject, to
ensure correct Auto-Completion.
Correct auto-completion for QObjects.
- Now even QObjects can correctly provide auto-completion, and avoid
showing "not for users" methods
- The strings used for the auto-completion are stored in a single
Index: minimum memory footprint
- Still, there is optimization that should be done (when "searching"
for the right completion by prefix)
- Completion for the objects not set up yet, but now it's just a
trivial sequence of "addCompletion('bla')" in their constructors
commit 9bd48618154b1530a37b41f4060440184e23253d
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Thu Feb 2 00:20:25 2012 -0800
Changing the way we import Linenoise.
Will just import a specific commit, and update manually when needed.
commit cfc9bae9fbdab13b01019b34b7cbd565e3153780
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Sun Jan 29 23:22:26 2012 -0800
Made the REPL into a Singleton. With Auto-completion!.
Reasons:
1) Needed a pointer to function (i.e. a static method) to be used
with Linenoise to provide auto-completions
2) It makes more sense, as it's not like we are going to have 2 REPL
running at the same time, are we?
There are problems to address:
- the enumeration in JS seems to return only the native interface of
our objects
- the function completions contain argument types of those functions
- "private" methods are exposed
commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Sun Jan 29 22:10:20 2012 -0800
Migrating from the original, now [unmantained
Linenoise](https://github.com/antirez/linenoise) to the fairly active
[tadmarshall fork](https://github.com/tadmarshall/linenoise).
Also now the project is imported as a Git Submodule.
Having migrated to the latest Linenoise (see prev. commit), now this
_SHOULD_ work on Windows too.
But, of course, this needs testing. :)
commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Tue Jan 24 23:17:06 2012 -0800
Now that the basics work, I'm adding support for REPL history.
This is something almost everyone today is accustomed to.
Also, now REPL history works!
And I found some useful resources to solve pending TODOs.
commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Sun Jan 22 20:56:36 2012 -0800
Adding Linenoise Project (https://github.com/antirez/linenoise).
For now is included as a drop-in set of files.
Later on, if the Linenoise project has frequent
updates, we might prefer to do it as a
git-submodule.
commit 4be9c15c65db4767e482fba0be13f8aab286d5f3
Author: Ivan De Marino <ivan.de.marino@gmail.com>
Date: Thu Jan 5 15:31:13 2012 +0000
First simple REPL implementation.
- Not complete
- Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
|
|
|
private:
|
|
|
|
QImage renderImage();
|
|
|
|
bool renderPdf(const QString &fileName);
|
|
|
|
void applySettings(const QVariantMap &defaultSettings);
|
|
|
|
QString userAgent() const;
|
|
|
|
|
2012-09-16 20:57:56 +04:00
|
|
|
/**
|
|
|
|
* Switches focus from the Current Frame to the Child Frame, identified by `frame`.
|
|
|
|
*
|
|
|
|
* @brief changeCurrentFrame
|
|
|
|
* @param frame The Child frame
|
|
|
|
*/
|
|
|
|
void changeCurrentFrame(QWebFrame * const frame);
|
|
|
|
|
2012-10-29 04:30:23 +04:00
|
|
|
QString filePicker(const QString &oldFile);
|
2012-05-12 04:32:16 +04:00
|
|
|
bool javaScriptConfirm(const QString &msg);
|
|
|
|
bool javaScriptPrompt(const QString &msg, const QString &defaultValue, QString *result);
|
|
|
|
|
2011-04-08 17:30:50 +04:00
|
|
|
private:
|
2012-07-05 04:21:15 +04:00
|
|
|
CustomPage *m_customWebPage;
|
2011-09-17 04:34:02 +04:00
|
|
|
NetworkAccessManager *m_networkAccessManager;
|
2011-05-25 21:46:51 +04:00
|
|
|
QWebFrame *m_mainFrame;
|
2012-09-16 20:57:56 +04:00
|
|
|
QWebFrame *m_currentFrame;
|
2011-05-25 21:46:51 +04:00
|
|
|
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;
|
2012-05-12 04:32:16 +04:00
|
|
|
WebpageCallbacks *m_callbacks;
|
2012-06-15 10:51:42 +04:00
|
|
|
bool m_navigationLocked;
|
2012-07-05 04:21:15 +04:00
|
|
|
QPoint m_mousePos;
|
2012-07-27 20:13:43 +04:00
|
|
|
bool m_ownsPages;
|
2013-02-23 02:41:01 +04:00
|
|
|
int m_loadingProgress;
|
2011-05-25 21:46:51 +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-04-08 17:30:50 +04:00
|
|
|
};
|
2011-04-09 22:49:22 +04:00
|
|
|
|
|
|
|
#endif // WEBPAGE_H
|