Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / v8 / qv8qobjectwrapper_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QV8QOBJECTWRAPPER_P_H
43 #define QV8QOBJECTWRAPPER_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include <QtCore/qglobal.h>
57 #include <QtCore/qmetatype.h>
58 #include <QtCore/qpair.h>
59 #include <QtCore/qhash.h>
60 #include <private/qv8_p.h>
61 #include <private/qhashedstring_p.h>
62 #include <private/qdeclarativedata_p.h>
63 #include <private/qdeclarativepropertycache_p.h>
64
65 QT_BEGIN_NAMESPACE
66
67 class QObject;
68 class QV8Engine;
69 class QDeclarativeData;
70 class QV8ObjectResource;
71 class QV8QObjectInstance;
72 class QV8QObjectConnectionList;
73 class QDeclarativePropertyCache;
74 class Q_DECLARATIVE_EXPORT QV8QObjectWrapper
75 {
76 public:
77     QV8QObjectWrapper();
78     ~QV8QObjectWrapper();
79
80     void init(QV8Engine *);
81     void destroy();
82
83     v8::Handle<v8::Value> newQObject(QObject *object);
84     bool isQObject(v8::Handle<v8::Object>);
85     QObject *toQObject(v8::Handle<v8::Object>);
86     static QObject *toQObject(QV8ObjectResource *);
87
88     enum RevisionMode { IgnoreRevision, CheckRevision };
89     inline v8::Handle<v8::Value> getProperty(QObject *, const QHashedV8String &, RevisionMode);
90     inline bool setProperty(QObject *, const QHashedV8String &, v8::Handle<v8::Value>, RevisionMode);
91
92 private:
93     friend class QDeclarativePropertyCache;
94     friend class QV8QObjectConnectionList;
95     friend class QV8QObjectInstance;
96
97     v8::Local<v8::Object> newQObject(QObject *, QDeclarativeData *, QV8Engine *);
98     static v8::Handle<v8::Value> GetProperty(QV8Engine *, QObject *, v8::Handle<v8::Value> *, 
99                                              const QHashedV8String &, QV8QObjectWrapper::RevisionMode);
100     static bool SetProperty(QV8Engine *, QObject *, const QHashedV8String &,
101                             v8::Handle<v8::Value>, QV8QObjectWrapper::RevisionMode);
102     static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property, 
103                                         const v8::AccessorInfo &info);
104     static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property, 
105                                         v8::Local<v8::Value> value,
106                                         const v8::AccessorInfo &info);
107     static v8::Handle<v8::Integer> Query(v8::Local<v8::String> property,
108                                          const v8::AccessorInfo &info);
109     static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo &info);
110     static v8::Handle<v8::Value> Connect(const v8::Arguments &args);
111     static v8::Handle<v8::Value> Disconnect(const v8::Arguments &args);
112     static v8::Handle<v8::Value> Invoke(const v8::Arguments &args);
113     static QPair<QObject *, int> ExtractQtMethod(QV8Engine *, v8::Handle<v8::Function>);
114     static QPair<QObject *, int> ExtractQtSignal(QV8Engine *, v8::Handle<v8::Object>);
115
116     QV8Engine *m_engine;
117     quint32 m_id;
118     v8::Persistent<v8::Function> m_constructor;
119     v8::Persistent<v8::Function> m_methodConstructor;
120     v8::Persistent<v8::Function> m_signalHandlerConstructor;
121     v8::Persistent<v8::String> m_toStringSymbol;
122     v8::Persistent<v8::String> m_destroySymbol;
123     QHashedV8String m_toStringString;
124     QHashedV8String m_destroyString;
125     v8::Persistent<v8::Object> m_hiddenObject;
126     QHash<QObject *, QV8QObjectConnectionList *> m_connections;
127     typedef QHash<QObject *, QV8QObjectInstance *> TaintedHash;
128     TaintedHash m_taintedObjects;
129 };
130
131 v8::Handle<v8::Value> QV8QObjectWrapper::getProperty(QObject *object, const QHashedV8String &string,  
132                                                      RevisionMode mode)
133 {
134     QDeclarativeData *dd = QDeclarativeData::get(object, false);
135     if (!dd || !dd->propertyCache || m_toStringString == string || m_destroyString == string ||
136         dd->propertyCache->property(string)) {
137         return GetProperty(m_engine, object, 0, string, mode);
138     } else {
139         return v8::Handle<v8::Value>();
140     }
141 }
142
143 bool QV8QObjectWrapper::setProperty(QObject *object, const QHashedV8String &string, 
144                                     v8::Handle<v8::Value> value, RevisionMode mode)
145 {
146     QDeclarativeData *dd = QDeclarativeData::get(object, false);
147     if (!dd || !dd->propertyCache || m_toStringString == string || m_destroyString == string ||
148         dd->propertyCache->property(string)) {
149         return SetProperty(m_engine, object, string, value, mode);
150     } else {
151         return false;
152     }
153 }
154
155 QT_END_NAMESPACE
156
157 #endif // QV8QOBJECTWRAPPER_P_H
158
159