2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file JavaScriptInterface.h
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19 * @author Piotr Fatyga (p.fatyga@samsung.com)
23 #ifndef WRT_SRC_PLUGIN_SERVICE_WEBKIT_INTERFACE_H_
24 #define WRT_SRC_PLUGIN_SERVICE_WEBKIT_INTERFACE_H_
30 #include <dpl/noncopyable.h>
31 #include <dpl/singleton.h>
32 #include <Commons/JSObjectDeclaration.h>
33 #include <Commons/JSObject.h>
35 //forward declaration of JSConectexRef
37 typedef const struct OpaqueJSContext* JSContextRef;
38 typedef struct OpaqueJSContext* JSGlobalContextRef;
39 typedef struct OpaqueJSValue* JSObjectRef;
42 class JavaScriptInterface : DPL::Noncopyable
46 typedef std::vector<std::string> PropertiesList;
48 typedef std::list<JSObjectPtr> ObjectsList;
49 typedef std::shared_ptr<ObjectsList> ObjectsListPtr;
52 JSObjectPtr getGlobalObject(JSGlobalContextRef context) const;
55 JSObjectPtr createObject(JSGlobalContextRef context,
56 const JSObjectDeclarationPtr& declaration);
59 void setObjectProperty(JSGlobalContextRef context,
60 const JSObjectPtr& parentObject,
61 const std::string &propertyName,
62 const JSObjectPtr& propertyObject);
64 void removeObjectProperty(JSGlobalContextRef context,
65 const JSObjectPtr& parentObject,
66 const std::string &propertyName);
68 PropertiesList getObjectPropertiesList(JSGlobalContextRef context,
69 const JSObjectPtr& object) const;
71 JSObjectPtr copyObjectToIframe(JSGlobalContextRef context,
72 const JSObjectPtr& iframe,
73 const std::string& name);
75 ObjectsListPtr getIframesList(JSGlobalContextRef context) const;
77 void removeIframes(JSGlobalContextRef context);
79 void invokeGarbageCollector(JSGlobalContextRef context);
81 JSObjectPtr getJSObjectProperty(JSGlobalContextRef ctx,
82 const JSObjectPtr& frame,
83 const std::string& name) const;
90 JSObjectPtr makeJSFunctionObject(
91 JSGlobalContextRef context,
92 const std::string &name,
93 js_function_impl functionImplementation) const;
94 JSObjectPtr makeJSClassObject(
95 JSGlobalContextRef context,
96 JSObjectDeclaration::ConstClassTemplate classTemplate) const;
97 JSObjectPtr makeJSObjectBasedOnInterface(
98 JSGlobalContextRef context,
99 const std::string &interfaceName) const;
100 JSObjectPtr makeJSInterface(
101 JSGlobalContextRef context,
102 JSObjectDeclaration::ConstClassTemplate classTemplate,
103 JSObjectDeclaration::ConstructorCallback constructorCallback) const;
105 ObjectsListPtr getIframesList(JSContextRef context,
106 JSObjectRef object) const;
108 friend class DPL::Singleton<JavaScriptInterface>;
111 typedef DPL::Singleton<JavaScriptInterface> JavaScriptInterfaceSingleton;