Qt 4.8
Classes | Macros | Functions
qdeclarativexmlhttprequest.cpp File Reference
#include "private/qdeclarativexmlhttprequest_p.h"
#include "qdeclarativeengine.h"
#include "private/qdeclarativeengine_p.h"
#include "private/qdeclarativerefcount_p.h"
#include "private/qdeclarativeexpression_p.h"
#include "qdeclarativeglobal_p.h"
#include <QtCore/qobject.h>
#include <QtScript/qscriptvalue.h>
#include <QtScript/qscriptcontext.h>
#include <QtScript/qscriptengine.h>
#include <QtNetwork/qnetworkreply.h>
#include <QtCore/qtextcodec.h>
#include <QtCore/qxmlstream.h>
#include <QtCore/qstack.h>
#include <QtCore/qdebug.h>
#include <QtCore/QStringBuilder>
#include <qdeclarativexmlhttprequest.moc>

Go to the source code of this file.

Classes

class  Attr
 
class  CDATA
 
class  CharacterData
 
class  Document
 
class  DocumentImpl
 
class  Element
 
class  NamedNodeMap
 
class  NamedNodeMapClass
 
class  Node
 
class  NodeImpl
 
class  NodeList
 
class  NodeListClass
 
class  QDeclarativeXMLHttpRequest
 
class  Text
 The Text item allows you to add formatted text to a scene. More...
 

Macros

#define A(arg)   (arg)->addref()
 
#define D(arg)   (arg)->release()
 
#define DOMSTRING_SIZE_ERR   2
 
#define HIERARCHY_REQUEST_ERR   3
 
#define INDEX_SIZE_ERR   1
 
#define INUSE_ATTRIBUTE_ERR   10
 
#define INVALID_ACCESS_ERR   15
 
#define INVALID_CHARACTER_ERR   5
 
#define INVALID_MODIFICATION_ERR   13
 
#define INVALID_STATE_ERR   11
 
#define NAMESPACE_ERR   14
 
#define NO_DATA_ALLOWED_ERR   6
 
#define NO_MODIFICATION_ALLOWED_ERR   7
 
#define NOT_FOUND_ERR   8
 
#define NOT_SUPPORTED_ERR   9
 
#define SYNTAX_ERR   12
 
#define THROW_DOM(error, desc)
 
#define THROW_REFERENCE(desc)   return context->throwError(QScriptContext::ReferenceError, QLatin1String(desc));
 
#define THROW_SYNTAX(desc)   return context->throwError(QScriptContext::SyntaxError, QLatin1String(desc));
 
#define TYPE_MISMATCH_ERR   17
 
#define VALIDATION_ERR   16
 
#define WRONG_DOCUMENT_ERR   4
 
#define XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION   15
 

Functions

 DEFINE_BOOL_CONFIG_OPTION (xhrDump, QML_XHR_DUMP)
 
static QScriptValue qmlxmlhttprequest_abort (QScriptContext *context, QScriptEngine *)
 
static QScriptValue qmlxmlhttprequest_getAllResponseHeaders (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_getResponseHeader (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_new (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_onreadystatechange (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_open (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_readyState (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_responseText (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_responseXML (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_send (QScriptContext *context, QScriptEngine *)
 
static QScriptValue qmlxmlhttprequest_setRequestHeader (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_status (QScriptContext *context, QScriptEngine *engine)
 
static QScriptValue qmlxmlhttprequest_statusText (QScriptContext *context, QScriptEngine *engine)
 
void qt_add_qmlxmlhttprequest (QScriptEngine *engine)
 

Macro Definition Documentation

◆ A

#define A (   arg)    (arg)->addref()

◆ D

#define D (   arg)    (arg)->release()

◆ DOMSTRING_SIZE_ERR

#define DOMSTRING_SIZE_ERR   2

Definition at line 68 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ HIERARCHY_REQUEST_ERR

#define HIERARCHY_REQUEST_ERR   3

Definition at line 69 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ INDEX_SIZE_ERR

#define INDEX_SIZE_ERR   1

Definition at line 67 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ INUSE_ATTRIBUTE_ERR

#define INUSE_ATTRIBUTE_ERR   10

Definition at line 76 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ INVALID_ACCESS_ERR

#define INVALID_ACCESS_ERR   15

Definition at line 81 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ INVALID_CHARACTER_ERR

#define INVALID_CHARACTER_ERR   5

Definition at line 71 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ INVALID_MODIFICATION_ERR

#define INVALID_MODIFICATION_ERR   13

Definition at line 79 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ INVALID_STATE_ERR

#define INVALID_STATE_ERR   11

◆ NAMESPACE_ERR

#define NAMESPACE_ERR   14

Definition at line 80 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ NO_DATA_ALLOWED_ERR

#define NO_DATA_ALLOWED_ERR   6

Definition at line 72 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ NO_MODIFICATION_ALLOWED_ERR

#define NO_MODIFICATION_ALLOWED_ERR   7

Definition at line 73 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ NOT_FOUND_ERR

#define NOT_FOUND_ERR   8

Definition at line 74 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ NOT_SUPPORTED_ERR

#define NOT_SUPPORTED_ERR   9

◆ SYNTAX_ERR

#define SYNTAX_ERR   12

◆ THROW_DOM

#define THROW_DOM (   error,
  desc 
)
Value:
{ \
QScriptValue errorValue = context->throwError(QLatin1String(desc)); \
errorValue.setProperty(QLatin1String("code"), error); \
return errorValue; \
}
#define error(msg)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

Definition at line 85 of file qdeclarativexmlhttprequest.cpp.

Referenced by qmlxmlhttprequest_getAllResponseHeaders(), qmlxmlhttprequest_getResponseHeader(), qmlxmlhttprequest_open(), qmlxmlhttprequest_send(), qmlxmlhttprequest_setRequestHeader(), qmlxmlhttprequest_status(), and qmlxmlhttprequest_statusText().

◆ THROW_REFERENCE

#define THROW_REFERENCE (   desc)    return context->throwError(QScriptContext::ReferenceError, QLatin1String(desc));

◆ THROW_SYNTAX

#define THROW_SYNTAX (   desc)    return context->throwError(QScriptContext::SyntaxError, QLatin1String(desc));

Definition at line 92 of file qdeclarativexmlhttprequest.cpp.

◆ TYPE_MISMATCH_ERR

#define TYPE_MISMATCH_ERR   17

Definition at line 83 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ VALIDATION_ERR

#define VALIDATION_ERR   16

Definition at line 82 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ WRONG_DOCUMENT_ERR

#define WRONG_DOCUMENT_ERR   4

Definition at line 70 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

◆ XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION

#define XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION   15

Function Documentation

◆ DEFINE_BOOL_CONFIG_OPTION()

DEFINE_BOOL_CONFIG_OPTION ( xhrDump  ,
QML_XHR_DUMP   
)

◆ qmlxmlhttprequest_abort()

static QScriptValue qmlxmlhttprequest_abort ( QScriptContext context,
QScriptEngine  
)
static

Definition at line 1540 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1541 {
1542  QScriptValue dataObject = context->thisObject().data();
1544  if (!request)
1545  THROW_REFERENCE("Not an XMLHttpRequest object");
1546 
1547  return request->abort(&dataObject);
1548 }
#define THROW_REFERENCE(desc)
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QScriptValue data() const
Returns the internal data of this QScriptValue object.
QScriptValue abort(QScriptValue *me)
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ qmlxmlhttprequest_getAllResponseHeaders()

static QScriptValue qmlxmlhttprequest_getAllResponseHeaders ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1570 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1571 {
1572  Q_UNUSED(engine)
1574  if (!request)
1575  THROW_REFERENCE("Not an XMLHttpRequest object");
1576 
1577  if (context->argumentCount() != 0)
1578  THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
1579 
1580  if (request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
1583  THROW_DOM(INVALID_STATE_ERR, "Invalid state");
1584 
1585  return QScriptValue(request->headers());
1586 }
#define THROW_REFERENCE(desc)
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define SYNTAX_ERR
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QScriptValue data() const
Returns the internal data of this QScriptValue object.
#define INVALID_STATE_ERR
#define THROW_DOM(error, desc)
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qmlxmlhttprequest_getResponseHeader()

static QScriptValue qmlxmlhttprequest_getResponseHeader ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1550 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1551 {
1552  Q_UNUSED(engine)
1554  if (!request)
1555  THROW_REFERENCE("Not an XMLHttpRequest object");
1556 
1557  if (context->argumentCount() != 1)
1558  THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
1559 
1560  if (request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
1563  THROW_DOM(INVALID_STATE_ERR, "Invalid state");
1564 
1565  QString headerName = context->argument(0).toString();
1566 
1567  return QScriptValue(request->header(headerName));
1568 }
#define THROW_REFERENCE(desc)
static QByteArray headerName(QNetworkRequest::KnownHeaders header)
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
#define SYNTAX_ERR
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QScriptValue data() const
Returns the internal data of this QScriptValue object.
QString header(const QString &name)
#define INVALID_STATE_ERR
#define THROW_DOM(error, desc)
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QScriptValue argument(int index) const
Returns the function argument at the given index.

◆ qmlxmlhttprequest_new()

static QScriptValue qmlxmlhttprequest_new ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1679 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1680 {
1681  if (context->isCalledAsConstructor()) {
1683  }
1684  return engine->undefinedValue();
1685 }
bool isCalledAsConstructor() const
Returns true if the function was called as a constructor (e.g.
static QDeclarativeScriptEngine * get(QScriptEngine *e)
QScriptValue newQObject(QObject *object, ValueOwnership ownership=QtOwnership, const QObjectWrapOptions &options=0)
Creates a QtScript object that wraps the given QObject object, using the given ownership.
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.

◆ qmlxmlhttprequest_onreadystatechange()

static QScriptValue qmlxmlhttprequest_onreadystatechange ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1661 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1662 {
1663  Q_UNUSED(engine);
1664  QScriptValue dataObject = context->thisObject().data();
1666  if (!request)
1667  THROW_REFERENCE("Not an XMLHttpRequest object");
1668 
1669  if (context->argumentCount()) {
1670  QScriptValue v = context->argument(0);
1671  dataObject.setProperty(QLatin1String("callback"), v);
1672  return v;
1673  } else {
1674  return dataObject.property(QLatin1String("callback"));
1675  }
1676 }
#define THROW_REFERENCE(desc)
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QScriptValue data() const
Returns the internal data of this QScriptValue object.
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QScriptValue argument(int index) const
Returns the function argument at the given index.

◆ qmlxmlhttprequest_open()

static QScriptValue qmlxmlhttprequest_open ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1423 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1424 {
1425  QScriptValue dataObject = context->thisObject().data();
1427  if (!request)
1428  THROW_REFERENCE("Not an XMLHttpRequest object");
1429 
1430  if (context->argumentCount() < 2 || context->argumentCount() > 5)
1431  THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
1432 
1433  // Argument 0 - Method
1434  QString method = context->argument(0).toString().toUpper();
1435  if (method != QLatin1String("GET") &&
1436  method != QLatin1String("PUT") &&
1437  method != QLatin1String("HEAD") &&
1438  method != QLatin1String("POST") &&
1439  method != QLatin1String("DELETE"))
1440  THROW_DOM(SYNTAX_ERR, "Unsupported HTTP method type");
1441 
1442 
1443  // Argument 1 - URL
1444  QUrl url = QUrl::fromEncoded(context->argument(1).toString().toUtf8());
1445 
1446  if (url.isRelative()) {
1447  url = QDeclarativeScriptEngine::get(engine)->resolvedUrl(context,url);
1448  }
1449 
1450  // Argument 2 - async (optional)
1451  if (context->argumentCount() > 2 && !context->argument(2).toBoolean())
1452  THROW_DOM(NOT_SUPPORTED_ERR, "Synchronous XMLHttpRequest calls are not supported");
1453 
1454 
1455  // Argument 3/4 - user/pass (optional)
1456  QString username, password;
1457  if (context->argumentCount() > 3)
1458  username = context->argument(3).toString();
1459  if (context->argumentCount() > 4)
1460  password = context->argument(4).toString();
1461 
1462 
1463  // Clear the fragment (if any)
1464  url.setFragment(QString());
1465  // Set username/password
1466  if (!username.isNull()) url.setUserName(username);
1467  if (!password.isNull()) url.setPassword(password);
1468 
1469  return request->open(&dataObject, method, url);
1470 }
#define THROW_REFERENCE(desc)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
static QDeclarativeScriptEngine * get(QScriptEngine *e)
#define SYNTAX_ERR
bool toBoolean() const
Use toBool() instead.
void setFragment(const QString &fragment)
Sets the fragment of the URL to fragment.
Definition: qurl.cpp:5669
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QUrl resolvedUrl(QScriptContext *context, const QUrl &url)
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QScriptValue data() const
Returns the internal data of this QScriptValue object.
#define NOT_SUPPORTED_ERR
#define THROW_DOM(error, desc)
QScriptValue open(QScriptValue *me, const QString &, const QUrl &)
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
Definition: qurl.cpp:5964
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
void setUserName(const QString &userName)
Sets the URL&#39;s user name to userName.
Definition: qurl.cpp:4648
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue argument(int index) const
Returns the function argument at the given index.
void setPassword(const QString &password)
Sets the URL&#39;s password to password.
Definition: qurl.cpp:4736

◆ qmlxmlhttprequest_readyState()

static QScriptValue qmlxmlhttprequest_readyState ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1589 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1590 {
1591  Q_UNUSED(engine)
1593  if (!request)
1594  THROW_REFERENCE("Not an XMLHttpRequest object");
1595 
1596  return QScriptValue(request->readyState());
1597 }
#define THROW_REFERENCE(desc)
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QScriptValue data() const
Returns the internal data of this QScriptValue object.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qmlxmlhttprequest_responseText()

static QScriptValue qmlxmlhttprequest_responseText ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1633 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1634 {
1635  Q_UNUSED(engine)
1637  if (!request)
1638  THROW_REFERENCE("Not an XMLHttpRequest object");
1639 
1640  if (request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
1642  return QScriptValue(QString());
1643  else
1644  return QScriptValue(request->responseBody());
1645 }
#define THROW_REFERENCE(desc)
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QScriptValue data() const
Returns the internal data of this QScriptValue object.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qmlxmlhttprequest_responseXML()

static QScriptValue qmlxmlhttprequest_responseXML ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1647 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1648 {
1650  if (!request)
1651  THROW_REFERENCE("Not an XMLHttpRequest object");
1652 
1653  if (!request->receivedXml() ||
1656  return engine->nullValue();
1657  else
1658  return Document::load(engine, request->rawResponseBody());
1659 }
#define THROW_REFERENCE(desc)
const QByteArray & rawResponseBody() const
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QScriptValue data() const
Returns the internal data of this QScriptValue object.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
static QScriptValue load(QScriptEngine *engine, const QByteArray &data)

◆ qmlxmlhttprequest_send()

static QScriptValue qmlxmlhttprequest_send ( QScriptContext context,
QScriptEngine  
)
static

Definition at line 1520 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1521 {
1522  QScriptValue dataObject = context->thisObject().data();
1524  if (!request)
1525  THROW_REFERENCE("Not an XMLHttpRequest object");
1526 
1528  THROW_DOM(INVALID_STATE_ERR, "Invalid state");
1529 
1530  if (request->sendFlag())
1531  THROW_DOM(INVALID_STATE_ERR, "Invalid state");
1532 
1533  QByteArray data;
1534  if (context->argumentCount() > 0)
1535  data = context->argument(0).toString().toUtf8();
1536 
1537  return request->send(&dataObject, data);
1538 }
#define THROW_REFERENCE(desc)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
static const char * data(const QByteArray &arr)
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QScriptValue data() const
Returns the internal data of this QScriptValue object.
#define INVALID_STATE_ERR
#define THROW_DOM(error, desc)
QScriptValue send(QScriptValue *me, const QByteArray &)
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue argument(int index) const
Returns the function argument at the given index.

◆ qmlxmlhttprequest_setRequestHeader()

static QScriptValue qmlxmlhttprequest_setRequestHeader ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1472 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1473 {
1475  if (!request)
1476  THROW_REFERENCE("Not an XMLHttpRequest object");
1477 
1478  if (context->argumentCount() != 2)
1479  THROW_DOM(SYNTAX_ERR, "Incorrect argument count");
1480 
1481 
1482  if (request->readyState() != QDeclarativeXMLHttpRequest::Opened ||
1483  request->sendFlag())
1484  THROW_DOM(INVALID_STATE_ERR, "Invalid state");
1485 
1486 
1487  QString name = context->argument(0).toString();
1488  QString value = context->argument(1).toString();
1489 
1490  // ### Check that name and value are well formed
1491 
1492  QString nameUpper = name.toUpper();
1493  if (nameUpper == QLatin1String("ACCEPT-CHARSET") ||
1494  nameUpper == QLatin1String("ACCEPT-ENCODING") ||
1495  nameUpper == QLatin1String("CONNECTION") ||
1496  nameUpper == QLatin1String("CONTENT-LENGTH") ||
1497  nameUpper == QLatin1String("COOKIE") ||
1498  nameUpper == QLatin1String("COOKIE2") ||
1499  nameUpper == QLatin1String("CONTENT-TRANSFER-ENCODING") ||
1500  nameUpper == QLatin1String("DATE") ||
1501  nameUpper == QLatin1String("EXPECT") ||
1502  nameUpper == QLatin1String("HOST") ||
1503  nameUpper == QLatin1String("KEEP-ALIVE") ||
1504  nameUpper == QLatin1String("REFERER") ||
1505  nameUpper == QLatin1String("TE") ||
1506  nameUpper == QLatin1String("TRAILER") ||
1507  nameUpper == QLatin1String("TRANSFER-ENCODING") ||
1508  nameUpper == QLatin1String("UPGRADE") ||
1509  nameUpper == QLatin1String("USER-AGENT") ||
1510  nameUpper == QLatin1String("VIA") ||
1511  nameUpper.startsWith(QLatin1String("PROXY-")) ||
1512  nameUpper.startsWith(QLatin1String("SEC-")))
1513  return engine->undefinedValue();
1514 
1515  request->addHeader(nameUpper, value);
1516 
1517  return engine->undefinedValue();
1518 }
#define THROW_REFERENCE(desc)
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
const char * name
#define SYNTAX_ERR
void addHeader(const QString &, const QString &)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QScriptValue data() const
Returns the internal data of this QScriptValue object.
#define INVALID_STATE_ERR
#define THROW_DOM(error, desc)
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
QScriptValue argument(int index) const
Returns the function argument at the given index.

◆ qmlxmlhttprequest_status()

static QScriptValue qmlxmlhttprequest_status ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1599 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1600 {
1601  Q_UNUSED(engine)
1603  if (!request)
1604  THROW_REFERENCE("Not an XMLHttpRequest object");
1605 
1606  if (request->readyState() == QDeclarativeXMLHttpRequest::Unsent ||
1608  THROW_DOM(INVALID_STATE_ERR, "Invalid state");
1609 
1610  if (request->errorFlag())
1611  return QScriptValue(0);
1612  else
1613  return QScriptValue(request->replyStatus());
1614 }
#define THROW_REFERENCE(desc)
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QScriptValue data() const
Returns the internal data of this QScriptValue object.
#define INVALID_STATE_ERR
#define THROW_DOM(error, desc)
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qmlxmlhttprequest_statusText()

static QScriptValue qmlxmlhttprequest_statusText ( QScriptContext context,
QScriptEngine engine 
)
static

Definition at line 1616 of file qdeclarativexmlhttprequest.cpp.

Referenced by qt_add_qmlxmlhttprequest().

1617 {
1618  Q_UNUSED(engine)
1620  if (!request)
1621  THROW_REFERENCE("Not an XMLHttpRequest object");
1622 
1623  if (request->readyState() == QDeclarativeXMLHttpRequest::Unsent ||
1625  THROW_DOM(INVALID_STATE_ERR, "Invalid state");
1626 
1627  if (request->errorFlag())
1628  return QScriptValue(0);
1629  else
1630  return QScriptValue(request->replyStatusText());
1631 }
#define THROW_REFERENCE(desc)
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QScriptValue data() const
Returns the internal data of this QScriptValue object.
#define INVALID_STATE_ERR
#define THROW_DOM(error, desc)
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qt_add_qmlxmlhttprequest()

void qt_add_qmlxmlhttprequest ( QScriptEngine engine)

Definition at line 1687 of file qdeclarativexmlhttprequest.cpp.

Referenced by QDeclarativeScriptEngine::QDeclarativeScriptEngine().

1688 {
1689  QScriptValue prototype = engine->newObject();
1690 
1691  // Methods
1692  prototype.setProperty(QLatin1String("open"), engine->newFunction(qmlxmlhttprequest_open, 2));
1693  prototype.setProperty(QLatin1String("setRequestHeader"), engine->newFunction(qmlxmlhttprequest_setRequestHeader, 2));
1694  prototype.setProperty(QLatin1String("send"), engine->newFunction(qmlxmlhttprequest_send));
1695  prototype.setProperty(QLatin1String("abort"), engine->newFunction(qmlxmlhttprequest_abort));
1696  prototype.setProperty(QLatin1String("getResponseHeader"), engine->newFunction(qmlxmlhttprequest_getResponseHeader, 1));
1697  prototype.setProperty(QLatin1String("getAllResponseHeaders"), engine->newFunction(qmlxmlhttprequest_getAllResponseHeaders));
1698 
1699  // Read-only properties
1706 
1707  // State values
1713 
1714  // Constructor
1715  QScriptValue constructor = engine->newFunction(qmlxmlhttprequest_new, prototype);
1721  engine->globalObject().setProperty(QLatin1String("XMLHttpRequest"), constructor);
1722 
1723  // DOM Exception
1724  QScriptValue domExceptionPrototype = engine->newObject();
1742 
1743  engine->globalObject().setProperty(QLatin1String("DOMException"), domExceptionPrototype);
1744 }
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
#define INVALID_ACCESS_ERR
static QScriptValue qmlxmlhttprequest_getAllResponseHeaders(QScriptContext *context, QScriptEngine *engine)
#define NAMESPACE_ERR
static QScriptValue qmlxmlhttprequest_new(QScriptContext *context, QScriptEngine *engine)
static QScriptValue qmlxmlhttprequest_statusText(QScriptContext *context, QScriptEngine *engine)
static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, QScriptEngine *engine)
static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context, QScriptEngine *engine)
QScriptValue globalObject() const
Returns this engine&#39;s Global Object.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define INDEX_SIZE_ERR
static QScriptValue qmlxmlhttprequest_status(QScriptContext *context, QScriptEngine *engine)
#define VALIDATION_ERR
#define NOT_FOUND_ERR
static QScriptValue qmlxmlhttprequest_setRequestHeader(QScriptContext *context, QScriptEngine *engine)
#define INUSE_ATTRIBUTE_ERR
#define SYNTAX_ERR
QScriptValue newObject()
Creates a QtScript object of class Object.
#define NO_MODIFICATION_ALLOWED_ERR
static QScriptValue qmlxmlhttprequest_responseText(QScriptContext *context, QScriptEngine *engine)
#define NO_DATA_ALLOWED_ERR
static QScriptValue qmlxmlhttprequest_abort(QScriptContext *context, QScriptEngine *)
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
#define NOT_SUPPORTED_ERR
#define INVALID_STATE_ERR
#define TYPE_MISMATCH_ERR
static QScriptValue qmlxmlhttprequest_readyState(QScriptContext *context, QScriptEngine *engine)
static QScriptValue qmlxmlhttprequest_send(QScriptContext *context, QScriptEngine *)
static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScriptEngine *engine)
static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngine *engine)
#define INVALID_CHARACTER_ERR
#define HIERARCHY_REQUEST_ERR
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define WRONG_DOCUMENT_ERR
#define DOMSTRING_SIZE_ERR
#define INVALID_MODIFICATION_ERR